Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/data/PreferencesHolder.java
Show All 17 Lines | |||||
package it.reyboz.bustorino.data; | package it.reyboz.bustorino.data; | ||||
import android.content.Context; | import android.content.Context; | ||||
import android.content.SharedPreferences; | import android.content.SharedPreferences; | ||||
import it.reyboz.bustorino.R; | import it.reyboz.bustorino.R; | ||||
import static android.content.Context.MODE_PRIVATE; | import static android.content.Context.MODE_PRIVATE; | ||||
import androidx.preference.PreferenceManager; | |||||
/** | /** | ||||
* Static class for commonly used SharedPreference operations | * Static class for commonly used SharedPreference operations | ||||
*/ | */ | ||||
public abstract class PreferencesHolder { | public abstract class PreferencesHolder { | ||||
public static final String PREF_GTFS_DB_VERSION = "gtfs_db_version"; | public static final String PREF_GTFS_DB_VERSION = "gtfs_db_version"; | ||||
public static SharedPreferences getMainSharedPreferences(Context context){ | public static SharedPreferences getMainSharedPreferences(Context context){ | ||||
return context.getSharedPreferences(context.getString(R.string.mainSharedPreferences), MODE_PRIVATE); | return context.getSharedPreferences(context.getString(R.string.mainSharedPreferences), MODE_PRIVATE); | ||||
} | } | ||||
public static SharedPreferences getAppPreferences(Context con){ | |||||
return PreferenceManager.getDefaultSharedPreferences(con); | |||||
} | |||||
public static int getGtfsDBVersion(SharedPreferences pref){ | public static int getGtfsDBVersion(SharedPreferences pref){ | ||||
return pref.getInt(PREF_GTFS_DB_VERSION,-1); | return pref.getInt(PREF_GTFS_DB_VERSION,-1); | ||||
} | } | ||||
public static void setGtfsDBVersion(SharedPreferences pref,int version){ | public static void setGtfsDBVersion(SharedPreferences pref,int version){ | ||||
SharedPreferences.Editor ed = pref.edit(); | SharedPreferences.Editor ed = pref.edit(); | ||||
ed.putInt(PREF_GTFS_DB_VERSION,version); | ed.putInt(PREF_GTFS_DB_VERSION,version); | ||||
ed.apply(); | ed.apply(); | ||||
} | } | ||||
} | } |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register