diff --git a/src/main/java/com/nextcloud/client/preferences/AppPreferences.java b/src/main/java/com/nextcloud/client/preferences/AppPreferences.java index 19e714dae4..6bacc3437a 100644 --- a/src/main/java/com/nextcloud/client/preferences/AppPreferences.java +++ b/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(); } diff --git a/src/main/java/com/nextcloud/client/preferences/PreferenceManager.java b/src/main/java/com/nextcloud/client/preferences/PreferenceManager.java index ebc6d38cfc..406fad8da9 100644 --- a/src/main/java/com/nextcloud/client/preferences/PreferenceManager.java +++ b/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 diff --git a/src/main/java/com/owncloud/android/authentication/PassCodeManager.java b/src/main/java/com/owncloud/android/authentication/PassCodeManager.java index e508dadcf0..421586314c 100644 --- a/src/main/java/com/owncloud/android/authentication/PassCodeManager.java +++ b/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) { diff --git a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index b780cbc667..10984fd0df 100644 --- a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/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(); } }