add reset extSD card folder dialog
This commit is contained in:
parent
badd4d3207
commit
44a71d8565
6 changed files with 88 additions and 7 deletions
|
|
@ -0,0 +1,40 @@
|
|||
package org.schabi.newpipe.download;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.settings.NewPipeSettings;
|
||||
import org.schabi.newpipe.util.ServiceHelper;
|
||||
import org.schabi.newpipe.util.ThemeHelper;
|
||||
|
||||
public class ExtSDDownloadFailedActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.download_to_sdcard_error_title)
|
||||
.setMessage(R.string.download_to_sdcard_error_message)
|
||||
.setPositiveButton(R.string.yes, (DialogInterface dialogInterface, int i) -> {
|
||||
|
||||
NewPipeSettings.resetDownloadFolders(this);
|
||||
finish();
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, (DialogInterface dialogInterface, int i) -> {
|
||||
|
||||
dialogInterface.dismiss();
|
||||
finish();
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<DownloadMission> mMissions = new ArrayList<DownloadMission>();
|
||||
private final ArrayList<DownloadMission> mMissions = new ArrayList<>();
|
||||
private final Context context;
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
|
|
@ -33,6 +46,13 @@ public class DownloadManagerImpl implements DownloadManager {
|
|||
*/
|
||||
public DownloadManagerImpl(Collection<String> searchLocations, DownloadDataSource downloadDataSource) {
|
||||
mDownloadDataSource = downloadDataSource;
|
||||
this.context = null;
|
||||
loadMissions(searchLocations);
|
||||
}
|
||||
|
||||
public DownloadManagerImpl(Collection<String> 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);
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public class DownloadManagerService extends Service {
|
|||
ArrayList<String> 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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue