aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java46
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewRedditGalleryImageOrGifFragment.java14
4 files changed, 65 insertions, 11 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java
index 471a4ea1..22a921e6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java
@@ -1,5 +1,6 @@
package ml.docilealligator.infinityforreddit.Activity;
+import android.Manifest;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
@@ -21,6 +22,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.ActivityCompat;
+import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import com.bumptech.glide.Glide;
@@ -277,16 +280,28 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
finish();
return true;
case R.id.action_download_view_image_or_gif_activity:
- Intent intent = new Intent(this, DownloadImageService.class);
- intent.putExtra(DownloadImageService.EXTRA_URL, mImageUrl);
- intent.putExtra(DownloadImageService.EXTRA_IS_GIF, isGif);
- intent.putExtra(DownloadImageService.EXTRA_FILE_NAME, mImageFileName);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- startForegroundService(intent);
+ if (isDownloading) {
+ return false;
+ }
+
+ isDownloading = true;
+
+ if (Build.VERSION.SDK_INT >= 23) {
+ if (ContextCompat.checkSelfPermission(this,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE)
+ != PackageManager.PERMISSION_GRANTED) {
+
+ // Permission is not granted
+ // No explanation needed; request the permission
+ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
+ PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
+ } else {
+ // Permission has already been granted
+ download();
+ }
} else {
- startService(intent);
+ download();
}
- Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
return true;
case R.id.action_share_view_image_or_gif_activity:
@@ -321,6 +336,21 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
return false;
}
+ private void download() {
+ isDownloading = false;
+
+ Intent intent = new Intent(this, DownloadImageService.class);
+ intent.putExtra(DownloadImageService.EXTRA_URL, mImageUrl);
+ intent.putExtra(DownloadImageService.EXTRA_IS_GIF, isGif);
+ intent.putExtra(DownloadImageService.EXTRA_FILE_NAME, mImageFileName);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ startForegroundService(intent);
+ } else {
+ startService(intent);
+ }
+ Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
+ }
+
private void shareImage() {
glide.asBitmap().load(mImageUrl).into(new CustomTarget<Bitmap>() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
index 79ef0477..c1c2c45c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
@@ -374,6 +374,10 @@ public class ViewVideoActivity extends AppCompatActivity {
finish();
return true;
case R.id.action_download_view_video_activity:
+ if (isDownloading) {
+ return false;
+ }
+
if (videoDownloadUrl == null) {
Toast.makeText(this, R.string.fetching_video_info_please_wait, Toast.LENGTH_SHORT).show();
return true;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java
index 91d25aed..6a801091 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java
@@ -48,6 +48,7 @@ import ml.docilealligator.infinityforreddit.ImgurMedia;
import ml.docilealligator.infinityforreddit.MediaDownloader;
import ml.docilealligator.infinityforreddit.MediaDownloaderImpl;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.Service.DownloadImageService;
import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback;
public class ViewImgurImageFragment extends Fragment {
@@ -235,7 +236,16 @@ public class ViewImgurImageFragment extends Fragment {
private void download() {
isDownloading = false;
- mediaDownloader.download(imgurMedia.getLink(), imgurMedia.getFileName(), getContext());
+ Intent intent = new Intent(activity, DownloadImageService.class);
+ intent.putExtra(DownloadImageService.EXTRA_URL, imgurMedia.getLink());
+ intent.putExtra(DownloadImageService.EXTRA_IS_GIF, false);
+ intent.putExtra(DownloadImageService.EXTRA_FILE_NAME, imgurMedia.getFileName());
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ activity.startForegroundService(intent);
+ } else {
+ activity.startService(intent);
+ }
+ Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewRedditGalleryImageOrGifFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewRedditGalleryImageOrGifFragment.java
index e8954f41..eb809fa5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewRedditGalleryImageOrGifFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewRedditGalleryImageOrGifFragment.java
@@ -46,14 +46,15 @@ import java.io.File;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Activity.ViewRedditGalleryActivity;
-import ml.docilealligator.infinityforreddit.AsyncTask.SaveGIFToFileAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.SaveBitmapImageToFileAsyncTask;
+import ml.docilealligator.infinityforreddit.AsyncTask.SaveGIFToFileAsyncTask;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.SetAsWallpaperBottomSheetFragment;
import ml.docilealligator.infinityforreddit.BuildConfig;
import ml.docilealligator.infinityforreddit.MediaDownloader;
import ml.docilealligator.infinityforreddit.MediaDownloaderImpl;
import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.Service.DownloadImageService;
import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback;
public class ViewRedditGalleryImageOrGifFragment extends Fragment {
@@ -268,7 +269,16 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
private void download() {
isDownloading = false;
- mediaDownloader.download(media.url, media.fileName, getContext());
+ Intent intent = new Intent(activity, DownloadImageService.class);
+ intent.putExtra(DownloadImageService.EXTRA_URL, media.url);
+ intent.putExtra(DownloadImageService.EXTRA_IS_GIF, media.mediaType == Post.Gallery.TYPE_GIF);
+ intent.putExtra(DownloadImageService.EXTRA_FILE_NAME, media.fileName);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ activity.startForegroundService(intent);
+ } else {
+ activity.startService(intent);
+ }
+ Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
}
private void shareImage() {