Java Code Examples for com.gianlu.commonutils.preferences.CommonPK

The following examples show how to use com.gianlu.commonutils.preferences.CommonPK. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: CommonUtils   Source File: AnalyticsPreferenceDialog.java    License: Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dialog_analytics_preference, container, false);

    SwitchMaterial tracking = layout.findViewById(R.id.analyticsPrefsDialog_tracking);
    tracking.setChecked(Prefs.getBoolean(CommonPK.TRACKING_ENABLED, true));
    tracking.setOnCheckedChangeListener((buttonView, isChecked) -> Prefs.putBoolean(CommonPK.TRACKING_ENABLED, isChecked));

    SwitchMaterial crashReport = layout.findViewById(R.id.analyticsPrefsDialog_crashReport);
    crashReport.setChecked(Prefs.getBoolean(CommonPK.CRASH_REPORT_ENABLED, true));
    crashReport.setOnCheckedChangeListener((buttonView, isChecked) -> Prefs.putBoolean(CommonPK.CRASH_REPORT_ENABLED, isChecked));

    Button ok = layout.findViewById(R.id.analyticsPrefsDialog_ok);
    ok.setOnClickListener(v -> dismissAllowingStateLoss());

    return layout;
}
 
Example 2
Source Project: CommonUtils   Source File: AnalyticsApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@CallSuper
public void onCreate() {
    super.onCreate();

    String uuid = Prefs.getString(CommonPK.ANALYTICS_USER_ID, null);
    if (uuid == null) {
        uuid = UUID.randomUUID().toString();
        Prefs.putString(CommonPK.ANALYTICS_USER_ID, uuid);
    }

    if (FossUtils.hasFirebaseCrashlytics()) {
        if (Prefs.getBoolean(CommonPK.CRASH_REPORT_ENABLED)) {
            FirebaseCrashlytics.getInstance().setUserId(uuid);
            CRASHLYTICS_ENABLED = true;
        } else {
            CRASHLYTICS_ENABLED = false;
        }
    } else {
        Prefs.putBoolean(CommonPK.CRASH_REPORT_ENABLED, false);
    }

    if (FossUtils.hasFirebaseAnalytics()) {
        ANALYTICS = FirebaseAnalytics.getInstance(this);
        if (Prefs.getBoolean(CommonPK.TRACKING_ENABLED)) {
            ANALYTICS.setUserId(uuid);
            ANALYTICS.setAnalyticsCollectionEnabled(true);
        } else {
            ANALYTICS.setAnalyticsCollectionEnabled(false);
            ANALYTICS = null;
        }
    } else {
        Prefs.putBoolean(CommonPK.TRACKING_ENABLED, false);
    }
}
 
Example 3
Source Project: CommonUtils   Source File: AnalyticsApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@CallSuper
public void onCreate() {
    super.onCreate();

    Prefs.putBoolean(CommonPK.CRASH_REPORT_ENABLED, false);
    Prefs.putBoolean(CommonPK.TRACKING_ENABLED, false);
}
 
Example 4
Source Project: CommonUtils   Source File: TutorialManager.java    License: Apache License 2.0 4 votes vote down vote up
public static void restartTutorial() {
    Prefs.remove(CommonPK.TUTORIAL_DISCOVERIES);
}
 
Example 5
Source Project: CommonUtils   Source File: TutorialManager.java    License: Apache License 2.0 4 votes vote down vote up
private boolean shouldShowFor(@NonNull BaseTutorial tutorial) {
    return !Prefs.setContains(CommonPK.TUTORIAL_DISCOVERIES, tutorial.discovery.name());
}
 
Example 6
Source Project: CommonUtils   Source File: TutorialManager.java    License: Apache License 2.0 4 votes vote down vote up
private void setShown(@NonNull BaseTutorial tutorial) {
    Prefs.addToSet(CommonPK.TUTORIAL_DISCOVERIES, tutorial.discovery.name());
}
 
Example 7
Source Project: CommonUtils   Source File: NightlyActivity.java    License: Apache License 2.0 4 votes vote down vote up
public final void applyNight() {
    getDelegate().setLocalNightMode(Prefs.getBoolean(CommonPK.NIGHT_MODE, false) ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_UNSPECIFIED);
}