mirror of
https://github.com/gsantner/dandelion
synced 2024-11-24 21:32:07 +01:00
Added image in ThemedPreference and cleaned some code
This commit is contained in:
parent
1356b81c64
commit
e79c1d48ea
12 changed files with 73 additions and 71 deletions
|
@ -24,8 +24,6 @@ import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.github.dfa.diaspora_android.R;
|
import com.github.dfa.diaspora_android.R;
|
||||||
|
@ -84,8 +82,6 @@ public class SettingsFragment__Debugging extends ThemedSettingsFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,6 @@ import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.github.dfa.diaspora_android.R;
|
import com.github.dfa.diaspora_android.R;
|
||||||
|
@ -40,7 +38,7 @@ import butterknife.ButterKnife;
|
||||||
* Created by vanitas on 16.10.16.
|
* Created by vanitas on 16.10.16.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SettingsFragment__NavigationSlider extends ThemedFragment {
|
public class SettingsFragment__NavigationSlider extends ThemedSettingsFragment {
|
||||||
public static final String TAG = "com.github.dfa.diaspora_android.SettingsFragment__NavigationSlider";
|
public static final String TAG = "com.github.dfa.diaspora_android.SettingsFragment__NavigationSlider";
|
||||||
|
|
||||||
@BindView(R.id.settings_activity__header_appearance__nav_slider)
|
@BindView(R.id.settings_activity__header_appearance__nav_slider)
|
||||||
|
@ -73,4 +71,16 @@ public class SettingsFragment__NavigationSlider extends ThemedFragment {
|
||||||
public boolean onBackPressed() {
|
public boolean onBackPressed() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void applySettingsToViews() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setOnClickListenersOnViews() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,23 +19,20 @@
|
||||||
package com.github.dfa.diaspora_android.fragment;
|
package com.github.dfa.diaspora_android.fragment;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.AlertDialog;
|
|
||||||
import android.text.InputType;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.github.dfa.diaspora_android.R;
|
import com.github.dfa.diaspora_android.R;
|
||||||
import com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference;
|
import com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference;
|
||||||
import com.github.dfa.diaspora_android.ui.ThemedIntEditTextPreference;
|
import com.github.dfa.diaspora_android.ui.ThemedIntEditTextPreference;
|
||||||
|
import com.github.dfa.diaspora_android.ui.ThemedPreference;
|
||||||
import com.github.dfa.diaspora_android.ui.ThemedStringEditTextPreference;
|
import com.github.dfa.diaspora_android.ui.ThemedStringEditTextPreference;
|
||||||
import com.github.dfa.diaspora_android.util.AppLog;
|
import com.github.dfa.diaspora_android.util.AppLog;
|
||||||
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
|
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
|
||||||
|
@ -64,7 +61,7 @@ public class SettingsFragment__Proxy extends ThemedSettingsFragment {
|
||||||
protected ThemedIntEditTextPreference editTextProxyPort;
|
protected ThemedIntEditTextPreference editTextProxyPort;
|
||||||
|
|
||||||
@BindView(R.id.settings_activity__proxy_orbot_preset)
|
@BindView(R.id.settings_activity__proxy_orbot_preset)
|
||||||
protected RelativeLayout optionProxyOrbotPreset;
|
protected ThemedPreference optionProxyOrbotPreset;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
@ -83,7 +80,6 @@ public class SettingsFragment__Proxy extends ThemedSettingsFragment {
|
||||||
@Override
|
@Override
|
||||||
protected void applySettingsToViews() {
|
protected void applySettingsToViews() {
|
||||||
boolean enabled = getAppSettings().isProxyHttpEnabled();
|
boolean enabled = getAppSettings().isProxyHttpEnabled();
|
||||||
|
|
||||||
editTextProxyHost.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
editTextProxyHost.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
||||||
editTextProxyHost.setEnabled(enabled);
|
editTextProxyHost.setEnabled(enabled);
|
||||||
editTextProxyPort.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
editTextProxyPort.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
||||||
|
@ -112,6 +108,7 @@ public class SettingsFragment__Proxy extends ThemedSettingsFragment {
|
||||||
AppLog.d(this, "Clicked: Proxy Preset");
|
AppLog.d(this, "Clicked: Proxy Preset");
|
||||||
editTextProxyHost.setValue("localhost");
|
editTextProxyHost.setValue("localhost");
|
||||||
editTextProxyPort.setValue(8118);
|
editTextProxyPort.setValue(8118);
|
||||||
|
Toast.makeText(getContext(), R.string.toast__proxy_orbot_preset_set, Toast.LENGTH_SHORT).show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,20 +38,20 @@ public class ThemedCheckBoxPreference extends RelativeLayout implements ThemedPr
|
||||||
|
|
||||||
public ThemedCheckBoxPreference(Context context) {
|
public ThemedCheckBoxPreference(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
init(context, null);
|
init(context, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ThemedCheckBoxPreference(Context context, AttributeSet attrs) {
|
public ThemedCheckBoxPreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
init(context, attrs);
|
init(context, attrs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ThemedCheckBoxPreference(Context context, AttributeSet attrs, int defStyle) {
|
public ThemedCheckBoxPreference(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
init(context, attrs);
|
init(context, attrs, defStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void init(Context context, AttributeSet attrs) {
|
protected void init(Context context, AttributeSet attrs, int defStyle) {
|
||||||
appSettings = new AppSettings(context.getApplicationContext());
|
appSettings = new AppSettings(context.getApplicationContext());
|
||||||
View.inflate(context, R.layout.preference__themed_checkbox, this);
|
View.inflate(context, R.layout.preference__themed_checkbox, this);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
@ -68,10 +68,7 @@ public class ThemedCheckBoxPreference extends RelativeLayout implements ThemedPr
|
||||||
String titleText = "";
|
String titleText = "";
|
||||||
String summaryText = "";
|
String summaryText = "";
|
||||||
|
|
||||||
TypedArray a = context.getTheme().obtainStyledAttributes(
|
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ThemedCheckBoxPreference, defStyle, 0);
|
||||||
attrs,
|
|
||||||
R.styleable.ThemedCheckBoxPreference,
|
|
||||||
0, 0);
|
|
||||||
try {
|
try {
|
||||||
titleText = a.getString(R.styleable.ThemedCheckBoxPreference_titleText);
|
titleText = a.getString(R.styleable.ThemedCheckBoxPreference_titleText);
|
||||||
summaryText = a.getString(R.styleable.ThemedCheckBoxPreference_summaryText);
|
summaryText = a.getString(R.styleable.ThemedCheckBoxPreference_summaryText);
|
||||||
|
|
|
@ -62,10 +62,7 @@ public class ThemedIntEditTextPreference extends LinearLayout implements ThemedP
|
||||||
String titleText = "";
|
String titleText = "";
|
||||||
String summaryText = "";
|
String summaryText = "";
|
||||||
|
|
||||||
TypedArray a = context.obtainStyledAttributes(
|
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ThemedIntEditTextPreference, defStyle, 0);
|
||||||
attrs,
|
|
||||||
R.styleable.ThemedIntEditTextPreference,
|
|
||||||
defStyle, 0);
|
|
||||||
try {
|
try {
|
||||||
titleText = a.getString(R.styleable.ThemedIntEditTextPreference_titleText);
|
titleText = a.getString(R.styleable.ThemedIntEditTextPreference_titleText);
|
||||||
summaryText = a.getString(R.styleable.ThemedIntEditTextPreference_summaryText);
|
summaryText = a.getString(R.styleable.ThemedIntEditTextPreference_summaryText);
|
||||||
|
|
|
@ -2,9 +2,11 @@ package com.github.dfa.diaspora_android.ui;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.github.dfa.diaspora_android.R;
|
import com.github.dfa.diaspora_android.R;
|
||||||
|
@ -18,12 +20,14 @@ import butterknife.ButterKnife;
|
||||||
* Created by vanitas on 23.10.16.
|
* Created by vanitas on 23.10.16.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ThemedPreference extends LinearLayout implements ThemedPreferenceObject<Void> {
|
public class ThemedPreference extends RelativeLayout implements ThemedPreferenceObject<Void> {
|
||||||
|
|
||||||
@BindView(R.id.preference__themed_preference_title)
|
@BindView(R.id.preference__themed_preference_title)
|
||||||
protected TextView title;
|
protected TextView title;
|
||||||
@BindView(R.id.preference__themed_preference_summary)
|
@BindView(R.id.preference__themed_preference_summary)
|
||||||
protected TextView summary;
|
protected TextView summary;
|
||||||
|
@BindView(R.id.preference__themed_preference_image)
|
||||||
|
protected ImageView image;
|
||||||
|
|
||||||
protected String prefKey;
|
protected String prefKey;
|
||||||
|
|
||||||
|
@ -48,11 +52,13 @@ public class ThemedPreference extends LinearLayout implements ThemedPreferenceOb
|
||||||
if (attrs != null) {
|
if (attrs != null) {
|
||||||
String titleText = "";
|
String titleText = "";
|
||||||
String summaryText = "";
|
String summaryText = "";
|
||||||
|
Drawable imageDrawable = null;
|
||||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ThemedPreference, defStyle, 0);
|
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ThemedPreference, defStyle, 0);
|
||||||
try {
|
try {
|
||||||
titleText = a.getString(R.styleable.ThemedPreference_titleText);
|
titleText = a.getString(R.styleable.ThemedPreference_titleText);
|
||||||
summaryText = a.getString(R.styleable.ThemedPreference_summaryText);
|
summaryText = a.getString(R.styleable.ThemedPreference_summaryText);
|
||||||
prefKey = a.getString(R.styleable.ThemedPreference_prefKey);
|
prefKey = a.getString(R.styleable.ThemedPreference_prefKey);
|
||||||
|
imageDrawable = a.getDrawable(R.styleable.ThemedPreference_image);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
AppLog.e(this, "There was an error loading attributes.");
|
AppLog.e(this, "There was an error loading attributes.");
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -60,6 +66,7 @@ public class ThemedPreference extends LinearLayout implements ThemedPreferenceOb
|
||||||
}
|
}
|
||||||
setTitleText(titleText);
|
setTitleText(titleText);
|
||||||
setSummaryText(summaryText);
|
setSummaryText(summaryText);
|
||||||
|
setImageDrawable(imageDrawable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +95,16 @@ public class ThemedPreference extends LinearLayout implements ThemedPreferenceOb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setImageDrawable(Drawable drawable) {
|
||||||
|
if(drawable != null) {
|
||||||
|
image.setImageDrawable(drawable);
|
||||||
|
image.setVisibility(VISIBLE);
|
||||||
|
} else {
|
||||||
|
image.setImageDrawable(null);
|
||||||
|
image.setVisibility(GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void getDefaultValue() {
|
public Void getDefaultValue() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.github.dfa.diaspora_android.ui;
|
package com.github.dfa.diaspora_android.ui;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Basic methods a ThemedPreference class should implement
|
||||||
* Created by vanitas on 23.10.16.
|
* Created by vanitas on 23.10.16.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -62,10 +62,7 @@ public class ThemedStringEditTextPreference extends LinearLayout implements Them
|
||||||
String titleText = "";
|
String titleText = "";
|
||||||
String summaryText = "";
|
String summaryText = "";
|
||||||
|
|
||||||
TypedArray a = context.obtainStyledAttributes(
|
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ThemedStringEditTextPreference, defStyle, 0);
|
||||||
attrs,
|
|
||||||
R.styleable.ThemedStringEditTextPreference,
|
|
||||||
defStyle, 0);
|
|
||||||
try {
|
try {
|
||||||
titleText = a.getString(R.styleable.ThemedStringEditTextPreference_titleText);
|
titleText = a.getString(R.styleable.ThemedStringEditTextPreference_titleText);
|
||||||
summaryText = a.getString(R.styleable.ThemedStringEditTextPreference_summaryText);
|
summaryText = a.getString(R.styleable.ThemedStringEditTextPreference_summaryText);
|
||||||
|
|
|
@ -1,18 +1,31 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/preference__themed_preference_root"
|
android:id="@+id/preference__themed_preference_root"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
||||||
android:layout_marginTop="@dimen/activity_vertical_margin">
|
android:layout_marginTop="@dimen/activity_vertical_margin">
|
||||||
<TextView
|
<ImageView
|
||||||
android:id="@+id/preference__themed_preference_title"
|
android:id="@+id/preference__themed_preference_image"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>
|
android:layout_alignParentStart="true"
|
||||||
<TextView
|
android:layout_marginEnd="@dimen/activity_horizontal_margin"
|
||||||
android:id="@+id/preference__themed_preference_summary"
|
android:layout_centerVertical="true" />
|
||||||
android:layout_width="wrap_content"
|
<LinearLayout
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_width="match_parent"
|
||||||
</LinearLayout>
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_toEndOf="@+id/preference__themed_preference_image">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/preference__themed_preference_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/preference__themed_preference_summary"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
</LinearLayout>
|
||||||
|
</RelativeLayout>
|
|
@ -59,38 +59,13 @@
|
||||||
app:prefKey="@string/pref_key__http_proxy_port"/>
|
app:prefKey="@string/pref_key__http_proxy_port"/>
|
||||||
|
|
||||||
<!-- Orbot Preset -->
|
<!-- Orbot Preset -->
|
||||||
<RelativeLayout
|
<com.github.dfa.diaspora_android.ui.ThemedPreference
|
||||||
android:id="@+id/settings_activity__proxy_orbot_preset"
|
android:id="@+id/settings_activity__proxy_orbot_preset"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
app:titleText="@string/pref_title__http_proxy_load_tor_preset"
|
||||||
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
app:summaryText="@string/pref_desc__http_proxy_load_tor_preset"
|
||||||
android:layout_marginTop="@dimen/activity_vertical_margin"
|
app:image="@drawable/tor_onion"/>
|
||||||
android:clickable="true">
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/settings_activity__proxy_orbot_preset_image"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:layout_marginRight="@dimen/activity_horizontal_margin"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:src="@drawable/tor_onion"/>
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_toEndOf="@+id/settings_activity__proxy_orbot_preset_image">
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
|
||||||
android:text="@string/pref_title__http_proxy_load_tor_preset"/>
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/pref_desc__http_proxy_load_tor_preset"/>
|
|
||||||
</LinearLayout>
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</android.support.v7.widget.CardView>
|
</android.support.v7.widget.CardView>
|
||||||
|
|
|
@ -32,5 +32,6 @@
|
||||||
<attr name="titleText" />
|
<attr name="titleText" />
|
||||||
<attr name="summaryText" />
|
<attr name="summaryText" />
|
||||||
<attr name="prefKey" />
|
<attr name="prefKey" />
|
||||||
|
<attr name="image" format="reference" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
</resources>
|
</resources>
|
|
@ -112,6 +112,7 @@
|
||||||
<string name="pref_title__http_proxy_port">Port</string>
|
<string name="pref_title__http_proxy_port">Port</string>
|
||||||
<string name="HTTP" translatable="false">HTTP</string>
|
<string name="HTTP" translatable="false">HTTP</string>
|
||||||
<string name="SOCKS5" translatable="false">SOCKS5</string>
|
<string name="SOCKS5" translatable="false">SOCKS5</string>
|
||||||
|
<string name="toast__proxy_orbot_preset_set">Orbot proxy settings applied</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Chrome custom tabs -->
|
<!-- Chrome custom tabs -->
|
||||||
|
|
Loading…
Reference in a new issue