diff --git a/briar-android/src/main/java/org/briarproject/briar/android/settings/SettingsFragment.java b/briar-android/src/main/java/org/briarproject/briar/android/settings/SettingsFragment.java index 12e64ea84eff3f56a1767e06baf46aa11924339a..cff44bb8a560806031fcffffb329dcc0abcee98b 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/settings/SettingsFragment.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/settings/SettingsFragment.java @@ -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(); diff --git a/briar-android/src/main/java/org/briarproject/briar/android/widget/PreferenceDividerDecoration.java b/briar-android/src/main/java/org/briarproject/briar/android/widget/PreferenceDividerDecoration.java deleted file mode 100644 index 50835db2dd8bba9c45bdd0805a5c8a3eea4b90a7..0000000000000000000000000000000000000000 --- a/briar-android/src/main/java/org/briarproject/briar/android/widget/PreferenceDividerDecoration.java +++ /dev/null @@ -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); - } -} diff --git a/briar-android/src/main/res/layout/divider_preference.xml b/briar-android/src/main/res/layout/divider_preference.xml new file mode 100644 index 0000000000000000000000000000000000000000..4ce00c8b7c28447f07d9b96aa6bcb6e669397dce --- /dev/null +++ b/briar-android/src/main/res/layout/divider_preference.xml @@ -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> \ No newline at end of file diff --git a/briar-android/src/main/res/xml/settings.xml b/briar-android/src/main/res/xml/settings.xml index dec7e21836baeaf09620ddd1dda91b174e5882f4..43ad96985aa583ecfefceab56a780dbfc1afe65a 100644 --- a/briar-android/src/main/res/xml/settings.xml +++ b/briar-android/src/main/res/xml/settings.xml @@ -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">