mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-01-11 01:40:59 +00:00
Add setting migration to promote using SAF
This commit is contained in:
parent
7efe62ee80
commit
1e8b3826dc
@ -9,10 +9,11 @@ import android.os.Build;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreferenceCompat;
|
||||||
|
|
||||||
import com.nononsenseapps.filepicker.Utils;
|
import com.nononsenseapps.filepicker.Utils;
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ public class DownloadSettingsFragment extends BasePreferenceFragment {
|
|||||||
prefPathAudio = findPreference(downloadPathAudioPreference);
|
prefPathAudio = findPreference(downloadPathAudioPreference);
|
||||||
prefStorageAsk = findPreference(downloadStorageAsk);
|
prefStorageAsk = findPreference(downloadStorageAsk);
|
||||||
|
|
||||||
final SwitchPreference prefUseSaf = findPreference(storageUseSafPreference);
|
final SwitchPreferenceCompat prefUseSaf = findPreference(storageUseSafPreference);
|
||||||
prefUseSaf.setDefaultValue(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
|
prefUseSaf.setDefaultValue(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
|
||||||
prefUseSaf.setChecked(NewPipeSettings.useStorageAccessFramework(ctx));
|
prefUseSaf.setChecked(NewPipeSettings.useStorageAccessFramework(ctx));
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
||||||
@ -84,7 +85,7 @@ public class DownloadSettingsFragment extends BasePreferenceFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(final Context context) {
|
public void onAttach(@NonNull final Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
ctx = context;
|
ctx = context;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package org.schabi.newpipe.settings;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
@ -18,7 +19,7 @@ public final class SettingMigrations {
|
|||||||
/**
|
/**
|
||||||
* Version number for preferences. Must be incremented every time a migration is necessary.
|
* 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;
|
private static SharedPreferences sp;
|
||||||
|
|
||||||
public static final Migration MIGRATION_0_1 = new Migration(0, 1) {
|
public static final Migration MIGRATION_0_1 = new Migration(0, 1) {
|
||||||
@ -54,6 +55,20 @@ public final class SettingMigrations {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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 #5415, 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.
|
* List of all implemented migrations.
|
||||||
* <p>
|
* <p>
|
||||||
@ -62,7 +77,8 @@ public final class SettingMigrations {
|
|||||||
*/
|
*/
|
||||||
private static final Migration[] SETTING_MIGRATIONS = {
|
private static final Migration[] SETTING_MIGRATIONS = {
|
||||||
MIGRATION_0_1,
|
MIGRATION_0_1,
|
||||||
MIGRATION_1_2
|
MIGRATION_1_2,
|
||||||
|
MIGRATION_2_3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user