From eb0df2b1013fe46c649a6ab7ae340ef4f4913242 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Tue, 5 Jan 2016 21:11:15 +0100 Subject: [PATCH] set download path on startup --- app/src/main/java/org/schabi/newpipe/App.java | 4 ++++ .../java/org/schabi/newpipe/DownloadDialog.java | 4 +++- .../java/org/schabi/newpipe/SettingsActivity.java | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index debb1a2a5..55e782259 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -23,6 +23,10 @@ public class App extends Application { } else { configureTor(false); } + + // DO NOT REMOVE THIS FUNCTION!!! + // Otherwise downloadPathPreference has invalid value. + SettingsActivity.initSettings(this); } /** diff --git a/app/src/main/java/org/schabi/newpipe/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/DownloadDialog.java index 1f018618a..dbada86a6 100644 --- a/app/src/main/java/org/schabi/newpipe/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/DownloadDialog.java @@ -81,12 +81,14 @@ public class DownloadDialog extends DialogFragment { Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + downloadFolder); final File dir = new File(downloadPath); if(!dir.exists()) { - boolean mkdir = dir.mkdir(); //attempt to create directory + //attempt to create directory + boolean mkdir = dir.mkdir(); if(!mkdir && !dir.isDirectory()) { Log.e(TAG, "Cant' create directory named " + dir.toString()); //TODO notify user "download directory should be changed" ? } } + String saveFilePath = dir + "/" + title + suffix; if (App.isUsingTor()) { // if using Tor, do not use DownloadManager because the proxy cannot be set diff --git a/app/src/main/java/org/schabi/newpipe/SettingsActivity.java b/app/src/main/java/org/schabi/newpipe/SettingsActivity.java index 3f747c2da..680c8996d 100644 --- a/app/src/main/java/org/schabi/newpipe/SettingsActivity.java +++ b/app/src/main/java/org/schabi/newpipe/SettingsActivity.java @@ -7,6 +7,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Bundle; +import android.os.Environment; import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; import android.preference.ListPreference; @@ -245,4 +246,17 @@ 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(); + } + } }