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.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
|
@ -84,8 +82,6 @@ public class SettingsFragment__Debugging extends ThemedSettingsFragment {
|
|||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,6 @@ import android.view.Menu;
|
|||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
|
@ -40,7 +38,7 @@ import butterknife.ButterKnife;
|
|||
* 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";
|
||||
|
||||
@BindView(R.id.settings_activity__header_appearance__nav_slider)
|
||||
|
@ -73,4 +71,16 @@ public class SettingsFragment__NavigationSlider extends ThemedFragment {
|
|||
public boolean onBackPressed() {
|
||||
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;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.InputType;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference;
|
||||
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.util.AppLog;
|
||||
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
|
||||
|
@ -64,7 +61,7 @@ public class SettingsFragment__Proxy extends ThemedSettingsFragment {
|
|||
protected ThemedIntEditTextPreference editTextProxyPort;
|
||||
|
||||
@BindView(R.id.settings_activity__proxy_orbot_preset)
|
||||
protected RelativeLayout optionProxyOrbotPreset;
|
||||
protected ThemedPreference optionProxyOrbotPreset;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -83,7 +80,6 @@ public class SettingsFragment__Proxy extends ThemedSettingsFragment {
|
|||
@Override
|
||||
protected void applySettingsToViews() {
|
||||
boolean enabled = getAppSettings().isProxyHttpEnabled();
|
||||
|
||||
editTextProxyHost.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
||||
editTextProxyHost.setEnabled(enabled);
|
||||
editTextProxyPort.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
||||
|
@ -112,6 +108,7 @@ public class SettingsFragment__Proxy extends ThemedSettingsFragment {
|
|||
AppLog.d(this, "Clicked: Proxy Preset");
|
||||
editTextProxyHost.setValue("localhost");
|
||||
editTextProxyPort.setValue(8118);
|
||||
Toast.makeText(getContext(), R.string.toast__proxy_orbot_preset_set, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,20 +38,20 @@ public class ThemedCheckBoxPreference extends RelativeLayout implements ThemedPr
|
|||
|
||||
public ThemedCheckBoxPreference(Context context) {
|
||||
super(context);
|
||||
init(context, null);
|
||||
init(context, null, 0);
|
||||
}
|
||||
|
||||
public ThemedCheckBoxPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs);
|
||||
init(context, attrs, 0);
|
||||
}
|
||||
|
||||
public ThemedCheckBoxPreference(Context context, AttributeSet attrs, int 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());
|
||||
View.inflate(context, R.layout.preference__themed_checkbox, this);
|
||||
ButterKnife.bind(this);
|
||||
|
@ -68,10 +68,7 @@ public class ThemedCheckBoxPreference extends RelativeLayout implements ThemedPr
|
|||
String titleText = "";
|
||||
String summaryText = "";
|
||||
|
||||
TypedArray a = context.getTheme().obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.ThemedCheckBoxPreference,
|
||||
0, 0);
|
||||
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ThemedCheckBoxPreference, defStyle, 0);
|
||||
try {
|
||||
titleText = a.getString(R.styleable.ThemedCheckBoxPreference_titleText);
|
||||
summaryText = a.getString(R.styleable.ThemedCheckBoxPreference_summaryText);
|
||||
|
|
|
@ -62,10 +62,7 @@ public class ThemedIntEditTextPreference extends LinearLayout implements ThemedP
|
|||
String titleText = "";
|
||||
String summaryText = "";
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.ThemedIntEditTextPreference,
|
||||
defStyle, 0);
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ThemedIntEditTextPreference, defStyle, 0);
|
||||
try {
|
||||
titleText = a.getString(R.styleable.ThemedIntEditTextPreference_titleText);
|
||||
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.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
|
@ -18,12 +20,14 @@ import butterknife.ButterKnife;
|
|||
* 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)
|
||||
protected TextView title;
|
||||
@BindView(R.id.preference__themed_preference_summary)
|
||||
protected TextView summary;
|
||||
@BindView(R.id.preference__themed_preference_image)
|
||||
protected ImageView image;
|
||||
|
||||
protected String prefKey;
|
||||
|
||||
|
@ -48,11 +52,13 @@ public class ThemedPreference extends LinearLayout implements ThemedPreferenceOb
|
|||
if (attrs != null) {
|
||||
String titleText = "";
|
||||
String summaryText = "";
|
||||
Drawable imageDrawable = null;
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ThemedPreference, defStyle, 0);
|
||||
try {
|
||||
titleText = a.getString(R.styleable.ThemedPreference_titleText);
|
||||
summaryText = a.getString(R.styleable.ThemedPreference_summaryText);
|
||||
prefKey = a.getString(R.styleable.ThemedPreference_prefKey);
|
||||
imageDrawable = a.getDrawable(R.styleable.ThemedPreference_image);
|
||||
} catch (Exception e) {
|
||||
AppLog.e(this, "There was an error loading attributes.");
|
||||
} finally {
|
||||
|
@ -60,6 +66,7 @@ public class ThemedPreference extends LinearLayout implements ThemedPreferenceOb
|
|||
}
|
||||
setTitleText(titleText);
|
||||
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
|
||||
public Void getDefaultValue() {
|
||||
return null;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.github.dfa.diaspora_android.ui;
|
||||
|
||||
/**
|
||||
* Basic methods a ThemedPreference class should implement
|
||||
* Created by vanitas on 23.10.16.
|
||||
*/
|
||||
|
||||
|
|
|
@ -62,10 +62,7 @@ public class ThemedStringEditTextPreference extends LinearLayout implements Them
|
|||
String titleText = "";
|
||||
String summaryText = "";
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.ThemedStringEditTextPreference,
|
||||
defStyle, 0);
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ThemedStringEditTextPreference, defStyle, 0);
|
||||
try {
|
||||
titleText = a.getString(R.styleable.ThemedStringEditTextPreference_titleText);
|
||||
summaryText = a.getString(R.styleable.ThemedStringEditTextPreference_summaryText);
|
||||
|
|
|
@ -1,11 +1,23 @@
|
|||
<?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:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin">
|
||||
<ImageView
|
||||
android:id="@+id/preference__themed_preference_image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginEnd="@dimen/activity_horizontal_margin"
|
||||
android:layout_centerVertical="true" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
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"
|
||||
|
@ -15,4 +27,5 @@
|
|||
android:id="@+id/preference__themed_preference_summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
|
@ -59,38 +59,13 @@
|
|||
app:prefKey="@string/pref_key__http_proxy_port"/>
|
||||
|
||||
<!-- Orbot Preset -->
|
||||
<RelativeLayout
|
||||
<com.github.dfa.diaspora_android.ui.ThemedPreference
|
||||
android:id="@+id/settings_activity__proxy_orbot_preset"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin"
|
||||
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>
|
||||
app:titleText="@string/pref_title__http_proxy_load_tor_preset"
|
||||
app:summaryText="@string/pref_desc__http_proxy_load_tor_preset"
|
||||
app:image="@drawable/tor_onion"/>
|
||||
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
|
|
@ -32,5 +32,6 @@
|
|||
<attr name="titleText" />
|
||||
<attr name="summaryText" />
|
||||
<attr name="prefKey" />
|
||||
<attr name="image" format="reference" />
|
||||
</declare-styleable>
|
||||
</resources>
|
|
@ -112,6 +112,7 @@
|
|||
<string name="pref_title__http_proxy_port">Port</string>
|
||||
<string name="HTTP" translatable="false">HTTP</string>
|
||||
<string name="SOCKS5" translatable="false">SOCKS5</string>
|
||||
<string name="toast__proxy_orbot_preset_set">Orbot proxy settings applied</string>
|
||||
|
||||
|
||||
<!-- Chrome custom tabs -->
|
||||
|
|
Loading…
Reference in a new issue