Added hiding keyboard when "done" button pressed

This commit is contained in:
Viktor De Pasquale 2019-11-14 15:19:48 +01:00
parent eec5b37da1
commit c69dcf3e20
3 changed files with 18 additions and 0 deletions

View File

@ -1,9 +1,12 @@
package com.topjohnwu.magisk.redesign.compat package com.topjohnwu.magisk.redesign.compat
import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import androidx.core.content.getSystemService
import androidx.databinding.OnRebindCallback import androidx.databinding.OnRebindCallback
import androidx.databinding.ViewDataBinding import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
@ -17,6 +20,7 @@ import com.topjohnwu.magisk.model.navigation.MagiskNavigationEvent
import com.topjohnwu.magisk.model.navigation.Navigator import com.topjohnwu.magisk.model.navigation.Navigator
import kotlin.reflect.KClass import kotlin.reflect.KClass
abstract class CompatActivity<ViewModel : CompatViewModel, Binding : ViewDataBinding> : abstract class CompatActivity<ViewModel : CompatViewModel, Binding : ViewDataBinding> :
BaseActivity<ViewModel, Binding>(), CompatView<ViewModel>, Navigator { BaseActivity<ViewModel, Binding>(), CompatView<ViewModel>, Navigator {
@ -79,3 +83,10 @@ abstract class CompatActivity<ViewModel : CompatViewModel, Binding : ViewDataBin
protected fun ViewEvent.dispatchOnSelf() = onEventDispatched(this) protected fun ViewEvent.dispatchOnSelf() = onEventDispatched(this)
} }
fun Activity.hideKeyboard() {
val view = currentFocus ?: return
getSystemService<InputMethodManager>()
?.hideSoftInputFromWindow(view.windowToken, 0)
view.clearFocus()
}

View File

@ -5,6 +5,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.databinding.OnRebindCallback import androidx.databinding.OnRebindCallback
import androidx.databinding.ViewDataBinding import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import com.topjohnwu.magisk.base.BaseFragment import com.topjohnwu.magisk.base.BaseFragment
import com.topjohnwu.magisk.extensions.startAnimations import com.topjohnwu.magisk.extensions.startAnimations
import com.topjohnwu.magisk.model.events.ViewEvent import com.topjohnwu.magisk.model.events.ViewEvent
@ -49,3 +50,7 @@ abstract class CompatFragment<ViewModel : CompatViewModel, Binding : ViewDataBin
protected fun ViewEvent.dispatchOnSelf() = delegate.onEventExecute(this, this@CompatFragment) protected fun ViewEvent.dispatchOnSelf() = delegate.onEventExecute(this, this@CompatFragment)
} }
fun Fragment.hideKeyboard() {
activity?.hideKeyboard()
}

View File

@ -22,6 +22,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.FragmentHideMd2Binding import com.topjohnwu.magisk.databinding.FragmentHideMd2Binding
import com.topjohnwu.magisk.redesign.compat.CompatFragment import com.topjohnwu.magisk.redesign.compat.CompatFragment
import com.topjohnwu.magisk.redesign.compat.hideKeyboard
import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.androidx.viewmodel.ext.android.viewModel
import kotlin.math.hypot import kotlin.math.hypot
@ -45,6 +46,7 @@ class HideFragment : CompatFragment<HideViewModel, FragmentHideMd2Binding>() {
MotionRevealHelper.withViews(binding.hideFilter, binding.hideFilterToggle, true) MotionRevealHelper.withViews(binding.hideFilter, binding.hideFilterToggle, true)
} }
binding.hideFilterInclude.hideFilterDone.setOnClickListener { binding.hideFilterInclude.hideFilterDone.setOnClickListener {
hideKeyboard()
MotionRevealHelper.withViews(binding.hideFilter, binding.hideFilterToggle, false) MotionRevealHelper.withViews(binding.hideFilter, binding.hideFilterToggle, false)
} }