Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sensible download name #1256

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
public static final String EXTRA_IMAGE_URL_KEY = "EIUK";
public static final String EXTRA_GIF_URL_KEY = "EGUK";
public static final String EXTRA_FILE_NAME_KEY = "EFNK";
public static final String EXTRA_SENSIBLE_FILE_NAME_KEY = "ESFNK";
public static final String EXTRA_SUBREDDIT_OR_USERNAME_KEY = "ESOUK";
public static final String EXTRA_POST_TITLE_KEY = "EPTK";
public static final String EXTRA_IS_NSFW = "EIN";
Expand Down Expand Up @@ -114,6 +115,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
private RequestManager glide;
private String mImageUrl;
private String mImageFileName;
private String mImageSensibleFileName;
private String mSubredditName;
private boolean isGif = true;
private boolean isNsfw;
Expand Down Expand Up @@ -172,6 +174,8 @@ protected void onCreate(Bundle savedInstanceState) {
mImageUrl = intent.getStringExtra(EXTRA_IMAGE_URL_KEY);
}
mImageFileName = intent.getStringExtra(EXTRA_FILE_NAME_KEY);
mImageSensibleFileName = intent.getStringExtra(EXTRA_SENSIBLE_FILE_NAME_KEY);

String postTitle = intent.getStringExtra(EXTRA_POST_TITLE_KEY);
mSubredditName = intent.getStringExtra(EXTRA_SUBREDDIT_OR_USERNAME_KEY);
isNsfw = intent.getBooleanExtra(EXTRA_IS_NSFW, false);
Expand Down Expand Up @@ -377,10 +381,12 @@ private void requestPermissionAndDownload() {
private void download() {
isDownloading = false;

boolean isSensibleFileName = mSharedPreferences.getBoolean(SharedPreferencesUtils.DOWNLOAD_WITH_SENSIBLE_FILE_NAME, false);

Intent intent = new Intent(this, DownloadMediaService.class);
intent.putExtra(DownloadMediaService.EXTRA_URL, mImageUrl);
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, isGif ? DownloadMediaService.EXTRA_MEDIA_TYPE_GIF : DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE);
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, mImageFileName);
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, isSensibleFileName ? mImageSensibleFileName : mImageFileName);
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, mSubredditName);
intent.putExtra(DownloadMediaService.EXTRA_IS_NSFW, isNsfw);
ContextCompat.startForegroundService(this, intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,8 @@ private void openMedia(Post post, int galleryItemIndex) {
intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, post.getUrl());
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
+ "-" + post.getId() + ".jpg");
intent.putExtra(ViewImageOrGifActivity.EXTRA_SENSIBLE_FILE_NAME_KEY, post.getSubredditName()
+ "-" + post.getTitle() + ".jpg");
intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,8 @@ class PostDetailImageAndGifAutoplayViewHolder extends PostDetailBaseViewHolder {
intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mPost.getUrl());
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditNamePrefixed().substring(2)
+ "-" + mPost.getId().substring(3) + ".jpg");
intent.putExtra(ViewImageOrGifActivity.EXTRA_SENSIBLE_FILE_NAME_KEY, mPost.getSubredditName()
+ "-" + mPost.getTitle() + ".jpg");
intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
mActivity.startActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,8 @@ private void openMedia(Post post, int galleryItemIndex) {
intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, post.getUrl());
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
+ "-" + post.getId() + ".jpg");
intent.putExtra(ViewImageOrGifActivity.EXTRA_SENSIBLE_FILE_NAME_KEY, post.getSubredditName()
+ "-" + post.getTitle() + ".jpg");
intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public class SharedPreferencesUtils {
public static final String GIF_DOWNLOAD_LOCATION = "gif_download_location";
public static final String VIDEO_DOWNLOAD_LOCATION = "video_download_location";
public static final String SEPARATE_FOLDER_FOR_EACH_SUBREDDIT = "separate_folder_for_each_subreddit";
public static final String DOWNLOAD_WITH_SENSIBLE_FILE_NAME = "download_with_sensible_file_name";
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";
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@
<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_separate_folder_for_each_subreddit">Separate Folder for Each Subreddit</string>
<string name="settings_download_with_sensible_file_name">Download with Sensible File Name</string>
<string name="settings_save_nsfw_media_in_different_folder_title">Save NSFW Media in Different Location</string>
<string name="settings_nsfw_download_location_title">NSFW Download Location</string>
<string name="settings_swipe_action_title">Swipe Action</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/download_location_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
app:key="separate_folder_for_each_subreddit"
app:title="@string/settings_separate_folder_for_each_subreddit" />

<ml.docilealligator.infinityforreddit.customviews.CustomFontSwitchPreference
app:defaultValue="false"
app:key="download_with_sensible_file_name"
app:title="@string/settings_download_with_sensible_file_name" />

<ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceCategory
app:title="@string/nsfw" />

Expand Down