From 2d80f6f26bb67e1f1f3c8b5e77d3293ba60db8a4 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 13 Jan 2020 21:05:59 -0800 Subject: [PATCH] Dismiss keybaord when long pressing manga while searching --- .../tachiyomi/ui/library/LibraryCategoryView.kt | 1 + .../tachiyomi/ui/library/LibraryController.kt | 11 +++++++---- .../eu/kanade/tachiyomi/util/ViewExtensions.kt | 17 +++++++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index ddfc3cf9e6..c68f83f40c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -259,6 +259,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att is LibrarySelectionEvent.Cleared -> { adapter.mode = SelectableAdapter.Mode.SINGLE adapter.clearSelection() + adapter.notifyDataSetChanged() lastClickPosition = -1 adapter.isLongPressDragEnabled = canDrag() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 366277a4a1..8da6c3f89f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.library import android.app.Activity +import android.content.Context import android.content.Intent import android.content.res.Configuration import android.graphics.Color @@ -13,9 +14,11 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.view.WindowInsets +import android.view.inputmethod.InputMethodManager import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode import androidx.appcompat.widget.SearchView +import androidx.core.content.ContextCompat.getSystemService import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.GravityCompat import androidx.drawerlayout.widget.DrawerLayout @@ -89,8 +92,6 @@ class LibraryController( */ private var query = "" - private var searchItem:MenuItem? = null - /** * Currently selected mangas. */ @@ -361,7 +362,10 @@ class LibraryController( fun createActionModeIfNeeded() { if (actionMode == null) { actionMode = (activity as AppCompatActivity).startSupportActionMode(this) - searchItem?.collapseActionView() + val view = activity?.window?.currentFocus ?: return + val imm = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as? + InputMethodManager ?: return + imm.hideSoftInputFromWindow(view.windowToken, 0) } } @@ -381,7 +385,6 @@ class LibraryController( val searchItem = menu.findItem(R.id.action_search) val searchView = searchItem.actionView as SearchView searchView.queryHint = resources?.getString(R.string.search_hint) - this.searchItem = searchItem searchItem.collapseActionView() if (!query.isEmpty()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt index 83db35c3fb..69b4f32b48 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt @@ -6,21 +6,22 @@ import android.content.Context import android.graphics.Color import android.graphics.Point import android.graphics.Typeface -import android.os.Build -import androidx.annotation.Px -import androidx.annotation.RequiresApi -import com.google.android.material.snackbar.Snackbar -import androidx.core.view.ViewCompat -import androidx.core.view.WindowInsetsCompat import android.view.View import android.view.ViewGroup -import android.view.Window import android.view.WindowInsets import android.widget.TextView +import androidx.annotation.Px +import androidx.annotation.RequiresApi import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.core.view.ViewCompat +import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.WhichButton +import com.afollestad.materialdialogs.actions.getActionButton +import com.afollestad.materialdialogs.actions.hasActionButton import com.amulyakhare.textdrawable.TextDrawable -import com.amulyakhare.textdrawable.util.ColorGenerator import eu.kanade.tachiyomi.R +import com.amulyakhare.textdrawable.util.ColorGenerator +import com.google.android.material.snackbar.Snackbar import kotlin.math.min /**