From 50ed962a8286648eaff2657c2f65258c9208e0d8 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Sat, 25 Feb 2017 15:34:45 -0300 Subject: [PATCH 1/3] Add necessary strings --- app/src/main/res/values/strings.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b0db9a2e1..f90b3bb3e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -86,6 +86,8 @@ Error report All Channel + Yes + Later Error @@ -155,6 +157,7 @@ K M B + Restart Start @@ -183,6 +186,7 @@ Please wait… Copied to clipboard. Please select an available download directory. + You have to restart the application to apply the theme.\n\nDo you want to restart now? MD5 From f8d9e0fa60022f93a84988b5ffcda5b08b5340f0 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Sat, 25 Feb 2017 15:36:31 -0300 Subject: [PATCH 2/3] Implement restart dialog --- .../newpipe/settings/SettingsFragment.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SettingsFragment.java index a6466daf9..48940138e 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsFragment.java @@ -1,27 +1,27 @@ package org.schabi.newpipe.settings; import android.app.Activity; -import android.app.ListActivity; import android.content.ClipData; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.preference.PreferenceScreen; +import android.support.v7.app.AlertDialog; import com.nononsenseapps.filepicker.FilePickerActivity; import org.schabi.newpipe.App; +import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; import java.util.ArrayList; -import java.util.Objects; import info.guardianproject.netcipher.proxy.OrbotHelper; @@ -141,6 +141,23 @@ public class SettingsFragment extends PreferenceFragment { String theme = sharedPreferences.getString(THEME, "Light"); themePreference.setSummary(theme); + + new AlertDialog.Builder(activity) + .setTitle(R.string.restart_title) + .setMessage(R.string.msg_restart) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intentToMain = new Intent(activity, MainActivity.class); + intentToMain.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + activity.startActivity(intentToMain); + + activity.finish(); + Runtime.getRuntime().exit(0); + } + }) + .setNegativeButton(R.string.later, null) + .create().show(); } updateSummary(); } From 6ec393699eef298018cf3aa6e04b3db5c2b7f6dc Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Sat, 25 Feb 2017 16:04:10 -0300 Subject: [PATCH 3/3] Check if selected theme it's not the current --- .../newpipe/settings/SettingsFragment.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SettingsFragment.java index 48940138e..c4eae1baf 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsFragment.java @@ -98,6 +98,8 @@ public class SettingsFragment extends PreferenceFragment downloadPathAudioPreference = findPreference(DOWNLOAD_PATH_AUDIO_PREFERENCE); themePreference = findPreference(THEME); + final String currentTheme = defaultPreferences.getString(THEME, "Light"); + prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, @@ -139,25 +141,27 @@ public class SettingsFragment extends PreferenceFragment } else if (key == THEME) { - String theme = sharedPreferences.getString(THEME, "Light"); - themePreference.setSummary(theme); + String selectedTheme = sharedPreferences.getString(THEME, "Light"); + themePreference.setSummary(selectedTheme); - new AlertDialog.Builder(activity) - .setTitle(R.string.restart_title) - .setMessage(R.string.msg_restart) - .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Intent intentToMain = new Intent(activity, MainActivity.class); - intentToMain.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); - activity.startActivity(intentToMain); + if(!selectedTheme.equals(currentTheme)) { // If it's not the current theme + new AlertDialog.Builder(activity) + .setTitle(R.string.restart_title) + .setMessage(R.string.msg_restart) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intentToMain = new Intent(activity, MainActivity.class); + intentToMain.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + activity.startActivity(intentToMain); - activity.finish(); - Runtime.getRuntime().exit(0); - } - }) - .setNegativeButton(R.string.later, null) - .create().show(); + activity.finish(); + Runtime.getRuntime().exit(0); + } + }) + .setNegativeButton(R.string.later, null) + .create().show(); + } } updateSummary(); }