From d8e598aaafeb0e5589d5ebfe2a79261122d264fa Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 9 Jan 2020 22:29:08 -0800 Subject: [PATCH] Remove Source sorting, added searching by source --- .../kanade/tachiyomi/source/SourceManager.kt | 4 ++++ .../ui/library/LibraryCategoryAdapter.kt | 5 ---- .../tachiyomi/ui/library/LibraryItem.kt | 7 ++++++ .../ui/library/LibraryNavigationView.kt | 8 ++----- .../tachiyomi/ui/library/LibraryPresenter.kt | 8 +------ .../tachiyomi/ui/library/LibrarySort.kt | 1 - .../ui/reader/PageIndicatorTextView.kt | 24 +++++++++---------- 7 files changed, 26 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt b/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt index cb41050c9a..c63951811c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt @@ -71,6 +71,10 @@ open class SourceManager(private val context: Context) { return SourceNotFoundException(context.getString(R.string.source_not_installed, id .toString()), id) } + + override fun hashCode(): Int { + return id.hashCode() + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt index a0ea327614..25d2d3cf59 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt @@ -92,11 +92,6 @@ class LibraryCategoryAdapter(val view: LibraryCategoryView) : else "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 -> { val title = (iFlexible as LibraryItem).manga.title if (preferences.removeArticles().getOrDefault()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index 2c560231be..d5dff0589a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.ui.library +import android.annotation.SuppressLint import android.view.Gravity import android.view.View 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.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.widget.AutofitRecyclerView import kotlinx.android.synthetic.main.catalogue_grid_item.view.* +import uy.kohesive.injekt.injectLazy class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference) : AbstractFlexibleItem(), IFilterable { @@ -65,8 +68,11 @@ class LibraryItem(val manga: LibraryManga, private val libraryAsList: Preference * @return true if the manga should be included, false otherwise. */ override fun filter(constraint: String): Boolean { + val sourceManager by injectLazy() + val sourceName = sourceManager.getOrStub(manga.source).name return manga.title.contains(constraint, true) || (manga.author?.contains(constraint, true) ?: false) || + sourceName.contains(constraint, true) || if (constraint.contains(",")) { val genres = manga.genre?.split(", ") 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(", ")) } + @SuppressLint("DefaultLocale") private fun containsGenre(tag: String, genres: List?): Boolean { return if (tag.startsWith("-")) genres?.find { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt index ac2d10d179..9df4b79f1c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt @@ -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 source = Item.MultiSort(R.string.manga_info_source_label, 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) 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 unread.state = if (sorting == LibrarySort.UNREAD) 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 } @@ -175,9 +172,8 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A lastUpdated -> LibrarySort.LAST_UPDATED unread -> LibrarySort.UNREAD total -> LibrarySort.TOTAL - source -> LibrarySort.SOURCE dragAndDrop -> LibrarySort.DRAG_AND_DROP - else -> throw Exception("Unknown sorting") + else -> LibrarySort.ALPHA }) preferences.librarySortingAscending().set(item.state == SORT_ASC) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 388874e75d..68862af5de 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -208,16 +208,10 @@ class LibraryPresenter( val mangaCompare = manga1TotalChapter.compareTo(mange2TotalChapter) 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 -> { 0 } - else -> throw Exception("Unknown sorting mode") + else -> sortAlphabetical(i1, i2) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt index 170a61388c..4514afdb0c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt @@ -7,6 +7,5 @@ object LibrarySort { const val LAST_UPDATED = 2 const val UNREAD = 3 const val TOTAL = 4 - const val SOURCE = 5 const val DRAG_AND_DROP = 6 } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt index a6201364ef..d7383723bb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt @@ -19,19 +19,8 @@ class PageIndicatorTextView( attrs: AttributeSet? = null ) : AppCompatTextView(context, attrs) { - private val fillColor = Color.rgb(235, 235, 235) - 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) - + init { setTextColor(fillColor) - paint.strokeWidth = 0f - paint.style = Paint.Style.FILL - super.onDraw(canvas) } @SuppressLint("SetTextI18n") @@ -52,4 +41,15 @@ class PageIndicatorTextView( 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 + ) + } }