diff --git a/app/build.gradle b/app/build.gradle index 945ecb7c5..3994cb7b9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -146,7 +146,7 @@ dependencies { implementation 'org.conscrypt:conscrypt-android:2.5.2' debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.14' - debugImplementation 'com.github.Koitharu:WorkInspector:2c2919f9f1' + debugImplementation 'com.github.Koitharu:WorkInspector:5778dd1747' testImplementation 'junit:junit:4.13.2' testImplementation 'org.json:json:20240303' diff --git a/app/src/debug/kotlin/org/koitharu/kotatsu/KotatsuApp.kt b/app/src/debug/kotlin/org/koitharu/kotatsu/KotatsuApp.kt index 4dd63e838..1694ddc89 100644 --- a/app/src/debug/kotlin/org/koitharu/kotatsu/KotatsuApp.kt +++ b/app/src/debug/kotlin/org/koitharu/kotatsu/KotatsuApp.kt @@ -8,14 +8,12 @@ import org.koitharu.kotatsu.local.data.LocalMangaRepository import org.koitharu.kotatsu.local.data.PagesCache import org.koitharu.kotatsu.parsers.MangaLoaderContext import org.koitharu.kotatsu.reader.domain.PageLoader -import org.koitharu.workinspector.WorkInspector class KotatsuApp : BaseApp() { override fun attachBaseContext(base: Context) { super.attachBaseContext(base) enableStrictMode() - WorkInspector.setLauncherIconEnabled(base, false) } private fun enableStrictMode() { diff --git a/app/src/debug/res/values/bools.xml b/app/src/debug/res/values/bools.xml index 36b9b0867..e5b0cc536 100644 --- a/app/src/debug/res/values/bools.xml +++ b/app/src/debug/res/values/bools.xml @@ -1,4 +1,5 @@ false + false diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt index 4b731dc56..1951887c4 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt @@ -124,7 +124,6 @@ class DetailsActivity : private val viewModel: DetailsViewModel by viewModels() - private lateinit var chaptersBadge: ViewBadge private lateinit var menuProvider: DetailsMenuProvider override fun onCreate(savedInstanceState: Bundle?) { @@ -158,11 +157,9 @@ class DetailsActivity : viewBinding.containerBottomSheet?.let { BottomSheetBehavior.from(it) }?.let { behavior -> onBackPressedDispatcher.addCallback(BottomSheetClollapseCallback(behavior)) } - chaptersBadge = ViewBadge(viewBinding.buttonRead, this) viewModel.details.filterNotNull().observe(this, ::onMangaUpdated) viewModel.onMangaRemoved.observeEvent(this, ::onMangaRemoved) - viewModel.newChaptersCount.observe(this, ::onNewChaptersChanged) viewModel.onError .filterNot { ChaptersPagesSheet.isShown(supportFragmentManager) } .observeEvent(this, DetailsErrorObserver(this, viewModel, exceptionResolver)) @@ -379,15 +376,6 @@ class DetailsActivity : chip.textAndVisible = time?.formatShort(chip.resources) } - private fun onDescriptionChanged(description: CharSequence?) { - val tv = viewBinding.textViewDescription - if (description.isNullOrBlank()) { - tv.setText(R.string.no_description) - } else { - tv.text = description - } - } - private fun onLocalSizeChanged(size: Long) { val chip = viewBinding.infoLayout.chipSize if (size == 0L) { @@ -550,10 +538,6 @@ class DetailsActivity : buttonRead.isEnabled = info.isValid } - private fun onNewChaptersChanged(count: Int) { - chaptersBadge.counter = count - } - private fun showBranchPopupMenu(v: View) { val menu = PopupMenu(v.context, v) val branches = viewModel.branches.value diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsMenuProvider.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsMenuProvider.kt index 3f31ae0eb..87ef10aa0 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsMenuProvider.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsMenuProvider.kt @@ -19,7 +19,6 @@ import org.koitharu.kotatsu.browser.BrowserActivity import org.koitharu.kotatsu.core.os.AppShortcutManager import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.util.ShareHelper -import org.koitharu.kotatsu.details.ui.pager.ChaptersPagesSheet import org.koitharu.kotatsu.download.ui.dialog.DownloadOption import org.koitharu.kotatsu.parsers.model.MangaSource import org.koitharu.kotatsu.scrobbling.common.ui.selector.ScrobblingSelectorSheet @@ -135,7 +134,6 @@ class DetailsMenuProvider( is DownloadOption.WholeManga -> null is DownloadOption.SelectionHint -> { viewModel.startChaptersSelection() - ChaptersPagesSheet.show(activity.supportFragmentManager, ChaptersPagesSheet.TAB_CHAPTERS) return } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt index b1d0031ac..64d62bb12 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt @@ -88,7 +88,6 @@ class DetailsViewModel @Inject constructor( val mangaId = intent.mangaId val onActionDone = MutableEventFlow() - val onShowTip = MutableEventFlow() val onSelectChapter = MutableEventFlow() val onDownloadStarted = MutableEventFlow() @@ -161,11 +160,6 @@ class DetailsViewModel @Inject constructor( } }.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.WhileSubscribed(5000), 0L) - @Deprecated("") - val description = details - .map { it?.description } - .stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Lazily, null) - val onMangaRemoved = MutableEventFlow() val isScrobblingAvailable: Boolean get() = scrobblers.any { it.isAvailable } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/ChaptersPagesSheet.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/ChaptersPagesSheet.kt index c280dcb37..4c50f73d5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/ChaptersPagesSheet.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/ChaptersPagesSheet.kt @@ -13,7 +13,6 @@ import com.google.android.material.tabs.TabLayoutMediator import dagger.hilt.android.AndroidEntryPoint import org.koitharu.kotatsu.core.exceptions.resolve.SnackbarErrorObserver import org.koitharu.kotatsu.core.prefs.AppSettings -import org.koitharu.kotatsu.core.ui.sheet.AdaptiveSheetBehavior import org.koitharu.kotatsu.core.ui.sheet.AdaptiveSheetBehavior.Companion.STATE_COLLAPSED import org.koitharu.kotatsu.core.ui.sheet.AdaptiveSheetBehavior.Companion.STATE_DRAGGING import org.koitharu.kotatsu.core.ui.sheet.AdaptiveSheetBehavior.Companion.STATE_EXPANDED @@ -21,6 +20,7 @@ import org.koitharu.kotatsu.core.ui.sheet.AdaptiveSheetBehavior.Companion.STATE_ import org.koitharu.kotatsu.core.ui.sheet.AdaptiveSheetCallback import org.koitharu.kotatsu.core.ui.sheet.BaseAdaptiveSheet import org.koitharu.kotatsu.core.ui.util.ActionModeListener +import org.koitharu.kotatsu.core.ui.util.MenuInvalidator import org.koitharu.kotatsu.core.ui.util.ReversibleActionObserver import org.koitharu.kotatsu.core.util.ext.doOnPageChanged import org.koitharu.kotatsu.core.util.ext.menuView @@ -64,6 +64,10 @@ class ChaptersPagesSheet : BaseAdaptiveSheet(), Actio onBackPressedDispatcher.addCallback(viewLifecycleOwner, menuProvider) binding.toolbar.addMenuProvider(menuProvider) + val menuInvalidator = MenuInvalidator(binding.toolbar) + viewModel.isChaptersReversed.observe(viewLifecycleOwner, menuInvalidator) + viewModel.isChaptersInGridView.observe(viewLifecycleOwner, menuInvalidator) + actionModeDelegate?.addListener(this, viewLifecycleOwner) addSheetCallback(this, viewLifecycleOwner) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/chapters/ChaptersFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/chapters/ChaptersFragment.kt index e88c5329b..f355f3793 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/chapters/ChaptersFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/pager/chapters/ChaptersFragment.kt @@ -17,6 +17,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map +import kotlinx.coroutines.withContext import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.ui.BaseFragment import org.koitharu.kotatsu.core.ui.list.ListSelectionController @@ -25,6 +26,7 @@ import org.koitharu.kotatsu.core.util.RecyclerViewScrollCallback import org.koitharu.kotatsu.core.util.ext.dismissParentDialog import org.koitharu.kotatsu.core.util.ext.findAppCompatDelegate import org.koitharu.kotatsu.core.util.ext.findParentCallback +import org.koitharu.kotatsu.core.util.ext.firstVisibleItemPosition import org.koitharu.kotatsu.core.util.ext.observe import org.koitharu.kotatsu.core.util.ext.observeEvent import org.koitharu.kotatsu.databinding.FragmentChaptersBinding @@ -91,12 +93,7 @@ class ChaptersFragment : viewModel.isChaptersEmpty.observe(viewLifecycleOwner) { binding.textViewHolder.isVisible = it } - viewModel.onSelectChapter.observeEvent(viewLifecycleOwner) { chapterId -> - chaptersAdapter?.observeItems()?.firstOrNull { items -> - items.any { x -> x is ChapterListItem && x.chapter.id == chapterId } - } - selectionController?.onItemLongClick(chapterId) - } + viewModel.onSelectChapter.observeEvent(viewLifecycleOwner, ::onSelectChapter) } override fun onDestroyView() { @@ -273,6 +270,22 @@ class ChaptersFragment : } } + private suspend fun onSelectChapter(chapterId: Long) { + val position = withContext(Dispatchers.Default) { + val predicate: (ListModel) -> Boolean = { x -> x is ChapterListItem && x.chapter.id == chapterId } + val items = chaptersAdapter?.observeItems()?.firstOrNull { it.any(predicate) } + items?.indexOfFirst(predicate) ?: -1 + } + if (position >= 0) { + selectionController?.onItemLongClick(chapterId) + val lm = (viewBinding?.recyclerViewChapters?.layoutManager as? LinearLayoutManager) + if (lm != null) { + val offset = resources.getDimensionPixelOffset(R.dimen.chapter_list_item_height) + lm.scrollToPositionWithOffset(position, offset) + } + } + } + private fun onLoadingStateChanged(isLoading: Boolean) { requireViewBinding().progressBar.isVisible = isLoading } diff --git a/app/src/main/res/layout/activity_details.xml b/app/src/main/res/layout/activity_details.xml index 04bf6c818..81730d4ab 100644 --- a/app/src/main/res/layout/activity_details.xml +++ b/app/src/main/res/layout/activity_details.xml @@ -405,7 +405,7 @@ android:nestedScrollingEnabled="false" android:outlineProvider="background" app:behavior_fitToContents="false" - app:behavior_halfExpandedRatio="0.8" + app:behavior_halfExpandedRatio="0.00001" app:behavior_hideable="false" app:behavior_peekHeight="@dimen/details_bs_peek_height" app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"