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

View File

@ -1,13 +1,9 @@
package org.schabi.newpipe; package org.schabi.newpipe;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
@ -148,17 +144,4 @@ public class SettingsActivity extends PreferenceActivity {
} }
return true; 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.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.NavUtils; import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView; 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:key="@string/downloadPathPreference"
android:title="@string/downloadLocation" android:title="@string/downloadLocation"
android:summary="@string/downloadLocationSummary" android:summary="@string/downloadLocationSummary"
android:dialogTitle="@string/downloadLocationDialogTitle" android:dialogTitle="@string/downloadLocationDialogTitle" />
android:defaultValue=""/>
<CheckBoxPreference <CheckBoxPreference
android:key="@string/autoPlayThroughIntent" android:key="@string/autoPlayThroughIntent"