set download path on startup

pull/141/head
Christian Schabesberger 2016-01-05 21:11:15 +01:00
rodzic 0aade598ff
commit eb0df2b101
3 zmienionych plików z 21 dodań i 1 usunięć

Wyświetl plik

@ -23,6 +23,10 @@ public class App extends Application {
} else { } else {
configureTor(false); configureTor(false);
} }
// DO NOT REMOVE THIS FUNCTION!!!
// Otherwise downloadPathPreference has invalid value.
SettingsActivity.initSettings(this);
} }
/** /**

Wyświetl plik

@ -81,12 +81,14 @@ public class DownloadDialog extends DialogFragment {
Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + downloadFolder); Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + downloadFolder);
final File dir = new File(downloadPath); final File dir = new File(downloadPath);
if(!dir.exists()) { if(!dir.exists()) {
boolean mkdir = dir.mkdir(); //attempt to create directory //attempt to create directory
boolean mkdir = dir.mkdir();
if(!mkdir && !dir.isDirectory()) { if(!mkdir && !dir.isDirectory()) {
Log.e(TAG, "Cant' create directory named " + dir.toString()); Log.e(TAG, "Cant' create directory named " + dir.toString());
//TODO notify user "download directory should be changed" ? //TODO notify user "download directory should be changed" ?
} }
} }
String saveFilePath = dir + "/" + title + suffix; String saveFilePath = dir + "/" + title + suffix;
if (App.isUsingTor()) { if (App.isUsingTor()) {
// if using Tor, do not use DownloadManager because the proxy cannot be set // if using Tor, do not use DownloadManager because the proxy cannot be set

Wyświetl plik

@ -7,6 +7,7 @@ import android.content.Intent;
import android.content.SharedPreferences; 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.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference; import android.preference.EditTextPreference;
import android.preference.ListPreference; import android.preference.ListPreference;
@ -245,4 +246,17 @@ 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();
}
}
} }