use the standard "Movies" folder for downloads

On all of the devices that I've checked, there is a folder called "Movies"
on the SD Card by default.  NewPipe should use that standard location
since it is always downloading movies :).  People can always change that
via the preferences.

Also, this makes the defaults the same when creating the dir and when
setting the destination URL.
This commit is contained in:
Hans-Christoph Steiner 2016-01-01 22:09:36 +01:00
parent 8aa5f87a1c
commit 5533f6ba86
4 changed files with 10 additions and 29 deletions

View file

@ -57,7 +57,7 @@ public class DownloadDialog extends DialogFragment {
@Override
public void onClick(DialogInterface dialog, int which) {
Context context = getActivity();
SharedPreferences defaultPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String suffix = "";
String title = arguments.getString(TITLE);
String url = "";
@ -73,10 +73,10 @@ public class DownloadDialog extends DialogFragment {
default:
Log.d(TAG, "lolz");
}
//to avoid hard-coded string like "/storage/emulated/0/NewPipe"
final File dir = new File(defaultPreferences.getString(
"download_path_preference",
Environment.getExternalStorageDirectory().getAbsolutePath() + "/NewPipe"));
//to avoid hard-coded string like "/storage/emulated/0/Movies"
String downloadPath = prefs.getString(getString(R.string.downloadPathPreference),
Environment.getExternalStorageDirectory().getAbsolutePath() + "/Movies");
final File dir = new File(downloadPath);
if(!dir.exists()) {
boolean mkdir = dir.mkdir(); //attempt to create directory
if(!mkdir && !dir.isDirectory()) {
@ -87,9 +87,7 @@ public class DownloadDialog extends DialogFragment {
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(url));
request.setDestinationUri(Uri.fromFile(new File(
defaultPreferences.getString("download_path_preference", "/storage/emulated/0/NewPipe")
+ "/" + title + suffix)));
request.setDestinationUri(Uri.fromFile(new File(dir + "/" + title + suffix)));
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
try {
dm.enqueue(request);