aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-09-10 16:30:15 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-09-10 16:30:15 +0000
commitf109d28c9dc81000570da3e16ecfec6a89bb6c35 (patch)
tree7a004b09582c359c799d20c975041222e069a6ae /app/src
parentf5f2acfab167b704c0925f7e1a7b95af98a1f811 (diff)
downloadinfinity-for-reddit-f109d28c9dc81000570da3e16ecfec6a89bb6c35.tar
infinity-for-reddit-f109d28c9dc81000570da3e16ecfec6a89bb6c35.tar.gz
infinity-for-reddit-f109d28c9dc81000570da3e16ecfec6a89bb6c35.tar.bz2
infinity-for-reddit-f109d28c9dc81000570da3e16ecfec6a89bb6c35.tar.lz
infinity-for-reddit-f109d28c9dc81000570da3e16ecfec6a89bb6c35.tar.xz
infinity-for-reddit-f109d28c9dc81000570da3e16ecfec6a89bb6c35.tar.zst
infinity-for-reddit-f109d28c9dc81000570da3e16ecfec6a89bb6c35.zip
Fixed images cannot be saved. Fixed crashes when downloading videos
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java32
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java16
2 files changed, 32 insertions, 16 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java
index 9ed2fe62..0e08dcb3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java
@@ -426,22 +426,6 @@ public class ViewImageActivity extends AppCompatActivity {
@Override
protected Void doInBackground(Void... params) {
try {
- String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
- File directory = new File(path + "/Infinity/");
- if(!directory.exists()) {
- if(!directory.mkdir()) {
- saveSuccess = false;
- return null;
- }
- } else {
- if(directory.isFile()) {
- if(!directory.delete() && !directory.mkdir()) {
- saveSuccess = false;
- return null;
- }
- }
- }
-
//Android Q support
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ContentValues values = new ContentValues();
@@ -478,6 +462,22 @@ public class ViewImageActivity extends AppCompatActivity {
values.put(MediaStore.Images.Media.IS_PENDING, 0);
resolver.update(item, values, null, null);
} else {
+ String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
+ File directory = new File(path + "/Infinity/");
+ if(!directory.exists()) {
+ if(!directory.mkdir()) {
+ saveSuccess = false;
+ return null;
+ }
+ } else {
+ if(directory.isFile()) {
+ if(!directory.delete() && !directory.mkdir()) {
+ saveSuccess = false;
+ return null;
+ }
+ }
+ }
+
File file = new File(path + "/Infinity/", mImageFileName + ".jpg");
int postfix = 1;
while(file.exists()) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java
index bb471562..e96f0cff 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java
@@ -51,6 +51,8 @@ import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
+import java.io.File;
+
import butterknife.BindView;
import butterknife.ButterKnife;
@@ -395,6 +397,20 @@ public class ViewVideoActivity extends AppCompatActivity {
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, mGifOrVideoFileName);
} else {
+ String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
+ File directory = new File(path + "/Infinity/");
+ if(!directory.exists()) {
+ if(!directory.mkdir()) {
+ request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, mGifOrVideoFileName);
+ }
+ } else {
+ if(directory.isFile()) {
+ if(!directory.delete() && !directory.mkdir()) {
+ request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, mGifOrVideoFileName);
+ }
+ }
+ }
+
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES + "/Infinity/", mGifOrVideoFileName);
}