Move last seen version preference to AppPreferences interface

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
Chris Narkiewicz 2019-03-06 22:26:22 +00:00
parent 62534afba7
commit f5b356cdf6
No known key found for this signature in database
GPG key ID: 98BF5BA2F3BB4D28
5 changed files with 46 additions and 34 deletions

View file

@ -143,5 +143,19 @@ public interface AppPreferences {
long getLockTimestamp();
void setLockTimestamp(long timestamp);
/**
* Gets the last seen version code right before updating.
*
* @return grid columns grid columns
*/
int getLastSeenVersionCode();
/**
* Saves the version code as the last seen version code.
*
* @param versionCode the app's version code
*/
void setLastSeenVersionCode(int versionCode);
void removeLegacyPreferences();
}

View file

@ -450,24 +450,14 @@ public final class PreferenceManager implements AppPreferences {
preferences.edit().putFloat(AUTO_PREF__GRID_COLUMNS, gridColumns).apply();
}
/**
* Gets the last seen version code right before updating.
*
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @return grid columns grid columns
*/
public static int getLastSeenVersionCode(Context context) {
return getDefaultSharedPreferences(context).getInt(AUTO_PREF__LAST_SEEN_VERSION_CODE, 0);
@Override
public int getLastSeenVersionCode() {
return preferences.getInt(AUTO_PREF__LAST_SEEN_VERSION_CODE, 0);
}
/**
* Saves the version code as the last seen version code.
*
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @param versionCode the app's version code
*/
public static void setLastSeenVersionCode(Context context, int versionCode) {
saveIntPreference(context, AUTO_PREF__LAST_SEEN_VERSION_CODE, versionCode);
@Override
public void setLastSeenVersionCode(int versionCode) {
preferences.edit().putInt(AUTO_PREF__LAST_SEEN_VERSION_CODE, versionCode).apply();
}
public long getLockTimestamp() {

View file

@ -113,7 +113,8 @@ public class MainApp extends MultiDexApplication {
private static boolean mOnlyOnDevice;
private SharedPreferences appPrefs;
private SharedPreferences sharedPreferences;
private AppPreferences preferences;
@SuppressWarnings("unused")
private boolean mBound;
@ -128,11 +129,11 @@ public class MainApp extends MultiDexApplication {
new SecurityUtils();
DisplayUtils.useCompatVectorIfNeeded();
appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
fixStoragePath();
MainApp.storagePath = appPrefs.getString(SettingsActivity.PreferenceKeys.STORAGE_PATH,
MainApp.storagePath = sharedPreferences.getString(SettingsActivity.PreferenceKeys.STORAGE_PATH,
getApplicationContext().getFilesDir().getAbsolutePath());
boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
@ -243,22 +244,22 @@ public class MainApp extends MultiDexApplication {
if (!PreferenceManager.getStoragePathFix(this)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
StoragePoint[] storagePoints = DataStorageProvider.getInstance().getAvailableStoragePoints();
String storagePath = appPrefs.getString(SettingsActivity.PreferenceKeys.STORAGE_PATH, "");
String storagePath = sharedPreferences.getString(SettingsActivity.PreferenceKeys.STORAGE_PATH, "");
if (TextUtils.isEmpty(storagePath)) {
if (PreferenceManager.getLastSeenVersionCode(this) != 0) {
if (preferences.getLastSeenVersionCode() != 0) {
// We already used the app, but no storage is set - fix that!
appPrefs.edit().putString(SettingsActivity.PreferenceKeys.STORAGE_PATH,
sharedPreferences.edit().putString(SettingsActivity.PreferenceKeys.STORAGE_PATH,
Environment.getExternalStorageDirectory().getAbsolutePath()).commit();
appPrefs.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
sharedPreferences.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
} else {
// find internal storage path that's indexable
boolean set = false;
for (StoragePoint storagePoint : storagePoints) {
if (storagePoint.getStorageType().equals(StoragePoint.StorageType.INTERNAL) &&
storagePoint.getPrivacyType().equals(StoragePoint.PrivacyType.PUBLIC)) {
appPrefs.edit().putString(SettingsActivity.PreferenceKeys.STORAGE_PATH,
sharedPreferences.edit().putString(SettingsActivity.PreferenceKeys.STORAGE_PATH,
storagePoint.getPath()).commit();
appPrefs.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
sharedPreferences.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
set = true;
break;
}
@ -267,9 +268,9 @@ public class MainApp extends MultiDexApplication {
if (!set) {
for (StoragePoint storagePoint : storagePoints) {
if (storagePoint.getPrivacyType().equals(StoragePoint.PrivacyType.PUBLIC)) {
appPrefs.edit().putString(SettingsActivity.PreferenceKeys.STORAGE_PATH,
sharedPreferences.edit().putString(SettingsActivity.PreferenceKeys.STORAGE_PATH,
storagePoint.getPath()).commit();
appPrefs.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
sharedPreferences.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
set = true;
break;
}
@ -279,15 +280,15 @@ public class MainApp extends MultiDexApplication {
}
PreferenceManager.setStoragePathFix(this, true);
} else {
appPrefs.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
sharedPreferences.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
PreferenceManager.setStoragePathFix(this, true);
}
} else {
if (TextUtils.isEmpty(storagePath)) {
appPrefs.edit().putString(SettingsActivity.PreferenceKeys.STORAGE_PATH,
sharedPreferences.edit().putString(SettingsActivity.PreferenceKeys.STORAGE_PATH,
Environment.getExternalStorageDirectory().getAbsolutePath()).commit();
}
appPrefs.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
sharedPreferences.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
PreferenceManager.setStoragePathFix(this, true);
}
}

View file

@ -36,6 +36,7 @@ import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.nextcloud.client.preferences.AppPreferences;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
@ -58,11 +59,13 @@ public class FirstRunActivity extends BaseActivity implements ViewPager.OnPageCh
public static final int FIRST_RUN_RESULT_CODE = 199;
private ProgressIndicator progressIndicator;
private AppPreferences preferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first_run_activity);
preferences = PreferenceManager.fromContext(this);
boolean isProviderOrOwnInstallationVisible = getResources().getBoolean(R.bool.show_provider_or_own_installation);
@ -168,7 +171,7 @@ public class FirstRunActivity extends BaseActivity implements ViewPager.OnPageCh
}
private void onFinish() {
PreferenceManager.setLastSeenVersionCode(this, MainApp.getVersionCode());
preferences.setLastSeenVersionCode(MainApp.getVersionCode());
}
@Override

View file

@ -31,6 +31,7 @@ import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import com.nextcloud.client.preferences.AppPreferences;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
@ -53,11 +54,13 @@ public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPa
private Button mSkipButton;
private ProgressIndicator mProgress;
private ViewPager mPager;
private AppPreferences preferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.whats_new_activity);
preferences = PreferenceManager.fromContext(this);
int fontColor = getResources().getColor(R.color.login_text_color);
@ -136,7 +139,7 @@ public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPa
}
private void onFinish() {
PreferenceManager.setLastSeenVersionCode(this, MainApp.getVersionCode());
preferences.setLastSeenVersionCode(MainApp.getVersionCode());
}
public static void runIfNeeded(Context context) {
@ -173,11 +176,12 @@ public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPa
return AccountUtils.getCurrentOwnCloudAccount(context) == null;
}
static private FeatureItem[] getWhatsNew(Context context) {
private static FeatureItem[] getWhatsNew(Context context) {
int itemVersionCode = 30030099;
AppPreferences preferences = PreferenceManager.fromContext(context);
if (!isFirstRun(context) && MainApp.getVersionCode() >= itemVersionCode
&& PreferenceManager.getLastSeenVersionCode(context) < itemVersionCode) {
&& preferences.getLastSeenVersionCode() < itemVersionCode) {
return new FeatureItem[]{new FeatureItem(R.drawable.whats_new_device_credentials,
R.string.whats_new_device_credentials_title, R.string.whats_new_device_credentials_content,
false, false)};