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 c3b6fa5e..8db85255 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()); + + ThemeHelper.updateTitleColor(textPodAddress); + ThemeHelper.updateTitleColor(textPodName); + ThemeHelper.updateTitleColor(textProfile); + ThemeHelper.updateTitleColor(textProtocol); + ThemeHelper.updateTitleColor(textTorPreset); + + 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 1f4a8ca9..616ba63c 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 @@ -20,30 +20,27 @@ package com.github.dfa.diaspora_android.util.theming; import android.content.res.ColorStateList; -import android.content.res.Resources; import android.graphics.Color; import android.graphics.PorterDuff; -import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +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; import android.util.Log; import android.view.View; import android.widget.CheckBox; import android.widget.EditText; -import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ProgressBar; +import android.widget.RadioButton; +import android.widget.RadioGroup; import android.widget.TextView; -import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.data.AppSettings; -import com.github.dfa.diaspora_android.util.AppLog; /** * Singleton that can be used to color views @@ -74,6 +71,9 @@ 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); + } } } @@ -154,15 +154,27 @@ public class ThemeHelper { } public static void updateAccentColorPreview(ImageView imageView) { - if(imageView != null) { + if (imageView != null) { Drawable circle = imageView.getDrawable(); - if(circle != null) { + if (circle != null) { circle.setColorFilter(getAccentColor(), PorterDuff.Mode.SRC_ATOP); imageView.setImageDrawable(circle); } } } + 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 void updatePrimaryColorPreview(ImageView imageView) { if(imageView != null) { Drawable circle = imageView.getDrawable(); 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" />