Browse Source

Merge pull request #3717 from nextcloud/ezaquarii/refactor-lock-timestamp-preference

Move lock timestamp pref to AppPreferences
Tobias Kaminsky 6 years ago
parent
commit
558fa2273a

+ 3 - 0
src/main/java/com/nextcloud/client/preferences/AppPreferences.java

@@ -109,5 +109,8 @@ public interface AppPreferences {
     float getGridColumns();
     void setGridColumns(float gridColumns);
 
+    long getLockTimestamp();
+    void setLockTimestamp(long timestamp);
+
     void removeLegacyPreferences();
 }

+ 4 - 4
src/main/java/com/nextcloud/client/preferences/PreferenceManager.java

@@ -489,12 +489,12 @@ public final class PreferenceManager implements AppPreferences {
         saveIntPreference(context, AUTO_PREF__LAST_SEEN_VERSION_CODE, versionCode);
     }
 
-    public static long getLockTimestamp(Context context) {
-        return getDefaultSharedPreferences(context).getLong(PREF__LOCK_TIMESTAMP, 0);
+    public long getLockTimestamp() {
+        return preferences.getLong(PREF__LOCK_TIMESTAMP, 0);
     }
 
-    public static void setLockTimestamp(Context context, long timestamp) {
-        saveLongPreference(context, PREF__LOCK_TIMESTAMP, timestamp);
+    public void setLockTimestamp(long timestamp) {
+        preferences.edit().putLong(PREF__LOCK_TIMESTAMP, timestamp).apply();
     }
 
     @Override

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

@@ -78,7 +78,7 @@ public final class PassCodeManager {
     }
 
     public void onActivityStarted(Activity activity) {
-        Long timestamp = PreferenceManager.getLockTimestamp(activity);
+        Long timestamp = PreferenceManager.fromContext(activity).getLockTimestamp();
         if (!exemptOfPasscodeActivities.contains(activity.getClass()) && passCodeShouldBeRequested(timestamp)) {
 
             Intent i = new Intent(MainApp.getAppContext(), PassCodeActivity.class);
@@ -110,7 +110,7 @@ public final class PassCodeManager {
     }
 
     private void setUnlockTimestamp(Activity activity) {
-        PreferenceManager.setLockTimestamp(activity, System.currentTimeMillis());
+        PreferenceManager.fromContext(activity).setLockTimestamp(System.currentTimeMillis());
     }
 
     private boolean passCodeShouldBeRequested(Long timestamp) {

+ 6 - 1
src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -54,6 +54,7 @@ import com.bumptech.glide.Glide;
 import com.bumptech.glide.request.animation.GlideAnimation;
 import com.bumptech.glide.request.target.SimpleTarget;
 import com.google.android.material.navigation.NavigationView;
+import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.client.preferences.PreferenceManager;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
@@ -204,6 +205,8 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
     private ExternalLinksProvider externalLinksProvider;
     private ArbitraryDataProvider arbitraryDataProvider;
 
+    private AppPreferences preferences;
+
     /**
      * Initializes the drawer, its content and highlights the menu item with the given id.
      * This method needs to be called after the content view has been set.
@@ -1150,6 +1153,8 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
+        preferences = PreferenceManager.fromContext(this);
+
         if (savedInstanceState != null) {
             mIsAccountChooserActive = savedInstanceState.getBoolean(KEY_IS_ACCOUNT_CHOOSER_ACTIVE, false);
             mCheckedMenuItem = savedInstanceState.getInt(KEY_CHECKED_MENU_ITEM, Menu.NONE);
@@ -1254,7 +1259,7 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
 
             if (result == RequestCredentialsActivity.KEY_CHECK_RESULT_CANCEL) {
                 Log_OC.d(TAG, "PassCodeManager cancelled");
-                PreferenceManager.setLockTimestamp(this, 0);
+                preferences.setLockTimestamp(0);
                 finish();
             }
         }