From 6cc651bfcc8cc0fe6dc16a70524c0ad6858c1b69 Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Sat, 22 Oct 2016 23:30:22 +0200 Subject: [PATCH] Themed PodSelectionDialog --- .../fragment/PodSelectionFragment.java | 9 ++++- .../ThemedAppCompatDialogFragment.java | 27 ++++++++++++++ .../ui/PodSelectionDialog.java | 37 +++++++++++++++++-- .../util/theming/ThemeHelper.java | 31 +++++++++++++++- .../main/res/layout/podselection__dialog.xml | 5 ++- 5 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/com/github/dfa/diaspora_android/fragment/ThemedAppCompatDialogFragment.java diff --git a/app/src/main/java/com/github/dfa/diaspora_android/fragment/PodSelectionFragment.java b/app/src/main/java/com/github/dfa/diaspora_android/fragment/PodSelectionFragment.java index 1bdd4621..f4d600b4 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/fragment/PodSelectionFragment.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/fragment/PodSelectionFragment.java @@ -22,6 +22,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.res.Resources; import android.os.Build; import android.os.Bundle; import android.support.design.widget.Snackbar; @@ -51,6 +52,7 @@ import com.github.dfa.diaspora_android.ui.PodSelectionDialog; import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.DiasporaUrlHelper; import com.github.dfa.diaspora_android.util.Helpers; +import com.github.dfa.diaspora_android.util.theming.ThemeHelper; import org.json.JSONException; import org.json.JSONObject; @@ -66,7 +68,7 @@ import butterknife.OnClick; * Created by vanitas on 01.10.16. */ -public class PodSelectionFragment extends CustomFragment implements SearchView.OnQueryTextListener, PodSelectionDialog.PodSelectionDialogResultListener { +public class PodSelectionFragment extends ThemedFragment implements SearchView.OnQueryTextListener, PodSelectionDialog.PodSelectionDialogResultListener { public static final String TAG = "com.github.dfa.diaspora_android.PodSelectionFragment"; @BindView(R.id.podselection__fragment__listpods) @@ -155,6 +157,11 @@ public class PodSelectionFragment extends CustomFragment implements SearchView.O } }; + @Override + protected void applyColorToViews() { + /* Not really anything to do. Maybe later */ + } + @Override public void onResume() { super.onResume(); diff --git a/app/src/main/java/com/github/dfa/diaspora_android/fragment/ThemedAppCompatDialogFragment.java b/app/src/main/java/com/github/dfa/diaspora_android/fragment/ThemedAppCompatDialogFragment.java new file mode 100644 index 00000000..632fad22 --- /dev/null +++ b/app/src/main/java/com/github/dfa/diaspora_android/fragment/ThemedAppCompatDialogFragment.java @@ -0,0 +1,27 @@ +package com.github.dfa.diaspora_android.fragment; + +import android.app.Dialog; +import android.os.Bundle; +import android.support.v7.app.AppCompatDialogFragment; + +import com.github.dfa.diaspora_android.data.AppSettings; +import com.github.dfa.diaspora_android.util.theming.ThemeHelper; + +/** + * Themed DialogFragment + * Created by vanitas on 22.10.16. + */ + +public abstract class ThemedAppCompatDialogFragment extends AppCompatDialogFragment { + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + Dialog dialog = super.onCreateDialog(savedInstanceState); + ThemeHelper.getInstance(getAppSettings()); + return dialog; + } + + protected abstract void applyColorsToViews(); + + protected abstract AppSettings getAppSettings(); +} 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 65cae8cb..c843b34e 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 @@ -21,7 +21,9 @@ import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.data.AppSettings; import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod; import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod.DiasporaPodUrl; +import com.github.dfa.diaspora_android.fragment.ThemedAppCompatDialogFragment; import com.github.dfa.diaspora_android.util.ProxyHandler; +import com.github.dfa.diaspora_android.util.theming.ThemeHelper; import org.json.JSONException; @@ -35,7 +37,7 @@ import butterknife.OnItemSelected; /** * Created by gsantner (https://gsantner.github.io) on 06.10.16. */ -public class PodSelectionDialog extends AppCompatDialogFragment { +public class PodSelectionDialog extends ThemedAppCompatDialogFragment { public static final String TAG = "com.github.dfa.diaspora_android.PodSelectionDialog"; public static interface PodSelectionDialogResultListener { @@ -65,7 +67,7 @@ public class PodSelectionDialog extends AppCompatDialogFragment { @BindView(R.id.podselection__dialog__edit_podaddress) EditText editPodAddress; - @BindView(R.id.podselection__dialog__edit_podname) + @BindView(R.id.podselection__dialog__edit_pod_name) EditText editPodName; @BindView(R.id.podselection__dialog__radiogroup_protocol) @@ -83,6 +85,15 @@ public class PodSelectionDialog extends AppCompatDialogFragment { @BindView(R.id.podselection__dialog__text_torpreset) TextView textTorPreset; + @BindView(R.id.podselection__dialog__text_pod_name) + TextView textPodName; + + @BindView(R.id.podselection__dialog__text_pod_address) + TextView textPodAddress; + + @BindView(R.id.podselection__dialog__text_protocol) + TextView textProtocol; + private PodSelectionDialogResultListener resultListener; private View root; private DiasporaPod pod = new DiasporaPod(); @@ -112,11 +123,31 @@ public class PodSelectionDialog extends AppCompatDialogFragment { spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerProfile.setAdapter(spinnerAdapter); } - + applyColorsToViews(); builder.setView(root); return builder.create(); } + protected void applyColorsToViews() { + ThemeHelper.getInstance(app.getSettings()); + + textPodAddress.setTextColor(ThemeHelper.getAccentColor()); + textPodName.setTextColor(ThemeHelper.getAccentColor()); + textProfile.setTextColor(ThemeHelper.getAccentColor()); + textProtocol.setTextColor(ThemeHelper.getAccentColor()); + textTorPreset.setTextColor(ThemeHelper.getAccentColor()); + + ThemeHelper.updateEditTextColor(editPodAddress); + ThemeHelper.updateEditTextColor(editPodName); + ThemeHelper.updateCheckBoxColor(checkboxTorPreset); + ThemeHelper.updateRadioGroupColor(radiogrpProtocol); + } + + @Override + protected AppSettings getAppSettings() { + return app.getSettings(); + } + @OnItemSelected(R.id.podselection__dialog__spinner_profile) public void spinnerItemSelected(Spinner spinner, int position) { uiLoadDiasporaUrl(position); diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/theming/ThemeHelper.java b/app/src/main/java/com/github/dfa/diaspora_android/util/theming/ThemeHelper.java index d23c3785..ff451e6c 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/theming/ThemeHelper.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/theming/ThemeHelper.java @@ -19,9 +19,14 @@ */ package com.github.dfa.diaspora_android.util.theming; +import android.content.res.ColorStateList; +import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.ColorDrawable; +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.ActionBar; import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.Toolbar; @@ -29,8 +34,11 @@ import android.view.View; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ProgressBar; +import android.widget.RadioButton; +import android.widget.RadioGroup; import android.widget.TextView; +import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.data.AppSettings; /** @@ -62,12 +70,17 @@ public class ThemeHelper { public static void updateEditTextColor(EditText editText) { if (editText != null) { editText.setHighlightColor(getInstance().appSettings.getAccentColor()); + if(Build.VERSION.SDK_INT >= 21) { + editText.getBackground().mutate().setColorFilter(getAccentColor(), PorterDuff.Mode.SRC_ATOP); + } } } public static void updateCheckBoxColor(CheckBox checkBox) { if (checkBox != null) { - checkBox.setHighlightColor(getInstance().appSettings.getAccentColor()); + int states[][] = {{android.R.attr.state_checked}, {}}; + int colors[] = {ThemeHelper.getAccentColor(), getNeutralGreyColor()}; + CompoundButtonCompat.setButtonTintList(checkBox, new ColorStateList(states, colors)); } } @@ -126,4 +139,20 @@ public class ThemeHelper { progressBar.getProgressDrawable().setColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN); } } + + public static void updateRadioGroupColor(RadioGroup radioGroup) { + if(radioGroup != null && Build.VERSION.SDK_INT >= 21) { + for (int i = 0; i < radioGroup.getChildCount(); ++i) { + RadioButton btn = ((RadioButton) radioGroup.getChildAt(i)); + btn.setButtonTintList(new ColorStateList( + new int[][]{ new int[]{-android.R.attr.state_enabled}, new int[]{android.R.attr.state_enabled} }, + new int[] { Color.BLACK ,ThemeHelper.getAccentColor() })); + btn.invalidate(); + } + } + } + + public static int getNeutralGreyColor() { + return ContextCompat.getColor(getInstance().appSettings.getApplicationContext(), R.color.md_grey_800); + } } diff --git a/app/src/main/res/layout/podselection__dialog.xml b/app/src/main/res/layout/podselection__dialog.xml index cd81055f..d51a31e9 100644 --- a/app/src/main/res/layout/podselection__dialog.xml +++ b/app/src/main/res/layout/podselection__dialog.xml @@ -30,6 +30,7 @@ android:visibility="gone" />