1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-11-16 06:44:55 +00:00

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);

View File

@ -1,13 +1,9 @@
package org.schabi.newpipe;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
@ -148,17 +144,4 @@ public class SettingsActivity extends PreferenceActivity {
}
return true;
}
public static void initSettings(Context context) {
PreferenceManager.setDefaultValues(context, R.xml.settings_screen, false);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
if(sp.getString(context.getString(R.string.downloadPathPreference), "").isEmpty()){
SharedPreferences.Editor spEditor = sp.edit();
String newPipeDownloadStorage =
Environment.getExternalStorageDirectory().getAbsolutePath() + "/NewPipe";
spEditor.putString(context.getString(R.string.downloadPathPreference)
, newPipeDownloadStorage);
spEditor.apply();
}
}
}

View File

@ -3,6 +3,7 @@ package org.schabi.newpipe;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
@ -171,7 +172,7 @@ public class VideoItemListActivity extends AppCompatActivity
}
}
SettingsActivity.initSettings(this);
PreferenceManager.setDefaultValues(this, R.xml.settings_screen, false);
}
/**

View File

@ -64,8 +64,7 @@
android:key="@string/downloadPathPreference"
android:title="@string/downloadLocation"
android:summary="@string/downloadLocationSummary"
android:dialogTitle="@string/downloadLocationDialogTitle"
android:defaultValue=""/>
android:dialogTitle="@string/downloadLocationDialogTitle" />
<CheckBoxPreference
android:key="@string/autoPlayThroughIntent"