From a83640f01a70eabc53691ccd269711f44fc4dfd1 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 20 Dec 2021 22:16:33 +0800 Subject: Fix NSFW download location option not working. Hide options in Data Saving Mode settings if Data Saving Mode is off. --- .../services/DownloadMediaService.java | 2 +- .../services/DownloadRedditVideoService.java | 2 +- .../settings/DataSavingModePreferenceFragment.java | 12 ++++++------ .../settings/DownloadLocationPreferenceFragment.java | 10 ++++++++-- .../utils/SharedPreferencesUtils.java | 4 ++-- app/src/main/res/values/strings.xml | 5 +++-- .../main/res/xml/download_location_preferences.xml | 20 ++++++++++++-------- 7 files changed, 33 insertions(+), 22 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java index d811ddf0..b27c6f09 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java @@ -465,7 +465,7 @@ public class DownloadMediaService extends Service { } private String getDownloadLocation(int mediaType, boolean isNsfw) { - if (isNsfw && mSharedPreferences.getBoolean(SharedPreferencesUtils.SEPARATE_NSFW_FOLDER, false)) { + if (isNsfw && mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_NSFW_MEDIA_IN_DIFFERENT_FOLDER, false)) { return mSharedPreferences.getString(SharedPreferencesUtils.NSFW_DOWNLOAD_LOCATION, ""); } switch (mediaType) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java index 5a7dcef9..eebbf8ea 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java @@ -144,7 +144,7 @@ public class DownloadRedditVideoService extends Service { if (videoResponse.isSuccessful() && videoResponse.body() != null) { String externalCacheDirectoryPath = externalCacheDirectory.getAbsolutePath() + "/"; String destinationFileDirectory; - if (isNsfw && sharedPreferences.getBoolean(SharedPreferencesUtils.SEPARATE_NSFW_FOLDER, false)) { + if (isNsfw && sharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_NSFW_MEDIA_IN_DIFFERENT_FOLDER, false)) { destinationFileDirectory = sharedPreferences.getString(SharedPreferencesUtils.NSFW_DOWNLOAD_LOCATION, ""); } else { destinationFileDirectory = sharedPreferences.getString(SharedPreferencesUtils.VIDEO_DOWNLOAD_LOCATION, ""); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java index 915438a6..045f356b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java @@ -28,27 +28,27 @@ public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat { if (dataSavingModeListPreference != null) { if (dataSavingModeListPreference.getValue().equals("0")) { if (onlyDisablePreviewInVideoAndGifPostsPreference != null) { - onlyDisablePreviewInVideoAndGifPostsPreference.setEnabled(false); + onlyDisablePreviewInVideoAndGifPostsPreference.setVisible(false); } if (disableImagePreviewPreference != null) { - disableImagePreviewPreference.setEnabled(false); + disableImagePreviewPreference.setVisible(false); } } dataSavingModeListPreference.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeDataSavingModeEvent((String) newValue)); if (newValue.equals("0")) { if (onlyDisablePreviewInVideoAndGifPostsPreference != null) { - onlyDisablePreviewInVideoAndGifPostsPreference.setEnabled(false); + onlyDisablePreviewInVideoAndGifPostsPreference.setVisible(false); } if (disableImagePreviewPreference != null) { - disableImagePreviewPreference.setEnabled(false); + disableImagePreviewPreference.setVisible(false); } } else { if (onlyDisablePreviewInVideoAndGifPostsPreference != null) { - onlyDisablePreviewInVideoAndGifPostsPreference.setEnabled(true); + onlyDisablePreviewInVideoAndGifPostsPreference.setVisible(true); } if (disableImagePreviewPreference != null) { - disableImagePreviewPreference.setEnabled(true); + disableImagePreviewPreference.setVisible(true); } } return true; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DownloadLocationPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DownloadLocationPreferenceFragment.java index 331f7de6..6bfb459e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DownloadLocationPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DownloadLocationPreferenceFragment.java @@ -1,5 +1,7 @@ package ml.docilealligator.infinityforreddit.settings; +import static android.content.Intent.ACTION_OPEN_DOCUMENT_TREE; + import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -18,8 +20,6 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import static android.content.Intent.ACTION_OPEN_DOCUMENT_TREE; - public class DownloadLocationPreferenceFragment extends PreferenceFragmentCompat { private static final int IMAGE_DOWNLOAD_LOCATION_REQUEST_CODE = 10; private static final int GIF_DOWNLOAD_LOCATION_REQUEST_CODE = 11; @@ -122,6 +122,12 @@ public class DownloadLocationPreferenceFragment extends PreferenceFragmentCompat if (videoDownloadLocationPreference != null) { videoDownloadLocationPreference.setSummary(data.getDataString()); } + } else if (requestCode == NSFW_DOWNLOAD_LOCATION_REQUEST_CODE) { + activity.getContentResolver().takePersistableUriPermission(data.getData(), Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + sharedPreferences.edit().putString(SharedPreferencesUtils.NSFW_DOWNLOAD_LOCATION, data.getDataString()).apply(); + if (nsfwDownloadLocationPreference != null) { + nsfwDownloadLocationPreference.setSummary(data.getDataString()); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index 6ee508c5..296fc651 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -130,9 +130,9 @@ public class SharedPreferencesUtils { public static final String IMAGE_DOWNLOAD_LOCATION = "image_download_location"; public static final String GIF_DOWNLOAD_LOCATION = "gif_download_location"; public static final String VIDEO_DOWNLOAD_LOCATION = "video_download_location"; - public static final String NSFW_DOWNLOAD_LOCATION = "nsfw_download_location"; - public static final String SEPARATE_NSFW_FOLDER = "separate_nsfw_folder"; public static final String SEPARATE_FOLDER_FOR_EACH_SUBREDDIT = "separate_folder_for_each_subreddit"; + public static final String SAVE_NSFW_MEDIA_IN_DIFFERENT_FOLDER = "save_nsfw_media_in_different_folder"; + public static final String NSFW_DOWNLOAD_LOCATION = "nsfw_download_location"; public static final String VIBRATE_WHEN_ACTION_TRIGGERED = "vibrate_when_action_triggered"; public static final String DISABLE_SWIPING_BETWEEN_TABS = "disable_swiping_between_tabs"; public static final String ENABLE_SWIPE_ACTION = "enable_swipe_action"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6d795c87..093c6213 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -516,9 +516,10 @@ Image Download Location Gif Download Location Video Download Location - NSFW Download Location - Separate Folder for NSFW Posts Separate Folder for Each Subreddit + Save NSFW Media in Different Location + Does not separate folder for NSFW media from different subreddits even if Separate Folder for Each Subreddit is enabled. + NSFW Download Location Swipe Action Haptic Feedback Disable Swiping Between Tabs diff --git a/app/src/main/res/xml/download_location_preferences.xml b/app/src/main/res/xml/download_location_preferences.xml index 4e2c1f7a..3de56ef3 100644 --- a/app/src/main/res/xml/download_location_preferences.xml +++ b/app/src/main/res/xml/download_location_preferences.xml @@ -11,17 +11,21 @@ app:key="video_download_location" app:title="@string/settings_video_download_location_title" /> - - + app:key="separate_folder_for_each_subreddit" + app:title="@string/settings_separate_folder_for_each_subreddit" /> + + + app:key="save_nsfw_media_in_different_folder" + app:title="@string/settings_save_nsfw_media_in_different_folder_title" + app:summary="@string/settings_save_nsfw_media_in_different_folder_summary" /> + + \ No newline at end of file -- cgit v1.2.3