2016-08-02 21:17:54 +02:00
|
|
|
package org.schabi.newpipe.settings;
|
2016-01-07 14:22:55 +01:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Environment;
|
2020-03-31 19:20:15 +02:00
|
|
|
|
2019-10-04 14:59:08 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2020-03-31 19:20:15 +02:00
|
|
|
import androidx.preference.PreferenceManager;
|
2016-01-07 14:22:55 +01:00
|
|
|
|
2016-08-02 21:17:54 +02:00
|
|
|
import org.schabi.newpipe.R;
|
|
|
|
|
2016-01-07 14:22:55 +01:00
|
|
|
import java.io.File;
|
|
|
|
|
2017-09-03 08:04:18 +02:00
|
|
|
/*
|
2020-03-31 19:20:15 +02:00
|
|
|
* Created by k3b on 07.01.2016.
|
|
|
|
*
|
|
|
|
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
|
2016-09-12 00:33:11 +02:00
|
|
|
* NewPipeSettings.java is part of NewPipe.
|
|
|
|
*
|
|
|
|
* NewPipe is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* NewPipe is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
/**
|
|
|
|
* Helper class for global settings.
|
|
|
|
*/
|
|
|
|
public final class NewPipeSettings {
|
|
|
|
private NewPipeSettings() { }
|
2016-03-10 10:50:42 +01:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static void initSettings(final Context context) {
|
2017-09-03 08:04:18 +02:00
|
|
|
PreferenceManager.setDefaultValues(context, R.xml.appearance_settings, true);
|
|
|
|
PreferenceManager.setDefaultValues(context, R.xml.content_settings, true);
|
|
|
|
PreferenceManager.setDefaultValues(context, R.xml.download_settings, true);
|
|
|
|
PreferenceManager.setDefaultValues(context, R.xml.history_settings, true);
|
|
|
|
PreferenceManager.setDefaultValues(context, R.xml.main_settings, true);
|
|
|
|
PreferenceManager.setDefaultValues(context, R.xml.video_audio_settings, true);
|
2018-02-21 06:09:57 +01:00
|
|
|
PreferenceManager.setDefaultValues(context, R.xml.debug_settings, true);
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2019-08-17 18:38:33 +02:00
|
|
|
getVideoDownloadFolder(context);
|
|
|
|
getAudioDownloadFolder(context);
|
2016-01-07 14:22:55 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private static void getVideoDownloadFolder(final Context context) {
|
2019-04-05 19:45:39 +02:00
|
|
|
getDir(context, R.string.download_path_video_key, Environment.DIRECTORY_MOVIES);
|
2016-01-07 14:22:55 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private static void getAudioDownloadFolder(final Context context) {
|
2019-04-05 19:45:39 +02:00
|
|
|
getDir(context, R.string.download_path_audio_key, Environment.DIRECTORY_MUSIC);
|
2016-01-07 14:22:55 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private static void getDir(final Context context, final int keyID,
|
|
|
|
final String defaultDirectoryName) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
2016-01-07 14:22:55 +01:00
|
|
|
final String key = context.getString(keyID);
|
2020-08-16 10:24:58 +02:00
|
|
|
final String downloadPath = prefs.getString(key, null);
|
2020-03-31 19:20:15 +02:00
|
|
|
if ((downloadPath != null) && (!downloadPath.isEmpty())) {
|
|
|
|
return;
|
|
|
|
}
|
2016-01-07 14:22:55 +01:00
|
|
|
|
2020-08-16 10:24:58 +02:00
|
|
|
final SharedPreferences.Editor spEditor = prefs.edit();
|
2019-04-05 19:45:39 +02:00
|
|
|
spEditor.putString(key, getNewPipeChildFolderPathForDir(getDir(defaultDirectoryName)));
|
2016-01-07 14:22:55 +01:00
|
|
|
spEditor.apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
2020-03-31 19:20:15 +02:00
|
|
|
public static File getDir(final String defaultDirectoryName) {
|
2017-09-03 08:04:18 +02:00
|
|
|
return new File(Environment.getExternalStorageDirectory(), defaultDirectoryName);
|
2016-01-07 14:22:55 +01:00
|
|
|
}
|
2018-08-17 18:50:35 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private static String getNewPipeChildFolderPathForDir(final File dir) {
|
2019-04-19 21:18:19 +02:00
|
|
|
return new File(dir, "NewPipe").toURI().toString();
|
2018-08-24 17:42:35 +02:00
|
|
|
}
|
2019-08-14 20:30:34 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public static boolean useStorageAccessFramework(final Context context) {
|
2019-08-17 18:38:33 +02:00
|
|
|
final String key = context.getString(R.string.storage_use_saf);
|
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
2019-08-14 20:30:34 +02:00
|
|
|
|
2019-08-17 18:38:33 +02:00
|
|
|
return prefs.getBoolean(key, false);
|
2019-08-14 20:30:34 +02:00
|
|
|
}
|
2019-08-17 18:38:33 +02:00
|
|
|
|
2016-01-07 14:22:55 +01:00
|
|
|
}
|