Skip to content

Commit

Permalink
super fun visibility modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
fennifith committed Jun 22, 2020
1 parent dcef9c2 commit 8d4874b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions androidutils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 29
versionCode 2
versionName "0.0.2"
versionCode 3
versionName "0.0.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
18 changes: 9 additions & 9 deletions androidutils/src/main/java/me/jfenn/androidutils/ViewUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ import androidx.annotation.RequiresApi
import androidx.core.graphics.drawable.DrawableCompat
import androidx.fragment.app.Fragment

internal inline fun <reified T> ignore(what: () -> T?) =
inline fun <reified T> ignore(what: () -> T?) =
try {
what()
} catch (e: Exception) {
e.printStackTrace()
null
}

internal inline fun <reified T : View> Activity.bind(@IdRes res: Int): Lazy<T?> = lazy { findView<T>(res) }
inline fun <reified T : View> Activity.bind(@IdRes res: Int): Lazy<T?> = lazy { findView<T>(res) }

internal inline fun <reified T : View> Fragment.bind(@IdRes res: Int): Lazy<T?>? = lazy { findView<T>(res) }
inline fun <reified T : View> Fragment.bind(@IdRes res: Int): Lazy<T?>? = lazy { findView<T>(res) }

internal inline fun <reified T : View> View.bind(@IdRes res: Int): Lazy<T?> = lazy { findView<T>(res) }
inline fun <reified T : View> View.bind(@IdRes res: Int): Lazy<T?> = lazy { findView<T>(res) }

internal inline fun <reified T : View> Dialog.bind(@IdRes res: Int): Lazy<T?> = lazy { findView<T>(res) }
inline fun <reified T : View> Dialog.bind(@IdRes res: Int): Lazy<T?> = lazy { findView<T>(res) }

internal inline fun <reified T : View> Activity.findView(@IdRes res: Int): T? = ignore { findViewById(res) }
inline fun <reified T : View> Activity.findView(@IdRes res: Int): T? = ignore { findViewById(res) }

internal inline fun <reified T : View> Fragment.findView(@IdRes res: Int): T? = ignore { view?.findView(res) }
inline fun <reified T : View> Fragment.findView(@IdRes res: Int): T? = ignore { view?.findView(res) }

internal inline fun <reified T : View> View.findView(@IdRes res: Int): T? = ignore { findViewById(res) }
inline fun <reified T : View> View.findView(@IdRes res: Int): T? = ignore { findViewById(res) }

internal inline fun <reified T : View> Dialog.findView(@IdRes res: Int): T? = ignore { findViewById(res) }
inline fun <reified T : View> Dialog.findView(@IdRes res: Int): T? = ignore { findViewById(res) }

@RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
fun View.setBackgroundTint(@ColorInt color: Int) {
Expand Down

0 comments on commit 8d4874b

Please sign in to comment.