Fix NSFW download location option not working. Hide options in Data Saving Mode settings if Data Saving Mode is off.

This commit is contained in:
Alex Ning 2021-12-20 22:16:33 +08:00
parent dc4fa2e6b8
commit a83640f01a
7 changed files with 34 additions and 23 deletions

View File

@ -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) {

View File

@ -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, "");

View File

@ -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;

View File

@ -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());
}
}
}
}

View File

@ -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";

View File

@ -516,9 +516,10 @@
<string name="settings_image_download_location_title">Image Download Location</string>
<string name="settings_gif_download_location_title">Gif Download Location</string>
<string name="settings_video_download_location_title">Video Download Location</string>
<string name="settings_nsfw_download_location_title">NSFW Download Location</string>
<string name="settings_nsfw_separate_folder">Separate Folder for NSFW Posts</string>
<string name="settings_separate_folder_for_each_subreddit">Separate Folder for Each Subreddit</string>
<string name="settings_save_nsfw_media_in_different_folder_title">Save NSFW Media in Different Location</string>
<string name="settings_save_nsfw_media_in_different_folder_summary">Does not separate folder for NSFW media from different subreddits even if Separate Folder for Each Subreddit is enabled.</string>
<string name="settings_nsfw_download_location_title">NSFW Download Location</string>
<string name="settings_swipe_action_title">Swipe Action</string>
<string name="settings_swipe_action_haptic_feedback_title">Haptic Feedback</string>
<string name="settings_disable_swiping_between_tabs_title">Disable Swiping Between Tabs</string>

View File

@ -11,17 +11,21 @@
app:key="video_download_location"
app:title="@string/settings_video_download_location_title" />
<Preference
app:key="nsfw_download_location"
app:title="@string/settings_nsfw_download_location_title" />
<SwitchPreference
app:defaultValue="false"
app:key="separate_nsfw_folder"
app:title="@string/settings_nsfw_separate_folder" />
<SwitchPreference
app:defaultValue="false"
app:key="separate_folder_for_each_subreddit"
app:title="@string/settings_separate_folder_for_each_subreddit" />
<PreferenceCategory
app:title="@string/nsfw" />
<SwitchPreference
app:defaultValue="false"
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" />
<Preference
app:key="nsfw_download_location"
app:title="@string/settings_nsfw_download_location_title" />
</PreferenceScreen>