From a8830e2ede6eed37145eb745507dbc595aac1a3c Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 3 Jan 2016 19:55:04 +0100 Subject: [PATCH 1/4] preference screen previews set values --- .../java/org/schabi/newpipe/Localization.java | 4 +- .../org/schabi/newpipe/SettingsActivity.java | 75 ++++++++++++++++++- .../schabi/newpipe/VideoItemListFragment.java | 5 +- app/src/main/res/values/settings_keys.xml | 4 +- app/src/main/res/xml/settings_screen.xml | 6 +- 5 files changed, 82 insertions(+), 12 deletions(-) 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" /> From f451e11f82fe5de0fb6cfb6a9f760bd4fa503325 Mon Sep 17 00:00:00 2001 From: M2ck Date: Sun, 3 Jan 2016 20:51:48 +0100 Subject: [PATCH 2/4] Translated using Weblate (French) Currently translated at 100.0% (53 of 53 strings) --- app/src/main/res/values-fr/strings.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 227877c52..9e241c54c 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -54,4 +54,6 @@ Chargement Lecture - + Utiliser Tor + Forcer le trafic de téléchargement via Tor pour plus de confidentialité (vidéos streaming non supporté) + From 5c492c01a174a0e509cceebc1312a0c9a6272095 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 4 Jan 2016 00:10:51 +0100 Subject: [PATCH 3/4] adjusted orbot support and moved on to 0.7.2 --- README.md | 1 + app/build.gradle | 4 +-- app/src/main/java/org/schabi/newpipe/App.java | 11 +++--- .../java/org/schabi/newpipe/Downloader.java | 12 +++---- .../org/schabi/newpipe/SettingsActivity.java | 35 +++++++------------ .../newpipe/services/VideoExtractor.java | 1 + app/src/main/res/xml/settings_screen.xml | 3 +- 7 files changed, 32 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index e6d1d9498..b24ed14af 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ NewPipe does not use any Google framework libraries, or the YouTube API. It only * Open a video in Kodi * Show Next/Related videos * Search YouTube in a specific language +* Orbot/Tor support (no streaming yet) ### Coming Features diff --git a/app/build.gradle b/app/build.gradle index 9eb3ccef7..5eaf3a6c4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "org.schabi.newpipe" minSdkVersion 15 targetSdkVersion 23 - versionCode 10 - versionName "0.7.1" + versionCode 11 + versionName "0.7.2" } buildTypes { release { diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index 877000e61..debb1a2a5 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -15,10 +15,13 @@ public class App extends Application { @Override public void onCreate() { super.onCreate(); - // if Orbot is installed, then default to using Tor, the user can still override - if (OrbotHelper.requestStartTor(this)) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - configureTor(prefs.getBoolean(getString(R.string.useTor), true)); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + if(prefs.getBoolean(getString(R.string.useTorKey), false)) { + OrbotHelper.requestStartTor(this); + configureTor(true); + } else { + configureTor(false); } } diff --git a/app/src/main/java/org/schabi/newpipe/Downloader.java b/app/src/main/java/org/schabi/newpipe/Downloader.java index 8a296c61e..cbc4c26c2 100644 --- a/app/src/main/java/org/schabi/newpipe/Downloader.java +++ b/app/src/main/java/org/schabi/newpipe/Downloader.java @@ -1,23 +1,23 @@ package org.schabi.newpipe; -import android.app.Notification; + import android.app.NotificationManager; import android.content.Context; +import android.content.SharedPreferences; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.AsyncTask; +import android.preference.PreferenceManager; import android.support.v4.app.NotificationCompat; import android.util.Log; import java.io.BufferedInputStream; import java.io.BufferedReader; -import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; -import java.net.MalformedURLException; import java.net.URL; import java.net.UnknownHostException; @@ -47,7 +47,6 @@ import info.guardianproject.netcipher.NetCipher; public class Downloader { public static final String TAG = "Downloader"; - private static final String USER_AGENT = "Mozilla/5.0"; /**Download the text file at the supplied URL as in download(String), @@ -59,7 +58,7 @@ public class Downloader { String ret = ""; try { URL url = new URL(siteUrl); - HttpsURLConnection con = NetCipher.getHttpsURLConnection(url); + HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); con.setRequestProperty("Accept-Language", language); ret = dl(con); } @@ -68,8 +67,9 @@ public class Downloader { } return ret; } + /**Common functionality between download(String url) and download(String url, String language)*/ - private static String dl(HttpURLConnection con) throws IOException { + private static String dl(HttpsURLConnection con) throws IOException { StringBuilder response = new StringBuilder(); try { diff --git a/app/src/main/java/org/schabi/newpipe/SettingsActivity.java b/app/src/main/java/org/schabi/newpipe/SettingsActivity.java index bfc2a158c..3f747c2da 100644 --- a/app/src/main/java/org/schabi/newpipe/SettingsActivity.java +++ b/app/src/main/java/org/schabi/newpipe/SettingsActivity.java @@ -109,33 +109,24 @@ public class SettingsActivity extends PreferenceActivity { (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); - useTorCheckBox.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object o) { - boolean useTor = (Boolean) o; - if (useTor) { - if (OrbotHelper.isOrbotInstalled(activity)) { - App.configureTor(true); - } else { - Intent intent = OrbotHelper.getOrbotInstallIntent(activity); - activity.startActivityForResult(intent, REQUEST_INSTALL_ORBOT); - } - } else { - App.configureTor(false); - } - return true; - } - }); - prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + Activity a = getActivity(); updateSummary(); + + if (defaultPreferences.getBoolean(USE_TOR_KEY, false)) { + if (OrbotHelper.isOrbotInstalled(a)) { + App.configureTor(true); + OrbotHelper.requestStartTor(a); + } else { + Intent intent = OrbotHelper.getOrbotInstallIntent(a); + a.startActivityForResult(intent, REQUEST_INSTALL_ORBOT); + } + } else { + App.configureTor(false); + } } }; defaultPreferences.registerOnSharedPreferenceChangeListener(prefListener); diff --git a/app/src/main/java/org/schabi/newpipe/services/VideoExtractor.java b/app/src/main/java/org/schabi/newpipe/services/VideoExtractor.java index 9da25fc92..e9735b32e 100644 --- a/app/src/main/java/org/schabi/newpipe/services/VideoExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/services/VideoExtractor.java @@ -107,6 +107,7 @@ public abstract class VideoExtractor { } + //todo: add licence field protected abstract int getErrorCode(); protected abstract String getErrorMessage(); protected abstract String getVideoUrl(String videoId); diff --git a/app/src/main/res/xml/settings_screen.xml b/app/src/main/res/xml/settings_screen.xml index f4de87d49..46ad3ecb9 100644 --- a/app/src/main/res/xml/settings_screen.xml +++ b/app/src/main/res/xml/settings_screen.xml @@ -75,7 +75,8 @@ + android:summary="@string/useTorSummary" + android:defaultValue="false"/> From fb4bf0dde41801e8ef757cb6398572e2f03ee354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20Gei=C3=9Fler?= Date: Sun, 3 Jan 2016 21:32:40 +0100 Subject: [PATCH 4/4] Translated using Weblate (German) Currently translated at 98.1% (52 of 53 strings) --- app/src/main/res/values-de/strings.xml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index d17fae7bd..11478a6f7 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -44,10 +44,18 @@ VIDEO & AUDIO INFO ETC -Bevorzugte Sprache +Bevorzugte Sprache des Inhalts Video-Vorschau-Bild Video-Vorschau-Bild Nutzerbild - gefällt nicht - gefällt + Gefällt nicht + Gefällt +Lade + Benutze externen Videoabspieler + Benutze externen Audioabspieler + Spiele im Hintergrund ab + Abspielen + + Benutze TOR + Erzwinge das Herunterladen durch TOR für verbesserte Privatsphäre (Videostream noch nicht unterstützt)