pull/529/head
Koitharu 3 years ago
parent f3e597275b
commit 8bfdf07a2f
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -1,9 +1,9 @@
package org.koitharu.kotatsu.details.domain package org.koitharu.kotatsu.details.domain
import org.koitharu.kotatsu.core.db.MangaDatabase
import org.koitharu.kotatsu.core.model.findChapter import org.koitharu.kotatsu.core.model.findChapter
import org.koitharu.kotatsu.core.model.isLocal import org.koitharu.kotatsu.core.model.isLocal
import org.koitharu.kotatsu.core.parser.MangaRepository import org.koitharu.kotatsu.core.parser.MangaRepository
import org.koitharu.kotatsu.history.data.HistoryRepository
import org.koitharu.kotatsu.history.data.PROGRESS_NONE import org.koitharu.kotatsu.history.data.PROGRESS_NONE
import org.koitharu.kotatsu.local.data.LocalMangaRepository import org.koitharu.kotatsu.local.data.LocalMangaRepository
import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.Manga
@ -11,12 +11,12 @@ import javax.inject.Inject
class ProgressUpdateUseCase @Inject constructor( class ProgressUpdateUseCase @Inject constructor(
private val mangaRepositoryFactory: MangaRepository.Factory, private val mangaRepositoryFactory: MangaRepository.Factory,
private val historyRepository: HistoryRepository, private val database: MangaDatabase,
private val localMangaRepository: LocalMangaRepository, private val localMangaRepository: LocalMangaRepository,
) { ) {
suspend operator fun invoke(manga: Manga): Float { suspend operator fun invoke(manga: Manga): Float {
val history = historyRepository.getOne(manga) ?: return PROGRESS_NONE val history = database.historyDao.find(manga.id) ?: return PROGRESS_NONE
val seed = if (manga.isLocal) { val seed = if (manga.isLocal) {
localMangaRepository.getRemoteManga(manga) ?: manga localMangaRepository.getRemoteManga(manga) ?: manga
} else { } else {
@ -42,13 +42,14 @@ class ProgressUpdateUseCase @Inject constructor(
val pagePercent = (history.page + 1) / pagesCount.toFloat() val pagePercent = (history.page + 1) / pagesCount.toFloat()
val ppc = 1f / chaptersCount val ppc = 1f / chaptersCount
val result = ppc * chapterIndex + ppc * pagePercent val result = ppc * chapterIndex + ppc * pagePercent
historyRepository.addOrUpdate( if (result != history.percent) {
manga = details, database.historyDao.update(
chapterId = chapter.id, history.copy(
page = history.page, chapterId = chapter.id,
scroll = history.scroll, percent = result,
percent = result, ),
) )
}
return result return result
} }
} }

@ -14,7 +14,7 @@ import kotlinx.coroutines.runInterruptible
import org.koitharu.kotatsu.core.model.isLocal import org.koitharu.kotatsu.core.model.isLocal
import org.koitharu.kotatsu.core.parser.MangaRepository import org.koitharu.kotatsu.core.parser.MangaRepository
import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.util.CompositeMutex import org.koitharu.kotatsu.core.util.CompositeMutex2
import org.koitharu.kotatsu.core.util.ext.children import org.koitharu.kotatsu.core.util.ext.children
import org.koitharu.kotatsu.core.util.ext.deleteAwait import org.koitharu.kotatsu.core.util.ext.deleteAwait
import org.koitharu.kotatsu.core.util.ext.filterWith import org.koitharu.kotatsu.core.util.ext.filterWith
@ -45,7 +45,7 @@ class LocalMangaRepository @Inject constructor(
) : MangaRepository { ) : MangaRepository {
override val source = MangaSource.LOCAL override val source = MangaSource.LOCAL
private val locks = CompositeMutex<Long>() private val locks = CompositeMutex2<Long>()
override val sortOrders: Set<SortOrder> = EnumSet.of(SortOrder.ALPHABETICAL, SortOrder.RATING, SortOrder.NEWEST) override val sortOrders: Set<SortOrder> = EnumSet.of(SortOrder.ALPHABETICAL, SortOrder.RATING, SortOrder.NEWEST)
@ -122,7 +122,7 @@ class LocalMangaRepository @Inject constructor(
suspend fun getRemoteManga(localManga: Manga): Manga? { suspend fun getRemoteManga(localManga: Manga): Manga? {
return runCatchingCancellable { return runCatchingCancellable {
LocalMangaInput.of(localManga).getMangaInfo() LocalMangaInput.of(localManga).getMangaInfo()?.takeUnless { it.isLocal }
}.onFailure { }.onFailure {
it.printStackTraceDebug() it.printStackTraceDebug()
}.getOrNull() }.getOrNull()

@ -4,6 +4,7 @@ import androidx.annotation.WorkerThread
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.core.model.isLocal
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
@ -21,7 +22,8 @@ class MangaIndex(source: String?) {
private val json: JSONObject = source?.let(::JSONObject) ?: JSONObject() private val json: JSONObject = source?.let(::JSONObject) ?: JSONObject()
fun setMangaInfo(manga: Manga, append: Boolean) { fun setMangaInfo(manga: Manga) {
require(!manga.isLocal) { "Local manga information cannot be stored" }
json.put("id", manga.id) json.put("id", manga.id)
json.put("title", manga.title) json.put("title", manga.title)
json.put("title_alt", manga.altTitle) json.put("title_alt", manga.altTitle)
@ -46,7 +48,7 @@ class MangaIndex(source: String?) {
} }
}, },
) )
if (!append || !json.has("chapters")) { if (!json.has("chapters")) {
json.put("chapters", JSONObject()) json.put("chapters", JSONObject())
} }
json.put("app_id", BuildConfig.APPLICATION_ID) json.put("app_id", BuildConfig.APPLICATION_ID)

@ -3,6 +3,7 @@ package org.koitharu.kotatsu.local.data.output
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runInterruptible import kotlinx.coroutines.runInterruptible
import org.koitharu.kotatsu.core.model.findById import org.koitharu.kotatsu.core.model.findById
import org.koitharu.kotatsu.core.model.isLocal
import org.koitharu.kotatsu.core.util.ext.deleteAwait import org.koitharu.kotatsu.core.util.ext.deleteAwait
import org.koitharu.kotatsu.core.util.ext.takeIfReadable import org.koitharu.kotatsu.core.util.ext.takeIfReadable
import org.koitharu.kotatsu.core.zip.ZipOutput import org.koitharu.kotatsu.core.zip.ZipOutput
@ -21,7 +22,9 @@ class LocalMangaDirOutput(
private val index = MangaIndex(File(rootFile, ENTRY_NAME_INDEX).takeIfReadable()?.readText()) private val index = MangaIndex(File(rootFile, ENTRY_NAME_INDEX).takeIfReadable()?.readText())
init { init {
index.setMangaInfo(manga, append = true) if (!manga.isLocal) {
index.setMangaInfo(manga)
}
} }
override suspend fun mergeWithExisting() = Unit override suspend fun mergeWithExisting() = Unit

@ -3,6 +3,7 @@ package org.koitharu.kotatsu.local.data.output
import androidx.annotation.WorkerThread import androidx.annotation.WorkerThread
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runInterruptible import kotlinx.coroutines.runInterruptible
import org.koitharu.kotatsu.core.model.isLocal
import org.koitharu.kotatsu.core.util.ext.deleteAwait import org.koitharu.kotatsu.core.util.ext.deleteAwait
import org.koitharu.kotatsu.core.util.ext.readText import org.koitharu.kotatsu.core.util.ext.readText
import org.koitharu.kotatsu.core.zip.ZipOutput import org.koitharu.kotatsu.core.zip.ZipOutput
@ -21,7 +22,9 @@ class LocalMangaZipOutput(
private val index = MangaIndex(null) private val index = MangaIndex(null)
init { init {
index.setMangaInfo(manga, false) if (!manga.isLocal) {
index.setMangaInfo(manga)
}
} }
override suspend fun mergeWithExisting() { override suspend fun mergeWithExisting() {

@ -47,7 +47,7 @@ class LocalChaptersRemoveService : CoroutineIntentService() {
startForeground() startForeground()
val mangaWithChapters = localMangaRepository.getDetails(manga) val mangaWithChapters = localMangaRepository.getDetails(manga)
localMangaRepository.deleteChapters(mangaWithChapters, chaptersIds) localMangaRepository.deleteChapters(mangaWithChapters, chaptersIds)
localStorageChanges.emit(LocalManga(manga)) localStorageChanges.emit(LocalManga(localMangaRepository.getDetails(manga)))
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE) ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
} }

@ -24,7 +24,7 @@ class LocalListMenuProvider(
true true
} }
R.id.action_settings -> { R.id.action_directories -> {
context.startActivity(MangaDirectoriesActivity.newIntent(context)) context.startActivity(MangaDirectoriesActivity.newIntent(context))
true true
} }

@ -3,6 +3,7 @@ package org.koitharu.kotatsu.reader.ui.colorfilter
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.res.Resources import android.content.res.Resources
import android.graphics.Bitmap
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -121,10 +122,10 @@ class ColorFilterConfigActivity :
.scale(Scale.FILL) .scale(Scale.FILL)
.decodeRegion() .decodeRegion()
.tag(page.source) .tag(page.source)
.bitmapConfig(if (viewModel.is32BitColorsEnabled) Bitmap.Config.ARGB_8888 else Bitmap.Config.RGB_565)
.indicator(listOf(viewBinding.progressBefore, viewBinding.progressAfter)) .indicator(listOf(viewBinding.progressBefore, viewBinding.progressAfter))
.error(R.drawable.ic_error_placeholder) .error(R.drawable.ic_error_placeholder)
.size(ViewSizeResolver(viewBinding.imageViewBefore)) .size(ViewSizeResolver(viewBinding.imageViewBefore))
.allowRgb565(false)
.target(DoubleViewTarget(viewBinding.imageViewBefore, viewBinding.imageViewAfter)) .target(DoubleViewTarget(viewBinding.imageViewBefore, viewBinding.imageViewAfter))
.enqueueWith(coil) .enqueueWith(coil)
} }

@ -7,6 +7,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
import org.koitharu.kotatsu.core.model.parcelable.ParcelableMangaPage import org.koitharu.kotatsu.core.model.parcelable.ParcelableMangaPage
import org.koitharu.kotatsu.core.parser.MangaDataRepository import org.koitharu.kotatsu.core.parser.MangaDataRepository
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.MutableEventFlow import org.koitharu.kotatsu.core.util.ext.MutableEventFlow
import org.koitharu.kotatsu.core.util.ext.call import org.koitharu.kotatsu.core.util.ext.call
@ -18,6 +19,7 @@ import javax.inject.Inject
@HiltViewModel @HiltViewModel
class ColorFilterConfigViewModel @Inject constructor( class ColorFilterConfigViewModel @Inject constructor(
savedStateHandle: SavedStateHandle, savedStateHandle: SavedStateHandle,
private val settings: AppSettings,
private val mangaDataRepository: MangaDataRepository, private val mangaDataRepository: MangaDataRepository,
) : BaseViewModel() { ) : BaseViewModel() {
@ -31,6 +33,9 @@ class ColorFilterConfigViewModel @Inject constructor(
val isChanged: Boolean val isChanged: Boolean
get() = colorFilter.value != initialColorFilter get() = colorFilter.value != initialColorFilter
val is32BitColorsEnabled: Boolean
get() = settings.is32BitColorsEnabled
init { init {
launchLoadingJob { launchLoadingJob {
initialColorFilter = mangaDataRepository.getColorFilter(manga.id) initialColorFilter = mangaDataRepository.getColorFilter(manga.id)

@ -18,6 +18,7 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.plus import kotlinx.coroutines.plus
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.model.distinctById
import org.koitharu.kotatsu.core.parser.MangaRepository import org.koitharu.kotatsu.core.parser.MangaRepository
import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.util.ext.MutableEventFlow import org.koitharu.kotatsu.core.util.ext.MutableEventFlow
@ -67,7 +68,7 @@ open class RemoteListViewModel @Inject constructor(
private var randomJob: Job? = null private var randomJob: Job? = null
override val content = combine( override val content = combine(
mangaList.map { it?.skipNsfwIfNeeded() }, mangaList.map { it?.distinctById()?.skipNsfwIfNeeded() },
listMode, listMode,
listError, listError,
hasNextPage, hasNextPage,
@ -138,7 +139,7 @@ open class RemoteListViewModel @Inject constructor(
} else if (list.isNotEmpty()) { } else if (list.isNotEmpty()) {
mangaList.value = mangaList.value?.plus(list) ?: list mangaList.value = mangaList.value?.plus(list) ?: list
} }
hasNextPage.value = list.isNotEmpty() hasNextPage.value = list.isNotEmpty() // TODO check if new ids added
} catch (e: CancellationException) { } catch (e: CancellationException) {
throw e throw e
} catch (e: Throwable) { } catch (e: Throwable) {

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Fills the entire area with the divider's color first... -->
<item>
<shape
android:shape="rectangle">
<solid android:color="?attr/colorOutline"/>
</shape>
</item>
<!-- ..., then draws a rectangle with the container color to cover the area not for the divider. -->
<item
android:bottom="1dp">
<shape
android:shape="rectangle">
<solid android:color="?attr/m3ColorBackground"/>
</shape>
</item>
</layer-list>

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Fills the entire area with the divider's color first... -->
<item>
<shape
android:shape="rectangle">
<solid android:color="@color/kotatsu_primaryContainer"/>
</shape>
</item>
<!-- ..., then draws a rectangle with the container color to cover the area not for the divider. -->
<item
android:bottom="1dp">
<shape
android:shape="rectangle">
<solid android:color="@color/kotatsu_m3_background"/>
</shape>
</item>
</layer-list>

@ -21,7 +21,6 @@
android:id="@id/toolbar" android:id="@id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="@drawable/toolbar_background"
android:theme="?attr/actionBarTheme" android:theme="?attr/actionBarTheme"
app:layout_scrollFlags="noScroll" app:layout_scrollFlags="noScroll"
tools:ignore="PrivateResource" /> tools:ignore="PrivateResource" />

Loading…
Cancel
Save