diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java index ebc64f54..38d054fe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java @@ -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)); - }*/ } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/preference/CustomFontPreferenceWithBackground.kt b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/preference/CustomFontPreferenceWithBackground.kt new file mode 100644 index 00000000..5ebd79a5 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/preference/CustomFontPreferenceWithBackground.kt @@ -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 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 + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/preference/SliderPreference.kt b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/preference/SliderPreference.kt index 081742ab..16b6292e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/preference/SliderPreference.kt +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/preference/SliderPreference.kt @@ -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) diff --git a/app/src/main/res/drawable/preference_background_bottom.xml b/app/src/main/res/drawable/preference_background_bottom.xml new file mode 100644 index 00000000..50d704de --- /dev/null +++ b/app/src/main/res/drawable/preference_background_bottom.xml @@ -0,0 +1,13 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/preference_background_middle.xml b/app/src/main/res/drawable/preference_background_middle.xml new file mode 100644 index 00000000..b1e4312a --- /dev/null +++ b/app/src/main/res/drawable/preference_background_middle.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/preference_background_top.xml b/app/src/main/res/drawable/preference_background_top.xml new file mode 100644 index 00000000..0ad7a80d --- /dev/null +++ b/app/src/main/res/drawable/preference_background_top.xml @@ -0,0 +1,13 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/preference_background_top_and_bottom.xml b/app/src/main/res/drawable/preference_background_top_and_bottom.xml new file mode 100644 index 00000000..2ab1fb43 --- /dev/null +++ b/app/src/main/res/drawable/preference_background_top_and_bottom.xml @@ -0,0 +1,13 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/attr.xml b/app/src/main/res/values/attr.xml index 620d92bc..98a3a6fe 100644 --- a/app/src/main/res/values/attr.xml +++ b/app/src/main/res/values/attr.xml @@ -55,4 +55,9 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/interface_preferences.xml b/app/src/main/res/xml/interface_preferences.xml index f43c0068..da51f660 100644 --- a/app/src/main/res/xml/interface_preferences.xml +++ b/app/src/main/res/xml/interface_preferences.xml @@ -1,5 +1,6 @@ - + + + diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml index b63380b0..e0686061 100644 --- a/app/src/main/res/xml/main_preferences.xml +++ b/app/src/main/res/xml/main_preferences.xml @@ -2,109 +2,110 @@ - - - - - - - + - - - - - - + + - - - - + app:title="@string/settings_comment_filter_title" + app:bottom="true" /> - - + + - - - - + app:title="@string/settings_reddit_user_agreement_title" + app:bottom="true" /> \ No newline at end of file