Search in sources :

Example 1 with UserConfig

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));
    }
}
Also used : SingleContainer(se.oort.diplicity.apigen.SingleContainer) FCMToken(se.oort.diplicity.apigen.FCMToken) BigInteger(java.math.BigInteger) UserConfig(se.oort.diplicity.apigen.UserConfig) Date(java.util.Date) FCMNotificationConfig(se.oort.diplicity.apigen.FCMNotificationConfig)

Example 2 with UserConfig

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)));
}
Also used : SharedPreferences(android.content.SharedPreferences) Gson(com.google.gson.Gson) UserConfig(se.oort.diplicity.apigen.UserConfig) SingleContainer(se.oort.diplicity.apigen.SingleContainer) MultiContainer(se.oort.diplicity.apigen.MultiContainer) Func2(rx.functions.Func2)

Aggregations

SingleContainer (se.oort.diplicity.apigen.SingleContainer)2 UserConfig (se.oort.diplicity.apigen.UserConfig)2 SharedPreferences (android.content.SharedPreferences)1 Gson (com.google.gson.Gson)1 BigInteger (java.math.BigInteger)1 Date (java.util.Date)1 Func2 (rx.functions.Func2)1 FCMNotificationConfig (se.oort.diplicity.apigen.FCMNotificationConfig)1 FCMToken (se.oort.diplicity.apigen.FCMToken)1 MultiContainer (se.oort.diplicity.apigen.MultiContainer)1