mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 22:38:49 +00:00
Fix up preference screen a little
1) Remove phantom padding on left margin for all fragments 2) Move preferences around slightly 3) Add some card separators and style led list pref // FREEBIE
This commit is contained in:
@@ -27,7 +27,7 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class AppProtectionPreferenceFragment extends PreferenceFragment {
|
||||
public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment {
|
||||
|
||||
private static final String PREFERENCE_CATEGORY_BLOCKED = "preference_category_blocked";
|
||||
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2017 Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.ListPreference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
/**
|
||||
* List preference that disables dependents when set to "none", similar to a CheckBoxPreference.
|
||||
*
|
||||
* @author Taylor Kline
|
||||
*/
|
||||
|
||||
public class BooleanListPreference extends ListPreference {
|
||||
|
||||
public BooleanListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public BooleanListPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
CharSequence oldEntry = getEntry();
|
||||
super.setValue(value);
|
||||
CharSequence newEntry = getEntry();
|
||||
if (oldEntry != newEntry) {
|
||||
notifyDependencyChange(shouldDisableDependents());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldDisableDependents() {
|
||||
CharSequence newEntry = getEntry();
|
||||
String noneEntry = getContext().getString(R.string.preferences__none);
|
||||
boolean shouldDisable = newEntry.equals(noneEntry);
|
||||
return shouldDisable || super.shouldDisableDependents();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import android.support.v4.preference.PreferenceFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
@@ -20,7 +21,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ChatsPreferenceFragment extends PreferenceFragment {
|
||||
public class ChatsPreferenceFragment extends CorrectedPreferenceFragment {
|
||||
private static final String TAG = ChatsPreferenceFragment.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.thoughtcrime.securesms.preferences;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.preference.PreferenceFragment;
|
||||
import android.view.View;
|
||||
|
||||
public class CorrectedPreferenceFragment extends PreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
View lv = getView().findViewById(android.R.id.list);
|
||||
if (lv != null) lv.setPadding(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* Copyright (C) 2017 Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.preference.ListPreference;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
/**
|
||||
* List preference that disables dependents when set to "none", similar to a CheckBoxPreference.
|
||||
*
|
||||
* @author Taylor Kline
|
||||
*/
|
||||
|
||||
public class LEDColorListPreference extends ListPreference {
|
||||
|
||||
private static final String TAG = LEDColorListPreference.class.getSimpleName();
|
||||
|
||||
private ImageView colorImageView;
|
||||
|
||||
public LEDColorListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setWidgetLayoutResource(R.layout.led_color_preference_widget);
|
||||
}
|
||||
|
||||
public LEDColorListPreference(Context context) {
|
||||
super(context);
|
||||
setWidgetLayoutResource(R.layout.led_color_preference_widget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
CharSequence oldEntry = getEntry();
|
||||
super.setValue(value);
|
||||
CharSequence newEntry = getEntry();
|
||||
if (oldEntry != newEntry) {
|
||||
notifyDependencyChange(shouldDisableDependents());
|
||||
}
|
||||
|
||||
if (value != null) setPreviewColor(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldDisableDependents() {
|
||||
CharSequence newEntry = getValue();
|
||||
boolean shouldDisable = newEntry.equals("none");
|
||||
return shouldDisable || super.shouldDisableDependents();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindView(View view) {
|
||||
super.onBindView(view);
|
||||
this.colorImageView = (ImageView)view.findViewById(R.id.color_view);
|
||||
setPreviewColor(getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSummary(CharSequence summary) {
|
||||
super.setSummary(null);
|
||||
}
|
||||
|
||||
private void setPreviewColor(@NonNull String value) {
|
||||
int color;
|
||||
|
||||
switch (value) {
|
||||
case "green": color = getContext().getResources().getColor(R.color.green_500); break;
|
||||
case "red": color = getContext().getResources().getColor(R.color.red_500); break;
|
||||
case "blue": color = getContext().getResources().getColor(R.color.blue_500); break;
|
||||
case "yellow": color = getContext().getResources().getColor(R.color.yellow_500); break;
|
||||
case "cyan": color = getContext().getResources().getColor(R.color.cyan_500); break;
|
||||
case "magenta": color = getContext().getResources().getColor(R.color.pink_500); break;
|
||||
case "white": color = getContext().getResources().getColor(R.color.white); break;
|
||||
default: color = getContext().getResources().getColor(R.color.transparent); break;
|
||||
}
|
||||
|
||||
if (colorImageView != null) {
|
||||
GradientDrawable drawable = new GradientDrawable();
|
||||
drawable.setShape(GradientDrawable.OVAL);
|
||||
drawable.setColor(color);
|
||||
|
||||
colorImageView.setImageDrawable(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import org.thoughtcrime.securesms.R;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public abstract class ListSummaryPreferenceFragment extends PreferenceFragment {
|
||||
public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceFragment {
|
||||
|
||||
protected class ListSummaryListener implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
public class SmsMmsPreferenceFragment extends PreferenceFragment {
|
||||
public class SmsMmsPreferenceFragment extends CorrectedPreferenceFragment {
|
||||
private static final String KITKAT_DEFAULT_PREF = "pref_set_default";
|
||||
private static final String MMS_PREF = "pref_mms_preferences";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user