Prevent recreating monitor MenuItem

This commit is contained in:
Mygod
2019-04-03 16:32:09 +08:00
parent 10a2b777f2
commit f97afdf8ae
3 changed files with 22 additions and 17 deletions

View File

@@ -5,6 +5,7 @@ import android.os.Build
import android.text.Spannable
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.view.MenuItem
import android.view.View
import android.widget.ImageView
import androidx.annotation.DrawableRes
@@ -91,6 +92,13 @@ fun Context.stopAndUnbind(connection: ServiceConnection) {
unbindService(connection)
}
var MenuItem.isNotGone: Boolean
get() = isVisible || isEnabled
set(value) {
isVisible = value
isEnabled = value
}
fun <K, V> MutableMap<K, V>.computeIfAbsentCompat(key: K, value: () -> V) = if (Build.VERSION.SDK_INT >= 24)
computeIfAbsent(key) { value() } else this[key] ?: value().also { put(key, it) }
fun <K, V> MutableMap<K, V>.putIfAbsentCompat(key: K, value: V) = if (Build.VERSION.SDK_INT >= 24)