From b668cc9abc5ebe439acb339e589147ff6acbd62b Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 6 Jan 2020 02:28:15 -0800 Subject: [PATCH] Fixes to the fast scroller for this fork + remove keyword searching --- .../data/preference/PreferencesHelper.kt | 2 - .../smartsearch/SmartSearchEngine.kt | 50 +------------- .../ui/library/LibraryCategoryAdapter.kt | 66 ++++++++++++++++++- .../ui/library/LibraryCategoryView.kt | 8 ++- .../design/MigrationBottomSheetDialog.kt | 4 +- .../manga/process/MigrationListController.kt | 15 ++--- .../res/layout/migration_bottom_sheet.xml | 19 ++---- 7 files changed, 82 insertions(+), 82 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 5fe9335b78..414e9738ce 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -193,8 +193,6 @@ class PreferencesHelper(val context: Context) { fun migrationSources() = rxPrefs.getString("migrate_sources", "") - fun smartMigration() = rxPrefs.getBoolean("smart_migrate", false) - fun useSourceWithMost() = rxPrefs.getBoolean("use_source_with_most", false) fun skipPreMigration() = rxPrefs.getBoolean(Keys.skipPreMigration, false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/smartsearch/SmartSearchEngine.kt b/app/src/main/java/eu/kanade/tachiyomi/smartsearch/SmartSearchEngine.kt index 64c0fbe068..4bfa4b5516 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/smartsearch/SmartSearchEngine.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/smartsearch/SmartSearchEngine.kt @@ -25,7 +25,7 @@ class SmartSearchEngine(parentContext: CoroutineContext, private val normalizedLevenshtein = NormalizedLevenshtein() - suspend fun smartSearch(source: CatalogueSource, title: String): SManga? { + /*suspend fun smartSearch(source: CatalogueSource, title: String): SManga? { val cleanedTitle = cleanSmartSearchTitle(title) val queries = getSmartSearchQueries(cleanedTitle) @@ -52,7 +52,7 @@ class SmartSearchEngine(parentContext: CoroutineContext, } return eligibleManga.maxBy { it.dist }?.manga - } + }*/ suspend fun normalSearch(source: CatalogueSource, title: String): SManga? { val eligibleManga = supervisorScope { @@ -74,52 +74,6 @@ class SmartSearchEngine(parentContext: CoroutineContext, return eligibleManga.maxBy { it.dist }?.manga } - - private fun getSmartSearchQueries(cleanedTitle: String): List { - val splitCleanedTitle = cleanedTitle.split(" ") - val splitSortedByLargest = splitCleanedTitle.sortedByDescending { it.length } - - if(splitCleanedTitle.isEmpty()) { - return emptyList() - } - - // Search cleaned title - // Search two largest words - // Search largest word - // Search first two words - // Search first word - - val searchQueries = listOf( - listOf(cleanedTitle), - splitSortedByLargest.take(2), - splitSortedByLargest.take(1), - splitCleanedTitle.take(2), - splitCleanedTitle.take(1) - ) - - return searchQueries.map { - it.joinToString(" ").trim() - }.distinct() - } - - private fun cleanSmartSearchTitle(title: String): String { - val preTitle = title.toLowerCase() - - // Remove text in brackets - var cleanedTitle = removeTextInBrackets(preTitle, true) - if(cleanedTitle.length <= 5) { // Title is suspiciously short, try parsing it backwards - cleanedTitle = removeTextInBrackets(preTitle, false) - } - - // Strip non-special characters - cleanedTitle = cleanedTitle.replace(titleRegex, " ") - - // Strip splitters and consecutive spaces - cleanedTitle = cleanedTitle.trim().replace(" - ", " ").replace(consecutiveSpacesRegex, " ").trim() - - return cleanedTitle - } - private fun removeTextInBrackets(text: String, readForward: Boolean): String { val bracketPairs = listOf( '(' to ')', 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 11396534d5..a0ea327614 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 @@ -1,9 +1,25 @@ package eu.kanade.tachiyomi.ui.library +import android.graphics.Color +import android.text.format.DateUtils +import androidx.core.content.ContextCompat import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.ui.category.CategoryAdapter +import eu.kanade.tachiyomi.util.getResourceColor +import eu.kanade.tachiyomi.util.removeArticles +import uy.kohesive.injekt.injectLazy +import java.text.DateFormat +import java.text.SimpleDateFormat +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.Year import java.util.* @@ -12,7 +28,7 @@ import java.util.* * * @param view the fragment containing this adapter. */ -class LibraryCategoryAdapter(view: LibraryCategoryView) : +class LibraryCategoryAdapter(val view: LibraryCategoryView) : FlexibleAdapter(null, view, true) { /** @@ -51,15 +67,59 @@ class LibraryCategoryAdapter(view: LibraryCategoryView) : updateDataSet(mangas.filter { it.filter(s) }) } - override fun onCreateBubbleText(position: Int): String { + override fun onCreateBubbleText(position: Int):String { return if (position < scrollableHeaders.size) { "Top" } else if (position >= itemCount - scrollableFooters.size) { "Bottom" } else { // Get and show the first character val iFlexible: IFlexible<*>? = getItem(position) - (iFlexible as LibraryItem).manga.title.substring(0, 1).toUpperCase(Locale.US) + val preferences:PreferencesHelper by injectLazy() + when (preferences.librarySortingMode().getOrDefault()) { + LibrarySort.LAST_READ -> { + val db:DatabaseHelper by injectLazy() + val id = (iFlexible as LibraryItem).manga.id ?: return "" + val history = db.getHistoryByMangaId(id).executeAsBlocking() + if (history.firstOrNull() != null) + getShortDate(Date(history.first().last_read)) + else + "Never Read" + } + LibrarySort.LAST_UPDATED -> { + val lastUpdate = (iFlexible as LibraryItem).manga.last_update + if (lastUpdate > 0) + getShortDate(Date(lastUpdate)) + 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()) + title.removeArticles().substring(0, 1).toUpperCase(Locale.US) + else title.substring(0, 1).toUpperCase(Locale.US) + } + } } } + private fun getShortDate(date:Date):String { + val cal = Calendar.getInstance() + cal.time = Date() + + val yearNow = cal.get(Calendar.YEAR) + val cal2 = Calendar.getInstance() + cal2.time = date + val yearThen = cal2.get(Calendar.YEAR) + + return if (yearNow == yearThen) + SimpleDateFormat("MMM").format(date) + else + SimpleDateFormat("yyyy").format(date) + } + } 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 5abf404a77..00957bc1ce 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 @@ -6,6 +6,7 @@ import androidx.recyclerview.widget.RecyclerView import android.util.AttributeSet import android.view.MotionEvent import android.view.View +import android.view.ViewGroup import android.widget.FrameLayout import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.SelectableAdapter @@ -19,6 +20,7 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.category.CategoryAdapter import eu.kanade.tachiyomi.util.* import eu.kanade.tachiyomi.widget.AutofitRecyclerView +import kotlinx.android.synthetic.main.chapters_controller.* import kotlinx.android.synthetic.main.library_category.view.* import rx.subscriptions.CompositeSubscription import uy.kohesive.injekt.injectLazy @@ -91,13 +93,17 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recycler: RecyclerView, newState: Int) { // Disable swipe refresh when view is not at the top - val firstPos = (recycler.layoutManager as androidx.recyclerview.widget.LinearLayoutManager) + val firstPos = (recycler.layoutManager as LinearLayoutManager) .findFirstCompletelyVisibleItemPosition() swipe_refresh.isEnabled = firstPos <= 0 } }) recycler.doOnApplyWindowInsets { v, insets, padding -> v.updatePaddingRelative(bottom = padding.bottom + insets.systemWindowInsetBottom) + + fast_scroller?.updateLayoutParams { + bottomMargin = insets.systemWindowInsetBottom + } } // Double the distance required to trigger sync diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationBottomSheetDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationBottomSheetDialog.kt index 0c76f2cbc7..1fa5c198e0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationBottomSheetDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationBottomSheetDialog.kt @@ -24,7 +24,6 @@ import kotlinx.android.synthetic.main.migration_bottom_sheet.extra_search_param_ import kotlinx.android.synthetic.main.migration_bottom_sheet.mig_categories import kotlinx.android.synthetic.main.migration_bottom_sheet.mig_chapters import kotlinx.android.synthetic.main.migration_bottom_sheet.mig_tracking -import kotlinx.android.synthetic.main.migration_bottom_sheet.use_smart_search import uy.kohesive.injekt.injectLazy class MigrationBottomSheetDialog(activity: Activity, theme: Int, private val listener: @@ -59,7 +58,7 @@ StartMigrationListener) : fab.setOnClickListener { preferences.skipPreMigration().set(skip_step.isChecked) listener.startMigration( - if (use_smart_search.isChecked && extra_search_param_text.text.isNotBlank()) + if (extra_search_param.isChecked && extra_search_param_text.text.isNotBlank()) extra_search_param_text.text.toString() else null) dismiss() } @@ -79,7 +78,6 @@ StartMigrationListener) : mig_categories.setOnCheckedChangeListener { _, _ -> setFlags() } mig_tracking.setOnCheckedChangeListener { _, _ -> setFlags() } - use_smart_search.bindToPreference(preferences.smartMigration()) extra_search_param_text.gone() extra_search_param.setOnCheckedChangeListener { _, isChecked -> if (isChecked) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt index fba58b47ce..dac0202f5f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt @@ -122,7 +122,6 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), suspend fun runMigrations(mangas: List) { val useSourceWithMost = preferences.useSourceWithMost().getOrDefault() - val useSmartSearch = preferences.smartMigration().getOrDefault() val sources = preferences.migrationSources().getOrDefault().split("/").mapNotNull { val value = it.toLongOrNull() ?: return @@ -152,11 +151,10 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), async { sourceSemaphore.withPermit { try { - val searchResult = if (useSmartSearch) { + /* val searchResult = if (useSmartSearch) { smartSearchEngine.smartSearch(source, mangaObj.title) - } else { - smartSearchEngine.normalSearch(source, mangaObj.title) - } + } else {*/ + val searchResult = smartSearchEngine.normalSearch(source, mangaObj.title) if(searchResult != null) { val localManga = smartSearchEngine.networkToLocalManga(searchResult, source.id) @@ -185,11 +183,8 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), } else { validSources.forEachIndexed { index, source -> val searchResult = try { - val searchResult = if (useSmartSearch) { - smartSearchEngine.smartSearch(source, mangaObj.title) - } else { - smartSearchEngine.normalSearch(source, mangaObj.title) - } + val searchResult = smartSearchEngine.normalSearch(source, + mangaObj.title) if (searchResult != null) { val localManga = smartSearchEngine.networkToLocalManga(searchResult, source.id) diff --git a/app/src/main/res/layout/migration_bottom_sheet.xml b/app/src/main/res/layout/migration_bottom_sheet.xml index 7d8d59f983..75058bec0b 100644 --- a/app/src/main/res/layout/migration_bottom_sheet.xml +++ b/app/src/main/res/layout/migration_bottom_sheet.xml @@ -101,26 +101,15 @@ android:text="@string/use_most_chapters" /> - - + app:layout_constraintEnd_toEndOf="@+id/sourceGroup" + app:layout_constraintStart_toStartOf="@+id/sourceGroup" + app:layout_constraintTop_toBottomOf="@+id/sourceGroup" />