diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/DiasporaStreamFragment.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/DiasporaStreamFragment.java index 2e02f5fe..b2ab2cb3 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/DiasporaStreamFragment.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/DiasporaStreamFragment.java @@ -30,7 +30,6 @@ import android.os.Build; import android.os.Bundle; import android.provider.MediaStore; import android.support.design.widget.Snackbar; -import android.support.v7.app.AlertDialog; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -43,6 +42,7 @@ import android.webkit.WebView; import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.data.DiasporaUserProfile; +import com.github.dfa.diaspora_android.ui.theme.ThemedAlertDialogBuilder; import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.DiasporaUrlHelper; import com.github.dfa.diaspora_android.util.Helpers; @@ -247,7 +247,7 @@ public class DiasporaStreamFragment extends BrowserFragment { int hasWRITE_EXTERNAL_STORAGE = getActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) { if (!shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - new AlertDialog.Builder(getContext()) + new ThemedAlertDialogBuilder(getContext(), appSettings) .setMessage(R.string.permissions_image) .setNegativeButton(android.R.string.no, null) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java index f5153fd7..fbc15087 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java @@ -39,6 +39,7 @@ import android.support.v4.content.LocalBroadcastManager; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v7.app.AlertDialog; import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.Toolbar; import android.view.KeyEvent; @@ -69,6 +70,7 @@ import com.github.dfa.diaspora_android.ui.PodSelectionDialog; import com.github.dfa.diaspora_android.ui.theme.CustomFragment; import com.github.dfa.diaspora_android.ui.theme.ThemeHelper; import com.github.dfa.diaspora_android.ui.theme.ThemedActivity; +import com.github.dfa.diaspora_android.ui.theme.ThemedAlertDialogBuilder; import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.AppSettings; import com.github.dfa.diaspora_android.util.DiasporaUrlHelper; @@ -485,7 +487,7 @@ public class MainActivity extends ThemedActivity return; } //Catch split screen recreation - if (action.equals(Intent.ACTION_MAIN) && getTopFragment() != null) { + if (action != null && action.equals(Intent.ACTION_MAIN) && getTopFragment() != null) { return; } @@ -774,7 +776,7 @@ public class MainActivity extends ThemedActivity } }; - final android.support.v7.app.AlertDialog dialog = new android.support.v7.app.AlertDialog.Builder(this) + final AlertDialog dialog = new ThemedAlertDialogBuilder(this, appSettings) .setView(layout).setTitle(R.string.search_alert_title) .setCancelable(true) .setPositiveButton(R.string.search_alert_tag, clickListener) diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java index 07887dfa..2e10b627 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java @@ -2,7 +2,6 @@ package com.github.dfa.diaspora_android.activity; import android.annotation.SuppressLint; import android.app.AlarmManager; -import android.app.AlertDialog; import android.app.FragmentTransaction; import android.app.PendingIntent; import android.content.Context; @@ -27,6 +26,7 @@ import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.ui.theme.ColorPalette; import com.github.dfa.diaspora_android.ui.theme.ThemeHelper; import com.github.dfa.diaspora_android.ui.theme.ThemedActivity; +import com.github.dfa.diaspora_android.ui.theme.ThemedAlertDialogBuilder; import com.github.dfa.diaspora_android.ui.theme.ThemedPreferenceFragment; import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.AppSettings; @@ -215,7 +215,7 @@ public class SettingsActivity extends ThemedActivity { getActivity().finish(); return true; } else if (settings.isKeyEqual(key, R.string.pref_key__change_account)) { - new AlertDialog.Builder(getActivity()) + new ThemedAlertDialogBuilder(getActivity(), new AppSettings(getActivity().getApplication())) .setTitle(getString(R.string.confirmation)) .setMessage(getString(R.string.pref_warning__change_account)) .setNegativeButton(android.R.string.no, null) @@ -293,7 +293,7 @@ public class SettingsActivity extends ThemedActivity { //Inflate dialog layout LayoutInflater inflater = getActivity().getLayoutInflater(); View dialogLayout = inflater.inflate(R.layout.ui__dialog__color_picker, null); - final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context); + final ThemedAlertDialogBuilder builder = new ThemedAlertDialogBuilder(context, appSettings); builder.setView(dialogLayout); final FrameLayout titleBackground = (FrameLayout) dialogLayout.findViewById(R.id.color_picker_dialog__title_background); @@ -449,5 +449,39 @@ public class SettingsActivity extends ThemedActivity { public String getFragmentTag() { return TAG; } + + @Override + public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) { + if (isAdded() && preference.hasKey()) { + AppSettings appSettings = ((App) getActivity().getApplication()).getSettings(); + String key = preference.getKey(); + if (appSettings.isKeyEqual(key, R.string.pref_key__wipe_settings)) { + showWipeSettingsDialog(); + return true; + } + } + return super.onPreferenceTreeClick(screen, preference); + } + + private void showWipeSettingsDialog() { + final AppSettings appSettings = new AppSettings(this.getActivity().getApplication()); + + ThemedAlertDialogBuilder builder = new ThemedAlertDialogBuilder(getActivity(), appSettings); + builder.setTitle(R.string.confirmation) + .setMessage(R.string.dialog_content__wipe_settings) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + appSettings.clearAppSettings(); + appSettings.clearPodSettings(); + Intent restartActivity = new Intent(getActivity(), MainActivity.class); + PendingIntent pendingIntent = PendingIntent.getActivity(getActivity(), 12374, restartActivity, PendingIntent.FLAG_CANCEL_CURRENT); + AlarmManager mgr = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE); + mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent); + System.exit(0); + } + }).setNegativeButton(android.R.string.cancel, null) + .create().show(); + } } } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/BadgeDrawable.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/BadgeDrawable.java index ef74eafc..f296f6f8 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/BadgeDrawable.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/BadgeDrawable.java @@ -88,7 +88,7 @@ public class BadgeDrawable extends Drawable { canvas.drawCircle(centerX, centerY, (int) (radius + 6.5), badgeBackground); //canvas.drawRoundRect(radius, radius, radius, radius, 10, 10, badgeBackground); } - // Draw badge count text inside the circle. + // Draw badge count message inside the circle. badgeText.getTextBounds(badgeValue, 0, badgeValue.length(), textRect); float textHeight = textRect.bottom - textRect.top; float textY = centerY + (textHeight / 2f); diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/HtmlTextView.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/HtmlTextView.java index fca6c04c..0f9a8455 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/HtmlTextView.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/HtmlTextView.java @@ -62,7 +62,7 @@ public class HtmlTextView extends TextView { } /** - * Linkify, format markdown and escape the displayed text. + * Linkify, format markdown and escape the displayed message. */ private void init() { formatHtmlAndCustomTags(); diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemeHelper.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemeHelper.java index 0251bae2..cb8c95a5 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemeHelper.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemeHelper.java @@ -40,6 +40,7 @@ import android.widget.RadioGroup; import android.widget.TextView; import com.github.dfa.diaspora_android.R; +import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.AppSettings; /** @@ -159,7 +160,10 @@ public class ThemeHelper { public static void updateAlertDialogColor(AlertDialog alertDialog) { if(alertDialog != null) { - for(int i : new int[]{DialogInterface.BUTTON_POSITIVE, DialogInterface.BUTTON_NEGATIVE, DialogInterface.BUTTON_NEUTRAL}) { + for(int i : new int[]{ + DialogInterface.BUTTON_POSITIVE, + DialogInterface.BUTTON_NEUTRAL, + DialogInterface.BUTTON_NEGATIVE}) { Button b = alertDialog.getButton(i); if(b != null) { b.setTextColor(getAccentColor()); diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedActivity.java index c01236c4..169f47ea 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedActivity.java @@ -22,6 +22,7 @@ import android.annotation.TargetApi; import android.app.ActivityManager; import android.graphics.drawable.BitmapDrawable; import android.os.Build; +import android.support.v4.app.FragmentManager; import android.support.v7.app.AppCompatActivity; import com.github.dfa.diaspora_android.App; diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedAlertDialogBuilder.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedAlertDialogBuilder.java index be6fa57c..c5a3cde7 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedAlertDialogBuilder.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedAlertDialogBuilder.java @@ -1,6 +1,7 @@ package com.github.dfa.diaspora_android.ui.theme; import android.content.Context; +import android.content.DialogInterface; import android.support.annotation.NonNull; import android.support.annotation.StyleRes; import android.support.v7.app.AlertDialog; @@ -27,8 +28,13 @@ public class ThemedAlertDialogBuilder extends AlertDialog.Builder { @Override public AlertDialog create() { - AlertDialog dialog = super.create(); - applyColors(dialog); + final AlertDialog dialog = super.create(); + dialog.setOnShowListener(new DialogInterface.OnShowListener() { + @Override + public void onShow(DialogInterface dialogInterface) { + applyColors(dialog); + } + }); return dialog; } @@ -36,5 +42,4 @@ public class ThemedAlertDialogBuilder extends AlertDialog.Builder { ThemeHelper.getInstance(appSettings); ThemeHelper.updateAlertDialogColor(alertDialog); } - } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedAppCompatDialogFragment.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedAppCompatDialogFragment.java index 342026cb..11e6f707 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedAppCompatDialogFragment.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedAppCompatDialogFragment.java @@ -2,6 +2,7 @@ package com.github.dfa.diaspora_android.ui.theme; import android.app.Dialog; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v7.app.AppCompatDialogFragment; import com.github.dfa.diaspora_android.util.AppSettings; @@ -13,6 +14,7 @@ import com.github.dfa.diaspora_android.util.AppSettings; public abstract class ThemedAppCompatDialogFragment extends AppCompatDialogFragment { + @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = super.onCreateDialog(savedInstanceState); diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/AppSettings.java b/app/src/main/java/com/github/dfa/diaspora_android/util/AppSettings.java index bb7ffac4..9cd1f6a2 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/AppSettings.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/AppSettings.java @@ -50,15 +50,15 @@ public class AppSettings { } public void clearPodSettings() { - prefPod.edit().clear().apply(); + prefPod.edit().clear().commit(); } public void clearAppSettings() { - prefApp.edit().clear().apply(); + prefApp.edit().clear().commit(); } - public String getKey(int stringKeyRessourceId) { - return context.getString(stringKeyRessourceId); + public String getKey(int stringKeyResourceId) { + return context.getString(stringKeyResourceId); } public boolean isKeyEqual(String key, int stringKeyRessourceId) { diff --git a/app/src/main/res/values/strings-preferences.xml b/app/src/main/res/values/strings-preferences.xml index 16fec09c..2e8a1ae8 100644 --- a/app/src/main/res/values/strings-preferences.xml +++ b/app/src/main/res/values/strings-preferences.xml @@ -61,6 +61,7 @@ pref_catkey__category_more pref_key__logging_spam_enabled pref_key__logging_enabled + pref_key__wipe_settings Appearance @@ -153,10 +154,15 @@ @string/about_activity__title_debug_info @string/fragment_debug__section_log + Miscellaneous @string/fragment_debug__section_log @string/fragment_debug__section_log_spam + Full Reset + Locally wipe all settings related to the app and log out from all accounts + + This will reset all changed settings of the app to their default values and log you out from all pods. Your downloaded images will stay untouched. Are you sure you want to proceed? diff --git a/app/src/main/res/xml/preferences__sub_debugging.xml b/app/src/main/res/xml/preferences__sub_debugging.xml index 1bbea14f..8115f012 100644 --- a/app/src/main/res/xml/preferences__sub_debugging.xml +++ b/app/src/main/res/xml/preferences__sub_debugging.xml @@ -1,5 +1,7 @@ + + @@ -14,4 +16,16 @@ android:title="@string/pref_title__logging_spam_enabled" android:dependency="@string/pref_key__logging_enabled"/> + + + + + + + + \ No newline at end of file