From 5b0a3c465511c9f2d05ec7b76510c5fa4024b787 Mon Sep 17 00:00:00 2001 From: jacques Date: Wed, 17 Mar 2021 13:35:57 +0100 Subject: [PATCH] Add new Pref, DATABASE_VERSION used to update or not the database. --- .../net/foucry/pilldroid/PrefManager.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/PrefManager.java b/app/src/main/java/net/foucry/pilldroid/PrefManager.java index 637d4d1..cbd6736 100644 --- a/app/src/main/java/net/foucry/pilldroid/PrefManager.java +++ b/app/src/main/java/net/foucry/pilldroid/PrefManager.java @@ -10,29 +10,35 @@ import android.content.SharedPreferences; public class PrefManager { SharedPreferences pref; SharedPreferences.Editor editor; - Context _context; // shared pref mode int PRIVATE_MODE = 0; // Shared preferences file name - private static final String PREF_NAME = "androidhive-welcome"; - + private static final String PREF_NAME = "Pildroid-Prefs"; private static final String IS_FIRST_TIME_LAUNCH = "IsFirstTimeLaunch"; + private static final String DATABASE_VERSION = "DatabaseVersion"; public PrefManager(Context context) { - this._context = context; - pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE); - editor = pref.edit(); + pref = context.getSharedPreferences(PREF_NAME, PRIVATE_MODE); } public void setFirstTimeLaunch(boolean isFirstTime) { + editor = pref.edit(); editor.putBoolean(IS_FIRST_TIME_LAUNCH, isFirstTime); - editor.commit(); + editor.apply(); + } + + public void setDatabaseVersion(int version) { + editor = pref.edit(); + editor.putInt(DATABASE_VERSION, version); + editor.apply(); } public boolean isFirstTimeLaunch() { return pref.getBoolean(IS_FIRST_TIME_LAUNCH, true); } - + public int getDatabaseVersion() { + return pref.getInt(DATABASE_VERSION, 0); + } }