Search in sources :

Example 1 with FCMToken

use of se.oort.diplicity.apigen.FCMToken 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)

Aggregations

BigInteger (java.math.BigInteger)1 Date (java.util.Date)1 FCMNotificationConfig (se.oort.diplicity.apigen.FCMNotificationConfig)1 FCMToken (se.oort.diplicity.apigen.FCMToken)1 SingleContainer (se.oort.diplicity.apigen.SingleContainer)1 UserConfig (se.oort.diplicity.apigen.UserConfig)1