mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Don't use a custom widget to separate preference categories.
This commit is contained in:
@@ -11,9 +11,6 @@ import android.support.v7.preference.CheckBoxPreference;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.acra.ACRA;
|
||||
@@ -34,7 +31,6 @@ import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.util.UserFeedback;
|
||||
import org.briarproject.briar.android.widget.PreferenceDividerDecoration;
|
||||
import org.briarproject.briar.api.test.TestDataCreator;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
@@ -200,16 +196,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView onCreateRecyclerView(LayoutInflater inflater,
|
||||
ViewGroup parent, Bundle savedInstanceState) {
|
||||
RecyclerView list = super.onCreateRecyclerView(inflater, parent,
|
||||
savedInstanceState);
|
||||
list.addItemDecoration(
|
||||
new PreferenceDividerDecoration(getContext()).drawBottom(true));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
@@ -1,181 +0,0 @@
|
||||
package org.briarproject.briar.android.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.DimenRes;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceGroupAdapter;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.TintTypedArray;
|
||||
import android.view.View;
|
||||
|
||||
import org.briarproject.briar.R;
|
||||
|
||||
/**
|
||||
* Use this class to add dividers between {@link Preference} items.
|
||||
* <p/>
|
||||
* Source: https://github.com/consp1racy/android-support-preference
|
||||
* <br/>
|
||||
* License: Apache License v2.0
|
||||
*/
|
||||
public class PreferenceDividerDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
private boolean mDrawTop = false;
|
||||
private boolean mDrawBottom = false;
|
||||
private boolean mDrawBetweenItems = true;
|
||||
private boolean mDrawBetweenCategories = true;
|
||||
|
||||
private Drawable mDivider;
|
||||
private int mDividerHeight;
|
||||
|
||||
public PreferenceDividerDecoration(Drawable divider, int dividerHeight) {
|
||||
mDivider = divider;
|
||||
mDividerHeight = dividerHeight;
|
||||
}
|
||||
|
||||
public PreferenceDividerDecoration(Context context,
|
||||
@DrawableRes int divider, @DimenRes int dividerHeight) {
|
||||
mDivider = ContextCompat.getDrawable(context, divider);
|
||||
mDividerHeight =
|
||||
context.getResources().getDimensionPixelSize(dividerHeight);
|
||||
}
|
||||
|
||||
public PreferenceDividerDecoration(Context context) {
|
||||
TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, null,
|
||||
new int[] {R.attr.dividerHorizontal});
|
||||
mDivider = a.getDrawable(0);
|
||||
a.recycle();
|
||||
|
||||
mDividerHeight = mDivider.getIntrinsicHeight();
|
||||
}
|
||||
|
||||
public boolean getDrawTop() {
|
||||
return mDrawTop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls whether to draw divider above the first item.
|
||||
*/
|
||||
public PreferenceDividerDecoration drawTop(boolean drawTop) {
|
||||
mDrawTop = drawTop;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean getDrawBottom() {
|
||||
return mDrawBottom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls whether to draw divider at the bottom of the last item.
|
||||
*/
|
||||
public PreferenceDividerDecoration drawBottom(boolean drawBottom) {
|
||||
mDrawBottom = drawBottom;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean getDrawBetweenItems() {
|
||||
return mDrawBetweenItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls whether to draw divider at the bottom of each
|
||||
* {@link Preference} and {@link PreferenceScreen} item.
|
||||
*/
|
||||
public PreferenceDividerDecoration drawBetweenItems(
|
||||
boolean drawBetweenItems) {
|
||||
mDrawBetweenItems = drawBetweenItems;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean getDrawBetweenCategories() {
|
||||
return mDrawBetweenCategories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls whether to draw divider above each {@link PreferenceGroup}
|
||||
* usually {@link PreferenceCategory}.
|
||||
*/
|
||||
public PreferenceDividerDecoration drawBetweenCategories(
|
||||
boolean drawBetweenCategories) {
|
||||
mDrawBetweenCategories = drawBetweenCategories;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawOver(Canvas c, RecyclerView parent,
|
||||
RecyclerView.State state) {
|
||||
int left = parent.getPaddingLeft();
|
||||
int right = parent.getWidth() - parent.getPaddingRight();
|
||||
|
||||
final PreferenceGroupAdapter adapter =
|
||||
(PreferenceGroupAdapter) parent.getAdapter();
|
||||
final int adapterCount = adapter.getItemCount();
|
||||
|
||||
boolean wasLastPreferenceGroup = false;
|
||||
for (int i = 0, childCount = parent.getChildCount(); i < childCount;
|
||||
i++) {
|
||||
final View child = parent.getChildAt(i);
|
||||
|
||||
final int adapterPosition = parent.getChildAdapterPosition(child);
|
||||
Preference preference = adapter.getItem(adapterPosition);
|
||||
|
||||
boolean skipNextAboveDivider = false;
|
||||
if (adapterPosition == 0) {
|
||||
if (mDrawTop) {
|
||||
drawAbove(c, left, right, child);
|
||||
}
|
||||
skipNextAboveDivider = true;
|
||||
}
|
||||
|
||||
if (preference instanceof PreferenceGroup
|
||||
&& !(preference instanceof PreferenceScreen)) {
|
||||
if (mDrawBetweenCategories) {
|
||||
if (!skipNextAboveDivider) {
|
||||
drawAbove(c, left, right, child);
|
||||
skipNextAboveDivider = true;
|
||||
}
|
||||
}
|
||||
wasLastPreferenceGroup = true;
|
||||
} else {
|
||||
if (mDrawBetweenItems && !wasLastPreferenceGroup) {
|
||||
if (!skipNextAboveDivider) {
|
||||
drawAbove(c, left, right, child);
|
||||
skipNextAboveDivider = true;
|
||||
}
|
||||
}
|
||||
wasLastPreferenceGroup = false;
|
||||
}
|
||||
|
||||
if (adapterPosition == adapterCount - 1) {
|
||||
if (mDrawBottom) {
|
||||
drawBottom(c, left, right, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawAbove(Canvas c, int left, int right, View child) {
|
||||
final RecyclerView.LayoutParams params =
|
||||
(RecyclerView.LayoutParams) child.getLayoutParams();
|
||||
final int top = child.getTop() - params.topMargin - mDividerHeight;
|
||||
final int bottom = top + mDividerHeight;
|
||||
mDivider.setBounds(left, top, right, bottom);
|
||||
mDivider.draw(c);
|
||||
}
|
||||
|
||||
private void drawBottom(Canvas c, int left, int right, View child) {
|
||||
final RecyclerView.LayoutParams params =
|
||||
(RecyclerView.LayoutParams) child.getLayoutParams();
|
||||
final int top =
|
||||
child.getBottom() + params.bottomMargin - mDividerHeight;
|
||||
final int bottom = top + mDividerHeight;
|
||||
mDivider.setBounds(left, top, right, bottom);
|
||||
mDivider.draw(c);
|
||||
}
|
||||
}
|
||||
6
briar-android/src/main/res/layout/divider_preference.xml
Normal file
6
briar-android/src/main/res/layout/divider_preference.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<View xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/divider">
|
||||
</View>
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:layout="@layout/divider_preference"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/security_settings_title">
|
||||
|
||||
@@ -39,6 +41,8 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:layout="@layout/divider_preference"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/panic_setting_title">
|
||||
|
||||
@@ -54,6 +58,8 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:layout="@layout/divider_preference"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/notification_settings_title">
|
||||
|
||||
@@ -61,36 +67,36 @@
|
||||
android:defaultValue="true"
|
||||
android:key="pref_key_notify_private_messages"
|
||||
android:persistent="false"
|
||||
android:title="@string/notify_private_messages_setting_title"
|
||||
android:summary="@string/notify_private_messages_setting_summary"/>
|
||||
android:summary="@string/notify_private_messages_setting_summary"
|
||||
android:title="@string/notify_private_messages_setting_title"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="pref_key_notify_group_messages"
|
||||
android:persistent="false"
|
||||
android:title="@string/notify_group_messages_setting_title"
|
||||
android:summary="@string/notify_group_messages_setting_summary"/>
|
||||
android:summary="@string/notify_group_messages_setting_summary"
|
||||
android:title="@string/notify_group_messages_setting_title"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="pref_key_notify_forum_posts"
|
||||
android:persistent="false"
|
||||
android:title="@string/notify_forum_posts_setting_title"
|
||||
android:summary="@string/notify_forum_posts_setting_summary"/>
|
||||
android:summary="@string/notify_forum_posts_setting_summary"
|
||||
android:title="@string/notify_forum_posts_setting_title"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="pref_key_notify_blog_posts"
|
||||
android:persistent="false"
|
||||
android:title="@string/notify_blog_posts_setting_title"
|
||||
android:summary="@string/notify_blog_posts_setting_summary"/>
|
||||
android:summary="@string/notify_blog_posts_setting_summary"
|
||||
android:title="@string/notify_blog_posts_setting_title"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="pref_key_notify_lock_screen"
|
||||
android:persistent="false"
|
||||
android:title="@string/notify_lock_screen_setting_title"
|
||||
android:summary="@string/notify_lock_screen_setting_summary"
|
||||
android:title="@string/notify_lock_screen_setting_title"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
@@ -105,6 +111,8 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:layout="@layout/divider_preference"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/feedback_settings_title">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user