Compare commits
65 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
c7a1312cd6
|
|||
|
b2927854d4
|
|||
|
cfda150630
|
|||
|
4fa1382ce9
|
|||
|
43075c52d1
|
|||
|
87942747fc
|
|||
|
bb6cd73acd
|
|||
|
|
6790e5b0d4 | ||
|
|
845c356a73 | ||
|
|
34499ea77d | ||
|
|
6210864280 | ||
|
|
19084419c7 | ||
|
|
84ce4c508c | ||
|
|
0db8fafe61 | ||
|
fed241215e
|
|||
|
761f24daf9
|
|||
|
a435435496
|
|||
|
81e8c25563
|
|||
| e3504c3b1e | |||
|
|
2601c12348 | ||
|
138cf44e37
|
|||
|
65d83e0921
|
|||
|
6e1cd05fa8
|
|||
|
8398c01929
|
|||
|
835c49ae79
|
|||
|
36065ccf6c
|
|||
|
4ab40566f7
|
|||
|
|
bf01a4d1ab | ||
|
8dce9dcc3f
|
|||
|
d872044252
|
|||
|
f4313525c2
|
|||
|
4eb4ec7de0
|
|||
|
ecb4dd87d9
|
|||
|
|
3d0f5f75cd | ||
|
|
c5462e8454 | ||
|
|
5039e324fb | ||
|
|
b251b3e654 | ||
|
|
5f10070564 | ||
|
|
3da6f80eb6 | ||
|
|
4b2cfdb972 | ||
|
|
51387ace7e | ||
|
2bdb83ff28
|
|||
|
a1b85433ec
|
|||
|
|
ca5207c658 | ||
|
81de6124f0
|
|||
|
a93bc0ed5b
|
|||
|
a1b96ebbb5
|
|||
|
6b93e49f56
|
|||
|
c88a9dff36
|
|||
|
ca47c475d3
|
|||
|
8df7fa2729
|
|||
|
ea34abb1d7
|
|||
|
c4ff37350c
|
|||
|
95547a8d03
|
|||
|
4c2197aa5d
|
|||
|
a679b6775d
|
|||
|
d3e4e97c6f
|
|||
|
d1b0af85c4
|
|||
| ce95e0657b | |||
|
|
6bb159a6d9 | ||
|
|
a75583f750 | ||
|
fff9df9609
|
|||
|
f9609edea5
|
|||
|
f1245742c0
|
|||
|
|
ded7cdb71e |
@@ -16,8 +16,8 @@ android {
|
|||||||
applicationId 'org.koitharu.kotatsu'
|
applicationId 'org.koitharu.kotatsu'
|
||||||
minSdk = 21
|
minSdk = 21
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 575
|
versionCode = 583
|
||||||
versionName = '6.0.2'
|
versionName = '6.1.5'
|
||||||
generatedDensities = []
|
generatedDensities = []
|
||||||
testInstrumentationRunner "org.koitharu.kotatsu.HiltTestRunner"
|
testInstrumentationRunner "org.koitharu.kotatsu.HiltTestRunner"
|
||||||
ksp {
|
ksp {
|
||||||
@@ -81,7 +81,7 @@ afterEvaluate {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
//noinspection GradleDependency
|
//noinspection GradleDependency
|
||||||
implementation('com.github.KotatsuApp:kotatsu-parsers:3a76504380') {
|
implementation('com.github.KotatsuApp:kotatsu-parsers:931f126119') {
|
||||||
exclude group: 'org.json', module: 'json'
|
exclude group: 'org.json', module: 'json'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,13 +89,13 @@ dependencies {
|
|||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
|
||||||
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'androidx.core:core-ktx:1.10.1'
|
implementation 'androidx.core:core-ktx:1.12.0'
|
||||||
implementation 'androidx.activity:activity-ktx:1.7.2'
|
implementation 'androidx.activity:activity-ktx:1.8.0-rc01'
|
||||||
implementation 'androidx.fragment:fragment-ktx:1.6.1'
|
implementation 'androidx.fragment:fragment-ktx:1.6.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
|
||||||
implementation 'androidx.lifecycle:lifecycle-service:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-service:2.6.2'
|
||||||
implementation 'androidx.lifecycle:lifecycle-process:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-process:2.6.2'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||||
implementation 'androidx.recyclerview:recyclerview:1.3.1'
|
implementation 'androidx.recyclerview:recyclerview:1.3.1'
|
||||||
@@ -103,7 +103,7 @@ dependencies {
|
|||||||
implementation 'androidx.preference:preference-ktx:1.2.1'
|
implementation 'androidx.preference:preference-ktx:1.2.1'
|
||||||
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
|
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
|
||||||
implementation 'com.google.android.material:material:1.9.0'
|
implementation 'com.google.android.material:material:1.9.0'
|
||||||
implementation 'androidx.lifecycle:lifecycle-common-java8:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-common-java8:2.6.2'
|
||||||
|
|
||||||
// TODO https://issuetracker.google.com/issues/254846063
|
// TODO https://issuetracker.google.com/issues/254846063
|
||||||
implementation 'androidx.work:work-runtime-ktx:2.8.1'
|
implementation 'androidx.work:work-runtime-ktx:2.8.1'
|
||||||
@@ -120,24 +120,24 @@ dependencies {
|
|||||||
|
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
|
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
|
||||||
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.11.0'
|
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.11.0'
|
||||||
implementation 'com.squareup.okio:okio:3.5.0'
|
implementation 'com.squareup.okio:okio:3.6.0'
|
||||||
|
|
||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
||||||
|
|
||||||
implementation 'com.google.dagger:hilt-android:2.47'
|
implementation 'com.google.dagger:hilt-android:2.48'
|
||||||
kapt 'com.google.dagger:hilt-compiler:2.47'
|
kapt 'com.google.dagger:hilt-compiler:2.48'
|
||||||
implementation 'androidx.hilt:hilt-work:1.0.0'
|
implementation 'androidx.hilt:hilt-work:1.0.0'
|
||||||
kapt 'androidx.hilt:hilt-compiler:1.0.0'
|
kapt 'androidx.hilt:hilt-compiler:1.0.0'
|
||||||
|
|
||||||
implementation 'io.coil-kt:coil-base:2.4.0'
|
implementation 'io.coil-kt:coil-base:2.4.0'
|
||||||
implementation 'io.coil-kt:coil-svg:2.4.0'
|
implementation 'io.coil-kt:coil-svg:2.4.0'
|
||||||
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:9b1d20be67'
|
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:169806d928'
|
||||||
implementation 'com.github.solkin:disk-lru-cache:1.4'
|
implementation 'com.github.solkin:disk-lru-cache:1.4'
|
||||||
implementation 'io.noties.markwon:core:4.6.2'
|
implementation 'io.noties.markwon:core:4.6.2'
|
||||||
|
|
||||||
implementation 'ch.acra:acra-http:5.11.1'
|
implementation 'ch.acra:acra-http:5.11.2'
|
||||||
implementation 'ch.acra:acra-dialog:5.11.1'
|
implementation 'ch.acra:acra-dialog:5.11.2'
|
||||||
|
|
||||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'
|
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'
|
||||||
|
|
||||||
@@ -155,6 +155,6 @@ dependencies {
|
|||||||
androidTestImplementation 'androidx.room:room-testing:2.5.2'
|
androidTestImplementation 'androidx.room:room-testing:2.5.2'
|
||||||
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.15.0'
|
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.15.0'
|
||||||
|
|
||||||
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.47'
|
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.48'
|
||||||
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.47'
|
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.48'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||||
|
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
android:maxSdkVersion="29" />
|
android:maxSdkVersion="29" />
|
||||||
@@ -95,7 +96,12 @@
|
|||||||
android:label="@string/search" />
|
android:label="@string/search" />
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.search.ui.MangaListActivity"
|
android:name="org.koitharu.kotatsu.search.ui.MangaListActivity"
|
||||||
android:label="@string/search_manga" />
|
android:exported="true"
|
||||||
|
android:label="@string/manga_list">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="${applicationId}.action.EXPLORE_MANGA" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.history.ui.HistoryActivity"
|
android:name="org.koitharu.kotatsu.history.ui.HistoryActivity"
|
||||||
android:label="@string/history" />
|
android:label="@string/history" />
|
||||||
@@ -138,6 +144,7 @@
|
|||||||
android:windowSoftInputMode="adjustResize" />
|
android:windowSoftInputMode="adjustResize" />
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.browser.cloudflare.CloudFlareActivity"
|
android:name="org.koitharu.kotatsu.browser.cloudflare.CloudFlareActivity"
|
||||||
|
android:autoRemoveFromRecents="true"
|
||||||
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
||||||
android:windowSoftInputMode="adjustResize" />
|
android:windowSoftInputMode="adjustResize" />
|
||||||
<activity
|
<activity
|
||||||
@@ -313,6 +320,13 @@
|
|||||||
android:name="android.appwidget.provider"
|
android:name="android.appwidget.provider"
|
||||||
android:resource="@xml/widget_recent" />
|
android:resource="@xml/widget_recent" />
|
||||||
</receiver>
|
</receiver>
|
||||||
|
<receiver
|
||||||
|
android:name="org.koitharu.kotatsu.settings.about.UpdateDownloadReceiver"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.webkit.WebView.EnableSafeBrowsing"
|
android:name="android.webkit.WebView.EnableSafeBrowsing"
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import androidx.core.view.updatePadding
|
|||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.google.android.material.snackbar.Snackbar
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
@@ -25,8 +24,7 @@ import org.koitharu.kotatsu.core.ui.BaseFragment
|
|||||||
import org.koitharu.kotatsu.core.ui.list.ListSelectionController
|
import org.koitharu.kotatsu.core.ui.list.ListSelectionController
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.core.ui.list.fastscroll.FastScroller
|
import org.koitharu.kotatsu.core.ui.list.fastscroll.FastScroller
|
||||||
import org.koitharu.kotatsu.core.ui.util.ReversibleAction
|
import org.koitharu.kotatsu.core.ui.util.ReversibleActionObserver
|
||||||
import org.koitharu.kotatsu.core.ui.util.reverseAsync
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
import org.koitharu.kotatsu.core.util.ext.observe
|
||||||
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
||||||
import org.koitharu.kotatsu.databinding.FragmentListSimpleBinding
|
import org.koitharu.kotatsu.databinding.FragmentListSimpleBinding
|
||||||
@@ -38,7 +36,6 @@ import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
|
|||||||
import org.koitharu.kotatsu.list.ui.adapter.TypedListSpacingDecoration
|
import org.koitharu.kotatsu.list.ui.adapter.TypedListSpacingDecoration
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListHeader
|
import org.koitharu.kotatsu.list.ui.model.ListHeader
|
||||||
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
||||||
import org.koitharu.kotatsu.main.ui.owners.SnackbarOwner
|
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -61,11 +58,17 @@ class BookmarksFragment :
|
|||||||
private var bookmarksAdapter: BookmarksAdapter? = null
|
private var bookmarksAdapter: BookmarksAdapter? = null
|
||||||
private var selectionController: ListSelectionController? = null
|
private var selectionController: ListSelectionController? = null
|
||||||
|
|
||||||
override fun onCreateViewBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentListSimpleBinding {
|
override fun onCreateViewBinding(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
): FragmentListSimpleBinding {
|
||||||
return FragmentListSimpleBinding.inflate(inflater, container, false)
|
return FragmentListSimpleBinding.inflate(inflater, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewBindingCreated(binding: FragmentListSimpleBinding, savedInstanceState: Bundle?) {
|
override fun onViewBindingCreated(
|
||||||
|
binding: FragmentListSimpleBinding,
|
||||||
|
savedInstanceState: Bundle?,
|
||||||
|
) {
|
||||||
super.onViewBindingCreated(binding, savedInstanceState)
|
super.onViewBindingCreated(binding, savedInstanceState)
|
||||||
selectionController = ListSelectionController(
|
selectionController = ListSelectionController(
|
||||||
activity = requireActivity(),
|
activity = requireActivity(),
|
||||||
@@ -95,8 +98,11 @@ class BookmarksFragment :
|
|||||||
viewModel.content.observe(viewLifecycleOwner) {
|
viewModel.content.observe(viewLifecycleOwner) {
|
||||||
bookmarksAdapter?.setItems(it, spanSizeLookup)
|
bookmarksAdapter?.setItems(it, spanSizeLookup)
|
||||||
}
|
}
|
||||||
viewModel.onError.observeEvent(viewLifecycleOwner, SnackbarErrorObserver(binding.recyclerView, this))
|
viewModel.onError.observeEvent(
|
||||||
viewModel.onActionDone.observeEvent(viewLifecycleOwner, ::onActionDone)
|
viewLifecycleOwner,
|
||||||
|
SnackbarErrorObserver(binding.recyclerView, this)
|
||||||
|
)
|
||||||
|
viewModel.onActionDone.observeEvent(viewLifecycleOwner, ReversibleActionObserver(binding.recyclerView))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@@ -139,12 +145,20 @@ class BookmarksFragment :
|
|||||||
requireViewBinding().recyclerView.invalidateItemDecorations()
|
requireViewBinding().recyclerView.invalidateItemDecorations()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateActionMode(controller: ListSelectionController, mode: ActionMode, menu: Menu): Boolean {
|
override fun onCreateActionMode(
|
||||||
|
controller: ListSelectionController,
|
||||||
|
mode: ActionMode,
|
||||||
|
menu: Menu,
|
||||||
|
): Boolean {
|
||||||
mode.menuInflater.inflate(R.menu.mode_bookmarks, menu)
|
mode.menuInflater.inflate(R.menu.mode_bookmarks, menu)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActionItemClicked(controller: ListSelectionController, mode: ActionMode, item: MenuItem): Boolean {
|
override fun onActionItemClicked(
|
||||||
|
controller: ListSelectionController,
|
||||||
|
mode: ActionMode,
|
||||||
|
item: MenuItem,
|
||||||
|
): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.action_remove -> {
|
R.id.action_remove -> {
|
||||||
val ids = selectionController?.snapshot() ?: return false
|
val ids = selectionController?.snapshot() ?: return false
|
||||||
@@ -167,16 +181,6 @@ class BookmarksFragment :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onActionDone(action: ReversibleAction) {
|
|
||||||
val handle = action.handle
|
|
||||||
val length = if (handle == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG
|
|
||||||
val snackbar = Snackbar.make((activity as SnackbarOwner).snackbarHost, action.stringResId, length)
|
|
||||||
if (handle != null) {
|
|
||||||
snackbar.setAction(R.string.undo) { handle.reverseAsync() }
|
|
||||||
}
|
|
||||||
snackbar.show()
|
|
||||||
}
|
|
||||||
|
|
||||||
private inner class SpanSizeLookup : GridLayoutManager.SpanSizeLookup(), Runnable {
|
private inner class SpanSizeLookup : GridLayoutManager.SpanSizeLookup(), Runnable {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -185,7 +189,8 @@ class BookmarksFragment :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getSpanSize(position: Int): Int {
|
override fun getSpanSize(position: Int): Int {
|
||||||
val total = (viewBinding?.recyclerView?.layoutManager as? GridLayoutManager)?.spanCount ?: return 1
|
val total = (viewBinding?.recyclerView?.layoutManager as? GridLayoutManager)?.spanCount
|
||||||
|
?: return 1
|
||||||
return when (bookmarksAdapter?.getItemViewType(position)) {
|
return when (bookmarksAdapter?.getItemViewType(position)) {
|
||||||
ListItemType.PAGE_THUMB.ordinal -> 1
|
ListItemType.PAGE_THUMB.ordinal -> 1
|
||||||
else -> total
|
else -> total
|
||||||
@@ -200,6 +205,12 @@ class BookmarksFragment :
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"", ReplaceWith(
|
||||||
|
"BookmarksFragment()",
|
||||||
|
"org.koitharu.kotatsu.bookmarks.ui.BookmarksFragment"
|
||||||
|
)
|
||||||
|
)
|
||||||
fun newInstance() = BookmarksFragment()
|
fun newInstance() = BookmarksFragment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ class BookmarksSheet :
|
|||||||
|
|
||||||
fun show(fm: FragmentManager, manga: Manga) {
|
fun show(fm: FragmentManager, manga: Manga) {
|
||||||
BookmarksSheet().withArgs(1) {
|
BookmarksSheet().withArgs(1) {
|
||||||
putParcelable(ARG_MANGA, ParcelableManga(manga, withChapters = true))
|
putParcelable(ARG_MANGA, ParcelableManga(manga))
|
||||||
}.showDistinct(fm, TAG)
|
}.showDistinct(fm, TAG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class BookmarksSheetViewModel @Inject constructor(
|
|||||||
|
|
||||||
val content: StateFlow<List<ListModel>> = bookmarksRepository.observeBookmarks(manga)
|
val content: StateFlow<List<ListModel>> = bookmarksRepository.observeBookmarks(manga)
|
||||||
.map { mapList(it) }
|
.map { mapList(it) }
|
||||||
|
.withErrorHandling()
|
||||||
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Lazily, listOf(LoadingFooter()))
|
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Lazily, listOf(LoadingFooter()))
|
||||||
|
|
||||||
private suspend fun mapList(bookmarks: List<Bookmark>): List<ListModel> {
|
private suspend fun mapList(bookmarks: List<Bookmark>): List<ListModel> {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.koitharu.kotatsu.browser.cloudflare
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
import androidx.activity.result.contract.ActivityResultContract
|
import androidx.activity.result.contract.ActivityResultContract
|
||||||
@@ -11,8 +12,14 @@ import androidx.core.net.toUri
|
|||||||
import androidx.core.view.isInvisible
|
import androidx.core.view.isInvisible
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runInterruptible
|
||||||
|
import kotlinx.coroutines.yield
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
|
import okhttp3.HttpUrl
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.browser.WebViewBackPressedCallback
|
import org.koitharu.kotatsu.browser.WebViewBackPressedCallback
|
||||||
@@ -38,7 +45,13 @@ class CloudFlareActivity : BaseActivity<ActivityBrowserBinding>(), CloudFlareCal
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
if (!catchingWebViewUnavailability { setContentView(ActivityBrowserBinding.inflate(layoutInflater)) }) {
|
if (!catchingWebViewUnavailability {
|
||||||
|
setContentView(
|
||||||
|
ActivityBrowserBinding.inflate(
|
||||||
|
layoutInflater
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
supportActionBar?.run {
|
supportActionBar?.run {
|
||||||
@@ -86,6 +99,11 @@ class CloudFlareActivity : BaseActivity<ActivityBrowserBinding>(), CloudFlareCal
|
|||||||
viewBinding.webView.restoreState(savedInstanceState)
|
viewBinding.webView.restoreState(savedInstanceState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
|
menuInflater.inflate(R.menu.opt_captcha, menu)
|
||||||
|
return super.onCreateOptionsMenu(menu)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onWindowInsetsChanged(insets: Insets) {
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
viewBinding.appbar.updatePadding(
|
viewBinding.appbar.updatePadding(
|
||||||
top = insets.top,
|
top = insets.top,
|
||||||
@@ -104,6 +122,19 @@ class CloudFlareActivity : BaseActivity<ActivityBrowserBinding>(), CloudFlareCal
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
R.id.action_retry -> {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
viewBinding.webView.stopLoading()
|
||||||
|
yield()
|
||||||
|
val targetUrl = intent?.dataString?.toHttpUrlOrNull()
|
||||||
|
if (targetUrl != null) {
|
||||||
|
clearCfCookies(targetUrl)
|
||||||
|
viewBinding.webView.loadUrl(targetUrl.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
else -> super.onOptionsItemSelected(item)
|
else -> super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +172,15 @@ class CloudFlareActivity : BaseActivity<ActivityBrowserBinding>(), CloudFlareCal
|
|||||||
|
|
||||||
override fun onTitleChanged(title: CharSequence, subtitle: CharSequence?) {
|
override fun onTitleChanged(title: CharSequence, subtitle: CharSequence?) {
|
||||||
setTitle(title)
|
setTitle(title)
|
||||||
supportActionBar?.subtitle = subtitle?.toString()?.toHttpUrlOrNull()?.topPrivateDomain() ?: subtitle
|
supportActionBar?.subtitle =
|
||||||
|
subtitle?.toString()?.toHttpUrlOrNull()?.topPrivateDomain() ?: subtitle
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun clearCfCookies(url: HttpUrl) = runInterruptible(Dispatchers.Default) {
|
||||||
|
cookieJar.removeCookies(url) { cookie ->
|
||||||
|
val name = cookie.name
|
||||||
|
name.startsWith("cf_") || name.startsWith("_cf") || name.startsWith("__cf")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Contract : ActivityResultContract<Pair<String, Headers?>, TaggedActivityResult>() {
|
class Contract : ActivityResultContract<Pair<String, Headers?>, TaggedActivityResult>() {
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ import org.koitharu.kotatsu.core.cache.ContentCache
|
|||||||
import org.koitharu.kotatsu.core.cache.MemoryContentCache
|
import org.koitharu.kotatsu.core.cache.MemoryContentCache
|
||||||
import org.koitharu.kotatsu.core.cache.StubContentCache
|
import org.koitharu.kotatsu.core.cache.StubContentCache
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.network.*
|
import org.koitharu.kotatsu.core.network.ImageProxyInterceptor
|
||||||
|
import org.koitharu.kotatsu.core.network.MangaHttpClient
|
||||||
import org.koitharu.kotatsu.core.os.AppShortcutManager
|
import org.koitharu.kotatsu.core.os.AppShortcutManager
|
||||||
import org.koitharu.kotatsu.core.os.NetworkState
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.core.parser.MangaLoaderContextImpl
|
import org.koitharu.kotatsu.core.parser.MangaLoaderContextImpl
|
||||||
@@ -40,7 +41,6 @@ import org.koitharu.kotatsu.core.ui.image.CoilImageGetter
|
|||||||
import org.koitharu.kotatsu.core.ui.util.ActivityRecreationHandle
|
import org.koitharu.kotatsu.core.ui.util.ActivityRecreationHandle
|
||||||
import org.koitharu.kotatsu.core.util.AcraScreenLogger
|
import org.koitharu.kotatsu.core.util.AcraScreenLogger
|
||||||
import org.koitharu.kotatsu.core.util.IncognitoModeIndicator
|
import org.koitharu.kotatsu.core.util.IncognitoModeIndicator
|
||||||
import org.koitharu.kotatsu.core.util.ext.activityManager
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.connectivityManager
|
import org.koitharu.kotatsu.core.util.ext.connectivityManager
|
||||||
import org.koitharu.kotatsu.core.util.ext.isLowRamDevice
|
import org.koitharu.kotatsu.core.util.ext.isLowRamDevice
|
||||||
import org.koitharu.kotatsu.local.data.CacheDir
|
import org.koitharu.kotatsu.local.data.CacheDir
|
||||||
@@ -161,7 +161,7 @@ interface AppModule {
|
|||||||
fun provideContentCache(
|
fun provideContentCache(
|
||||||
application: Application,
|
application: Application,
|
||||||
): ContentCache {
|
): ContentCache {
|
||||||
return if (application.activityManager?.isLowRamDevice == true) {
|
return if (application.isLowRamDevice()) {
|
||||||
StubContentCache()
|
StubContentCache()
|
||||||
} else {
|
} else {
|
||||||
MemoryContentCache(application)
|
MemoryContentCache(application)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import androidx.room.InvalidationTracker
|
|||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import androidx.room.migration.Migration
|
import androidx.room.migration.Migration
|
||||||
|
import kotlinx.coroutines.CoroutineStart
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -118,7 +119,7 @@ fun MangaDatabase(context: Context): MangaDatabase = Room
|
|||||||
fun InvalidationTracker.removeObserverAsync(observer: InvalidationTracker.Observer) {
|
fun InvalidationTracker.removeObserverAsync(observer: InvalidationTracker.Observer) {
|
||||||
val scope = processLifecycleScope
|
val scope = processLifecycleScope
|
||||||
if (scope.isActive) {
|
if (scope.isActive) {
|
||||||
processLifecycleScope.launch(Dispatchers.Default) {
|
processLifecycleScope.launch(Dispatchers.Default, CoroutineStart.ATOMIC) {
|
||||||
removeObserver(observer)
|
removeObserver(observer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ const val TABLE_TAGS = "tags"
|
|||||||
const val TABLE_FAVOURITE_CATEGORIES = "favourite_categories"
|
const val TABLE_FAVOURITE_CATEGORIES = "favourite_categories"
|
||||||
const val TABLE_HISTORY = "history"
|
const val TABLE_HISTORY = "history"
|
||||||
const val TABLE_MANGA_TAGS = "manga_tags"
|
const val TABLE_MANGA_TAGS = "manga_tags"
|
||||||
|
const val TABLE_SOURCES = "sources"
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ package org.koitharu.kotatsu.core.db.entity
|
|||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
|
import org.koitharu.kotatsu.core.db.TABLE_SOURCES
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = "sources",
|
tableName = TABLE_SOURCES,
|
||||||
)
|
)
|
||||||
data class MangaSourceEntity(
|
data class MangaSourceEntity(
|
||||||
@PrimaryKey(autoGenerate = false)
|
@PrimaryKey(autoGenerate = false)
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ fun Collection<Manga>.distinctById() = distinctBy { it.id }
|
|||||||
@JvmName("chaptersIds")
|
@JvmName("chaptersIds")
|
||||||
fun Collection<MangaChapter>.ids() = mapToSet { it.id }
|
fun Collection<MangaChapter>.ids() = mapToSet { it.id }
|
||||||
|
|
||||||
|
fun Collection<MangaChapter>.findById(id: Long) = find { x -> x.id == id }
|
||||||
|
|
||||||
fun Collection<ChapterListItem>.countChaptersByBranch(): Int {
|
fun Collection<ChapterListItem>.countChaptersByBranch(): Int {
|
||||||
if (size <= 1) {
|
if (size <= 1) {
|
||||||
return size
|
return size
|
||||||
@@ -30,7 +32,7 @@ fun Collection<ChapterListItem>.countChaptersByBranch(): Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Manga.findChapter(id: Long): MangaChapter? {
|
fun Manga.findChapter(id: Long): MangaChapter? {
|
||||||
return chapters?.find { it.id == id }
|
return chapters?.findById(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Manga.getPreferredBranch(history: MangaHistory?): String? {
|
fun Manga.getPreferredBranch(history: MangaHistory?): String? {
|
||||||
@@ -39,7 +41,7 @@ fun Manga.getPreferredBranch(history: MangaHistory?): String? {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
if (history != null) {
|
if (history != null) {
|
||||||
val currentChapter = ch.find { it.id == history.chapterId }
|
val currentChapter = ch.findById(history.chapterId)
|
||||||
if (currentChapter != null) {
|
if (currentChapter != null) {
|
||||||
return currentChapter.branch
|
return currentChapter.branch
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.core.model
|
package org.koitharu.kotatsu.core.model
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.parsers.model.ContentType
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
@@ -15,3 +16,5 @@ fun MangaSource(name: String): MangaSource {
|
|||||||
}
|
}
|
||||||
return MangaSource.DUMMY
|
return MangaSource.DUMMY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun MangaSource.isNsfw() = contentType == ContentType.HENTAI
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package org.koitharu.kotatsu.core.model.parcelable
|
||||||
|
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
import kotlinx.parcelize.Parceler
|
||||||
|
import kotlinx.parcelize.Parcelize
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.readSerializableCompat
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
data class ParcelableChapter(
|
||||||
|
val chapter: MangaChapter,
|
||||||
|
) : Parcelable {
|
||||||
|
|
||||||
|
companion object : Parceler<ParcelableChapter> {
|
||||||
|
|
||||||
|
override fun create(parcel: Parcel) = ParcelableChapter(
|
||||||
|
MangaChapter(
|
||||||
|
id = parcel.readLong(),
|
||||||
|
name = parcel.readString().orEmpty(),
|
||||||
|
number = parcel.readInt(),
|
||||||
|
url = parcel.readString().orEmpty(),
|
||||||
|
scanlator = parcel.readString(),
|
||||||
|
uploadDate = parcel.readLong(),
|
||||||
|
branch = parcel.readString(),
|
||||||
|
source = parcel.readSerializableCompat() ?: MangaSource.DUMMY,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun ParcelableChapter.write(parcel: Parcel, flags: Int) = with(chapter) {
|
||||||
|
parcel.writeLong(id)
|
||||||
|
parcel.writeString(name)
|
||||||
|
parcel.writeInt(number)
|
||||||
|
parcel.writeString(url)
|
||||||
|
parcel.writeString(scanlator)
|
||||||
|
parcel.writeLong(uploadDate)
|
||||||
|
parcel.writeString(branch)
|
||||||
|
parcel.writeSerializable(source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,55 +9,28 @@ import org.koitharu.kotatsu.core.util.ext.readParcelableCompat
|
|||||||
import org.koitharu.kotatsu.core.util.ext.readSerializableCompat
|
import org.koitharu.kotatsu.core.util.ext.readSerializableCompat
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
|
||||||
// Limits to avoid TransactionTooLargeException
|
|
||||||
private const val MAX_SAFE_SIZE = 1024 * 100 // Assume that 100 kb is safe parcel size
|
|
||||||
private const val MAX_SAFE_CHAPTERS_COUNT = 24 // this is 100% safe
|
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class ParcelableManga(
|
data class ParcelableManga(
|
||||||
val manga: Manga,
|
val manga: Manga,
|
||||||
private val withChapters: Boolean,
|
|
||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
companion object : Parceler<ParcelableManga> {
|
|
||||||
private fun Manga.writeToParcel(out: Parcel, flags: Int, withChapters: Boolean) {
|
|
||||||
out.writeLong(id)
|
|
||||||
out.writeString(title)
|
|
||||||
out.writeString(altTitle)
|
|
||||||
out.writeString(url)
|
|
||||||
out.writeString(publicUrl)
|
|
||||||
out.writeFloat(rating)
|
|
||||||
ParcelCompat.writeBoolean(out, isNsfw)
|
|
||||||
out.writeString(coverUrl)
|
|
||||||
out.writeString(largeCoverUrl)
|
|
||||||
out.writeString(description)
|
|
||||||
out.writeParcelable(ParcelableMangaTags(tags), flags)
|
|
||||||
out.writeSerializable(state)
|
|
||||||
out.writeString(author)
|
|
||||||
val parcelableChapters = if (withChapters) null else chapters?.let(::ParcelableMangaChapters)
|
|
||||||
out.writeParcelable(parcelableChapters, flags)
|
|
||||||
out.writeSerializable(source)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun ParcelableManga.write(parcel: Parcel, flags: Int) {
|
companion object : Parceler<ParcelableManga> {
|
||||||
val chapters = manga.chapters
|
|
||||||
if (!withChapters || chapters == null) {
|
override fun ParcelableManga.write(parcel: Parcel, flags: Int) = with(manga) {
|
||||||
manga.writeToParcel(parcel, flags, withChapters = false)
|
parcel.writeLong(id)
|
||||||
return
|
parcel.writeString(title)
|
||||||
}
|
parcel.writeString(altTitle)
|
||||||
if (chapters.size <= MAX_SAFE_CHAPTERS_COUNT) {
|
parcel.writeString(url)
|
||||||
// fast path
|
parcel.writeString(publicUrl)
|
||||||
manga.writeToParcel(parcel, flags, withChapters = true)
|
parcel.writeFloat(rating)
|
||||||
return
|
ParcelCompat.writeBoolean(parcel, isNsfw)
|
||||||
}
|
parcel.writeString(coverUrl)
|
||||||
val tempParcel = Parcel.obtain()
|
parcel.writeString(largeCoverUrl)
|
||||||
manga.writeToParcel(tempParcel, flags, withChapters = true)
|
parcel.writeString(description)
|
||||||
val size = tempParcel.dataSize()
|
parcel.writeParcelable(ParcelableMangaTags(tags), flags)
|
||||||
if (size < MAX_SAFE_SIZE) {
|
parcel.writeSerializable(state)
|
||||||
parcel.appendFrom(tempParcel, 0, size)
|
parcel.writeString(author)
|
||||||
} else {
|
parcel.writeSerializable(source)
|
||||||
manga.writeToParcel(parcel, flags, withChapters = false)
|
|
||||||
}
|
|
||||||
tempParcel.recycle()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun create(parcel: Parcel) = ParcelableManga(
|
override fun create(parcel: Parcel) = ParcelableManga(
|
||||||
@@ -75,10 +48,9 @@ data class ParcelableManga(
|
|||||||
tags = requireNotNull(parcel.readParcelableCompat<ParcelableMangaTags>()).tags,
|
tags = requireNotNull(parcel.readParcelableCompat<ParcelableMangaTags>()).tags,
|
||||||
state = parcel.readSerializableCompat(),
|
state = parcel.readSerializableCompat(),
|
||||||
author = parcel.readString(),
|
author = parcel.readString(),
|
||||||
chapters = parcel.readParcelableCompat<ParcelableMangaChapters>()?.chapters,
|
chapters = null,
|
||||||
source = requireNotNull(parcel.readSerializableCompat()),
|
source = requireNotNull(parcel.readSerializableCompat()),
|
||||||
),
|
)
|
||||||
withChapters = true
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.model.parcelable
|
|
||||||
|
|
||||||
import android.os.Parcel
|
|
||||||
import android.os.Parcelable
|
|
||||||
import kotlinx.parcelize.Parceler
|
|
||||||
import kotlinx.parcelize.Parcelize
|
|
||||||
import kotlinx.parcelize.TypeParceler
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.readSerializableCompat
|
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
|
||||||
|
|
||||||
object MangaChapterParceler : Parceler<MangaChapter> {
|
|
||||||
override fun create(parcel: Parcel) = MangaChapter(
|
|
||||||
id = parcel.readLong(),
|
|
||||||
name = requireNotNull(parcel.readString()),
|
|
||||||
number = parcel.readInt(),
|
|
||||||
url = requireNotNull(parcel.readString()),
|
|
||||||
scanlator = parcel.readString(),
|
|
||||||
uploadDate = parcel.readLong(),
|
|
||||||
branch = parcel.readString(),
|
|
||||||
source = requireNotNull(parcel.readSerializableCompat()),
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun MangaChapter.write(parcel: Parcel, flags: Int) {
|
|
||||||
parcel.writeLong(id)
|
|
||||||
parcel.writeString(name)
|
|
||||||
parcel.writeInt(number)
|
|
||||||
parcel.writeString(url)
|
|
||||||
parcel.writeString(scanlator)
|
|
||||||
parcel.writeLong(uploadDate)
|
|
||||||
parcel.writeString(branch)
|
|
||||||
parcel.writeSerializable(source)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Parcelize
|
|
||||||
@TypeParceler<MangaChapter, MangaChapterParceler>
|
|
||||||
data class ParcelableMangaChapters(val chapters: List<MangaChapter>) : Parcelable
|
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.core.network
|
package org.koitharu.kotatsu.core.network
|
||||||
|
|
||||||
|
import androidx.collection.ArraySet
|
||||||
import dagger.Lazy
|
import dagger.Lazy
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.runInterruptible
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
@@ -13,6 +16,7 @@ import org.koitharu.kotatsu.core.parser.MangaRepository
|
|||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import java.util.EnumMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@@ -22,9 +26,15 @@ class MirrorSwitchInterceptor @Inject constructor(
|
|||||||
private val settings: AppSettings,
|
private val settings: AppSettings,
|
||||||
) : Interceptor {
|
) : Interceptor {
|
||||||
|
|
||||||
|
private val locks = EnumMap<MangaSource, Any>(MangaSource::class.java)
|
||||||
|
private val blacklist = EnumMap<MangaSource, MutableSet<String>>(MangaSource::class.java)
|
||||||
|
|
||||||
|
val isEnabled: Boolean
|
||||||
|
get() = settings.isMirrorSwitchingAvailable
|
||||||
|
|
||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
val request = chain.request()
|
val request = chain.request()
|
||||||
if (!settings.isMirrorSwitchingAvailable) {
|
if (!isEnabled) {
|
||||||
return chain.proceed(request)
|
return chain.proceed(request)
|
||||||
}
|
}
|
||||||
return try {
|
return try {
|
||||||
@@ -43,6 +53,30 @@ class MirrorSwitchInterceptor @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun trySwitchMirror(repository: RemoteMangaRepository): Boolean = runInterruptible(Dispatchers.Default) {
|
||||||
|
if (!isEnabled) {
|
||||||
|
return@runInterruptible false
|
||||||
|
}
|
||||||
|
val mirrors = repository.getAvailableMirrors()
|
||||||
|
if (mirrors.size <= 1) {
|
||||||
|
return@runInterruptible false
|
||||||
|
}
|
||||||
|
synchronized(obtainLock(repository.source)) {
|
||||||
|
val currentMirror = repository.domain
|
||||||
|
addToBlacklist(repository.source, currentMirror)
|
||||||
|
val newMirror = mirrors.firstOrNull { x ->
|
||||||
|
x != currentMirror && !isBlacklisted(repository.source, x)
|
||||||
|
} ?: return@synchronized false
|
||||||
|
repository.domain = newMirror
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rollback(repository: RemoteMangaRepository, oldMirror: String) = synchronized(obtainLock(repository.source)) {
|
||||||
|
blacklist[repository.source]?.remove(oldMirror)
|
||||||
|
repository.domain = oldMirror
|
||||||
|
}
|
||||||
|
|
||||||
private fun trySwitchMirror(request: Request, chain: Interceptor.Chain): Response? {
|
private fun trySwitchMirror(request: Request, chain: Interceptor.Chain): Response? {
|
||||||
val source = request.tag(MangaSource::class.java) ?: return null
|
val source = request.tag(MangaSource::class.java) ?: return null
|
||||||
val repository = mangaRepositoryFactoryLazy.get().create(source) as? RemoteMangaRepository ?: return null
|
val repository = mangaRepositoryFactoryLazy.get().create(source) as? RemoteMangaRepository ?: return null
|
||||||
@@ -50,7 +84,9 @@ class MirrorSwitchInterceptor @Inject constructor(
|
|||||||
if (mirrors.isEmpty()) {
|
if (mirrors.isEmpty()) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return tryMirrors(repository, mirrors, chain, request)
|
return synchronized(obtainLock(repository.source)) {
|
||||||
|
tryMirrors(repository, mirrors, chain, request)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryMirrors(
|
private fun tryMirrors(
|
||||||
@@ -66,7 +102,7 @@ class MirrorSwitchInterceptor @Inject constructor(
|
|||||||
}
|
}
|
||||||
val urlBuilder = url.newBuilder()
|
val urlBuilder = url.newBuilder()
|
||||||
for (mirror in mirrors) {
|
for (mirror in mirrors) {
|
||||||
if (mirror == currentDomain) {
|
if (mirror == currentDomain || isBlacklisted(repository.source, mirror)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
val newHost = hostOf(url.host, mirror) ?: continue
|
val newHost = hostOf(url.host, mirror) ?: continue
|
||||||
@@ -75,6 +111,7 @@ class MirrorSwitchInterceptor @Inject constructor(
|
|||||||
.build()
|
.build()
|
||||||
val response = chain.proceed(newRequest)
|
val response = chain.proceed(newRequest)
|
||||||
if (response.isFailed) {
|
if (response.isFailed) {
|
||||||
|
addToBlacklist(repository.source, mirror)
|
||||||
response.closeQuietly()
|
response.closeQuietly()
|
||||||
} else {
|
} else {
|
||||||
repository.domain = mirror
|
repository.domain = mirror
|
||||||
@@ -104,4 +141,18 @@ class MirrorSwitchInterceptor @Inject constructor(
|
|||||||
private fun ResponseBody.copy(): ResponseBody {
|
private fun ResponseBody.copy(): ResponseBody {
|
||||||
return source().readByteArray().toResponseBody(contentType())
|
return source().readByteArray().toResponseBody(contentType())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun obtainLock(source: MangaSource): Any = locks.getOrPut(source) {
|
||||||
|
Any()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isBlacklisted(source: MangaSource, domain: String): Boolean {
|
||||||
|
return blacklist[source]?.contains(domain) == true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addToBlacklist(source: MangaSource, domain: String) {
|
||||||
|
blacklist.getOrPut(source) {
|
||||||
|
ArraySet(2)
|
||||||
|
}.add(domain)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.core.network.cookies
|
|||||||
|
|
||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
|
import androidx.core.util.Predicate
|
||||||
import okhttp3.Cookie
|
import okhttp3.Cookie
|
||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
import org.koitharu.kotatsu.core.util.ext.newBuilder
|
import org.koitharu.kotatsu.core.util.ext.newBuilder
|
||||||
@@ -31,19 +32,21 @@ class AndroidCookieJar : MutableCookieJar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun removeCookies(url: HttpUrl) {
|
override fun removeCookies(url: HttpUrl, predicate: Predicate<Cookie>?) {
|
||||||
val cookies = loadForRequest(url)
|
val cookies = loadForRequest(url)
|
||||||
if (cookies.isEmpty()) {
|
if (cookies.isEmpty()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val urlString = url.toString()
|
val urlString = url.toString()
|
||||||
for (c in cookies) {
|
for (c in cookies) {
|
||||||
|
if (predicate != null && !predicate.test(c)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
val nc = c.newBuilder()
|
val nc = c.newBuilder()
|
||||||
.expiresAt(System.currentTimeMillis() - 100000)
|
.expiresAt(System.currentTimeMillis() - 100000)
|
||||||
.build()
|
.build()
|
||||||
cookieManager.setCookie(urlString, nc.toString())
|
cookieManager.setCookie(urlString, nc.toString())
|
||||||
}
|
}
|
||||||
check(loadForRequest(url).isEmpty())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun clear() = suspendCoroutine<Boolean> { continuation ->
|
override suspend fun clear() = suspendCoroutine<Boolean> { continuation ->
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.core.network.cookies
|
package org.koitharu.kotatsu.core.network.cookies
|
||||||
|
|
||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
|
import androidx.core.util.Predicate
|
||||||
import okhttp3.Cookie
|
import okhttp3.Cookie
|
||||||
import okhttp3.CookieJar
|
import okhttp3.CookieJar
|
||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
@@ -14,7 +15,7 @@ interface MutableCookieJar : CookieJar {
|
|||||||
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>)
|
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>)
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
fun removeCookies(url: HttpUrl)
|
fun removeCookies(url: HttpUrl, predicate: Predicate<Cookie>?)
|
||||||
|
|
||||||
suspend fun clear(): Boolean
|
suspend fun clear(): Boolean
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
import androidx.collection.ArrayMap
|
import androidx.collection.ArrayMap
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
|
import androidx.core.util.Predicate
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import okhttp3.Cookie
|
import okhttp3.Cookie
|
||||||
@@ -57,12 +58,14 @@ class PreferencesCookieJar(
|
|||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
override fun removeCookies(url: HttpUrl) {
|
override fun removeCookies(url: HttpUrl, predicate: Predicate<Cookie>?) {
|
||||||
loadPersistent()
|
loadPersistent()
|
||||||
val toRemove = HashSet<String>()
|
val toRemove = HashSet<String>()
|
||||||
for ((key, cookie) in cache) {
|
for ((key, cookie) in cache) {
|
||||||
if (cookie.isExpired() || cookie.cookie.matches(url)) {
|
if (cookie.isExpired() || cookie.cookie.matches(url)) {
|
||||||
toRemove += key
|
if (predicate == null || predicate.test(cookie.cookie)) {
|
||||||
|
toRemove += key
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (toRemove.isNotEmpty()) {
|
if (toRemove.isNotEmpty()) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import kotlinx.coroutines.launch
|
|||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.db.TABLE_HISTORY
|
import org.koitharu.kotatsu.core.db.TABLE_HISTORY
|
||||||
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
||||||
|
import org.koitharu.kotatsu.core.parser.favicon.faviconUri
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.ui.image.ThumbnailTransformation
|
import org.koitharu.kotatsu.core.ui.image.ThumbnailTransformation
|
||||||
import org.koitharu.kotatsu.core.util.ext.getDrawableOrThrow
|
import org.koitharu.kotatsu.core.util.ext.getDrawableOrThrow
|
||||||
@@ -29,8 +30,10 @@ import org.koitharu.kotatsu.core.util.ext.processLifecycleScope
|
|||||||
import org.koitharu.kotatsu.core.util.ext.source
|
import org.koitharu.kotatsu.core.util.ext.source
|
||||||
import org.koitharu.kotatsu.history.data.HistoryRepository
|
import org.koitharu.kotatsu.history.data.HistoryRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
||||||
|
import org.koitharu.kotatsu.search.ui.MangaListActivity
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@@ -73,8 +76,18 @@ class AppShortcutManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun requestPinShortcut(manga: Manga): Boolean {
|
suspend fun requestPinShortcut(manga: Manga): Boolean = try {
|
||||||
return ShortcutManagerCompat.requestPinShortcut(context, buildShortcutInfo(manga), null)
|
ShortcutManagerCompat.requestPinShortcut(context, buildShortcutInfo(manga), null)
|
||||||
|
} catch (e: IllegalStateException) {
|
||||||
|
e.printStackTraceDebug()
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun requestPinShortcut(source: MangaSource): Boolean = try {
|
||||||
|
ShortcutManagerCompat.requestPinShortcut(context, buildShortcutInfo(source), null)
|
||||||
|
} catch (e: IllegalStateException) {
|
||||||
|
e.printStackTraceDebug()
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -86,6 +99,11 @@ class AppShortcutManager @Inject constructor(
|
|||||||
ShortcutManagerCompat.reportShortcutUsed(context, mangaId.toString())
|
ShortcutManagerCompat.reportShortcutUsed(context, mangaId.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isDynamicShortcutsAvailable(): Boolean {
|
||||||
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 &&
|
||||||
|
context.getSystemService(ShortcutManager::class.java).maxShortcutCountPerActivity > 0
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun updateShortcutsImpl() = runCatchingCancellable {
|
private suspend fun updateShortcutsImpl() = runCatchingCancellable {
|
||||||
val maxShortcuts = ShortcutManagerCompat.getMaxShortcutCountPerActivity(context).coerceAtLeast(5)
|
val maxShortcuts = ShortcutManagerCompat.getMaxShortcutCountPerActivity(context).coerceAtLeast(5)
|
||||||
val shortcuts = historyRepository.getList(0, maxShortcuts)
|
val shortcuts = historyRepository.getList(0, maxShortcuts)
|
||||||
@@ -132,8 +150,25 @@ class AppShortcutManager @Inject constructor(
|
|||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isDynamicShortcutsAvailable(): Boolean {
|
private suspend fun buildShortcutInfo(source: MangaSource): ShortcutInfoCompat {
|
||||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 &&
|
val icon = runCatchingCancellable {
|
||||||
context.getSystemService(ShortcutManager::class.java).maxShortcutCountPerActivity > 0
|
coil.execute(
|
||||||
|
ImageRequest.Builder(context)
|
||||||
|
.data(source.faviconUri())
|
||||||
|
.size(iconSize)
|
||||||
|
.scale(Scale.FIT)
|
||||||
|
.build(),
|
||||||
|
).getDrawableOrThrow().toBitmap()
|
||||||
|
}.fold(
|
||||||
|
onSuccess = { IconCompat.createWithAdaptiveBitmap(it) },
|
||||||
|
onFailure = { IconCompat.createWithResource(context, R.drawable.ic_shortcut_default) },
|
||||||
|
)
|
||||||
|
return ShortcutInfoCompat.Builder(context, source.name)
|
||||||
|
.setShortLabel(source.title)
|
||||||
|
.setLongLabel(source.title)
|
||||||
|
.setIcon(icon)
|
||||||
|
.setLongLived(true)
|
||||||
|
.setIntent(MangaListActivity.newIntent(context, source))
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.core.parser
|
|||||||
|
|
||||||
import androidx.annotation.AnyThread
|
import androidx.annotation.AnyThread
|
||||||
import org.koitharu.kotatsu.core.cache.ContentCache
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
||||||
|
import org.koitharu.kotatsu.core.network.MirrorSwitchInterceptor
|
||||||
import org.koitharu.kotatsu.local.data.LocalMangaRepository
|
import org.koitharu.kotatsu.local.data.LocalMangaRepository
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
@@ -43,6 +44,7 @@ interface MangaRepository {
|
|||||||
private val localMangaRepository: LocalMangaRepository,
|
private val localMangaRepository: LocalMangaRepository,
|
||||||
private val loaderContext: MangaLoaderContext,
|
private val loaderContext: MangaLoaderContext,
|
||||||
private val contentCache: ContentCache,
|
private val contentCache: ContentCache,
|
||||||
|
private val mirrorSwitchInterceptor: MirrorSwitchInterceptor,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val cache = EnumMap<MangaSource, WeakReference<RemoteMangaRepository>>(MangaSource::class.java)
|
private val cache = EnumMap<MangaSource, WeakReference<RemoteMangaRepository>>(MangaSource::class.java)
|
||||||
@@ -55,7 +57,11 @@ interface MangaRepository {
|
|||||||
cache[source]?.get()?.let { return it }
|
cache[source]?.get()?.let { return it }
|
||||||
return synchronized(cache) {
|
return synchronized(cache) {
|
||||||
cache[source]?.get()?.let { return it }
|
cache[source]?.get()?.let { return it }
|
||||||
val repository = RemoteMangaRepository(MangaParser(source, loaderContext), contentCache)
|
val repository = RemoteMangaRepository(
|
||||||
|
parser = MangaParser(source, loaderContext),
|
||||||
|
cache = contentCache,
|
||||||
|
mirrorSwitchInterceptor = mirrorSwitchInterceptor,
|
||||||
|
)
|
||||||
cache[source] = WeakReference(repository)
|
cache[source] = WeakReference(repository)
|
||||||
repository
|
repository
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,13 @@ import okhttp3.Response
|
|||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.core.cache.ContentCache
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
||||||
import org.koitharu.kotatsu.core.cache.SafeDeferred
|
import org.koitharu.kotatsu.core.cache.SafeDeferred
|
||||||
|
import org.koitharu.kotatsu.core.network.MirrorSwitchInterceptor
|
||||||
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
||||||
import org.koitharu.kotatsu.core.util.ext.processLifecycleScope
|
import org.koitharu.kotatsu.core.util.ext.processLifecycleScope
|
||||||
import org.koitharu.kotatsu.parsers.MangaParser
|
import org.koitharu.kotatsu.parsers.MangaParser
|
||||||
import org.koitharu.kotatsu.parsers.MangaParserAuthProvider
|
import org.koitharu.kotatsu.parsers.MangaParserAuthProvider
|
||||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||||
|
import org.koitharu.kotatsu.parsers.exception.ParseException
|
||||||
import org.koitharu.kotatsu.parsers.model.Favicons
|
import org.koitharu.kotatsu.parsers.model.Favicons
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
@@ -31,6 +33,7 @@ import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
|||||||
class RemoteMangaRepository(
|
class RemoteMangaRepository(
|
||||||
private val parser: MangaParser,
|
private val parser: MangaParser,
|
||||||
private val cache: ContentCache,
|
private val cache: ContentCache,
|
||||||
|
private val mirrorSwitchInterceptor: MirrorSwitchInterceptor,
|
||||||
) : MangaRepository, Interceptor {
|
) : MangaRepository, Interceptor {
|
||||||
|
|
||||||
override val source: MangaSource
|
override val source: MangaSource
|
||||||
@@ -66,11 +69,15 @@ class RemoteMangaRepository(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getList(offset: Int, query: String): List<Manga> {
|
override suspend fun getList(offset: Int, query: String): List<Manga> {
|
||||||
return parser.getList(offset, query)
|
return mirrorSwitchInterceptor.withMirrorSwitching {
|
||||||
|
parser.getList(offset, query)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getList(offset: Int, tags: Set<MangaTag>?, sortOrder: SortOrder?): List<Manga> {
|
override suspend fun getList(offset: Int, tags: Set<MangaTag>?, sortOrder: SortOrder?): List<Manga> {
|
||||||
return parser.getList(offset, tags, sortOrder)
|
return mirrorSwitchInterceptor.withMirrorSwitching {
|
||||||
|
parser.getList(offset, tags, sortOrder)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga = getDetails(manga, withCache = true)
|
override suspend fun getDetails(manga: Manga): Manga = getDetails(manga, withCache = true)
|
||||||
@@ -78,17 +85,25 @@ class RemoteMangaRepository(
|
|||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
||||||
cache.getPages(source, chapter.url)?.let { return it }
|
cache.getPages(source, chapter.url)?.let { return it }
|
||||||
val pages = asyncSafe {
|
val pages = asyncSafe {
|
||||||
parser.getPages(chapter).distinctById()
|
mirrorSwitchInterceptor.withMirrorSwitching {
|
||||||
|
parser.getPages(chapter).distinctById()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cache.putPages(source, chapter.url, pages)
|
cache.putPages(source, chapter.url, pages)
|
||||||
return pages.await()
|
return pages.await()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getPageUrl(page: MangaPage): String = parser.getPageUrl(page)
|
override suspend fun getPageUrl(page: MangaPage): String = mirrorSwitchInterceptor.withMirrorSwitching {
|
||||||
|
parser.getPageUrl(page)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> = parser.getTags()
|
override suspend fun getTags(): Set<MangaTag> = mirrorSwitchInterceptor.withMirrorSwitching {
|
||||||
|
parser.getTags()
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun getFavicons(): Favicons = parser.getFavicons()
|
suspend fun getFavicons(): Favicons = mirrorSwitchInterceptor.withMirrorSwitching {
|
||||||
|
parser.getFavicons()
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getRelated(seed: Manga): List<Manga> {
|
override suspend fun getRelated(seed: Manga): List<Manga> {
|
||||||
cache.getRelatedManga(source, seed.url)?.let { return it }
|
cache.getRelatedManga(source, seed.url)?.let { return it }
|
||||||
@@ -105,7 +120,9 @@ class RemoteMangaRepository(
|
|||||||
}
|
}
|
||||||
cache.getDetails(source, manga.url)?.let { return it }
|
cache.getDetails(source, manga.url)?.let { return it }
|
||||||
val details = asyncSafe {
|
val details = asyncSafe {
|
||||||
parser.getDetails(manga)
|
mirrorSwitchInterceptor.withMirrorSwitching {
|
||||||
|
parser.getDetails(manga)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cache.putDetails(source, manga.url, details)
|
cache.putDetails(source, manga.url, details)
|
||||||
return details.await()
|
return details.await()
|
||||||
@@ -155,4 +172,33 @@ class RemoteMangaRepository(
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun <R> MirrorSwitchInterceptor.withMirrorSwitching(block: suspend () -> R): R {
|
||||||
|
if (!isEnabled) {
|
||||||
|
return block()
|
||||||
|
}
|
||||||
|
val initialMirror = domain
|
||||||
|
val result = runCatchingCancellable {
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
if (result.isValidResult()) {
|
||||||
|
return result.getOrThrow()
|
||||||
|
}
|
||||||
|
return if (trySwitchMirror(this@RemoteMangaRepository)) {
|
||||||
|
val newResult = runCatchingCancellable {
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
if (newResult.isValidResult()) {
|
||||||
|
return newResult.getOrThrow()
|
||||||
|
} else {
|
||||||
|
rollback(this@RemoteMangaRepository, initialMirror)
|
||||||
|
return result.getOrThrow()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result.getOrThrow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Result<*>.isValidResult() = exceptionOrNull() !is ParseException
|
||||||
|
&& (getOrNull() as? Collection<*>)?.isEmpty() != true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.koitharu.kotatsu.core.util.ext.takeIfReadable
|
|||||||
import org.koitharu.kotatsu.core.util.ext.toUriOrNull
|
import org.koitharu.kotatsu.core.util.ext.toUriOrNull
|
||||||
import org.koitharu.kotatsu.history.domain.model.HistoryOrder
|
import org.koitharu.kotatsu.history.domain.model.HistoryOrder
|
||||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
|
import org.koitharu.kotatsu.parsers.util.find
|
||||||
import org.koitharu.kotatsu.parsers.util.mapNotNullToSet
|
import org.koitharu.kotatsu.parsers.util.mapNotNullToSet
|
||||||
import org.koitharu.kotatsu.parsers.util.mapToSet
|
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -43,7 +44,8 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
set(value) = prefs.edit { putEnumValue(KEY_LIST_MODE, value) }
|
set(value) = prefs.edit { putEnumValue(KEY_LIST_MODE, value) }
|
||||||
|
|
||||||
val theme: Int
|
val theme: Int
|
||||||
get() = prefs.getString(KEY_THEME, null)?.toIntOrNull() ?: AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
get() = prefs.getString(KEY_THEME, null)?.toIntOrNull()
|
||||||
|
?: AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||||
|
|
||||||
val colorScheme: ColorScheme
|
val colorScheme: ColorScheme
|
||||||
get() = prefs.getEnumValue(KEY_COLOR_THEME, ColorScheme.default)
|
get() = prefs.getEnumValue(KEY_COLOR_THEME, ColorScheme.default)
|
||||||
@@ -51,8 +53,20 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val isAmoledTheme: Boolean
|
val isAmoledTheme: Boolean
|
||||||
get() = prefs.getBoolean(KEY_THEME_AMOLED, false)
|
get() = prefs.getBoolean(KEY_THEME_AMOLED, false)
|
||||||
|
|
||||||
val isFavoritesNavItemFirst: Boolean
|
var mainNavItems: List<NavItem>
|
||||||
get() = (prefs.getString(KEY_FIRST_NAV_ITEM, null)?.toIntOrNull() ?: 0) == 1
|
get() {
|
||||||
|
val raw = prefs.getString(KEY_NAV_MAIN, null)?.split(',')
|
||||||
|
return if (raw.isNullOrEmpty()) {
|
||||||
|
listOf(NavItem.HISTORY, NavItem.FAVORITES, NavItem.EXPLORE, NavItem.FEED)
|
||||||
|
} else {
|
||||||
|
raw.mapNotNull { x -> NavItem.entries.find(x) }.ifEmpty { listOf(NavItem.EXPLORE) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
prefs.edit {
|
||||||
|
putString(KEY_NAV_MAIN, value.joinToString(",") { it.name })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var gridSize: Int
|
var gridSize: Int
|
||||||
get() = prefs.getInt(KEY_GRID_SIZE, 100)
|
get() = prefs.getInt(KEY_GRID_SIZE, 100)
|
||||||
@@ -76,6 +90,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val readerPageSwitch: Set<String>
|
val readerPageSwitch: Set<String>
|
||||||
get() = prefs.getStringSet(KEY_READER_SWITCHERS, null) ?: setOf(PAGE_SWITCH_TAPS)
|
get() = prefs.getStringSet(KEY_READER_SWITCHERS, null) ?: setOf(PAGE_SWITCH_TAPS)
|
||||||
|
|
||||||
|
val isReaderZoomButtonsEnabled: Boolean
|
||||||
|
get() = prefs.getBoolean(KEY_READER_ZOOM_BUTTONS, false)
|
||||||
|
|
||||||
val isReaderTapsAdaptive: Boolean
|
val isReaderTapsAdaptive: Boolean
|
||||||
get() = !prefs.getBoolean(KEY_READER_TAPS_LTR, false)
|
get() = !prefs.getBoolean(KEY_READER_TAPS_LTR, false)
|
||||||
|
|
||||||
@@ -145,7 +162,11 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
|
|
||||||
var appPassword: String?
|
var appPassword: String?
|
||||||
get() = prefs.getString(KEY_APP_PASSWORD, null)
|
get() = prefs.getString(KEY_APP_PASSWORD, null)
|
||||||
set(value) = prefs.edit { if (value != null) putString(KEY_APP_PASSWORD, value) else remove(KEY_APP_PASSWORD) }
|
set(value) = prefs.edit {
|
||||||
|
if (value != null) putString(KEY_APP_PASSWORD, value) else remove(
|
||||||
|
KEY_APP_PASSWORD,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val isLoggingEnabled: Boolean
|
val isLoggingEnabled: Boolean
|
||||||
get() = prefs.getBoolean(KEY_LOGGING_ENABLED, false)
|
get() = prefs.getBoolean(KEY_LOGGING_ENABLED, false)
|
||||||
@@ -171,7 +192,8 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
if (isBackgroundNetworkRestricted()) {
|
if (isBackgroundNetworkRestricted()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
val policy = NetworkPolicy.from(prefs.getString(KEY_PREFETCH_CONTENT, null), NetworkPolicy.NEVER)
|
val policy =
|
||||||
|
NetworkPolicy.from(prefs.getString(KEY_PREFETCH_CONTENT, null), NetworkPolicy.NEVER)
|
||||||
return policy.isNetworkAllowed(connectivityManager)
|
return policy.isNetworkAllowed(connectivityManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +270,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val isReaderSliderEnabled: Boolean
|
val isReaderSliderEnabled: Boolean
|
||||||
get() = prefs.getBoolean(KEY_READER_SLIDER, true)
|
get() = prefs.getBoolean(KEY_READER_SLIDER, true)
|
||||||
|
|
||||||
|
val isReaderKeepScreenOn: Boolean
|
||||||
|
get() = prefs.getBoolean(KEY_READER_SCREEN_ON, true)
|
||||||
|
|
||||||
val isImagesProxyEnabled: Boolean
|
val isImagesProxyEnabled: Boolean
|
||||||
get() = prefs.getBoolean(KEY_IMAGES_PROXY, false)
|
get() = prefs.getBoolean(KEY_IMAGES_PROXY, false)
|
||||||
|
|
||||||
@@ -292,14 +317,22 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
@get:FloatRange(from = 0.0, to = 1.0)
|
@get:FloatRange(from = 0.0, to = 1.0)
|
||||||
var readerAutoscrollSpeed: Float
|
var readerAutoscrollSpeed: Float
|
||||||
get() = prefs.getFloat(KEY_READER_AUTOSCROLL_SPEED, 0f)
|
get() = prefs.getFloat(KEY_READER_AUTOSCROLL_SPEED, 0f)
|
||||||
set(@FloatRange(from = 0.0, to = 1.0) value) = prefs.edit { putFloat(KEY_READER_AUTOSCROLL_SPEED, value) }
|
set(@FloatRange(from = 0.0, to = 1.0) value) = prefs.edit {
|
||||||
|
putFloat(
|
||||||
|
KEY_READER_AUTOSCROLL_SPEED,
|
||||||
|
value,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val isPagesPreloadEnabled: Boolean
|
val isPagesPreloadEnabled: Boolean
|
||||||
get() {
|
get() {
|
||||||
if (isBackgroundNetworkRestricted()) {
|
if (isBackgroundNetworkRestricted()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
val policy = NetworkPolicy.from(prefs.getString(KEY_PAGES_PRELOAD, null), NetworkPolicy.NON_METERED)
|
val policy = NetworkPolicy.from(
|
||||||
|
prefs.getString(KEY_PAGES_PRELOAD, null),
|
||||||
|
NetworkPolicy.NON_METERED,
|
||||||
|
)
|
||||||
return policy.isNetworkAllowed(connectivityManager)
|
return policy.isNetworkAllowed(connectivityManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,6 +415,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
const val KEY_REMOTE_SOURCES = "remote_sources"
|
const val KEY_REMOTE_SOURCES = "remote_sources"
|
||||||
const val KEY_LOCAL_STORAGE = "local_storage"
|
const val KEY_LOCAL_STORAGE = "local_storage"
|
||||||
const val KEY_READER_SWITCHERS = "reader_switchers"
|
const val KEY_READER_SWITCHERS = "reader_switchers"
|
||||||
|
const val KEY_READER_ZOOM_BUTTONS = "reader_zoom_buttons"
|
||||||
const val KEY_TRACKER_ENABLED = "tracker_enabled"
|
const val KEY_TRACKER_ENABLED = "tracker_enabled"
|
||||||
const val KEY_TRACKER_WIFI_ONLY = "tracker_wifi"
|
const val KEY_TRACKER_WIFI_ONLY = "tracker_wifi"
|
||||||
const val KEY_TRACK_SOURCES = "track_sources"
|
const val KEY_TRACK_SOURCES = "track_sources"
|
||||||
@@ -429,6 +463,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
const val KEY_READER_BAR = "reader_bar"
|
const val KEY_READER_BAR = "reader_bar"
|
||||||
const val KEY_READER_SLIDER = "reader_slider"
|
const val KEY_READER_SLIDER = "reader_slider"
|
||||||
const val KEY_READER_BACKGROUND = "reader_background"
|
const val KEY_READER_BACKGROUND = "reader_background"
|
||||||
|
const val KEY_READER_SCREEN_ON = "reader_screen_on"
|
||||||
const val KEY_SHORTCUTS = "dynamic_shortcuts"
|
const val KEY_SHORTCUTS = "dynamic_shortcuts"
|
||||||
const val KEY_READER_TAPS_LTR = "reader_taps_ltr"
|
const val KEY_READER_TAPS_LTR = "reader_taps_ltr"
|
||||||
const val KEY_LOCAL_LIST_ORDER = "local_order"
|
const val KEY_LOCAL_LIST_ORDER = "local_order"
|
||||||
@@ -455,7 +490,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
const val KEY_LOCAL_MANGA_DIRS = "local_manga_dirs"
|
const val KEY_LOCAL_MANGA_DIRS = "local_manga_dirs"
|
||||||
const val KEY_DISABLE_NSFW = "no_nsfw"
|
const val KEY_DISABLE_NSFW = "no_nsfw"
|
||||||
const val KEY_RELATED_MANGA = "related_manga"
|
const val KEY_RELATED_MANGA = "related_manga"
|
||||||
const val KEY_FIRST_NAV_ITEM = "nav_first"
|
const val KEY_NAV_MAIN = "nav_main"
|
||||||
|
|
||||||
// About
|
// About
|
||||||
const val KEY_APP_UPDATE = "app_update"
|
const val KEY_APP_UPDATE = "app_update"
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package org.koitharu.kotatsu.core.prefs
|
||||||
|
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.annotation.IdRes
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
|
||||||
|
enum class NavItem(
|
||||||
|
@IdRes val id: Int,
|
||||||
|
@StringRes val title: Int,
|
||||||
|
@DrawableRes val icon: Int,
|
||||||
|
) : ListModel {
|
||||||
|
|
||||||
|
HISTORY(R.id.nav_history, R.string.history, R.drawable.ic_history_selector),
|
||||||
|
FAVORITES(R.id.nav_favorites, R.string.favourites, R.drawable.ic_favourites_selector),
|
||||||
|
LOCAL(R.id.nav_local, R.string.on_device, R.drawable.ic_storage_selector),
|
||||||
|
EXPLORE(R.id.nav_explore, R.string.explore, R.drawable.ic_explore_selector),
|
||||||
|
SUGGESTIONS(R.id.nav_suggestions, R.string.suggestions, R.drawable.ic_suggestion_selector),
|
||||||
|
FEED(R.id.nav_feed, R.string.feed, R.drawable.ic_feed_selector),
|
||||||
|
BOOKMARKS(R.id.nav_bookmarks, R.string.bookmarks, R.drawable.ic_bookmark_selector),
|
||||||
|
;
|
||||||
|
|
||||||
|
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||||
|
return other is NavItem && ordinal == other.ordinal
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isAvailable(settings: AppSettings): Boolean = when (this) {
|
||||||
|
SUGGESTIONS -> settings.isSuggestionsEnabled
|
||||||
|
FEED -> settings.isTrackerEnabled
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,20 +5,19 @@ import android.os.Build
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
|
||||||
import androidx.core.view.WindowInsetsControllerCompat
|
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.ui.util.SystemUiController
|
||||||
|
|
||||||
abstract class BaseFullscreenActivity<B : ViewBinding> :
|
abstract class BaseFullscreenActivity<B : ViewBinding> :
|
||||||
BaseActivity<B>() {
|
BaseActivity<B>() {
|
||||||
|
|
||||||
private lateinit var insetsControllerCompat: WindowInsetsControllerCompat
|
protected lateinit var systemUiController: SystemUiController
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
with(window) {
|
with(window) {
|
||||||
insetsControllerCompat = WindowInsetsControllerCompat(this, decorView)
|
systemUiController = SystemUiController(this)
|
||||||
statusBarColor = Color.TRANSPARENT
|
statusBarColor = Color.TRANSPARENT
|
||||||
navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||||
ContextCompat.getColor(this@BaseFullscreenActivity, R.color.dim)
|
ContextCompat.getColor(this@BaseFullscreenActivity, R.color.dim)
|
||||||
@@ -30,15 +29,7 @@ abstract class BaseFullscreenActivity<B : ViewBinding> :
|
|||||||
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
insetsControllerCompat.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
// insetsControllerCompat.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
showSystemUI()
|
systemUiController.setSystemUiVisible(true)
|
||||||
}
|
|
||||||
|
|
||||||
protected fun hideSystemUI() {
|
|
||||||
insetsControllerCompat.hide(WindowInsetsCompat.Type.systemBars())
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun showSystemUI() {
|
|
||||||
insetsControllerCompat.show(WindowInsetsCompat.Type.systemBars())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.withStyledAttributes
|
import androidx.core.content.withStyledAttributes
|
||||||
import androidx.core.view.GravityCompat
|
import androidx.core.view.GravityCompat
|
||||||
|
import androidx.core.view.ancestors
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
||||||
import org.koitharu.kotatsu.core.util.ext.isLayoutReversed
|
import org.koitharu.kotatsu.core.util.ext.isLayoutReversed
|
||||||
import org.koitharu.kotatsu.core.util.ext.parents
|
|
||||||
import org.koitharu.kotatsu.databinding.FastScrollerBinding
|
import org.koitharu.kotatsu.databinding.FastScrollerBinding
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import com.google.android.material.R as materialR
|
import com.google.android.material.R as materialR
|
||||||
@@ -522,7 +522,7 @@ class FastScroller @JvmOverloads constructor(
|
|||||||
return BubbleSize.entries.getOrNull(ordinal) ?: defaultValue
|
return BubbleSize.entries.getOrNull(ordinal) ?: defaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findValidParent(view: View): ViewGroup? = view.parents.firstNotNullOfOrNull { p ->
|
private fun findValidParent(view: View): ViewGroup? = view.ancestors.firstNotNullOfOrNull { p ->
|
||||||
if (p is FrameLayout || p is ConstraintLayout || p is CoordinatorLayout || p is RelativeLayout) {
|
if (p is FrameLayout || p is ConstraintLayout || p is CoordinatorLayout || p is RelativeLayout) {
|
||||||
p as ViewGroup
|
p as ViewGroup
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ sealed class AdaptiveSheetBehavior {
|
|||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
const val STATE_EXPANDED = SideSheetBehavior.STATE_EXPANDED
|
const val STATE_EXPANDED = SideSheetBehavior.STATE_EXPANDED
|
||||||
|
const val STATE_COLLAPSED = BottomSheetBehavior.STATE_COLLAPSED
|
||||||
const val STATE_SETTLING = SideSheetBehavior.STATE_SETTLING
|
const val STATE_SETTLING = SideSheetBehavior.STATE_SETTLING
|
||||||
const val STATE_DRAGGING = SideSheetBehavior.STATE_DRAGGING
|
const val STATE_DRAGGING = SideSheetBehavior.STATE_DRAGGING
|
||||||
const val STATE_HIDDEN = SideSheetBehavior.STATE_HIDDEN
|
const val STATE_HIDDEN = SideSheetBehavior.STATE_HIDDEN
|
||||||
@@ -114,10 +115,11 @@ sealed class AdaptiveSheetBehavior {
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun from(lp: CoordinatorLayout.LayoutParams): AdaptiveSheetBehavior? = when (val behavior = lp.behavior) {
|
fun from(lp: CoordinatorLayout.LayoutParams): AdaptiveSheetBehavior? =
|
||||||
is BottomSheetBehavior<*> -> Bottom(behavior)
|
when (val behavior = lp.behavior) {
|
||||||
is SideSheetBehavior<*> -> Side(behavior)
|
is BottomSheetBehavior<*> -> Bottom(behavior)
|
||||||
else -> null
|
is SideSheetBehavior<*> -> Side(behavior)
|
||||||
}
|
else -> null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,19 @@ package org.koitharu.kotatsu.core.ui.sheet
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
|
import android.view.InputDevice
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import androidx.core.content.withStyledAttributes
|
import androidx.core.content.withStyledAttributes
|
||||||
|
import androidx.core.view.ancestors
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.util.ext.parents
|
|
||||||
import org.koitharu.kotatsu.databinding.LayoutSheetHeaderAdaptiveBinding
|
import org.koitharu.kotatsu.databinding.LayoutSheetHeaderAdaptiveBinding
|
||||||
|
|
||||||
class AdaptiveSheetHeaderBar @JvmOverloads constructor(
|
class AdaptiveSheetHeaderBar @JvmOverloads constructor(
|
||||||
@@ -21,7 +23,8 @@ class AdaptiveSheetHeaderBar @JvmOverloads constructor(
|
|||||||
@AttrRes defStyleAttr: Int = 0,
|
@AttrRes defStyleAttr: Int = 0,
|
||||||
) : LinearLayout(context, attrs, defStyleAttr), AdaptiveSheetCallback {
|
) : LinearLayout(context, attrs, defStyleAttr), AdaptiveSheetCallback {
|
||||||
|
|
||||||
private val binding = LayoutSheetHeaderAdaptiveBinding.inflate(LayoutInflater.from(context), this)
|
private val binding =
|
||||||
|
LayoutSheetHeaderAdaptiveBinding.inflate(LayoutInflater.from(context), this)
|
||||||
private var sheetBehavior: AdaptiveSheetBehavior? = null
|
private var sheetBehavior: AdaptiveSheetBehavior? = null
|
||||||
|
|
||||||
var title: CharSequence?
|
var title: CharSequence?
|
||||||
@@ -60,6 +63,28 @@ class AdaptiveSheetHeaderBar @JvmOverloads constructor(
|
|||||||
super.onDetachedFromWindow()
|
super.onDetachedFromWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onGenericMotionEvent(event: MotionEvent): Boolean {
|
||||||
|
val behavior = sheetBehavior ?: return super.onGenericMotionEvent(event)
|
||||||
|
if (event.source and InputDevice.SOURCE_CLASS_POINTER != 0) {
|
||||||
|
if (event.actionMasked == MotionEvent.ACTION_SCROLL) {
|
||||||
|
if (event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0f) {
|
||||||
|
behavior.state = if (
|
||||||
|
behavior is AdaptiveSheetBehavior.Bottom
|
||||||
|
&& behavior.state == AdaptiveSheetBehavior.STATE_EXPANDED
|
||||||
|
) {
|
||||||
|
AdaptiveSheetBehavior.STATE_COLLAPSED
|
||||||
|
} else {
|
||||||
|
AdaptiveSheetBehavior.STATE_HIDDEN
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
behavior.state = AdaptiveSheetBehavior.STATE_EXPANDED
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.onGenericMotionEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStateChanged(sheet: View, newState: Int) {
|
override fun onStateChanged(sheet: View, newState: Int) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -81,14 +106,9 @@ class AdaptiveSheetHeaderBar @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun findParentSheetBehavior(): AdaptiveSheetBehavior? {
|
private fun findParentSheetBehavior(): AdaptiveSheetBehavior? {
|
||||||
for (p in parents) {
|
return ancestors.firstNotNullOfOrNull {
|
||||||
val layoutParams = (p as? View)?.layoutParams
|
((it as? View)?.layoutParams as? CoordinatorLayout.LayoutParams)
|
||||||
if (layoutParams is CoordinatorLayout.LayoutParams) {
|
?.let { params -> AdaptiveSheetBehavior.from(params) }
|
||||||
AdaptiveSheetBehavior.from(layoutParams)?.let {
|
|
||||||
return it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package org.koitharu.kotatsu.core.ui.util
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import android.view.View
|
||||||
|
import android.view.Window
|
||||||
|
import android.view.WindowInsets
|
||||||
|
import android.view.WindowInsetsController
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
|
|
||||||
|
sealed class SystemUiController(
|
||||||
|
protected val window: Window,
|
||||||
|
) {
|
||||||
|
|
||||||
|
abstract fun setSystemUiVisible(value: Boolean)
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.S)
|
||||||
|
private class Api30Impl(window: Window) : SystemUiController(window) {
|
||||||
|
|
||||||
|
private val insetsController = checkNotNull(window.decorView.windowInsetsController)
|
||||||
|
|
||||||
|
override fun setSystemUiVisible(value: Boolean) {
|
||||||
|
if (value) {
|
||||||
|
insetsController.show(WindowInsets.Type.systemBars())
|
||||||
|
insetsController.systemBarsBehavior = WindowInsetsController.BEHAVIOR_DEFAULT
|
||||||
|
} else {
|
||||||
|
insetsController.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
|
insetsController.hide(WindowInsets.Type.systemBars())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
private class LegacyImpl(window: Window) : SystemUiController(window) {
|
||||||
|
|
||||||
|
override fun setSystemUiVisible(value: Boolean) {
|
||||||
|
window.decorView.systemUiVisibility = if (value) {
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
|
} else {
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
|
||||||
|
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
|
||||||
|
View.SYSTEM_UI_FLAG_FULLSCREEN or
|
||||||
|
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
operator fun invoke(window: Window): SystemUiController =
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
Api30Impl(window)
|
||||||
|
} else {
|
||||||
|
LegacyImpl(window)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import android.content.Context
|
|||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import androidx.viewpager.widget.ViewPager
|
import androidx.viewpager.widget.ViewPager
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
class EnhancedViewPager @JvmOverloads constructor(
|
class EnhancedViewPager @JvmOverloads constructor(
|
||||||
@@ -25,6 +26,11 @@ class EnhancedViewPager @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
||||||
return isUserInputEnabled && super.onInterceptTouchEvent(event)
|
return try {
|
||||||
|
isUserInputEnabled && super.onInterceptTouchEvent(event)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
e.printStackTraceDebug()
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.koitharu.kotatsu.core.ui.widgets
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.databinding.ViewZoomBinding
|
||||||
|
|
||||||
|
class ZoomControl @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
) : LinearLayout(context, attrs), View.OnClickListener {
|
||||||
|
|
||||||
|
private val binding = ViewZoomBinding.inflate(LayoutInflater.from(context), this)
|
||||||
|
|
||||||
|
var listener: ZoomControlListener? = null
|
||||||
|
|
||||||
|
init {
|
||||||
|
binding.buttonZoomIn.setOnClickListener(this)
|
||||||
|
binding.buttonZoomOut.setOnClickListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick(v: View) {
|
||||||
|
when (v.id) {
|
||||||
|
R.id.button_zoom_in -> listener?.onZoomIn()
|
||||||
|
R.id.button_zoom_out -> listener?.onZoomOut()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ZoomControlListener {
|
||||||
|
|
||||||
|
fun onZoomIn()
|
||||||
|
|
||||||
|
fun onZoomOut()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,8 +16,10 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.core.fs.FileSequence
|
import org.koitharu.kotatsu.core.fs.FileSequence
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileFilter
|
import java.io.FileFilter
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
|
import kotlin.io.path.readAttributes
|
||||||
|
|
||||||
fun File.subdir(name: String) = File(this, name).also {
|
fun File.subdir(name: String) = File(this, name).also {
|
||||||
if (!it.exists()) it.mkdirs()
|
if (!it.exists()) it.mkdirs()
|
||||||
@@ -99,3 +101,10 @@ private suspend fun SequenceScope<File>.listFilesRecursiveImpl(root: File, filte
|
|||||||
fun File.children() = FileSequence(this)
|
fun File.children() = FileSequence(this)
|
||||||
|
|
||||||
fun Sequence<File>.filterWith(filter: FileFilter): Sequence<File> = filter { f -> filter.accept(f) }
|
fun Sequence<File>.filterWith(filter: FileFilter): Sequence<File> = filter { f -> filter.accept(f) }
|
||||||
|
|
||||||
|
val File.creationTime
|
||||||
|
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
toPath().readAttributes<BasicFileAttributes>().creationTime().toMillis()
|
||||||
|
} else {
|
||||||
|
lastModified()
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import kotlinx.coroutines.delay
|
|||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onCompletion
|
import kotlinx.coroutines.flow.onCompletion
|
||||||
@@ -72,7 +74,7 @@ fun <T1, T2, T3, T4, T5, T6, R> combine(
|
|||||||
flow4: Flow<T4>,
|
flow4: Flow<T4>,
|
||||||
flow5: Flow<T5>,
|
flow5: Flow<T5>,
|
||||||
flow6: Flow<T6>,
|
flow6: Flow<T6>,
|
||||||
transform: suspend (T1, T2, T3, T4, T5, T6) -> R
|
transform: suspend (T1, T2, T3, T4, T5, T6) -> R,
|
||||||
): Flow<R> = combine(flow, flow2, flow3, flow4, flow5, flow6) { args: Array<*> ->
|
): Flow<R> = combine(flow, flow2, flow3, flow4, flow5, flow6) { args: Array<*> ->
|
||||||
transform(
|
transform(
|
||||||
args[0] as T1,
|
args[0] as T1,
|
||||||
@@ -83,3 +85,7 @@ fun <T1, T2, T3, T4, T5, T6, R> combine(
|
|||||||
args[5] as T6,
|
args[5] as T6,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun <T : Any> Flow<T?>.firstNotNull(): T = checkNotNull(first { x -> x != null })
|
||||||
|
|
||||||
|
suspend fun <T : Any> Flow<T?>.firstNotNullOrNull(): T? = firstOrNull { x -> x != null }
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import java.net.SocketTimeoutException
|
|||||||
import java.net.UnknownHostException
|
import java.net.UnknownHostException
|
||||||
|
|
||||||
private const val MSG_NO_SPACE_LEFT = "No space left on device"
|
private const val MSG_NO_SPACE_LEFT = "No space left on device"
|
||||||
|
private const val IMAGE_FORMAT_NO_SUPPORTED = "Image format not supported"
|
||||||
|
|
||||||
fun Throwable.getDisplayMessage(resources: Resources): String = when (this) {
|
fun Throwable.getDisplayMessage(resources: Resources): String = when (this) {
|
||||||
is AuthRequiredException -> resources.getString(R.string.auth_required)
|
is AuthRequiredException -> resources.getString(R.string.auth_required)
|
||||||
@@ -81,6 +82,7 @@ private fun getHttpDisplayMessage(statusCode: Int, resources: Resources): String
|
|||||||
private fun getDisplayMessage(msg: String?, resources: Resources): String? = when {
|
private fun getDisplayMessage(msg: String?, resources: Resources): String? = when {
|
||||||
msg.isNullOrEmpty() -> null
|
msg.isNullOrEmpty() -> null
|
||||||
msg.contains(MSG_NO_SPACE_LEFT) -> resources.getString(R.string.error_no_space_left)
|
msg.contains(MSG_NO_SPACE_LEFT) -> resources.getString(R.string.error_no_space_left)
|
||||||
|
msg.contains(IMAGE_FORMAT_NO_SUPPORTED) -> resources.getString(R.string.error_corrupted_file)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,18 @@ package org.koitharu.kotatsu.core.util.ext
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
|
import android.os.Build
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.View.MeasureSpec
|
import android.view.View.MeasureSpec
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.ViewParent
|
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.Checkable
|
import android.widget.Checkable
|
||||||
import android.widget.CompoundButton
|
|
||||||
import androidx.core.view.children
|
import androidx.core.view.children
|
||||||
|
import androidx.core.view.descendants
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.viewpager2.widget.ViewPager2
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
|
import com.google.android.material.progressindicator.BaseProgressIndicator
|
||||||
import com.google.android.material.slider.Slider
|
import com.google.android.material.slider.Slider
|
||||||
import com.google.android.material.tabs.TabLayout
|
import com.google.android.material.tabs.TabLayout
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
@@ -88,23 +90,8 @@ fun Slider.setValueRounded(newValue: Float) {
|
|||||||
value = roundedValue.coerceIn(valueFrom, valueTo)
|
value = roundedValue.coerceIn(valueFrom, valueTo)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : View> ViewGroup.findViewsByType(clazz: Class<T>): Sequence<T> {
|
|
||||||
if (childCount == 0) {
|
|
||||||
return emptySequence()
|
|
||||||
}
|
|
||||||
return sequence {
|
|
||||||
for (view in children) {
|
|
||||||
if (clazz.isInstance(view)) {
|
|
||||||
yield(clazz.cast(view)!!)
|
|
||||||
} else if (view is ViewGroup && view.childCount != 0) {
|
|
||||||
yieldAll(view.findViewsByType(clazz))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun RecyclerView.invalidateNestedItemDecorations() {
|
fun RecyclerView.invalidateNestedItemDecorations() {
|
||||||
findViewsByType(RecyclerView::class.java).forEach {
|
descendants.filterIsInstance<RecyclerView>().forEach {
|
||||||
it.invalidateItemDecorations()
|
it.invalidateItemDecorations()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,15 +99,6 @@ fun RecyclerView.invalidateNestedItemDecorations() {
|
|||||||
val View.parentView: ViewGroup?
|
val View.parentView: ViewGroup?
|
||||||
get() = parent as? ViewGroup
|
get() = parent as? ViewGroup
|
||||||
|
|
||||||
val View.parents: Sequence<ViewParent>
|
|
||||||
get() = sequence {
|
|
||||||
var p: ViewParent? = parent
|
|
||||||
while (p != null) {
|
|
||||||
yield(p)
|
|
||||||
p = p.parent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun View.measureDimension(desiredSize: Int, measureSpec: Int): Int {
|
fun View.measureDimension(desiredSize: Int, measureSpec: Int): Int {
|
||||||
var result: Int
|
var result: Int
|
||||||
val specMode = MeasureSpec.getMode(measureSpec)
|
val specMode = MeasureSpec.getMode(measureSpec)
|
||||||
@@ -155,3 +133,17 @@ fun TabLayout.setTabsEnabled(enabled: Boolean) {
|
|||||||
getTabAt(i)?.view?.isEnabled = enabled
|
getTabAt(i)?.view?.isEnabled = enabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun BaseProgressIndicator<*>.showOrHide(value: Boolean) {
|
||||||
|
if (value) {
|
||||||
|
if (!isVisible) show()
|
||||||
|
} else {
|
||||||
|
if (isVisible) hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun View.setOnContextClickListenerCompat(listener: View.OnLongClickListener) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
setOnContextClickListener(listener::onLongClick)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package org.koitharu.kotatsu.details.domain
|
package org.koitharu.kotatsu.details.domain
|
||||||
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import org.koitharu.kotatsu.core.model.isLocal
|
import org.koitharu.kotatsu.core.model.isLocal
|
||||||
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
||||||
import org.koitharu.kotatsu.core.parser.MangaIntent
|
import org.koitharu.kotatsu.core.parser.MangaIntent
|
||||||
@@ -23,24 +26,28 @@ class DoubleMangaLoadUseCase @Inject constructor(
|
|||||||
private val recoverUseCase: RecoverMangaUseCase,
|
private val recoverUseCase: RecoverMangaUseCase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend operator fun invoke(manga: Manga): DoubleManga = coroutineScope {
|
operator fun invoke(manga: Manga): Flow<DoubleManga> = flow {
|
||||||
val remoteDeferred = async(Dispatchers.Default) { loadRemote(manga) }
|
var lastValue: DoubleManga? = null
|
||||||
val localDeferred = async(Dispatchers.Default) { loadLocal(manga) }
|
var emitted = false
|
||||||
DoubleManga(
|
invokeImpl(manga).collect {
|
||||||
remoteManga = remoteDeferred.await(),
|
lastValue = it
|
||||||
localManga = localDeferred.await(),
|
if (it.any != null) {
|
||||||
)
|
emitted = true
|
||||||
}
|
emit(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!emitted) {
|
||||||
|
lastValue?.requireAny()
|
||||||
|
}
|
||||||
|
}.flowOn(Dispatchers.Default)
|
||||||
|
|
||||||
suspend operator fun invoke(mangaId: Long): DoubleManga {
|
operator fun invoke(mangaId: Long): Flow<DoubleManga> = flow {
|
||||||
val manga = mangaDataRepository.findMangaById(mangaId) ?: throwNFE()
|
emit(mangaDataRepository.findMangaById(mangaId) ?: throwNFE())
|
||||||
return invoke(manga)
|
}.flatMapLatest { invoke(it) }
|
||||||
}
|
|
||||||
|
|
||||||
suspend operator fun invoke(intent: MangaIntent): DoubleManga {
|
operator fun invoke(intent: MangaIntent): Flow<DoubleManga> = flow {
|
||||||
val manga = mangaDataRepository.resolveIntent(intent) ?: throwNFE()
|
emit(mangaDataRepository.resolveIntent(intent) ?: throwNFE())
|
||||||
return invoke(manga)
|
}.flatMapLatest { invoke(it) }
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun loadLocal(manga: Manga): Result<Manga>? {
|
private suspend fun loadLocal(manga: Manga): Result<Manga>? {
|
||||||
return runCatchingCancellable {
|
return runCatchingCancellable {
|
||||||
@@ -70,5 +77,15 @@ class DoubleMangaLoadUseCase @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun invokeImpl(manga: Manga): Flow<DoubleManga> = combine(
|
||||||
|
flow { emit(null); emit(loadRemote(manga)) },
|
||||||
|
flow { emit(null); emit(loadLocal(manga)) },
|
||||||
|
) { remote, local ->
|
||||||
|
DoubleManga(
|
||||||
|
remoteManga = remote,
|
||||||
|
localManga = local,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun throwNFE(): Nothing = throw NotFoundException("Cannot find manga", "")
|
private fun throwNFE(): Nothing = throw NotFoundException("Cannot find manga", "")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.details.domain.model
|
package org.koitharu.kotatsu.details.domain.model
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.core.model.findById
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
@@ -34,6 +35,10 @@ data class DoubleManga(
|
|||||||
mergeChapters()
|
mergeChapters()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hasChapter(id: Long): Boolean {
|
||||||
|
return local?.chapters?.findById(id) != null || remote?.chapters?.findById(id) != null
|
||||||
|
}
|
||||||
|
|
||||||
fun requireAny(): Manga {
|
fun requireAny(): Manga {
|
||||||
val result = remoteManga?.getOrNull() ?: localManga?.getOrNull()
|
val result = remoteManga?.getOrNull() ?: localManga?.getOrNull()
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import android.content.Intent
|
|||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import dagger.hilt.android.EntryPointAccessors
|
import dagger.hilt.android.EntryPointAccessors
|
||||||
import org.koitharu.kotatsu.core.cache.ContentCache
|
import org.koitharu.kotatsu.core.cache.ContentCache
|
||||||
|
import org.koitharu.kotatsu.core.model.findById
|
||||||
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableChapter
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableMangaChapters
|
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.core.ui.CoroutineIntentService
|
import org.koitharu.kotatsu.core.ui.CoroutineIntentService
|
||||||
import org.koitharu.kotatsu.core.util.ext.getParcelableExtraCompat
|
import org.koitharu.kotatsu.core.util.ext.getParcelableExtraCompat
|
||||||
@@ -34,12 +35,13 @@ class MangaPrefetchService : CoroutineIntentService() {
|
|||||||
override suspend fun processIntent(startId: Int, intent: Intent) {
|
override suspend fun processIntent(startId: Int, intent: Intent) {
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
ACTION_PREFETCH_DETAILS -> prefetchDetails(
|
ACTION_PREFETCH_DETAILS -> prefetchDetails(
|
||||||
manga = intent.getParcelableExtraCompat<ParcelableManga>(EXTRA_MANGA)?.manga ?: return,
|
manga = intent.getParcelableExtraCompat<ParcelableManga>(EXTRA_MANGA)?.manga
|
||||||
|
?: return,
|
||||||
)
|
)
|
||||||
|
|
||||||
ACTION_PREFETCH_PAGES -> prefetchPages(
|
ACTION_PREFETCH_PAGES -> prefetchPages(
|
||||||
chapter = intent.getParcelableExtraCompat<ParcelableMangaChapters>(EXTRA_CHAPTER)
|
chapter = intent.getParcelableExtraCompat<ParcelableChapter>(EXTRA_CHAPTER)?.chapter
|
||||||
?.chapters?.singleOrNull() ?: return,
|
?: return,
|
||||||
)
|
)
|
||||||
|
|
||||||
ACTION_PREFETCH_LAST -> prefetchLast()
|
ACTION_PREFETCH_LAST -> prefetchLast()
|
||||||
@@ -71,7 +73,7 @@ class MangaPrefetchService : CoroutineIntentService() {
|
|||||||
val chapter = if (history == null) {
|
val chapter = if (history == null) {
|
||||||
chapters.firstOrNull()
|
chapters.firstOrNull()
|
||||||
} else {
|
} else {
|
||||||
chapters.find { x -> x.id == history.chapterId } ?: chapters.firstOrNull()
|
chapters.findById(history.chapterId) ?: chapters.firstOrNull()
|
||||||
} ?: return
|
} ?: return
|
||||||
runCatchingCancellable { repo.getPages(chapter) }
|
runCatchingCancellable { repo.getPages(chapter) }
|
||||||
}
|
}
|
||||||
@@ -88,7 +90,7 @@ class MangaPrefetchService : CoroutineIntentService() {
|
|||||||
if (!isPrefetchAvailable(context, manga.source)) return
|
if (!isPrefetchAvailable(context, manga.source)) return
|
||||||
val intent = Intent(context, MangaPrefetchService::class.java)
|
val intent = Intent(context, MangaPrefetchService::class.java)
|
||||||
intent.action = ACTION_PREFETCH_DETAILS
|
intent.action = ACTION_PREFETCH_DETAILS
|
||||||
intent.putExtra(EXTRA_MANGA, ParcelableManga(manga, withChapters = false))
|
intent.putExtra(EXTRA_MANGA, ParcelableManga(manga))
|
||||||
context.startService(intent)
|
context.startService(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +98,7 @@ class MangaPrefetchService : CoroutineIntentService() {
|
|||||||
if (!isPrefetchAvailable(context, chapter.source)) return
|
if (!isPrefetchAvailable(context, chapter.source)) return
|
||||||
val intent = Intent(context, MangaPrefetchService::class.java)
|
val intent = Intent(context, MangaPrefetchService::class.java)
|
||||||
intent.action = ACTION_PREFETCH_PAGES
|
intent.action = ACTION_PREFETCH_PAGES
|
||||||
intent.putExtra(EXTRA_CHAPTER, ParcelableMangaChapters(listOf(chapter)))
|
intent.putExtra(EXTRA_CHAPTER, ParcelableChapter(chapter))
|
||||||
try {
|
try {
|
||||||
context.startService(intent)
|
context.startService(intent)
|
||||||
} catch (e: IllegalStateException) {
|
} catch (e: IllegalStateException) {
|
||||||
@@ -119,7 +121,10 @@ class MangaPrefetchService : CoroutineIntentService() {
|
|||||||
if (context.isPowerSaveMode()) {
|
if (context.isPowerSaveMode()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
val entryPoint = EntryPointAccessors.fromApplication(context, PrefetchCompanionEntryPoint::class.java)
|
val entryPoint = EntryPointAccessors.fromApplication(
|
||||||
|
context,
|
||||||
|
PrefetchCompanionEntryPoint::class.java,
|
||||||
|
)
|
||||||
return entryPoint.contentCache.isCachingEnabled && entryPoint.settings.isContentPrefetchEnabled
|
return entryPoint.contentCache.isCachingEnabled && entryPoint.settings.isContentPrefetchEnabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.details.ui
|
package org.koitharu.kotatsu.details.ui
|
||||||
|
|
||||||
|
import android.view.InputDevice
|
||||||
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.View.OnLayoutChangeListener
|
import android.view.View.OnLayoutChangeListener
|
||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
@@ -12,7 +14,7 @@ class ChaptersBottomSheetMediator(
|
|||||||
private val behavior: BottomSheetBehavior<*>,
|
private val behavior: BottomSheetBehavior<*>,
|
||||||
) : OnBackPressedCallback(false),
|
) : OnBackPressedCallback(false),
|
||||||
ActionModeListener,
|
ActionModeListener,
|
||||||
OnLayoutChangeListener {
|
OnLayoutChangeListener, View.OnGenericMotionListener {
|
||||||
|
|
||||||
private var lockCounter = 0
|
private var lockCounter = 0
|
||||||
|
|
||||||
@@ -55,6 +57,20 @@ class ChaptersBottomSheetMediator(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onGenericMotion(v: View?, event: MotionEvent): Boolean {
|
||||||
|
if (event.source and InputDevice.SOURCE_CLASS_POINTER != 0) {
|
||||||
|
if (event.actionMasked == MotionEvent.ACTION_SCROLL) {
|
||||||
|
if (event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0f) {
|
||||||
|
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||||
|
} else {
|
||||||
|
behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
fun lock() {
|
fun lock() {
|
||||||
lockCounter++
|
lockCounter++
|
||||||
behavior.isDraggable = lockCounter <= 0
|
behavior.isDraggable = lockCounter <= 0
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import org.koitharu.kotatsu.core.util.ext.observe
|
|||||||
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
||||||
import org.koitharu.kotatsu.core.util.ext.setNavigationBarTransparentCompat
|
import org.koitharu.kotatsu.core.util.ext.setNavigationBarTransparentCompat
|
||||||
import org.koitharu.kotatsu.core.util.ext.setNavigationIconSafe
|
import org.koitharu.kotatsu.core.util.ext.setNavigationIconSafe
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.setOnContextClickListenerCompat
|
||||||
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
||||||
import org.koitharu.kotatsu.databinding.ActivityDetailsBinding
|
import org.koitharu.kotatsu.databinding.ActivityDetailsBinding
|
||||||
import org.koitharu.kotatsu.details.service.MangaPrefetchService
|
import org.koitharu.kotatsu.details.service.MangaPrefetchService
|
||||||
@@ -89,6 +90,7 @@ class DetailsActivity :
|
|||||||
}
|
}
|
||||||
viewBinding.buttonRead.setOnClickListener(this)
|
viewBinding.buttonRead.setOnClickListener(this)
|
||||||
viewBinding.buttonRead.setOnLongClickListener(this)
|
viewBinding.buttonRead.setOnLongClickListener(this)
|
||||||
|
viewBinding.buttonRead.setOnContextClickListenerCompat(this)
|
||||||
viewBinding.buttonDropdown.setOnClickListener(this)
|
viewBinding.buttonDropdown.setOnClickListener(this)
|
||||||
viewBadge = ViewBadge(viewBinding.buttonRead, this)
|
viewBadge = ViewBadge(viewBinding.buttonRead, this)
|
||||||
|
|
||||||
@@ -103,6 +105,7 @@ class DetailsActivity :
|
|||||||
viewBinding.toolbarChapters?.setNavigationOnClickListener {
|
viewBinding.toolbarChapters?.setNavigationOnClickListener {
|
||||||
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||||
}
|
}
|
||||||
|
viewBinding.toolbarChapters?.setOnGenericMotionListener(bsMediator)
|
||||||
} else {
|
} else {
|
||||||
chaptersMenuProvider = ChaptersMenuProvider(viewModel, null)
|
chaptersMenuProvider = ChaptersMenuProvider(viewModel, null)
|
||||||
addMenuProvider(chaptersMenuProvider)
|
addMenuProvider(chaptersMenuProvider)
|
||||||
@@ -134,13 +137,19 @@ class DetailsActivity :
|
|||||||
viewBinding.toolbarChapters?.subtitle = it
|
viewBinding.toolbarChapters?.subtitle = it
|
||||||
viewBinding.textViewSubtitle?.textAndVisible = it
|
viewBinding.textViewSubtitle?.textAndVisible = it
|
||||||
}
|
}
|
||||||
viewModel.isChaptersReversed.observe(this, MenuInvalidator(viewBinding.toolbarChapters ?: this))
|
viewModel.isChaptersReversed.observe(
|
||||||
|
this,
|
||||||
|
MenuInvalidator(viewBinding.toolbarChapters ?: this)
|
||||||
|
)
|
||||||
viewModel.favouriteCategories.observe(this, MenuInvalidator(this))
|
viewModel.favouriteCategories.observe(this, MenuInvalidator(this))
|
||||||
viewModel.branches.observe(this) {
|
viewModel.branches.observe(this) {
|
||||||
viewBinding.buttonDropdown.isVisible = it.size > 1
|
viewBinding.buttonDropdown.isVisible = it.size > 1
|
||||||
}
|
}
|
||||||
viewModel.chapters.observe(this, PrefetchObserver(this))
|
viewModel.chapters.observe(this, PrefetchObserver(this))
|
||||||
viewModel.onDownloadStarted.observeEvent(this, DownloadStartedObserver(viewBinding.containerDetails))
|
viewModel.onDownloadStarted.observeEvent(
|
||||||
|
this,
|
||||||
|
DownloadStartedObserver(viewBinding.containerDetails)
|
||||||
|
)
|
||||||
|
|
||||||
addMenuProvider(
|
addMenuProvider(
|
||||||
DetailsMenuProvider(
|
DetailsMenuProvider(
|
||||||
@@ -243,7 +252,11 @@ class DetailsActivity :
|
|||||||
right = insets.right,
|
right = insets.right,
|
||||||
)
|
)
|
||||||
if (insets.bottom > 0) {
|
if (insets.bottom > 0) {
|
||||||
window.setNavigationBarTransparentCompat(this, viewBinding.layoutBottom?.elevation ?: 0f, 0.9f)
|
window.setNavigationBarTransparentCompat(
|
||||||
|
this,
|
||||||
|
viewBinding.layoutBottom?.elevation ?: 0f,
|
||||||
|
0.9f
|
||||||
|
)
|
||||||
}
|
}
|
||||||
viewBinding.cardChapters?.updateLayoutParams<MarginLayoutParams> {
|
viewBinding.cardChapters?.updateLayoutParams<MarginLayoutParams> {
|
||||||
bottomMargin = insets.bottom + marginEnd
|
bottomMargin = insets.bottom + marginEnd
|
||||||
@@ -265,9 +278,18 @@ class DetailsActivity :
|
|||||||
}
|
}
|
||||||
val text = when {
|
val text = when {
|
||||||
!info.isValid -> getString(R.string.loading_)
|
!info.isValid -> getString(R.string.loading_)
|
||||||
info.currentChapter >= 0 -> getString(R.string.chapter_d_of_d, info.currentChapter + 1, info.totalChapters)
|
info.currentChapter >= 0 -> getString(
|
||||||
|
R.string.chapter_d_of_d,
|
||||||
|
info.currentChapter + 1,
|
||||||
|
info.totalChapters
|
||||||
|
)
|
||||||
|
|
||||||
info.totalChapters == 0 -> getString(R.string.no_chapters)
|
info.totalChapters == 0 -> getString(R.string.no_chapters)
|
||||||
else -> resources.getQuantityString(R.plurals.chapters, info.totalChapters, info.totalChapters)
|
else -> resources.getQuantityString(
|
||||||
|
R.plurals.chapters,
|
||||||
|
info.totalChapters,
|
||||||
|
info.totalChapters
|
||||||
|
)
|
||||||
}
|
}
|
||||||
viewBinding.toolbarChapters?.title = text
|
viewBinding.toolbarChapters?.title = text
|
||||||
viewBinding.textViewTitle?.text = text
|
viewBinding.textViewTitle?.text = text
|
||||||
@@ -286,7 +308,12 @@ class DetailsActivity :
|
|||||||
append(' ')
|
append(' ')
|
||||||
append(' ')
|
append(' ')
|
||||||
inSpans(
|
inSpans(
|
||||||
ForegroundColorSpan(v.context.getThemeColor(android.R.attr.textColorSecondary, Color.LTGRAY)),
|
ForegroundColorSpan(
|
||||||
|
v.context.getThemeColor(
|
||||||
|
android.R.attr.textColorSecondary,
|
||||||
|
Color.LTGRAY
|
||||||
|
)
|
||||||
|
),
|
||||||
RelativeSizeSpan(0.74f),
|
RelativeSizeSpan(0.74f),
|
||||||
) {
|
) {
|
||||||
append(branch.count.toString())
|
append(branch.count.toString())
|
||||||
@@ -305,7 +332,8 @@ class DetailsActivity :
|
|||||||
val manga = viewModel.manga.value ?: return
|
val manga = viewModel.manga.value ?: return
|
||||||
val chapterId = viewModel.historyInfo.value.history?.chapterId
|
val chapterId = viewModel.historyInfo.value.history?.chapterId
|
||||||
if (chapterId != null && manga.chapters?.none { x -> x.id == chapterId } == true) {
|
if (chapterId != null && manga.chapters?.none { x -> x.id == chapterId } == true) {
|
||||||
val snackbar = makeSnackbar(getString(R.string.chapter_is_missing), Snackbar.LENGTH_SHORT)
|
val snackbar =
|
||||||
|
makeSnackbar(getString(R.string.chapter_is_missing), Snackbar.LENGTH_SHORT)
|
||||||
snackbar.show()
|
snackbar.show()
|
||||||
} else {
|
} else {
|
||||||
startActivity(
|
startActivity(
|
||||||
@@ -331,7 +359,10 @@ class DetailsActivity :
|
|||||||
view.isVisible = isVisible
|
view.isVisible = isVisible
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun makeSnackbar(text: CharSequence, @BaseTransientBottomBar.Duration duration: Int): Snackbar {
|
private fun makeSnackbar(
|
||||||
|
text: CharSequence,
|
||||||
|
@BaseTransientBottomBar.Duration duration: Int,
|
||||||
|
): Snackbar {
|
||||||
val sb = Snackbar.make(viewBinding.containerDetails, text, duration)
|
val sb = Snackbar.make(viewBinding.containerDetails, text, duration)
|
||||||
if (viewBinding.layoutBottom?.isVisible == true) {
|
if (viewBinding.layoutBottom?.isVisible == true) {
|
||||||
sb.anchorView = viewBinding.toolbarChapters
|
sb.anchorView = viewBinding.toolbarChapters
|
||||||
@@ -369,7 +400,7 @@ class DetailsActivity :
|
|||||||
|
|
||||||
fun newIntent(context: Context, manga: Manga): Intent {
|
fun newIntent(context: Context, manga: Manga): Intent {
|
||||||
return Intent(context, DetailsActivity::class.java)
|
return Intent(context, DetailsActivity::class.java)
|
||||||
.putExtra(MangaIntent.KEY_MANGA, ParcelableManga(manga, withChapters = true))
|
.putExtra(MangaIntent.KEY_MANGA, ParcelableManga(manga))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun newIntent(context: Context, mangaId: Long): Intent {
|
fun newIntent(context: Context, mangaId: Long): Intent {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import org.koitharu.kotatsu.core.util.ext.observe
|
|||||||
import org.koitharu.kotatsu.core.util.ext.parentView
|
import org.koitharu.kotatsu.core.util.ext.parentView
|
||||||
import org.koitharu.kotatsu.core.util.ext.resolveDp
|
import org.koitharu.kotatsu.core.util.ext.resolveDp
|
||||||
import org.koitharu.kotatsu.core.util.ext.scaleUpActivityOptionsOf
|
import org.koitharu.kotatsu.core.util.ext.scaleUpActivityOptionsOf
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.showOrHide
|
||||||
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
||||||
import org.koitharu.kotatsu.databinding.FragmentDetailsBinding
|
import org.koitharu.kotatsu.databinding.FragmentDetailsBinding
|
||||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
||||||
@@ -247,11 +248,7 @@ class DetailsFragment :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onLoadingStateChanged(isLoading: Boolean) {
|
private fun onLoadingStateChanged(isLoading: Boolean) {
|
||||||
if (isLoading) {
|
requireViewBinding().progressBar.showOrHide(isLoading)
|
||||||
requireViewBinding().progressBar.show()
|
|
||||||
} else {
|
|
||||||
requireViewBinding().progressBar.hide()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onBookmarksChanged(bookmarks: List<Bookmark>) {
|
private fun onBookmarksChanged(bookmarks: List<Bookmark>) {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import org.koitharu.kotatsu.core.util.ext.MutableEventFlow
|
|||||||
import org.koitharu.kotatsu.core.util.ext.call
|
import org.koitharu.kotatsu.core.util.ext.call
|
||||||
import org.koitharu.kotatsu.core.util.ext.combine
|
import org.koitharu.kotatsu.core.util.ext.combine
|
||||||
import org.koitharu.kotatsu.core.util.ext.computeSize
|
import org.koitharu.kotatsu.core.util.ext.computeSize
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.onFirst
|
||||||
import org.koitharu.kotatsu.core.util.ext.requireValue
|
import org.koitharu.kotatsu.core.util.ext.requireValue
|
||||||
import org.koitharu.kotatsu.core.util.ext.sanitize
|
import org.koitharu.kotatsu.core.util.ext.sanitize
|
||||||
import org.koitharu.kotatsu.core.util.ext.toFileOrNull
|
import org.koitharu.kotatsu.core.util.ext.toFileOrNull
|
||||||
@@ -87,7 +88,8 @@ class DetailsViewModel @Inject constructor(
|
|||||||
|
|
||||||
private val intent = MangaIntent(savedStateHandle)
|
private val intent = MangaIntent(savedStateHandle)
|
||||||
private val mangaId = intent.mangaId
|
private val mangaId = intent.mangaId
|
||||||
private val doubleManga: MutableStateFlow<DoubleManga?> = MutableStateFlow(intent.manga?.let { DoubleManga(it) })
|
private val doubleManga: MutableStateFlow<DoubleManga?> =
|
||||||
|
MutableStateFlow(intent.manga?.let { DoubleManga(it) })
|
||||||
private var loadingJob: Job
|
private var loadingJob: Job
|
||||||
|
|
||||||
val onShowToast = MutableEventFlow<Int>()
|
val onShowToast = MutableEventFlow<Int>()
|
||||||
@@ -202,7 +204,14 @@ class DetailsViewModel @Inject constructor(
|
|||||||
bookmarks,
|
bookmarks,
|
||||||
networkState,
|
networkState,
|
||||||
) { manga, history, branch, news, bookmarks, isOnline ->
|
) { manga, history, branch, news, bookmarks, isOnline ->
|
||||||
mapChapters(manga?.remote?.takeIf { isOnline }, manga?.local, history, news, branch, bookmarks)
|
mapChapters(
|
||||||
|
manga?.remote?.takeIf { isOnline },
|
||||||
|
manga?.local,
|
||||||
|
history,
|
||||||
|
news,
|
||||||
|
branch,
|
||||||
|
bookmarks,
|
||||||
|
)
|
||||||
},
|
},
|
||||||
isChaptersReversed,
|
isChaptersReversed,
|
||||||
chaptersQuery,
|
chaptersQuery,
|
||||||
@@ -324,12 +333,15 @@ class DetailsViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun doLoad() = launchLoadingJob(Dispatchers.Default) {
|
private fun doLoad() = launchLoadingJob(Dispatchers.Default) {
|
||||||
val result = doubleMangaLoadUseCase(intent)
|
doubleMangaLoadUseCase.invoke(intent)
|
||||||
val manga = result.requireAny()
|
.onFirst {
|
||||||
// find default branch
|
val manga = it.requireAny()
|
||||||
val hist = historyRepository.getOne(manga)
|
// find default branch
|
||||||
selectedBranch.value = manga.getPreferredBranch(hist)
|
val hist = historyRepository.getOne(manga)
|
||||||
doubleManga.value = result
|
selectedBranch.value = manga.getPreferredBranch(hist)
|
||||||
|
}.collect {
|
||||||
|
doubleManga.value = it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun List<ChapterListItem>.filterSearch(query: String): List<ChapterListItem> {
|
private fun List<ChapterListItem>.filterSearch(query: String): List<ChapterListItem> {
|
||||||
|
|||||||
@@ -45,6 +45,6 @@ class RelatedMangaActivity : BaseActivity<ActivityContainerBinding>(), AppBarOwn
|
|||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun newIntent(context: Context, seed: Manga) = Intent(context, RelatedMangaActivity::class.java)
|
fun newIntent(context: Context, seed: Manga) = Intent(context, RelatedMangaActivity::class.java)
|
||||||
.putExtra(MangaIntent.KEY_MANGA, ParcelableManga(seed, withChapters = false))
|
.putExtra(MangaIntent.KEY_MANGA, ParcelableManga(seed))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.koitharu.kotatsu.explore.data
|
|||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import dagger.Reusable
|
import dagger.Reusable
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.flatMapLatest
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
@@ -11,12 +12,12 @@ import org.koitharu.kotatsu.core.db.MangaDatabase
|
|||||||
import org.koitharu.kotatsu.core.db.dao.MangaSourcesDao
|
import org.koitharu.kotatsu.core.db.dao.MangaSourcesDao
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaSourceEntity
|
import org.koitharu.kotatsu.core.db.entity.MangaSourceEntity
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.core.model.isNsfw
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||||
import org.koitharu.kotatsu.core.ui.util.ReversibleHandle
|
import org.koitharu.kotatsu.core.ui.util.ReversibleHandle
|
||||||
import org.koitharu.kotatsu.parsers.model.ContentType
|
import org.koitharu.kotatsu.parsers.model.ContentType
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.util.move
|
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import java.util.EnumSet
|
import java.util.EnumSet
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -76,14 +77,6 @@ class MangaSourcesRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun setSourcesEnabled(sources: Iterable<MangaSource>, isEnabled: Boolean) {
|
|
||||||
db.withTransaction {
|
|
||||||
for (s in sources) {
|
|
||||||
dao.setEnabled(s.name, isEnabled)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun disableAllSources() {
|
suspend fun disableAllSources() {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
assimilateNewSources()
|
assimilateNewSources()
|
||||||
@@ -99,46 +92,20 @@ class MangaSourcesRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun setPosition(source: MangaSource, index: Int) {
|
fun observeNewSources(): Flow<Set<MangaSource>> = combine(
|
||||||
db.withTransaction {
|
dao.observeAll(),
|
||||||
val all = dao.findAll().toMutableList()
|
observeIsNsfwDisabled(),
|
||||||
val sourceIndex = all.indexOfFirst { x -> x.source == source.name }
|
) { entities, skipNsfw ->
|
||||||
if (sourceIndex !in all.indices) {
|
|
||||||
val entity = MangaSourceEntity(
|
|
||||||
source = source.name,
|
|
||||||
isEnabled = false,
|
|
||||||
sortKey = index,
|
|
||||||
)
|
|
||||||
all.add(index, entity)
|
|
||||||
dao.upsert(entity)
|
|
||||||
} else {
|
|
||||||
all.move(sourceIndex, index)
|
|
||||||
}
|
|
||||||
for ((i, e) in all.withIndex()) {
|
|
||||||
if (e.sortKey != i) {
|
|
||||||
dao.setSortKey(e.source, i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun observeNewSources(): Flow<Set<MangaSource>> = dao.observeAll().map { entities ->
|
|
||||||
val result = EnumSet.copyOf(remoteSources)
|
val result = EnumSet.copyOf(remoteSources)
|
||||||
for (e in entities) {
|
for (e in entities) {
|
||||||
result.remove(MangaSource(e.source))
|
result.remove(MangaSource(e.source))
|
||||||
}
|
}
|
||||||
|
if (skipNsfw) {
|
||||||
|
result.removeAll { x -> x.isNsfw() }
|
||||||
|
}
|
||||||
result
|
result
|
||||||
}.distinctUntilChanged()
|
}.distinctUntilChanged()
|
||||||
|
|
||||||
suspend fun getNewSources(): Set<MangaSource> {
|
|
||||||
val entities = dao.findAll()
|
|
||||||
val result = EnumSet.copyOf(remoteSources)
|
|
||||||
for (e in entities) {
|
|
||||||
result.remove(MangaSource(e.source))
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun assimilateNewSources(): Set<MangaSource> {
|
suspend fun assimilateNewSources(): Set<MangaSource> {
|
||||||
val new = getNewSources()
|
val new = getNewSources()
|
||||||
if (new.isEmpty()) {
|
if (new.isEmpty()) {
|
||||||
@@ -153,6 +120,9 @@ class MangaSourcesRepository @Inject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
dao.insertIfAbsent(entities)
|
dao.insertIfAbsent(entities)
|
||||||
|
if (settings.isNsfwContentDisabled) {
|
||||||
|
new.removeAll { x -> x.isNsfw() }
|
||||||
|
}
|
||||||
return new
|
return new
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,6 +130,15 @@ class MangaSourcesRepository @Inject constructor(
|
|||||||
return dao.findAll().isEmpty()
|
return dao.findAll().isEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun getNewSources(): MutableSet<MangaSource> {
|
||||||
|
val entities = dao.findAll()
|
||||||
|
val result = EnumSet.copyOf(remoteSources)
|
||||||
|
for (e in entities) {
|
||||||
|
result.remove(MangaSource(e.source))
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
private fun List<MangaSourceEntity>.toSources(skipNsfwSources: Boolean): List<MangaSource> {
|
private fun List<MangaSourceEntity>.toSources(skipNsfwSources: Boolean): List<MangaSource> {
|
||||||
val result = ArrayList<MangaSource>(size)
|
val result = ArrayList<MangaSource>(size)
|
||||||
for (entity in this) {
|
for (entity in this) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.view.MenuItem
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.widget.PopupMenu
|
import androidx.appcompat.widget.PopupMenu
|
||||||
|
import androidx.core.content.pm.ShortcutManagerCompat
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
@@ -15,9 +16,11 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.bookmarks.ui.BookmarksActivity
|
import org.koitharu.kotatsu.bookmarks.ui.BookmarksActivity
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.SnackbarErrorObserver
|
import org.koitharu.kotatsu.core.exceptions.resolve.SnackbarErrorObserver
|
||||||
|
import org.koitharu.kotatsu.core.os.AppShortcutManager
|
||||||
import org.koitharu.kotatsu.core.ui.BaseFragment
|
import org.koitharu.kotatsu.core.ui.BaseFragment
|
||||||
import org.koitharu.kotatsu.core.ui.dialog.TwoButtonsAlertDialog
|
import org.koitharu.kotatsu.core.ui.dialog.TwoButtonsAlertDialog
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
@@ -28,6 +31,7 @@ import org.koitharu.kotatsu.core.ui.widgets.TipView
|
|||||||
import org.koitharu.kotatsu.core.util.ext.addMenuProvider
|
import org.koitharu.kotatsu.core.util.ext.addMenuProvider
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
import org.koitharu.kotatsu.core.util.ext.observe
|
||||||
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.viewLifecycleScope
|
||||||
import org.koitharu.kotatsu.databinding.FragmentExploreBinding
|
import org.koitharu.kotatsu.databinding.FragmentExploreBinding
|
||||||
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||||
import org.koitharu.kotatsu.download.ui.list.DownloadsActivity
|
import org.koitharu.kotatsu.download.ui.list.DownloadsActivity
|
||||||
@@ -55,6 +59,9 @@ class ExploreFragment :
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var coil: ImageLoader
|
lateinit var coil: ImageLoader
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var shortcutManager: AppShortcutManager
|
||||||
|
|
||||||
private val viewModel by viewModels<ExploreViewModel>()
|
private val viewModel by viewModels<ExploreViewModel>()
|
||||||
private var exploreAdapter: ExploreAdapter? = null
|
private var exploreAdapter: ExploreAdapter? = null
|
||||||
|
|
||||||
@@ -141,6 +148,8 @@ class ExploreFragment :
|
|||||||
override fun onItemLongClick(item: MangaSourceItem, view: View): Boolean {
|
override fun onItemLongClick(item: MangaSourceItem, view: View): Boolean {
|
||||||
val menu = PopupMenu(view.context, view)
|
val menu = PopupMenu(view.context, view)
|
||||||
menu.inflate(R.menu.popup_source)
|
menu.inflate(R.menu.popup_source)
|
||||||
|
menu.menu.findItem(R.id.action_shortcut)
|
||||||
|
?.isVisible = ShortcutManagerCompat.isRequestPinShortcutSupported(view.context)
|
||||||
menu.setOnMenuItemClickListener(SourceMenuListener(item))
|
menu.setOnMenuItemClickListener(SourceMenuListener(item))
|
||||||
menu.show()
|
menu.show()
|
||||||
return true
|
return true
|
||||||
@@ -195,6 +204,12 @@ class ExploreFragment :
|
|||||||
viewModel.hideSource(sourceItem.source)
|
viewModel.hideSource(sourceItem.source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
R.id.action_shortcut -> {
|
||||||
|
viewLifecycleScope.launch {
|
||||||
|
shortcutManager.requestPinShortcut(sourceItem.source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
|||||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
||||||
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
||||||
import org.koitharu.kotatsu.core.util.ext.resolveDp
|
import org.koitharu.kotatsu.core.util.ext.resolveDp
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.setOnContextClickListenerCompat
|
||||||
import org.koitharu.kotatsu.core.util.ext.source
|
import org.koitharu.kotatsu.core.util.ext.source
|
||||||
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
||||||
import org.koitharu.kotatsu.databinding.ItemExploreButtonsBinding
|
import org.koitharu.kotatsu.databinding.ItemExploreButtonsBinding
|
||||||
@@ -44,7 +45,12 @@ fun exploreButtonsAD(
|
|||||||
if (item.isRandomLoading) {
|
if (item.isRandomLoading) {
|
||||||
val icon = CircularProgressDrawable(context)
|
val icon = CircularProgressDrawable(context)
|
||||||
icon.strokeWidth = context.resources.resolveDp(2f)
|
icon.strokeWidth = context.resources.resolveDp(2f)
|
||||||
icon.setColorSchemeColors(context.getThemeColor(materialR.attr.colorPrimary, Color.DKGRAY))
|
icon.setColorSchemeColors(
|
||||||
|
context.getThemeColor(
|
||||||
|
materialR.attr.colorPrimary,
|
||||||
|
Color.DKGRAY
|
||||||
|
)
|
||||||
|
)
|
||||||
binding.buttonRandom.icon = icon
|
binding.buttonRandom.icon = icon
|
||||||
icon.start()
|
icon.start()
|
||||||
} else {
|
} else {
|
||||||
@@ -88,7 +94,13 @@ fun exploreSourceListItemAD(
|
|||||||
listener: OnListItemClickListener<MangaSourceItem>,
|
listener: OnListItemClickListener<MangaSourceItem>,
|
||||||
lifecycleOwner: LifecycleOwner,
|
lifecycleOwner: LifecycleOwner,
|
||||||
) = adapterDelegateViewBinding<MangaSourceItem, ListModel, ItemExploreSourceListBinding>(
|
) = adapterDelegateViewBinding<MangaSourceItem, ListModel, ItemExploreSourceListBinding>(
|
||||||
{ layoutInflater, parent -> ItemExploreSourceListBinding.inflate(layoutInflater, parent, false) },
|
{ layoutInflater, parent ->
|
||||||
|
ItemExploreSourceListBinding.inflate(
|
||||||
|
layoutInflater,
|
||||||
|
parent,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
},
|
||||||
on = { item, _, _ -> item is MangaSourceItem && !item.isGrid },
|
on = { item, _, _ -> item is MangaSourceItem && !item.isGrid },
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -96,6 +108,7 @@ fun exploreSourceListItemAD(
|
|||||||
|
|
||||||
binding.root.setOnClickListener(eventListener)
|
binding.root.setOnClickListener(eventListener)
|
||||||
binding.root.setOnLongClickListener(eventListener)
|
binding.root.setOnLongClickListener(eventListener)
|
||||||
|
binding.root.setOnContextClickListenerCompat(eventListener)
|
||||||
|
|
||||||
bind {
|
bind {
|
||||||
binding.textViewTitle.text = item.source.title
|
binding.textViewTitle.text = item.source.title
|
||||||
@@ -115,7 +128,13 @@ fun exploreSourceGridItemAD(
|
|||||||
listener: OnListItemClickListener<MangaSourceItem>,
|
listener: OnListItemClickListener<MangaSourceItem>,
|
||||||
lifecycleOwner: LifecycleOwner,
|
lifecycleOwner: LifecycleOwner,
|
||||||
) = adapterDelegateViewBinding<MangaSourceItem, ListModel, ItemExploreSourceGridBinding>(
|
) = adapterDelegateViewBinding<MangaSourceItem, ListModel, ItemExploreSourceGridBinding>(
|
||||||
{ layoutInflater, parent -> ItemExploreSourceGridBinding.inflate(layoutInflater, parent, false) },
|
{ layoutInflater, parent ->
|
||||||
|
ItemExploreSourceGridBinding.inflate(
|
||||||
|
layoutInflater,
|
||||||
|
parent,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
},
|
||||||
on = { item, _, _ -> item is MangaSourceItem && item.isGrid },
|
on = { item, _, _ -> item is MangaSourceItem && item.isGrid },
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -123,6 +142,7 @@ fun exploreSourceGridItemAD(
|
|||||||
|
|
||||||
binding.root.setOnClickListener(eventListener)
|
binding.root.setOnClickListener(eventListener)
|
||||||
binding.root.setOnLongClickListener(eventListener)
|
binding.root.setOnLongClickListener(eventListener)
|
||||||
|
binding.root.setOnContextClickListenerCompat(eventListener)
|
||||||
|
|
||||||
bind {
|
bind {
|
||||||
binding.textViewTitle.text = item.source.title
|
binding.textViewTitle.text = item.source.title
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class FavouriteCategoriesActivity :
|
|||||||
attachToRecyclerView(viewBinding.recyclerView)
|
attachToRecyclerView(viewBinding.recyclerView)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.categories.observe(this, ::onCategoriesChanged)
|
viewModel.content.observe(this, ::onCategoriesChanged)
|
||||||
viewModel.onError.observeEvent(this, SnackbarErrorObserver(viewBinding.recyclerView, null))
|
viewModel.onError.observeEvent(this, SnackbarErrorObserver(viewBinding.recyclerView, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
package org.koitharu.kotatsu.favourites.ui.categories
|
package org.koitharu.kotatsu.favourites.ui.categories
|
||||||
|
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.cancelAndJoin
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.plus
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
|
import kotlinx.coroutines.yield
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
||||||
import org.koitharu.kotatsu.core.util.ext.requireValue
|
import org.koitharu.kotatsu.core.util.ext.requireValue
|
||||||
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
||||||
|
import org.koitharu.kotatsu.favourites.domain.model.Cover
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.adapter.CategoryListModel
|
import org.koitharu.kotatsu.favourites.ui.categories.adapter.CategoryListModel
|
||||||
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.list.ui.model.LoadingState
|
import org.koitharu.kotatsu.list.ui.model.LoadingState
|
||||||
import org.koitharu.kotatsu.parsers.util.move
|
import org.koitharu.kotatsu.parsers.util.move
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -26,28 +28,19 @@ class FavouritesCategoriesViewModel @Inject constructor(
|
|||||||
private val settings: AppSettings,
|
private val settings: AppSettings,
|
||||||
) : BaseViewModel() {
|
) : BaseViewModel() {
|
||||||
|
|
||||||
private var reorderJob: Job? = null
|
private var commitJob: Job? = null
|
||||||
|
|
||||||
val categories = repository.observeCategoriesWithCovers()
|
val content = MutableStateFlow<List<ListModel>>(listOf(LoadingState))
|
||||||
.map { list ->
|
|
||||||
list.map { (category, covers) ->
|
init {
|
||||||
CategoryListModel(
|
launchJob(Dispatchers.Default) {
|
||||||
mangaCount = covers.size,
|
repository.observeCategoriesWithCovers()
|
||||||
covers = covers.take(3),
|
.collectLatest {
|
||||||
category = category,
|
commitJob?.join()
|
||||||
isTrackerEnabled = settings.isTrackerEnabled && AppSettings.TRACK_FAVOURITES in settings.trackSources,
|
updateContent(it)
|
||||||
)
|
}
|
||||||
}.ifEmpty {
|
}
|
||||||
listOf(
|
}
|
||||||
EmptyState(
|
|
||||||
icon = R.drawable.ic_empty_favourites,
|
|
||||||
textPrimary = R.string.text_empty_holder_primary,
|
|
||||||
textSecondary = R.string.empty_favourite_categories,
|
|
||||||
actionStringRes = 0,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, listOf(LoadingState))
|
|
||||||
|
|
||||||
fun deleteCategories(ids: Set<Long>) {
|
fun deleteCategories(ids: Set<Long>) {
|
||||||
launchJob(Dispatchers.Default) {
|
launchJob(Dispatchers.Default) {
|
||||||
@@ -59,19 +52,13 @@ class FavouritesCategoriesViewModel @Inject constructor(
|
|||||||
settings.isAllFavouritesVisible = isVisible
|
settings.isAllFavouritesVisible = isVisible
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isEmpty(): Boolean = categories.value.none { it is CategoryListModel }
|
fun isEmpty(): Boolean = content.value.none { it is CategoryListModel }
|
||||||
|
|
||||||
fun reorderCategories(oldPos: Int, newPos: Int) {
|
fun reorderCategories(oldPos: Int, newPos: Int) {
|
||||||
val prevJob = reorderJob
|
val snapshot = content.requireValue().toMutableList()
|
||||||
reorderJob = launchJob(Dispatchers.Default) {
|
snapshot.move(oldPos, newPos)
|
||||||
prevJob?.join()
|
content.value = snapshot
|
||||||
val snapshot = categories.requireValue().toMutableList()
|
commit(snapshot)
|
||||||
snapshot.move(oldPos, newPos)
|
|
||||||
val ids = snapshot.mapNotNullTo(ArrayList(snapshot.size)) {
|
|
||||||
(it as? CategoryListModel)?.category?.id
|
|
||||||
}
|
|
||||||
repository.reorderCategories(ids)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setIsVisible(ids: Set<Long>, isVisible: Boolean) {
|
fun setIsVisible(ids: Set<Long>, isVisible: Boolean) {
|
||||||
@@ -83,9 +70,42 @@ class FavouritesCategoriesViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getCategories(ids: Set<Long>): ArrayList<FavouriteCategory> {
|
fun getCategories(ids: Set<Long>): ArrayList<FavouriteCategory> {
|
||||||
val items = categories.requireValue()
|
val items = content.requireValue()
|
||||||
return items.mapNotNullTo(ArrayList(ids.size)) { item ->
|
return items.mapNotNullTo(ArrayList(ids.size)) { item ->
|
||||||
(item as? CategoryListModel)?.category?.takeIf { it.id in ids }
|
(item as? CategoryListModel)?.category?.takeIf { it.id in ids }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun commit(snapshot: List<ListModel>) {
|
||||||
|
val prevJob = commitJob
|
||||||
|
commitJob = launchJob {
|
||||||
|
prevJob?.cancelAndJoin()
|
||||||
|
delay(500)
|
||||||
|
val ids = snapshot.mapNotNullTo(ArrayList(snapshot.size)) {
|
||||||
|
(it as? CategoryListModel)?.category?.id
|
||||||
|
}
|
||||||
|
repository.reorderCategories(ids)
|
||||||
|
yield()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateContent(categories: Map<FavouriteCategory, List<Cover>>) {
|
||||||
|
content.value = categories.map { (category, covers) ->
|
||||||
|
CategoryListModel(
|
||||||
|
mangaCount = covers.size,
|
||||||
|
covers = covers.take(3),
|
||||||
|
category = category,
|
||||||
|
isTrackerEnabled = settings.isTrackerEnabled && AppSettings.TRACK_FAVOURITES in settings.trackSources,
|
||||||
|
)
|
||||||
|
}.ifEmpty {
|
||||||
|
listOf(
|
||||||
|
EmptyState(
|
||||||
|
icon = R.drawable.ic_empty_favourites,
|
||||||
|
textPrimary = R.string.text_empty_holder_primary,
|
||||||
|
textSecondary = R.string.empty_favourite_categories,
|
||||||
|
actionStringRes = 0,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,10 +76,7 @@ class FavouriteSheet :
|
|||||||
putParcelableArrayList(
|
putParcelableArrayList(
|
||||||
KEY_MANGA_LIST,
|
KEY_MANGA_LIST,
|
||||||
manga.mapTo(ArrayList(manga.size)) {
|
manga.mapTo(ArrayList(manga.size)) {
|
||||||
ParcelableManga(
|
ParcelableManga(it)
|
||||||
it,
|
|
||||||
withChapters = false,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}.showDistinct(fm, TAG)
|
}.showDistinct(fm, TAG)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.koitharu.kotatsu.core.db.entity.toManga
|
|||||||
import org.koitharu.kotatsu.core.db.entity.toMangaTag
|
import org.koitharu.kotatsu.core.db.entity.toMangaTag
|
||||||
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
||||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||||
|
import org.koitharu.kotatsu.core.model.findById
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.ui.util.ReversibleHandle
|
import org.koitharu.kotatsu.core.ui.util.ReversibleHandle
|
||||||
import org.koitharu.kotatsu.core.util.ext.mapItems
|
import org.koitharu.kotatsu.core.util.ext.mapItems
|
||||||
@@ -107,7 +108,7 @@ class HistoryRepository @Inject constructor(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
trackingRepository.syncWithHistory(manga, chapterId)
|
trackingRepository.syncWithHistory(manga, chapterId)
|
||||||
val chapter = manga.chapters?.find { x -> x.id == chapterId }
|
val chapter = manga.chapters?.findById(chapterId)
|
||||||
if (chapter != null) {
|
if (chapter != null) {
|
||||||
scrobblers.forEach { it.tryScrobble(manga.id, chapter) }
|
scrobblers.forEach { it.tryScrobble(manga.id, chapter) }
|
||||||
}
|
}
|
||||||
@@ -181,7 +182,7 @@ class HistoryRepository @Inject constructor(
|
|||||||
|
|
||||||
private suspend fun HistoryEntity.recoverIfNeeded(manga: Manga): HistoryEntity {
|
private suspend fun HistoryEntity.recoverIfNeeded(manga: Manga): HistoryEntity {
|
||||||
val chapters = manga.chapters
|
val chapters = manga.chapters
|
||||||
if (chapters.isNullOrEmpty() || chapters.any { it.id == chapterId }) {
|
if (chapters.isNullOrEmpty() || chapters.findById(chapterId) != null) {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
val newChapterId = chapters.getOrNull(
|
val newChapterId = chapters.getOrNull(
|
||||||
|
|||||||
@@ -25,4 +25,5 @@ enum class ListItemType {
|
|||||||
DOWNLOAD,
|
DOWNLOAD,
|
||||||
CATEGORY_LARGE,
|
CATEGORY_LARGE,
|
||||||
MANGA_SCROBBLING,
|
MANGA_SCROBBLING,
|
||||||
|
NAV_ITEM,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.list.ui.adapter
|
package org.koitharu.kotatsu.list.ui.adapter
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.google.android.material.badge.BadgeDrawable
|
import com.google.android.material.badge.BadgeDrawable
|
||||||
@@ -10,6 +11,7 @@ import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
|||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
||||||
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.setOnContextClickListenerCompat
|
||||||
import org.koitharu.kotatsu.core.util.ext.source
|
import org.koitharu.kotatsu.core.util.ext.source
|
||||||
import org.koitharu.kotatsu.databinding.ItemMangaGridBinding
|
import org.koitharu.kotatsu.databinding.ItemMangaGridBinding
|
||||||
import org.koitharu.kotatsu.list.ui.ListModelDiffCallback
|
import org.koitharu.kotatsu.list.ui.ListModelDiffCallback
|
||||||
@@ -28,12 +30,13 @@ fun mangaGridItemAD(
|
|||||||
) {
|
) {
|
||||||
var badge: BadgeDrawable? = null
|
var badge: BadgeDrawable? = null
|
||||||
|
|
||||||
itemView.setOnClickListener {
|
val eventListener = object : View.OnClickListener, View.OnLongClickListener {
|
||||||
clickListener.onItemClick(item.manga, it)
|
override fun onClick(v: View) = clickListener.onItemClick(item.manga, v)
|
||||||
}
|
override fun onLongClick(v: View): Boolean = clickListener.onItemLongClick(item.manga, v)
|
||||||
itemView.setOnLongClickListener {
|
|
||||||
clickListener.onItemLongClick(item.manga, it)
|
|
||||||
}
|
}
|
||||||
|
itemView.setOnClickListener(eventListener)
|
||||||
|
itemView.setOnLongClickListener(eventListener)
|
||||||
|
itemView.setOnContextClickListenerCompat(eventListener)
|
||||||
sizeResolver.attachToView(lifecycleOwner, itemView, binding.textViewTitle, binding.progressView)
|
sizeResolver.attachToView(lifecycleOwner, itemView, binding.textViewTitle, binding.progressView)
|
||||||
|
|
||||||
bind { payloads ->
|
bind { payloads ->
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
|||||||
import org.koitharu.kotatsu.core.ui.widgets.ChipsView
|
import org.koitharu.kotatsu.core.ui.widgets.ChipsView
|
||||||
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
||||||
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.setOnContextClickListenerCompat
|
||||||
import org.koitharu.kotatsu.core.util.ext.source
|
import org.koitharu.kotatsu.core.util.ext.source
|
||||||
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
||||||
import org.koitharu.kotatsu.databinding.ItemMangaListDetailsBinding
|
import org.koitharu.kotatsu.databinding.ItemMangaListDetailsBinding
|
||||||
@@ -45,6 +46,7 @@ fun mangaListDetailedItemAD(
|
|||||||
}
|
}
|
||||||
itemView.setOnClickListener(listenerAdapter)
|
itemView.setOnClickListener(listenerAdapter)
|
||||||
itemView.setOnLongClickListener(listenerAdapter)
|
itemView.setOnLongClickListener(listenerAdapter)
|
||||||
|
itemView.setOnContextClickListenerCompat(listenerAdapter)
|
||||||
binding.buttonRead.setOnClickListener(listenerAdapter)
|
binding.buttonRead.setOnClickListener(listenerAdapter)
|
||||||
binding.chipsTags.onChipClickListener = listenerAdapter
|
binding.chipsTags.onChipClickListener = listenerAdapter
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.list.ui.adapter
|
package org.koitharu.kotatsu.list.ui.adapter
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.google.android.material.badge.BadgeDrawable
|
import com.google.android.material.badge.BadgeDrawable
|
||||||
@@ -9,6 +10,7 @@ import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
|||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
||||||
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.setOnContextClickListenerCompat
|
||||||
import org.koitharu.kotatsu.core.util.ext.source
|
import org.koitharu.kotatsu.core.util.ext.source
|
||||||
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
||||||
import org.koitharu.kotatsu.databinding.ItemMangaListBinding
|
import org.koitharu.kotatsu.databinding.ItemMangaListBinding
|
||||||
@@ -25,12 +27,13 @@ fun mangaListItemAD(
|
|||||||
) {
|
) {
|
||||||
var badge: BadgeDrawable? = null
|
var badge: BadgeDrawable? = null
|
||||||
|
|
||||||
itemView.setOnClickListener {
|
val eventListener = object : View.OnClickListener, View.OnLongClickListener {
|
||||||
clickListener.onItemClick(item.manga, it)
|
override fun onClick(v: View) = clickListener.onItemClick(item.manga, v)
|
||||||
}
|
override fun onLongClick(v: View): Boolean = clickListener.onItemLongClick(item.manga, v)
|
||||||
itemView.setOnLongClickListener {
|
|
||||||
clickListener.onItemLongClick(item.manga, it)
|
|
||||||
}
|
}
|
||||||
|
itemView.setOnClickListener(eventListener)
|
||||||
|
itemView.setOnLongClickListener(eventListener)
|
||||||
|
itemView.setOnContextClickListenerCompat(eventListener)
|
||||||
|
|
||||||
bind {
|
bind {
|
||||||
binding.textViewTitle.text = item.title
|
binding.textViewTitle.text = item.title
|
||||||
|
|||||||
@@ -13,34 +13,39 @@ class TypedListSpacingDecoration(
|
|||||||
) : ItemDecoration() {
|
) : ItemDecoration() {
|
||||||
|
|
||||||
private val spacingSmall = context.resources.getDimensionPixelOffset(R.dimen.list_spacing_small)
|
private val spacingSmall = context.resources.getDimensionPixelOffset(R.dimen.list_spacing_small)
|
||||||
private val spacingNormal = context.resources.getDimensionPixelOffset(R.dimen.list_spacing_normal)
|
private val spacingNormal =
|
||||||
|
context.resources.getDimensionPixelOffset(R.dimen.list_spacing_normal)
|
||||||
private val spacingLarge = context.resources.getDimensionPixelOffset(R.dimen.list_spacing_large)
|
private val spacingLarge = context.resources.getDimensionPixelOffset(R.dimen.list_spacing_large)
|
||||||
|
|
||||||
override fun getItemOffsets(
|
override fun getItemOffsets(
|
||||||
outRect: Rect,
|
outRect: Rect,
|
||||||
view: View,
|
view: View,
|
||||||
parent: RecyclerView,
|
parent: RecyclerView,
|
||||||
state: RecyclerView.State
|
state: RecyclerView.State,
|
||||||
) {
|
) {
|
||||||
val itemType = parent.getChildViewHolder(view)?.itemViewType?.let {
|
val itemType = parent.getChildViewHolder(view)?.itemViewType?.let {
|
||||||
ListItemType.entries.getOrNull(it)
|
ListItemType.entries.getOrNull(it)
|
||||||
}
|
}
|
||||||
when (itemType) {
|
when (itemType) {
|
||||||
ListItemType.FILTER_SORT,
|
ListItemType.FILTER_SORT,
|
||||||
ListItemType.FILTER_TAG -> outRect.set(0)
|
ListItemType.FILTER_TAG,
|
||||||
|
-> outRect.set(0)
|
||||||
|
|
||||||
ListItemType.HEADER,
|
ListItemType.HEADER,
|
||||||
ListItemType.FEED,
|
ListItemType.FEED,
|
||||||
ListItemType.EXPLORE_SOURCE_LIST,
|
ListItemType.EXPLORE_SOURCE_LIST,
|
||||||
ListItemType.MANGA_SCROBBLING,
|
ListItemType.MANGA_SCROBBLING,
|
||||||
ListItemType.MANGA_LIST -> outRect.set(0)
|
ListItemType.MANGA_LIST,
|
||||||
|
-> outRect.set(0)
|
||||||
|
|
||||||
ListItemType.DOWNLOAD,
|
ListItemType.DOWNLOAD,
|
||||||
ListItemType.HINT_EMPTY,
|
ListItemType.HINT_EMPTY,
|
||||||
ListItemType.MANGA_LIST_DETAILED -> outRect.set(spacingNormal)
|
ListItemType.MANGA_LIST_DETAILED,
|
||||||
|
-> outRect.set(spacingNormal)
|
||||||
|
|
||||||
ListItemType.PAGE_THUMB,
|
ListItemType.PAGE_THUMB,
|
||||||
ListItemType.MANGA_GRID -> outRect.set(spacingNormal)
|
ListItemType.MANGA_GRID,
|
||||||
|
-> outRect.set(spacingNormal)
|
||||||
|
|
||||||
ListItemType.EXPLORE_BUTTONS -> outRect.set(spacingNormal)
|
ListItemType.EXPLORE_BUTTONS -> outRect.set(spacingNormal)
|
||||||
|
|
||||||
@@ -53,7 +58,9 @@ class TypedListSpacingDecoration(
|
|||||||
ListItemType.EXPLORE_SUGGESTION,
|
ListItemType.EXPLORE_SUGGESTION,
|
||||||
ListItemType.MANGA_NESTED_GROUP,
|
ListItemType.MANGA_NESTED_GROUP,
|
||||||
ListItemType.CATEGORY_LARGE,
|
ListItemType.CATEGORY_LARGE,
|
||||||
null -> outRect.set(0)
|
ListItemType.NAV_ITEM,
|
||||||
|
null,
|
||||||
|
-> outRect.set(0)
|
||||||
|
|
||||||
ListItemType.TIP -> outRect.set(0) // TODO
|
ListItemType.TIP -> outRect.set(0) // TODO
|
||||||
}
|
}
|
||||||
@@ -70,6 +77,6 @@ class TypedListSpacingDecoration(
|
|||||||
private fun Rect.set(spacing: Int) = set(spacing, spacing, spacing, spacing)
|
private fun Rect.set(spacing: Int) = set(spacing, spacing, spacing, spacing)
|
||||||
|
|
||||||
private fun ListItemType?.isEdgeToEdge() = this == ListItemType.MANGA_NESTED_GROUP
|
private fun ListItemType?.isEdgeToEdge() = this == ListItemType.MANGA_NESTED_GROUP
|
||||||
|| this == ListItemType.FILTER_SORT
|
|| this == ListItemType.FILTER_SORT
|
||||||
|| this == ListItemType.FILTER_TAG
|
|| this == ListItemType.FILTER_TAG
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import androidx.core.net.toUri
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.runInterruptible
|
import kotlinx.coroutines.runInterruptible
|
||||||
import org.koitharu.kotatsu.core.util.AlphanumComparator
|
import org.koitharu.kotatsu.core.util.AlphanumComparator
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.creationTime
|
||||||
import org.koitharu.kotatsu.core.util.ext.listFilesRecursive
|
import org.koitharu.kotatsu.core.util.ext.listFilesRecursive
|
||||||
import org.koitharu.kotatsu.core.util.ext.longHashCode
|
import org.koitharu.kotatsu.core.util.ext.longHashCode
|
||||||
import org.koitharu.kotatsu.core.util.ext.toListSorted
|
import org.koitharu.kotatsu.core.util.ext.toListSorted
|
||||||
@@ -62,7 +63,7 @@ class LocalMangaDirInput(root: File) : LocalMangaInput(root) {
|
|||||||
name = f.nameWithoutExtension.toHumanReadable(),
|
name = f.nameWithoutExtension.toHumanReadable(),
|
||||||
number = i + 1,
|
number = i + 1,
|
||||||
source = MangaSource.LOCAL,
|
source = MangaSource.LOCAL,
|
||||||
uploadDate = f.lastModified(),
|
uploadDate = f.creationTime,
|
||||||
url = f.toUri().toString(),
|
url = f.toUri().toString(),
|
||||||
scanlator = null,
|
scanlator = null,
|
||||||
branch = null,
|
branch = null,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.local.data.output
|
|||||||
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.runInterruptible
|
import kotlinx.coroutines.runInterruptible
|
||||||
|
import org.koitharu.kotatsu.core.model.findById
|
||||||
import org.koitharu.kotatsu.core.util.ext.deleteAwait
|
import org.koitharu.kotatsu.core.util.ext.deleteAwait
|
||||||
import org.koitharu.kotatsu.core.util.ext.takeIfReadable
|
import org.koitharu.kotatsu.core.util.ext.takeIfReadable
|
||||||
import org.koitharu.kotatsu.core.zip.ZipOutput
|
import org.koitharu.kotatsu.core.zip.ZipOutput
|
||||||
@@ -87,7 +88,7 @@ class LocalMangaDirOutput(
|
|||||||
suspend fun deleteChapter(chapterId: Long) {
|
suspend fun deleteChapter(chapterId: Long) {
|
||||||
val chapter = checkNotNull(index.getMangaInfo()?.chapters) {
|
val chapter = checkNotNull(index.getMangaInfo()?.chapters) {
|
||||||
"No chapters found"
|
"No chapters found"
|
||||||
}.first { it.id == chapterId }
|
}.findById(chapterId) ?: error("Chapter not found")
|
||||||
val chapterDir = File(rootFile, chapterFileName(chapter))
|
val chapterDir = File(rootFile, chapterFileName(chapter))
|
||||||
chapterDir.deleteAwait()
|
chapterDir.deleteAwait()
|
||||||
index.removeChapter(chapterId)
|
index.removeChapter(chapterId)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.local.domain.model
|
|||||||
|
|
||||||
import androidx.core.net.toFile
|
import androidx.core.net.toFile
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.creationTime
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -15,7 +16,7 @@ data class LocalManga(
|
|||||||
private set
|
private set
|
||||||
get() {
|
get() {
|
||||||
if (field == -1L) {
|
if (field == -1L) {
|
||||||
field = file.lastModified()
|
field = file.creationTime
|
||||||
}
|
}
|
||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import androidx.fragment.app.FragmentManager
|
|||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.ui.AlertDialogFragment
|
import org.koitharu.kotatsu.core.ui.AlertDialogFragment
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.tryLaunch
|
||||||
import org.koitharu.kotatsu.databinding.DialogImportBinding
|
import org.koitharu.kotatsu.databinding.DialogImportBinding
|
||||||
|
|
||||||
class ImportDialogFragment : AlertDialogFragment<DialogImportBinding>(), View.OnClickListener {
|
class ImportDialogFragment : AlertDialogFragment<DialogImportBinding>(), View.OnClickListener {
|
||||||
@@ -40,9 +41,13 @@ class ImportDialogFragment : AlertDialogFragment<DialogImportBinding>(), View.On
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onClick(v: View) {
|
override fun onClick(v: View) {
|
||||||
when (v.id) {
|
val res = when (v.id) {
|
||||||
R.id.button_file -> importFileCall.launch(arrayOf("*/*"))
|
R.id.button_file -> importFileCall.tryLaunch(arrayOf("*/*"))
|
||||||
R.id.button_dir -> importDirCall.launch(null)
|
R.id.button_dir -> importDirCall.tryLaunch(null)
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
|
if (!res) {
|
||||||
|
Toast.makeText(v.context, R.string.operation_not_supported, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class LocalChaptersRemoveService : CoroutineIntentService() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val intent = Intent(context, LocalChaptersRemoveService::class.java)
|
val intent = Intent(context, LocalChaptersRemoveService::class.java)
|
||||||
intent.putExtra(EXTRA_MANGA, ParcelableManga(manga, withChapters = false))
|
intent.putExtra(EXTRA_MANGA, ParcelableManga(manga))
|
||||||
intent.putExtra(EXTRA_CHAPTERS_IDS, chaptersIds.toLongArray())
|
intent.putExtra(EXTRA_CHAPTERS_IDS, chaptersIds.toLongArray())
|
||||||
ContextCompat.startForegroundService(context, intent)
|
ContextCompat.startForegroundService(context, intent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,12 +47,20 @@ class LocalListFragment : MangaListFragment(), FilterOwner {
|
|||||||
|
|
||||||
override fun onScrolledToEnd() = viewModel.loadNextPage()
|
override fun onScrolledToEnd() = viewModel.loadNextPage()
|
||||||
|
|
||||||
override fun onCreateActionMode(controller: ListSelectionController, mode: ActionMode, menu: Menu): Boolean {
|
override fun onCreateActionMode(
|
||||||
|
controller: ListSelectionController,
|
||||||
|
mode: ActionMode,
|
||||||
|
menu: Menu,
|
||||||
|
): Boolean {
|
||||||
mode.menuInflater.inflate(R.menu.mode_local, menu)
|
mode.menuInflater.inflate(R.menu.mode_local, menu)
|
||||||
return super.onCreateActionMode(controller, mode, menu)
|
return super.onCreateActionMode(controller, mode, menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActionItemClicked(controller: ListSelectionController, mode: ActionMode, item: MenuItem): Boolean {
|
override fun onActionItemClicked(
|
||||||
|
controller: ListSelectionController,
|
||||||
|
mode: ActionMode,
|
||||||
|
item: MenuItem,
|
||||||
|
): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.action_remove -> {
|
R.id.action_remove -> {
|
||||||
showDeletionConfirm(selectedItemsIds, mode)
|
showDeletionConfirm(selectedItemsIds, mode)
|
||||||
@@ -83,13 +91,20 @@ class LocalListFragment : MangaListFragment(), FilterOwner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onItemRemoved() {
|
private fun onItemRemoved() {
|
||||||
Snackbar.make(requireViewBinding().recyclerView, R.string.removal_completed, Snackbar.LENGTH_SHORT).show()
|
Snackbar.make(
|
||||||
|
requireViewBinding().recyclerView,
|
||||||
|
R.string.removal_completed,
|
||||||
|
Snackbar.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun newInstance() = LocalListFragment().withArgs(1) {
|
fun newInstance() = LocalListFragment().withArgs(1) {
|
||||||
putSerializable(RemoteListFragment.ARG_SOURCE, MangaSource.LOCAL) // required by FilterCoordinator
|
putSerializable(
|
||||||
|
RemoteListFragment.ARG_SOURCE,
|
||||||
|
MangaSource.LOCAL
|
||||||
|
) // required by FilterCoordinator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import coil.request.ImageResult
|
|||||||
import org.jsoup.HttpStatusException
|
import org.jsoup.HttpStatusException
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
|
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
|
||||||
|
import org.koitharu.kotatsu.core.model.findById
|
||||||
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||||
@@ -92,7 +93,7 @@ class CoverRestoreInterceptor @Inject constructor(
|
|||||||
|
|
||||||
private suspend fun restoreBookmarkImpl(bookmark: Bookmark): Boolean {
|
private suspend fun restoreBookmarkImpl(bookmark: Bookmark): Boolean {
|
||||||
val repo = repositoryFactory.create(bookmark.manga.source) as? RemoteMangaRepository ?: return false
|
val repo = repositoryFactory.create(bookmark.manga.source) as? RemoteMangaRepository ?: return false
|
||||||
val chapter = repo.getDetails(bookmark.manga).chapters?.find { it.id == bookmark.chapterId } ?: return false
|
val chapter = repo.getDetails(bookmark.manga).chapters?.findById(bookmark.chapterId) ?: return false
|
||||||
val page = repo.getPages(chapter)[bookmark.page]
|
val page = repo.getPages(chapter)[bookmark.page]
|
||||||
val imageUrl = page.preview.ifNullOrEmpty { page.url }
|
val imageUrl = page.preview.ifNullOrEmpty { page.url }
|
||||||
return if (imageUrl != bookmark.imageUrl) {
|
return if (imageUrl != bookmark.imageUrl) {
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import kotlinx.coroutines.withContext
|
|||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.SnackbarErrorObserver
|
import org.koitharu.kotatsu.core.exceptions.resolve.SnackbarErrorObserver
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.core.prefs.NavItem
|
||||||
import org.koitharu.kotatsu.core.ui.BaseActivity
|
import org.koitharu.kotatsu.core.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.core.ui.util.MenuInvalidator
|
import org.koitharu.kotatsu.core.ui.util.MenuInvalidator
|
||||||
import org.koitharu.kotatsu.core.ui.util.OptionsMenuBadgeHelper
|
import org.koitharu.kotatsu.core.ui.util.OptionsMenuBadgeHelper
|
||||||
@@ -71,8 +72,10 @@ import com.google.android.material.R as materialR
|
|||||||
private const val TAG_SEARCH = "search"
|
private const val TAG_SEARCH = "search"
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNavOwner, View.OnClickListener,
|
class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNavOwner,
|
||||||
View.OnFocusChangeListener, SearchSuggestionListener, MainNavigationDelegate.OnFragmentChangedListener {
|
View.OnClickListener,
|
||||||
|
View.OnFocusChangeListener, SearchSuggestionListener,
|
||||||
|
MainNavigationDelegate.OnFragmentChangedListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var settings: AppSettings
|
lateinit var settings: AppSettings
|
||||||
@@ -80,6 +83,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
private val viewModel by viewModels<MainViewModel>()
|
private val viewModel by viewModels<MainViewModel>()
|
||||||
private val searchSuggestionViewModel by viewModels<SearchSuggestionViewModel>()
|
private val searchSuggestionViewModel by viewModels<SearchSuggestionViewModel>()
|
||||||
private val closeSearchCallback = CloseSearchCallback()
|
private val closeSearchCallback = CloseSearchCallback()
|
||||||
|
private val appUpdateDialog = AppUpdateDialog(this)
|
||||||
private lateinit var navigationDelegate: MainNavigationDelegate
|
private lateinit var navigationDelegate: MainNavigationDelegate
|
||||||
private lateinit var appUpdateBadge: OptionsMenuBadgeHelper
|
private lateinit var appUpdateBadge: OptionsMenuBadgeHelper
|
||||||
|
|
||||||
@@ -119,7 +123,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
settings = settings,
|
settings = settings,
|
||||||
)
|
)
|
||||||
navigationDelegate.addOnFragmentChangedListener(this)
|
navigationDelegate.addOnFragmentChangedListener(this)
|
||||||
navigationDelegate.onCreate(savedInstanceState)
|
navigationDelegate.onCreate(this, savedInstanceState)
|
||||||
|
|
||||||
appUpdateBadge = OptionsMenuBadgeHelper(viewBinding.toolbar, R.id.action_app_update)
|
appUpdateBadge = OptionsMenuBadgeHelper(viewBinding.toolbar, R.id.action_app_update)
|
||||||
|
|
||||||
@@ -137,8 +141,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
viewModel.isResumeEnabled.observe(this, this::onResumeEnabledChanged)
|
viewModel.isResumeEnabled.observe(this, this::onResumeEnabledChanged)
|
||||||
viewModel.counters.observe(this, ::onCountersChanged)
|
viewModel.counters.observe(this, ::onCountersChanged)
|
||||||
viewModel.appUpdate.observe(this, MenuInvalidator(this))
|
viewModel.appUpdate.observe(this, MenuInvalidator(this))
|
||||||
viewModel.onFirstStart.observeEvent(this) { OnboardDialogFragment.showWelcome(supportFragmentManager) }
|
viewModel.onFirstStart.observeEvent(this) {
|
||||||
viewModel.isFeedAvailable.observe(this, ::onFeedAvailabilityChanged)
|
OnboardDialogFragment.show(supportFragmentManager)
|
||||||
|
}
|
||||||
searchSuggestionViewModel.isIncognitoModeEnabled.observe(this, this::onIncognitoModeChanged)
|
searchSuggestionViewModel.isIncognitoModeEnabled.observe(this, this::onIncognitoModeChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +171,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
if (menu == null) {
|
if (menu == null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
menu.findItem(R.id.action_incognito)?.isChecked = searchSuggestionViewModel.isIncognitoModeEnabled.value
|
menu.findItem(R.id.action_incognito)?.isChecked =
|
||||||
|
searchSuggestionViewModel.isIncognitoModeEnabled.value
|
||||||
val hasAppUpdate = viewModel.appUpdate.value != null
|
val hasAppUpdate = viewModel.appUpdate.value != null
|
||||||
menu.findItem(R.id.action_app_update)?.isVisible = hasAppUpdate
|
menu.findItem(R.id.action_app_update)?.isVisible = hasAppUpdate
|
||||||
appUpdateBadge.setBadgeVisible(hasAppUpdate)
|
appUpdateBadge.setBadgeVisible(hasAppUpdate)
|
||||||
@@ -193,8 +199,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
|
|
||||||
R.id.action_app_update -> {
|
R.id.action_app_update -> {
|
||||||
viewModel.appUpdate.value?.also {
|
viewModel.appUpdate.value?.also {
|
||||||
AppUpdateDialog(this)
|
appUpdateDialog.show(it)
|
||||||
.show(it)
|
|
||||||
} != null
|
} != null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,10 +239,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
|
|
||||||
override fun onQueryClick(query: String, submit: Boolean) {
|
override fun onQueryClick(query: String, submit: Boolean) {
|
||||||
viewBinding.searchView.query = query
|
viewBinding.searchView.query = query
|
||||||
if (submit) {
|
if (submit && query.isNotEmpty()) {
|
||||||
if (query.isNotEmpty()) {
|
startActivity(MultiSearchActivity.newIntent(this, query))
|
||||||
startActivity(MultiSearchActivity.newIntent(this, query))
|
searchSuggestionViewModel.saveQuery(query)
|
||||||
searchSuggestionViewModel.saveQuery(query)
|
viewBinding.searchView.post {
|
||||||
|
closeSearchCallback.handleOnBackPressed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,17 +285,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
startActivity(IntentBuilder(this).manga(manga).build(), options)
|
startActivity(IntentBuilder(this).manga(manga).build(), options)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onCountersChanged(counters: IntArray) {
|
private fun onCountersChanged(counters: Map<NavItem, Int>) {
|
||||||
repeat(counters.size) { i ->
|
counters.forEach { (navItem, counter) ->
|
||||||
val counter = counters[i]
|
navigationDelegate.setCounter(navItem, counter)
|
||||||
navigationDelegate.setCounterAt(i, counter)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onFeedAvailabilityChanged(isFeedAvailable: Boolean) {
|
|
||||||
navigationDelegate.setItemVisibility(R.id.nav_feed, isFeedAvailable)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onIncognitoModeChanged(isIncognito: Boolean) {
|
private fun onIncognitoModeChanged(isIncognito: Boolean) {
|
||||||
var options = viewBinding.searchView.imeOptions
|
var options = viewBinding.searchView.imeOptions
|
||||||
options = if (isIncognito) {
|
options = if (isIncognito) {
|
||||||
@@ -362,8 +363,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
} else {
|
} else {
|
||||||
SCROLL_FLAG_SCROLL or SCROLL_FLAG_ENTER_ALWAYS or SCROLL_FLAG_SNAP
|
SCROLL_FLAG_SCROLL or SCROLL_FLAG_ENTER_ALWAYS or SCROLL_FLAG_SNAP
|
||||||
}
|
}
|
||||||
viewBinding.toolbarCard.updateLayoutParams<AppBarLayout.LayoutParams> { scrollFlags = appBarScrollFlags }
|
viewBinding.toolbarCard.updateLayoutParams<AppBarLayout.LayoutParams> {
|
||||||
viewBinding.insetsHolder.updateLayoutParams<AppBarLayout.LayoutParams> { scrollFlags = appBarScrollFlags }
|
scrollFlags = appBarScrollFlags
|
||||||
|
}
|
||||||
|
viewBinding.insetsHolder.updateLayoutParams<AppBarLayout.LayoutParams> {
|
||||||
|
scrollFlags = appBarScrollFlags
|
||||||
|
}
|
||||||
viewBinding.toolbarCard.background = if (isOpened) {
|
viewBinding.toolbarCard.background = if (isOpened) {
|
||||||
null
|
null
|
||||||
} else {
|
} else {
|
||||||
@@ -372,9 +377,14 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
val padding = if (isOpened) 0 else resources.getDimensionPixelOffset(R.dimen.margin_normal)
|
val padding = if (isOpened) 0 else resources.getDimensionPixelOffset(R.dimen.margin_normal)
|
||||||
viewBinding.appbar.updatePadding(left = padding, right = padding)
|
viewBinding.appbar.updatePadding(left = padding, right = padding)
|
||||||
adjustFabVisibility(isSearchOpened = isOpened)
|
adjustFabVisibility(isSearchOpened = isOpened)
|
||||||
supportActionBar?.setHomeAsUpIndicator(
|
supportActionBar?.apply {
|
||||||
if (isOpened) materialR.drawable.abc_ic_ab_back_material else materialR.drawable.abc_ic_search_api_material,
|
setHomeAsUpIndicator(
|
||||||
)
|
if (isOpened) materialR.drawable.abc_ic_ab_back_material else materialR.drawable.abc_ic_search_api_material,
|
||||||
|
)
|
||||||
|
setHomeActionContentDescription(
|
||||||
|
if (isOpened) R.string.back else R.string.search,
|
||||||
|
)
|
||||||
|
}
|
||||||
viewBinding.searchView.setHintCompat(
|
viewBinding.searchView.setHintCompat(
|
||||||
if (isOpened) R.string.search_hint else R.string.search_manga,
|
if (isOpened) R.string.search_hint else R.string.search_manga,
|
||||||
)
|
)
|
||||||
@@ -387,7 +397,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
Manifest.permission.POST_NOTIFICATIONS,
|
Manifest.permission.POST_NOTIFICATIONS,
|
||||||
) != PERMISSION_GRANTED
|
) != PERMISSION_GRANTED
|
||||||
) {
|
) {
|
||||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.POST_NOTIFICATIONS), 1)
|
ActivityCompat.requestPermissions(
|
||||||
|
this,
|
||||||
|
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
|
||||||
|
1,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.main.ui
|
package org.koitharu.kotatsu.main.ui
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.annotation.IdRes
|
import androidx.annotation.IdRes
|
||||||
@@ -8,16 +9,28 @@ import androidx.core.view.isEmpty
|
|||||||
import androidx.core.view.iterator
|
import androidx.core.view.iterator
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.google.android.material.navigation.NavigationBarView
|
import com.google.android.material.navigation.NavigationBarView
|
||||||
import com.google.android.material.transition.MaterialFadeThrough
|
import com.google.android.material.transition.MaterialFadeThrough
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.flowOn
|
||||||
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.flow.onStart
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.bookmarks.ui.BookmarksFragment
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.core.prefs.NavItem
|
||||||
import org.koitharu.kotatsu.core.ui.util.RecyclerViewOwner
|
import org.koitharu.kotatsu.core.ui.util.RecyclerViewOwner
|
||||||
import org.koitharu.kotatsu.core.util.ext.firstVisibleItemPosition
|
import org.koitharu.kotatsu.core.util.ext.firstVisibleItemPosition
|
||||||
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
||||||
import org.koitharu.kotatsu.explore.ui.ExploreFragment
|
import org.koitharu.kotatsu.explore.ui.ExploreFragment
|
||||||
import org.koitharu.kotatsu.favourites.ui.container.FavouritesContainerFragment
|
import org.koitharu.kotatsu.favourites.ui.container.FavouritesContainerFragment
|
||||||
import org.koitharu.kotatsu.history.ui.HistoryListFragment
|
import org.koitharu.kotatsu.history.ui.HistoryListFragment
|
||||||
|
import org.koitharu.kotatsu.local.ui.LocalListFragment
|
||||||
|
import org.koitharu.kotatsu.suggestions.ui.SuggestionsFragment
|
||||||
import org.koitharu.kotatsu.tracker.ui.feed.FeedFragment
|
import org.koitharu.kotatsu.tracker.ui.feed.FeedFragment
|
||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
|
|
||||||
@@ -62,11 +75,11 @@ class MainNavigationDelegate(
|
|||||||
navBar.selectedItemId = R.id.nav_history
|
navBar.selectedItemId = R.id.nav_history
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onCreate(savedInstanceState: Bundle?) {
|
fun onCreate(lifecycleOwner: LifecycleOwner, savedInstanceState: Bundle?) {
|
||||||
if (navBar.menu.isEmpty()) {
|
if (navBar.menu.isEmpty()) {
|
||||||
val menuRes = if (settings.isFavoritesNavItemFirst) R.menu.nav_bottom_alt else R.menu.nav_bottom
|
createMenu(settings.mainNavItems, navBar.menu)
|
||||||
navBar.inflateMenu(menuRes)
|
|
||||||
}
|
}
|
||||||
|
observeSettings(lifecycleOwner)
|
||||||
val fragment = primaryFragment
|
val fragment = primaryFragment
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
onFragmentChanged(fragment, fromUser = false)
|
onFragmentChanged(fragment, fromUser = false)
|
||||||
@@ -84,12 +97,11 @@ class MainNavigationDelegate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setCounterAt(position: Int, counter: Int) {
|
fun setCounter(item: NavItem, counter: Int) {
|
||||||
val id = navBar.menu.getItem(position).itemId
|
setCounter(item.id, counter)
|
||||||
setCounter(id, counter)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setCounter(@IdRes id: Int, counter: Int) {
|
private fun setCounter(@IdRes id: Int, counter: Int) {
|
||||||
if (counter == 0) {
|
if (counter == 0) {
|
||||||
navBar.getBadge(id)?.isVisible = false
|
navBar.getBadge(id)?.isVisible = false
|
||||||
} else {
|
} else {
|
||||||
@@ -123,9 +135,12 @@ class MainNavigationDelegate(
|
|||||||
return setPrimaryFragment(
|
return setPrimaryFragment(
|
||||||
when (itemId) {
|
when (itemId) {
|
||||||
R.id.nav_history -> HistoryListFragment()
|
R.id.nav_history -> HistoryListFragment()
|
||||||
R.id.nav_favourites -> FavouritesContainerFragment()
|
R.id.nav_favorites -> FavouritesContainerFragment()
|
||||||
R.id.nav_explore -> ExploreFragment()
|
R.id.nav_explore -> ExploreFragment()
|
||||||
R.id.nav_feed -> FeedFragment()
|
R.id.nav_feed -> FeedFragment()
|
||||||
|
R.id.nav_local -> LocalListFragment.newInstance()
|
||||||
|
R.id.nav_suggestions -> SuggestionsFragment()
|
||||||
|
R.id.nav_bookmarks -> BookmarksFragment()
|
||||||
else -> return false
|
else -> return false
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -133,9 +148,12 @@ class MainNavigationDelegate(
|
|||||||
|
|
||||||
private fun getItemId(fragment: Fragment) = when (fragment) {
|
private fun getItemId(fragment: Fragment) = when (fragment) {
|
||||||
is HistoryListFragment -> R.id.nav_history
|
is HistoryListFragment -> R.id.nav_history
|
||||||
is FavouritesContainerFragment -> R.id.nav_favourites
|
is FavouritesContainerFragment -> R.id.nav_favorites
|
||||||
is ExploreFragment -> R.id.nav_explore
|
is ExploreFragment -> R.id.nav_explore
|
||||||
is FeedFragment -> R.id.nav_feed
|
is FeedFragment -> R.id.nav_feed
|
||||||
|
is LocalListFragment -> R.id.nav_local
|
||||||
|
is SuggestionsFragment -> R.id.nav_suggestions
|
||||||
|
is BookmarksFragment -> R.id.nav_bookmarks
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +175,24 @@ class MainNavigationDelegate(
|
|||||||
listeners.forEach { it.onFragmentChanged(fragment, fromUser) }
|
listeners.forEach { it.onFragmentChanged(fragment, fromUser) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createMenu(items: List<NavItem>, menu: Menu) {
|
||||||
|
for (item in items) {
|
||||||
|
menu.add(Menu.NONE, item.id, Menu.NONE, item.title)
|
||||||
|
.setIcon(item.icon)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun observeSettings(lifecycleOwner: LifecycleOwner) {
|
||||||
|
settings.observe()
|
||||||
|
.filter { x -> x == AppSettings.KEY_TRACKER_ENABLED || x == AppSettings.KEY_SUGGESTIONS }
|
||||||
|
.onStart { emit("") }
|
||||||
|
.flowOn(Dispatchers.Default)
|
||||||
|
.onEach {
|
||||||
|
setItemVisibility(R.id.nav_suggestions, settings.isSuggestionsEnabled)
|
||||||
|
setItemVisibility(R.id.nav_feed, settings.isTrackerEnabled)
|
||||||
|
}.launchIn(lifecycleOwner.lifecycleScope)
|
||||||
|
}
|
||||||
|
|
||||||
private fun firstItem(): MenuItem? {
|
private fun firstItem(): MenuItem? {
|
||||||
val menu = navBar.menu
|
val menu = navBar.menu
|
||||||
for (item in menu) {
|
for (item in menu) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import kotlinx.coroutines.plus
|
|||||||
import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException
|
import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException
|
||||||
import org.koitharu.kotatsu.core.github.AppUpdateRepository
|
import org.koitharu.kotatsu.core.github.AppUpdateRepository
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.prefs.observeAsStateFlow
|
import org.koitharu.kotatsu.core.prefs.NavItem
|
||||||
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
||||||
import org.koitharu.kotatsu.core.util.ext.MutableEventFlow
|
import org.koitharu.kotatsu.core.util.ext.MutableEventFlow
|
||||||
import org.koitharu.kotatsu.core.util.ext.call
|
import org.koitharu.kotatsu.core.util.ext.call
|
||||||
@@ -21,6 +21,7 @@ import org.koitharu.kotatsu.history.data.HistoryRepository
|
|||||||
import org.koitharu.kotatsu.main.domain.ReadingResumeEnabledUseCase
|
import org.koitharu.kotatsu.main.domain.ReadingResumeEnabledUseCase
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
||||||
|
import java.util.EnumMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
@@ -42,23 +43,20 @@ class MainViewModel @Inject constructor(
|
|||||||
initialValue = false,
|
initialValue = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
val isFeedAvailable = settings.observeAsStateFlow(
|
|
||||||
scope = viewModelScope + Dispatchers.Default,
|
|
||||||
key = AppSettings.KEY_TRACKER_ENABLED,
|
|
||||||
valueProducer = { isTrackerEnabled },
|
|
||||||
)
|
|
||||||
|
|
||||||
val appUpdate = appUpdateRepository.observeAvailableUpdate()
|
val appUpdate = appUpdateRepository.observeAvailableUpdate()
|
||||||
|
|
||||||
val counters = combine(
|
val counters = combine(
|
||||||
trackingRepository.observeUpdatedMangaCount(),
|
trackingRepository.observeUpdatedMangaCount(),
|
||||||
observeNewSourcesCount(),
|
observeNewSourcesCount(),
|
||||||
) { tracks, newSources ->
|
) { tracks, newSources ->
|
||||||
intArrayOf(0, 0, newSources, tracks)
|
val em = EnumMap<NavItem, Int>(NavItem::class.java)
|
||||||
|
em[NavItem.EXPLORE] = newSources
|
||||||
|
em[NavItem.FEED] = tracks
|
||||||
|
em
|
||||||
}.stateIn(
|
}.stateIn(
|
||||||
scope = viewModelScope + Dispatchers.Default,
|
scope = viewModelScope + Dispatchers.Default,
|
||||||
started = SharingStarted.WhileSubscribed(5000),
|
started = SharingStarted.WhileSubscribed(5000),
|
||||||
initialValue = IntArray(4),
|
initialValue = emptyMap<NavItem, Int>(),
|
||||||
)
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|||||||
@@ -2,6 +2,12 @@ package org.koitharu.kotatsu.reader.domain
|
|||||||
|
|
||||||
import android.util.LongSparseArray
|
import android.util.LongSparseArray
|
||||||
import dagger.hilt.android.scopes.ViewModelScoped
|
import dagger.hilt.android.scopes.ViewModelScoped
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
@@ -17,24 +23,32 @@ class ChaptersLoader @Inject constructor(
|
|||||||
private val mangaRepositoryFactory: MangaRepository.Factory,
|
private val mangaRepositoryFactory: MangaRepository.Factory,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val chapters = LongSparseArray<MangaChapter>()
|
private val chapters = MutableStateFlow(LongSparseArray<MangaChapter>(0))
|
||||||
private val chapterPages = ChapterPages()
|
private val chapterPages = ChapterPages()
|
||||||
private val mutex = Mutex()
|
private val mutex = Mutex()
|
||||||
|
|
||||||
val size: Int
|
val size: Int // TODO flow
|
||||||
get() = chapters.size()
|
get() = chapters.value.size()
|
||||||
|
|
||||||
suspend fun init(manga: DoubleManga) = mutex.withLock {
|
fun init(scope: CoroutineScope, manga: Flow<DoubleManga>) = scope.launch {
|
||||||
chapters.clear()
|
manga.collect {
|
||||||
manga.chapters?.forEach {
|
val ch = it.chapters.orEmpty()
|
||||||
chapters.put(it.id, it)
|
val longSparseArray = LongSparseArray<MangaChapter>(ch.size)
|
||||||
|
ch.forEach { x -> longSparseArray.put(x.id, x) }
|
||||||
|
mutex.withLock {
|
||||||
|
chapters.value = longSparseArray
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun loadPrevNextChapter(manga: DoubleManga, currentId: Long, isNext: Boolean) {
|
suspend fun loadPrevNextChapter(manga: DoubleManga, currentId: Long, isNext: Boolean) {
|
||||||
val chapters = manga.chapters ?: return
|
val chapters = manga.chapters ?: return
|
||||||
val predicate: (MangaChapter) -> Boolean = { it.id == currentId }
|
val predicate: (MangaChapter) -> Boolean = { it.id == currentId }
|
||||||
val index = if (isNext) chapters.indexOfFirst(predicate) else chapters.indexOfLast(predicate)
|
val index = if (isNext) {
|
||||||
|
chapters.indexOfFirst(predicate)
|
||||||
|
} else {
|
||||||
|
chapters.indexOfLast(predicate)
|
||||||
|
}
|
||||||
if (index == -1) return
|
if (index == -1) return
|
||||||
val newChapter = chapters.getOrNull(if (isNext) index + 1 else index - 1) ?: return
|
val newChapter = chapters.getOrNull(if (isNext) index + 1 else index - 1) ?: return
|
||||||
val newPages = loadChapter(newChapter.id)
|
val newPages = loadChapter(newChapter.id)
|
||||||
@@ -65,7 +79,11 @@ class ChaptersLoader @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun peekChapter(chapterId: Long): MangaChapter? = chapters[chapterId]
|
fun peekChapter(chapterId: Long): MangaChapter? = chapters.value[chapterId]
|
||||||
|
|
||||||
|
suspend fun awaitChapter(chapterId: Long): MangaChapter? = chapters.mapNotNull { x ->
|
||||||
|
x[chapterId]
|
||||||
|
}.firstOrNull()
|
||||||
|
|
||||||
fun getPages(chapterId: Long): List<ReaderPage> {
|
fun getPages(chapterId: Long): List<ReaderPage> {
|
||||||
return chapterPages.subList(chapterId)
|
return chapterPages.subList(chapterId)
|
||||||
@@ -82,7 +100,7 @@ class ChaptersLoader @Inject constructor(
|
|||||||
fun snapshot() = chapterPages.toList()
|
fun snapshot() = chapterPages.toList()
|
||||||
|
|
||||||
private suspend fun loadChapter(chapterId: Long): List<ReaderPage> {
|
private suspend fun loadChapter(chapterId: Long): List<ReaderPage> {
|
||||||
val chapter = checkNotNull(chapters[chapterId]) { "Requested chapter not found" }
|
val chapter = checkNotNull(awaitChapter(chapterId)) { "Requested chapter not found" }
|
||||||
val repo = mangaRepositoryFactory.create(chapter.source)
|
val repo = mangaRepositoryFactory.create(chapter.source)
|
||||||
return repo.getPages(chapter).mapIndexed { index, page ->
|
return repo.getPages(chapter).mapIndexed { index, page ->
|
||||||
ReaderPage(page, index, chapterId)
|
ReaderPage(page, index, chapterId)
|
||||||
|
|||||||
@@ -5,16 +5,14 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
|
import androidx.fragment.app.activityViewModels
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableMangaChapters
|
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.core.ui.sheet.BaseAdaptiveSheet
|
import org.koitharu.kotatsu.core.ui.sheet.BaseAdaptiveSheet
|
||||||
import org.koitharu.kotatsu.core.util.RecyclerViewScrollCallback
|
import org.koitharu.kotatsu.core.util.RecyclerViewScrollCallback
|
||||||
import org.koitharu.kotatsu.core.util.ext.getParcelableCompat
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.showDistinct
|
import org.koitharu.kotatsu.core.util.ext.showDistinct
|
||||||
import org.koitharu.kotatsu.core.util.ext.withArgs
|
|
||||||
import org.koitharu.kotatsu.databinding.SheetChaptersBinding
|
import org.koitharu.kotatsu.databinding.SheetChaptersBinding
|
||||||
import org.koitharu.kotatsu.details.ui.adapter.ChaptersAdapter
|
import org.koitharu.kotatsu.details.ui.adapter.ChaptersAdapter
|
||||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
import org.koitharu.kotatsu.details.ui.model.ChapterListItem
|
||||||
@@ -24,23 +22,29 @@ import javax.inject.Inject
|
|||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ChaptersSheet : BaseAdaptiveSheet<SheetChaptersBinding>(), OnListItemClickListener<ChapterListItem> {
|
class ChaptersSheet : BaseAdaptiveSheet<SheetChaptersBinding>(),
|
||||||
|
OnListItemClickListener<ChapterListItem> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var settings: AppSettings
|
lateinit var settings: AppSettings
|
||||||
|
|
||||||
override fun onCreateViewBinding(inflater: LayoutInflater, container: ViewGroup?): SheetChaptersBinding {
|
private val viewModel: ReaderViewModel by activityViewModels()
|
||||||
|
|
||||||
|
override fun onCreateViewBinding(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
): SheetChaptersBinding {
|
||||||
return SheetChaptersBinding.inflate(inflater, container, false)
|
return SheetChaptersBinding.inflate(inflater, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewBindingCreated(binding: SheetChaptersBinding, savedInstanceState: Bundle?) {
|
override fun onViewBindingCreated(binding: SheetChaptersBinding, savedInstanceState: Bundle?) {
|
||||||
super.onViewBindingCreated(binding, savedInstanceState)
|
super.onViewBindingCreated(binding, savedInstanceState)
|
||||||
val chapters = arguments?.getParcelableCompat<ParcelableMangaChapters>(ARG_CHAPTERS)?.chapters
|
val chapters = viewModel.manga?.chapters
|
||||||
if (chapters.isNullOrEmpty()) {
|
if (chapters.isNullOrEmpty()) {
|
||||||
dismissAllowingStateLoss()
|
dismissAllowingStateLoss()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val currentId = requireArguments().getLong(ARG_CURRENT_ID, 0L)
|
val currentId = viewModel.getCurrentState()?.chapterId ?: 0L
|
||||||
val currentPosition = chapters.indexOfFirst { it.id == currentId }
|
val currentPosition = chapters.indexOfFirst { it.id == currentId }
|
||||||
val items = chapters.mapIndexed { index, chapter ->
|
val items = chapters.mapIndexed { index, chapter ->
|
||||||
chapter.toListItem(
|
chapter.toListItem(
|
||||||
@@ -54,8 +58,11 @@ class ChaptersSheet : BaseAdaptiveSheet<SheetChaptersBinding>(), OnListItemClick
|
|||||||
binding.recyclerView.adapter = ChaptersAdapter(this).also { adapter ->
|
binding.recyclerView.adapter = ChaptersAdapter(this).also { adapter ->
|
||||||
if (currentPosition >= 0) {
|
if (currentPosition >= 0) {
|
||||||
val targetPosition = (currentPosition - 1).coerceAtLeast(0)
|
val targetPosition = (currentPosition - 1).coerceAtLeast(0)
|
||||||
val offset = (resources.getDimensionPixelSize(R.dimen.chapter_list_item_height) * 0.6).roundToInt()
|
val offset =
|
||||||
adapter.setItems(items, RecyclerViewScrollCallback(binding.recyclerView, targetPosition, offset))
|
(resources.getDimensionPixelSize(R.dimen.chapter_list_item_height) * 0.6).roundToInt()
|
||||||
|
adapter.setItems(
|
||||||
|
items, RecyclerViewScrollCallback(binding.recyclerView, targetPosition, offset)
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
adapter.items = items
|
adapter.items = items
|
||||||
}
|
}
|
||||||
@@ -63,7 +70,8 @@ class ChaptersSheet : BaseAdaptiveSheet<SheetChaptersBinding>(), OnListItemClick
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemClick(item: ChapterListItem, view: View) {
|
override fun onItemClick(item: ChapterListItem, view: View) {
|
||||||
((parentFragment as? OnChapterChangeListener) ?: (activity as? OnChapterChangeListener))?.let {
|
((parentFragment as? OnChapterChangeListener)
|
||||||
|
?: (activity as? OnChapterChangeListener))?.let {
|
||||||
dismiss()
|
dismiss()
|
||||||
it.onChapterChanged(item.chapter)
|
it.onChapterChanged(item.chapter)
|
||||||
}
|
}
|
||||||
@@ -76,18 +84,8 @@ class ChaptersSheet : BaseAdaptiveSheet<SheetChaptersBinding>(), OnListItemClick
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val ARG_CHAPTERS = "chapters"
|
|
||||||
private const val ARG_CURRENT_ID = "current_id"
|
|
||||||
|
|
||||||
private const val TAG = "ChaptersBottomSheet"
|
private const val TAG = "ChaptersBottomSheet"
|
||||||
|
|
||||||
fun show(
|
fun show(fm: FragmentManager) = ChaptersSheet().showDistinct(fm, TAG)
|
||||||
fm: FragmentManager,
|
|
||||||
chapters: List<MangaChapter>,
|
|
||||||
currentId: Long,
|
|
||||||
) = ChaptersSheet().withArgs(2) {
|
|
||||||
putParcelable(ARG_CHAPTERS, ParcelableMangaChapters(chapters))
|
|
||||||
putLong(ARG_CURRENT_ID, currentId)
|
|
||||||
}.showDistinct(fm, TAG)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import org.koitharu.kotatsu.core.util.GridTouchHelper
|
|||||||
import org.koitharu.kotatsu.core.util.IdlingDetector
|
import org.koitharu.kotatsu.core.util.IdlingDetector
|
||||||
import org.koitharu.kotatsu.core.util.ShareHelper
|
import org.koitharu.kotatsu.core.util.ShareHelper
|
||||||
import org.koitharu.kotatsu.core.util.ext.hasGlobalPoint
|
import org.koitharu.kotatsu.core.util.ext.hasGlobalPoint
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
||||||
import org.koitharu.kotatsu.core.util.ext.isRtl
|
import org.koitharu.kotatsu.core.util.ext.isRtl
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
import org.koitharu.kotatsu.core.util.ext.observe
|
||||||
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
||||||
@@ -106,7 +107,7 @@ class ReaderActivity :
|
|||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
touchHelper = GridTouchHelper(this, this)
|
touchHelper = GridTouchHelper(this, this)
|
||||||
scrollTimer = scrollTimerFactory.create(this, this)
|
scrollTimer = scrollTimerFactory.create(this, this)
|
||||||
controlDelegate = ReaderControlDelegate(settings, this, this)
|
controlDelegate = ReaderControlDelegate(resources, settings, this, this)
|
||||||
viewBinding.toolbarBottom.setOnMenuItemClickListener(::onOptionsItemSelected)
|
viewBinding.toolbarBottom.setOnMenuItemClickListener(::onOptionsItemSelected)
|
||||||
viewBinding.slider.setLabelFormatter(PageLabelFormatter())
|
viewBinding.slider.setLabelFormatter(PageLabelFormatter())
|
||||||
ReaderSliderListener(this, viewModel).attachToSlider(viewBinding.slider)
|
ReaderSliderListener(this, viewModel).attachToSlider(viewBinding.slider)
|
||||||
@@ -136,6 +137,7 @@ class ReaderActivity :
|
|||||||
onLoadingStateChanged(viewModel.isLoading.value)
|
onLoadingStateChanged(viewModel.isLoading.value)
|
||||||
}
|
}
|
||||||
viewModel.isScreenshotsBlockEnabled.observe(this, this::setWindowSecure)
|
viewModel.isScreenshotsBlockEnabled.observe(this, this::setWindowSecure)
|
||||||
|
viewModel.isKeepScreenOnEnabled.observe(this, this::setKeepScreenOn)
|
||||||
viewModel.isInfoBarEnabled.observe(this, ::onReaderBarChanged)
|
viewModel.isInfoBarEnabled.observe(this, ::onReaderBarChanged)
|
||||||
viewModel.isBookmarkAdded.observe(this, this::onBookmarkStateChanged)
|
viewModel.isBookmarkAdded.observe(this, this::onBookmarkStateChanged)
|
||||||
viewModel.onShowToast.observeEvent(this) { msgId ->
|
viewModel.onShowToast.observeEvent(this) { msgId ->
|
||||||
@@ -180,11 +182,7 @@ class ReaderActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_chapters -> {
|
R.id.action_chapters -> {
|
||||||
ChaptersSheet.show(
|
ChaptersSheet.show(supportFragmentManager)
|
||||||
supportFragmentManager,
|
|
||||||
viewModel.manga?.chapters.orEmpty(),
|
|
||||||
viewModel.getCurrentState()?.chapterId ?: 0L,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_pages_thumbs -> {
|
R.id.action_pages_thumbs -> {
|
||||||
@@ -307,24 +305,30 @@ class ReaderActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setKeepScreenOn(isKeep: Boolean) {
|
||||||
|
if (isKeep) {
|
||||||
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
} else {
|
||||||
|
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setUiIsVisible(isUiVisible: Boolean) {
|
private fun setUiIsVisible(isUiVisible: Boolean) {
|
||||||
if (viewBinding.appbarTop.isVisible != isUiVisible) {
|
if (viewBinding.appbarTop.isVisible != isUiVisible) {
|
||||||
val transition = TransitionSet()
|
if (isAnimationsEnabled) {
|
||||||
.setOrdering(TransitionSet.ORDERING_TOGETHER)
|
val transition = TransitionSet()
|
||||||
.addTransition(Slide(Gravity.TOP).addTarget(viewBinding.appbarTop))
|
.setOrdering(TransitionSet.ORDERING_TOGETHER)
|
||||||
.addTransition(Fade().addTarget(viewBinding.infoBar))
|
.addTransition(Slide(Gravity.TOP).addTarget(viewBinding.appbarTop))
|
||||||
viewBinding.appbarBottom?.let { bottomBar ->
|
.addTransition(Fade().addTarget(viewBinding.infoBar))
|
||||||
transition.addTransition(Slide(Gravity.BOTTOM).addTarget(bottomBar))
|
viewBinding.appbarBottom?.let { bottomBar ->
|
||||||
|
transition.addTransition(Slide(Gravity.BOTTOM).addTarget(bottomBar))
|
||||||
|
}
|
||||||
|
TransitionManager.beginDelayedTransition(viewBinding.root, transition)
|
||||||
}
|
}
|
||||||
TransitionManager.beginDelayedTransition(viewBinding.root, transition)
|
|
||||||
viewBinding.appbarTop.isVisible = isUiVisible
|
viewBinding.appbarTop.isVisible = isUiVisible
|
||||||
viewBinding.appbarBottom?.isVisible = isUiVisible
|
viewBinding.appbarBottom?.isVisible = isUiVisible
|
||||||
viewBinding.infoBar.isGone = isUiVisible || (!viewModel.isInfoBarEnabled.value)
|
viewBinding.infoBar.isGone = isUiVisible || (!viewModel.isInfoBarEnabled.value)
|
||||||
if (isUiVisible) {
|
systemUiController.setSystemUiVisible(isUiVisible)
|
||||||
showSystemUI()
|
|
||||||
} else {
|
|
||||||
hideSystemUI()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,8 +356,8 @@ class ReaderActivity :
|
|||||||
readerManager.currentReader?.switchPageBy(delta)
|
readerManager.currentReader?.switchPageBy(delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun scrollBy(delta: Int): Boolean {
|
override fun scrollBy(delta: Int, smooth: Boolean): Boolean {
|
||||||
return readerManager.currentReader?.scrollBy(delta) ?: false
|
return readerManager.currentReader?.scrollBy(delta, smooth) ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toggleUiVisibility() {
|
override fun toggleUiVisibility() {
|
||||||
@@ -405,7 +409,7 @@ class ReaderActivity :
|
|||||||
.setAction(ACTION_MANGA_READ)
|
.setAction(ACTION_MANGA_READ)
|
||||||
|
|
||||||
fun manga(manga: Manga) = apply {
|
fun manga(manga: Manga) = apply {
|
||||||
intent.putExtra(MangaIntent.KEY_MANGA, ParcelableManga(manga, withChapters = true))
|
intent.putExtra(MangaIntent.KEY_MANGA, ParcelableManga(manga))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mangaId(mangaId: Long) = apply {
|
fun mangaId(mangaId: Long) = apply {
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
package org.koitharu.kotatsu.reader.ui
|
package org.koitharu.kotatsu.reader.ui
|
||||||
|
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import android.content.res.Resources
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.SoundEffectConstants
|
import android.view.SoundEffectConstants
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver
|
import androidx.lifecycle.DefaultLifecycleObserver
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
||||||
import org.koitharu.kotatsu.core.util.GridTouchHelper
|
import org.koitharu.kotatsu.core.util.GridTouchHelper
|
||||||
|
|
||||||
class ReaderControlDelegate(
|
class ReaderControlDelegate(
|
||||||
|
resources: Resources,
|
||||||
private val settings: AppSettings,
|
private val settings: AppSettings,
|
||||||
private val listener: OnInteractionListener,
|
private val listener: OnInteractionListener,
|
||||||
owner: LifecycleOwner,
|
owner: LifecycleOwner,
|
||||||
@@ -19,6 +22,7 @@ class ReaderControlDelegate(
|
|||||||
private var isTapSwitchEnabled: Boolean = true
|
private var isTapSwitchEnabled: Boolean = true
|
||||||
private var isVolumeKeysSwitchEnabled: Boolean = false
|
private var isVolumeKeysSwitchEnabled: Boolean = false
|
||||||
private var isReaderTapsAdaptive: Boolean = true
|
private var isReaderTapsAdaptive: Boolean = true
|
||||||
|
private var minScrollDelta = resources.getDimensionPixelSize(R.dimen.reader_scroll_delta_min)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
owner.lifecycle.addObserver(this)
|
owner.lifecycle.addObserver(this)
|
||||||
@@ -82,8 +86,6 @@ class ReaderControlDelegate(
|
|||||||
|
|
||||||
KeyEvent.KEYCODE_SPACE,
|
KeyEvent.KEYCODE_SPACE,
|
||||||
KeyEvent.KEYCODE_PAGE_DOWN,
|
KeyEvent.KEYCODE_PAGE_DOWN,
|
||||||
KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN,
|
|
||||||
KeyEvent.KEYCODE_DPAD_DOWN,
|
|
||||||
-> {
|
-> {
|
||||||
listener.switchPageBy(1)
|
listener.switchPageBy(1)
|
||||||
true
|
true
|
||||||
@@ -95,8 +97,6 @@ class ReaderControlDelegate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
KeyEvent.KEYCODE_PAGE_UP,
|
KeyEvent.KEYCODE_PAGE_UP,
|
||||||
KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP,
|
|
||||||
KeyEvent.KEYCODE_DPAD_UP,
|
|
||||||
-> {
|
-> {
|
||||||
listener.switchPageBy(-1)
|
listener.switchPageBy(-1)
|
||||||
true
|
true
|
||||||
@@ -112,6 +112,22 @@ class ReaderControlDelegate(
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP,
|
||||||
|
KeyEvent.KEYCODE_DPAD_UP -> {
|
||||||
|
if (!listener.scrollBy(-minScrollDelta, smooth = true)) {
|
||||||
|
listener.switchPageBy(-1)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN,
|
||||||
|
KeyEvent.KEYCODE_DPAD_DOWN -> {
|
||||||
|
if (!listener.scrollBy(minScrollDelta, smooth = true)) {
|
||||||
|
listener.switchPageBy(1)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +155,7 @@ class ReaderControlDelegate(
|
|||||||
|
|
||||||
fun switchPageBy(delta: Int)
|
fun switchPageBy(delta: Int)
|
||||||
|
|
||||||
fun scrollBy(delta: Int): Boolean
|
fun scrollBy(delta: Int, smooth: Boolean): Boolean
|
||||||
|
|
||||||
fun toggleUiVisibility()
|
fun toggleUiVisibility()
|
||||||
|
|
||||||
|
|||||||
@@ -113,12 +113,24 @@ class ReaderViewModel @Inject constructor(
|
|||||||
valueProducer = { isReaderBarEnabled },
|
valueProducer = { isReaderBarEnabled },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val isKeepScreenOnEnabled = settings.observeAsStateFlow(
|
||||||
|
scope = viewModelScope + Dispatchers.Default,
|
||||||
|
key = AppSettings.KEY_READER_SCREEN_ON,
|
||||||
|
valueProducer = { isReaderKeepScreenOn },
|
||||||
|
)
|
||||||
|
|
||||||
val isWebtoonZoomEnabled = settings.observeAsStateFlow(
|
val isWebtoonZoomEnabled = settings.observeAsStateFlow(
|
||||||
scope = viewModelScope + Dispatchers.Default,
|
scope = viewModelScope + Dispatchers.Default,
|
||||||
key = AppSettings.KEY_WEBTOON_ZOOM,
|
key = AppSettings.KEY_WEBTOON_ZOOM,
|
||||||
valueProducer = { isWebtoonZoomEnable },
|
valueProducer = { isWebtoonZoomEnable },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val isZoomControlEnabled = settings.observeAsStateFlow(
|
||||||
|
scope = viewModelScope + Dispatchers.Default,
|
||||||
|
key = AppSettings.KEY_READER_ZOOM_BUTTONS,
|
||||||
|
valueProducer = { isReaderZoomButtonsEnabled },
|
||||||
|
)
|
||||||
|
|
||||||
val readerSettings = ReaderSettings(
|
val readerSettings = ReaderSettings(
|
||||||
parentScope = viewModelScope,
|
parentScope = viewModelScope,
|
||||||
settings = settings,
|
settings = settings,
|
||||||
@@ -317,8 +329,9 @@ class ReaderViewModel @Inject constructor(
|
|||||||
?: throw NotFoundException("Cannot find manga", ""),
|
?: throw NotFoundException("Cannot find manga", ""),
|
||||||
)
|
)
|
||||||
mangaData.value = manga
|
mangaData.value = manga
|
||||||
manga = doubleMangaLoadUseCase(intent)
|
val mangaFlow = doubleMangaLoadUseCase(intent)
|
||||||
chaptersLoader.init(manga)
|
manga = mangaFlow.first { x -> x.any != null }
|
||||||
|
chaptersLoader.init(viewModelScope, mangaFlow.withErrorHandling())
|
||||||
// determine mode
|
// determine mode
|
||||||
val singleManga = manga.requireAny()
|
val singleManga = manga.requireAny()
|
||||||
// obtain state
|
// obtain state
|
||||||
@@ -328,7 +341,7 @@ class ReaderViewModel @Inject constructor(
|
|||||||
} ?: ReaderState(singleManga, preselectedBranch)
|
} ?: ReaderState(singleManga, preselectedBranch)
|
||||||
}
|
}
|
||||||
val mode = detectReaderModeUseCase.invoke(singleManga, currentState.value)
|
val mode = detectReaderModeUseCase.invoke(singleManga, currentState.value)
|
||||||
val branch = chaptersLoader.peekChapter(currentState.value?.chapterId ?: 0L)?.branch
|
val branch = chaptersLoader.awaitChapter(currentState.value?.chapterId ?: 0L)?.branch
|
||||||
mangaData.value = manga.filterChapters(branch)
|
mangaData.value = manga.filterChapters(branch)
|
||||||
readerMode.value = mode
|
readerMode.value = mode
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import org.koitharu.kotatsu.core.prefs.AppSettings
|
|||||||
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||||
import kotlin.math.roundToLong
|
import kotlin.math.roundToLong
|
||||||
|
|
||||||
private const val MAX_DELAY = 20L
|
private const val MAX_DELAY = 8L
|
||||||
private const val MAX_SWITCH_DELAY = 10_000L
|
private const val MAX_SWITCH_DELAY = 10_000L
|
||||||
private const val INTERACTION_SKIP_MS = 2_000L
|
private const val INTERACTION_SKIP_MS = 2_000L
|
||||||
private const val SPEED_FACTOR_DELTA = 0.02f
|
private const val SPEED_FACTOR_DELTA = 0.02f
|
||||||
@@ -96,7 +96,7 @@ class ScrollTimer @AssistedInject constructor(
|
|||||||
if (!listener.isReaderResumed()) {
|
if (!listener.isReaderResumed()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (!listener.scrollBy(1)) {
|
if (!listener.scrollBy(1, false)) {
|
||||||
accumulator += delayMs
|
accumulator += delayMs
|
||||||
}
|
}
|
||||||
if (accumulator >= pageSwitchDelay) {
|
if (accumulator >= pageSwitchDelay) {
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ class ColorFilterConfigActivity :
|
|||||||
|
|
||||||
fun newIntent(context: Context, manga: Manga, page: MangaPage) =
|
fun newIntent(context: Context, manga: Manga, page: MangaPage) =
|
||||||
Intent(context, ColorFilterConfigActivity::class.java)
|
Intent(context, ColorFilterConfigActivity::class.java)
|
||||||
.putExtra(EXTRA_MANGA, ParcelableManga(manga, withChapters = false))
|
.putExtra(EXTRA_MANGA, ParcelableManga(manga))
|
||||||
.putExtra(EXTRA_PAGES, ParcelableMangaPage(page))
|
.putExtra(EXTRA_PAGES, ParcelableMangaPage(page))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ class ReaderSettings(
|
|||||||
val isPagesNumbersEnabled: Boolean
|
val isPagesNumbersEnabled: Boolean
|
||||||
get() = settings.isPagesNumbersEnabled
|
get() = settings.isPagesNumbersEnabled
|
||||||
|
|
||||||
|
val isZoomControlsEnabled: Boolean
|
||||||
|
get() = settings.isReaderZoomButtonsEnabled
|
||||||
|
|
||||||
fun applyBackground(view: View) {
|
fun applyBackground(view: View) {
|
||||||
val bg = settings.readerBackground
|
val bg = settings.readerBackground
|
||||||
view.background = bg.resolve(view.context)
|
view.background = bg.resolve(view.context)
|
||||||
@@ -74,6 +77,7 @@ class ReaderSettings(
|
|||||||
key == AppSettings.KEY_ZOOM_MODE ||
|
key == AppSettings.KEY_ZOOM_MODE ||
|
||||||
key == AppSettings.KEY_PAGES_NUMBERS ||
|
key == AppSettings.KEY_PAGES_NUMBERS ||
|
||||||
key == AppSettings.KEY_WEBTOON_ZOOM ||
|
key == AppSettings.KEY_WEBTOON_ZOOM ||
|
||||||
|
key == AppSettings.KEY_READER_ZOOM_BUTTONS ||
|
||||||
key == AppSettings.KEY_READER_BACKGROUND
|
key == AppSettings.KEY_READER_BACKGROUND
|
||||||
) {
|
) {
|
||||||
notifyChanged()
|
notifyChanged()
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
|||||||
abstract class BasePageHolder<B : ViewBinding>(
|
abstract class BasePageHolder<B : ViewBinding>(
|
||||||
protected val binding: B,
|
protected val binding: B,
|
||||||
loader: PageLoader,
|
loader: PageLoader,
|
||||||
private val settings: ReaderSettings,
|
protected val settings: ReaderSettings,
|
||||||
networkState: NetworkState,
|
networkState: NetworkState,
|
||||||
exceptionResolver: ExceptionResolver,
|
exceptionResolver: ExceptionResolver,
|
||||||
) : RecyclerView.ViewHolder(binding.root), PageHolderDelegate.Callback {
|
) : RecyclerView.ViewHolder(binding.root), PageHolderDelegate.Callback {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ abstract class BaseReaderFragment<B : ViewBinding> : BaseFragment<B>() {
|
|||||||
|
|
||||||
abstract fun switchPageTo(position: Int, smooth: Boolean)
|
abstract fun switchPageTo(position: Int, smooth: Boolean)
|
||||||
|
|
||||||
open fun scrollBy(delta: Int): Boolean = false
|
open fun scrollBy(delta: Int, smooth: Boolean): Boolean = false
|
||||||
|
|
||||||
abstract fun getCurrentState(): ReaderState?
|
abstract fun getCurrentState(): ReaderState?
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
package org.koitharu.kotatsu.reader.ui.pager.reversed
|
package org.koitharu.kotatsu.reader.ui.pager.reversed
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.InputDevice
|
||||||
|
import android.view.KeyEvent
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.view.children
|
import androidx.core.view.children
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
@@ -23,12 +28,15 @@ import org.koitharu.kotatsu.reader.ui.pager.BaseReaderAdapter
|
|||||||
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderFragment
|
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderFragment
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.standard.NoAnimPageTransformer
|
import org.koitharu.kotatsu.reader.ui.pager.standard.NoAnimPageTransformer
|
||||||
|
import org.koitharu.kotatsu.reader.ui.pager.standard.PagerEventSupplier
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.standard.PagerReaderFragment
|
import org.koitharu.kotatsu.reader.ui.pager.standard.PagerReaderFragment
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
import kotlin.math.sign
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>() {
|
class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>(),
|
||||||
|
View.OnGenericMotionListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var networkState: NetworkState
|
lateinit var networkState: NetworkState
|
||||||
@@ -47,6 +55,11 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
|
|||||||
adapter = readerAdapter
|
adapter = readerAdapter
|
||||||
offscreenPageLimit = 2
|
offscreenPageLimit = 2
|
||||||
doOnPageChanged(::notifyPageChanged)
|
doOnPageChanged(::notifyPageChanged)
|
||||||
|
setOnGenericMotionListener(this@ReversedReaderFragment)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
recyclerView?.defaultFocusHighlightEnabled = false
|
||||||
|
}
|
||||||
|
PagerEventSupplier(this).attach()
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.pageAnimation.observe(viewLifecycleOwner) {
|
viewModel.pageAnimation.observe(viewLifecycleOwner) {
|
||||||
@@ -69,6 +82,20 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
|
|||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onGenericMotion(v: View?, event: MotionEvent): Boolean {
|
||||||
|
if (event.source and InputDevice.SOURCE_CLASS_POINTER != 0) {
|
||||||
|
if (event.actionMasked == MotionEvent.ACTION_SCROLL) {
|
||||||
|
val axisValue = event.getAxisValue(MotionEvent.AXIS_VSCROLL)
|
||||||
|
val withCtrl = event.metaState and KeyEvent.META_CTRL_MASK != 0
|
||||||
|
if (!withCtrl) {
|
||||||
|
switchPageBy(-axisValue.sign.toInt())
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateAdapter() = ReversedPagesAdapter(
|
override fun onCreateAdapter() = ReversedPagesAdapter(
|
||||||
lifecycleOwner = viewLifecycleOwner,
|
lifecycleOwner = viewLifecycleOwner,
|
||||||
loader = pageLoader,
|
loader = pageLoader,
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ open class PageHolder(
|
|||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
bindingInfo.buttonErrorDetails.setOnClickListener(this)
|
bindingInfo.buttonErrorDetails.setOnClickListener(this)
|
||||||
binding.textViewNumber.isVisible = settings.isPagesNumbersEnabled
|
binding.textViewNumber.isVisible = settings.isPagesNumbersEnabled
|
||||||
|
binding.zoomControl.listener = SsivZoomListener(binding.ssiv)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onConfigChanged() {
|
||||||
|
super.onConfigChanged()
|
||||||
|
binding.zoomControl.isVisible = settings.isZoomControlsEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.koitharu.kotatsu.reader.ui.pager.standard
|
||||||
|
|
||||||
|
import android.view.KeyEvent
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.view.children
|
||||||
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
||||||
|
|
||||||
|
class PagerEventSupplier(private val pager: ViewPager2) : View.OnKeyListener {
|
||||||
|
|
||||||
|
fun attach() {
|
||||||
|
pager.recyclerView?.setOnKeyListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onKey(v: View?, keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
|
val rootView = pager.recyclerView?.findViewHolderForAdapterPosition(pager.currentItem)?.itemView as? ViewGroup
|
||||||
|
?: return false
|
||||||
|
return rootView.children.firstNotNullOfOrNull { x ->
|
||||||
|
x as? SubsamplingScaleImageView
|
||||||
|
}?.dispatchKeyEvent(event) == true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
package org.koitharu.kotatsu.reader.ui.pager.standard
|
package org.koitharu.kotatsu.reader.ui.pager.standard
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.InputDevice
|
||||||
|
import android.view.KeyEvent
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.view.children
|
import androidx.core.view.children
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
@@ -24,9 +29,11 @@ import org.koitharu.kotatsu.reader.ui.pager.BaseReaderFragment
|
|||||||
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
import kotlin.math.sign
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>() {
|
class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>(),
|
||||||
|
View.OnGenericMotionListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var networkState: NetworkState
|
lateinit var networkState: NetworkState
|
||||||
@@ -39,12 +46,20 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>()
|
|||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
) = FragmentReaderStandardBinding.inflate(inflater, container, false)
|
) = FragmentReaderStandardBinding.inflate(inflater, container, false)
|
||||||
|
|
||||||
override fun onViewBindingCreated(binding: FragmentReaderStandardBinding, savedInstanceState: Bundle?) {
|
override fun onViewBindingCreated(
|
||||||
|
binding: FragmentReaderStandardBinding,
|
||||||
|
savedInstanceState: Bundle?,
|
||||||
|
) {
|
||||||
super.onViewBindingCreated(binding, savedInstanceState)
|
super.onViewBindingCreated(binding, savedInstanceState)
|
||||||
with(binding.pager) {
|
with(binding.pager) {
|
||||||
adapter = readerAdapter
|
adapter = readerAdapter
|
||||||
offscreenPageLimit = 2
|
offscreenPageLimit = 2
|
||||||
doOnPageChanged(::notifyPageChanged)
|
doOnPageChanged(::notifyPageChanged)
|
||||||
|
setOnGenericMotionListener(this@PagerReaderFragment)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
recyclerView?.defaultFocusHighlightEnabled = false
|
||||||
|
}
|
||||||
|
PagerEventSupplier(this).attach()
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.pageAnimation.observe(viewLifecycleOwner) {
|
viewModel.pageAnimation.observe(viewLifecycleOwner) {
|
||||||
@@ -67,28 +82,43 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>()
|
|||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun onPagesChanged(pages: List<ReaderPage>, pendingState: ReaderState?) = coroutineScope {
|
override fun onGenericMotion(v: View?, event: MotionEvent): Boolean {
|
||||||
val items = async {
|
if (event.source and InputDevice.SOURCE_CLASS_POINTER != 0) {
|
||||||
requireAdapter().setItems(pages)
|
if (event.actionMasked == MotionEvent.ACTION_SCROLL) {
|
||||||
yield()
|
val axisValue = event.getAxisValue(MotionEvent.AXIS_VSCROLL)
|
||||||
}
|
val withCtrl = event.metaState and KeyEvent.META_CTRL_MASK != 0
|
||||||
if (pendingState != null) {
|
if (!withCtrl) {
|
||||||
val position = pages.indexOfFirst {
|
switchPageBy(-axisValue.sign.toInt())
|
||||||
it.chapterId == pendingState.chapterId && it.index == pendingState.page
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
items.await()
|
|
||||||
if (position != -1) {
|
|
||||||
requireViewBinding().pager.setCurrentItem(position, false)
|
|
||||||
notifyPageChanged(position)
|
|
||||||
} else {
|
|
||||||
Snackbar.make(requireView(), R.string.not_found_404, Snackbar.LENGTH_SHORT)
|
|
||||||
.show()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
items.await()
|
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun onPagesChanged(pages: List<ReaderPage>, pendingState: ReaderState?) =
|
||||||
|
coroutineScope {
|
||||||
|
val items = async {
|
||||||
|
requireAdapter().setItems(pages)
|
||||||
|
yield()
|
||||||
|
}
|
||||||
|
if (pendingState != null) {
|
||||||
|
val position = pages.indexOfFirst {
|
||||||
|
it.chapterId == pendingState.chapterId && it.index == pendingState.page
|
||||||
|
}
|
||||||
|
items.await()
|
||||||
|
if (position != -1) {
|
||||||
|
requireViewBinding().pager.setCurrentItem(position, false)
|
||||||
|
notifyPageChanged(position)
|
||||||
|
} else {
|
||||||
|
Snackbar.make(requireView(), R.string.not_found_404, Snackbar.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
items.await()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateAdapter() = PagesAdapter(
|
override fun onCreateAdapter() = PagesAdapter(
|
||||||
lifecycleOwner = viewLifecycleOwner,
|
lifecycleOwner = viewLifecycleOwner,
|
||||||
loader = pageLoader,
|
loader = pageLoader,
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.koitharu.kotatsu.reader.ui.pager.standard
|
||||||
|
|
||||||
|
import android.view.animation.DecelerateInterpolator
|
||||||
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
|
import org.koitharu.kotatsu.core.ui.widgets.ZoomControl
|
||||||
|
|
||||||
|
class SsivZoomListener(
|
||||||
|
private val ssiv: SubsamplingScaleImageView,
|
||||||
|
) : ZoomControl.ZoomControlListener {
|
||||||
|
|
||||||
|
override fun onZoomIn() {
|
||||||
|
scaleBy(1.2f)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onZoomOut() {
|
||||||
|
scaleBy(0.8f)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun scaleBy(factor: Float) {
|
||||||
|
val center = ssiv.getCenter() ?: return
|
||||||
|
val newScale = ssiv.scale * factor
|
||||||
|
ssiv.animateScaleAndCenter(newScale, center)?.apply {
|
||||||
|
withDuration(ssiv.resources.getInteger(android.R.integer.config_shortAnimTime).toLong())
|
||||||
|
withInterpolator(DecelerateInterpolator())
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,8 +12,8 @@ class WebtoonFrameLayout @JvmOverloads constructor(
|
|||||||
@AttrRes defStyleAttr: Int = 0,
|
@AttrRes defStyleAttr: Int = 0,
|
||||||
) : FrameLayout(context, attrs, defStyleAttr) {
|
) : FrameLayout(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
val target by lazy(LazyThreadSafetyMode.NONE) {
|
val target: WebtoonImageView by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
findViewById<WebtoonImageView>(R.id.ssiv)
|
findViewById(R.id.ssiv)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dispatchVerticalScroll(dy: Int): Int {
|
fun dispatchVerticalScroll(dy: Int): Int {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package org.koitharu.kotatsu.reader.ui.pager.webtoon
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.PointF
|
import android.graphics.PointF
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
|
import androidx.core.view.ancestors
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
import org.koitharu.kotatsu.core.util.ext.parents
|
|
||||||
import org.koitharu.kotatsu.parsers.util.toIntUp
|
import org.koitharu.kotatsu.parsers.util.toIntUp
|
||||||
|
|
||||||
private const val SCROLL_UNKNOWN = -1
|
private const val SCROLL_UNKNOWN = -1
|
||||||
@@ -93,7 +93,7 @@ class WebtoonImageView @JvmOverloads constructor(
|
|||||||
if (oldh == h || oldw == 0 || oldh == 0 || scrollRange == SCROLL_UNKNOWN) return
|
if (oldh == h || oldw == 0 || oldh == 0 || scrollRange == SCROLL_UNKNOWN) return
|
||||||
|
|
||||||
computeScrollRange()
|
computeScrollRange()
|
||||||
val container = parents.firstNotNullOfOrNull { it as? WebtoonFrameLayout } ?: return
|
val container = ancestors.firstNotNullOfOrNull { it as? WebtoonFrameLayout } ?: return
|
||||||
val parentHeight = parentHeight()
|
val parentHeight = parentHeight()
|
||||||
if (scrollPos != 0 && container.bottom < parentHeight) {
|
if (scrollPos != 0 && container.bottom < parentHeight) {
|
||||||
scrollTo(scrollRange)
|
scrollTo(scrollRange)
|
||||||
@@ -115,6 +115,6 @@ class WebtoonImageView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun parentHeight(): Int {
|
private fun parentHeight(): Int {
|
||||||
return parents.firstNotNullOfOrNull { it as? RecyclerView }?.height ?: 0
|
return ancestors.firstNotNullOfOrNull { it as? RecyclerView }?.height ?: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package org.koitharu.kotatsu.reader.ui.pager.webtoon
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.animation.AccelerateDecelerateInterpolator
|
import android.view.animation.DecelerateInterpolator
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.os.NetworkState
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
@@ -31,7 +33,7 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var pageLoader: PageLoader
|
lateinit var pageLoader: PageLoader
|
||||||
|
|
||||||
private val scrollInterpolator = AccelerateDecelerateInterpolator()
|
private val scrollInterpolator = DecelerateInterpolator()
|
||||||
|
|
||||||
override fun onCreateViewBinding(
|
override fun onCreateViewBinding(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
@@ -45,10 +47,15 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
|
|||||||
adapter = readerAdapter
|
adapter = readerAdapter
|
||||||
addOnPageScrollListener(PageScrollListener())
|
addOnPageScrollListener(PageScrollListener())
|
||||||
}
|
}
|
||||||
|
binding.zoomControl.listener = binding.frame
|
||||||
|
|
||||||
viewModel.isWebtoonZoomEnabled.observe(viewLifecycleOwner) {
|
viewModel.isWebtoonZoomEnabled.observe(viewLifecycleOwner) {
|
||||||
binding.frame.isZoomEnable = it
|
binding.frame.isZoomEnable = it
|
||||||
}
|
}
|
||||||
|
combine(viewModel.isWebtoonZoomEnabled, viewModel.isZoomControlEnabled, Boolean::and)
|
||||||
|
.observe(viewLifecycleOwner) {
|
||||||
|
binding.zoomControl.isVisible = it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@@ -122,8 +129,12 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
|
|||||||
requireViewBinding().recyclerView.firstVisibleItemPosition = position
|
requireViewBinding().recyclerView.firstVisibleItemPosition = position
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun scrollBy(delta: Int): Boolean {
|
override fun scrollBy(delta: Int, smooth: Boolean): Boolean {
|
||||||
requireViewBinding().recyclerView.nestedScrollBy(0, delta)
|
if (smooth && isAnimationEnabled()) {
|
||||||
|
requireViewBinding().recyclerView.smoothScrollBy(0, delta, scrollInterpolator)
|
||||||
|
} else {
|
||||||
|
requireViewBinding().recyclerView.nestedScrollBy(0, delta)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,19 @@ import android.graphics.Rect
|
|||||||
import android.graphics.RectF
|
import android.graphics.RectF
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.GestureDetector
|
import android.view.GestureDetector
|
||||||
|
import android.view.InputDevice
|
||||||
|
import android.view.KeyEvent
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.ScaleGestureDetector
|
import android.view.ScaleGestureDetector
|
||||||
|
import android.view.ViewConfiguration
|
||||||
import android.view.animation.AccelerateDecelerateInterpolator
|
import android.view.animation.AccelerateDecelerateInterpolator
|
||||||
|
import android.view.animation.DecelerateInterpolator
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.OverScroller
|
import android.widget.OverScroller
|
||||||
import androidx.core.view.GestureDetectorCompat
|
import androidx.core.view.GestureDetectorCompat
|
||||||
|
import androidx.core.view.ViewConfigurationCompat
|
||||||
|
import org.koitharu.kotatsu.core.ui.widgets.ZoomControl
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.getAnimationDuration
|
||||||
|
|
||||||
private const val MAX_SCALE = 2.5f
|
private const val MAX_SCALE = 2.5f
|
||||||
private const val MIN_SCALE = 0.5f
|
private const val MIN_SCALE = 0.5f
|
||||||
@@ -21,7 +28,9 @@ class WebtoonScalingFrame @JvmOverloads constructor(
|
|||||||
context: Context,
|
context: Context,
|
||||||
attrs: AttributeSet? = null,
|
attrs: AttributeSet? = null,
|
||||||
defStyles: Int = 0,
|
defStyles: Int = 0,
|
||||||
) : FrameLayout(context, attrs, defStyles), ScaleGestureDetector.OnScaleGestureListener {
|
) : FrameLayout(context, attrs, defStyles),
|
||||||
|
ScaleGestureDetector.OnScaleGestureListener,
|
||||||
|
ZoomControl.ZoomControlListener {
|
||||||
|
|
||||||
private val targetChild by lazy(LazyThreadSafetyMode.NONE) { getChildAt(0) as WebtoonRecyclerView }
|
private val targetChild by lazy(LazyThreadSafetyMode.NONE) { getChildAt(0) as WebtoonRecyclerView }
|
||||||
|
|
||||||
@@ -40,6 +49,7 @@ class WebtoonScalingFrame @JvmOverloads constructor(
|
|||||||
private var halfHeight = 0f
|
private var halfHeight = 0f
|
||||||
private val translateBounds = RectF()
|
private val translateBounds = RectF()
|
||||||
private val targetHitRect = Rect()
|
private val targetHitRect = Rect()
|
||||||
|
private var animator: ValueAnimator? = null
|
||||||
|
|
||||||
var isZoomEnable = true
|
var isZoomEnable = true
|
||||||
set(value) {
|
set(value) {
|
||||||
@@ -77,10 +87,79 @@ class WebtoonScalingFrame @JvmOverloads constructor(
|
|||||||
return super.dispatchTouchEvent(ev)
|
return super.dispatchTouchEvent(ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
override fun onGenericMotionEvent(event: MotionEvent): Boolean {
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
if (isZoomEnable && event.source and InputDevice.SOURCE_CLASS_POINTER != 0) {
|
||||||
halfWidth = measuredWidth / 2f
|
if (event.actionMasked == MotionEvent.ACTION_SCROLL) {
|
||||||
halfHeight = measuredHeight / 2f
|
val withCtrl = event.metaState and KeyEvent.META_CTRL_MASK != 0
|
||||||
|
if (withCtrl) {
|
||||||
|
val axisValue =
|
||||||
|
event.getAxisValue(MotionEvent.AXIS_VSCROLL) * ViewConfigurationCompat.getScaledVerticalScrollFactor(
|
||||||
|
ViewConfiguration.get(context), context,
|
||||||
|
)
|
||||||
|
val newScale = (scale + axisValue).coerceIn(MIN_SCALE, MAX_SCALE)
|
||||||
|
scaleChild(newScale, event.x, event.y)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.onGenericMotionEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
|
if (!isZoomEnable) {
|
||||||
|
return super.onKeyDown(keyCode, event)
|
||||||
|
}
|
||||||
|
return when (keyCode) {
|
||||||
|
KeyEvent.KEYCODE_ZOOM_IN,
|
||||||
|
KeyEvent.KEYCODE_NUMPAD_ADD,
|
||||||
|
KeyEvent.KEYCODE_PLUS -> {
|
||||||
|
onZoomIn()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyEvent.KEYCODE_ZOOM_OUT,
|
||||||
|
KeyEvent.KEYCODE_NUMPAD_SUBTRACT,
|
||||||
|
KeyEvent.KEYCODE_MINUS -> {
|
||||||
|
onZoomOut()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyEvent.KEYCODE_ESCAPE -> {
|
||||||
|
smoothScaleTo(1f)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> super.onKeyDown(keyCode, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
|
return if (isZoomEnable) {
|
||||||
|
keyCode == KeyEvent.KEYCODE_NUMPAD_ADD
|
||||||
|
|| keyCode == KeyEvent.KEYCODE_PLUS
|
||||||
|
|| keyCode == KeyEvent.KEYCODE_NUMPAD_SUBTRACT
|
||||||
|
|| keyCode == KeyEvent.KEYCODE_MINUS
|
||||||
|
|| keyCode == KeyEvent.KEYCODE_ZOOM_IN
|
||||||
|
|| keyCode == KeyEvent.KEYCODE_ZOOM_OUT
|
||||||
|
|| keyCode == KeyEvent.KEYCODE_ESCAPE
|
||||||
|
|| super.onKeyUp(keyCode, event)
|
||||||
|
} else {
|
||||||
|
super.onKeyUp(keyCode, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||||
|
super.onSizeChanged(w, h, oldw, oldh)
|
||||||
|
halfWidth = w / 2f
|
||||||
|
halfHeight = h / 2f
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onZoomIn() {
|
||||||
|
smoothScaleTo(scale * 1.1f)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onZoomOut() {
|
||||||
|
smoothScaleTo(scale * 0.9f)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun invalidateTarget() {
|
private fun invalidateTarget() {
|
||||||
@@ -154,14 +233,33 @@ class WebtoonScalingFrame @JvmOverloads constructor(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean = true
|
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
|
||||||
|
animator?.cancel()
|
||||||
|
animator = null
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
override fun onScaleEnd(p0: ScaleGestureDetector) = Unit
|
override fun onScaleEnd(p0: ScaleGestureDetector) = Unit
|
||||||
|
|
||||||
|
private fun smoothScaleTo(target: Float) {
|
||||||
|
val newScale = target.coerceIn(MIN_SCALE, MAX_SCALE)
|
||||||
|
animator?.cancel()
|
||||||
|
animator = ValueAnimator.ofFloat(scale, newScale).apply {
|
||||||
|
setDuration(context.getAnimationDuration(android.R.integer.config_shortAnimTime))
|
||||||
|
interpolator = DecelerateInterpolator()
|
||||||
|
addUpdateListener { scaleChild(it.animatedValue as Float, halfWidth, halfHeight) }
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private inner class GestureListener : GestureDetector.SimpleOnGestureListener(), Runnable {
|
private inner class GestureListener : GestureDetector.SimpleOnGestureListener(), Runnable {
|
||||||
|
|
||||||
override fun onScroll(e1: MotionEvent?, e2: MotionEvent, distanceX: Float, distanceY: Float): Boolean {
|
override fun onScroll(
|
||||||
|
e1: MotionEvent?,
|
||||||
|
e2: MotionEvent,
|
||||||
|
distanceX: Float,
|
||||||
|
distanceY: Float,
|
||||||
|
): Boolean {
|
||||||
if (scale <= 1f) return false
|
if (scale <= 1f) return false
|
||||||
transformMatrix.postTranslate(-distanceX, -distanceY)
|
transformMatrix.postTranslate(-distanceX, -distanceY)
|
||||||
invalidateTarget()
|
invalidateTarget()
|
||||||
@@ -181,7 +279,12 @@ class WebtoonScalingFrame @JvmOverloads constructor(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFling(e1: MotionEvent?, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
|
override fun onFling(
|
||||||
|
e1: MotionEvent?,
|
||||||
|
e2: MotionEvent,
|
||||||
|
velocityX: Float,
|
||||||
|
velocityY: Float,
|
||||||
|
): Boolean {
|
||||||
if (scale <= 1) return false
|
if (scale <= 1) return false
|
||||||
|
|
||||||
overScroller.fling(
|
overScroller.fling(
|
||||||
@@ -200,7 +303,10 @@ class WebtoonScalingFrame @JvmOverloads constructor(
|
|||||||
|
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (overScroller.computeScrollOffset()) {
|
if (overScroller.computeScrollOffset()) {
|
||||||
transformMatrix.postTranslate(overScroller.currX - transX, overScroller.currY - transY)
|
transformMatrix.postTranslate(
|
||||||
|
overScroller.currX - transX,
|
||||||
|
overScroller.currY - transY,
|
||||||
|
)
|
||||||
invalidateTarget()
|
invalidateTarget()
|
||||||
postOnAnimation(this)
|
postOnAnimation(this)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.koitharu.kotatsu.core.util.ext.observe
|
|||||||
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
||||||
import org.koitharu.kotatsu.core.util.ext.plus
|
import org.koitharu.kotatsu.core.util.ext.plus
|
||||||
import org.koitharu.kotatsu.core.util.ext.showDistinct
|
import org.koitharu.kotatsu.core.util.ext.showDistinct
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.showOrHide
|
||||||
import org.koitharu.kotatsu.core.util.ext.withArgs
|
import org.koitharu.kotatsu.core.util.ext.withArgs
|
||||||
import org.koitharu.kotatsu.databinding.SheetPagesBinding
|
import org.koitharu.kotatsu.databinding.SheetPagesBinding
|
||||||
import org.koitharu.kotatsu.list.ui.MangaListSpanResolver
|
import org.koitharu.kotatsu.list.ui.MangaListSpanResolver
|
||||||
@@ -84,6 +85,7 @@ class PagesThumbnailsSheet :
|
|||||||
viewModel.thumbnails.observe(viewLifecycleOwner, ::onThumbnailsChanged)
|
viewModel.thumbnails.observe(viewLifecycleOwner, ::onThumbnailsChanged)
|
||||||
viewModel.branch.observe(viewLifecycleOwner, ::updateTitle)
|
viewModel.branch.observe(viewLifecycleOwner, ::updateTitle)
|
||||||
viewModel.onError.observeEvent(viewLifecycleOwner, SnackbarErrorObserver(binding.recyclerView, this))
|
viewModel.onError.observeEvent(viewLifecycleOwner, SnackbarErrorObserver(binding.recyclerView, this))
|
||||||
|
viewModel.isLoading.observe(viewLifecycleOwner) { binding.progressBar.showOrHide(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@@ -150,13 +152,6 @@ class PagesThumbnailsSheet :
|
|||||||
override fun onScrolledToEnd(recyclerView: RecyclerView) {
|
override fun onScrolledToEnd(recyclerView: RecyclerView) {
|
||||||
viewModel.loadNextChapter()
|
viewModel.loadNextChapter()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPostScrolled(recyclerView: RecyclerView, firstVisibleItemPosition: Int, visibleItemCount: Int) {
|
|
||||||
super.onPostScrolled(recyclerView, firstVisibleItemPosition, visibleItemCount)
|
|
||||||
if (firstVisibleItemPosition > offsetTop) {
|
|
||||||
viewModel.allowLoadAbove()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class SpanSizeLookup : GridLayoutManager.SpanSizeLookup() {
|
private inner class SpanSizeLookup : GridLayoutManager.SpanSizeLookup() {
|
||||||
@@ -190,7 +185,7 @@ class PagesThumbnailsSheet :
|
|||||||
|
|
||||||
fun show(fm: FragmentManager, manga: Manga, chapterId: Long, currentPage: Int = -1) {
|
fun show(fm: FragmentManager, manga: Manga, chapterId: Long, currentPage: Int = -1) {
|
||||||
PagesThumbnailsSheet().withArgs(3) {
|
PagesThumbnailsSheet().withArgs(3) {
|
||||||
putParcelable(ARG_MANGA, ParcelableManga(manga, withChapters = true))
|
putParcelable(ARG_MANGA, ParcelableManga(manga))
|
||||||
putLong(ARG_CHAPTER_ID, chapterId)
|
putLong(ARG_CHAPTER_ID, chapterId)
|
||||||
putInt(ARG_CURRENT_PAGE, currentPage)
|
putInt(ARG_CURRENT_PAGE, currentPage)
|
||||||
}.showDistinct(fm, TAG)
|
}.showDistinct(fm, TAG)
|
||||||
|
|||||||
@@ -1,19 +1,25 @@
|
|||||||
package org.koitharu.kotatsu.reader.ui.thumbnails
|
package org.koitharu.kotatsu.reader.ui.thumbnails
|
||||||
|
|
||||||
import androidx.lifecycle.SavedStateHandle
|
import androidx.lifecycle.SavedStateHandle
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import org.koitharu.kotatsu.core.model.findById
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.firstNotNull
|
||||||
import org.koitharu.kotatsu.core.util.ext.require
|
import org.koitharu.kotatsu.core.util.ext.require
|
||||||
import org.koitharu.kotatsu.details.domain.DoubleMangaLoadUseCase
|
import org.koitharu.kotatsu.details.domain.DoubleMangaLoadUseCase
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListHeader
|
import org.koitharu.kotatsu.list.ui.model.ListHeader
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.list.ui.model.LoadingFooter
|
|
||||||
import org.koitharu.kotatsu.parsers.util.SuspendLazy
|
|
||||||
import org.koitharu.kotatsu.reader.domain.ChaptersLoader
|
import org.koitharu.kotatsu.reader.domain.ChaptersLoader
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -22,48 +28,39 @@ class PagesThumbnailsViewModel @Inject constructor(
|
|||||||
savedStateHandle: SavedStateHandle,
|
savedStateHandle: SavedStateHandle,
|
||||||
mangaRepositoryFactory: MangaRepository.Factory,
|
mangaRepositoryFactory: MangaRepository.Factory,
|
||||||
private val chaptersLoader: ChaptersLoader,
|
private val chaptersLoader: ChaptersLoader,
|
||||||
private val doubleMangaLoadUseCase: DoubleMangaLoadUseCase,
|
doubleMangaLoadUseCase: DoubleMangaLoadUseCase,
|
||||||
) : BaseViewModel() {
|
) : BaseViewModel() {
|
||||||
|
|
||||||
private val currentPageIndex: Int = savedStateHandle[PagesThumbnailsSheet.ARG_CURRENT_PAGE] ?: -1
|
private val currentPageIndex: Int =
|
||||||
|
savedStateHandle[PagesThumbnailsSheet.ARG_CURRENT_PAGE] ?: -1
|
||||||
private val initialChapterId: Long = savedStateHandle[PagesThumbnailsSheet.ARG_CHAPTER_ID] ?: 0L
|
private val initialChapterId: Long = savedStateHandle[PagesThumbnailsSheet.ARG_CHAPTER_ID] ?: 0L
|
||||||
val manga = savedStateHandle.require<ParcelableManga>(PagesThumbnailsSheet.ARG_MANGA).manga
|
val manga = savedStateHandle.require<ParcelableManga>(PagesThumbnailsSheet.ARG_MANGA).manga
|
||||||
|
|
||||||
private val repository = mangaRepositoryFactory.create(manga.source)
|
private val repository = mangaRepositoryFactory.create(manga.source)
|
||||||
private val mangaDetails = SuspendLazy {
|
private val mangaDetails = doubleMangaLoadUseCase(manga).map {
|
||||||
doubleMangaLoadUseCase(manga).let {
|
val b = manga.chapters?.findById(initialChapterId)?.branch
|
||||||
val b = manga.chapters?.find { ch -> ch.id == initialChapterId }?.branch
|
branch.value = b
|
||||||
branch.value = b
|
it.filterChapters(b)
|
||||||
it.filterChapters(b)
|
}.withErrorHandling()
|
||||||
}
|
.stateIn(viewModelScope, SharingStarted.Lazily, null)
|
||||||
}
|
|
||||||
private var loadingJob: Job? = null
|
private var loadingJob: Job? = null
|
||||||
private var loadingPrevJob: Job? = null
|
private var loadingPrevJob: Job? = null
|
||||||
private var loadingNextJob: Job? = null
|
private var loadingNextJob: Job? = null
|
||||||
private var isLoadAboveAllowed = false
|
|
||||||
|
|
||||||
val thumbnails = MutableStateFlow<List<ListModel>>(emptyList())
|
val thumbnails = MutableStateFlow<List<ListModel>>(emptyList())
|
||||||
val branch = MutableStateFlow<String?>(null)
|
val branch = MutableStateFlow<String?>(null)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
loadingJob = launchJob(Dispatchers.Default) {
|
loadingJob = launchLoadingJob(Dispatchers.Default) {
|
||||||
chaptersLoader.init(mangaDetails.get())
|
chaptersLoader.init(viewModelScope, mangaDetails.filterNotNull())
|
||||||
|
mangaDetails.first { x -> x?.hasChapter(initialChapterId) == true }
|
||||||
chaptersLoader.loadSingleChapter(initialChapterId)
|
chaptersLoader.loadSingleChapter(initialChapterId)
|
||||||
updateList()
|
updateList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun allowLoadAbove() {
|
|
||||||
if (!isLoadAboveAllowed) {
|
|
||||||
loadingJob = launchJob(Dispatchers.Default) {
|
|
||||||
isLoadAboveAllowed = true
|
|
||||||
updateList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun loadPrevChapter() {
|
fun loadPrevChapter() {
|
||||||
if (!isLoadAboveAllowed || loadingJob?.isActive == true || loadingPrevJob?.isActive == true) {
|
if (loadingJob?.isActive == true || loadingPrevJob?.isActive == true) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
loadingPrevJob = loadPrevNextChapter(isNext = false)
|
loadingPrevJob = loadPrevNextChapter(isNext = false)
|
||||||
@@ -78,23 +75,17 @@ class PagesThumbnailsViewModel @Inject constructor(
|
|||||||
|
|
||||||
private fun loadPrevNextChapter(isNext: Boolean): Job = launchLoadingJob(Dispatchers.Default) {
|
private fun loadPrevNextChapter(isNext: Boolean): Job = launchLoadingJob(Dispatchers.Default) {
|
||||||
val currentId = (if (isNext) chaptersLoader.last() else chaptersLoader.first()).chapterId
|
val currentId = (if (isNext) chaptersLoader.last() else chaptersLoader.first()).chapterId
|
||||||
chaptersLoader.loadPrevNextChapter(mangaDetails.get(), currentId, isNext)
|
chaptersLoader.loadPrevNextChapter(mangaDetails.firstNotNull(), currentId, isNext)
|
||||||
updateList()
|
updateList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun updateList() {
|
private suspend fun updateList() {
|
||||||
val snapshot = chaptersLoader.snapshot()
|
val snapshot = chaptersLoader.snapshot()
|
||||||
val mangaChapters = mangaDetails.tryGet().getOrNull()?.chapters.orEmpty()
|
|
||||||
val hasPrevChapter = isLoadAboveAllowed && snapshot.firstOrNull()?.chapterId != mangaChapters.firstOrNull()?.id
|
|
||||||
val hasNextChapter = snapshot.lastOrNull()?.chapterId != mangaChapters.lastOrNull()?.id
|
|
||||||
val pages = buildList(snapshot.size + chaptersLoader.size + 2) {
|
val pages = buildList(snapshot.size + chaptersLoader.size + 2) {
|
||||||
if (hasPrevChapter) {
|
|
||||||
add(LoadingFooter(-1))
|
|
||||||
}
|
|
||||||
var previousChapterId = 0L
|
var previousChapterId = 0L
|
||||||
for (page in snapshot) {
|
for (page in snapshot) {
|
||||||
if (page.chapterId != previousChapterId) {
|
if (page.chapterId != previousChapterId) {
|
||||||
chaptersLoader.peekChapter(page.chapterId)?.let {
|
chaptersLoader.awaitChapter(page.chapterId)?.let {
|
||||||
add(ListHeader(it.name))
|
add(ListHeader(it.name))
|
||||||
}
|
}
|
||||||
previousChapterId = page.chapterId
|
previousChapterId = page.chapterId
|
||||||
@@ -105,9 +96,6 @@ class PagesThumbnailsViewModel @Inject constructor(
|
|||||||
page = page,
|
page = page,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (hasNextChapter) {
|
|
||||||
add(LoadingFooter(1))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
thumbnails.value = pages
|
thumbnails.value = pages
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
|||||||
import org.koitharu.kotatsu.core.ui.list.fastscroll.FastScroller
|
import org.koitharu.kotatsu.core.ui.list.fastscroll.FastScroller
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.ListItemType
|
import org.koitharu.kotatsu.list.ui.adapter.ListItemType
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.listHeaderAD
|
import org.koitharu.kotatsu.list.ui.adapter.listHeaderAD
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.loadingFooterAD
|
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListHeader
|
import org.koitharu.kotatsu.list.ui.model.ListHeader
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.reader.ui.thumbnails.PageThumbnail
|
import org.koitharu.kotatsu.reader.ui.thumbnails.PageThumbnail
|
||||||
@@ -22,7 +21,6 @@ class PageThumbnailAdapter(
|
|||||||
init {
|
init {
|
||||||
addDelegate(ListItemType.PAGE_THUMB, pageThumbnailAD(coil, lifecycleOwner, clickListener))
|
addDelegate(ListItemType.PAGE_THUMB, pageThumbnailAD(coil, lifecycleOwner, clickListener))
|
||||||
addDelegate(ListItemType.HEADER, listHeaderAD(null))
|
addDelegate(ListItemType.HEADER, listHeaderAD(null))
|
||||||
addDelegate(ListItemType.FOOTER_LOADING, loadingFooterAD())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSectionText(context: Context, position: Int): CharSequence? {
|
override fun getSectionText(context: Context, position: Int): CharSequence? {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
|||||||
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
import org.koitharu.kotatsu.core.util.ext.observe
|
||||||
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.showOrHide
|
||||||
import org.koitharu.kotatsu.databinding.ActivityScrobblerConfigBinding
|
import org.koitharu.kotatsu.databinding.ActivityScrobblerConfigBinding
|
||||||
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.TypedListSpacingDecoration
|
import org.koitharu.kotatsu.list.ui.adapter.TypedListSpacingDecoration
|
||||||
@@ -115,13 +116,7 @@ class ScrobblerConfigActivity : BaseActivity<ActivityScrobblerConfigBinding>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onLoadingStateChanged(isLoading: Boolean) {
|
private fun onLoadingStateChanged(isLoading: Boolean) {
|
||||||
viewBinding.progressBar.run {
|
viewBinding.progressBar.showOrHide(isLoading)
|
||||||
if (isLoading) {
|
|
||||||
show()
|
|
||||||
} else {
|
|
||||||
hide()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showUserDialog() {
|
private fun showUserDialog() {
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ class ScrobblingSelectorSheet :
|
|||||||
|
|
||||||
fun show(fm: FragmentManager, manga: Manga, scrobblerService: ScrobblerService?) =
|
fun show(fm: FragmentManager, manga: Manga, scrobblerService: ScrobblerService?) =
|
||||||
ScrobblingSelectorSheet().withArgs(2) {
|
ScrobblingSelectorSheet().withArgs(2) {
|
||||||
putParcelable(MangaIntent.KEY_MANGA, ParcelableManga(manga, withChapters = false))
|
putParcelable(MangaIntent.KEY_MANGA, ParcelableManga(manga))
|
||||||
if (scrobblerService != null) {
|
if (scrobblerService != null) {
|
||||||
putInt(ARG_SCROBBLER, scrobblerService.id)
|
putInt(ARG_SCROBBLER, scrobblerService.id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,14 +17,15 @@ import dagger.hilt.android.AndroidEntryPoint
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableMangaTags
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableMangaTags
|
||||||
import org.koitharu.kotatsu.core.parser.MangaIntent
|
import org.koitharu.kotatsu.core.parser.MangaIntent
|
||||||
import org.koitharu.kotatsu.core.ui.BaseActivity
|
import org.koitharu.kotatsu.core.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.core.ui.model.titleRes
|
import org.koitharu.kotatsu.core.ui.model.titleRes
|
||||||
import org.koitharu.kotatsu.core.util.ext.getParcelableExtraCompat
|
import org.koitharu.kotatsu.core.util.ext.getParcelableExtraCompat
|
||||||
import org.koitharu.kotatsu.core.util.ext.getSerializableExtraCompat
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
import org.koitharu.kotatsu.core.util.ext.observe
|
||||||
import org.koitharu.kotatsu.core.util.ext.setTextAndVisible
|
import org.koitharu.kotatsu.core.util.ext.setTextAndVisible
|
||||||
@@ -64,7 +65,7 @@ class MangaListActivity :
|
|||||||
if (viewBinding.containerFilterHeader != null) {
|
if (viewBinding.containerFilterHeader != null) {
|
||||||
viewBinding.appbar.addOnOffsetChangedListener(this)
|
viewBinding.appbar.addOnOffsetChangedListener(this)
|
||||||
}
|
}
|
||||||
val source = intent.getSerializableExtraCompat(EXTRA_SOURCE) ?: tags?.firstOrNull()?.source
|
val source = intent.getStringExtra(EXTRA_SOURCE)?.let(::MangaSource) ?: tags?.firstOrNull()?.source
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
finishAfterTransition()
|
finishAfterTransition()
|
||||||
return
|
return
|
||||||
@@ -102,7 +103,7 @@ class MangaListActivity :
|
|||||||
|
|
||||||
fun showPreview(manga: Manga): Boolean = setSideFragment(
|
fun showPreview(manga: Manga): Boolean = setSideFragment(
|
||||||
PreviewFragment::class.java,
|
PreviewFragment::class.java,
|
||||||
bundleOf(MangaIntent.KEY_MANGA to ParcelableManga(manga, true)),
|
bundleOf(MangaIntent.KEY_MANGA to ParcelableManga(manga)),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun hidePreview() = setSideFragment(FilterSheetFragment::class.java, null)
|
fun hidePreview() = setSideFragment(FilterSheetFragment::class.java, null)
|
||||||
@@ -186,11 +187,14 @@ class MangaListActivity :
|
|||||||
|
|
||||||
private const val EXTRA_TAGS = "tags"
|
private const val EXTRA_TAGS = "tags"
|
||||||
private const val EXTRA_SOURCE = "source"
|
private const val EXTRA_SOURCE = "source"
|
||||||
|
const val ACTION_MANGA_EXPLORE = "${BuildConfig.APPLICATION_ID}.action.EXPLORE_MANGA"
|
||||||
|
|
||||||
fun newIntent(context: Context, tags: Set<MangaTag>) = Intent(context, MangaListActivity::class.java)
|
fun newIntent(context: Context, tags: Set<MangaTag>) = Intent(context, MangaListActivity::class.java)
|
||||||
|
.setAction(ACTION_MANGA_EXPLORE)
|
||||||
.putExtra(EXTRA_TAGS, ParcelableMangaTags(tags))
|
.putExtra(EXTRA_TAGS, ParcelableMangaTags(tags))
|
||||||
|
|
||||||
fun newIntent(context: Context, source: MangaSource) = Intent(context, MangaListActivity::class.java)
|
fun newIntent(context: Context, source: MangaSource) = Intent(context, MangaListActivity::class.java)
|
||||||
.putExtra(EXTRA_SOURCE, source)
|
.setAction(ACTION_MANGA_EXPLORE)
|
||||||
|
.putExtra(EXTRA_SOURCE, source.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.text.Spannable
|
|||||||
import android.text.SpannableString
|
import android.text.SpannableString
|
||||||
import android.text.style.TextAppearanceSpan
|
import android.text.style.TextAppearanceSpan
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
|
import android.view.InputDevice
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.SoundEffectConstants
|
import android.view.SoundEffectConstants
|
||||||
@@ -32,7 +33,8 @@ class SearchEditText @JvmOverloads constructor(
|
|||||||
) : AppCompatEditText(context, attrs, defStyleAttr) {
|
) : AppCompatEditText(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
var searchSuggestionListener: SearchSuggestionListener? = null
|
var searchSuggestionListener: SearchSuggestionListener? = null
|
||||||
private val clearIcon = ContextCompat.getDrawable(context, materialR.drawable.abc_ic_clear_material)
|
private val clearIcon =
|
||||||
|
ContextCompat.getDrawable(context, materialR.drawable.abc_ic_clear_material)
|
||||||
private var isEmpty = text.isNullOrEmpty()
|
private var isEmpty = text.isNullOrEmpty()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -52,12 +54,25 @@ class SearchEditText @JvmOverloads constructor(
|
|||||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) {
|
if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) {
|
||||||
if (hasFocus()) {
|
if (hasFocus()) {
|
||||||
clearFocus()
|
clearFocus()
|
||||||
// return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.onKeyPreIme(keyCode, event)
|
return super.onKeyPreIme(keyCode, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
|
||||||
|
if (event.isFromSource(InputDevice.SOURCE_KEYBOARD)
|
||||||
|
&& (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER)
|
||||||
|
&& event.hasNoModifiers()
|
||||||
|
&& query.isNotEmpty()
|
||||||
|
) {
|
||||||
|
cancelLongPress()
|
||||||
|
searchSuggestionListener?.onQueryClick(query, submit = true)
|
||||||
|
clearFocus()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return super.onKeyUp(keyCode, event)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onEditorAction(actionCode: Int) {
|
override fun onEditorAction(actionCode: Int) {
|
||||||
super.onEditorAction(actionCode)
|
super.onEditorAction(actionCode)
|
||||||
if (actionCode == EditorInfo.IME_ACTION_SEARCH) {
|
if (actionCode == EditorInfo.IME_ACTION_SEARCH) {
|
||||||
@@ -88,7 +103,8 @@ class SearchEditText @JvmOverloads constructor(
|
|||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
if (event.action == MotionEvent.ACTION_UP) {
|
if (event.action == MotionEvent.ACTION_UP) {
|
||||||
val drawable = compoundDrawablesRelative[DRAWABLE_END] ?: return super.onTouchEvent(event)
|
val drawable =
|
||||||
|
compoundDrawablesRelative[DRAWABLE_END] ?: return super.onTouchEvent(event)
|
||||||
val isOnDrawable = drawable.isVisible && if (layoutDirection == LAYOUT_DIRECTION_RTL) {
|
val isOnDrawable = drawable.isVisible && if (layoutDirection == LAYOUT_DIRECTION_RTL) {
|
||||||
event.x.toInt() in paddingLeft..(drawable.bounds.width() + paddingLeft)
|
event.x.toInt() in paddingLeft..(drawable.bounds.width() + paddingLeft)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import org.koitharu.kotatsu.core.util.ext.map
|
|||||||
import org.koitharu.kotatsu.core.util.ext.postDelayed
|
import org.koitharu.kotatsu.core.util.ext.postDelayed
|
||||||
import org.koitharu.kotatsu.core.util.ext.setDefaultValueCompat
|
import org.koitharu.kotatsu.core.util.ext.setDefaultValueCompat
|
||||||
import org.koitharu.kotatsu.core.util.ext.toList
|
import org.koitharu.kotatsu.core.util.ext.toList
|
||||||
import org.koitharu.kotatsu.main.ui.MainActivity
|
|
||||||
import org.koitharu.kotatsu.parsers.util.names
|
import org.koitharu.kotatsu.parsers.util.names
|
||||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||||
import org.koitharu.kotatsu.settings.utils.ActivityListPreference
|
import org.koitharu.kotatsu.settings.utils.ActivityListPreference
|
||||||
@@ -67,6 +66,7 @@ class AppearanceSettingsFragment :
|
|||||||
}
|
}
|
||||||
setDefaultValueCompat("")
|
setDefaultValueCompat("")
|
||||||
}
|
}
|
||||||
|
bindNavSummary()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
@@ -86,7 +86,8 @@ class AppearanceSettingsFragment :
|
|||||||
}
|
}
|
||||||
|
|
||||||
AppSettings.KEY_COLOR_THEME,
|
AppSettings.KEY_COLOR_THEME,
|
||||||
AppSettings.KEY_THEME_AMOLED -> {
|
AppSettings.KEY_THEME_AMOLED,
|
||||||
|
-> {
|
||||||
postRestart()
|
postRestart()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +95,8 @@ class AppearanceSettingsFragment :
|
|||||||
AppCompatDelegate.setApplicationLocales(settings.appLocales)
|
AppCompatDelegate.setApplicationLocales(settings.appLocales)
|
||||||
}
|
}
|
||||||
|
|
||||||
AppSettings.KEY_FIRST_NAV_ITEM -> {
|
AppSettings.KEY_NAV_MAIN -> {
|
||||||
activityRecreationHandle.recreate(MainActivity::class.java)
|
bindNavSummary()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,6 +128,13 @@ class AppearanceSettingsFragment :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun bindNavSummary() {
|
||||||
|
val pref = findPreference<Preference>(AppSettings.KEY_NAV_MAIN) ?: return
|
||||||
|
pref.summary = settings.mainNavItems.joinToString {
|
||||||
|
getString(it.title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class LocaleComparator(context: Context) : Comparator<Locale> {
|
private class LocaleComparator(context: Context) : Comparator<Locale> {
|
||||||
|
|
||||||
private val deviceLocales = LocaleManagerCompat.getSystemLocales(context)
|
private val deviceLocales = LocaleManagerCompat.getSystemLocales(context)
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.koitharu.kotatsu.databinding.ActivitySettingsBinding
|
|||||||
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.settings.about.AboutSettingsFragment
|
import org.koitharu.kotatsu.settings.about.AboutSettingsFragment
|
||||||
|
import org.koitharu.kotatsu.settings.about.AppUpdateDialog
|
||||||
import org.koitharu.kotatsu.settings.sources.SourceSettingsFragment
|
import org.koitharu.kotatsu.settings.sources.SourceSettingsFragment
|
||||||
import org.koitharu.kotatsu.settings.sources.SourcesManageFragment
|
import org.koitharu.kotatsu.settings.sources.SourcesManageFragment
|
||||||
import org.koitharu.kotatsu.settings.tracker.TrackerSettingsFragment
|
import org.koitharu.kotatsu.settings.tracker.TrackerSettingsFragment
|
||||||
@@ -41,6 +42,8 @@ class SettingsActivity :
|
|||||||
AppBarOwner,
|
AppBarOwner,
|
||||||
FragmentManager.OnBackStackChangedListener {
|
FragmentManager.OnBackStackChangedListener {
|
||||||
|
|
||||||
|
val appUpdateDialog = AppUpdateDialog(this)
|
||||||
|
|
||||||
override val appBar: AppBarLayout
|
override val appBar: AppBarLayout
|
||||||
get() = viewBinding.appbar
|
get() = viewBinding.appbar
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class SyncSettingsFragment : BasePreferenceFragment(R.string.sync_settings), Fra
|
|||||||
override fun onPreferenceTreeClick(preference: Preference): Boolean {
|
override fun onPreferenceTreeClick(preference: Preference): Boolean {
|
||||||
return when (preference.key) {
|
return when (preference.key) {
|
||||||
SyncSettings.KEY_HOST -> {
|
SyncSettings.KEY_HOST -> {
|
||||||
SyncHostDialogFragment.show(childFragmentManager)
|
SyncHostDialogFragment.show(childFragmentManager, null)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.koitharu.kotatsu.core.ui.BasePreferenceFragment
|
|||||||
import org.koitharu.kotatsu.core.util.ShareHelper
|
import org.koitharu.kotatsu.core.util.ShareHelper
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
import org.koitharu.kotatsu.core.util.ext.observe
|
||||||
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
||||||
|
import org.koitharu.kotatsu.settings.SettingsActivity
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@@ -76,7 +77,7 @@ class AboutSettingsFragment : BasePreferenceFragment(R.string.about) {
|
|||||||
Snackbar.make(listView, R.string.no_update_available, Snackbar.LENGTH_SHORT).show()
|
Snackbar.make(listView, R.string.no_update_available, Snackbar.LENGTH_SHORT).show()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
AppUpdateDialog(context ?: return).show(version)
|
(activity as SettingsActivity).appUpdateDialog.show(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openLink(url: String, title: CharSequence?) {
|
private fun openLink(url: String, title: CharSequence?) {
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
package org.koitharu.kotatsu.settings.about
|
package org.koitharu.kotatsu.settings.about
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.app.DownloadManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Environment
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.core.text.buildSpannedString
|
import androidx.core.text.buildSpannedString
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
@@ -11,31 +18,71 @@ import org.koitharu.kotatsu.core.github.AppVersion
|
|||||||
import org.koitharu.kotatsu.core.util.FileSize
|
import org.koitharu.kotatsu.core.util.FileSize
|
||||||
import com.google.android.material.R as materialR
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
class AppUpdateDialog(private val context: Context) {
|
class AppUpdateDialog(private val activity: AppCompatActivity) {
|
||||||
|
|
||||||
|
private lateinit var latestVersion: AppVersion
|
||||||
|
|
||||||
|
private val permissionRequest = activity.registerForActivityResult(
|
||||||
|
ActivityResultContracts.RequestPermission(),
|
||||||
|
) {
|
||||||
|
if (it) {
|
||||||
|
downloadUpdateImpl()
|
||||||
|
} else {
|
||||||
|
openInBrowser()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun show(version: AppVersion) {
|
fun show(version: AppVersion) {
|
||||||
|
latestVersion = version
|
||||||
val message = buildSpannedString {
|
val message = buildSpannedString {
|
||||||
append(context.getString(R.string.new_version_s, version.name))
|
append(activity.getString(R.string.new_version_s, version.name))
|
||||||
appendLine()
|
appendLine()
|
||||||
append(context.getString(R.string.size_s, FileSize.BYTES.format(context, version.apkSize)))
|
append(activity.getString(R.string.size_s, FileSize.BYTES.format(activity, version.apkSize)))
|
||||||
appendLine()
|
appendLine()
|
||||||
appendLine()
|
appendLine()
|
||||||
append(Markwon.create(context).toMarkdown(version.description))
|
append(Markwon.create(activity).toMarkdown(version.description))
|
||||||
}
|
}
|
||||||
MaterialAlertDialogBuilder(
|
MaterialAlertDialogBuilder(
|
||||||
context,
|
activity,
|
||||||
materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered,
|
materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered,
|
||||||
)
|
)
|
||||||
.setTitle(R.string.app_update_available)
|
.setTitle(R.string.app_update_available)
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setIcon(R.drawable.ic_app_update)
|
.setIcon(R.drawable.ic_app_update)
|
||||||
.setPositiveButton(R.string.download) { _, _ ->
|
.setNeutralButton(R.string.open_in_browser) { _, _ ->
|
||||||
val intent = Intent(Intent.ACTION_VIEW, version.apkUrl.toUri())
|
val intent = Intent(Intent.ACTION_VIEW, version.url.toUri())
|
||||||
context.startActivity(Intent.createChooser(intent, context.getString(R.string.open_in_browser)))
|
activity.startActivity(Intent.createChooser(intent, activity.getString(R.string.open_in_browser)))
|
||||||
}
|
}.setPositiveButton(R.string.update) { _, _ ->
|
||||||
.setNegativeButton(R.string.close, null)
|
downloadUpdate()
|
||||||
|
}.setNegativeButton(android.R.string.cancel, null)
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.create()
|
.create()
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun downloadUpdate() {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
|
permissionRequest.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
|
} else {
|
||||||
|
downloadUpdateImpl()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun downloadUpdateImpl() {
|
||||||
|
val version = latestVersion
|
||||||
|
val url = version.apkUrl.toUri()
|
||||||
|
val dm = activity.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||||
|
val request = DownloadManager.Request(url)
|
||||||
|
.setTitle("${activity.getString(R.string.app_name)} v${version.name}")
|
||||||
|
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, url.lastPathSegment)
|
||||||
|
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
||||||
|
.setMimeType("application/vnd.android.package-archive")
|
||||||
|
dm.enqueue(request)
|
||||||
|
Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun openInBrowser() {
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW, latestVersion.url.toUri())
|
||||||
|
activity.startActivity(Intent.createChooser(intent, activity.getString(R.string.open_in_browser)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.koitharu.kotatsu.settings.about
|
||||||
|
|
||||||
|
import android.app.DownloadManager
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateDownloadReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
when (intent.action) {
|
||||||
|
DownloadManager.ACTION_DOWNLOAD_COMPLETE -> {
|
||||||
|
val downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0L)
|
||||||
|
if (downloadId == 0L) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val dm = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE)
|
||||||
|
installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
installIntent.setDataAndType(
|
||||||
|
dm.getUriForDownloadedFile(downloadId),
|
||||||
|
dm.getMimeTypeForDownloadedFile(downloadId),
|
||||||
|
)
|
||||||
|
installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
|
||||||
|
try {
|
||||||
|
context.startActivity(installIntent)
|
||||||
|
} catch (e: ActivityNotFoundException) {
|
||||||
|
e.printStackTraceDebug()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
package org.koitharu.kotatsu.settings.nav
|
||||||
|
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.graphics.Insets
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
|
import androidx.fragment.app.viewModels
|
||||||
|
import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.prefs.NavItem
|
||||||
|
import org.koitharu.kotatsu.core.ui.BaseFragment
|
||||||
|
import org.koitharu.kotatsu.core.ui.BaseListAdapter
|
||||||
|
import org.koitharu.kotatsu.core.ui.dialog.RecyclerViewAlertDialog
|
||||||
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.core.ui.util.RecyclerViewOwner
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.observe
|
||||||
|
import org.koitharu.kotatsu.databinding.FragmentSettingsSourcesBinding
|
||||||
|
import org.koitharu.kotatsu.list.ui.adapter.ListItemType
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.settings.nav.adapter.navAddAD
|
||||||
|
import org.koitharu.kotatsu.settings.nav.adapter.navAvailableAD
|
||||||
|
import org.koitharu.kotatsu.settings.nav.adapter.navConfigAD
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
|
class NavConfigFragment : BaseFragment<FragmentSettingsSourcesBinding>(), RecyclerViewOwner,
|
||||||
|
OnListItemClickListener<NavItem>, View.OnClickListener {
|
||||||
|
|
||||||
|
private var reorderHelper: ItemTouchHelper? = null
|
||||||
|
private val viewModel by viewModels<NavConfigViewModel>()
|
||||||
|
|
||||||
|
override val recyclerView: RecyclerView
|
||||||
|
get() = requireViewBinding().recyclerView
|
||||||
|
|
||||||
|
override fun onCreateViewBinding(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
): FragmentSettingsSourcesBinding {
|
||||||
|
return FragmentSettingsSourcesBinding.inflate(inflater, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewBindingCreated(
|
||||||
|
binding: FragmentSettingsSourcesBinding,
|
||||||
|
savedInstanceState: Bundle?,
|
||||||
|
) {
|
||||||
|
super.onViewBindingCreated(binding, savedInstanceState)
|
||||||
|
val navConfigAdapter = BaseListAdapter<ListModel>()
|
||||||
|
.addDelegate(ListItemType.NAV_ITEM, navConfigAD(this))
|
||||||
|
.addDelegate(ListItemType.FOOTER_LOADING, navAddAD(this))
|
||||||
|
with(binding.recyclerView) {
|
||||||
|
setHasFixedSize(true)
|
||||||
|
adapter = navConfigAdapter
|
||||||
|
reorderHelper = ItemTouchHelper(ReorderCallback()).also {
|
||||||
|
it.attachToRecyclerView(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
viewModel.content.observe(viewLifecycleOwner, navConfigAdapter)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
activity?.setTitle(R.string.main_screen_sections)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
reorderHelper = null
|
||||||
|
super.onDestroyView()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
|
requireViewBinding().recyclerView.updatePadding(
|
||||||
|
bottom = insets.bottom,
|
||||||
|
left = insets.left,
|
||||||
|
right = insets.right,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick(v: View) {
|
||||||
|
var dialog: DialogInterface? = null
|
||||||
|
val listener = OnListItemClickListener<NavItem> { item, _ ->
|
||||||
|
viewModel.addItem(item)
|
||||||
|
dialog?.dismiss()
|
||||||
|
}
|
||||||
|
dialog = RecyclerViewAlertDialog.Builder<NavItem>(v.context)
|
||||||
|
.setTitle(R.string.add)
|
||||||
|
.addAdapterDelegate(navAvailableAD(listener))
|
||||||
|
.setCancelable(true)
|
||||||
|
.setItems(viewModel.availableItems)
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.create()
|
||||||
|
.apply { show() }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemClick(item: NavItem, view: View) {
|
||||||
|
viewModel.removeItem(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemLongClick(item: NavItem, view: View): Boolean {
|
||||||
|
val holder = viewBinding?.recyclerView?.findContainingViewHolder(view) ?: return false
|
||||||
|
reorderHelper?.startDrag(holder)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class ReorderCallback : ItemTouchHelper.SimpleCallback(
|
||||||
|
ItemTouchHelper.DOWN or ItemTouchHelper.UP,
|
||||||
|
0,
|
||||||
|
) {
|
||||||
|
|
||||||
|
override fun onMove(
|
||||||
|
recyclerView: RecyclerView,
|
||||||
|
viewHolder: RecyclerView.ViewHolder,
|
||||||
|
target: RecyclerView.ViewHolder,
|
||||||
|
): Boolean = target.itemViewType == ListItemType.NAV_ITEM.ordinal
|
||||||
|
|
||||||
|
override fun onMoved(
|
||||||
|
recyclerView: RecyclerView,
|
||||||
|
viewHolder: RecyclerView.ViewHolder,
|
||||||
|
fromPos: Int,
|
||||||
|
target: RecyclerView.ViewHolder,
|
||||||
|
toPos: Int,
|
||||||
|
x: Int,
|
||||||
|
y: Int,
|
||||||
|
) {
|
||||||
|
super.onMoved(recyclerView, viewHolder, fromPos, target, toPos, x, y)
|
||||||
|
viewModel.reorder(fromPos, toPos)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) = Unit
|
||||||
|
|
||||||
|
override fun isLongPressDragEnabled() = false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package org.koitharu.kotatsu.settings.nav
|
||||||
|
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.cancelAndJoin
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.plus
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.core.prefs.NavItem
|
||||||
|
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
||||||
|
import org.koitharu.kotatsu.core.ui.util.ActivityRecreationHandle
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.main.ui.MainActivity
|
||||||
|
import org.koitharu.kotatsu.parsers.util.move
|
||||||
|
import org.koitharu.kotatsu.settings.nav.model.NavItemAddModel
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@HiltViewModel
|
||||||
|
class NavConfigViewModel @Inject constructor(
|
||||||
|
private val settings: AppSettings,
|
||||||
|
private val activityRecreationHandle: ActivityRecreationHandle,
|
||||||
|
) : BaseViewModel() {
|
||||||
|
|
||||||
|
private val items = MutableStateFlow(settings.mainNavItems)
|
||||||
|
|
||||||
|
val content: StateFlow<List<ListModel>> = items.map { snapshot ->
|
||||||
|
if (snapshot.size < NavItem.entries.size) {
|
||||||
|
snapshot + NavItemAddModel(snapshot.size < 5)
|
||||||
|
} else {
|
||||||
|
snapshot
|
||||||
|
}
|
||||||
|
}.stateIn(
|
||||||
|
viewModelScope + Dispatchers.Default,
|
||||||
|
SharingStarted.WhileSubscribed(5000),
|
||||||
|
emptyList()
|
||||||
|
)
|
||||||
|
|
||||||
|
private var commitJob: Job? = null
|
||||||
|
|
||||||
|
val availableItems
|
||||||
|
get() = items.value.let { snapshot ->
|
||||||
|
NavItem.entries.filterNot { x -> x in snapshot }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun reorder(fromPos: Int, toPos: Int) {
|
||||||
|
items.value = items.value.toMutableList().apply {
|
||||||
|
move(fromPos, toPos)
|
||||||
|
commit(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addItem(item: NavItem) {
|
||||||
|
items.value = items.value.plus(item).also {
|
||||||
|
commit(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeItem(item: NavItem) {
|
||||||
|
val newList = items.value.toMutableList()
|
||||||
|
newList.remove(item)
|
||||||
|
if (newList.isEmpty()) {
|
||||||
|
newList.add(NavItem.EXPLORE)
|
||||||
|
}
|
||||||
|
items.value = newList
|
||||||
|
commit(newList)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun commit(value: List<NavItem>) {
|
||||||
|
val prevJob = commitJob
|
||||||
|
commitJob = launchJob {
|
||||||
|
prevJob?.cancelAndJoin()
|
||||||
|
delay(500)
|
||||||
|
settings.mainNavItems = value
|
||||||
|
activityRecreationHandle.recreate(MainActivity::class.java)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package org.koitharu.kotatsu.settings.nav.adapter
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.view.View
|
||||||
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.prefs.NavItem
|
||||||
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.databinding.ItemNavAvailableBinding
|
||||||
|
import org.koitharu.kotatsu.databinding.ItemNavConfigBinding
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.settings.nav.model.NavItemAddModel
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
fun navConfigAD(
|
||||||
|
clickListener: OnListItemClickListener<NavItem>,
|
||||||
|
) = adapterDelegateViewBinding<NavItem, ListModel, ItemNavConfigBinding>(
|
||||||
|
{ layoutInflater, parent -> ItemNavConfigBinding.inflate(layoutInflater, parent, false) },
|
||||||
|
) {
|
||||||
|
|
||||||
|
val eventListener = object : View.OnClickListener, View.OnTouchListener {
|
||||||
|
override fun onClick(v: View) = clickListener.onItemClick(item, v)
|
||||||
|
|
||||||
|
override fun onTouch(v: View?, event: MotionEvent): Boolean =
|
||||||
|
event.actionMasked == MotionEvent.ACTION_DOWN &&
|
||||||
|
clickListener.onItemLongClick(item, itemView)
|
||||||
|
}
|
||||||
|
binding.imageViewRemove.setOnClickListener(eventListener)
|
||||||
|
binding.imageViewReorder.setOnTouchListener(eventListener)
|
||||||
|
|
||||||
|
bind {
|
||||||
|
with(binding.textViewTitle) {
|
||||||
|
setText(item.title)
|
||||||
|
setCompoundDrawablesRelativeWithIntrinsicBounds(item.icon, 0, 0, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun navAvailableAD(
|
||||||
|
clickListener: OnListItemClickListener<NavItem>,
|
||||||
|
) = adapterDelegateViewBinding<NavItem, NavItem, ItemNavAvailableBinding>(
|
||||||
|
{ layoutInflater, parent -> ItemNavAvailableBinding.inflate(layoutInflater, parent, false) },
|
||||||
|
) {
|
||||||
|
|
||||||
|
binding.root.setOnClickListener { v ->
|
||||||
|
clickListener.onItemClick(item, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
bind {
|
||||||
|
with(binding.root) {
|
||||||
|
setText(item.title)
|
||||||
|
setCompoundDrawablesRelativeWithIntrinsicBounds(item.icon, 0, 0, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun navAddAD(
|
||||||
|
clickListener: View.OnClickListener,
|
||||||
|
) = adapterDelegateViewBinding<NavItemAddModel, ListModel, ItemNavAvailableBinding>(
|
||||||
|
{ layoutInflater, parent -> ItemNavAvailableBinding.inflate(layoutInflater, parent, false) },
|
||||||
|
) {
|
||||||
|
|
||||||
|
binding.root.setOnClickListener(clickListener)
|
||||||
|
binding.root.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_add, 0, 0, 0)
|
||||||
|
|
||||||
|
bind {
|
||||||
|
with(binding.root) {
|
||||||
|
setText(if (item.canAdd) R.string.add else R.string.items_limit_exceeded)
|
||||||
|
isEnabled = item.canAdd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user