Disable Volumes keys on flash

- Thank Diareuse for helping me
This commit is contained in:
Fox2Code 2020-06-07 09:43:49 +02:00 committed by John Wu
parent 4b8e92f00a
commit 93d5716414
3 changed files with 19 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package com.topjohnwu.magisk.ui.base
import android.content.Intent
import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatDelegate
@ -96,6 +97,10 @@ abstract class BaseUIActivity<ViewModel : BaseViewModel, Binding : ViewDataBindi
delegate.onResume()
}
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
return currentFragment?.onKeyEvent(event) == true || super.dispatchKeyEvent(event)
}
override fun onEventDispatched(event: ViewEvent) {
delegate.onEventExecute(event, this)
when (event) {

View File

@ -1,6 +1,7 @@
package com.topjohnwu.magisk.ui.base
import android.os.Bundle
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -51,6 +52,10 @@ abstract class BaseUIFragment<ViewModel : BaseViewModel, Binding : ViewDataBindi
delegate.onEventExecute(event, this)
}
open fun onKeyEvent(event: KeyEvent): Boolean {
return false
}
open fun onBackPressed(): Boolean = false

View File

@ -5,6 +5,7 @@ import android.content.Context
import android.content.pm.ActivityInfo
import android.net.Uri
import android.os.Bundle
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
@ -62,6 +63,14 @@ class FlashFragment : BaseUIFragment<FlashViewModel, FragmentFlashMd2Binding>()
super.onDestroyView()
}
override fun onKeyEvent(event: KeyEvent): Boolean {
return when(event.keyCode) {
KeyEvent.KEYCODE_VOLUME_UP,
KeyEvent.KEYCODE_VOLUME_DOWN -> true
else -> false
}
}
override fun onBackPressed(): Boolean {
if (viewModel.loading) return true
return super.onBackPressed()