diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 33e0651e5..e4d448184 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -76,10 +76,6 @@
android:name=".about.AboutActivity"
android:label="@string/title_activity_about"/>
-
-
@@ -122,6 +118,7 @@
+
{
+
+ NewPipeSettings.resetDownloadFolders(this);
+ finish();
+ })
+ .setNegativeButton(R.string.cancel, (DialogInterface dialogInterface, int i) -> {
+
+ dialogInterface.dismiss();
+ finish();
+ })
+ .create()
+ .show();
+ }
+}
diff --git a/app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java b/app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java
index 92f98a9a2..08ec74d17 100644
--- a/app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java
+++ b/app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java
@@ -107,4 +107,17 @@ public class NewPipeSettings {
private static File getFolder(String defaultDirectoryName) {
return new File(Environment.getExternalStorageDirectory(), defaultDirectoryName);
}
+
+ public static void resetDownloadFolders(Context context) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ resetDownloadFolder(prefs, context.getString(R.string.download_path_audio_key), Environment.DIRECTORY_MUSIC);
+ resetDownloadFolder(prefs, context.getString(R.string.download_path_key), Environment.DIRECTORY_MOVIES);
+ }
+
+ private static void resetDownloadFolder(SharedPreferences prefs, String key, String defaultDirectoryName) {
+ final File folder = getFolder(defaultDirectoryName);
+ SharedPreferences.Editor spEditor = prefs.edit();
+ spEditor.putString(key, new File(folder, "NewPipe").getAbsolutePath());
+ spEditor.apply();
+ }
}
diff --git a/app/src/main/java/us/shandian/giga/get/DownloadManagerImpl.java b/app/src/main/java/us/shandian/giga/get/DownloadManagerImpl.java
index ecd3ce562..550bd420d 100755
--- a/app/src/main/java/us/shandian/giga/get/DownloadManagerImpl.java
+++ b/app/src/main/java/us/shandian/giga/get/DownloadManagerImpl.java
@@ -1,10 +1,22 @@
package us.shandian.giga.get;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Handler;
+import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.util.Log;
+import org.schabi.newpipe.R;
+import org.schabi.newpipe.download.ExtSDDownloadFailedActivity;
+import org.schabi.newpipe.settings.NewPipeSettings;
+
import java.io.File;
import java.io.FilenameFilter;
+import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.URL;
@@ -23,7 +35,8 @@ public class DownloadManagerImpl implements DownloadManager {
private static final String TAG = DownloadManagerImpl.class.getSimpleName();
private final DownloadDataSource mDownloadDataSource;
- private final ArrayList mMissions = new ArrayList();
+ private final ArrayList mMissions = new ArrayList<>();
+ private final Context context;
/**
* Create a new instance
@@ -33,6 +46,13 @@ public class DownloadManagerImpl implements DownloadManager {
*/
public DownloadManagerImpl(Collection searchLocations, DownloadDataSource downloadDataSource) {
mDownloadDataSource = downloadDataSource;
+ this.context = null;
+ loadMissions(searchLocations);
+ }
+
+ public DownloadManagerImpl(Collection searchLocations, DownloadDataSource downloadDataSource, Context context) {
+ mDownloadDataSource = downloadDataSource;
+ this.context = context;
loadMissions(searchLocations);
}
@@ -277,10 +297,12 @@ public class DownloadManagerImpl implements DownloadManager {
}
private class Initializer extends Thread {
- private DownloadMission mission;
+ private final DownloadMission mission;
+ private final Handler handler;
public Initializer(DownloadMission mission) {
this.mission = mission;
+ this.handler = new Handler();
}
@Override
@@ -335,6 +357,13 @@ public class DownloadManagerImpl implements DownloadManager {
af.close();
mission.start();
+ } catch (IOException ie) {
+ if(context == null) throw new RuntimeException(ie);
+
+ if(ie.getMessage().contains("Permission denied")) {
+ handler.post(() ->
+ context.startActivity(new Intent(context, ExtSDDownloadFailedActivity.class)));
+ } else throw new RuntimeException(ie);
} catch (Exception e) {
// TODO Notify
throw new RuntimeException(e);
diff --git a/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java b/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java
index 50975728f..59f5e2225 100755
--- a/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java
+++ b/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java
@@ -81,7 +81,7 @@ public class DownloadManagerService extends Service {
ArrayList paths = new ArrayList<>(2);
paths.add(NewPipeSettings.getVideoDownloadPath(this));
paths.add(NewPipeSettings.getAudioDownloadPath(this));
- mManager = new DownloadManagerImpl(paths, mDataSource);
+ mManager = new DownloadManagerImpl(paths, mDataSource, this);
if (DEBUG) {
Log.d(TAG, "mManager == null");
Log.d(TAG, "Download directory: " + paths);
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 344ef2198..0e72ecd35 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -170,6 +170,8 @@
Search history deleted.
Error
+ External storage not available.
+ Download to external SD Card is not possible yet. Should the download place be reseted?
Network error
Could not load all thumbnails
Could not decrypt video URL signature