add reset extSD card folder dialog
This commit is contained in:
parent
badd4d3207
commit
44a71d8565
|
@ -76,10 +76,6 @@
|
||||||
android:name=".about.AboutActivity"
|
android:name=".about.AboutActivity"
|
||||||
android:label="@string/title_activity_about"/>
|
android:label="@string/title_activity_about"/>
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name=".history.HistoryActivity"
|
|
||||||
android:label="@string/title_activity_history"/>
|
|
||||||
|
|
||||||
<service android:name=".local.subscription.services.SubscriptionsImportService"/>
|
<service android:name=".local.subscription.services.SubscriptionsImportService"/>
|
||||||
<service android:name=".local.subscription.services.SubscriptionsExportService"/>
|
<service android:name=".local.subscription.services.SubscriptionsExportService"/>
|
||||||
|
|
||||||
|
@ -122,6 +118,7 @@
|
||||||
<activity
|
<activity
|
||||||
android:name=".ReCaptchaActivity"
|
android:name=".ReCaptchaActivity"
|
||||||
android:label="@string/reCaptchaActivity"/>
|
android:label="@string/reCaptchaActivity"/>
|
||||||
|
<activity android:name=".download.ExtSDDownloadFailedActivity" />
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name="android.support.v4.content.FileProvider"
|
android:name="android.support.v4.content.FileProvider"
|
||||||
|
|
|
@ -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) {
|
private static File getFolder(String defaultDirectoryName) {
|
||||||
return new File(Environment.getExternalStorageDirectory(), 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;
|
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.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
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.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -23,7 +35,8 @@ public class DownloadManagerImpl implements DownloadManager {
|
||||||
private static final String TAG = DownloadManagerImpl.class.getSimpleName();
|
private static final String TAG = DownloadManagerImpl.class.getSimpleName();
|
||||||
private final DownloadDataSource mDownloadDataSource;
|
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
|
* Create a new instance
|
||||||
|
@ -33,6 +46,13 @@ public class DownloadManagerImpl implements DownloadManager {
|
||||||
*/
|
*/
|
||||||
public DownloadManagerImpl(Collection<String> searchLocations, DownloadDataSource downloadDataSource) {
|
public DownloadManagerImpl(Collection<String> searchLocations, DownloadDataSource downloadDataSource) {
|
||||||
mDownloadDataSource = downloadDataSource;
|
mDownloadDataSource = downloadDataSource;
|
||||||
|
this.context = null;
|
||||||
|
loadMissions(searchLocations);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DownloadManagerImpl(Collection<String> searchLocations, DownloadDataSource downloadDataSource, Context context) {
|
||||||
|
mDownloadDataSource = downloadDataSource;
|
||||||
|
this.context = context;
|
||||||
loadMissions(searchLocations);
|
loadMissions(searchLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,10 +297,12 @@ public class DownloadManagerImpl implements DownloadManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Initializer extends Thread {
|
private class Initializer extends Thread {
|
||||||
private DownloadMission mission;
|
private final DownloadMission mission;
|
||||||
|
private final Handler handler;
|
||||||
|
|
||||||
public Initializer(DownloadMission mission) {
|
public Initializer(DownloadMission mission) {
|
||||||
this.mission = mission;
|
this.mission = mission;
|
||||||
|
this.handler = new Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -335,6 +357,13 @@ public class DownloadManagerImpl implements DownloadManager {
|
||||||
af.close();
|
af.close();
|
||||||
|
|
||||||
mission.start();
|
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) {
|
} catch (Exception e) {
|
||||||
// TODO Notify
|
// TODO Notify
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class DownloadManagerService extends Service {
|
||||||
ArrayList<String> paths = new ArrayList<>(2);
|
ArrayList<String> paths = new ArrayList<>(2);
|
||||||
paths.add(NewPipeSettings.getVideoDownloadPath(this));
|
paths.add(NewPipeSettings.getVideoDownloadPath(this));
|
||||||
paths.add(NewPipeSettings.getAudioDownloadPath(this));
|
paths.add(NewPipeSettings.getAudioDownloadPath(this));
|
||||||
mManager = new DownloadManagerImpl(paths, mDataSource);
|
mManager = new DownloadManagerImpl(paths, mDataSource, this);
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "mManager == null");
|
Log.d(TAG, "mManager == null");
|
||||||
Log.d(TAG, "Download directory: " + paths);
|
Log.d(TAG, "Download directory: " + paths);
|
||||||
|
|
|
@ -170,6 +170,8 @@
|
||||||
<string name="search_history_deleted">Search history deleted.</string>
|
<string name="search_history_deleted">Search history deleted.</string>
|
||||||
<!-- error strings -->
|
<!-- error strings -->
|
||||||
<string name="general_error">Error</string>
|
<string name="general_error">Error</string>
|
||||||
|
<string name="download_to_sdcard_error_title">External storage not available.</string>
|
||||||
|
<string name="download_to_sdcard_error_message">Download to external SD Card is not possible yet. Should the download place be reseted?</string>
|
||||||
<string name="network_error">Network error</string>
|
<string name="network_error">Network error</string>
|
||||||
<string name="could_not_load_thumbnails">Could not load all thumbnails</string>
|
<string name="could_not_load_thumbnails">Could not load all thumbnails</string>
|
||||||
<string name="youtube_signature_decryption_error">Could not decrypt video URL signature</string>
|
<string name="youtube_signature_decryption_error">Could not decrypt video URL signature</string>
|
||||||
|
|
Loading…
Reference in New Issue