Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
81de6124f0
|
|||
|
a93bc0ed5b
|
|||
|
a1b96ebbb5
|
|||
|
6b93e49f56
|
|||
|
c88a9dff36
|
|||
|
ca47c475d3
|
|||
|
8df7fa2729
|
|||
|
ea34abb1d7
|
|||
|
c4ff37350c
|
|||
|
95547a8d03
|
|||
|
4c2197aa5d
|
|||
|
a679b6775d
|
|||
|
d3e4e97c6f
|
|||
|
d1b0af85c4
|
|||
| ce95e0657b | |||
|
|
6bb159a6d9 | ||
|
|
a75583f750 | ||
|
fff9df9609
|
|||
|
f9609edea5
|
|||
|
f1245742c0
|
|||
|
42d933ba83
|
|||
|
4df644e21f
|
|||
|
|
e4ba738c00 | ||
|
|
b7f09243aa | ||
|
|
50d4c41855 | ||
|
67adc8b681
|
|||
|
34fb4af9fe
|
|||
|
05241f73d9
|
|||
|
d666e4b967
|
|||
| b4bf607d3a | |||
|
|
a417d5aaa9 | ||
|
4b6b2c3e12
|
|||
|
51300e30bd
|
|||
|
399ac07fb3
|
|||
|
|
eeba161235 | ||
|
|
088a388812 | ||
|
|
943bba3ee8 | ||
|
18c3229200
|
|||
|
9b6f511ac6
|
|||
|
|
ad3b5dde91 | ||
|
|
ded7cdb71e | ||
|
74ca19a931
|
|||
|
2684a7384e
|
|||
|
2c561824ef
|
|||
|
61e9796269
|
|||
|
54597eb8f0
|
|||
|
|
e07ea0552f | ||
| b8e90719ce | |||
|
|
2ec716973c | ||
|
|
0000c97e6a | ||
|
|
70684de683 | ||
|
|
5a2288eb2d | ||
|
|
6a023fa976 | ||
| 3cc0fbe7bc | |||
|
b3b022807a
|
|||
|
ba0ea5a9fc
|
|||
|
ca1380e2b1
|
|||
|
05dbd11fc1
|
|||
|
aa650d44d3
|
|||
|
99b698ad12
|
|||
|
2f9c2d9ab6
|
|||
|
ab753787b0
|
|||
| 478ca351eb | |||
|
|
559b2cfd64 |
@@ -14,10 +14,10 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId 'org.koitharu.kotatsu'
|
applicationId 'org.koitharu.kotatsu'
|
||||||
minSdkVersion 21
|
minSdk = 21
|
||||||
targetSdkVersion 34
|
targetSdk = 34
|
||||||
versionCode 571
|
versionCode = 577
|
||||||
versionName '6.0-a2'
|
versionName = '6.1'
|
||||||
generatedDensities = []
|
generatedDensities = []
|
||||||
testInstrumentationRunner "org.koitharu.kotatsu.HiltTestRunner"
|
testInstrumentationRunner "org.koitharu.kotatsu.HiltTestRunner"
|
||||||
ksp {
|
ksp {
|
||||||
@@ -81,11 +81,11 @@ afterEvaluate {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
//noinspection GradleDependency
|
//noinspection GradleDependency
|
||||||
implementation('com.github.KotatsuApp:kotatsu-parsers:06a2aa6f97') {
|
implementation('com.github.KotatsuApp:kotatsu-parsers:aae3fa3b05') {
|
||||||
exclude group: 'org.json', module: 'json'
|
exclude group: 'org.json', module: 'json'
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.9.0'
|
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.9.10'
|
||||||
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'
|
||||||
|
|||||||
45
app/src/debug/kotlin/org/koitharu/kotatsu/KotatsuApp.kt
Normal file
45
app/src/debug/kotlin/org/koitharu/kotatsu/KotatsuApp.kt
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package org.koitharu.kotatsu
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.StrictMode
|
||||||
|
import androidx.fragment.app.strictmode.FragmentStrictMode
|
||||||
|
import org.koitharu.kotatsu.core.BaseApp
|
||||||
|
import org.koitharu.kotatsu.local.data.LocalMangaRepository
|
||||||
|
import org.koitharu.kotatsu.local.data.PagesCache
|
||||||
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
|
|
||||||
|
class KotatsuApp : BaseApp() {
|
||||||
|
|
||||||
|
override fun attachBaseContext(base: Context?) {
|
||||||
|
super.attachBaseContext(base)
|
||||||
|
enableStrictMode()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun enableStrictMode() {
|
||||||
|
StrictMode.setThreadPolicy(
|
||||||
|
StrictMode.ThreadPolicy.Builder()
|
||||||
|
.detectAll()
|
||||||
|
.penaltyLog()
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
|
StrictMode.setVmPolicy(
|
||||||
|
StrictMode.VmPolicy.Builder()
|
||||||
|
.detectAll()
|
||||||
|
.setClassInstanceLimit(LocalMangaRepository::class.java, 1)
|
||||||
|
.setClassInstanceLimit(PagesCache::class.java, 1)
|
||||||
|
.setClassInstanceLimit(MangaLoaderContext::class.java, 1)
|
||||||
|
.setClassInstanceLimit(PageLoader::class.java, 1)
|
||||||
|
.penaltyLog()
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
|
FragmentStrictMode.defaultPolicy = FragmentStrictMode.Policy.Builder()
|
||||||
|
.penaltyDeath()
|
||||||
|
.detectFragmentReuse()
|
||||||
|
// .detectWrongFragmentContainer() FIXME: migrate to ViewPager2
|
||||||
|
.detectRetainInstanceUsage()
|
||||||
|
.detectSetUserVisibleHint()
|
||||||
|
.detectFragmentTagUsage()
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -139,6 +139,7 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.browser.cloudflare.CloudFlareActivity"
|
android:name="org.koitharu.kotatsu.browser.cloudflare.CloudFlareActivity"
|
||||||
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
||||||
|
android:autoRemoveFromRecents="true"
|
||||||
android:windowSoftInputMode="adjustResize" />
|
android:windowSoftInputMode="adjustResize" />
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.settings.sources.auth.SourceAuthActivity"
|
android:name="org.koitharu.kotatsu.settings.sources.auth.SourceAuthActivity"
|
||||||
@@ -148,13 +149,21 @@
|
|||||||
android:name="org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesActivity"
|
android:name="org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesActivity"
|
||||||
android:label="@string/manage_categories" />
|
android:label="@string/manage_categories" />
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.widget.shelf.ShelfConfigActivity"
|
android:name="org.koitharu.kotatsu.widget.shelf.ShelfWidgetConfigActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/manga_shelf">
|
android:label="@string/manga_shelf">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.widget.recent.RecentWidgetConfigActivity"
|
||||||
|
android:exported="true"
|
||||||
|
android:label="@string/recent_manga">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.search.ui.multi.MultiSearchActivity"
|
android:name="org.koitharu.kotatsu.search.ui.multi.MultiSearchActivity"
|
||||||
android:label="@string/search" />
|
android:label="@string/search" />
|
||||||
|
|||||||
@@ -61,11 +61,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,7 +101,10 @@ 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(
|
||||||
|
viewLifecycleOwner,
|
||||||
|
SnackbarErrorObserver(binding.recyclerView, this)
|
||||||
|
)
|
||||||
viewModel.onActionDone.observeEvent(viewLifecycleOwner, ::onActionDone)
|
viewModel.onActionDone.observeEvent(viewLifecycleOwner, ::onActionDone)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,12 +148,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
|
||||||
@@ -170,7 +187,8 @@ class BookmarksFragment :
|
|||||||
private fun onActionDone(action: ReversibleAction) {
|
private fun onActionDone(action: ReversibleAction) {
|
||||||
val handle = action.handle
|
val handle = action.handle
|
||||||
val length = if (handle == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG
|
val length = if (handle == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG
|
||||||
val snackbar = Snackbar.make((activity as SnackbarOwner).snackbarHost, action.stringResId, length)
|
val snackbar =
|
||||||
|
Snackbar.make((activity as SnackbarOwner).snackbarHost, action.stringResId, length)
|
||||||
if (handle != null) {
|
if (handle != null) {
|
||||||
snackbar.setAction(R.string.undo) { handle.reverseAsync() }
|
snackbar.setAction(R.string.undo) { handle.reverseAsync() }
|
||||||
}
|
}
|
||||||
@@ -185,7 +203,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 +219,12 @@ class BookmarksFragment :
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"", ReplaceWith(
|
||||||
|
"BookmarksFragment()",
|
||||||
|
"org.koitharu.kotatsu.bookmarks.ui.BookmarksFragment"
|
||||||
|
)
|
||||||
|
)
|
||||||
fun newInstance() = BookmarksFragment()
|
fun newInstance() = BookmarksFragment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import org.koitharu.kotatsu.core.ui.image.CoverSizeResolver
|
|||||||
import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter
|
import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.core.util.ext.decodeRegion
|
import org.koitharu.kotatsu.core.util.ext.decodeRegion
|
||||||
import org.koitharu.kotatsu.core.util.ext.disposeImageRequest
|
|
||||||
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.source
|
import org.koitharu.kotatsu.core.util.ext.source
|
||||||
@@ -40,8 +39,4 @@ fun bookmarkListAD(
|
|||||||
enqueueWith(coil)
|
enqueueWith(coil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
|
||||||
binding.imageViewThumb.disposeImageRequest()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import org.koitharu.kotatsu.core.ui.image.CoverSizeResolver
|
|||||||
import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter
|
import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.core.util.ext.decodeRegion
|
import org.koitharu.kotatsu.core.util.ext.decodeRegion
|
||||||
import org.koitharu.kotatsu.core.util.ext.disposeImageRequest
|
|
||||||
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.source
|
import org.koitharu.kotatsu.core.util.ext.source
|
||||||
@@ -42,8 +41,4 @@ fun bookmarkLargeAD(
|
|||||||
}
|
}
|
||||||
binding.progressView.percent = item.percent
|
binding.progressView.percent = item.percent
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
|
||||||
binding.imageViewThumb.disposeImageRequest()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
package org.koitharu.kotatsu.browser.cloudflare
|
package org.koitharu.kotatsu.browser.cloudflare
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.core.app.NotificationChannelCompat
|
import androidx.core.app.NotificationChannelCompat
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import androidx.core.app.PendingIntentCompat
|
import androidx.core.app.PendingIntentCompat
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
|
import coil.EventListener
|
||||||
import coil.request.ErrorResult
|
import coil.request.ErrorResult
|
||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException
|
import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.checkNotificationPermission
|
||||||
import org.koitharu.kotatsu.parsers.model.ContentType
|
import org.koitharu.kotatsu.parsers.model.ContentType
|
||||||
|
|
||||||
class CaptchaNotifier(
|
class CaptchaNotifier(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
) : ImageRequest.Listener {
|
) : EventListener {
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
|
||||||
fun notify(exception: CloudFlareProtectedException) {
|
fun notify(exception: CloudFlareProtectedException) {
|
||||||
val manager = NotificationManagerCompat.from(context)
|
if (!context.checkNotificationPermission()) {
|
||||||
if (!manager.areNotificationsEnabled()) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
val manager = NotificationManagerCompat.from(context)
|
||||||
val channel = NotificationChannelCompat.Builder(CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_DEFAULT)
|
val channel = NotificationChannelCompat.Builder(CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_DEFAULT)
|
||||||
.setName(context.getString(R.string.captcha_required))
|
.setName(context.getString(R.string.captcha_required))
|
||||||
.setShowBadge(true)
|
.setShowBadge(true)
|
||||||
|
|||||||
@@ -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>() {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import coil.decode.SvgDecoder
|
|||||||
import coil.disk.DiskCache
|
import coil.disk.DiskCache
|
||||||
import coil.util.DebugLogger
|
import coil.util.DebugLogger
|
||||||
import dagger.Binds
|
import dagger.Binds
|
||||||
import dagger.Lazy
|
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
@@ -26,11 +25,13 @@ import kotlinx.coroutines.flow.SharedFlow
|
|||||||
import kotlinx.coroutines.flow.asSharedFlow
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
|
import org.koitharu.kotatsu.browser.cloudflare.CaptchaNotifier
|
||||||
import org.koitharu.kotatsu.core.cache.ContentCache
|
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,14 +41,13 @@ 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
|
||||||
import org.koitharu.kotatsu.local.data.CbzFetcher
|
import org.koitharu.kotatsu.local.data.CbzFetcher
|
||||||
import org.koitharu.kotatsu.local.data.LocalStorageChanges
|
import org.koitharu.kotatsu.local.data.LocalStorageChanges
|
||||||
import org.koitharu.kotatsu.local.domain.model.LocalManga
|
import org.koitharu.kotatsu.local.domain.model.LocalManga
|
||||||
import org.koitharu.kotatsu.main.domain.CoverRestorer
|
import org.koitharu.kotatsu.main.domain.CoverRestoreInterceptor
|
||||||
import org.koitharu.kotatsu.main.ui.protect.AppProtectHelper
|
import org.koitharu.kotatsu.main.ui.protect.AppProtectHelper
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.reader.ui.thumbnails.MangaPageFetcher
|
import org.koitharu.kotatsu.reader.ui.thumbnails.MangaPageFetcher
|
||||||
@@ -91,7 +91,7 @@ interface AppModule {
|
|||||||
mangaRepositoryFactory: MangaRepository.Factory,
|
mangaRepositoryFactory: MangaRepository.Factory,
|
||||||
imageProxyInterceptor: ImageProxyInterceptor,
|
imageProxyInterceptor: ImageProxyInterceptor,
|
||||||
pageFetcherFactory: MangaPageFetcher.Factory,
|
pageFetcherFactory: MangaPageFetcher.Factory,
|
||||||
coverRestorerProvider: Lazy<CoverRestorer>,
|
coverRestoreInterceptor: CoverRestoreInterceptor,
|
||||||
): ImageLoader {
|
): ImageLoader {
|
||||||
val diskCacheFactory = {
|
val diskCacheFactory = {
|
||||||
val rootDir = context.externalCacheDir ?: context.cacheDir
|
val rootDir = context.externalCacheDir ?: context.cacheDir
|
||||||
@@ -108,7 +108,7 @@ interface AppModule {
|
|||||||
.diskCache(diskCacheFactory)
|
.diskCache(diskCacheFactory)
|
||||||
.logger(if (BuildConfig.DEBUG) DebugLogger() else null)
|
.logger(if (BuildConfig.DEBUG) DebugLogger() else null)
|
||||||
.allowRgb565(context.isLowRamDevice())
|
.allowRgb565(context.isLowRamDevice())
|
||||||
.eventListenerFactory { coverRestorerProvider.get() }
|
.eventListener(CaptchaNotifier(context))
|
||||||
.components(
|
.components(
|
||||||
ComponentRegistry.Builder()
|
ComponentRegistry.Builder()
|
||||||
.add(SvgDecoder.Factory())
|
.add(SvgDecoder.Factory())
|
||||||
@@ -116,6 +116,7 @@ interface AppModule {
|
|||||||
.add(FaviconFetcher.Factory(context, okHttpClient, mangaRepositoryFactory))
|
.add(FaviconFetcher.Factory(context, okHttpClient, mangaRepositoryFactory))
|
||||||
.add(pageFetcherFactory)
|
.add(pageFetcherFactory)
|
||||||
.add(imageProxyInterceptor)
|
.add(imageProxyInterceptor)
|
||||||
|
.add(coverRestoreInterceptor)
|
||||||
.build(),
|
.build(),
|
||||||
).build()
|
).build()
|
||||||
}
|
}
|
||||||
@@ -160,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)
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package org.koitharu.kotatsu
|
package org.koitharu.kotatsu.core
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.StrictMode
|
|
||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.fragment.app.strictmode.FragmentStrictMode
|
|
||||||
import androidx.hilt.work.HiltWorkerFactory
|
import androidx.hilt.work.HiltWorkerFactory
|
||||||
import androidx.room.InvalidationTracker
|
import androidx.room.InvalidationTracker
|
||||||
import androidx.work.Configuration
|
import androidx.work.Configuration
|
||||||
@@ -20,21 +18,19 @@ import org.acra.config.httpSender
|
|||||||
import org.acra.data.StringFormat
|
import org.acra.data.StringFormat
|
||||||
import org.acra.ktx.initAcra
|
import org.acra.ktx.initAcra
|
||||||
import org.acra.sender.HttpSender
|
import org.acra.sender.HttpSender
|
||||||
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.os.AppValidator
|
import org.koitharu.kotatsu.core.os.AppValidator
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.util.WorkServiceStopHelper
|
import org.koitharu.kotatsu.core.util.WorkServiceStopHelper
|
||||||
import org.koitharu.kotatsu.core.util.ext.processLifecycleScope
|
import org.koitharu.kotatsu.core.util.ext.processLifecycleScope
|
||||||
import org.koitharu.kotatsu.local.data.LocalMangaRepository
|
|
||||||
import org.koitharu.kotatsu.local.data.PagesCache
|
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
|
||||||
import org.koitharu.kotatsu.settings.work.WorkScheduleManager
|
import org.koitharu.kotatsu.settings.work.WorkScheduleManager
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Provider
|
import javax.inject.Provider
|
||||||
|
|
||||||
@HiltAndroidApp
|
@HiltAndroidApp
|
||||||
class KotatsuApp : Application(), Configuration.Provider {
|
open class BaseApp : Application(), Configuration.Provider {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var databaseObservers: Set<@JvmSuppressWildcards InvalidationTracker.Observer>
|
lateinit var databaseObservers: Set<@JvmSuppressWildcards InvalidationTracker.Observer>
|
||||||
@@ -63,9 +59,6 @@ class KotatsuApp : Application(), Configuration.Provider {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
ACRA.errorReporter.putCustomData("isOriginalApp", appValidator.isOriginalApp.toString())
|
ACRA.errorReporter.putCustomData("isOriginalApp", appValidator.isOriginalApp.toString())
|
||||||
if (BuildConfig.DEBUG) {
|
|
||||||
enableStrictMode()
|
|
||||||
}
|
|
||||||
AppCompatDelegate.setDefaultNightMode(settings.theme)
|
AppCompatDelegate.setDefaultNightMode(settings.theme)
|
||||||
AppCompatDelegate.setApplicationLocales(settings.appLocales)
|
AppCompatDelegate.setApplicationLocales(settings.appLocales)
|
||||||
setupActivityLifecycleCallbacks()
|
setupActivityLifecycleCallbacks()
|
||||||
@@ -136,31 +129,4 @@ class KotatsuApp : Application(), Configuration.Provider {
|
|||||||
registerActivityLifecycleCallbacks(it)
|
registerActivityLifecycleCallbacks(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun enableStrictMode() {
|
|
||||||
StrictMode.setThreadPolicy(
|
|
||||||
StrictMode.ThreadPolicy.Builder()
|
|
||||||
.detectAll()
|
|
||||||
.penaltyLog()
|
|
||||||
.build(),
|
|
||||||
)
|
|
||||||
StrictMode.setVmPolicy(
|
|
||||||
StrictMode.VmPolicy.Builder()
|
|
||||||
.detectAll()
|
|
||||||
.setClassInstanceLimit(LocalMangaRepository::class.java, 1)
|
|
||||||
.setClassInstanceLimit(PagesCache::class.java, 1)
|
|
||||||
.setClassInstanceLimit(MangaLoaderContext::class.java, 1)
|
|
||||||
.setClassInstanceLimit(PageLoader::class.java, 1)
|
|
||||||
.penaltyLog()
|
|
||||||
.build(),
|
|
||||||
)
|
|
||||||
FragmentStrictMode.defaultPolicy = FragmentStrictMode.Policy.Builder()
|
|
||||||
.penaltyDeath()
|
|
||||||
.detectFragmentReuse()
|
|
||||||
// .detectWrongFragmentContainer() FIXME: migrate to ViewPager2
|
|
||||||
.detectRetainInstanceUsage()
|
|
||||||
.detectSetUserVisibleHint()
|
|
||||||
.detectFragmentTagUsage()
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -20,25 +20,8 @@ interface ContentCache {
|
|||||||
|
|
||||||
fun putRelatedManga(source: MangaSource, url: String, related: SafeDeferred<List<Manga>>)
|
fun putRelatedManga(source: MangaSource, url: String, related: SafeDeferred<List<Manga>>)
|
||||||
|
|
||||||
class Key(
|
data class Key(
|
||||||
val source: MangaSource,
|
val source: MangaSource,
|
||||||
val url: String,
|
val url: String,
|
||||||
) {
|
)
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as Key
|
|
||||||
|
|
||||||
if (source != other.source) return false
|
|
||||||
return url == other.url
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = source.hashCode()
|
|
||||||
result = 31 * result + url.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.room.Embedded
|
|||||||
import androidx.room.Junction
|
import androidx.room.Junction
|
||||||
import androidx.room.Relation
|
import androidx.room.Relation
|
||||||
|
|
||||||
class MangaWithTags(
|
data class MangaWithTags(
|
||||||
@Embedded val manga: MangaEntity,
|
@Embedded val manga: MangaEntity,
|
||||||
@Relation(
|
@Relation(
|
||||||
parentColumn = "manga_id",
|
parentColumn = "manga_id",
|
||||||
@@ -12,21 +12,4 @@ class MangaWithTags(
|
|||||||
associateBy = Junction(MangaTagsEntity::class)
|
associateBy = Junction(MangaTagsEntity::class)
|
||||||
)
|
)
|
||||||
val tags: List<TagEntity>,
|
val tags: List<TagEntity>,
|
||||||
) {
|
)
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as MangaWithTags
|
|
||||||
|
|
||||||
if (manga != other.manga) return false
|
|
||||||
return tags == other.tags
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = manga.hashCode()
|
|
||||||
result = 31 * result + tags.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,4 +6,8 @@ import java.util.Date
|
|||||||
class TooManyRequestExceptions(
|
class TooManyRequestExceptions(
|
||||||
val url: String,
|
val url: String,
|
||||||
val retryAt: Date?,
|
val retryAt: Date?,
|
||||||
) : IOException()
|
) : IOException() {
|
||||||
|
|
||||||
|
val retryAfter: Long
|
||||||
|
get() = if (retryAt == null) 0 else (retryAt.time - System.currentTimeMillis()).coerceAtLeast(0)
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package org.koitharu.kotatsu.core.github
|
|||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class VersionId(
|
data class VersionId(
|
||||||
val major: Int,
|
val major: Int,
|
||||||
val minor: Int,
|
val minor: Int,
|
||||||
val build: Int,
|
val build: Int,
|
||||||
@@ -30,28 +30,6 @@ class VersionId(
|
|||||||
return variantNumber.compareTo(other.variantNumber)
|
return variantNumber.compareTo(other.variantNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as VersionId
|
|
||||||
|
|
||||||
if (major != other.major) return false
|
|
||||||
if (minor != other.minor) return false
|
|
||||||
if (build != other.build) return false
|
|
||||||
if (variantType != other.variantType) return false
|
|
||||||
return variantNumber == other.variantNumber
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = major
|
|
||||||
result = 31 * result + minor
|
|
||||||
result = 31 * result + build
|
|
||||||
result = 31 * result + variantType.hashCode()
|
|
||||||
result = 31 * result + variantNumber
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun variantWeight(variantType: String) = when (variantType.lowercase(Locale.ROOT)) {
|
private fun variantWeight(variantType: String) = when (variantType.lowercase(Locale.ROOT)) {
|
||||||
"a", "alpha" -> 1
|
"a", "alpha" -> 1
|
||||||
"b", "beta" -> 2
|
"b", "beta" -> 2
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
@@ -48,10 +50,10 @@ fun Manga.getPreferredBranch(history: MangaHistory?): String? {
|
|||||||
if (groups.size == 1) {
|
if (groups.size == 1) {
|
||||||
return groups.keys.first()
|
return groups.keys.first()
|
||||||
}
|
}
|
||||||
val candidates = HashMap<String?, List<MangaChapter>>(groups.size)
|
|
||||||
for (locale in LocaleListCompat.getAdjustedDefault()) {
|
for (locale in LocaleListCompat.getAdjustedDefault()) {
|
||||||
val displayLanguage = locale.getDisplayLanguage(locale)
|
val displayLanguage = locale.getDisplayLanguage(locale)
|
||||||
val displayName = locale.getDisplayName(locale)
|
val displayName = locale.getDisplayName(locale)
|
||||||
|
val candidates = HashMap<String?, List<MangaChapter>>(3)
|
||||||
for (branch in groups.keys) {
|
for (branch in groups.keys) {
|
||||||
if (branch != null && (
|
if (branch != null && (
|
||||||
branch.contains(displayLanguage, ignoreCase = true) ||
|
branch.contains(displayLanguage, ignoreCase = true) ||
|
||||||
@@ -61,8 +63,11 @@ fun Manga.getPreferredBranch(history: MangaHistory?): String? {
|
|||||||
candidates[branch] = groups[branch] ?: continue
|
candidates[branch] = groups[branch] ?: continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (candidates.isNotEmpty()) {
|
||||||
|
return candidates.maxBy { it.value.size }.key
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return candidates.ifEmpty { groups }.maxByOrNull { it.value.size }?.key
|
return groups.maxByOrNull { it.value.size }?.key
|
||||||
}
|
}
|
||||||
|
|
||||||
val Manga.isLocal: Boolean
|
val Manga.isLocal: Boolean
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -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 ->
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.io.ObjectInputStream
|
|||||||
import java.io.ObjectOutputStream
|
import java.io.ObjectOutputStream
|
||||||
|
|
||||||
|
|
||||||
class CookieWrapper(
|
data class CookieWrapper(
|
||||||
val cookie: Cookie,
|
val cookie: Cookie,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -66,17 +66,4 @@ class CookieWrapper(
|
|||||||
fun key(): String {
|
fun key(): String {
|
||||||
return (if (cookie.secure) "https" else "http") + "://" + cookie.domain + cookie.path + "|" + cookie.name
|
return (if (cookie.secure) "https" else "http") + "://" + cookie.domain + cookie.path + "|" + cookie.name
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as CookieWrapper
|
|
||||||
|
|
||||||
return cookie == other.cookie
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
return cookie.hashCode()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()) {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import coil.network.HttpException
|
|||||||
import coil.request.Options
|
import coil.request.Options
|
||||||
import coil.size.Size
|
import coil.size.Size
|
||||||
import coil.size.pxOrElse
|
import coil.size.pxOrElse
|
||||||
|
import kotlinx.coroutines.ensureActive
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
@@ -25,11 +26,13 @@ import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException
|
|||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
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
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.writeAllCancellable
|
||||||
import org.koitharu.kotatsu.local.data.CacheDir
|
import org.koitharu.kotatsu.local.data.CacheDir
|
||||||
import org.koitharu.kotatsu.local.data.util.withExtraCloseable
|
import org.koitharu.kotatsu.local.data.util.withExtraCloseable
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.util.await
|
import org.koitharu.kotatsu.parsers.util.await
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
|
import kotlin.coroutines.coroutineContext
|
||||||
|
|
||||||
private const val FALLBACK_SIZE = 9999 // largest icon
|
private const val FALLBACK_SIZE = 9999 // largest icon
|
||||||
|
|
||||||
@@ -55,13 +58,16 @@ class FaviconFetcher(
|
|||||||
options.size.height.pxOrElse { FALLBACK_SIZE },
|
options.size.height.pxOrElse { FALLBACK_SIZE },
|
||||||
)
|
)
|
||||||
var favicons = repo.getFavicons()
|
var favicons = repo.getFavicons()
|
||||||
|
var lastError: Exception? = null
|
||||||
while (favicons.isNotEmpty()) {
|
while (favicons.isNotEmpty()) {
|
||||||
val icon = favicons.find(sizePx) ?: throwNSEE()
|
coroutineContext.ensureActive()
|
||||||
|
val icon = favicons.find(sizePx) ?: throwNSEE(lastError)
|
||||||
val response = try {
|
val response = try {
|
||||||
loadIcon(icon.url, mangaSource)
|
loadIcon(icon.url, mangaSource)
|
||||||
} catch (e: CloudFlareProtectedException) {
|
} catch (e: CloudFlareProtectedException) {
|
||||||
throw e
|
throw e
|
||||||
} catch (e: HttpException) {
|
} catch (e: HttpException) {
|
||||||
|
lastError = e
|
||||||
favicons -= icon
|
favicons -= icon
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -75,7 +81,7 @@ class FaviconFetcher(
|
|||||||
dataSource = response.toDataSource(),
|
dataSource = response.toDataSource(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
throwNSEE()
|
throwNSEE(lastError)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun loadIcon(url: String, source: MangaSource): Response {
|
private suspend fun loadIcon(url: String, source: MangaSource): Response {
|
||||||
@@ -105,14 +111,14 @@ class FaviconFetcher(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writeToDiskCache(body: ResponseBody): DiskCache.Snapshot? {
|
private suspend fun writeToDiskCache(body: ResponseBody): DiskCache.Snapshot? {
|
||||||
if (!options.diskCachePolicy.writeEnabled || body.contentLength() == 0L) {
|
if (!options.diskCachePolicy.writeEnabled || body.contentLength() == 0L) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val editor = diskCache.value?.openEditor(diskCacheKey) ?: return null
|
val editor = diskCache.value?.openEditor(diskCacheKey) ?: return null
|
||||||
try {
|
try {
|
||||||
fileSystem.write(editor.data) {
|
fileSystem.write(editor.data) {
|
||||||
body.source().readAll(this)
|
writeAllCancellable(body.source())
|
||||||
}
|
}
|
||||||
return editor.commitAndOpenSnapshot()
|
return editor.commitAndOpenSnapshot()
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
@@ -154,7 +160,13 @@ class FaviconFetcher(
|
|||||||
append(height.toString())
|
append(height.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun throwNSEE(): Nothing = throw NoSuchElementException("No favicons found")
|
private fun throwNSEE(lastError: Exception?): Nothing {
|
||||||
|
if (lastError != null) {
|
||||||
|
throw lastError
|
||||||
|
} else {
|
||||||
|
throw NoSuchElementException("No favicons found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Factory(
|
class Factory(
|
||||||
context: Context,
|
context: Context,
|
||||||
|
|||||||
@@ -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,6 +53,21 @@ 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)
|
||||||
|
|
||||||
|
var mainNavItems: List<NavItem>
|
||||||
|
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)
|
||||||
set(value) = prefs.edit { putInt(KEY_GRID_SIZE, value) }
|
set(value) = prefs.edit { putInt(KEY_GRID_SIZE, value) }
|
||||||
@@ -142,7 +159,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)
|
||||||
@@ -168,7 +189,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,14 +311,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,6 +482,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_NAV_MAIN = "nav_main"
|
||||||
|
|
||||||
// About
|
// About
|
||||||
const val KEY_APP_UPDATE = "app_update"
|
const val KEY_APP_UPDATE = "app_update"
|
||||||
|
|||||||
@@ -1,15 +1,38 @@
|
|||||||
package org.koitharu.kotatsu.core.prefs
|
package org.koitharu.kotatsu.core.prefs
|
||||||
|
|
||||||
|
import android.appwidget.AppWidgetProvider
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
|
|
||||||
private const val CATEGORY_ID = "cat_id"
|
private const val CATEGORY_ID = "cat_id"
|
||||||
|
private const val BACKGROUND = "bg"
|
||||||
|
|
||||||
class AppWidgetConfig(context: Context, val widgetId: Int) {
|
class AppWidgetConfig(
|
||||||
|
context: Context,
|
||||||
|
cls: Class<out AppWidgetProvider>,
|
||||||
|
val widgetId: Int,
|
||||||
|
) {
|
||||||
|
|
||||||
private val prefs = context.getSharedPreferences("appwidget_$widgetId", Context.MODE_PRIVATE)
|
private val prefs = context.getSharedPreferences("appwidget_${cls.simpleName}_$widgetId", Context.MODE_PRIVATE)
|
||||||
|
|
||||||
var categoryId: Long
|
var categoryId: Long
|
||||||
get() = prefs.getLong(CATEGORY_ID, 0L)
|
get() = prefs.getLong(CATEGORY_ID, 0L)
|
||||||
set(value) = prefs.edit { putLong(CATEGORY_ID, value) }
|
set(value) = prefs.edit { putLong(CATEGORY_ID, value) }
|
||||||
|
|
||||||
|
var hasBackground: Boolean
|
||||||
|
get() = prefs.getBoolean(BACKGROUND, Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
|
||||||
|
set(value) = prefs.edit { putBoolean(BACKGROUND, value) }
|
||||||
|
|
||||||
|
fun clear() {
|
||||||
|
prefs.edit { clear() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun copyFrom(other: AppWidgetConfig) {
|
||||||
|
prefs.edit {
|
||||||
|
clear()
|
||||||
|
putLong(CATEGORY_ID, other.categoryId)
|
||||||
|
putBoolean(BACKGROUND, other.hasBackground)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,8 +3,8 @@ package org.koitharu.kotatsu.core.prefs
|
|||||||
enum class ReaderMode(val id: Int) {
|
enum class ReaderMode(val id: Int) {
|
||||||
|
|
||||||
STANDARD(1),
|
STANDARD(1),
|
||||||
WEBTOON(2),
|
REVERSED(3),
|
||||||
REVERSED(3);
|
WEBTOON(2);
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package org.koitharu.kotatsu.core.ui
|
||||||
|
|
||||||
|
import android.appwidget.AppWidgetManager
|
||||||
|
import android.appwidget.AppWidgetProvider
|
||||||
|
import android.content.Context
|
||||||
|
import android.widget.RemoteViews
|
||||||
|
import androidx.annotation.CallSuper
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppWidgetConfig
|
||||||
|
|
||||||
|
abstract class BaseAppWidgetProvider : AppWidgetProvider() {
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
|
override fun onUpdate(
|
||||||
|
context: Context,
|
||||||
|
appWidgetManager: AppWidgetManager,
|
||||||
|
appWidgetIds: IntArray
|
||||||
|
) {
|
||||||
|
appWidgetIds.forEach { id ->
|
||||||
|
val config = AppWidgetConfig(context, javaClass, id)
|
||||||
|
val views = onUpdateWidget(context, config)
|
||||||
|
appWidgetManager.updateAppWidget(id, views)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDeleted(context: Context, appWidgetIds: IntArray) {
|
||||||
|
super.onDeleted(context, appWidgetIds)
|
||||||
|
for (id in appWidgetIds) {
|
||||||
|
AppWidgetConfig(context, javaClass, id).clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRestored(context: Context, oldWidgetIds: IntArray, newWidgetIds: IntArray) {
|
||||||
|
super.onRestored(context, oldWidgetIds, newWidgetIds)
|
||||||
|
if (oldWidgetIds.size != newWidgetIds.size) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for (i in oldWidgetIds.indices) {
|
||||||
|
val oldId = oldWidgetIds[i]
|
||||||
|
val newId = newWidgetIds[i]
|
||||||
|
val oldConfig = AppWidgetConfig(context, javaClass, oldId)
|
||||||
|
val newConfig = AppWidgetConfig(context, javaClass, newId)
|
||||||
|
newConfig.copyFrom(oldConfig)
|
||||||
|
oldConfig.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract fun onUpdateWidget(
|
||||||
|
context: Context,
|
||||||
|
config: AppWidgetConfig,
|
||||||
|
): RemoteViews
|
||||||
|
}
|
||||||
@@ -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())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,12 +106,7 @@ class TrimTransformation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
return this === other || (other is TrimTransformation && other.tolerance == tolerance)
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as TrimTransformation
|
|
||||||
|
|
||||||
return tolerance == other.tolerance
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
|
|||||||
@@ -20,38 +20,19 @@ sealed class DateTimeAgo {
|
|||||||
override fun equals(other: Any?): Boolean = other === JustNow
|
override fun equals(other: Any?): Boolean = other === JustNow
|
||||||
}
|
}
|
||||||
|
|
||||||
class MinutesAgo(val minutes: Int) : DateTimeAgo() {
|
data class MinutesAgo(val minutes: Int) : DateTimeAgo() {
|
||||||
|
|
||||||
override fun format(resources: Resources): String {
|
override fun format(resources: Resources): String {
|
||||||
return resources.getQuantityString(R.plurals.minutes_ago, minutes, minutes)
|
return resources.getQuantityString(R.plurals.minutes_ago, minutes, minutes)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
other as MinutesAgo
|
|
||||||
return minutes == other.minutes
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int = minutes
|
|
||||||
|
|
||||||
override fun toString() = "minutes_ago_$minutes"
|
override fun toString() = "minutes_ago_$minutes"
|
||||||
}
|
}
|
||||||
|
|
||||||
class HoursAgo(val hours: Int) : DateTimeAgo() {
|
data class HoursAgo(val hours: Int) : DateTimeAgo() {
|
||||||
override fun format(resources: Resources): String {
|
override fun format(resources: Resources): String {
|
||||||
return resources.getQuantityString(R.plurals.hours_ago, hours, hours)
|
return resources.getQuantityString(R.plurals.hours_ago, hours, hours)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
other as HoursAgo
|
|
||||||
return hours == other.hours
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int = hours
|
|
||||||
|
|
||||||
override fun toString() = "hours_ago_$hours"
|
override fun toString() = "hours_ago_$hours"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,26 +56,15 @@ sealed class DateTimeAgo {
|
|||||||
override fun equals(other: Any?): Boolean = other === Yesterday
|
override fun equals(other: Any?): Boolean = other === Yesterday
|
||||||
}
|
}
|
||||||
|
|
||||||
class DaysAgo(val days: Int) : DateTimeAgo() {
|
data class DaysAgo(val days: Int) : DateTimeAgo() {
|
||||||
|
|
||||||
override fun format(resources: Resources): String {
|
override fun format(resources: Resources): String {
|
||||||
return resources.getQuantityString(R.plurals.days_ago, days, days)
|
return resources.getQuantityString(R.plurals.days_ago, days, days)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
other as DaysAgo
|
|
||||||
return days == other.days
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int = days
|
|
||||||
|
|
||||||
override fun toString() = "days_ago_$days"
|
override fun toString() = "days_ago_$days"
|
||||||
}
|
}
|
||||||
|
|
||||||
class MonthsAgo(val months: Int) : DateTimeAgo() {
|
data class MonthsAgo(val months: Int) : DateTimeAgo() {
|
||||||
|
|
||||||
override fun format(resources: Resources): String {
|
override fun format(resources: Resources): String {
|
||||||
return if (months == 0) {
|
return if (months == 0) {
|
||||||
resources.getString(R.string.this_month)
|
resources.getString(R.string.this_month)
|
||||||
@@ -102,19 +72,6 @@ sealed class DateTimeAgo {
|
|||||||
resources.getQuantityString(R.plurals.months_ago, months, months)
|
resources.getQuantityString(R.plurals.months_ago, months, months)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as MonthsAgo
|
|
||||||
|
|
||||||
return months == other.months
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
return months
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Absolute(private val date: Date) : DateTimeAgo() {
|
class Absolute(private val date: Date) : DateTimeAgo() {
|
||||||
|
|||||||
@@ -25,4 +25,9 @@ class ActivityRecreationHandle @Inject constructor() : DefaultActivityLifecycleC
|
|||||||
val snapshot = activities.keys.toList()
|
val snapshot = activities.keys.toList()
|
||||||
snapshot.forEach { ActivityCompat.recreate(it) }
|
snapshot.forEach { ActivityCompat.recreate(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun recreate(cls: Class<out Activity>) {
|
||||||
|
val activity = activities.keys.find { x -> x.javaClass == cls } ?: return
|
||||||
|
ActivityCompat.recreate(activity)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -139,39 +139,14 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ChipModel(
|
data class ChipModel(
|
||||||
@ColorRes val tint: Int,
|
@ColorRes val tint: Int,
|
||||||
val title: CharSequence,
|
val title: CharSequence,
|
||||||
@DrawableRes val icon: Int,
|
@DrawableRes val icon: Int,
|
||||||
val isCheckable: Boolean,
|
val isCheckable: Boolean,
|
||||||
val isChecked: Boolean,
|
val isChecked: Boolean,
|
||||||
val data: Any? = null,
|
val data: Any? = null,
|
||||||
) {
|
)
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as ChipModel
|
|
||||||
|
|
||||||
if (tint != other.tint) return false
|
|
||||||
if (title != other.title) return false
|
|
||||||
if (icon != other.icon) return false
|
|
||||||
if (isCheckable != other.isCheckable) return false
|
|
||||||
if (isChecked != other.isChecked) return false
|
|
||||||
return data == other.data
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = tint.hashCode()
|
|
||||||
result = 31 * result + title.hashCode()
|
|
||||||
result = 31 * result + icon.hashCode()
|
|
||||||
result = 31 * result + isCheckable.hashCode()
|
|
||||||
result = 31 * result + isChecked.hashCode()
|
|
||||||
result = 31 * result + (data?.hashCode() ?: 0)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun interface OnChipClickListener {
|
fun interface OnChipClickListener {
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,27 +118,10 @@ class SegmentedBarView @JvmOverloads constructor(
|
|||||||
segmentsSizes.add(w)
|
segmentsSizes.add(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
class Segment(
|
data class Segment(
|
||||||
@FloatRange(from = 0.0, to = 1.0) val percent: Float,
|
@FloatRange(from = 0.0, to = 1.0) val percent: Float,
|
||||||
@ColorInt val color: Int,
|
@ColorInt val color: Int,
|
||||||
) {
|
)
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as Segment
|
|
||||||
|
|
||||||
if (percent != other.percent) return false
|
|
||||||
return color == other.color
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = percent.hashCode()
|
|
||||||
result = 31 * result + color
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class OutlineProvider : ViewOutlineProvider() {
|
private class OutlineProvider : ViewOutlineProvider() {
|
||||||
override fun getOutline(view: View, outline: Outline) {
|
override fun getOutline(view: View, outline: Outline) {
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class TipView @JvmOverloads constructor(
|
|||||||
val shapeAppearanceModel = ShapeAppearanceModel.builder(context, attrs, defStyleAttr, 0).build()
|
val shapeAppearanceModel = ShapeAppearanceModel.builder(context, attrs, defStyleAttr, 0).build()
|
||||||
background = MaterialShapeDrawable(shapeAppearanceModel).also {
|
background = MaterialShapeDrawable(shapeAppearanceModel).also {
|
||||||
it.fillColor = getColorStateList(R.styleable.TipView_cardBackgroundColor)
|
it.fillColor = getColorStateList(R.styleable.TipView_cardBackgroundColor)
|
||||||
?: context.getThemeColorStateList(materialR.attr.colorBackgroundFloating)
|
?: context.getThemeColorStateList(R.attr.m3ColorExploreButton)
|
||||||
it.strokeWidth = getDimension(R.styleable.TipView_strokeWidth, 0f)
|
it.strokeWidth = getDimension(R.styleable.TipView_strokeWidth, 0f)
|
||||||
it.strokeColor = getColorStateList(R.styleable.TipView_strokeColor)
|
it.strokeColor = getColorStateList(R.styleable.TipView_strokeColor)
|
||||||
it.elevation = getDimension(R.styleable.TipView_elevation, 0f)
|
it.elevation = getDimension(R.styleable.TipView_elevation, 0f)
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package org.koitharu.kotatsu.core.util
|
||||||
|
|
||||||
|
import androidx.collection.ArrayMap
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
|
||||||
|
class CompositeMutex2<T : Any> : Set<T> {
|
||||||
|
|
||||||
|
private val delegates = ArrayMap<T, Mutex>()
|
||||||
|
|
||||||
|
override val size: Int
|
||||||
|
get() = delegates.size
|
||||||
|
|
||||||
|
override fun contains(element: T): Boolean {
|
||||||
|
return delegates.containsKey(element)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun containsAll(elements: Collection<T>): Boolean {
|
||||||
|
return elements.all { x -> delegates.containsKey(x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isEmpty(): Boolean {
|
||||||
|
return delegates.isEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun iterator(): Iterator<T> {
|
||||||
|
return delegates.keys.iterator()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun lock(element: T) {
|
||||||
|
val mutex = synchronized(delegates) {
|
||||||
|
delegates.getOrPut(element) {
|
||||||
|
Mutex()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mutex.lock()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unlock(element: T) {
|
||||||
|
synchronized(delegates) {
|
||||||
|
delegates.remove(element)?.unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -102,7 +102,7 @@ fun <T> SharedPreferences.observe(key: String, valueProducer: suspend () -> T):
|
|||||||
}
|
}
|
||||||
}.distinctUntilChanged()
|
}.distinctUntilChanged()
|
||||||
|
|
||||||
fun Lifecycle.postDelayed(runnable: Runnable, delay: Long) {
|
fun Lifecycle.postDelayed(delay: Long, runnable: Runnable) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
delay(delay)
|
delay(delay)
|
||||||
runnable.run()
|
runnable.run()
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import coil.request.SuccessResult
|
|||||||
import coil.util.CoilUtils
|
import coil.util.CoilUtils
|
||||||
import com.google.android.material.progressindicator.BaseProgressIndicator
|
import com.google.android.material.progressindicator.BaseProgressIndicator
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.browser.cloudflare.CaptchaNotifier
|
|
||||||
import org.koitharu.kotatsu.core.ui.image.RegionBitmapDecoder
|
import org.koitharu.kotatsu.core.ui.image.RegionBitmapDecoder
|
||||||
import org.koitharu.kotatsu.core.util.progress.ImageRequestIndicatorListener
|
import org.koitharu.kotatsu.core.util.progress.ImageRequestIndicatorListener
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
@@ -29,7 +28,6 @@ fun ImageView.newImageRequest(lifecycleOwner: LifecycleOwner, data: Any?): Image
|
|||||||
.data(data)
|
.data(data)
|
||||||
.lifecycle(lifecycleOwner)
|
.lifecycle(lifecycleOwner)
|
||||||
.crossfade(context)
|
.crossfade(context)
|
||||||
.addListener(CaptchaNotifier(context.applicationContext))
|
|
||||||
.target(this)
|
.target(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import androidx.lifecycle.ProcessLifecycleOwner
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import dagger.hilt.android.lifecycle.RetainedLifecycle
|
import dagger.hilt.android.lifecycle.RetainedLifecycle
|
||||||
import kotlinx.coroutines.CancellableContinuation
|
import kotlinx.coroutines.CancellableContinuation
|
||||||
|
import kotlinx.coroutines.Deferred
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
import org.koitharu.kotatsu.core.util.RetainedLifecycleCoroutineScope
|
import org.koitharu.kotatsu.core.util.RetainedLifecycleCoroutineScope
|
||||||
@@ -70,3 +71,11 @@ private fun Lifecycle.removeObserverFromAnyThread(observer: LifecycleObserver) {
|
|||||||
removeObserver(observer)
|
removeObserver(observer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T> Deferred<T>.getCompletionResultOrNull(): Result<T>? = if (isCompleted) {
|
||||||
|
getCompletionExceptionOrNull()?.let { error ->
|
||||||
|
Result.failure(error)
|
||||||
|
} ?: Result.success(getCompleted())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ import android.view.ViewGroup
|
|||||||
import android.view.ViewParent
|
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.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
|
||||||
@@ -155,3 +156,11 @@ 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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<DoubleManga> {
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -369,7 +369,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> {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import android.text.format.DateUtils
|
|||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
|
||||||
class ChapterListItem(
|
data class ChapterListItem(
|
||||||
val chapter: MangaChapter,
|
val chapter: MangaChapter,
|
||||||
val flags: Int,
|
val flags: Int,
|
||||||
private val uploadDateMs: Long,
|
private val uploadDateMs: Long,
|
||||||
@@ -66,24 +66,6 @@ class ChapterListItem(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as ChapterListItem
|
|
||||||
|
|
||||||
if (chapter != other.chapter) return false
|
|
||||||
if (flags != other.flags) return false
|
|
||||||
return uploadDateMs == other.uploadDateMs
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = chapter.hashCode()
|
|
||||||
result = 31 * result + flags
|
|
||||||
result = 31 * result + uploadDateMs.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
const val FLAG_UNREAD = 2
|
const val FLAG_UNREAD = 2
|
||||||
|
|||||||
@@ -3,35 +3,14 @@ package org.koitharu.kotatsu.details.ui.model
|
|||||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
|
||||||
class HistoryInfo(
|
data class HistoryInfo(
|
||||||
val totalChapters: Int,
|
val totalChapters: Int,
|
||||||
val currentChapter: Int,
|
val currentChapter: Int,
|
||||||
val history: MangaHistory?,
|
val history: MangaHistory?,
|
||||||
val isIncognitoMode: Boolean,
|
val isIncognitoMode: Boolean,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val isValid: Boolean
|
val isValid: Boolean
|
||||||
get() = totalChapters >= 0
|
get() = totalChapters >= 0
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as HistoryInfo
|
|
||||||
|
|
||||||
if (totalChapters != other.totalChapters) return false
|
|
||||||
if (currentChapter != other.currentChapter) return false
|
|
||||||
if (history != other.history) return false
|
|
||||||
return isIncognitoMode == other.isIncognitoMode
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = totalChapters
|
|
||||||
result = 31 * result + currentChapter
|
|
||||||
result = 31 * result + (history?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + isIncognitoMode.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun HistoryInfo(
|
fun HistoryInfo(
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package org.koitharu.kotatsu.details.ui.model
|
|||||||
import org.koitharu.kotatsu.list.ui.ListModelDiffCallback
|
import org.koitharu.kotatsu.list.ui.ListModelDiffCallback
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
|
||||||
class MangaBranch(
|
data class MangaBranch(
|
||||||
val name: String?,
|
val name: String?,
|
||||||
val count: Int,
|
val count: Int,
|
||||||
val isSelected: Boolean,
|
val isSelected: Boolean,
|
||||||
@@ -21,24 +21,6 @@ class MangaBranch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as MangaBranch
|
|
||||||
|
|
||||||
if (name != other.name) return false
|
|
||||||
if (count != other.count) return false
|
|
||||||
return isSelected == other.isSelected
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = name.hashCode()
|
|
||||||
result = 31 * result + count
|
|
||||||
result = 31 * result + isSelected.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "$name: $count"
|
return "$name: $count"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import androidx.lifecycle.LifecycleOwner
|
|||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.util.ext.disposeImageRequest
|
|
||||||
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.databinding.ItemScrobblingInfoBinding
|
import org.koitharu.kotatsu.databinding.ItemScrobblingInfoBinding
|
||||||
@@ -37,8 +36,4 @@ fun scrobblingInfoAD(
|
|||||||
context.resources.getStringArray(R.array.scrobbling_statuses).getOrNull(it.ordinal)
|
context.resources.getStringArray(R.array.scrobbling_statuses).getOrNull(it.ordinal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
|
||||||
binding.imageViewCover.disposeImageRequest()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import coil.ImageLoader
|
|||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
||||||
import org.koitharu.kotatsu.core.util.ext.disposeImageRequest
|
|
||||||
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.source
|
import org.koitharu.kotatsu.core.util.ext.source
|
||||||
@@ -135,8 +134,4 @@ fun downloadItemAD(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
|
||||||
binding.imageViewCover.disposeImageRequest()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import org.koitharu.kotatsu.parsers.model.Manga
|
|||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
class DownloadItemModel(
|
data class DownloadItemModel(
|
||||||
val id: UUID,
|
val id: UUID,
|
||||||
val workState: WorkInfo.State,
|
val workState: WorkInfo.State,
|
||||||
val isIndeterminate: Boolean,
|
val isIndeterminate: Boolean,
|
||||||
@@ -64,38 +64,4 @@ class DownloadItemModel(
|
|||||||
else -> super.getChangePayload(previousState)
|
else -> super.getChangePayload(previousState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as DownloadItemModel
|
|
||||||
|
|
||||||
if (id != other.id) return false
|
|
||||||
if (workState != other.workState) return false
|
|
||||||
if (isIndeterminate != other.isIndeterminate) return false
|
|
||||||
if (isPaused != other.isPaused) return false
|
|
||||||
if (manga != other.manga) return false
|
|
||||||
if (error != other.error) return false
|
|
||||||
if (max != other.max) return false
|
|
||||||
if (totalChapters != other.totalChapters) return false
|
|
||||||
if (progress != other.progress) return false
|
|
||||||
if (eta != other.eta) return false
|
|
||||||
return timestamp == other.timestamp
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = id.hashCode()
|
|
||||||
result = 31 * result + workState.hashCode()
|
|
||||||
result = 31 * result + isIndeterminate.hashCode()
|
|
||||||
result = 31 * result + isPaused.hashCode()
|
|
||||||
result = 31 * result + manga.hashCode()
|
|
||||||
result = 31 * result + (error?.hashCode() ?: 0)
|
|
||||||
result = 31 * result + max
|
|
||||||
result = 31 * result + totalChapters
|
|
||||||
result = 31 * result + progress
|
|
||||||
result = 31 * result + eta.hashCode()
|
|
||||||
result = 31 * result + timestamp.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import okio.IOException
|
|||||||
import okio.buffer
|
import okio.buffer
|
||||||
import okio.sink
|
import okio.sink
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.exceptions.TooManyRequestExceptions
|
||||||
import org.koitharu.kotatsu.core.network.CommonHeaders
|
import org.koitharu.kotatsu.core.network.CommonHeaders
|
||||||
import org.koitharu.kotatsu.core.network.MangaHttpClient
|
import org.koitharu.kotatsu.core.network.MangaHttpClient
|
||||||
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
import org.koitharu.kotatsu.core.parser.MangaDataRepository
|
||||||
@@ -277,7 +278,12 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
publishState(currentState.copy(isPaused = false, error = null))
|
publishState(currentState.copy(isPaused = false, error = null))
|
||||||
} else {
|
} else {
|
||||||
countDown--
|
countDown--
|
||||||
delay(DOWNLOAD_ERROR_DELAY)
|
val retryDelay = if (e is TooManyRequestExceptions) {
|
||||||
|
e.retryAfter + DOWNLOAD_ERROR_DELAY
|
||||||
|
} else {
|
||||||
|
DOWNLOAD_ERROR_DELAY
|
||||||
|
}
|
||||||
|
delay(retryDelay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,14 @@ class MangaSourcesRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun setPositions(sources: List<MangaSource>) {
|
||||||
|
db.withTransaction {
|
||||||
|
for ((index, item) in sources.withIndex()) {
|
||||||
|
dao.setSortKey(item.name, index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun setPosition(source: MangaSource, index: Int) {
|
suspend fun setPosition(source: MangaSource, index: Int) {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
val all = dao.findAll().toMutableList()
|
val all = dao.findAll().toMutableList()
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import org.koitharu.kotatsu.core.ui.image.FaviconDrawable
|
|||||||
import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
||||||
import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter
|
import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.core.util.ext.disposeImageRequest
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
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
|
||||||
@@ -82,10 +81,6 @@ fun exploreRecommendationItemAD(
|
|||||||
enqueueWith(coil)
|
enqueueWith(coil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
|
||||||
binding.imageViewCover.disposeImageRequest()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun exploreSourceListItemAD(
|
fun exploreSourceListItemAD(
|
||||||
@@ -113,10 +108,6 @@ fun exploreSourceListItemAD(
|
|||||||
enqueueWith(coil)
|
enqueueWith(coil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
|
||||||
binding.imageViewIcon.disposeImageRequest()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun exploreSourceGridItemAD(
|
fun exploreSourceGridItemAD(
|
||||||
@@ -144,8 +135,4 @@ fun exploreSourceGridItemAD(
|
|||||||
enqueueWith(coil)
|
enqueueWith(coil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
|
||||||
binding.imageViewIcon.disposeImageRequest()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,11 @@ package org.koitharu.kotatsu.explore.ui.model
|
|||||||
|
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
|
||||||
class ExploreButtons(
|
data class ExploreButtons(
|
||||||
val isRandomLoading: Boolean,
|
val isRandomLoading: Boolean,
|
||||||
) : ListModel {
|
) : ListModel {
|
||||||
|
|
||||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||||
return other is ExploreButtons
|
return other is ExploreButtons
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as ExploreButtons
|
|
||||||
|
|
||||||
return isRandomLoading == other.isRandomLoading
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
return isRandomLoading.hashCode()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package org.koitharu.kotatsu.explore.ui.model
|
|||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
|
||||||
class MangaSourceItem(
|
data class MangaSourceItem(
|
||||||
val source: MangaSource,
|
val source: MangaSource,
|
||||||
val isGrid: Boolean,
|
val isGrid: Boolean,
|
||||||
) : ListModel {
|
) : ListModel {
|
||||||
@@ -11,20 +11,4 @@ class MangaSourceItem(
|
|||||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||||
return other is MangaSourceItem && other.source == source
|
return other is MangaSourceItem && other.source == source
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as MangaSourceItem
|
|
||||||
|
|
||||||
if (source != other.source) return false
|
|
||||||
return isGrid == other.isGrid
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = source.hashCode()
|
|
||||||
result = 31 * result + isGrid.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import org.koitharu.kotatsu.parsers.model.Manga
|
|||||||
data class RecommendationsItem(
|
data class RecommendationsItem(
|
||||||
val manga: Manga
|
val manga: Manga
|
||||||
) : ListModel {
|
) : ListModel {
|
||||||
|
|
||||||
val summary: String = manga.tags.joinToString { it.title }
|
val summary: String = manga.tags.joinToString { it.title }
|
||||||
|
|
||||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||||
|
|||||||
@@ -3,31 +3,10 @@ package org.koitharu.kotatsu.favourites.domain.model
|
|||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.util.find
|
import org.koitharu.kotatsu.parsers.util.find
|
||||||
|
|
||||||
class Cover(
|
data class Cover(
|
||||||
val url: String,
|
val url: String,
|
||||||
val source: String,
|
val source: String,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val mangaSource: MangaSource?
|
val mangaSource: MangaSource?
|
||||||
get() = if (source.isEmpty()) null else MangaSource.entries.find(source)
|
get() = if (source.isEmpty()) null else MangaSource.entries.find(source)
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as Cover
|
|
||||||
|
|
||||||
if (url != other.url) return false
|
|
||||||
return source == other.source
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = url.hashCode()
|
|
||||||
result = 31 * result + source.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
|
||||||
return "Cover(url='$url', source=$source)"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import org.koitharu.kotatsu.core.ui.list.ListSelectionController
|
|||||||
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.ActivityCategoriesBinding
|
import org.koitharu.kotatsu.databinding.ActivityCategoriesBinding
|
||||||
|
import org.koitharu.kotatsu.favourites.ui.FavouritesActivity
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.adapter.CategoriesAdapter
|
import org.koitharu.kotatsu.favourites.ui.categories.adapter.CategoriesAdapter
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.edit.FavouritesCategoryEditActivity
|
import org.koitharu.kotatsu.favourites.ui.categories.edit.FavouritesCategoryEditActivity
|
||||||
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
|
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
|
||||||
@@ -66,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))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +78,14 @@ class FavouriteCategoriesActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemClick(item: FavouriteCategory, view: View) {
|
override fun onItemClick(item: FavouriteCategory, view: View) {
|
||||||
|
if (selectionController.onItemClick(item.id)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val intent = FavouritesActivity.newIntent(view.context, item)
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onEditClick(item: FavouriteCategory, view: View) {
|
||||||
if (selectionController.onItemClick(item.id)) {
|
if (selectionController.onItemClick(item.id)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -112,8 +121,8 @@ class FavouriteCategoriesActivity :
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onCategoriesChanged(categories: List<ListModel>) {
|
private suspend fun onCategoriesChanged(categories: List<ListModel>) {
|
||||||
adapter.items = categories
|
adapter.emit(categories)
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +137,14 @@ class FavouriteCategoriesActivity :
|
|||||||
recyclerView: RecyclerView,
|
recyclerView: RecyclerView,
|
||||||
viewHolder: RecyclerView.ViewHolder,
|
viewHolder: RecyclerView.ViewHolder,
|
||||||
target: RecyclerView.ViewHolder,
|
target: RecyclerView.ViewHolder,
|
||||||
): Boolean = viewHolder.itemViewType == target.itemViewType
|
): Boolean {
|
||||||
|
if (viewHolder.itemViewType != target.itemViewType) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
val fromPos = viewHolder.bindingAdapterPosition
|
||||||
|
val toPos = target.bindingAdapterPosition
|
||||||
|
return fromPos != toPos && fromPos != RecyclerView.NO_POSITION && toPos != RecyclerView.NO_POSITION
|
||||||
|
}
|
||||||
|
|
||||||
override fun canDropOver(
|
override fun canDropOver(
|
||||||
recyclerView: RecyclerView,
|
recyclerView: RecyclerView,
|
||||||
@@ -153,7 +169,8 @@ class FavouriteCategoriesActivity :
|
|||||||
|
|
||||||
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
|
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
|
||||||
super.onSelectedChanged(viewHolder, actionState)
|
super.onSelectedChanged(viewHolder, actionState)
|
||||||
viewBinding.recyclerView.isNestedScrollingEnabled = actionState == ItemTouchHelper.ACTION_STATE_IDLE
|
viewBinding.recyclerView.isNestedScrollingEnabled =
|
||||||
|
actionState == ItemTouchHelper.ACTION_STATE_IDLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.favourites.ui.categories
|
package org.koitharu.kotatsu.favourites.ui.categories
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
||||||
@@ -7,4 +8,6 @@ import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
|
|||||||
interface FavouriteCategoriesListListener : OnListItemClickListener<FavouriteCategory> {
|
interface FavouriteCategoriesListListener : OnListItemClickListener<FavouriteCategory> {
|
||||||
|
|
||||||
fun onDragHandleTouch(holder: RecyclerView.ViewHolder): Boolean
|
fun onDragHandleTouch(holder: RecyclerView.ViewHolder): Boolean
|
||||||
|
|
||||||
|
fun onEditClick(item: FavouriteCategory, view: View)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,25 @@
|
|||||||
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 java.util.Collections
|
import org.koitharu.kotatsu.parsers.util.move
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
@@ -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,20 +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 items = categories.requireValue()
|
commit(snapshot)
|
||||||
val ids = items.mapNotNullTo(ArrayList(items.size)) {
|
|
||||||
(it as? CategoryListModel)?.category?.id
|
|
||||||
}
|
|
||||||
Collections.swap(ids, oldPos, newPos)
|
|
||||||
ids.remove(0L)
|
|
||||||
repository.reorderCategories(ids)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setIsVisible(ids: Set<Long>, isVisible: Boolean) {
|
fun setIsVisible(ids: Set<Long>, isVisible: Boolean) {
|
||||||
@@ -84,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,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ class CategoriesAdapter(
|
|||||||
) : BaseListAdapter<ListModel>() {
|
) : BaseListAdapter<ListModel>() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
addDelegate(ListItemType.CATEGORY_LARGE ,categoryAD(coil, lifecycleOwner, onItemClickListener))
|
addDelegate(ListItemType.CATEGORY_LARGE, categoryAD(coil, lifecycleOwner, onItemClickListener))
|
||||||
addDelegate(ListItemType.STATE_EMPTY ,emptyStateListAD(coil, lifecycleOwner, listListener))
|
addDelegate(ListItemType.STATE_EMPTY, emptyStateListAD(coil, lifecycleOwner, listListener))
|
||||||
addDelegate(ListItemType.STATE_LOADING ,loadingStateAD())
|
addDelegate(ListItemType.STATE_LOADING, loadingStateAD())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import androidx.lifecycle.LifecycleOwner
|
|||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.util.ext.disposeImageRequest
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
||||||
import org.koitharu.kotatsu.core.util.ext.getAnimationDuration
|
import org.koitharu.kotatsu.core.util.ext.getAnimationDuration
|
||||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
||||||
@@ -35,8 +34,13 @@ fun categoryAD(
|
|||||||
{ inflater, parent -> ItemCategoryBinding.inflate(inflater, parent, false) },
|
{ inflater, parent -> ItemCategoryBinding.inflate(inflater, parent, false) },
|
||||||
) {
|
) {
|
||||||
val eventListener = object : OnClickListener, OnLongClickListener, OnTouchListener {
|
val eventListener = object : OnClickListener, OnLongClickListener, OnTouchListener {
|
||||||
override fun onClick(v: View) = clickListener.onItemClick(item.category, itemView)
|
override fun onClick(v: View) = if (v.id == R.id.imageView_edit) {
|
||||||
override fun onLongClick(v: View) = clickListener.onItemLongClick(item.category, itemView)
|
clickListener.onEditClick(item.category, v)
|
||||||
|
} else {
|
||||||
|
clickListener.onItemClick(item.category, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLongClick(v: View) = clickListener.onItemLongClick(item.category, v)
|
||||||
override fun onTouch(v: View?, event: MotionEvent): Boolean = event.actionMasked == MotionEvent.ACTION_DOWN &&
|
override fun onTouch(v: View?, event: MotionEvent): Boolean = event.actionMasked == MotionEvent.ACTION_DOWN &&
|
||||||
clickListener.onDragHandleTouch(this@adapterDelegateViewBinding)
|
clickListener.onDragHandleTouch(this@adapterDelegateViewBinding)
|
||||||
}
|
}
|
||||||
@@ -58,6 +62,7 @@ fun categoryAD(
|
|||||||
val crossFadeDuration = context.getAnimationDuration(R.integer.config_defaultAnimTime).toInt()
|
val crossFadeDuration = context.getAnimationDuration(R.integer.config_defaultAnimTime).toInt()
|
||||||
itemView.setOnClickListener(eventListener)
|
itemView.setOnClickListener(eventListener)
|
||||||
itemView.setOnLongClickListener(eventListener)
|
itemView.setOnLongClickListener(eventListener)
|
||||||
|
binding.imageViewEdit.setOnClickListener(eventListener)
|
||||||
binding.imageViewHandle.setOnTouchListener(eventListener)
|
binding.imageViewHandle.setOnTouchListener(eventListener)
|
||||||
|
|
||||||
bind { payloads ->
|
bind { payloads ->
|
||||||
@@ -89,10 +94,4 @@ fun categoryAD(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
|
||||||
coverViews.forEach {
|
|
||||||
it.disposeImageRequest()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,4 +46,8 @@ class CategoryListModel(
|
|||||||
result = 31 * result + category.isVisibleInLibrary.hashCode()
|
result = 31 * result + category.isVisibleInLibrary.hashCode()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "CategoryListModel(categoryId=${category.id})"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package org.koitharu.kotatsu.favourites.ui.container
|
|||||||
|
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
|
||||||
class FavouriteTabModel(
|
data class FavouriteTabModel(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val title: String,
|
val title: String,
|
||||||
) : ListModel {
|
) : ListModel {
|
||||||
@@ -10,20 +10,4 @@ class FavouriteTabModel(
|
|||||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||||
return other is FavouriteTabModel && other.id == id
|
return other is FavouriteTabModel && other.id == id
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as FavouriteTabModel
|
|
||||||
|
|
||||||
if (id != other.id) return false
|
|
||||||
return title == other.title
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = id.hashCode()
|
|
||||||
result = 31 * result + title.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,30 +263,11 @@ class FilterCoordinator @Inject constructor(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TagsWrapper(
|
private data class TagsWrapper(
|
||||||
val tags: Set<MangaTag>,
|
val tags: Set<MangaTag>,
|
||||||
val isLoading: Boolean,
|
val isLoading: Boolean,
|
||||||
val isError: Boolean,
|
val isError: Boolean,
|
||||||
) {
|
)
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as TagsWrapper
|
|
||||||
|
|
||||||
if (tags != other.tags) return false
|
|
||||||
if (isLoading != other.isLoading) return false
|
|
||||||
return isError == other.isError
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = tags.hashCode()
|
|
||||||
result = 31 * result + isLoading.hashCode()
|
|
||||||
result = 31 * result + isError.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TagTitleComparator(lc: String?) : Comparator<MangaTag> {
|
private class TagTitleComparator(lc: String?) : Comparator<MangaTag> {
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class FilterSheetFragment :
|
|||||||
val adapter = FilterAdapter(filter, this)
|
val adapter = FilterAdapter(filter, this)
|
||||||
binding.recyclerView.adapter = adapter
|
binding.recyclerView.adapter = adapter
|
||||||
filter.filterItems.observe(viewLifecycleOwner, adapter)
|
filter.filterItems.observe(viewLifecycleOwner, adapter)
|
||||||
binding.recyclerView.addItemDecoration(TypedListSpacingDecoration(binding.root.context, false))
|
binding.recyclerView.addItemDecoration(TypedListSpacingDecoration(binding.root.context, true))
|
||||||
|
|
||||||
if (dialog == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (dialog == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
binding.recyclerView.scrollIndicators = 0
|
binding.recyclerView.scrollIndicators = 0
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.koitharu.kotatsu.parsers.model.SortOrder
|
|||||||
|
|
||||||
sealed interface FilterItem : ListModel {
|
sealed interface FilterItem : ListModel {
|
||||||
|
|
||||||
class Sort(
|
data class Sort(
|
||||||
val order: SortOrder,
|
val order: SortOrder,
|
||||||
val isSelected: Boolean,
|
val isSelected: Boolean,
|
||||||
) : FilterItem {
|
) : FilterItem {
|
||||||
@@ -24,25 +24,9 @@ sealed interface FilterItem : ListModel {
|
|||||||
super.getChangePayload(previousState)
|
super.getChangePayload(previousState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as Sort
|
|
||||||
|
|
||||||
if (order != other.order) return false
|
|
||||||
return isSelected == other.isSelected
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = order.hashCode()
|
|
||||||
result = 31 * result + isSelected.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Tag(
|
data class Tag(
|
||||||
val tag: MangaTag,
|
val tag: MangaTag,
|
||||||
val isChecked: Boolean,
|
val isChecked: Boolean,
|
||||||
) : FilterItem {
|
) : FilterItem {
|
||||||
@@ -58,43 +42,14 @@ sealed interface FilterItem : ListModel {
|
|||||||
super.getChangePayload(previousState)
|
super.getChangePayload(previousState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as Tag
|
|
||||||
|
|
||||||
if (tag != other.tag) return false
|
|
||||||
return isChecked == other.isChecked
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = tag.hashCode()
|
|
||||||
result = 31 * result + isChecked.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Error(
|
data class Error(
|
||||||
@StringRes val textResId: Int,
|
@StringRes val textResId: Int,
|
||||||
) : FilterItem {
|
) : FilterItem {
|
||||||
|
|
||||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||||
return other is Error && textResId == other.textResId
|
return other is Error && textResId == other.textResId
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as Error
|
|
||||||
|
|
||||||
return textResId == other.textResId
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
return textResId
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,24 +3,7 @@ package org.koitharu.kotatsu.filter.ui.model
|
|||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
|
|
||||||
class FilterState(
|
data class FilterState(
|
||||||
val sortOrder: SortOrder?,
|
val sortOrder: SortOrder?,
|
||||||
val tags: Set<MangaTag>,
|
val tags: Set<MangaTag>,
|
||||||
) {
|
)
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (javaClass != other?.javaClass) return false
|
|
||||||
|
|
||||||
other as FilterState
|
|
||||||
|
|
||||||
if (sortOrder != other.sortOrder) return false
|
|
||||||
return tags == other.tags
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
var result = sortOrder?.hashCode() ?: 0
|
|
||||||
result = 31 * result + tags.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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(
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.koitharu.kotatsu.list.ui.adapter
|
|||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.core.util.ext.disposeImageRequest
|
|
||||||
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.setTextAndVisible
|
import org.koitharu.kotatsu.core.util.ext.setTextAndVisible
|
||||||
@@ -27,8 +26,4 @@ fun emptyHintAD(
|
|||||||
binding.textSecondary.setTextAndVisible(item.textSecondary)
|
binding.textSecondary.setTextAndVisible(item.textSecondary)
|
||||||
binding.buttonRetry.setTextAndVisible(item.actionStringRes)
|
binding.buttonRetry.setTextAndVisible(item.actionStringRes)
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
|
||||||
binding.icon.disposeImageRequest()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.koitharu.kotatsu.list.ui.adapter
|
|||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.core.util.ext.disposeImageRequest
|
|
||||||
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.setTextAndVisible
|
import org.koitharu.kotatsu.core.util.ext.setTextAndVisible
|
||||||
@@ -31,8 +30,4 @@ fun emptyStateListAD(
|
|||||||
binding.buttonRetry.setTextAndVisible(item.actionStringRes)
|
binding.buttonRetry.setTextAndVisible(item.actionStringRes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
|
||||||
binding.icon.disposeImageRequest()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,5 @@ enum class ListItemType {
|
|||||||
DOWNLOAD,
|
DOWNLOAD,
|
||||||
CATEGORY_LARGE,
|
CATEGORY_LARGE,
|
||||||
MANGA_SCROBBLING,
|
MANGA_SCROBBLING,
|
||||||
|
NAV_ITEM,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,10 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.core.ui.image.CoverSizeResolver
|
import org.koitharu.kotatsu.core.ui.image.CoverSizeResolver
|
||||||
import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
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.disposeImageRequest
|
|
||||||
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.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.history.data.PROGRESS_NONE
|
|
||||||
import org.koitharu.kotatsu.list.ui.ListModelDiffCallback
|
import org.koitharu.kotatsu.list.ui.ListModelDiffCallback
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.list.ui.model.MangaGridModel
|
import org.koitharu.kotatsu.list.ui.model.MangaGridModel
|
||||||
@@ -54,11 +52,4 @@ fun mangaGridItemAD(
|
|||||||
}
|
}
|
||||||
badge = itemView.bindBadge(badge, item.counter)
|
badge = itemView.bindBadge(badge, item.counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
|
||||||
itemView.clearBadge(badge)
|
|
||||||
binding.progressView.percent = PROGRESS_NONE
|
|
||||||
badge = null
|
|
||||||
binding.imageViewCover.disposeImageRequest()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,11 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.core.ui.image.CoverSizeResolver
|
import org.koitharu.kotatsu.core.ui.image.CoverSizeResolver
|
||||||
import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
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.disposeImageRequest
|
|
||||||
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.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
|
||||||
import org.koitharu.kotatsu.history.data.PROGRESS_NONE
|
|
||||||
import org.koitharu.kotatsu.list.ui.ListModelDiffCallback
|
import org.koitharu.kotatsu.list.ui.ListModelDiffCallback
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
import org.koitharu.kotatsu.list.ui.model.MangaListDetailedModel
|
import org.koitharu.kotatsu.list.ui.model.MangaListDetailedModel
|
||||||
@@ -73,11 +71,4 @@ fun mangaListDetailedItemAD(
|
|||||||
binding.ratingBar.rating = binding.ratingBar.numStars * item.manga.rating
|
binding.ratingBar.rating = binding.ratingBar.numStars * item.manga.rating
|
||||||
badge = itemView.bindBadge(badge, item.counter)
|
badge = itemView.bindBadge(badge, item.counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
|
||||||
itemView.clearBadge(badge)
|
|
||||||
binding.progressView.percent = PROGRESS_NONE
|
|
||||||
badge = null
|
|
||||||
binding.imageViewCover.disposeImageRequest()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
|||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
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.disposeImageRequest
|
|
||||||
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.source
|
import org.koitharu.kotatsu.core.util.ext.source
|
||||||
@@ -48,10 +47,4 @@ fun mangaListItemAD(
|
|||||||
}
|
}
|
||||||
badge = itemView.bindBadge(badge, item.counter)
|
badge = itemView.bindBadge(badge, item.counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
|
||||||
itemView.clearBadge(badge)
|
|
||||||
badge = null
|
|
||||||
binding.imageViewCover.disposeImageRequest()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,4 +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_TAG
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user