mirror of
https://github.com/Docile-Alligator/Infinity-For-Reddit.git
synced 2026-02-06 06:35:42 +00:00
CustomFontPreferenceWithBackground. Update settings UI. Rearrange some settings.
This commit is contained in:
@ -58,24 +58,4 @@ public class AspectRatioGifImageView extends GifImageView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
|
||||
int desiredHeight = (int) (widthSize * ratio);
|
||||
int selectedHeight;
|
||||
|
||||
if(heightMode == MeasureSpec.EXACTLY) {
|
||||
selectedHeight = heightSize;
|
||||
} else if(heightMode == MeasureSpec.AT_MOST) {
|
||||
selectedHeight = Math.min(heightSize, desiredHeight);
|
||||
} else {
|
||||
selectedHeight = desiredHeight;
|
||||
}
|
||||
super.onMeasure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(selectedHeight, MeasureSpec.EXACTLY));
|
||||
}*/
|
||||
}
|
||||
|
||||
@ -0,0 +1,151 @@
|
||||
package ml.docilealligator.infinityforreddit.customviews.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.Typeface
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.ViewGroup.MarginLayoutParams
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import ml.docilealligator.infinityforreddit.CustomFontReceiver
|
||||
import ml.docilealligator.infinityforreddit.R
|
||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper
|
||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapperReceiver
|
||||
import ml.docilealligator.infinityforreddit.utils.Utils
|
||||
|
||||
class CustomFontPreferenceWithBackground @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = androidx.preference.R.attr.preferenceStyle,
|
||||
defStyleRes: Int = 0
|
||||
) : Preference(context, attrs, defStyleAttr, defStyleRes), CustomFontReceiver,
|
||||
CustomThemeWrapperReceiver {
|
||||
private var customThemeWrapper: CustomThemeWrapper? = null
|
||||
private var typeface: Typeface? = null
|
||||
private var top = false
|
||||
private var bottom = false
|
||||
|
||||
init {
|
||||
context.theme.obtainStyledAttributes(
|
||||
attrs, R.styleable.CustomFontPreference, 0, 0
|
||||
).let { a ->
|
||||
try {
|
||||
top = a.getBoolean(R.styleable.CustomFontPreference_top, false)
|
||||
bottom = a.getBoolean(R.styleable.CustomFontPreference_bottom, false)
|
||||
} finally {
|
||||
a.recycle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
val margin16 = Utils.convertDpToPixel(
|
||||
16f,
|
||||
context
|
||||
).toInt()
|
||||
val margin2 = Utils.convertDpToPixel(
|
||||
2f,
|
||||
context
|
||||
).toInt()
|
||||
|
||||
|
||||
if (top) {
|
||||
if (bottom) {
|
||||
holder.itemView.background = AppCompatResources.getDrawable(
|
||||
context,
|
||||
R.drawable.preference_background_top_and_bottom
|
||||
)
|
||||
} else {
|
||||
holder.itemView.background =
|
||||
AppCompatResources.getDrawable(context, R.drawable.preference_background_top)
|
||||
}
|
||||
setMargins(holder.itemView, margin16, margin16, margin16, -1)
|
||||
} else if (bottom) {
|
||||
holder.itemView.background =
|
||||
AppCompatResources.getDrawable(context, R.drawable.preference_background_bottom)
|
||||
setMargins(holder.itemView, margin16, margin2, margin16, -1)
|
||||
} else {
|
||||
holder.itemView.background =
|
||||
AppCompatResources.getDrawable(context, R.drawable.preference_background_middle)
|
||||
setMargins(holder.itemView, margin16, margin2, margin16, -1)
|
||||
}
|
||||
|
||||
val iconImageView = holder.findViewById(android.R.id.icon)
|
||||
val titleTextView = holder.findViewById(android.R.id.title)
|
||||
val summaryTextView = holder.findViewById(android.R.id.summary)
|
||||
|
||||
customThemeWrapper?.let {
|
||||
holder.itemView.backgroundTintList = ColorStateList.valueOf(it.filledCardViewBackgroundColor)
|
||||
if (iconImageView is ImageView) {
|
||||
if (isEnabled) {
|
||||
iconImageView.setColorFilter(
|
||||
it.primaryIconColor,
|
||||
PorterDuff.Mode.SRC_IN
|
||||
)
|
||||
} else {
|
||||
iconImageView.setColorFilter(
|
||||
it.secondaryTextColor,
|
||||
PorterDuff.Mode.SRC_IN
|
||||
)
|
||||
}
|
||||
}
|
||||
if (titleTextView is TextView) {
|
||||
titleTextView.setTextColor(it.primaryTextColor)
|
||||
}
|
||||
if (summaryTextView is TextView) {
|
||||
summaryTextView.setTextColor(it.secondaryTextColor)
|
||||
}
|
||||
}
|
||||
|
||||
if (typeface != null) {
|
||||
if (titleTextView is TextView) {
|
||||
titleTextView.setTypeface(typeface)
|
||||
}
|
||||
if (summaryTextView is TextView) {
|
||||
summaryTextView.setTypeface(typeface)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setCustomFont(
|
||||
typeface: Typeface?,
|
||||
titleTypeface: Typeface?,
|
||||
contentTypeface: Typeface?
|
||||
) {
|
||||
this.typeface = typeface
|
||||
}
|
||||
|
||||
override fun setCustomThemeWrapper(customThemeWrapper: CustomThemeWrapper) {
|
||||
this.customThemeWrapper = customThemeWrapper
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun <T : View?> setMargins(view: T, left: Int, top: Int, right: Int, bottom: Int) {
|
||||
val lp = view!!.layoutParams
|
||||
if (lp is MarginLayoutParams) {
|
||||
val marginParams = lp
|
||||
|
||||
if (top >= 0) {
|
||||
marginParams.topMargin = top
|
||||
}
|
||||
if (bottom >= 0) {
|
||||
marginParams.bottomMargin = bottom
|
||||
}
|
||||
if (left >= 0) {
|
||||
marginParams.marginStart = left
|
||||
}
|
||||
if (right >= 0) {
|
||||
marginParams.marginEnd = right
|
||||
}
|
||||
|
||||
view.layoutParams = marginParams
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,7 +49,8 @@ class SliderPreference @JvmOverloads constructor(
|
||||
context.theme.obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.SliderPreference,
|
||||
0, 0).let {
|
||||
0, 0
|
||||
).let {
|
||||
try {
|
||||
min = it.getInt(R.styleable.SliderPreference_sliderMin, 0)
|
||||
max = it.getInt(R.styleable.SliderPreference_sliderMax, 100)
|
||||
|
||||
13
app/src/main/res/drawable/preference_background_bottom.xml
Normal file
13
app/src/main/res/drawable/preference_background_bottom.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?android:attr/colorControlHighlight">
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<corners
|
||||
android:bottomLeftRadius="16dp"
|
||||
android:bottomRightRadius="16dp"
|
||||
android:topLeftRadius="4dp"
|
||||
android:topRightRadius="4dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
||||
10
app/src/main/res/drawable/preference_background_middle.xml
Normal file
10
app/src/main/res/drawable/preference_background_middle.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?android:attr/colorControlHighlight">
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<corners
|
||||
android:radius="4dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
||||
13
app/src/main/res/drawable/preference_background_top.xml
Normal file
13
app/src/main/res/drawable/preference_background_top.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?android:attr/colorControlHighlight">
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<corners
|
||||
android:bottomLeftRadius="4dp"
|
||||
android:bottomRightRadius="4dp"
|
||||
android:topLeftRadius="16dp"
|
||||
android:topRightRadius="16dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
||||
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?android:attr/colorControlHighlight">
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<corners
|
||||
android:bottomLeftRadius="16dp"
|
||||
android:bottomRightRadius="16dp"
|
||||
android:topLeftRadius="16dp"
|
||||
android:topRightRadius="16dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
||||
@ -55,4 +55,9 @@
|
||||
<attr name="sliderMax" format="integer" />
|
||||
<attr name="sliderStepSize" format="integer" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="CustomFontPreference">
|
||||
<attr name="top" format="boolean" />
|
||||
<attr name="bottom" format="boolean" />
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
app:title="@string/settings_font_title"
|
||||
@ -68,6 +69,15 @@
|
||||
app:title="@string/settings_category_comment_title"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.CommentPreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontListPreference
|
||||
app:defaultValue="2.5"
|
||||
android:entries="@array/settings_lazy_mode_interval"
|
||||
app:entryValues="@array/settings_lazy_mode_interval_values"
|
||||
app:key="lazy_mode_interval"
|
||||
app:icon="@drawable/ic_access_time_day_night_24dp"
|
||||
app:title="@string/settings_lazy_mode_interval_title"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceCategory
|
||||
app:title="@string/settings_category_post_and_comment_title" />
|
||||
|
||||
|
||||
@ -2,109 +2,110 @@
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:icon="@drawable/ic_notifications_day_night_24dp"
|
||||
app:title="@string/settings_notification_master_title"
|
||||
app:top="true"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.NotificationPreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:icon="@drawable/ic_interface_day_night_24dp"
|
||||
app:title="@string/settings_interface_title"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.InterfacePreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:title="@string/settings_theme_title"
|
||||
app:icon="@drawable/ic_color_lens_day_night_24dp"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.ThemePreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
app:icon="@drawable/ic_gesture_day_night_24dp"
|
||||
app:title="@string/settings_gestures_and_buttons_title"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.GesturesAndButtonsPreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:title="@string/settigns_video_title"
|
||||
android:icon="@drawable/ic_video_day_night_24dp"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.VideoPreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontListPreference
|
||||
app:defaultValue="2.5"
|
||||
android:entries="@array/settings_lazy_mode_interval"
|
||||
app:entryValues="@array/settings_lazy_mode_interval_values"
|
||||
app:key="lazy_mode_interval"
|
||||
app:icon="@drawable/ic_access_time_day_night_24dp"
|
||||
app:title="@string/settings_lazy_mode_interval_title"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:icon="@drawable/ic_gesture_day_night_24dp"
|
||||
app:title="@string/settings_gestures_and_buttons_title"
|
||||
app:bottom="true"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.GesturesAndButtonsPreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
app:title="@string/settings_download_location_title"
|
||||
android:icon="@drawable/ic_download_day_night_24dp"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.DownloadLocationPreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:key="security"
|
||||
app:title="@string/settings_security_title"
|
||||
app:icon="@drawable/ic_security_day_night_24dp"
|
||||
app:top="true"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.SecurityPreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:title="@string/settings_data_saving_mode"
|
||||
app:icon="@drawable/ic_data_saving_mode_day_night_24dp"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.DataSavingModePreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:icon="@drawable/ic_call_split_24"
|
||||
app:title="@string/settings_proxy_title"
|
||||
app:bottom="true"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.ProxyPreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:icon="@drawable/ic_history_day_night_24dp"
|
||||
android:title="@string/settings_post_history_title"
|
||||
app:top="true"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.PostHistoryFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:icon="@drawable/ic_nsfw_on_day_night_24dp"
|
||||
app:title="@string/settings_over_18_and_spoiler_title"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.NsfwAndSpoilerFragment"/>
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
app:icon="@drawable/ic_history_day_night_24dp"
|
||||
android:title="@string/settings_post_history_title"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.PostHistoryFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:key="post_filter"
|
||||
app:icon="@drawable/ic_filter_day_night_24dp"
|
||||
app:title="@string/settings_post_filter_title" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:key="comment_filter"
|
||||
app:icon="@drawable/ic_filter_day_night_24dp"
|
||||
app:title="@string/settings_comment_filter_title" />
|
||||
app:title="@string/settings_comment_filter_title"
|
||||
app:bottom="true" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:icon="@drawable/ic_sort_day_night_24dp"
|
||||
app:title="@string/settings_sort_type_title"
|
||||
app:top="true"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.SortTypePreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:title="@string/settings_download_location_title"
|
||||
android:icon="@drawable/ic_download_day_night_24dp"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.DownloadLocationPreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
app:icon="@drawable/ic_miscellaneous_day_night_24dp"
|
||||
app:title="@string/settings_miscellaneous_title"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.MiscellaneousPreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
android:icon="@drawable/ic_advanced_day_night_24dp"
|
||||
app:title="@string/settings_advanced_master_title"
|
||||
app:bottom="true"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.AdvancedPreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
android:icon="@drawable/ic_about_day_night_24dp"
|
||||
app:title="@string/settings_about_master_title"
|
||||
app:top="true"
|
||||
app:fragment="ml.docilealligator.infinityforreddit.settings.AboutPreferenceFragment" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
android:key="privacy_policy"
|
||||
app:icon="@drawable/ic_privacy_policy_day_night_24dp"
|
||||
app:title="@string/settings_privacy_policy_title" />
|
||||
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreference
|
||||
<ml.docilealligator.infinityforreddit.customviews.preference.CustomFontPreferenceWithBackground
|
||||
android:key="reddit_user_agreement"
|
||||
app:icon="@drawable/ic_user_agreement_day_night_24dp"
|
||||
app:title="@string/settings_reddit_user_agreement_title" />
|
||||
app:title="@string/settings_reddit_user_agreement_title"
|
||||
app:bottom="true" />
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
||||
Reference in New Issue
Block a user