Skip to content

Commit

Permalink
Add setting migration to promote using SAF
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Jan 14, 2021
1 parent 09312a9 commit b82ddb2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import androidx.preference.SwitchPreferenceCompat;

import com.nononsenseapps.filepicker.Utils;

Expand Down Expand Up @@ -58,7 +59,7 @@ public void onCreate(@Nullable final Bundle savedInstanceState) {
prefPathAudio = findPreference(downloadPathAudioPreference);
prefStorageAsk = findPreference(downloadStorageAsk);

final SwitchPreference prefUseSaf = findPreference(storageUseSafPreference);
final SwitchPreferenceCompat prefUseSaf = findPreference(storageUseSafPreference);
prefUseSaf.setDefaultValue(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
prefUseSaf.setChecked(NewPipeSettings.useStorageAccessFramework(ctx));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
Expand Down Expand Up @@ -90,7 +91,7 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
}

@Override
public void onAttach(final Context context) {
public void onAttach(@NonNull final Context context) {
super.onAttach(context);
ctx = context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.util.Log;

import androidx.preference.PreferenceManager;
Expand All @@ -18,7 +19,7 @@ public final class SettingMigrations {
/**
* Version number for preferences. Must be incremented every time a migration is necessary.
*/
public static final int VERSION = 2;
public static final int VERSION = 3;
private static SharedPreferences sp;

public static final Migration MIGRATION_0_1 = new Migration(0, 1) {
Expand Down Expand Up @@ -54,6 +55,20 @@ protected void migrate(final Context context) {
}
};

public static final Migration MIGRATION_2_3 = new Migration(2, 3) {
@Override
protected void migrate(final Context context) {
// Storage Access Framework implementation was improved in #3777, allowing the modern
// and standard way to access folders and files to be used consistently everywhere.
// We reset the setting to its default value, i.e. "use SAF", since now there are no
// more issues with SAF and users should use that one instead of the old
// NoNonsenseFilePicker. SAF does not work on KitKat and below, though, so the setting
// is set to false in that case.
sp.edit().putBoolean(context.getString(R.string.storage_use_saf),
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP).apply();
}
};

/**
* List of all implemented migrations.
* <p>
Expand All @@ -62,7 +77,8 @@ protected void migrate(final Context context) {
*/
private static final Migration[] SETTING_MIGRATIONS = {
MIGRATION_0_1,
MIGRATION_1_2
MIGRATION_1_2,
MIGRATION_2_3
};


Expand Down

0 comments on commit b82ddb2

Please sign in to comment.