Loading common/src/main/java/com/moez/QKSMS/common/util/extensions/ContextExtensions.kt +15 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.moez.QKSMS.common.util.extensions import android.content.Context import android.content.res.ColorStateList import android.graphics.Color import android.util.TypedValue import android.widget.Toast Loading @@ -31,6 +32,12 @@ fun Context.getColorCompat(colorRes: Int): Int { return tryOrNull { ContextCompat.getColor(this, colorRes) } ?: Color.BLACK } fun Context.getColorStateListCompat(colorStateListRes: Int): ColorStateList { //return black as a default color, in case an invalid color ID was passed in return tryOrNull { ContextCompat.getColorStateList(this, colorStateListRes) } ?: ColorStateList.valueOf(Color.BLACK) } /** * Tries to resolve a resource id from the current theme, based on the [attributeId] */ Loading @@ -55,6 +62,14 @@ fun Context.resolveThemeColor(attributeId: Int, default: Int = 0): Int { return if (wasResolved) getColorCompat(outValue.resourceId) else default } fun Context.resolveThemeColorStateList(attributeId: Int, default: Int = 0): ColorStateList { val outValue = TypedValue() val wasResolved = theme.resolveAttribute(attributeId, outValue, true) return getColorStateListCompat(if (wasResolved) outValue.resourceId else default) } fun Context.makeToast(@StringRes res: Int, duration: Int = Toast.LENGTH_SHORT) { Toast.makeText(this, res, duration).show() } Loading presentation/src/main/java/com/moez/QKSMS/common/widget/PreferenceView.kt +4 −1 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.widget.TextView import androidx.appcompat.widget.LinearLayoutCompat import com.moez.QKSMS.R import com.moez.QKSMS.common.util.extensions.resolveThemeAttribute import com.moez.QKSMS.common.util.extensions.resolveThemeColorStateList import com.moez.QKSMS.common.util.extensions.setVisible import com.moez.QKSMS.injection.appComponent import kotlinx.android.synthetic.main.preference_view.view.* Loading Loading @@ -71,7 +72,9 @@ class PreferenceView @JvmOverloads constructor( orientation = HORIZONTAL gravity = Gravity.CENTER_VERTICAL context.obtainStyledAttributes(attrs, R.styleable.PreferenceView)?.run { icon.imageTintList = context.resolveThemeColorStateList(android.R.attr.textColorSecondary) context.obtainStyledAttributes(attrs, R.styleable.PreferenceView).run { title = getString(R.styleable.PreferenceView_title) summary = getString(R.styleable.PreferenceView_summary) Loading presentation/src/main/res/layout/preference_view.xml +0 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ android:layout_height="24dp" android:layout_marginStart="24dp" android:duplicateParentState="true" android:tint="?android:attr/textColorSecondary" android:visibility="invisible" /> <LinearLayout Loading Loading
common/src/main/java/com/moez/QKSMS/common/util/extensions/ContextExtensions.kt +15 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.moez.QKSMS.common.util.extensions import android.content.Context import android.content.res.ColorStateList import android.graphics.Color import android.util.TypedValue import android.widget.Toast Loading @@ -31,6 +32,12 @@ fun Context.getColorCompat(colorRes: Int): Int { return tryOrNull { ContextCompat.getColor(this, colorRes) } ?: Color.BLACK } fun Context.getColorStateListCompat(colorStateListRes: Int): ColorStateList { //return black as a default color, in case an invalid color ID was passed in return tryOrNull { ContextCompat.getColorStateList(this, colorStateListRes) } ?: ColorStateList.valueOf(Color.BLACK) } /** * Tries to resolve a resource id from the current theme, based on the [attributeId] */ Loading @@ -55,6 +62,14 @@ fun Context.resolveThemeColor(attributeId: Int, default: Int = 0): Int { return if (wasResolved) getColorCompat(outValue.resourceId) else default } fun Context.resolveThemeColorStateList(attributeId: Int, default: Int = 0): ColorStateList { val outValue = TypedValue() val wasResolved = theme.resolveAttribute(attributeId, outValue, true) return getColorStateListCompat(if (wasResolved) outValue.resourceId else default) } fun Context.makeToast(@StringRes res: Int, duration: Int = Toast.LENGTH_SHORT) { Toast.makeText(this, res, duration).show() } Loading
presentation/src/main/java/com/moez/QKSMS/common/widget/PreferenceView.kt +4 −1 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.widget.TextView import androidx.appcompat.widget.LinearLayoutCompat import com.moez.QKSMS.R import com.moez.QKSMS.common.util.extensions.resolveThemeAttribute import com.moez.QKSMS.common.util.extensions.resolveThemeColorStateList import com.moez.QKSMS.common.util.extensions.setVisible import com.moez.QKSMS.injection.appComponent import kotlinx.android.synthetic.main.preference_view.view.* Loading Loading @@ -71,7 +72,9 @@ class PreferenceView @JvmOverloads constructor( orientation = HORIZONTAL gravity = Gravity.CENTER_VERTICAL context.obtainStyledAttributes(attrs, R.styleable.PreferenceView)?.run { icon.imageTintList = context.resolveThemeColorStateList(android.R.attr.textColorSecondary) context.obtainStyledAttributes(attrs, R.styleable.PreferenceView).run { title = getString(R.styleable.PreferenceView_title) summary = getString(R.styleable.PreferenceView_summary) Loading
presentation/src/main/res/layout/preference_view.xml +0 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ android:layout_height="24dp" android:layout_marginStart="24dp" android:duplicateParentState="true" android:tint="?android:attr/textColorSecondary" android:visibility="invisible" /> <LinearLayout Loading