Skip to content

Feature app defined setLanguage #452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 3, 2021
Merged

Feature app defined setLanguage #452

merged 7 commits into from
Aug 3, 2021

Conversation

tanaynigam
Copy link
Contributor

@tanaynigam tanaynigam commented Jul 29, 2021

Description

Line Summary

Add feature app-defined language implementation to OneSignal-Flutter-SDK. A user can define their own language setting to be used by OneSignal-SDK

Details

  • Add setLanguage method to OneSignal Android plugin
  • Add setLanguage method to OneSignal iOS plugin
  • Update Podfile and onesignal_flutter.podspec files with OneSignalXCFramework 3.6.0
  • Add setLanguage bridge methods to onesignal_flutter.dart

Test

  • Test device using button click to call _handleSetLanguage to set it to language different from language defined by the app. OneSignal app dashboard reflects the language set using OneSignal.setLanguage
  • Add unit test defining 'fr' using setLanguage callback that expects language returned to be the same

This change is Reviewable

* Add setLanguage method to Android plugin in OneSignalPlugin.java
* Update Podfile and Podspec with OneSignalXCFramework 3.6.0
* OneSignalXCFramework 3.6.0 enables the use of setLanguage on iOS
Copy link
Contributor

@emawby emawby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit the commit that changes the iOS plugin is named add setLanguage to Android plugin.

Reviewable status: 0 of 7 files reviewed, 1 unresolved discussion (waiting on @Jeasmine, @jkasten2, and @tanaynigam)


test/mock_channel.dart, line 71 at r1 (raw file):

        return {"success" : true};
      case "OneSignal#setLanguage":
      this.state.language = (call.arguments as Map<dynamic, dynamic>)['language'] as String?;;

nit indentation here looks off

* Add setLanguage method to iOS plugin in OneSignalPlugin.m
* Add setLanguage bridge method to onesignal_flutter.dart
* Add language string and OneSignal setLanguage call to OneSignalMockChannelController
* Add setLanguage test to onesignalflutter_test.dart
@tanaynigam tanaynigam force-pushed the feature/setLanguage branch from 9302f83 to 2872895 Compare August 2, 2021 17:31
* Fix indentation in mock_channel.dart
@@ -337,6 +339,14 @@ public void onFailure(OneSignal.OSSMSUpdateError error) {
});
}

private void setLanguage(MethodCall call, final Result result) {
String language = call.argument("language");
if(language != null && language.length() == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a space after the if? Also, isn't there a string utils notNullorEmpty? I might be wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this condition i referred from setExternalUserId looks for a condition where the string may be non-null but is empty. I which case it assigns null value to the string (possibly to push null to the endpoint instead of an empty string?)

@@ -320,6 +322,14 @@ - (void)removeExternalUserId:(FlutterMethodCall *)call withResult:(FlutterResult
}];
}

- (void)setLanguage:(FlutterMethodCall *)call withResult:(FlutterResult)result {
id language = call.arguments[@"language"];
if (language == [NSNull null])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in iOS i think you always need to put the braces {}

Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 7 files at r1, 1 of 1 files at r2.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @emawby and @tanaynigam)


test/mock_channel.dart, line 71 at r1 (raw file):

Previously, emawby (Elliot Mawby) wrote…

nit indentation here looks off

Remove extra semicolon ;

* fix format errors in OneSignalPlugin.java, OneSignalPlugin.m and mock_channel.dart
Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r3.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Jeasmine and @tanaynigam)


android/src/main/java/com/onesignal/flutter/OneSignalPlugin.java, line 344 at r2 (raw file):

Previously, tanaynigam (Tanay Nigam) wrote…

I think this condition i referred from setExternalUserId looks for a condition where the string may be non-null but is empty. I which case it assigns null value to the string (possibly to push null to the endpoint instead of an empty string?)

I think either way this is fine, since on REST API it will just set language to "en" for either "" or null values. Would code would be a simpler if we just remove this if completely. @Jeasmine thoughts on this?

Copy link
Contributor

@emawby emawby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Jeasmine and @tanaynigam)

@tanaynigam tanaynigam merged commit cf6919d into main Aug 3, 2021
@tanaynigam tanaynigam deleted the feature/setLanguage branch August 3, 2021 19:51
@Jeasmine Jeasmine mentioned this pull request Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants