Remove Source sorting, added searching by source

This commit is contained in:
Jay 2020-01-09 22:29:08 -08:00
parent c692510c54
commit d8e598aaaf
7 changed files with 26 additions and 31 deletions

View File

@ -71,6 +71,10 @@ open class SourceManager(private val context: Context) {
return SourceNotFoundException(context.getString(R.string.source_not_installed, id return SourceNotFoundException(context.getString(R.string.source_not_installed, id
.toString()), id) .toString()), id)
} }
override fun hashCode(): Int {
return id.hashCode()
}
} }
} }

View File

@ -92,11 +92,6 @@ class LibraryCategoryAdapter(val view: LibraryCategoryView) :
else else
"N/A" "N/A"
} }
LibrarySort.SOURCE -> {
val sourceId = (iFlexible as LibraryItem).manga.source
val sourceManager:SourceManager by injectLazy()
sourceManager.getOrStub(sourceId).name.substring(0, 1).toUpperCase(Locale.US)
}
else -> { else -> {
val title = (iFlexible as LibraryItem).manga.title val title = (iFlexible as LibraryItem).manga.title
if (preferences.removeArticles().getOrDefault()) if (preferences.removeArticles().getOrDefault())

View File

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.ui.library package eu.kanade.tachiyomi.ui.library
import android.annotation.SuppressLint
import android.view.Gravity import android.view.Gravity
import android.view.View import android.view.View
import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.MATCH_PARENT
@ -13,8 +14,10 @@ import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.LibraryManga
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.widget.AutofitRecyclerView import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import kotlinx.android.synthetic.main.catalogue_grid_item.view.* import kotlinx.android.synthetic.main.catalogue_grid_item.view.*
import uy.kohesive.injekt.injectLazy
class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference<Boolean>) : class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference<Boolean>) :
AbstractFlexibleItem<LibraryHolder>(), IFilterable<String> { AbstractFlexibleItem<LibraryHolder>(), IFilterable<String> {
@ -65,8 +68,11 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference
* @return true if the manga should be included, false otherwise. * @return true if the manga should be included, false otherwise.
*/ */
override fun filter(constraint: String): Boolean { override fun filter(constraint: String): Boolean {
val sourceManager by injectLazy<SourceManager>()
val sourceName = sourceManager.getOrStub(manga.source).name
return manga.title.contains(constraint, true) || return manga.title.contains(constraint, true) ||
(manga.author?.contains(constraint, true) ?: false) || (manga.author?.contains(constraint, true) ?: false) ||
sourceName.contains(constraint, true) ||
if (constraint.contains(",")) { if (constraint.contains(",")) {
val genres = manga.genre?.split(", ") val genres = manga.genre?.split(", ")
constraint.split(",").all { containsGenre(it.trim(), genres) } constraint.split(",").all { containsGenre(it.trim(), genres) }
@ -74,6 +80,7 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference
else containsGenre(constraint, manga.genre?.split(", ")) else containsGenre(constraint, manga.genre?.split(", "))
} }
@SuppressLint("DefaultLocale")
private fun containsGenre(tag: String, genres: List<String>?): Boolean { private fun containsGenre(tag: String, genres: List<String>?): Boolean {
return if (tag.startsWith("-")) return if (tag.startsWith("-"))
genres?.find { genres?.find {

View File

@ -129,11 +129,9 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
private val unread = Item.MultiSort(R.string.action_filter_unread, this) private val unread = Item.MultiSort(R.string.action_filter_unread, this)
private val source = Item.MultiSort(R.string.manga_info_source_label, this)
private val dragAndDrop = Item.MultiSort(R.string.action_sort_drag_and_drop, this) private val dragAndDrop = Item.MultiSort(R.string.action_sort_drag_and_drop, this)
override val items = listOf(alphabetically, lastRead, lastUpdated, unread, total, source, override val items = listOf(alphabetically, lastRead, lastUpdated, unread, total,
dragAndDrop) dragAndDrop)
override val header = Item.Header(R.string.action_sort) override val header = Item.Header(R.string.action_sort)
@ -150,7 +148,6 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
lastUpdated.state = if (sorting == LibrarySort.LAST_UPDATED) order else SORT_NONE lastUpdated.state = if (sorting == LibrarySort.LAST_UPDATED) order else SORT_NONE
unread.state = if (sorting == LibrarySort.UNREAD) order else SORT_NONE unread.state = if (sorting == LibrarySort.UNREAD) order else SORT_NONE
total.state = if (sorting == LibrarySort.TOTAL) order else SORT_NONE total.state = if (sorting == LibrarySort.TOTAL) order else SORT_NONE
source.state = if (sorting == LibrarySort.SOURCE) order else SORT_NONE
dragAndDrop.state = if (sorting == LibrarySort.DRAG_AND_DROP) order else SORT_NONE dragAndDrop.state = if (sorting == LibrarySort.DRAG_AND_DROP) order else SORT_NONE
} }
@ -175,9 +172,8 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
lastUpdated -> LibrarySort.LAST_UPDATED lastUpdated -> LibrarySort.LAST_UPDATED
unread -> LibrarySort.UNREAD unread -> LibrarySort.UNREAD
total -> LibrarySort.TOTAL total -> LibrarySort.TOTAL
source -> LibrarySort.SOURCE
dragAndDrop -> LibrarySort.DRAG_AND_DROP dragAndDrop -> LibrarySort.DRAG_AND_DROP
else -> throw Exception("Unknown sorting") else -> LibrarySort.ALPHA
}) })
preferences.librarySortingAscending().set(item.state == SORT_ASC) preferences.librarySortingAscending().set(item.state == SORT_ASC)

View File

@ -208,16 +208,10 @@ class LibraryPresenter(
val mangaCompare = manga1TotalChapter.compareTo(mange2TotalChapter) val mangaCompare = manga1TotalChapter.compareTo(mange2TotalChapter)
if (mangaCompare == 0) sortAlphabetical(i1, i2) else mangaCompare if (mangaCompare == 0) sortAlphabetical(i1, i2) else mangaCompare
} }
LibrarySort.SOURCE -> {
val source1Name = sourceManager.getOrStub(i1.manga.source).name
val source2Name = sourceManager.getOrStub(i2.manga.source).name
val mangaCompare = source1Name.compareTo(source2Name)
if (mangaCompare == 0) sortAlphabetical(i1, i2) else mangaCompare
}
LibrarySort.DRAG_AND_DROP -> { LibrarySort.DRAG_AND_DROP -> {
0 0
} }
else -> throw Exception("Unknown sorting mode") else -> sortAlphabetical(i1, i2)
} }
} }

View File

@ -7,6 +7,5 @@ object LibrarySort {
const val LAST_UPDATED = 2 const val LAST_UPDATED = 2
const val UNREAD = 3 const val UNREAD = 3
const val TOTAL = 4 const val TOTAL = 4
const val SOURCE = 5
const val DRAG_AND_DROP = 6 const val DRAG_AND_DROP = 6
} }

View File

@ -19,19 +19,8 @@ class PageIndicatorTextView(
attrs: AttributeSet? = null attrs: AttributeSet? = null
) : AppCompatTextView(context, attrs) { ) : AppCompatTextView(context, attrs) {
private val fillColor = Color.rgb(235, 235, 235) init {
private val strokeColor = Color.rgb(45, 45, 45)
override fun onDraw(canvas: Canvas) {
setTextColor(strokeColor)
paint.strokeWidth = 4f
paint.style = Paint.Style.STROKE
super.onDraw(canvas)
setTextColor(fillColor) setTextColor(fillColor)
paint.strokeWidth = 0f
paint.style = Paint.Style.FILL
super.onDraw(canvas)
} }
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
@ -52,4 +41,15 @@ class PageIndicatorTextView(
super.setText(finalText, TextView.BufferType.SPANNABLE) super.setText(finalText, TextView.BufferType.SPANNABLE)
} }
private companion object {
private val fillColor = Color.rgb(235, 235, 235)
private val strokeColor = Color.rgb(45, 45, 45)
// A span object with text outlining properties
val spanOutline = OutlineSpan(
strokeColor = strokeColor,
strokeWidth = 4f
)
}
} }