Merge pull request #786 from lbryio/i18n
add language constant for app launch
This commit is contained in:
commit
b61fc3a148
2 changed files with 36 additions and 2 deletions
2
app
2
app
|
@ -1 +1 @@
|
|||
Subproject commit e901e8107439dbe9a0a236515e9a584e0bdcd3d0
|
||||
Subproject commit f2ca5fb53e30c9af77bb710c2a2560b2fcd57b82
|
|
@ -25,6 +25,7 @@ import com.facebook.react.bridge.Promise;
|
|||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
|
@ -60,6 +61,10 @@ public class UtilityModule extends ReactContextBaseJavaModule {
|
|||
|
||||
public static final String RECEIVE_CREATOR_NOTIFICATIONS = "receiveCreatorNotifications";
|
||||
|
||||
// the last language set to be loaded
|
||||
private static final String LANGUAGE_SETTING_KEY = "language";
|
||||
|
||||
private String language;
|
||||
|
||||
private Context context;
|
||||
|
||||
|
@ -73,6 +78,16 @@ public class UtilityModule extends ReactContextBaseJavaModule {
|
|||
} catch (Exception ex) {
|
||||
// continue without keystore
|
||||
}
|
||||
|
||||
SharedPreferences sp = context.getSharedPreferences(MainActivity.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
language = sp.getString(LANGUAGE_SETTING_KEY, "en");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getConstants() {
|
||||
final Map<String, Object> constants = MapBuilder.newHashMap();
|
||||
constants.put("language", language);
|
||||
return constants;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -122,7 +137,6 @@ public class UtilityModule extends ReactContextBaseJavaModule {
|
|||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -397,6 +411,26 @@ public class UtilityModule extends ReactContextBaseJavaModule {
|
|||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void setNativeStringSetting(String key, String value) {
|
||||
if (context != null) {
|
||||
SharedPreferences sp = context.getSharedPreferences(MainActivity.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.putString(key, value);
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void getNativeStringSetting(String key, String defaultValue, Promise promise) {
|
||||
if (context != null) {
|
||||
SharedPreferences sp = context.getSharedPreferences(MainActivity.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
promise.resolve(sp.getString(key, defaultValue));
|
||||
} else {
|
||||
promise.resolve(null);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void getNotificationLaunchTarget(Promise promise) {
|
||||
Activity activity = MainActivity.getActivity();
|
||||
|
|
Loading…
Reference in a new issue