From b2e53d4938ab969421ebaffacfc347fd04a35a51 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Sat, 9 Dec 2023 13:31:43 +0200 Subject: [PATCH] Fix some warnings and remove unused code --- .../org/koitharu/kotatsu/core/BaseApp.kt | 8 +- .../kotatsu/core/cache/ExpiringLruCache.kt | 2 +- .../core/exceptions/CompositeException.kt | 8 - .../kotatsu/core/prefs/AppSettings.kt | 5 - .../kotatsu/core/ui/drawable/TextDrawable.kt | 100 -------- .../core/ui/list/NestedScrollStateHandle.kt | 64 ----- .../ui/list/SectionedSelectionController.kt | 233 ------------------ .../kotatsu/core/ui/widgets/ChipsView.kt | 2 +- .../kotatsu/core/ui/widgets/TipView.kt | 1 - .../koitharu/kotatsu/core/util/ext/View.kt | 1 + .../kotatsu/core/util/progress/ProgressJob.kt | 16 -- .../kotatsu/details/ui/ChaptersFragment.kt | 1 - .../kotatsu/details/ui/adapter/BranchAD.kt | 39 --- .../details/ui/adapter/ChapterListItemAD.kt | 1 - .../filter/ui/tags/TagsCatalogSheet.kt | 2 - .../kotatsu/history/data/HistoryRepository.kt | 1 - .../history/ui/HistoryListViewModel.kt | 2 +- .../reader/ui/pager/PageHolderDelegate.kt | 5 +- .../pager/standard/PagerPaginationListener.kt | 29 --- .../pager/webtoon/ListPaginationListener.kt | 32 --- .../adapter/TargetScrollObserver.kt | 41 --- .../anilist/data/AniListAuthenticator.kt | 1 - .../selector/ScrobblingSelectorViewModel.kt | 2 +- .../scrobbling/mal/data/MALAuthenticator.kt | 1 - .../shikimori/data/ShikimoriAuthenticator.kt | 1 - .../search/ui/multi/MultiSearchViewModel.kt | 2 +- .../search/ui/widget/SearchBehavior.kt | 53 ---- .../sources/SourcesSettingsViewModel.kt | 4 +- .../settings/utils/EditTextSummaryProvider.kt | 18 -- .../tracker/ui/updates/UpdatesViewModel.kt | 2 +- .../res/layout-w600dp-land/activity_main.xml | 3 +- app/src/main/res/layout/activity_main.xml | 3 +- .../main/res/layout/activity_sync_auth.xml | 1 + .../main/res/layout/dialog_two_buttons.xml | 1 + 34 files changed, 20 insertions(+), 665 deletions(-) delete mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/CompositeException.kt delete mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/core/ui/drawable/TextDrawable.kt delete mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/NestedScrollStateHandle.kt delete mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/core/util/progress/ProgressJob.kt delete mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/BranchAD.kt delete mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/standard/PagerPaginationListener.kt delete mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/ListPaginationListener.kt delete mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/thumbnails/adapter/TargetScrollObserver.kt delete mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/search/ui/widget/SearchBehavior.kt delete mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/settings/utils/EditTextSummaryProvider.kt diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/BaseApp.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/BaseApp.kt index 4f2502449..4082d125a 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/BaseApp.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/BaseApp.kt @@ -40,7 +40,7 @@ open class BaseApp : Application(), Configuration.Provider { lateinit var activityLifecycleCallbacks: Set<@JvmSuppressWildcards ActivityLifecycleCallbacks> @Inject - lateinit var database: MangaDatabase + lateinit var database: Provider @Inject lateinit var settings: AppSettings @@ -52,7 +52,7 @@ open class BaseApp : Application(), Configuration.Provider { lateinit var appValidator: AppValidator @Inject - lateinit var workScheduleManager: WorkScheduleManager + lateinit var workScheduleManager: Provider @Inject lateinit var workManagerProvider: Provider @@ -76,7 +76,7 @@ open class BaseApp : Application(), Configuration.Provider { processLifecycleScope.launch(Dispatchers.Default) { setupDatabaseObservers() } - workScheduleManager.init() + workScheduleManager.get().init() WorkServiceStopHelper(workManagerProvider).setup() } @@ -115,7 +115,7 @@ open class BaseApp : Application(), Configuration.Provider { @WorkerThread private fun setupDatabaseObservers() { - val tracker = database.invalidationTracker + val tracker = database.get().invalidationTracker databaseObservers.forEach { tracker.addObserver(it) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/cache/ExpiringLruCache.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/cache/ExpiringLruCache.kt index 34d46dfca..aa9465c32 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/cache/ExpiringLruCache.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/cache/ExpiringLruCache.kt @@ -12,7 +12,7 @@ class ExpiringLruCache( private val cache = LruCache>(maxSize) operator fun get(key: ContentCache.Key): T? { - val value = cache.get(key) ?: return null + val value = cache[key] ?: return null if (value.isExpired) { cache.remove(key) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/CompositeException.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/CompositeException.kt deleted file mode 100644 index e8c554107..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/CompositeException.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.koitharu.kotatsu.core.exceptions - -import org.koitharu.kotatsu.parsers.util.mapNotNullToSet - -class CompositeException(val errors: Collection) : Exception() { - - override val message: String = errors.mapNotNullToSet { it.message }.joinToString() -} \ No newline at end of file diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt index cb927bd67..01d109aa5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt @@ -1,6 +1,5 @@ package org.koitharu.kotatsu.core.prefs -import android.annotation.SuppressLint import android.content.Context import android.content.SharedPreferences import android.net.ConnectivityManager @@ -14,16 +13,12 @@ import androidx.core.content.edit import androidx.core.os.LocaleListCompat import androidx.preference.PreferenceManager import dagger.hilt.android.qualifiers.ApplicationContext -import kotlinx.coroutines.CoroutineStart -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch import org.json.JSONArray import org.koitharu.kotatsu.core.model.ZoomMode import org.koitharu.kotatsu.core.network.DoHProvider import org.koitharu.kotatsu.core.util.ext.connectivityManager import org.koitharu.kotatsu.core.util.ext.getEnumValue import org.koitharu.kotatsu.core.util.ext.observe -import org.koitharu.kotatsu.core.util.ext.processLifecycleScope import org.koitharu.kotatsu.core.util.ext.putEnumValue import org.koitharu.kotatsu.core.util.ext.takeIfReadable import org.koitharu.kotatsu.core.util.ext.toUriOrNull diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/drawable/TextDrawable.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/drawable/TextDrawable.kt deleted file mode 100644 index 21b5835e7..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/drawable/TextDrawable.kt +++ /dev/null @@ -1,100 +0,0 @@ -package org.koitharu.kotatsu.core.ui.drawable - -import android.annotation.SuppressLint -import android.content.Context -import android.graphics.Canvas -import android.graphics.Color -import android.graphics.ColorFilter -import android.graphics.Paint -import android.graphics.PixelFormat -import android.graphics.Typeface -import android.graphics.drawable.Drawable -import android.os.Build -import android.text.Layout -import android.text.StaticLayout -import android.text.TextPaint -import androidx.annotation.ColorInt -import androidx.annotation.Px -import androidx.annotation.StyleRes -import androidx.core.graphics.withTranslation -import com.google.android.material.resources.TextAppearance -import com.google.android.material.resources.TextAppearanceFontCallback -import org.koitharu.kotatsu.core.util.ext.getThemeColor - -class TextDrawable( - val text: CharSequence, -) : Drawable() { - - private val paint = TextPaint(Paint.ANTI_ALIAS_FLAG) - private var cachedLayout: StaticLayout? = null - - @SuppressLint("RestrictedApi") - constructor(context: Context, text: CharSequence, @StyleRes textAppearanceId: Int) : this(text) { - val ta = TextAppearance(context, textAppearanceId) - paint.color = ta.textColor?.defaultColor ?: context.getThemeColor(android.R.attr.textColorPrimary, Color.BLACK) - paint.typeface = ta.fallbackFont - ta.getFontAsync( - context, paint, - object : TextAppearanceFontCallback() { - override fun onFontRetrieved(typeface: Typeface?, fontResolvedSynchronously: Boolean) = Unit - override fun onFontRetrievalFailed(reason: Int) = Unit - }, - ) - paint.letterSpacing = ta.letterSpacing - } - - var alignment = Layout.Alignment.ALIGN_NORMAL - - var lineSpacingMultiplier = 1f - - @Px - var lineSpacingExtra = 0f - - @get:ColorInt - var textColor: Int - get() = paint.color - set(@ColorInt value) { - paint.color = value - } - - override fun draw(canvas: Canvas) { - val b = bounds - if (b.isEmpty) { - return - } - canvas.withTranslation(x = b.left.toFloat(), y = b.top.toFloat()) { - obtainLayout().draw(canvas) - } - } - - override fun setAlpha(alpha: Int) { - paint.alpha = alpha - } - - override fun setColorFilter(colorFilter: ColorFilter?) { - paint.setColorFilter(colorFilter) - } - - @Suppress("DeprecatedCallableAddReplaceWith") - @Deprecated("Deprecated in Java") - override fun getOpacity(): Int = PixelFormat.TRANSLUCENT - - private fun obtainLayout(): StaticLayout { - val width = bounds.width() - cachedLayout?.let { - if (it.width == width) { - return it - } - } - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - StaticLayout.Builder.obtain(text, 0, text.length, paint, width) - .setAlignment(alignment) - .setLineSpacing(lineSpacingExtra, lineSpacingMultiplier) - .setIncludePad(true) - .build() - } else { - @Suppress("DEPRECATION") - StaticLayout(text, paint, width, alignment, lineSpacingMultiplier, lineSpacingExtra, true) - }.also { cachedLayout = it } - } -} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/NestedScrollStateHandle.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/NestedScrollStateHandle.kt deleted file mode 100644 index b4946ccb0..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/NestedScrollStateHandle.kt +++ /dev/null @@ -1,64 +0,0 @@ -package org.koitharu.kotatsu.core.ui.list - -import android.os.Bundle -import android.os.Parcelable -import android.util.SparseArray -import androidx.core.os.BundleCompat -import androidx.core.view.doOnNextLayout -import androidx.recyclerview.widget.RecyclerView -import java.util.Collections -import java.util.WeakHashMap - -class NestedScrollStateHandle( - savedInstanceState: Bundle?, - private val key: String, -) { - - private val storage: SparseArray = savedInstanceState?.let { - BundleCompat.getSparseParcelableArray(it, key, Parcelable::class.java) - } ?: SparseArray() - private val controllers = Collections.newSetFromMap(WeakHashMap()) - - fun attach(recycler: RecyclerView) = Controller(recycler).also(controllers::add) - - fun onSaveInstanceState(outState: Bundle) { - controllers.forEach { - it.saveState() - } - outState.putSparseParcelableArray(key, storage) - } - - inner class Controller( - private val recycler: RecyclerView - ) { - - private var lastPosition: Int = -1 - - fun onBind(position: Int) { - if (position != lastPosition) { - saveState() - lastPosition = position - storage[position]?.let { - restoreState(it) - } - } - } - - fun onRecycled() { - saveState() - lastPosition = -1 - } - - fun saveState() { - if (lastPosition != -1) { - storage[lastPosition] = recycler.layoutManager?.onSaveInstanceState() - } - } - - private fun restoreState(state: Parcelable) { - recycler.doOnNextLayout { - recycler.layoutManager?.onRestoreInstanceState(state) - } - } - } -} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/SectionedSelectionController.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/SectionedSelectionController.kt index 066b4fa59..4ec8cc011 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/SectionedSelectionController.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/SectionedSelectionController.kt @@ -1,237 +1,4 @@ package org.koitharu.kotatsu.core.ui.list -import android.app.Activity -import android.os.Bundle -import android.view.Menu -import android.view.MenuItem -import androidx.appcompat.app.AppCompatActivity -import androidx.appcompat.view.ActionMode -import androidx.collection.ArrayMap -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.LifecycleEventObserver -import androidx.lifecycle.LifecycleOwner -import androidx.recyclerview.widget.RecyclerView -import androidx.savedstate.SavedStateRegistry -import androidx.savedstate.SavedStateRegistryOwner -import kotlinx.coroutines.Dispatchers -import org.koitharu.kotatsu.core.ui.list.decor.AbstractSelectionItemDecoration -import kotlin.coroutines.EmptyCoroutineContext - private const val PROVIDER_NAME = "selection_decoration_sectioned" -class SectionedSelectionController( - private val activity: Activity, - private val owner: SavedStateRegistryOwner, - private val callback: Callback, -) : ActionMode.Callback, SavedStateRegistry.SavedStateProvider { - - private var actionMode: ActionMode? = null - - private var pendingData: MutableMap>? = null - private val decorations = ArrayMap() - - val count: Int - get() = decorations.values.sumOf { it.checkedItemsCount } - - init { - owner.lifecycle.addObserver(StateEventObserver()) - } - - fun snapshot(): Map> { - return decorations.mapValues { it.value.checkedItemsIds.toSet() } - } - - fun peekCheckedIds(): Map> { - return decorations.mapValues { it.value.checkedItemsIds } - } - - fun clear() { - decorations.values.forEach { - it.clearSelection() - } - notifySelectionChanged() - } - - fun attachToRecyclerView(section: T, recyclerView: RecyclerView) { - val decoration = getDecoration(section) - val pendingIds = pendingData?.remove(section.toString()) - if (!pendingIds.isNullOrEmpty()) { - decoration.checkAll(pendingIds) - startActionMode() - notifySelectionChanged() - } - var shouldAddDecoration = true - for (i in (0 until recyclerView.itemDecorationCount).reversed()) { - val decor = recyclerView.getItemDecorationAt(i) - if (decor === decoration) { - shouldAddDecoration = false - break - } else if (decor.javaClass == decoration.javaClass) { - recyclerView.removeItemDecorationAt(i) - } - } - if (shouldAddDecoration) { - recyclerView.addItemDecoration(decoration) - } - if (pendingData?.isEmpty() == true) { - pendingData = null - } - } - - override fun saveState(): Bundle { - val bundle = Bundle(decorations.size) - for ((k, v) in decorations) { - bundle.putLongArray(k.toString(), v.checkedItemsIds.toLongArray()) - } - return bundle - } - - fun onItemClick(section: T, id: Long): Boolean { - val decoration = getDecoration(section) - if (isInSelectionMode()) { - decoration.toggleItemChecked(id) - if (isInSelectionMode()) { - actionMode?.invalidate() - } else { - actionMode?.finish() - } - notifySelectionChanged() - return true - } - return false - } - - fun onItemLongClick(section: T, id: Long): Boolean { - val decoration = getDecoration(section) - startActionMode() - return actionMode?.also { - decoration.setItemIsChecked(id, true) - notifySelectionChanged() - } != null - } - - fun getSectionCount(section: T): Int { - return decorations[section]?.checkedItemsCount ?: 0 - } - - fun addToSelection(section: T, ids: Collection): Boolean { - val decoration = getDecoration(section) - startActionMode() - return actionMode?.also { - decoration.checkAll(ids) - notifySelectionChanged() - } != null - } - - fun clearSelection(section: T) { - decorations[section]?.clearSelection() ?: return - notifySelectionChanged() - } - - override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { - return callback.onCreateActionMode(this, mode, menu) - } - - override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { - return callback.onPrepareActionMode(this, mode, menu) - } - - override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { - return callback.onActionItemClicked(this, mode, item) - } - - override fun onDestroyActionMode(mode: ActionMode) { - callback.onDestroyActionMode(this, mode) - clear() - actionMode = null - } - - private fun startActionMode() { - if (actionMode == null) { - actionMode = (activity as? AppCompatActivity)?.startSupportActionMode(this) - } - } - - private fun isInSelectionMode(): Boolean { - return decorations.values.any { x -> x.checkedItemsCount > 0 } - } - - private fun notifySelectionChanged() { - val count = this.count - callback.onSelectionChanged(this, count) - if (count == 0) { - actionMode?.finish() - } else { - actionMode?.invalidate() - } - } - - private fun restoreState(ids: MutableMap>) { - if (ids.isEmpty() || isInSelectionMode()) { - return - } - for ((k, v) in decorations) { - val items = ids.remove(k.toString()) - if (!items.isNullOrEmpty()) { - v.checkAll(items) - } - } - pendingData = ids - if (isInSelectionMode()) { - startActionMode() - notifySelectionChanged() - } - } - - private fun getDecoration(section: T): AbstractSelectionItemDecoration { - return decorations.getOrPut(section) { - callback.onCreateItemDecoration(this, section) - } - } - - interface Callback { - - fun onSelectionChanged(controller: SectionedSelectionController, count: Int) - - fun onCreateActionMode(controller: SectionedSelectionController, mode: ActionMode, menu: Menu): Boolean - - fun onPrepareActionMode(controller: SectionedSelectionController, mode: ActionMode, menu: Menu): Boolean { - mode.title = controller.count.toString() - return true - } - - fun onDestroyActionMode(controller: SectionedSelectionController, mode: ActionMode) = Unit - - fun onActionItemClicked( - controller: SectionedSelectionController, - mode: ActionMode, - item: MenuItem, - ): Boolean - - fun onCreateItemDecoration( - controller: SectionedSelectionController, - section: T, - ): AbstractSelectionItemDecoration - } - - private inner class StateEventObserver : LifecycleEventObserver { - - override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) { - if (event == Lifecycle.Event.ON_CREATE) { - val registry = owner.savedStateRegistry - registry.registerSavedStateProvider(PROVIDER_NAME, this@SectionedSelectionController) - val state = registry.consumeRestoredStateForKey(PROVIDER_NAME) - if (state != null) { - Dispatchers.Main.dispatch(EmptyCoroutineContext) { // == Handler.post - if (source.lifecycle.currentState.isAtLeast(Lifecycle.State.CREATED)) { - restoreState( - state.keySet() - .associateWithTo(HashMap()) { state.getLongArray(it)?.toList().orEmpty() }, - ) - } - } - } - } - } - } -} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/widgets/ChipsView.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/widgets/ChipsView.kt index 9c9487057..d1f69cb02 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/widgets/ChipsView.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/widgets/ChipsView.kt @@ -48,7 +48,7 @@ class ChipsView @JvmOverloads constructor( if (isInEditMode) { setChips( List(5) { - ChipModel(0, "Chip $it", 0, false, false) + ChipModel(0, "Chip $it", 0, isCheckable = false, isChecked = false) }, ) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/widgets/TipView.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/widgets/TipView.kt index 96174748a..53e5312de 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/widgets/TipView.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/widgets/TipView.kt @@ -22,7 +22,6 @@ import org.koitharu.kotatsu.core.util.ext.getThemeColorStateList import org.koitharu.kotatsu.core.util.ext.setTextAndVisible import org.koitharu.kotatsu.core.util.ext.textAndVisible import org.koitharu.kotatsu.databinding.ViewTipBinding -import com.google.android.material.R as materialR class TipView @JvmOverloads constructor( context: Context, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/View.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/View.kt index 4ffaca0d9..ff519da76 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/View.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/View.kt @@ -104,6 +104,7 @@ fun RecyclerView.invalidateNestedItemDecorations() { val View.parentView: ViewGroup? get() = parent as? ViewGroup +@Suppress("UnusedReceiverParameter") fun View.measureDimension(desiredSize: Int, measureSpec: Int): Int { var result: Int val specMode = MeasureSpec.getMode(measureSpec) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/progress/ProgressJob.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/progress/ProgressJob.kt deleted file mode 100644 index 826916ddf..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/progress/ProgressJob.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.koitharu.kotatsu.core.util.progress - -import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.StateFlow - -open class ProgressJob

( - private val job: Job, - private val progress: StateFlow

, -) : Job by job { - - val progressValue: P - get() = progress.value - - fun progressAsFlow(): Flow

= progress -} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/ChaptersFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/ChaptersFragment.kt index c8c3f59a4..87fb0f8a5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/ChaptersFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/ChaptersFragment.kt @@ -19,7 +19,6 @@ import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.util.RecyclerViewScrollCallback import org.koitharu.kotatsu.core.util.ext.observe import org.koitharu.kotatsu.core.util.ext.observeEvent -import org.koitharu.kotatsu.core.util.ext.scaleUpActivityOptionsOf import org.koitharu.kotatsu.databinding.FragmentChaptersBinding import org.koitharu.kotatsu.details.ui.adapter.ChaptersAdapter import org.koitharu.kotatsu.details.ui.adapter.ChaptersSelectionDecoration diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/BranchAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/BranchAD.kt deleted file mode 100644 index d471a5c0b..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/BranchAD.kt +++ /dev/null @@ -1,39 +0,0 @@ -package org.koitharu.kotatsu.details.ui.adapter - -import android.graphics.Color -import android.text.Spannable -import android.text.style.ForegroundColorSpan -import android.text.style.RelativeSizeSpan -import androidx.core.text.buildSpannedString -import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding -import org.koitharu.kotatsu.R -import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter -import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener -import org.koitharu.kotatsu.core.util.ext.getThemeColor -import org.koitharu.kotatsu.databinding.ItemCheckableNewBinding -import org.koitharu.kotatsu.details.ui.model.MangaBranch - -fun branchAD( - clickListener: OnListItemClickListener, -) = adapterDelegateViewBinding( - { inflater, parent -> ItemCheckableNewBinding.inflate(inflater, parent, false) }, -) { - - val clickAdapter = AdapterDelegateClickListenerAdapter(this, clickListener) - itemView.setOnClickListener(clickAdapter) - val counterColorSpan = ForegroundColorSpan(context.getThemeColor(android.R.attr.textColorSecondary, Color.LTGRAY)) - val counterSizeSpan = RelativeSizeSpan(0.86f) - - bind { - binding.root.text = buildSpannedString { - append(item.name ?: getString(R.string.system_default)) - append(' ') - append(' ') - val start = length - append(item.count.toString()) - setSpan(counterColorSpan, start, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) - setSpan(counterSizeSpan, start, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) - } - binding.root.isChecked = item.isSelected - } -} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt index fbe80b9d4..2c11ee18f 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt @@ -6,7 +6,6 @@ import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener -import org.koitharu.kotatsu.core.util.ext.drawableEnd import org.koitharu.kotatsu.core.util.ext.drawableStart import org.koitharu.kotatsu.core.util.ext.getThemeColor import org.koitharu.kotatsu.core.util.ext.textAndVisible diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/tags/TagsCatalogSheet.kt b/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/tags/TagsCatalogSheet.kt index c41bf72b3..da03be958 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/tags/TagsCatalogSheet.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/tags/TagsCatalogSheet.kt @@ -9,12 +9,10 @@ import android.view.View import android.view.ViewGroup import android.view.inputmethod.EditorInfo import android.widget.TextView -import androidx.core.view.isVisible import androidx.fragment.app.FragmentManager import androidx.fragment.app.viewModels import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.lifecycle.withCreationCallback -import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.ui.sheet.AdaptiveSheetBehavior import org.koitharu.kotatsu.core.ui.sheet.AdaptiveSheetCallback diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/history/data/HistoryRepository.kt b/app/src/main/kotlin/org/koitharu/kotatsu/history/data/HistoryRepository.kt index d039d5a87..5aae882ae 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/history/data/HistoryRepository.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/history/data/HistoryRepository.kt @@ -8,7 +8,6 @@ import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onStart import org.koitharu.kotatsu.core.db.MangaDatabase -import org.koitharu.kotatsu.core.db.entity.toEntities import org.koitharu.kotatsu.core.db.entity.toEntity import org.koitharu.kotatsu.core.db.entity.toManga import org.koitharu.kotatsu.core.db.entity.toMangaTag diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListViewModel.kt index a263b7038..1cd0aca74 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListViewModel.kt @@ -47,7 +47,7 @@ import javax.inject.Inject @HiltViewModel class HistoryListViewModel @Inject constructor( private val repository: HistoryRepository, - private val settings: AppSettings, + settings: AppSettings, private val extraProvider: ListExtraProvider, private val localMangaRepository: LocalMangaRepository, networkState: NetworkState, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/PageHolderDelegate.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/PageHolderDelegate.kt index 9c544deea..1d7e1d40a 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/PageHolderDelegate.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/PageHolderDelegate.kt @@ -17,6 +17,7 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.plus +import kotlinx.coroutines.withContext import kotlinx.coroutines.yield import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver import org.koitharu.kotatsu.core.os.NetworkState @@ -158,7 +159,9 @@ class PageHolderDelegate( callback.onLoadingStarted() yield() try { - val task = loader.loadPageAsync(data, force) + val task = withContext(Dispatchers.Default) { + loader.loadPageAsync(data, force) + } uri = coroutineScope { val progressObserver = observeProgress(this, task.progressAsFlow()) val file = task.await() diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/standard/PagerPaginationListener.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/standard/PagerPaginationListener.kt deleted file mode 100644 index 1f9c40cbf..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/standard/PagerPaginationListener.kt +++ /dev/null @@ -1,29 +0,0 @@ -package org.koitharu.kotatsu.reader.ui.pager.standard - -import androidx.recyclerview.widget.RecyclerView -import androidx.viewpager2.widget.ViewPager2 -import org.koitharu.kotatsu.reader.ui.pager.OnBoundsScrollListener - -class PagerPaginationListener( - private val adapter: RecyclerView.Adapter<*>, - private val offset: Int, - private val listener: OnBoundsScrollListener -) : ViewPager2.OnPageChangeCallback() { - - private var firstItemId: Long = 0 - private var lastItemId: Long = 0 - - override fun onPageSelected(position: Int) { - val itemCount = adapter.itemCount - if (itemCount == 0) { - return - } - if (position <= offset && adapter.getItemId(0) != firstItemId) { - firstItemId = adapter.getItemId(0) - listener.onScrolledToStart() - } else if (position >= itemCount - offset && adapter.getItemId(itemCount - 1) != lastItemId) { - lastItemId = adapter.getItemId(itemCount - 1) - listener.onScrolledToEnd() - } - } -} \ No newline at end of file diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/ListPaginationListener.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/ListPaginationListener.kt deleted file mode 100644 index a3879a762..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/ListPaginationListener.kt +++ /dev/null @@ -1,32 +0,0 @@ -package org.koitharu.kotatsu.reader.ui.pager.webtoon - -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import org.koitharu.kotatsu.reader.ui.pager.OnBoundsScrollListener - -class ListPaginationListener( - private val offset: Int, - private val listener: OnBoundsScrollListener -) : RecyclerView.OnScrollListener() { - - private var firstItemId: Long = 0 - private var lastItemId: Long = 0 - - override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { - val adapter = recyclerView.adapter ?: return - val layoutManager = (recyclerView.layoutManager as? LinearLayoutManager) ?: return - val firstVisiblePosition = layoutManager.findFirstVisibleItemPosition() - val lastVisiblePosition = layoutManager.findLastVisibleItemPosition() - val itemCount = adapter.itemCount - if (itemCount == 0) { - return - } - if (lastVisiblePosition >= itemCount - offset && adapter.getItemId(itemCount - 1) != lastItemId) { - lastItemId = adapter.getItemId(itemCount - 1) - listener.onScrolledToEnd() - } else if (firstVisiblePosition <= offset && adapter.getItemId(0) != firstItemId) { - firstItemId = adapter.getItemId(0) - listener.onScrolledToStart() - } - } -} \ No newline at end of file diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/thumbnails/adapter/TargetScrollObserver.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/thumbnails/adapter/TargetScrollObserver.kt deleted file mode 100644 index bc27e4a01..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/thumbnails/adapter/TargetScrollObserver.kt +++ /dev/null @@ -1,41 +0,0 @@ -package org.koitharu.kotatsu.reader.ui.thumbnails.adapter - -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter -import org.koitharu.kotatsu.reader.ui.thumbnails.PageThumbnail - -class TargetScrollObserver( - private val recyclerView: RecyclerView, -) : RecyclerView.AdapterDataObserver() { - - private var isScrollToCurrentPending = true - - private val layoutManager: LinearLayoutManager - get() = recyclerView.layoutManager as LinearLayoutManager - - override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { - if (isScrollToCurrentPending) { - postScroll() - } - } - - private fun postScroll() { - recyclerView.post { - scrollToTarget() - } - } - - private fun scrollToTarget() { - val adapter = recyclerView.adapter ?: return - if (recyclerView.computeVerticalScrollRange() == 0) { - return - } - val snapshot = (adapter as? AsyncListDifferDelegationAdapter<*>)?.items ?: return - val target = snapshot.indexOfFirst { it is PageThumbnail && it.isCurrent } - if (target in snapshot.indices) { - layoutManager.scrollToPositionWithOffset(target, 0) - isScrollToCurrentPending = false - } - } -} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/anilist/data/AniListAuthenticator.kt b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/anilist/data/AniListAuthenticator.kt index 4def5e1d6..01c909456 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/anilist/data/AniListAuthenticator.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/anilist/data/AniListAuthenticator.kt @@ -5,7 +5,6 @@ import okhttp3.Authenticator import okhttp3.Request import okhttp3.Response import okhttp3.Route -import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.core.network.CommonHeaders import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.scrobbling.common.data.ScrobblerStorage diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/common/ui/selector/ScrobblingSelectorViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/common/ui/selector/ScrobblingSelectorViewModel.kt index 844e1a815..54c28c99f 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/common/ui/selector/ScrobblingSelectorViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/common/ui/selector/ScrobblingSelectorViewModel.kt @@ -118,7 +118,7 @@ class ScrobblingSelectorViewModel @Inject constructor( if (!append) { scrobblerMangaList.value = list } else if (list.isNotEmpty()) { - scrobblerMangaList.value = scrobblerMangaList.value + list + scrobblerMangaList.value += list } hasNextPage.value = list.isNotEmpty() }.onFailure { error -> diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/mal/data/MALAuthenticator.kt b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/mal/data/MALAuthenticator.kt index 5a343bf9b..a365e4d09 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/mal/data/MALAuthenticator.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/mal/data/MALAuthenticator.kt @@ -5,7 +5,6 @@ import okhttp3.Authenticator import okhttp3.Request import okhttp3.Response import okhttp3.Route -import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.core.network.CommonHeaders import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.scrobbling.common.data.ScrobblerStorage diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/shikimori/data/ShikimoriAuthenticator.kt b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/shikimori/data/ShikimoriAuthenticator.kt index d67dd81d8..a7dc0b77d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/shikimori/data/ShikimoriAuthenticator.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/shikimori/data/ShikimoriAuthenticator.kt @@ -5,7 +5,6 @@ import okhttp3.Authenticator import okhttp3.Request import okhttp3.Response import okhttp3.Route -import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.core.network.CommonHeaders import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.scrobbling.common.data.ScrobblerStorage diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/multi/MultiSearchViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/multi/MultiSearchViewModel.kt index 8ae7a5052..fdf1e1b99 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/multi/MultiSearchViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/multi/MultiSearchViewModel.kt @@ -95,7 +95,7 @@ class MultiSearchViewModel @Inject constructor( } fun retry() { - retryCounter.value = retryCounter.value + 1 + retryCounter.value += 1 } fun download(items: Set) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/widget/SearchBehavior.kt b/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/widget/SearchBehavior.kt deleted file mode 100644 index e13a694de..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/widget/SearchBehavior.kt +++ /dev/null @@ -1,53 +0,0 @@ -package org.koitharu.kotatsu.search.ui.widget - -import android.content.Context -import android.util.AttributeSet -import android.view.View -import android.widget.LinearLayout -import androidx.coordinatorlayout.widget.CoordinatorLayout -import androidx.core.view.ViewCompat -import com.google.android.material.appbar.AppBarLayout -import com.google.android.material.bottomnavigation.BottomNavigationView - -class SearchBehavior(context: Context?, attrs: AttributeSet?) : - CoordinatorLayout.Behavior(context, attrs) { - - override fun layoutDependsOn( - parent: CoordinatorLayout, - child: SearchToolbar, - dependency: View, - ): Boolean { - return when (dependency) { - is AppBarLayout -> true - is LinearLayout, is BottomNavigationView -> { - dependency.z = child.z + 1 - true - } - else -> super.layoutDependsOn(parent, child, dependency) - } - } - - override fun onDependentViewChanged( - parent: CoordinatorLayout, - child: SearchToolbar, - dependency: View, - ): Boolean { - if (dependency is AppBarLayout) { - child.translationY = dependency.getY() - return true - } - return super.onDependentViewChanged(parent, child, dependency) - } - - override fun onStartNestedScroll( - coordinatorLayout: CoordinatorLayout, - child: SearchToolbar, - directTargetChild: View, - target: View, - axes: Int, - type: Int, - ): Boolean { - return axes == ViewCompat.SCROLL_AXIS_VERTICAL - } - -} \ No newline at end of file diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourcesSettingsViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourcesSettingsViewModel.kt index f6cb40bba..2d8f52c3c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourcesSettingsViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourcesSettingsViewModel.kt @@ -12,11 +12,9 @@ import javax.inject.Inject @HiltViewModel class SourcesSettingsViewModel @Inject constructor( - private val sourcesRepository: MangaSourcesRepository, + sourcesRepository: MangaSourcesRepository, ) : BaseViewModel() { - val totalSourcesCount = sourcesRepository.allMangaSources.size - val enabledSourcesCount = sourcesRepository.observeEnabledSourcesCount() .stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, -1) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/utils/EditTextSummaryProvider.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/utils/EditTextSummaryProvider.kt deleted file mode 100644 index 447092234..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/utils/EditTextSummaryProvider.kt +++ /dev/null @@ -1,18 +0,0 @@ -package org.koitharu.kotatsu.settings.utils - -import androidx.annotation.StringRes -import androidx.preference.EditTextPreference -import androidx.preference.Preference - -class EditTextSummaryProvider(@StringRes private val emptySummaryId: Int) : - Preference.SummaryProvider { - - override fun provideSummary(preference: EditTextPreference): CharSequence { - val text = preference.text - return if (text.isNullOrEmpty()) { - preference.context.getString(emptySummaryId) - } else { - text - } - } -} \ No newline at end of file diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/updates/UpdatesViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/updates/UpdatesViewModel.kt index 6c14436df..c6d9faf98 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/updates/UpdatesViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/updates/UpdatesViewModel.kt @@ -25,7 +25,7 @@ import javax.inject.Inject @HiltViewModel class UpdatesViewModel @Inject constructor( private val repository: TrackingRepository, - private val settings: AppSettings, + settings: AppSettings, private val extraProvider: ListExtraProvider, downloadScheduler: DownloadWorker.Scheduler, ) : MangaListViewModel(settings, downloadScheduler) { diff --git a/app/src/main/res/layout-w600dp-land/activity_main.xml b/app/src/main/res/layout-w600dp-land/activity_main.xml index 8cbbe62e9..c83309bb4 100644 --- a/app/src/main/res/layout-w600dp-land/activity_main.xml +++ b/app/src/main/res/layout-w600dp-land/activity_main.xml @@ -15,8 +15,7 @@ app:elevation="1dp" app:headerLayout="@layout/navigation_rail_fab" app:labelVisibilityMode="labeled" - app:layout_constraintStart_toStartOf="parent" - tools:menu="@menu/nav_bottom" /> + app:layout_constraintStart_toStartOf="parent" /> + tools:ignore="KeyboardInaccessibleWidget" /> diff --git a/app/src/main/res/layout/activity_sync_auth.xml b/app/src/main/res/layout/activity_sync_auth.xml index 797586b04..37f86f8c7 100644 --- a/app/src/main/res/layout/activity_sync_auth.xml +++ b/app/src/main/res/layout/activity_sync_auth.xml @@ -27,6 +27,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="?selectableItemBackgroundBorderless" + android:contentDescription="@string/settings" android:padding="4dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" diff --git a/app/src/main/res/layout/dialog_two_buttons.xml b/app/src/main/res/layout/dialog_two_buttons.xml index c6220526a..366e96301 100644 --- a/app/src/main/res/layout/dialog_two_buttons.xml +++ b/app/src/main/res/layout/dialog_two_buttons.xml @@ -13,6 +13,7 @@ android:layout_width="32dp" android:layout_height="32dp" android:layout_gravity="center_horizontal" + android:contentDescription="@null" app:tint="?colorPrimary" tools:src="@drawable/ic_notification" />