mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 11:10:52 +00:00
IMM service usage deprecation cleanup.
This commit is contained in:
parent
756aeba7ab
commit
486b1e94f8
@ -1,10 +1,12 @@
|
||||
package io.casey.musikcube.remote.ui.shared.extension
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.SearchManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Resources
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
@ -397,9 +399,16 @@ fun AppCompatActivity.getColorCompat(resourceId: Int): Int =
|
||||
*
|
||||
*/
|
||||
|
||||
fun showKeyboard(context: Context) {
|
||||
@Suppress("deprecation")
|
||||
fun showKeyboard(context: Activity) {
|
||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY)
|
||||
if (Build.VERSION.SDK_INT >= 31) {
|
||||
val view = context.currentFocus ?: context.findViewById(android.R.id.content)
|
||||
imm.showSoftInput(view , 0)
|
||||
}
|
||||
else {
|
||||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY)
|
||||
}
|
||||
}
|
||||
|
||||
fun hideKeyboard(context: Context, view: View) {
|
||||
@ -413,10 +422,10 @@ fun AppCompatActivity.hideKeyboard(view: View? = null) {
|
||||
}
|
||||
|
||||
fun DialogFragment.showKeyboard() =
|
||||
showKeyboard(activity!!)
|
||||
showKeyboard(requireActivity())
|
||||
|
||||
fun DialogFragment.hideKeyboard() {
|
||||
val fragmentActivity = activity!! /* keep it in the closure so it doesn't get gc'd */
|
||||
val fragmentActivity = requireActivity() /* keep it in the closure so it doesn't get gc'd */
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
hideKeyboard(
|
||||
fragmentActivity,
|
||||
|
@ -3,8 +3,8 @@ package io.casey.musikcube.remote.ui.shared.util
|
||||
import android.annotation.SuppressLint
|
||||
import android.util.Log
|
||||
import io.casey.musikcube.remote.Application
|
||||
import io.casey.musikcube.remote.ui.shared.extension.getPackageInfoCompat
|
||||
import io.casey.musikcube.remote.util.Preconditions
|
||||
import io.casey.musikcube.remote.util.getPackageInfoCompat
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
Loading…
Reference in New Issue
Block a user