From dd4af48b8ef677d96dcb5a7deb8394df80a2a8f4 Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Sun, 6 Nov 2016 16:23:18 +0100 Subject: [PATCH] Fixed lint issues (suppressed, where they cant be fixed) Release 0.2.0 (Updated translation files) Announcing 0.2.0-next Added wipe-settings option Merge branch 'master' of github.com:Diaspora-for-Android/diaspora-android Merge branch 'master' into wipe-settings Added ThemedAlertDialogBuilder and a corresponding method in ThemeHelper Merge branch 'master' into wipe-settings Reworked dialog --- CHANGELOG.md | 3 ++ app/build.gradle | 4 +- app/src/main/AndroidManifest.xml | 7 ++- .../activity/DiasporaStreamFragment.java | 4 +- .../activity/MainActivity.java | 6 ++- .../activity/SettingsActivity.java | 42 +++++++++++++++-- .../diaspora_android/ui/BadgeDrawable.java | 2 +- .../dfa/diaspora_android/ui/HtmlTextView.java | 2 +- .../ui/PodSelectionDialog.java | 11 +++++ .../ui/theme/ThemeHelper.java | 18 ++++++++ .../ui/theme/ThemedActivity.java | 1 + .../ui/theme/ThemedAlertDialogBuilder.java | 45 +++++++++++++++++++ .../theme/ThemedAppCompatDialogFragment.java | 2 + .../diaspora_android/util/AppSettings.java | 8 ++-- app/src/main/res/layout/main__nav_header.xml | 5 ++- .../main/res/layout/podselection__dialog.xml | 7 ++- app/src/main/res/menu/main__menu_bottom.xml | 3 +- app/src/main/res/menu/main__menu_top.xml | 3 +- ...main__menu_top__notifications_dropdown.xml | 3 +- app/src/main/res/menu/stream__menu_bottom.xml | 4 +- app/src/main/res/menu/stream__menu_top.xml | 2 - app/src/main/res/values-nl/strings-about.xml | 19 ++++++++ .../res/values-nl/strings-preferences.xml | 22 +++++++++ app/src/main/res/values-nl/strings.xml | 20 ++++++++- app/src/main/res/values/color.xml | 4 +- .../main/res/values/strings-preferences.xml | 6 +++ app/src/main/res/values/strings.xml | 2 + .../res/xml/preferences__sub_debugging.xml | 14 ++++++ 28 files changed, 240 insertions(+), 29 deletions(-) create mode 100644 app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedAlertDialogBuilder.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 34751a5a..cda9d050 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# v0.2.0-next + + # v0.2.0 - Added: Customizable Theme Colors! - Improved account setup with easy tor hidden service configuration diff --git a/app/build.gradle b/app/build.gradle index 1b99d571..e4b4585f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,7 +30,7 @@ android { // Additional repositories repositories { maven { - url "http://dl.bintray.com/dasar/maven" //Color picker + url "https://jitpack.io" } } @@ -52,7 +52,7 @@ dependencies { compile 'com.jakewharton:butterknife:8.0.1' compile 'info.guardianproject.netcipher:netcipher:2.0.0-alpha1' compile 'info.guardianproject.netcipher:netcipher-webkit:2.0.0-alpha1' - compile(group: 'uz.shift', name: 'colorpicker', version: '0.5', ext: 'aar') + compile 'com.github.DASAR:ShiftColorPicker:v0.5' apt 'com.jakewharton:butterknife-compiler:8.0.1' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fe8e3163..67edd76a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,8 @@ + xmlns:tools="http://schemas.android.com/tools" + package="com.github.dfa.diaspora_android" + tools:ignore="GoogleAppIndexingWarning"> @@ -15,7 +17,8 @@ + android:authorities="com.github.dfa.diaspora_android.mainactivity" + android:exported="false"/> Primary Color, 2 -> Accent Color */ + @SuppressLint("InflateParams") public void showColorPickerDialog(final int type) { final AppSettings appSettings = ((App) getActivity().getApplication()).getSettings(); final Context context = getActivity(); @@ -291,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); @@ -447,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/PodSelectionDialog.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/PodSelectionDialog.java index 663ae5f4..3286d7ea 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/PodSelectionDialog.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/PodSelectionDialog.java @@ -1,6 +1,7 @@ package com.github.dfa.diaspora_android.ui; +import android.annotation.SuppressLint; import android.app.Dialog; import android.os.Bundle; import android.support.annotation.NonNull; @@ -9,6 +10,7 @@ import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioGroup; @@ -93,6 +95,12 @@ public class PodSelectionDialog extends ThemedAppCompatDialogFragment { @BindView(R.id.podselection__dialog__text_protocol) TextView textProtocol; + @BindView(R.id.podselection__dialog__btn_ok) + Button btnOk; + + @BindView(R.id.podselection__dialog__btn_cancel) + Button btnCancel; + private PodSelectionDialogResultListener resultListener; private View root; private DiasporaPod pod = new DiasporaPod(); @@ -100,6 +108,7 @@ public class PodSelectionDialog extends ThemedAppCompatDialogFragment { @NonNull @Override + @SuppressLint("InflateParams") public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); @@ -135,6 +144,8 @@ public class PodSelectionDialog extends ThemedAppCompatDialogFragment { textProfile.setTextColor(ThemeHelper.getAccentColor()); textProtocol.setTextColor(ThemeHelper.getAccentColor()); textTorPreset.setTextColor(ThemeHelper.getAccentColor()); + btnOk.setTextColor(ThemeHelper.getAccentColor()); + btnCancel.setTextColor(ThemeHelper.getAccentColor()); ThemeHelper.updateEditTextColor(editPodAddress); ThemeHelper.updateEditTextColor(editPodName); 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 64030905..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 @@ -19,6 +19,7 @@ */ package com.github.dfa.diaspora_android.ui.theme; +import android.content.DialogInterface; import android.content.res.ColorStateList; import android.graphics.Color; import android.graphics.PorterDuff; @@ -26,9 +27,11 @@ import android.os.Build; import android.support.design.widget.TabLayout; import android.support.v4.content.ContextCompat; import android.support.v4.widget.CompoundButtonCompat; +import android.support.v7.app.AlertDialog; import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.Toolbar; import android.view.View; +import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ProgressBar; @@ -37,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; /** @@ -153,4 +157,18 @@ public class ThemeHelper { public static int getNeutralGreyColor() { return ContextCompat.getColor(getInstance().appSettings.getApplicationContext(), R.color.md_grey_800); } + + public static void updateAlertDialogColor(AlertDialog alertDialog) { + if(alertDialog != null) { + 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 new file mode 100644 index 00000000..c5a3cde7 --- /dev/null +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/theme/ThemedAlertDialogBuilder.java @@ -0,0 +1,45 @@ +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; + +import com.github.dfa.diaspora_android.util.AppSettings; + +/** + * AlertDialog Builder that colors its buttons + * Created by vanitas on 06.11.16. + */ + +public class ThemedAlertDialogBuilder extends AlertDialog.Builder { + protected AppSettings appSettings; + + public ThemedAlertDialogBuilder(@NonNull Context context, AppSettings appSettings) { + super(context); + this.appSettings = appSettings; + } + + public ThemedAlertDialogBuilder(@NonNull Context context, @StyleRes int themeResId, AppSettings appSettings) { + super(context, themeResId); + this.appSettings = appSettings; + } + + @Override + public AlertDialog create() { + final AlertDialog dialog = super.create(); + dialog.setOnShowListener(new DialogInterface.OnShowListener() { + @Override + public void onShow(DialogInterface dialogInterface) { + applyColors(dialog); + } + }); + return dialog; + } + + private void applyColors(AlertDialog alertDialog) { + 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/layout/main__nav_header.xml b/app/src/main/res/layout/main__nav_header.xml index d3294497..39003d1e 100644 --- a/app/src/main/res/layout/main__nav_header.xml +++ b/app/src/main/res/layout/main__nav_header.xml @@ -1,9 +1,9 @@ @@ -36,7 +36,8 @@ android:layout_marginEnd="@dimen/activity_horizontal_margin_half" android:layout_marginStart="@dimen/activity_horizontal_margin" android:scaleType="fitCenter" - android:src="@drawable/ic_launcher" /> + android:src="@drawable/ic_launcher" + tools:ignore="ContentDescription" /> + android:text="@string/http" /> + android:text="@string/https" />