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

Themed PodSelectionDialog

This commit is contained in:
vanitasvitae 2016-10-22 23:30:22 +02:00
parent 6e7ae16e33
commit 6cc651bfcc
Signed by: vanitasvitae
GPG key ID: DCCFB3302C9E4615
5 changed files with 103 additions and 6 deletions

View file

@ -22,6 +22,7 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.res.Resources;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.Snackbar; 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.AppLog;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper; import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.util.Helpers; import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -66,7 +68,7 @@ import butterknife.OnClick;
* Created by vanitas on 01.10.16. * 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"; public static final String TAG = "com.github.dfa.diaspora_android.PodSelectionFragment";
@BindView(R.id.podselection__fragment__listpods) @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 @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();

View file

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

View file

@ -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.AppSettings;
import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod; 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.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.ProxyHandler;
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
import org.json.JSONException; import org.json.JSONException;
@ -35,7 +37,7 @@ import butterknife.OnItemSelected;
/** /**
* Created by gsantner (https://gsantner.github.io) on 06.10.16. * 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 final String TAG = "com.github.dfa.diaspora_android.PodSelectionDialog";
public static interface PodSelectionDialogResultListener { public static interface PodSelectionDialogResultListener {
@ -65,7 +67,7 @@ public class PodSelectionDialog extends AppCompatDialogFragment {
@BindView(R.id.podselection__dialog__edit_podaddress) @BindView(R.id.podselection__dialog__edit_podaddress)
EditText editPodAddress; EditText editPodAddress;
@BindView(R.id.podselection__dialog__edit_podname) @BindView(R.id.podselection__dialog__edit_pod_name)
EditText editPodName; EditText editPodName;
@BindView(R.id.podselection__dialog__radiogroup_protocol) @BindView(R.id.podselection__dialog__radiogroup_protocol)
@ -83,6 +85,15 @@ public class PodSelectionDialog extends AppCompatDialogFragment {
@BindView(R.id.podselection__dialog__text_torpreset) @BindView(R.id.podselection__dialog__text_torpreset)
TextView textTorPreset; 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 PodSelectionDialogResultListener resultListener;
private View root; private View root;
private DiasporaPod pod = new DiasporaPod(); private DiasporaPod pod = new DiasporaPod();
@ -112,11 +123,31 @@ public class PodSelectionDialog extends AppCompatDialogFragment {
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerProfile.setAdapter(spinnerAdapter); spinnerProfile.setAdapter(spinnerAdapter);
} }
applyColorsToViews();
builder.setView(root); builder.setView(root);
return builder.create(); 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) @OnItemSelected(R.id.podselection__dialog__spinner_profile)
public void spinnerItemSelected(Spinner spinner, int position) { public void spinnerItemSelected(Spinner spinner, int position) {
uiLoadDiasporaUrl(position); uiLoadDiasporaUrl(position);

View file

@ -19,9 +19,14 @@
*/ */
package com.github.dfa.diaspora_android.util.theming; package com.github.dfa.diaspora_android.util.theming;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.support.design.widget.TabLayout; 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.app.ActionBar;
import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -29,8 +34,11 @@ import android.view.View;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView; import android.widget.TextView;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.AppSettings; import com.github.dfa.diaspora_android.data.AppSettings;
/** /**
@ -62,12 +70,17 @@ public class ThemeHelper {
public static void updateEditTextColor(EditText editText) { public static void updateEditTextColor(EditText editText) {
if (editText != null) { if (editText != null) {
editText.setHighlightColor(getInstance().appSettings.getAccentColor()); 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) { public static void updateCheckBoxColor(CheckBox checkBox) {
if (checkBox != null) { 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); 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);
}
} }

View file

@ -30,6 +30,7 @@
android:visibility="gone" /> android:visibility="gone" />
<TextView <TextView
android:id="@+id/podselection__dialog__text_pod_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_horizontal_margin_half" android:layout_marginTop="@dimen/activity_horizontal_margin_half"
@ -37,7 +38,7 @@
android:textAppearance="@style/AppTheme.TextAppearance.Caption" /> android:textAppearance="@style/AppTheme.TextAppearance.Caption" />
<EditText <EditText
android:id="@+id/podselection__dialog__edit_podname" android:id="@+id/podselection__dialog__edit_pod_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin_half" android:layout_marginStart="@dimen/activity_horizontal_margin_half"
@ -48,6 +49,7 @@
tools:text="Geraspora" /> tools:text="Geraspora" />
<TextView <TextView
android:id="@+id/podselection__dialog__text_pod_address"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_horizontal_margin_half" android:layout_marginTop="@dimen/activity_horizontal_margin_half"
@ -66,6 +68,7 @@
tools:text="pod.geraspora.de" /> tools:text="pod.geraspora.de" />
<TextView <TextView
android:id="@+id/podselection__dialog__text_protocol"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_horizontal_margin_half" android:layout_marginTop="@dimen/activity_horizontal_margin_half"