Эх сурвалжийг харах

move preference access to manager class

AndyScherzinger 6 жил өмнө
parent
commit
f4438afc03

+ 5 - 8
src/main/java/com/owncloud/android/authentication/PassCodeManager.java

@@ -22,13 +22,12 @@ package com.owncloud.android.authentication;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
-import android.content.SharedPreferences;
 import android.os.Build;
 import android.os.PowerManager;
-import android.preference.PreferenceManager;
 import android.view.WindowManager;
 
 import com.owncloud.android.MainApp;
+import com.owncloud.android.db.PreferenceManager;
 import com.owncloud.android.ui.activity.PassCodeActivity;
 import com.owncloud.android.ui.activity.Preferences;
 import com.owncloud.android.ui.activity.RequestCredentialsActivity;
@@ -117,8 +116,7 @@ public class PassCodeManager {
     }
 
     private boolean passCodeIsEnabled() {
-        SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(MainApp.getAppContext());
-        return appPrefs.getString(Preferences.PREFERENCE_LOCK, "").equals(Preferences.LOCK_PASSCODE);
+        return PreferenceManager.getLockPreference(MainApp.getAppContext()).equals(Preferences.LOCK_PASSCODE);
     }
 
     private boolean deviceCredentialsShouldBeRequested(Activity activity) {
@@ -127,10 +125,9 @@ public class PassCodeManager {
     }
 
     private boolean deviceCredentialsAreEnabled(Activity activity) {
-        SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
-        return appPrefs.getString(Preferences.PREFERENCE_LOCK, "").equals(Preferences.LOCK_DEVICE_CREDENTIALS) ||
-                Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
-                        (appPrefs.getBoolean(Preferences.PREFERENCE_USE_FINGERPRINT, false)
+        return PreferenceManager.getLockPreference(MainApp.getAppContext()).equals(Preferences.LOCK_DEVICE_CREDENTIALS)
+                || Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
+                        (PreferenceManager.isUseFingerprint(MainApp.getAppContext())
                                 && DeviceCredentialUtils.areCredentialsAvailable(activity));
     }
 }

+ 21 - 0
src/main/java/com/owncloud/android/db/PreferenceManager.java

@@ -28,6 +28,7 @@ import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.ui.activity.ComponentsGetter;
+import com.owncloud.android.ui.activity.Preferences;
 import com.owncloud.android.utils.FileSortOrder;
 
 import static com.owncloud.android.ui.fragment.OCFileListFragment.FOLDER_LAYOUT_LIST;
@@ -181,6 +182,26 @@ public abstract class PreferenceManager {
         saveStringPreference(context, AUTO_PREF__LAST_UPLOAD_PATH, path);
     }
 
+    /**
+     * Gets the lock preference configured by the user.
+     *
+     * @param context Caller {@link Context}, used to access to shared preferences manager.
+     * @return lock     lock preference value.
+     */
+    public static String getLockPreference(Context context) {
+        return getDefaultSharedPreferences(context).getString(Preferences.PREFERENCE_LOCK, "");
+    }
+
+    /**
+     * Gets the lock via fingerprint preference configured by the user.
+     *
+     * @param context Caller {@link Context}, used to access to shared preferences manager.
+     * @return useFingerprint     is lock via fingerprint preference.
+     */
+    public static boolean isUseFingerprint(Context context) {
+        return getDefaultSharedPreferences(context).getBoolean(Preferences.PREFERENCE_USE_FINGERPRINT, false);
+    }
+
     /**
      * Get preferred folder display type.
      *