use of se.oort.diplicity.apigen.UserConfig in project android-diplicity by zond.
the class RetrofitActivity method updateFCMPushOption.
public void updateFCMPushOption(UserConfig userConfig, boolean newValue, String message) {
FCMToken pushToken = getFCMToken(userConfig);
if (newValue) {
if (pushToken == null) {
pushToken = new FCMToken();
pushToken.Note = message + " at " + new Date();
if (userConfig.FCMTokens == null) {
userConfig.FCMTokens = new ArrayList<FCMToken>();
}
userConfig.FCMTokens.add(pushToken);
} else if (pushToken.Disabled) {
pushToken.Note = message + " at " + new Date();
}
pushToken.Disabled = false;
pushToken.Value = FirebaseInstanceId.getInstance().getToken();
pushToken.App = APP_NAME;
pushToken.ReplaceToken = new BigInteger(8 * 24, random).toString(32);
pushToken.MessageConfig = new FCMNotificationConfig();
pushToken.MessageConfig.ClickActionTemplate = MessagingService.FCM_NOTIFY_ACTION;
pushToken.PhaseConfig = new FCMNotificationConfig();
pushToken.PhaseConfig.ClickActionTemplate = MessagingService.FCM_NOTIFY_ACTION;
} else {
if (pushToken != null && (pushToken.Disabled == null || !pushToken.Disabled)) {
pushToken.Disabled = true;
pushToken.Note = message + " at " + new Date();
}
}
if (pushToken != null) {
final FCMToken finalToken = pushToken;
handleReq(userConfigService.UserConfigUpdate(userConfig, getLoggedInUser().Id), new Sendable<SingleContainer<UserConfig>>() {
@Override
public void send(SingleContainer<UserConfig> userConfigSingleContainer) {
PreferenceManager.getDefaultSharedPreferences(RetrofitActivity.this).edit().putString(FCM_REPLACE_TOKEN_PREF_KEY, finalToken.ReplaceToken).apply();
}
}, getResources().getString(R.string.updating_settings));
}
}
use of se.oort.diplicity.apigen.UserConfig in project android-diplicity by zond.
the class RetrofitActivity method performLogin.
protected void performLogin() {
observe(JoinObservable.when(JoinObservable.from(rootService.GetRoot()).and(variantService.GetVariants()).then(new Func2<RootService.Root, MultiContainer<VariantService.Variant>, Object>() {
@Override
public Object call(final RootService.Root root, final MultiContainer<VariantService.Variant> receivedVariants) {
SharedPreferences.Editor prefEditor = prefs.edit();
Gson gson = new Gson();
prefEditor.putString(LOGGED_IN_USER_PREF_KEY, gson.toJson(root.Properties.User));
loggedInUser = root.Properties.User;
prefEditor.putString(VARIANTS_PREF_KEY, gson.toJson(receivedVariants));
variants = receivedVariants;
prefEditor.apply();
List<LoginSubscriber<?>> subscribersCopy;
synchronized (loginSubscribers) {
subscribersCopy = new ArrayList<LoginSubscriber<?>>(loginSubscribers);
loginSubscribers.clear();
}
for (LoginSubscriber<?> subscriber : subscribersCopy) {
subscriber.retry();
}
if (!prefs.getBoolean(INITIAL_FCM_SETUP_DONE_PREF_KEY, false)) {
handleReq(userConfigService.UserConfigLoad(root.Properties.User.Id), new Sendable<SingleContainer<UserConfig>>() {
@Override
public void send(SingleContainer<UserConfig> userConfigSingleContainer) {
updateFCMPushOption(userConfigSingleContainer.Properties, true, "Enabled at initial startup");
prefs.edit().putBoolean(INITIAL_FCM_SETUP_DONE_PREF_KEY, true).apply();
}
}, getResources().getString(R.string.updating_settings));
}
return null;
}
})).toObservable(), null, newProgressAndToastHandler(null, getResources().getString(R.string.logging_in)));
}
Aggregations