Fix everything about the sort by tag list

This commit is contained in:
Jobobby04 2020-09-15 21:15:52 -04:00
parent db70a62c8f
commit 67e1fee4c5
7 changed files with 80 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.category.genre
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -9,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ActionMode import androidx.appcompat.view.ActionMode
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.afollestad.materialdialogs.MaterialDialog
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
@ -43,6 +45,8 @@ class SortTagController :
*/ */
private var actionMode: ActionMode? = null private var actionMode: ActionMode? = null
private var shownHelpDialog = false
/** /**
* Adapter containing category items. * Adapter containing category items.
*/ */
@ -68,6 +72,10 @@ class SortTagController :
return resources?.getString(R.string.action_edit_tags) return resources?.getString(R.string.action_edit_tags)
} }
init {
setHasOptionsMenu(true)
}
/** /**
* Returns the view of this controller. * Returns the view of this controller.
* *
@ -91,6 +99,7 @@ class SortTagController :
binding.recycler.layoutManager = LinearLayoutManager(view.context) binding.recycler.layoutManager = LinearLayoutManager(view.context)
binding.recycler.setHasFixedSize(true) binding.recycler.setHasFixedSize(true)
binding.recycler.adapter = adapter binding.recycler.adapter = adapter
adapter?.isHandleDragEnabled = true
adapter?.isPermanentDelete = false adapter?.isPermanentDelete = false
actionFabScrollListener = actionFab?.shrinkOnScroll(binding.recycler) actionFabScrollListener = actionFab?.shrinkOnScroll(binding.recycler)
@ -102,7 +111,12 @@ class SortTagController :
fab.setIconResource(R.drawable.ic_add_24dp) fab.setIconResource(R.drawable.ic_add_24dp)
fab.clicks() fab.clicks()
.onEach { .onEach {
SortTagCreateDialog(this@SortTagController).showDialog(router, null) if (!shownHelpDialog) {
shownHelpDialog = true
helpDialog(true)
} else {
SortTagCreateDialog(this@SortTagController).showDialog(router, null)
}
} }
.launchIn(scope) .launchIn(scope)
} }
@ -145,6 +159,21 @@ class SortTagController :
} }
} }
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.sort_tags, menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_help -> {
shownHelpDialog = true
helpDialog()
}
else -> return false
}
return true
}
/** /**
* Called when action mode is first created. The menu supplied will be used to generate action * Called when action mode is first created. The menu supplied will be used to generate action
* buttons for the action mode. * buttons for the action mode.
@ -202,11 +231,27 @@ class SortTagController :
) )
mode.finish() mode.finish()
} }
R.id.action_help -> {
shownHelpDialog = true
helpDialog()
}
else -> return false else -> return false
} }
return true return true
} }
private fun helpDialog(hasPositive: Boolean = false) {
MaterialDialog(activity!!)
.title(R.string.add_tag)
.message(R.string.action_add_tags_message)
.positiveButton(android.R.string.ok) {
if (hasPositive) {
SortTagCreateDialog(this@SortTagController).showDialog(router, null)
}
}
.show()
}
/** /**
* Called when an action mode is about to be exited and destroyed. * Called when an action mode is about to be exited and destroyed.
* *

View File

@ -32,7 +32,6 @@ class SortTagCreateDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog(activity!!) return MaterialDialog(activity!!)
.title(R.string.action_add_category) .title(R.string.action_add_category)
.message(R.string.action_add_tags_message)
.negativeButton(android.R.string.cancel) .negativeButton(android.R.string.cancel)
.input( .input(
hint = resources?.getString(R.string.name), hint = resources?.getString(R.string.name),

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.category.genre
import android.view.View import android.view.View
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import kotlinx.android.synthetic.main.categories_item.reorder
import kotlinx.android.synthetic.main.categories_item.title import kotlinx.android.synthetic.main.categories_item.title
/** /**
@ -11,13 +12,27 @@ import kotlinx.android.synthetic.main.categories_item.title
* @param adapter The adapter containing this holder. * @param adapter The adapter containing this holder.
*/ */
class SortTagHolder(view: View, val adapter: SortTagAdapter) : BaseFlexibleViewHolder(view, adapter) { class SortTagHolder(view: View, val adapter: SortTagAdapter) : BaseFlexibleViewHolder(view, adapter) {
init {
setDragHandleView(reorder)
}
/** /**
* Binds this holder with the given category. * Binds this holder with the given category.
* *
* @param tag The tag to bind. * @param tag The tag to bind.
*/ */
fun bind(tag: String) { fun bind(tag: String) {
// Set capitalized title.
title.text = tag title.text = tag
} }
/**
* Called when an item is released.
*
* @param position The position of the released item.
*/
override fun onItemReleased(position: Int) {
super.onItemReleased(position)
adapter.onItemReleaseListener.onItemReleased(position)
}
} }

View File

@ -60,6 +60,9 @@ class SortTagItem(val tag: String) : AbstractFlexibleItem<SortTagHolder>() {
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other is SortTagItem) {
return tag == other.tag
}
return false return false
} }

View File

@ -264,6 +264,9 @@ class SettingsLibraryController : SettingsController() {
titleRes = R.string.pref_tag_sorting titleRes = R.string.pref_tag_sorting
val count = preferences.sortTagsForLibrary().get().size val count = preferences.sortTagsForLibrary().get().size
summary = resources!!.getQuantityString(R.plurals.pref_tag_sorting_desc, count, count) summary = resources!!.getQuantityString(R.plurals.pref_tag_sorting_desc, count, count)
onClick {
router.pushController(SortTagController().withFadeTransaction())
}
} }
} }
@ -279,10 +282,6 @@ class SettingsLibraryController : SettingsController() {
titleRes = R.string.skip_pre_migration titleRes = R.string.skip_pre_migration
summaryRes = R.string.pref_skip_pre_migration_summary summaryRes = R.string.pref_skip_pre_migration_summary
defaultValue = false defaultValue = false
onClick {
router.pushController(SortTagController().withFadeTransaction())
}
} }
} }
} }

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_help"
android:icon="@drawable/ic_help_24dp"
android:title="@string/label_help"
app:showAsAction="always" />
</menu>

View File

@ -294,7 +294,7 @@
</plurals> </plurals>
<string name="pref_tag_sorting_desc">Tag sorting list</string> <string name="pref_tag_sorting_desc">Tag sorting list</string>
<string name="action_add_tags">Add tag</string> <string name="action_add_tags">Add tag</string>
<string name="action_add_tags_message">Read this! Tags must be exact, there are no partial matches, you cannot do netorare to filter out female:netorare or similar!\nThe style for namespace tags is "female: sole female" without quotes!\nAdding multiple variants of the same tag is supported, so feel free to do "tag: netorare" for NHentai and "female: netorare" for E-Hentai!</string> <string name="action_add_tags_message">Read this! Tags must be exact, there are no partial matches, you cannot do netorare to filter out female:netorare or similar!\nThe style for namespace tags is\n\"female: sole female\"\nwithout quotes!\nAdding multiple variants of the same tag is supported, so feel free to do \"tag: netorare\" for NHentai and \"female: netorare\" for E-Hentai!</string>
<string name="action_edit_tags">Edit tags</string> <string name="action_edit_tags">Edit tags</string>
<string name="information_empty_tags">You have no tags. Tap the plus button to create one for sorting your library by tags</string> <string name="information_empty_tags">You have no tags. Tap the plus button to create one for sorting your library by tags</string>
<string name="error_tag_exists">This tag exists!</string> <string name="error_tag_exists">This tag exists!</string>