mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-15 04:37:12 +01:00
Added Setting for Separate NSFW Download Folder (#584)
Add an option to separate NSFW media downloads
This commit is contained in:
parent
21e7dad1b0
commit
34127032de
@ -83,6 +83,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
|
|||||||
public static final String EXTRA_FILE_NAME_KEY = "EFNK";
|
public static final String EXTRA_FILE_NAME_KEY = "EFNK";
|
||||||
public static final String EXTRA_SUBREDDIT_OR_USERNAME_KEY = "ESOUK";
|
public static final String EXTRA_SUBREDDIT_OR_USERNAME_KEY = "ESOUK";
|
||||||
public static final String EXTRA_POST_TITLE_KEY = "EPTK";
|
public static final String EXTRA_POST_TITLE_KEY = "EPTK";
|
||||||
|
public static final String EXTRA_IS_NSFW = "EIN";
|
||||||
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
|
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
|
||||||
@BindView(R.id.progress_bar_view_image_or_gif_activity)
|
@BindView(R.id.progress_bar_view_image_or_gif_activity)
|
||||||
ProgressBar mProgressBar;
|
ProgressBar mProgressBar;
|
||||||
@ -112,6 +113,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
|
|||||||
private String mImageFileName;
|
private String mImageFileName;
|
||||||
private String mSubredditName;
|
private String mSubredditName;
|
||||||
private boolean isGif = true;
|
private boolean isGif = true;
|
||||||
|
private boolean isNsfw;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -165,6 +167,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
|
|||||||
mImageFileName = intent.getStringExtra(EXTRA_FILE_NAME_KEY);
|
mImageFileName = intent.getStringExtra(EXTRA_FILE_NAME_KEY);
|
||||||
String postTitle = intent.getStringExtra(EXTRA_POST_TITLE_KEY);
|
String postTitle = intent.getStringExtra(EXTRA_POST_TITLE_KEY);
|
||||||
mSubredditName = intent.getStringExtra(EXTRA_SUBREDDIT_OR_USERNAME_KEY);
|
mSubredditName = intent.getStringExtra(EXTRA_SUBREDDIT_OR_USERNAME_KEY);
|
||||||
|
isNsfw = intent.getBooleanExtra(EXTRA_IS_NSFW, false);
|
||||||
|
|
||||||
boolean useBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER, false);
|
boolean useBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER, false);
|
||||||
if (postTitle != null) {
|
if (postTitle != null) {
|
||||||
@ -368,6 +371,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
|
|||||||
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, isGif ? DownloadMediaService.EXTRA_MEDIA_TYPE_GIF : DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE);
|
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, mImageFileName);
|
||||||
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, mSubredditName);
|
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, mSubredditName);
|
||||||
|
intent.putExtra(DownloadMediaService.EXTRA_IS_NSFW, isNsfw);
|
||||||
ContextCompat.startForegroundService(this, intent);
|
ContextCompat.startForegroundService(this, intent);
|
||||||
Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
|
|||||||
|
|
||||||
public static final String EXTRA_REDDIT_GALLERY = "ERG";
|
public static final String EXTRA_REDDIT_GALLERY = "ERG";
|
||||||
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||||
|
public static final String EXTRA_IS_NSFW = "EIN";
|
||||||
|
|
||||||
@BindView(R.id.hauler_view_view_reddit_gallery_activity)
|
@BindView(R.id.hauler_view_view_reddit_gallery_activity)
|
||||||
HaulerView haulerView;
|
HaulerView haulerView;
|
||||||
@ -70,6 +71,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
|
|||||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||||
private ArrayList<Post.Gallery> gallery;
|
private ArrayList<Post.Gallery> gallery;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
|
private boolean isNsfw;
|
||||||
private boolean useBottomAppBar;
|
private boolean useBottomAppBar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -155,6 +157,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||||
|
isNsfw = getIntent().getBooleanExtra(EXTRA_IS_NSFW, false);
|
||||||
|
|
||||||
if (sharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_VERTICALLY_TO_GO_BACK_FROM_MEDIA, true)) {
|
if (sharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_VERTICALLY_TO_GO_BACK_FROM_MEDIA, true)) {
|
||||||
haulerView.setOnDragDismissedListener(dragDirection -> {
|
haulerView.setOnDragDismissedListener(dragDirection -> {
|
||||||
@ -290,6 +293,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
|
|||||||
bundle.putString(ViewRedditGalleryVideoFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
bundle.putString(ViewRedditGalleryVideoFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||||
bundle.putInt(ViewRedditGalleryVideoFragment.EXTRA_INDEX, position);
|
bundle.putInt(ViewRedditGalleryVideoFragment.EXTRA_INDEX, position);
|
||||||
bundle.putInt(ViewRedditGalleryVideoFragment.EXTRA_MEDIA_COUNT, gallery.size());
|
bundle.putInt(ViewRedditGalleryVideoFragment.EXTRA_MEDIA_COUNT, gallery.size());
|
||||||
|
bundle.putBoolean(ViewRedditGalleryVideoFragment.EXTRA_IS_NSFW, isNsfw);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
return fragment;
|
return fragment;
|
||||||
} else {
|
} else {
|
||||||
@ -299,6 +303,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
|
|||||||
bundle.putString(ViewRedditGalleryImageOrGifFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
bundle.putString(ViewRedditGalleryImageOrGifFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||||
bundle.putInt(ViewRedditGalleryImageOrGifFragment.EXTRA_INDEX, position);
|
bundle.putInt(ViewRedditGalleryImageOrGifFragment.EXTRA_INDEX, position);
|
||||||
bundle.putInt(ViewRedditGalleryImageOrGifFragment.EXTRA_MEDIA_COUNT, gallery.size());
|
bundle.putInt(ViewRedditGalleryImageOrGifFragment.EXTRA_MEDIA_COUNT, gallery.size());
|
||||||
|
bundle.putBoolean(ViewRedditGalleryImageOrGifFragment.EXTRA_IS_NSFW, false);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
@ -895,11 +895,13 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO);
|
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO);
|
||||||
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, videoFileName);
|
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, videoFileName);
|
||||||
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName);
|
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||||
|
intent.putExtra(DownloadMediaService.EXTRA_IS_NSFW, isNSFW);
|
||||||
} else {
|
} else {
|
||||||
intent = new Intent(this, DownloadRedditVideoService.class);
|
intent = new Intent(this, DownloadRedditVideoService.class);
|
||||||
intent.putExtra(DownloadRedditVideoService.EXTRA_VIDEO_URL, videoDownloadUrl);
|
intent.putExtra(DownloadRedditVideoService.EXTRA_VIDEO_URL, videoDownloadUrl);
|
||||||
intent.putExtra(DownloadRedditVideoService.EXTRA_POST_ID, id);
|
intent.putExtra(DownloadRedditVideoService.EXTRA_POST_ID, id);
|
||||||
intent.putExtra(DownloadRedditVideoService.EXTRA_SUBREDDIT, subredditName);
|
intent.putExtra(DownloadRedditVideoService.EXTRA_SUBREDDIT, subredditName);
|
||||||
|
intent.putExtra(DownloadRedditVideoService.EXTRA_IS_NSFW, isNSFW);
|
||||||
}
|
}
|
||||||
ContextCompat.startForegroundService(this, intent);
|
ContextCompat.startForegroundService(this, intent);
|
||||||
Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
|
||||||
|
@ -1968,6 +1968,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
+ "-" + post.getId() + ".jpg");
|
+ "-" + post.getId() + ".jpg");
|
||||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
|
intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
|
||||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
|
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
|
||||||
|
intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW());
|
||||||
mActivity.startActivity(intent);
|
mActivity.startActivity(intent);
|
||||||
} else if (post.getPostType() == Post.GIF_TYPE) {
|
} else if (post.getPostType() == Post.GIF_TYPE) {
|
||||||
Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
|
Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
|
||||||
@ -1976,6 +1977,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, post.getVideoUrl());
|
intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, post.getVideoUrl());
|
||||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
|
intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
|
||||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
|
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
|
||||||
|
intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW());
|
||||||
mActivity.startActivity(intent);
|
mActivity.startActivity(intent);
|
||||||
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
|
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
|
||||||
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
|
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
|
||||||
@ -1987,6 +1989,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
|
Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
|
||||||
intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery());
|
intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery());
|
||||||
intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName());
|
intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName());
|
||||||
|
intent.putExtra(ViewRedditGalleryActivity.EXTRA_IS_NSFW, post.isNSFW());
|
||||||
mActivity.startActivity(intent);
|
mActivity.startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
|
|||||||
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||||
public static final String EXTRA_INDEX = "EI";
|
public static final String EXTRA_INDEX = "EI";
|
||||||
public static final String EXTRA_MEDIA_COUNT = "EMC";
|
public static final String EXTRA_MEDIA_COUNT = "EMC";
|
||||||
|
public static final String EXTRA_IS_NSFW = "EIN";
|
||||||
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
|
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
|
||||||
|
|
||||||
@BindView(R.id.progress_bar_view_reddit_gallery_image_or_gif_fragment)
|
@BindView(R.id.progress_bar_view_reddit_gallery_image_or_gif_fragment)
|
||||||
@ -108,6 +109,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
|
|||||||
private RequestManager glide;
|
private RequestManager glide;
|
||||||
private Post.Gallery media;
|
private Post.Gallery media;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
|
private boolean isNsfw;
|
||||||
private boolean isDownloading = false;
|
private boolean isDownloading = false;
|
||||||
private boolean isActionBarHidden = false;
|
private boolean isActionBarHidden = false;
|
||||||
private boolean isUseBottomCaption = false;
|
private boolean isUseBottomCaption = false;
|
||||||
@ -132,6 +134,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
|
|||||||
|
|
||||||
media = getArguments().getParcelable(EXTRA_REDDIT_GALLERY_MEDIA);
|
media = getArguments().getParcelable(EXTRA_REDDIT_GALLERY_MEDIA);
|
||||||
subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME);
|
subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME);
|
||||||
|
isNsfw = getArguments().getBoolean(EXTRA_IS_NSFW, false);
|
||||||
glide = Glide.with(activity);
|
glide = Glide.with(activity);
|
||||||
|
|
||||||
imageView.setImageViewFactory(new GlideImageViewFactory());
|
imageView.setImageViewFactory(new GlideImageViewFactory());
|
||||||
@ -398,6 +401,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
|
|||||||
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, media.mediaType == Post.Gallery.TYPE_GIF ? DownloadMediaService.EXTRA_MEDIA_TYPE_GIF: DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE);
|
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, media.mediaType == Post.Gallery.TYPE_GIF ? DownloadMediaService.EXTRA_MEDIA_TYPE_GIF: DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE);
|
||||||
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, media.fileName);
|
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, media.fileName);
|
||||||
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName);
|
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||||
|
intent.putExtra(DownloadMediaService.EXTRA_IS_NSFW, isNsfw);
|
||||||
ContextCompat.startForegroundService(activity, intent);
|
ContextCompat.startForegroundService(activity, intent);
|
||||||
Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
|
|||||||
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||||
public static final String EXTRA_INDEX = "EI";
|
public static final String EXTRA_INDEX = "EI";
|
||||||
public static final String EXTRA_MEDIA_COUNT = "EMC";
|
public static final String EXTRA_MEDIA_COUNT = "EMC";
|
||||||
|
public static final String EXTRA_IS_NSFW = "EIN";
|
||||||
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
|
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
|
||||||
private static final String IS_MUTE_STATE = "IMS";
|
private static final String IS_MUTE_STATE = "IMS";
|
||||||
private static final String POSITION_STATE = "PS";
|
private static final String POSITION_STATE = "PS";
|
||||||
@ -79,6 +80,7 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
|
|||||||
private ViewRedditGalleryActivity activity;
|
private ViewRedditGalleryActivity activity;
|
||||||
private Post.Gallery galleryVideo;
|
private Post.Gallery galleryVideo;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
|
private boolean isNsfw;
|
||||||
private SimpleExoPlayer player;
|
private SimpleExoPlayer player;
|
||||||
private DataSource.Factory dataSourceFactory;
|
private DataSource.Factory dataSourceFactory;
|
||||||
private boolean wasPlaying = false;
|
private boolean wasPlaying = false;
|
||||||
@ -109,6 +111,7 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
|
|||||||
|
|
||||||
galleryVideo = getArguments().getParcelable(EXTRA_REDDIT_GALLERY_VIDEO);
|
galleryVideo = getArguments().getParcelable(EXTRA_REDDIT_GALLERY_VIDEO);
|
||||||
subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME);
|
subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME);
|
||||||
|
isNsfw = getArguments().getBoolean(EXTRA_IS_NSFW, false);
|
||||||
|
|
||||||
if (!mSharedPreferences.getBoolean(SharedPreferencesUtils.VIDEO_PLAYER_IGNORE_NAV_BAR, false)) {
|
if (!mSharedPreferences.getBoolean(SharedPreferencesUtils.VIDEO_PLAYER_IGNORE_NAV_BAR, false)) {
|
||||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || getResources().getBoolean(R.bool.isTablet)) {
|
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || getResources().getBoolean(R.bool.isTablet)) {
|
||||||
@ -242,6 +245,7 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
|
|||||||
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO);
|
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO);
|
||||||
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, galleryVideo.fileName);
|
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, galleryVideo.fileName);
|
||||||
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName);
|
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||||
|
intent.putExtra(DownloadMediaService.EXTRA_IS_NSFW, isNsfw);
|
||||||
ContextCompat.startForegroundService(activity, intent);
|
ContextCompat.startForegroundService(activity, intent);
|
||||||
Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ public class DownloadMediaService extends Service {
|
|||||||
public static final String EXTRA_FILE_NAME = "EFN";
|
public static final String EXTRA_FILE_NAME = "EFN";
|
||||||
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||||
public static final String EXTRA_MEDIA_TYPE = "EIG";
|
public static final String EXTRA_MEDIA_TYPE = "EIG";
|
||||||
|
public static final String EXTRA_IS_NSFW = "EIN";
|
||||||
public static final int EXTRA_MEDIA_TYPE_IMAGE = 0;
|
public static final int EXTRA_MEDIA_TYPE_IMAGE = 0;
|
||||||
public static final int EXTRA_MEDIA_TYPE_GIF = 1;
|
public static final int EXTRA_MEDIA_TYPE_GIF = 1;
|
||||||
public static final int EXTRA_MEDIA_TYPE_VIDEO = 2;
|
public static final int EXTRA_MEDIA_TYPE_VIDEO = 2;
|
||||||
@ -101,6 +102,7 @@ public class DownloadMediaService extends Service {
|
|||||||
String fileName = intent.getString(EXTRA_FILE_NAME);
|
String fileName = intent.getString(EXTRA_FILE_NAME);
|
||||||
String subredditName = intent.getString(EXTRA_SUBREDDIT_NAME);
|
String subredditName = intent.getString(EXTRA_SUBREDDIT_NAME);
|
||||||
int mediaType = intent.getInt(EXTRA_MEDIA_TYPE, EXTRA_MEDIA_TYPE_IMAGE);
|
int mediaType = intent.getInt(EXTRA_MEDIA_TYPE, EXTRA_MEDIA_TYPE_IMAGE);
|
||||||
|
boolean isNsfw = intent.getBoolean(EXTRA_IS_NSFW, false);
|
||||||
String mimeType = mediaType == EXTRA_MEDIA_TYPE_VIDEO ? "video/*" : "image/*";
|
String mimeType = mediaType == EXTRA_MEDIA_TYPE_VIDEO ? "video/*" : "image/*";
|
||||||
|
|
||||||
final DownloadProgressResponseBody.ProgressListener progressListener = new DownloadProgressResponseBody.ProgressListener() {
|
final DownloadProgressResponseBody.ProgressListener progressListener = new DownloadProgressResponseBody.ProgressListener() {
|
||||||
@ -139,7 +141,7 @@ public class DownloadMediaService extends Service {
|
|||||||
try {
|
try {
|
||||||
response = retrofit.create(DownloadFile.class).downloadFile(fileUrl).execute();
|
response = retrofit.create(DownloadFile.class).downloadFile(fileUrl).execute();
|
||||||
if (response.isSuccessful() && response.body() != null) {
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
String destinationFileDirectory = getDownloadLocation(mediaType);
|
String destinationFileDirectory = getDownloadLocation(mediaType, isNsfw);
|
||||||
if (destinationFileDirectory.equals("")) {
|
if (destinationFileDirectory.equals("")) {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
File directory = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
|
File directory = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
|
||||||
@ -462,7 +464,10 @@ public class DownloadMediaService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDownloadLocation(int mediaType) {
|
private String getDownloadLocation(int mediaType, boolean isNsfw) {
|
||||||
|
if (isNsfw && mSharedPreferences.getBoolean(SharedPreferencesUtils.SEPARATE_NSFW_FOLDER, false)) {
|
||||||
|
return mSharedPreferences.getString(SharedPreferencesUtils.NSFW_DOWNLOAD_LOCATION, "");
|
||||||
|
}
|
||||||
switch (mediaType) {
|
switch (mediaType) {
|
||||||
case EXTRA_MEDIA_TYPE_GIF:
|
case EXTRA_MEDIA_TYPE_GIF:
|
||||||
return mSharedPreferences.getString(SharedPreferencesUtils.GIF_DOWNLOAD_LOCATION, "");
|
return mSharedPreferences.getString(SharedPreferencesUtils.GIF_DOWNLOAD_LOCATION, "");
|
||||||
|
@ -63,6 +63,7 @@ public class DownloadRedditVideoService extends Service {
|
|||||||
public static final String EXTRA_VIDEO_URL = "EVU";
|
public static final String EXTRA_VIDEO_URL = "EVU";
|
||||||
public static final String EXTRA_SUBREDDIT = "ES";
|
public static final String EXTRA_SUBREDDIT = "ES";
|
||||||
public static final String EXTRA_POST_ID = "EPI";
|
public static final String EXTRA_POST_ID = "EPI";
|
||||||
|
public static final String EXTRA_IS_NSFW = "EIN";
|
||||||
|
|
||||||
private static final int NO_ERROR = -1;
|
private static final int NO_ERROR = -1;
|
||||||
private static final int ERROR_CANNOT_GET_CACHE_DIRECTORY = 0;
|
private static final int ERROR_CANNOT_GET_CACHE_DIRECTORY = 0;
|
||||||
@ -99,6 +100,7 @@ public class DownloadRedditVideoService extends Service {
|
|||||||
String audioUrl = videoUrl.substring(0, videoUrl.lastIndexOf('/')) + "/DASH_audio.mp4";
|
String audioUrl = videoUrl.substring(0, videoUrl.lastIndexOf('/')) + "/DASH_audio.mp4";
|
||||||
String subredditName = intent.getString(EXTRA_SUBREDDIT);
|
String subredditName = intent.getString(EXTRA_SUBREDDIT);
|
||||||
String fileNameWithoutExtension = subredditName + "-" + intent.getString(EXTRA_POST_ID);
|
String fileNameWithoutExtension = subredditName + "-" + intent.getString(EXTRA_POST_ID);
|
||||||
|
boolean isNsfw = intent.getBoolean(EXTRA_IS_NSFW, false);
|
||||||
int randomNotificationIdOffset = msg.arg1;
|
int randomNotificationIdOffset = msg.arg1;
|
||||||
|
|
||||||
final DownloadProgressResponseBody.ProgressListener progressListener = new DownloadProgressResponseBody.ProgressListener() {
|
final DownloadProgressResponseBody.ProgressListener progressListener = new DownloadProgressResponseBody.ProgressListener() {
|
||||||
@ -141,7 +143,12 @@ public class DownloadRedditVideoService extends Service {
|
|||||||
Response<ResponseBody> videoResponse = downloadFile.downloadFile(videoUrl).execute();
|
Response<ResponseBody> videoResponse = downloadFile.downloadFile(videoUrl).execute();
|
||||||
if (videoResponse.isSuccessful() && videoResponse.body() != null) {
|
if (videoResponse.isSuccessful() && videoResponse.body() != null) {
|
||||||
String externalCacheDirectoryPath = externalCacheDirectory.getAbsolutePath() + "/";
|
String externalCacheDirectoryPath = externalCacheDirectory.getAbsolutePath() + "/";
|
||||||
String destinationFileDirectory = sharedPreferences.getString(SharedPreferencesUtils.VIDEO_DOWNLOAD_LOCATION, "");
|
String destinationFileDirectory;
|
||||||
|
if (isNsfw && sharedPreferences.getBoolean(SharedPreferencesUtils.SEPARATE_NSFW_FOLDER, false)) {
|
||||||
|
destinationFileDirectory = sharedPreferences.getString(SharedPreferencesUtils.NSFW_DOWNLOAD_LOCATION, "");
|
||||||
|
} else {
|
||||||
|
destinationFileDirectory = sharedPreferences.getString(SharedPreferencesUtils.VIDEO_DOWNLOAD_LOCATION, "");
|
||||||
|
}
|
||||||
String destinationFileUriString;
|
String destinationFileUriString;
|
||||||
boolean isDefaultDestination;
|
boolean isDefaultDestination;
|
||||||
if (destinationFileDirectory.equals("")) {
|
if (destinationFileDirectory.equals("")) {
|
||||||
|
@ -24,10 +24,12 @@ public class DownloadLocationPreferenceFragment extends PreferenceFragmentCompat
|
|||||||
private static final int IMAGE_DOWNLOAD_LOCATION_REQUEST_CODE = 10;
|
private static final int IMAGE_DOWNLOAD_LOCATION_REQUEST_CODE = 10;
|
||||||
private static final int GIF_DOWNLOAD_LOCATION_REQUEST_CODE = 11;
|
private static final int GIF_DOWNLOAD_LOCATION_REQUEST_CODE = 11;
|
||||||
private static final int VIDEO_DOWNLOAD_LOCATION_REQUEST_CODE = 12;
|
private static final int VIDEO_DOWNLOAD_LOCATION_REQUEST_CODE = 12;
|
||||||
|
private static final int NSFW_DOWNLOAD_LOCATION_REQUEST_CODE = 13;
|
||||||
|
|
||||||
Preference imageDownloadLocationPreference;
|
Preference imageDownloadLocationPreference;
|
||||||
Preference gifDownloadLocationPreference;
|
Preference gifDownloadLocationPreference;
|
||||||
Preference videoDownloadLocationPreference;
|
Preference videoDownloadLocationPreference;
|
||||||
|
Preference nsfwDownloadLocationPreference;
|
||||||
private Activity activity;
|
private Activity activity;
|
||||||
@Inject
|
@Inject
|
||||||
@Named("default")
|
@Named("default")
|
||||||
@ -40,7 +42,21 @@ public class DownloadLocationPreferenceFragment extends PreferenceFragmentCompat
|
|||||||
imageDownloadLocationPreference = findPreference(SharedPreferencesUtils.IMAGE_DOWNLOAD_LOCATION);
|
imageDownloadLocationPreference = findPreference(SharedPreferencesUtils.IMAGE_DOWNLOAD_LOCATION);
|
||||||
gifDownloadLocationPreference = findPreference(SharedPreferencesUtils.GIF_DOWNLOAD_LOCATION);
|
gifDownloadLocationPreference = findPreference(SharedPreferencesUtils.GIF_DOWNLOAD_LOCATION);
|
||||||
videoDownloadLocationPreference = findPreference(SharedPreferencesUtils.VIDEO_DOWNLOAD_LOCATION);
|
videoDownloadLocationPreference = findPreference(SharedPreferencesUtils.VIDEO_DOWNLOAD_LOCATION);
|
||||||
|
nsfwDownloadLocationPreference = findPreference(SharedPreferencesUtils.NSFW_DOWNLOAD_LOCATION);
|
||||||
|
|
||||||
|
if (nsfwDownloadLocationPreference != null) {
|
||||||
|
String downloadLocation = sharedPreferences.getString(SharedPreferencesUtils.NSFW_DOWNLOAD_LOCATION, "");
|
||||||
|
if (!downloadLocation.equals("")) {
|
||||||
|
nsfwDownloadLocationPreference.setSummary(downloadLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsfwDownloadLocationPreference.setOnPreferenceClickListener(preference -> {
|
||||||
|
Intent intent = new Intent(ACTION_OPEN_DOCUMENT_TREE);
|
||||||
|
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||||
|
startActivityForResult(intent, NSFW_DOWNLOAD_LOCATION_REQUEST_CODE);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
if (imageDownloadLocationPreference != null) {
|
if (imageDownloadLocationPreference != null) {
|
||||||
String downloadLocation = sharedPreferences.getString(SharedPreferencesUtils.IMAGE_DOWNLOAD_LOCATION, "");
|
String downloadLocation = sharedPreferences.getString(SharedPreferencesUtils.IMAGE_DOWNLOAD_LOCATION, "");
|
||||||
if (!downloadLocation.equals("")) {
|
if (!downloadLocation.equals("")) {
|
||||||
|
@ -130,6 +130,8 @@ public class SharedPreferencesUtils {
|
|||||||
public static final String IMAGE_DOWNLOAD_LOCATION = "image_download_location";
|
public static final String IMAGE_DOWNLOAD_LOCATION = "image_download_location";
|
||||||
public static final String GIF_DOWNLOAD_LOCATION = "gif_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 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 SEPARATE_FOLDER_FOR_EACH_SUBREDDIT = "separate_folder_for_each_subreddit";
|
||||||
public static final String VIBRATE_WHEN_ACTION_TRIGGERED = "vibrate_when_action_triggered";
|
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 DISABLE_SWIPING_BETWEEN_TABS = "disable_swiping_between_tabs";
|
||||||
|
@ -516,6 +516,8 @@
|
|||||||
<string name="settings_image_download_location_title">Image Download Location</string>
|
<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_gif_download_location_title">Gif Download Location</string>
|
||||||
<string name="settings_video_download_location_title">Video 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_separate_folder_for_each_subreddit">Separate Folder for Each Subreddit</string>
|
||||||
<string name="settings_swipe_action_title">Swipe Action</string>
|
<string name="settings_swipe_action_title">Swipe Action</string>
|
||||||
<string name="settings_swipe_action_haptic_feedback_title">Haptic Feedback</string>
|
<string name="settings_swipe_action_haptic_feedback_title">Haptic Feedback</string>
|
||||||
|
@ -11,6 +11,15 @@
|
|||||||
app:key="video_download_location"
|
app:key="video_download_location"
|
||||||
app:title="@string/settings_video_download_location_title" />
|
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
|
<SwitchPreference
|
||||||
app:defaultValue="false"
|
app:defaultValue="false"
|
||||||
app:key="separate_folder_for_each_subreddit"
|
app:key="separate_folder_for_each_subreddit"
|
||||||
|
Loading…
Reference in New Issue
Block a user