Search in sources :

Example 1 with SecurePreferences

use of com.securepreferences.SecurePreferences in project pod-chat-android-sdk by FanapSoft.

the class App method getSharedPreferences.

/**
 * Single point for the app to get the secure prefs object
 *
 * @return
 */
public SecurePreferences getSharedPreferences() {
    if (mSecurePrefs == null) {
        mSecurePrefs = new SecurePreferences(this, "", "chat_prefs.xml");
        SecurePreferences.setLoggingEnabled(true);
    }
    return mSecurePrefs;
}
Also used : SecurePreferences(com.securepreferences.SecurePreferences)

Example 2 with SecurePreferences

use of com.securepreferences.SecurePreferences in project pod-chat-android-sdk by FanapSoft.

the class PodNotificationManager method saveConfig.

private static void saveConfig(CustomNotificationConfig mConfig, Context context) {
    SecurePreferences s = getSecurePrefs(context);
    SharedPreferences.Editor e = s.edit();
    if (mConfig.getTargetActivity() != null) {
        e.putString(TARGET_ACTIVITY, mConfig.getTargetActivity().getClass().getName());
    } else if (!Util.isNullOrEmpty(mConfig.getTargetActivityString())) {
        e.putString(TARGET_ACTIVITY, mConfig.getTargetActivityString());
    } else
        throw new IllegalStateException("Target Activity Could not be null");
    e.putInt(ICON, mConfig.getIcon());
    e.putInt(NOTIF_IMPORTANCE, mConfig.getNotificationImportance());
    e.putString(CHANNEL_ID, mConfig.getChannelId());
    e.putString(PACKAGE_NAME, context.getApplicationInfo().packageName);
    e.apply();
}
Also used : SharedPreferences(android.content.SharedPreferences) SecurePreferences(com.securepreferences.SecurePreferences)

Example 3 with SecurePreferences

use of com.securepreferences.SecurePreferences in project pod-chat-android-sdk by FanapSoft.

the class PodNotificationManager method checkForNewFCMToken.

private static void checkForNewFCMToken(Context context, long userId) {
    FirebaseOptions options = new FirebaseOptions.Builder().setApplicationId(context.getString(R.string.firebase_app_id)).setApiKey(context.getString(R.string.firebase_api_key)).setProjectId(context.getString(R.string.firebase_project_id)).build();
    FirebaseApp.initializeApp(context, /* Context */
    options, "secondary");
    FirebaseApp secondary = FirebaseApp.getInstance("secondary");
    FirebaseInstanceId.getInstance(secondary).getInstanceId().addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
            listener.onNotificationEvent("Token Retrieved");
            String newToken = task.getResult() != null ? task.getResult().getToken() : null;
            SecurePreferences mSecurePrefs = getSecurePrefs(context);
            String lastToken = mSecurePrefs.getString(KEY_FCM_TOKEN, null);
            // no token saved in device register device with new token
            if (lastToken == null && newToken != null) {
                fcmToken = newToken;
                createRegisterUserDeviceRequest(context, userId);
            }
            // token refreshed, should update in server
            if (lastToken != null && newToken != null && !lastToken.equals(newToken)) {
                fcmToken = lastToken;
                createUpdateUserDeviceRequest(newToken);
            }
        } else {
            String cause = task.getException() != null ? task.getException().getMessage() != null ? task.getException().getMessage() : "Unknown" : "Unknown";
            listener.onNotificationError("Failed to retrieve fcm token: " + cause);
            Log.w(TAG, "getInstanceId failed", task.getException());
        }
    });
}
Also used : SecurePreferences(com.securepreferences.SecurePreferences) FirebaseOptions(com.google.firebase.FirebaseOptions) FirebaseApp(com.google.firebase.FirebaseApp)

Example 4 with SecurePreferences

use of com.securepreferences.SecurePreferences in project pod-chat-android-sdk by FanapSoft.

the class PodNotificationManager method showNotification.

public static void showNotification(Map<String, String> data, Context context) {
    if (!shouldShowNotification)
        return;
    SecurePreferences securePreferences = getSecurePrefs(context);
    PodPushMessage pushMessage = new PodPushMessage().createFromMapData(data);
    notificationsList.add(pushMessage);
    PodThreadPushMessages.addNewMessage(pushMessage);
    new Thread(() -> ShowNotificationHelper.showNewMessageNotification(context, securePreferences.getString(TARGET_ACTIVITY, ""), securePreferences.getInt(NOTIF_IMPORTANCE, NotificationManagerCompat.IMPORTANCE_DEFAULT), securePreferences.getInt(ICON, R.drawable.common_google_signin_btn_icon_dark), securePreferences.getString(CHANNEL_ID, ""))).start();
// 
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// new Thread(() -> ShowNotificationHelper.showSampleNotification2(context)).start();
// } else {
// new Thread(() -> ShowNotificationHelper.showSampleNotification(context)).start();
// }
}
Also used : SecurePreferences(com.securepreferences.SecurePreferences)

Example 5 with SecurePreferences

use of com.securepreferences.SecurePreferences in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method init.

/**
 * Initialize the Chat
 *
 * @param context for Async sdk and other usage
 */
public static synchronized Chat init(Context context) {
    if (instance == null) {
        setupSentry(context);
        async = Async.getInstance(context);
        async.rawLog(BuildConfig.DEBUG);
        async.isLoggable(BuildConfig.DEBUG);
        async.setReconnectOnClose(false);
        instance = new Chat();
        gson = new GsonBuilder().setPrettyPrinting().create();
        parser = new JsonParser();
        instance.setContext(context);
        listenerManager = new ChatListenerManager();
        threadCallbacks = new HashMap<>();
        leaveThreadCallbacks = new HashMap<>();
        mSecurePrefs = new SecurePreferences(context, "", "chat_prefs.xml");
        // SecurePreferences.setLoggingEnabled(true);
        runDatabase(context);
        sendingQList = new HashMap();
        uploadingQList = new HashMap();
        waitQList = new HashMap<>();
        hashTagCallBacks = new HashMap<>();
        messageCallbacks = new HashMap<>();
        handlerSend = new HashMap<>();
        gson = new GsonBuilder().create();
        Sentry.setExtra("chat-sdk-version-name", BuildConfig.VERSION_NAME);
        Sentry.setExtra("chat-sdk-version-code", String.valueOf(BuildConfig.VERSION_CODE));
        Sentry.setExtra("chat-sdk-build-type", BuildConfig.BUILD_TYPE);
        Sentry.setExtra("chat-sdk-flavor", BuildConfig.FLAVOR);
        dataSource = new ChatDataSource(new MemoryDataSource(), new CacheDataSource(instance.messageDatabaseHelper));
    }
    return instance;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) HashMap(java.util.HashMap) CacheDataSource(com.fanap.podchat.repository.CacheDataSource) SecurePreferences(com.securepreferences.SecurePreferences) MemoryDataSource(com.fanap.podchat.repository.MemoryDataSource) ChatDataSource(com.fanap.podchat.repository.ChatDataSource) JsonParser(com.google.gson.JsonParser)

Aggregations

SecurePreferences (com.securepreferences.SecurePreferences)5 SharedPreferences (android.content.SharedPreferences)1 CacheDataSource (com.fanap.podchat.repository.CacheDataSource)1 ChatDataSource (com.fanap.podchat.repository.ChatDataSource)1 MemoryDataSource (com.fanap.podchat.repository.MemoryDataSource)1 FirebaseApp (com.google.firebase.FirebaseApp)1 FirebaseOptions (com.google.firebase.FirebaseOptions)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonParser (com.google.gson.JsonParser)1 HashMap (java.util.HashMap)1