Skip to content

Instantly share code, notes, and snippets.

View Skyyo's full-sized avatar
🇺🇦

Denys Rudenko Skyyo

🇺🇦
View GitHub Profile
@Skyyo
Skyyo / appbar_auto_elevation.txt
Last active August 8, 2020 16:46
Simple way to auto elevate app bar on content scroll using material styles. #elevation
implementation 'com.google.android.material:material:1.3.0-alpha01'
<CoordinatorLayout
<AppBarLayout
style="@style/Widget.MaterialComponents.AppBarLayout.Surface"
app:liftOnScroll="true"/>
<RecyclerView
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
@Skyyo
Skyyo / MiscellaneousExt.kt
Last active August 8, 2020 16:47
#extensions
package com.skyyo.ext
import android.util.Log
import android.view.View
fun hideViews(vararg views: View) = views.forEach { it.visibility = View.GONE }
fun showViews(vararg views: View) = views.forEach { it.visibility = View.VISIBLE }
fun Any.log(message: String) = Log.d("vv", message)
@Skyyo
Skyyo / RegexExt.kt
Last active August 8, 2020 16:47
#extensions
package com.skyyo.ext
inline val CharSequence?.isEmail: Boolean get() = isMatch(REGEX_EMAIL)
fun CharSequence?.isMatch(regex: String): Boolean =
!this.isNullOrEmpty() && Regex(regex).matches(this)
const val REGEX_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"
@Skyyo
Skyyo / AttentionExt.kt
Last active August 8, 2020 16:48
#extensions
package com.skyyo.ext
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.view.View
fun View.attentionBounce(): AnimatorSet {
val animatorSet = AnimatorSet()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationY", 0f, 0f, -30f, 0f, -15f, 0f, 0f)
@Skyyo
Skyyo / FlipExt.kt
Last active August 8, 2020 16:48
#extensions
package com.skyyo.ext
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.view.View
fun View.flipInX(): AnimatorSet {
val animatorSet = AnimatorSet()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0.25f, 0.5f, 0.75f, 1f)
@Skyyo
Skyyo / SlideExt.kt
Last active August 8, 2020 16:48
#extensions
package com.skyyo.ext
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.view.View
import android.view.ViewGroup
fun View.slideInDown(): AnimatorSet {
val animatorSet = AnimatorSet()
val distance = (top + height).toFloat()
@Skyyo
Skyyo / BounceExt.kt
Last active August 8, 2020 16:48
#extensions
package com.skyyo.ext
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.view.View
fun View.bounceIn(): AnimatorSet {
val animatorSet = AnimatorSet()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f, 1f, 1f)
@Skyyo
Skyyo / FadeExt.kt
Last active August 8, 2020 16:49
#extensions
package com.skyyo.ext
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.view.View
fun View.fadeIn(): AnimatorSet {
val animatorSet = AnimatorSet()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f)
@Skyyo
Skyyo / view_auto_elevation.txt
Created August 8, 2020 17:43
Solution for dynamic elevation using RV/ScrollView state. #elevation
<View
android:id="@+id/view"
android:background="@color/colorAccent"
android:stateListAnimator="@animator/toolbar_elevator"/>
<-- res/animator/toolbar_elevator.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<objectAnimator
android:duration="350"
@Skyyo
Skyyo / KeyboardExt.kt
Last active August 16, 2020 11:17
#extensions
package com.skyyo.ext
import android.app.Activity
import android.content.Context
import android.view.inputmethod.InputMethodManager
import androidx.fragment.app.Fragment
fun Fragment?.hideKeyboard() =
(this?.activity?.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager?)?.let {