From 489cef7962db32e5aae34127527103352e0f6643 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 7 Mar 2020 21:41:52 -0800 Subject: [PATCH] Restored "spinner" in library list mode Added Rudimentary search to recent updates, might expand on it more later --- .../tachiyomi/ui/base/CenteredToolbar.kt | 20 ++++++++++ .../tachiyomi/ui/category/CategoryHolder.kt | 2 +- .../ui/library/LibraryListController.kt | 26 +++++++++++- .../kanade/tachiyomi/ui/main/MainActivity.kt | 7 ++++ .../ui/recent_updates/RecentChapterItem.kt | 5 +++ .../recent_updates/RecentChaptersAdapter.kt | 16 ++++++++ .../RecentChaptersController.kt | 39 ++++++++++++++++-- .../recently_read/RecentlyReadController.kt | 6 +-- app/src/main/res/layout/main_activity.xml | 40 ++++++++++++++----- .../res/layout/recently_read_controller.xml | 19 ++++++++- app/src/main/res/menu/recent_updates.xml | 8 ++++ 11 files changed, 168 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/CenteredToolbar.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/CenteredToolbar.kt index b9f6a23d3c..00dccc4c69 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/CenteredToolbar.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/CenteredToolbar.kt @@ -2,8 +2,12 @@ package eu.kanade.tachiyomi.ui.base import android.content.Context import android.util.AttributeSet +import android.view.Gravity import androidx.appcompat.graphics.drawable.DrawerArrowDrawable +import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.Toolbar +import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.visible import kotlinx.android.synthetic.main.main_activity.view.* class CenteredToolbar@JvmOverloads constructor(context: Context, attrs: AttributeSet? = null): Toolbar @@ -30,4 +34,20 @@ class CenteredToolbar@JvmOverloads constructor(context: Context, attrs: Attribut super.setTitle(null) } } + + fun showSpinner(): PopupMenu { + val popupMenu = PopupMenu(context, title_layout, Gravity.CENTER) + dropdown.visible() + title_layout.setOnTouchListener(popupMenu.dragToOpenListener) + title_layout.setOnClickListener { + popupMenu.show() + } + return popupMenu + } + + fun removeSpinner() { + dropdown.gone() + title_layout.setOnTouchListener(null) + title_layout.setOnClickListener(null) + } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt index 96ee53745f..8f4cb3deee 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryHolder.kt @@ -100,7 +100,7 @@ class CategoryHolder(view: View, val adapter: CategoryAdapter) : BaseFlexibleVie reorder.setOnTouchListener { _, _ -> true} } edit_text.clearFocus() - edit_button.drawable.mutate().setTint(ContextCompat.getColor(itemView.context, R + edit_button.drawable?.mutate()?.setTint(ContextCompat.getColor(itemView.context, R .color.gray_button)) reorder.setImageDrawable(regularDrawable) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt index 293ad2f4a0..b2aaf7ec60 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt @@ -27,6 +27,7 @@ import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.ui.main.SpinnerTitleInterface import eu.kanade.tachiyomi.ui.main.SwipeGestureInterface import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.launchUI @@ -49,6 +50,7 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), FlexibleAdapter.OnItemLongClickListener, FlexibleAdapter.OnItemMoveListener, LibraryCategoryAdapter.LibraryListener, + SpinnerTitleInterface, SwipeGestureInterface { private lateinit var adapter: LibraryCategoryAdapter @@ -108,7 +110,6 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), override fun onViewCreated(view: View) { super.onViewCreated(view) - // pad the recycler if the filter bottom sheet is visible if (!phoneLandscape) { val height = view.context.resources.getDimensionPixelSize(R.dimen.rounder_radius) + 4.dpToPx @@ -166,6 +167,13 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { super.onChangeStarted(handler, type) + if (type.isEnter) { + if (presenter.categories.size > 1) { + activity?.toolbar?.showSpinner() + } else { + activity?.toolbar?.removeSpinner() + } + } /*if (type.isEnter) { (activity as MainActivity).supportActionBar ?.setDisplayShowCustomEnabled(router?.backstack?.lastOrNull()?.controller() == @@ -228,9 +236,23 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), } adapter.isLongPressDragEnabled = canDrag() + val popupMenu = if (presenter.categories.size > 1) { + activity?.toolbar?.showSpinner() + } + else { + activity?.toolbar?.removeSpinner() + null + } + titlePopupMenu.menu.clear() presenter.categories.forEach { category -> titlePopupMenu.menu.add(0, category.order, max(0, category.order), category.name) + popupMenu?.menu?.add(0, category.order, max(0, category.order), category.name) + } + + popupMenu?.setOnMenuItemClickListener { item -> + scrollToHeader(item.itemId) + true } customTitleSpinner.setOnClickListener { @@ -591,4 +613,6 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), scrollToHeader (newOffset, true) } } + + override fun popUpMenu(): PopupMenu = titlePopupMenu } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 6c77b6a5ba..fcd7a9b6c9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -20,6 +20,7 @@ import android.view.WindowManager import android.webkit.WebView import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.graphics.drawable.DrawerArrowDrawable +import androidx.appcompat.widget.PopupMenu import androidx.core.content.ContextCompat import androidx.core.graphics.ColorUtils import androidx.core.view.GestureDetectorCompat @@ -619,6 +620,8 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { }*/ } + if (to !is SpinnerTitleInterface) toolbar.removeSpinner() + if (to !is DialogController) { navigationView.visibility = if (router.backstackSize == 0 || (router.backstackSize <= 1 && !isPush)) @@ -736,6 +739,10 @@ interface BottomNavBarInterface { interface RootSearchInterface +interface SpinnerTitleInterface { + fun popUpMenu(): PopupMenu +} + interface SwipeGestureInterface { fun onSwipeRight(x: Float, y: Float) fun onSwipeLeft(x: Float, y: Float) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterItem.kt index ba0d0098e0..aeb7106a6d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterItem.kt @@ -40,6 +40,11 @@ class RecentChapterItem(val chapter: Chapter, val manga: Manga, header: DateItem holder.bind(this) } + fun filter(text: String): Boolean { + return chapter.name.contains(text, false) || + manga.currentTitle().contains(text, false) + } + override fun equals(other: Any?): Boolean { if (this === other) return true if (other is RecentChapterItem) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersAdapter.kt index 67715508e9..995bb3ee55 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersAdapter.kt @@ -7,12 +7,28 @@ class RecentChaptersAdapter(val controller: RecentChaptersController) : FlexibleAdapter>(null, controller, true) { val coverClickListener: OnCoverClickListener = controller + var recents = emptyList() init { setDisplayHeadersAtStartUp(true) //setStickyHeaders(true) } + fun setItems(recents: List) { + this.recents = recents + performFilter() + } + + fun performFilter() { + val s = getFilter(String::class.java) + if (s.isNullOrBlank()) { + updateDataSet(recents) + } + else { + updateDataSet(recents.filter { it.filter(s) }) + } + } + interface OnCoverClickListener { fun onCoverClick(position: Int) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt index d0f0946309..b34135f648 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt @@ -8,13 +8,13 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode +import androidx.appcompat.widget.SearchView import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import com.jakewharton.rxbinding.support.v4.widget.refreshes import com.jakewharton.rxbinding.support.v7.widget.scrollStateChanges import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.SelectableAdapter -import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.library.LibraryUpdateService @@ -23,12 +23,14 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.main.MainActivity +import eu.kanade.tachiyomi.ui.main.RootSearchInterface import eu.kanade.tachiyomi.ui.manga.MangaDetailsController import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.recently_read.RecentlyReadController import eu.kanade.tachiyomi.util.system.notificationManager import eu.kanade.tachiyomi.util.view.applyWindowInsetsForRootController import eu.kanade.tachiyomi.util.view.scrollViewWith +import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener import eu.kanade.tachiyomi.util.view.snack import kotlinx.android.synthetic.main.main_activity.* import kotlinx.android.synthetic.main.recent_chapters_controller.* @@ -47,6 +49,7 @@ class RecentChaptersController : NucleusController(), FlexibleAdapter.OnItemLongClickListener, FlexibleAdapter.OnUpdateListener, ConfirmDeleteChaptersDialog.Listener, + RootSearchInterface, RecentChaptersAdapter.OnCoverClickListener { init { @@ -63,6 +66,8 @@ class RecentChaptersController : NucleusController(), var adapter: RecentChaptersAdapter? = null private set + private var query = "" + override fun getTitle(): String? { return resources?.getString(R.string.label_recent_updates) } @@ -191,9 +196,9 @@ class RecentChaptersController : NucleusController(), * Populate adapter with chapters * @param chapters list of [Any] */ - fun onNextRecentChapters(chapters: List>) { + fun onNextRecentChapters(chapters: List) { destroyActionModeIfNeeded() - adapter?.updateDataSet(chapters) + adapter?.setItems(chapters) } override fun onUpdateEmptyView(size: Int) { @@ -344,6 +349,34 @@ class RecentChaptersController : NucleusController(), override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { inflater.inflate(R.menu.recent_updates, menu) + val searchItem = menu.findItem(R.id.action_search) + val searchView = searchItem.actionView as SearchView + searchView.queryHint = resources?.getString(R.string.action_search) + if (query.isNotEmpty()) { + searchItem.expandActionView() + searchView.setQuery(query, true) + searchView.clearFocus() + } + setOnQueryTextChangeListener(searchView) { + if (query != it) { + query = it ?: return@setOnQueryTextChangeListener false + adapter?.setFilter(query) + adapter?.performFilter() + } + true + } + + // Fixes problem with the overflow icon showing up in lieu of search + searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener { + override fun onMenuItemActionExpand(item: MenuItem): Boolean { + return true + } + + override fun onMenuItemActionCollapse(item: MenuItem): Boolean { + activity?.invalidateOptionsMenu() + return true + } + }) } override fun onOptionsItemSelected(item: MenuItem): Boolean { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt index 77923730bd..0367877c6c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt @@ -136,10 +136,10 @@ class RecentlyReadController(bundle: Bundle? = null) : BaseController(bundle), override fun onUpdateEmptyView(size: Int) { if (size > 0) { - // empty_view?.hide() + empty_view?.hide() } else { - // empty_view.show(R.drawable.ic_history_white_128dp, R.string - //.information_no_recent_manga) + empty_view.show(R.drawable.ic_history_white_128dp, R.string + .information_no_recent_manga) } } diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index c608fe3ac9..ed7fee46cd 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -1,6 +1,7 @@ - + android:clickable="true" + android:focusable="true" + android:orientation="horizontal" + tools:background="?colorPrimary"> + + + + + - + + + + + + diff --git a/app/src/main/res/menu/recent_updates.xml b/app/src/main/res/menu/recent_updates.xml index d6be66985c..2b4f9944a7 100644 --- a/app/src/main/res/menu/recent_updates.xml +++ b/app/src/main/res/menu/recent_updates.xml @@ -2,6 +2,14 @@ + +