All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.com.sceyt.chatuikit.shared.utils.ViewEnabledUtils.kt Maven / Gradle / Ivy

There is a newer version: 1.7.2
Show newest version
package com.sceyt.chatuikit.shared.utils

import android.os.Looper
import android.view.View
import androidx.core.view.forEach
import com.google.android.material.bottomnavigation.BottomNavigationView

object ViewEnabledUtils {

    private var runnable: Runnable? = null

    fun disableViewForWhile(view: View, duration: Long = 1000) {
        view.isEnabled = false
        val handler = android.os.Handler(Looper.getMainLooper())
        runnable = Runnable {
            view.isEnabled = true
            runnable?.let { handler.removeCallbacks(it) }
        }
        runnable?.let { handler.postDelayed(it, duration) }
    }

    fun disableClickViewForWhile(view: View, duration: Long = 1000) {
        view.isClickable = false
        val handler = android.os.Handler(Looper.getMainLooper())
        runnable = Runnable {
            view.isClickable = true
            runnable?.let { handler.removeCallbacks(it) }
        }
        runnable?.let { handler.postDelayed(it, duration) }
    }

    fun disableBottomNavForWhile(view: BottomNavigationView, duration: Long = 1000) {
        view.menu.forEach { it.isEnabled = false }

        val handler = android.os.Handler(Looper.getMainLooper())
        runnable = Runnable {
            view.menu.forEach { it.isEnabled = true }
            runnable?.let { handler.removeCallbacks(it) }
        }
        runnable?.let { handler.postDelayed(it, duration) }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy