|
@@ -13,6 +13,8 @@
|
|
|
* See the License for the specific language governing permissions and
|
|
|
* limitations under the License.
|
|
|
*/
|
|
|
+@file:Suppress("NOTHING_TO_INLINE")
|
|
|
+
|
|
|
package com.afollestad.materialdialogs.utils
|
|
|
|
|
|
import android.content.Context
|
|
@@ -39,19 +41,17 @@ import com.afollestad.materialdialogs.MaterialDialog
|
|
|
@RestrictTo(LIBRARY_GROUP)
|
|
|
object MDUtil {
|
|
|
|
|
|
- @RestrictTo(LIBRARY_GROUP) fun resolveString(
|
|
|
+ @RestrictTo(LIBRARY_GROUP) inline fun resolveString(
|
|
|
materialDialog: MaterialDialog,
|
|
|
@StringRes res: Int? = null,
|
|
|
@StringRes fallback: Int? = null,
|
|
|
html: Boolean = false
|
|
|
- ): CharSequence? {
|
|
|
- return resolveString(
|
|
|
- context = materialDialog.windowContext,
|
|
|
- res = res,
|
|
|
- fallback = fallback,
|
|
|
- html = html
|
|
|
- )
|
|
|
- }
|
|
|
+ ): CharSequence? = resolveString(
|
|
|
+ context = materialDialog.windowContext,
|
|
|
+ res = res,
|
|
|
+ fallback = fallback,
|
|
|
+ html = html
|
|
|
+ )
|
|
|
|
|
|
@RestrictTo(LIBRARY_GROUP) fun resolveString(
|
|
|
context: Context,
|
|
@@ -91,8 +91,7 @@ object MDUtil {
|
|
|
return ContextCompat.getDrawable(context, res)
|
|
|
}
|
|
|
|
|
|
- @RestrictTo(LIBRARY_GROUP)
|
|
|
- @ColorInt
|
|
|
+ @RestrictTo(LIBRARY_GROUP) @ColorInt
|
|
|
fun resolveColor(
|
|
|
context: Context,
|
|
|
@ColorRes res: Int? = null,
|
|
@@ -114,6 +113,28 @@ object MDUtil {
|
|
|
return ContextCompat.getColor(context, res ?: 0)
|
|
|
}
|
|
|
|
|
|
+ @RestrictTo(LIBRARY_GROUP)
|
|
|
+ fun resolveColors(
|
|
|
+ context: Context,
|
|
|
+ attrs: IntArray,
|
|
|
+ fallback: ((forAttr: Int) -> Int)? = null
|
|
|
+ ): IntArray {
|
|
|
+ val a = context.theme.obtainStyledAttributes(attrs)
|
|
|
+ try {
|
|
|
+ return (0 until attrs.size).map { index ->
|
|
|
+ val color = a.getColor(index, 0)
|
|
|
+ return@map if (color != 0) {
|
|
|
+ color
|
|
|
+ } else {
|
|
|
+ fallback?.invoke(attrs[index]) ?: 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .toIntArray()
|
|
|
+ } finally {
|
|
|
+ a.recycle()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@RestrictTo(LIBRARY_GROUP) fun resolveInt(
|
|
|
context: Context,
|
|
|
@AttrRes attr: Int,
|
|
@@ -136,11 +157,12 @@ object MDUtil {
|
|
|
return darkness >= threshold
|
|
|
}
|
|
|
|
|
|
- @RestrictTo(LIBRARY_GROUP) fun <T : View> T.dimenPx(@DimenRes res: Int): Int {
|
|
|
+ @RestrictTo(LIBRARY_GROUP)
|
|
|
+ inline fun <T : View> T.dimenPx(@DimenRes res: Int): Int {
|
|
|
return context.resources.getDimensionPixelSize(res)
|
|
|
}
|
|
|
|
|
|
- @RestrictTo(LIBRARY_GROUP) fun Context.isLandscape() =
|
|
|
+ @RestrictTo(LIBRARY_GROUP) inline fun Context.isLandscape() =
|
|
|
resources.configuration.orientation == ORIENTATION_LANDSCAPE
|
|
|
|
|
|
@RestrictTo(LIBRARY_GROUP) fun EditText.textChanged(callback: (CharSequence) -> Unit) {
|