From 50f959e5f41fa5d4117e821fb82db761cfdcf33f Mon Sep 17 00:00:00 2001 From: d-najd <59766732+d-najd@users.noreply.github.com> Date: Sat, 8 Oct 2022 23:12:09 +0200 Subject: [PATCH] Hiding the keyboard (#8160) * Hiding the keyboard (#8157) * Cleanup * Adding log * cleanup * moving code to ViewExtensions.kt * TrackDialog keyboard fix? * moving code to ContextExtensions.kt * MoreScreen: Remove title (#8158) * MoreScreen: Remove title Also removes the state banners as it's redundant * Add back banners * Allow manual selection of manga description instead of copying to clipboard Closes #6548 Notably missing some "standard" options like "Select all" or "Share": https://issuetracker.google.com/issues/226648919 * Allow marking partially read chapters as unread Closes #3777 * Tablet UI edge-to-edge tweaks (#8159) * LibraryScreen: Tweak content padding application to draw under nav bar * BrowseScreen: Tweak content padding application to draw under nav bar Side note the tab content doesn't actually use its scaffold (bottom) contentPadding so it's definitely will be a headache in the future. * Don't hardcode bottom nav padding * removed unnecessary import * refactoring code * rewriting code * cleanup? * cleanup Co-authored-by: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Co-authored-by: arkon --- .../eu/kanade/tachiyomi/ui/base/controller/BaseController.kt | 3 +++ .../eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt | 5 ++--- .../eu/kanade/tachiyomi/util/system/ContextExtensions.kt | 4 ++++ .../java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt | 5 +++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt index 94039e889..207f7fed8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt @@ -10,6 +10,7 @@ import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import eu.kanade.tachiyomi.util.system.logcat +import eu.kanade.tachiyomi.util.view.hideKeyboard import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.MainScope import kotlinx.coroutines.cancel @@ -61,6 +62,8 @@ abstract class BaseController(bundle: Bundle? = null) : Contro open fun onViewCreated(view: View) {} override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { + view?.hideKeyboard() + if (type.isEnter) { setTitle() setHasOptionsMenu(true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt index f8f0aaf43..6cd1bc368 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt @@ -6,8 +6,6 @@ import android.view.KeyEvent import android.view.LayoutInflater import android.view.View import android.view.inputmethod.EditorInfo -import android.view.inputmethod.InputMethodManager -import androidx.core.content.getSystemService import androidx.core.os.bundleOf import androidx.core.view.WindowCompat import androidx.core.view.isVisible @@ -19,6 +17,7 @@ import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.databinding.TrackSearchDialogBinding import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.manga.MangaController +import eu.kanade.tachiyomi.util.view.hideKeyboard import eu.kanade.tachiyomi.util.view.setNavigationBarTransparentCompat import eu.kanade.tachiyomi.widget.TachiyomiFullscreenDialog import kotlinx.coroutines.flow.filter @@ -103,7 +102,7 @@ class TrackSearchDialog : DialogController { if (query != currentlySearched) { currentlySearched = query search(it.view.text.toString()) - it.view.context.getSystemService()?.hideSoftInputFromWindow(it.view.windowToken, 0) + it.view.hideKeyboard() it.view.clearFocus() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index 075859c06..a055212d3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -24,6 +24,7 @@ import android.util.TypedValue import android.view.Display import android.view.View import android.view.WindowManager +import android.view.inputmethod.InputMethodManager import androidx.annotation.AttrRes import androidx.annotation.ColorInt import androidx.appcompat.view.ContextThemeWrapper @@ -185,6 +186,9 @@ val Context.powerManager: PowerManager val Context.keyguardManager: KeyguardManager get() = getSystemService()!! +val Context.inputMethodManager: InputMethodManager + get() = getSystemService()!! + val Context.displayCompat: Display? get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { display diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt index 4397fe3e1..66cc88503 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt @@ -37,6 +37,7 @@ import com.google.android.material.snackbar.Snackbar import eu.kanade.presentation.theme.TachiyomiTheme import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.getResourceColor +import eu.kanade.tachiyomi.util.system.inputMethodManager inline fun ComposeView.setComposeContent(crossinline content: @Composable () -> Unit) { consumeWindowInsets = false @@ -209,3 +210,7 @@ fun View?.isVisibleOnScreen(): Boolean { val screen = Rect(0, 0, Resources.getSystem().displayMetrics.widthPixels, Resources.getSystem().displayMetrics.heightPixels) return actualPosition.intersect(screen) } + +fun View.hideKeyboard() { + context.inputMethodManager.hideSoftInputFromWindow(windowToken, 0) +}