mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 06:37:30 +00:00
Set new uri path to a different PreferenceKey to maintain ability to downgrade.
This commit is contained in:
parent
7e3edf639d
commit
9ea7c2c3af
@ -30,8 +30,8 @@ import awais.instagrabber.utils.Utils;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static awais.instagrabber.activities.DirectorySelectActivity.SELECT_DIR_REQUEST_CODE;
|
||||
import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_BARINSTA_DIR_URI;
|
||||
import static awais.instagrabber.utils.Constants.DOWNLOAD_USER_FOLDER;
|
||||
import static awais.instagrabber.utils.Constants.FOLDER_PATH;
|
||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||
|
||||
public class DownloadsPreferencesFragment extends BasePreferencesFragment {
|
||||
@ -57,11 +57,11 @@ public class DownloadsPreferencesFragment extends BasePreferencesFragment {
|
||||
|
||||
private Preference getSaveToCustomFolderPreference(@NonNull final Context context) {
|
||||
final Preference preference = new Preference(context);
|
||||
preference.setKey(FOLDER_PATH);
|
||||
preference.setKey(PREF_BARINSTA_DIR_URI);
|
||||
preference.setIconSpaceReserved(false);
|
||||
preference.setTitle(R.string.barinsta_folder);
|
||||
preference.setSummaryProvider(p -> {
|
||||
final String currentValue = settingsHelper.getString(FOLDER_PATH);
|
||||
final String currentValue = settingsHelper.getString(PREF_BARINSTA_DIR_URI);
|
||||
if (TextUtils.isEmpty(currentValue)) return "";
|
||||
String path;
|
||||
try {
|
||||
|
@ -7,4 +7,5 @@ public final class PreferenceKeys {
|
||||
public static final String PREF_ENABLE_DM_AUTO_REFRESH_FREQ_NUMBER = "enable_dm_auto_refresh_freq_number";
|
||||
public static final String PREF_ENABLE_SENTRY = "enable_sentry";
|
||||
public static final String PREF_TAB_ORDER = "tab_order";
|
||||
public static final String PREF_BARINSTA_DIR_URI = "barinsta_dir_uri";
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ import awais.instagrabber.repositories.responses.User;
|
||||
import awais.instagrabber.repositories.responses.VideoVersion;
|
||||
import awais.instagrabber.workers.DownloadWorker;
|
||||
|
||||
import static awais.instagrabber.utils.Constants.FOLDER_PATH;
|
||||
import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_BARINSTA_DIR_URI;
|
||||
|
||||
public final class DownloadUtils {
|
||||
private static final String TAG = DownloadUtils.class.getSimpleName();
|
||||
@ -59,28 +59,15 @@ public final class DownloadUtils {
|
||||
private static DocumentFile root;
|
||||
|
||||
public static void init(@NonNull final Context context) throws ReselectDocumentTreeException {
|
||||
// if (DOWNLOADS_DIR_FILE == null) {
|
||||
// final Uri uri = Utils.getSafUris(context, new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DOWNLOADS))[0];
|
||||
// DOWNLOADS_DIR_FILE = DocumentFile.fromTreeUri(context, uri);
|
||||
// }
|
||||
// if (!Utils.settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
|
||||
// root = DOWNLOADS_DIR_FILE; // DocumentFile.fromFile(DOWNLOADS_DIR_FILE);
|
||||
// return;
|
||||
// }
|
||||
final String customPath = Utils.settingsHelper.getString(FOLDER_PATH);
|
||||
if (TextUtils.isEmpty(customPath)) {
|
||||
final String barinstaDirUri = Utils.settingsHelper.getString(PREF_BARINSTA_DIR_URI);
|
||||
if (TextUtils.isEmpty(barinstaDirUri)) {
|
||||
throw new ReselectDocumentTreeException("folder path is null or empty");
|
||||
// root = DOWNLOADS_DIR_FILE; // DocumentFile.fromFile(DOWNLOADS_DIR_FILE);
|
||||
// return;
|
||||
}
|
||||
if (!customPath.startsWith("content")) {
|
||||
// if (customPath.equals(DOWNLOADS_DIR_FILE.getAbsolutePath())) {
|
||||
// throw new ReselectDocumentTreeException();
|
||||
// }
|
||||
if (!barinstaDirUri.startsWith("content")) {
|
||||
// reselect the folder in selector view
|
||||
throw new ReselectDocumentTreeException(Uri.parse(customPath));
|
||||
throw new ReselectDocumentTreeException(Uri.parse(barinstaDirUri));
|
||||
}
|
||||
final Uri uri = Uri.parse(customPath);
|
||||
final Uri uri = Uri.parse(barinstaDirUri);
|
||||
final List<UriPermission> existingPermissions = context.getContentResolver().getPersistedUriPermissions();
|
||||
if (existingPermissions.isEmpty()) {
|
||||
// reselect the folder in selector view
|
||||
@ -96,10 +83,6 @@ public final class DownloadUtils {
|
||||
root = null;
|
||||
throw new ReselectDocumentTreeException(uri);
|
||||
}
|
||||
// Log.d(TAG, "init: " + root);
|
||||
// final File parent = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
||||
// final DocumentFile documentFile = DocumentFile.fromFile(parent);
|
||||
// Log.d(TAG, "init: " + documentFile);
|
||||
}
|
||||
|
||||
public static void destroy() {
|
||||
|
@ -11,6 +11,7 @@ import androidx.appcompat.app.AppCompatDelegate;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_BARINSTA_DIR_URI;
|
||||
import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH;
|
||||
import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH_FREQ_NUMBER;
|
||||
import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH_FREQ_UNIT;
|
||||
@ -158,7 +159,7 @@ public final class SettingsHelper {
|
||||
CUSTOM_DATE_TIME_FORMAT, DEVICE_UUID, SKIPPED_VERSION, DEFAULT_TAB, PREF_DARK_THEME, PREF_LIGHT_THEME,
|
||||
PREF_POSTS_LAYOUT, PREF_PROFILE_POSTS_LAYOUT, PREF_TOPIC_POSTS_LAYOUT, PREF_HASHTAG_POSTS_LAYOUT,
|
||||
PREF_LOCATION_POSTS_LAYOUT, PREF_LIKED_POSTS_LAYOUT, PREF_TAGGED_POSTS_LAYOUT, PREF_SAVED_POSTS_LAYOUT,
|
||||
STORY_SORT, PREF_EMOJI_VARIANTS, PREF_REACTIONS, PREF_ENABLE_DM_AUTO_REFRESH_FREQ_UNIT, PREF_TAB_ORDER})
|
||||
STORY_SORT, PREF_EMOJI_VARIANTS, PREF_REACTIONS, PREF_ENABLE_DM_AUTO_REFRESH_FREQ_UNIT, PREF_TAB_ORDER, PREF_BARINSTA_DIR_URI})
|
||||
public @interface StringSettings {}
|
||||
|
||||
@StringDef({DOWNLOAD_USER_FOLDER, DOWNLOAD_PREPEND_USER_NAME, FOLDER_SAVE_TO, AUTOPLAY_VIDEOS, SHOW_QUICK_ACCESS_DIALOG, MUTED_VIDEOS,
|
||||
|
@ -67,7 +67,7 @@ import awais.instagrabber.models.PostsLayoutPreferences;
|
||||
import awais.instagrabber.models.Tab;
|
||||
import awais.instagrabber.models.enums.FavoriteType;
|
||||
|
||||
import static awais.instagrabber.utils.Constants.FOLDER_PATH;
|
||||
import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_BARINSTA_DIR_URI;
|
||||
|
||||
public final class Utils {
|
||||
private static final String TAG = "Utils";
|
||||
@ -564,7 +564,7 @@ public final class Utils {
|
||||
if (dirUri == null) return;
|
||||
final int takeFlags = intent.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
context.getContentResolver().takePersistableUriPermission(dirUri, takeFlags);
|
||||
settingsHelper.putString(FOLDER_PATH, dirUri.toString());
|
||||
settingsHelper.putString(PREF_BARINSTA_DIR_URI, dirUri.toString());
|
||||
// re-init DownloadUtils
|
||||
DownloadUtils.init(context);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import java.util.List;
|
||||
import awais.instagrabber.R;
|
||||
import awais.instagrabber.utils.Constants;
|
||||
import awais.instagrabber.utils.DownloadUtils;
|
||||
import awais.instagrabber.utils.TextUtils;
|
||||
import awais.instagrabber.utils.Utils;
|
||||
|
||||
public class DirectorySelectActivityViewModel extends AndroidViewModel {
|
||||
@ -66,14 +67,15 @@ public class DirectorySelectActivityViewModel extends AndroidViewModel {
|
||||
|
||||
private void setMessage(@Nullable final Uri initialUri) {
|
||||
if (initialUri == null) {
|
||||
// default message
|
||||
message.postValue(getApplication().getString(R.string.dir_select_default_message));
|
||||
prevUri.postValue(null);
|
||||
return;
|
||||
}
|
||||
if (!initialUri.toString().startsWith("content")) {
|
||||
final String prevVersionFolderPath = Utils.settingsHelper.getString(Constants.FOLDER_PATH);
|
||||
if (TextUtils.isEmpty(prevVersionFolderPath)) {
|
||||
// default message
|
||||
message.postValue(getApplication().getString(R.string.dir_select_default_message));
|
||||
prevUri.postValue(null);
|
||||
return;
|
||||
}
|
||||
message.postValue(getApplication().getString(R.string.dir_select_reselect_message));
|
||||
prevUri.postValue(initialUri.toString());
|
||||
prevUri.postValue(prevVersionFolderPath);
|
||||
return;
|
||||
}
|
||||
final List<UriPermission> existingPermissions = getApplication().getContentResolver().getPersistedUriPermissions();
|
||||
|
Loading…
Reference in New Issue
Block a user