1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-25 13:52:08 +01:00

Merged wipe-settings

This commit is contained in:
vanitasvitae 2016-11-06 16:29:19 +01:00
commit 73cb775af2
Signed by: vanitasvitae
GPG key ID: DCCFB3302C9E4615
12 changed files with 85 additions and 17 deletions

View file

@ -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() {

View file

@ -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)

View file

@ -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();
}
}
}

View file

@ -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);

View file

@ -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();

View file

@ -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());

View file

@ -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;

View file

@ -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();
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);
}
}

View file

@ -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);

View file

@ -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) {

View file

@ -61,6 +61,7 @@
<string name="pref_catkey__category_more" translatable="false">pref_catkey__category_more</string>
<string name="pref_key__logging_spam_enabled" translatable="false">pref_key__logging_spam_enabled</string>
<string name="pref_key__logging_enabled" translatable="false">pref_key__logging_enabled</string>
<string name="pref_key__wipe_settings" translatable="false">pref_key__wipe_settings</string>
<!-- Category Titles -->
<string name="pref_cat__visuals">Appearance</string>
@ -153,10 +154,15 @@
<!-- More -->
<string name="pref_title__sub_logging" translatable="false">@string/about_activity__title_debug_info</string>
<string name="pref_desc__sub_logging" translatable="false">@string/fragment_debug__section_log</string>
<string name="pref_title__sub_miscelaneous">Miscellaneous</string>
<string name="pref_title__logging_enabled" translatable="false">@string/fragment_debug__section_log</string>
<string name="pref_title__logging_spam_enabled" translatable="false">@string/fragment_debug__section_log_spam</string>
<string name="pref_title__wipe_settings">Full Reset</string>
<string name="pref_desc__wipe_settings">Locally wipe all settings related to the app and log out from all accounts</string>
<string name="dialog_content__wipe_settings">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?</string>
<!-- Recently added - Please move to right section-->
<!-- Sorry -->

View file

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Logging -->
<com.github.dfa.diaspora_android.ui.theme.ThemedPreferenceCategory
android:key="@string/pref_key__title__debugging"
android:title="@string/pref_title__sub_logging">
@ -14,4 +16,16 @@
android:title="@string/pref_title__logging_spam_enabled"
android:dependency="@string/pref_key__logging_enabled"/>
</com.github.dfa.diaspora_android.ui.theme.ThemedPreferenceCategory>
<!-- Miscellaneous -->
<com.github.dfa.diaspora_android.ui.theme.ThemedPreferenceCategory
android:title="@string/pref_title__sub_miscelaneous">
<Preference
android:key="@string/pref_key__wipe_settings"
android:title="@string/pref_title__wipe_settings"
android:summary="@string/pref_desc__wipe_settings" />
</com.github.dfa.diaspora_android.ui.theme.ThemedPreferenceCategory>
</PreferenceScreen>