diff --git a/app/src/main/java/org/schabi/newpipe/Localization.java b/app/src/main/java/org/schabi/newpipe/Localization.java
index b38c52a90..796b7878d 100644
--- a/app/src/main/java/org/schabi/newpipe/Localization.java
+++ b/app/src/main/java/org/schabi/newpipe/Localization.java
@@ -1,6 +1,5 @@
package org.schabi.newpipe;
-import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
@@ -22,7 +21,8 @@ public class Localization {
public static Locale getPreferredLocale(Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
- String languageCode = sp.getString(String.valueOf(R.string.searchLanguage), "en");
+ String languageCode = sp.getString(String.valueOf(R.string.searchLanguagePreference),
+ context.getString(R.string.defaultLanguageItem));
if(languageCode.length() == 2) {
return new Locale(languageCode);
diff --git a/app/src/main/java/org/schabi/newpipe/SettingsActivity.java b/app/src/main/java/org/schabi/newpipe/SettingsActivity.java
index f599ebd8b..bfc2a158c 100644
--- a/app/src/main/java/org/schabi/newpipe/SettingsActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/SettingsActivity.java
@@ -1,14 +1,19 @@
package org.schabi.newpipe;
import android.app.Activity;
+import android.app.SharedElementCallback;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
+import android.preference.EditTextPreference;
+import android.preference.ListPreference;
import android.preference.Preference;
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;
@@ -40,7 +45,7 @@ import info.guardianproject.netcipher.proxy.OrbotHelper;
* along with NewPipe. If not, see .
*/
-public class SettingsActivity extends PreferenceActivity {
+public class SettingsActivity extends PreferenceActivity {
private static final int REQUEST_INSTALL_ORBOT = 0x1234;
private AppCompatDelegate mDelegate = null;
@@ -59,17 +64,52 @@ public class SettingsActivity extends PreferenceActivity {
}
- public static class SettingsFragment extends PreferenceFragment {
+ public static class SettingsFragment extends PreferenceFragment{
+ SharedPreferences.OnSharedPreferenceChangeListener prefListener;
+
+ // get keys
+ String DEFAULT_RESOLUTION_PREFERENCE;
+ String DEFAULT_AUDIO_FORMAT_PREFERENCE;
+ String SEARCH_LANGUAGE_PREFERENCE;
+ String DOWNLOAD_PATH_PREFERENCE;
+ String USE_TOR_KEY;
+
+ private ListPreference defaultResolutionPreference;
+ private ListPreference defaultAudioFormatPreference;
+ private ListPreference searchLanguagePreference;
+ private EditTextPreference downloadPathPreference;
private CheckBoxPreference useTorCheckBox;
+ private SharedPreferences defaultPreferences;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings_screen);
- // if Orbot is installed, then default to using Tor, the user can still override
- useTorCheckBox = (CheckBoxPreference) findPreference(getString(R.string.useTor));
final Activity activity = getActivity();
+
+ defaultPreferences = PreferenceManager.getDefaultSharedPreferences(activity);
+
+ // get keys
+ DEFAULT_RESOLUTION_PREFERENCE =getString(R.string.defaultResolutionPreference);
+ DEFAULT_AUDIO_FORMAT_PREFERENCE =getString(R.string.defaultAudioFormatPreference);
+ SEARCH_LANGUAGE_PREFERENCE =getString(R.string.searchLanguagePreference);
+ DOWNLOAD_PATH_PREFERENCE = getString(R.string.downloadPathPreference);
+ USE_TOR_KEY = getString(R.string.useTorKey);
+
+ // get pref objects
+ defaultResolutionPreference =
+ (ListPreference) findPreference(DEFAULT_RESOLUTION_PREFERENCE);
+ defaultAudioFormatPreference =
+ (ListPreference) findPreference(DEFAULT_AUDIO_FORMAT_PREFERENCE);
+ searchLanguagePreference =
+ (ListPreference) findPreference(SEARCH_LANGUAGE_PREFERENCE);
+ downloadPathPreference =
+ (EditTextPreference) findPreference(DOWNLOAD_PATH_PREFERENCE);
+ useTorCheckBox = (CheckBoxPreference) findPreference(USE_TOR_KEY);
+
+ // if Orbot is installed, then default to using Tor, the user can still override
final boolean useTor = OrbotHelper.isOrbotInstalled(activity);
useTorCheckBox.setDefaultValue(useTor);
useTorCheckBox.setChecked(useTor);
@@ -90,6 +130,33 @@ public class SettingsActivity extends PreferenceActivity {
return true;
}
});
+
+ prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
+ String key) {
+ updateSummary();
+ }
+ };
+ defaultPreferences.registerOnSharedPreferenceChangeListener(prefListener);
+
+ updateSummary();
+ }
+
+ // This is used to show the status of some preference in the description
+ private void updateSummary() {
+ defaultResolutionPreference.setSummary(
+ defaultPreferences.getString(DEFAULT_RESOLUTION_PREFERENCE,
+ getString(R.string.defaultResolutionListItem)));
+ defaultAudioFormatPreference.setSummary(
+ defaultPreferences.getString(DEFAULT_AUDIO_FORMAT_PREFERENCE,
+ getString(R.string.defaultAudioFormat)));
+ searchLanguagePreference.setSummary(
+ defaultPreferences.getString(SEARCH_LANGUAGE_PREFERENCE,
+ getString(R.string.defaultLanguageItem)));
+ downloadPathPreference.setSummary(
+ defaultPreferences.getString(DOWNLOAD_PATH_PREFERENCE,
+ getString(R.string.downloadLocationSummary)));
}
}
diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java
index 93c6074b2..8c9c61456 100644
--- a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java
@@ -99,8 +99,9 @@ public class VideoItemListFragment extends ListFragment {
public void run() {
try {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
- String searchLanguageKey = getContext().getString(R.string.searchLanguage);
- String searchLanguage = sp.getString(searchLanguageKey, "en");
+ String searchLanguageKey = getContext().getString(R.string.searchLanguagePreference);
+ String searchLanguage = sp.getString(searchLanguageKey,
+ getString(R.string.defaultLanguageItem));
SearchEngine.Result result = engine.search(query, page, searchLanguage);
Log.i(TAG, "language code passed:\""+searchLanguage+"\"");
if(run) {
diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml
index 0ff359a46..a909953ae 100644
--- a/app/src/main/res/values/settings_keys.xml
+++ b/app/src/main/res/values/settings_keys.xml
@@ -29,7 +29,8 @@
m4a
show_next_video
- search_language
+ search_language
+ use_tor
@@ -111,6 +112,7 @@
- ja
- ko
+ en
- Afrikaans
- Azərbaycan
diff --git a/app/src/main/res/xml/settings_screen.xml b/app/src/main/res/xml/settings_screen.xml
index 4d21b457b..f4de87d49 100644
--- a/app/src/main/res/xml/settings_screen.xml
+++ b/app/src/main/res/xml/settings_screen.xml
@@ -43,11 +43,11 @@
android:defaultValue="false" />
+ android:defaultValue="@string/defaultLanguageItem" />