Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Caio99BR committed Jul 1, 2024
1 parent 77db887 commit 1f08666
Show file tree
Hide file tree
Showing 702 changed files with 20,179 additions and 17,122 deletions.
18 changes: 11 additions & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ plugins {
kotlin("plugin.serialization")
}

if (gradle.startParameter.taskRequests.toString().contains("Standard")) {
if (gradle.startParameter.taskRequests
.toString()
.contains("Standard")
) {
apply<com.google.gms.googleservices.GoogleServicesPlugin>()
}

Expand Down Expand Up @@ -158,7 +161,7 @@ dependencies {
implementation(compose.ui.tooling.preview)
implementation(compose.ui.util)
implementation(compose.accompanist.systemuicontroller)

implementation(androidx.interpolator)

implementation(androidx.paging.runtime)
Expand Down Expand Up @@ -236,7 +239,6 @@ dependencies {
implementation(libs.compose.webview)
implementation(libs.compose.grid)


// Logging
implementation(libs.logcat)

Expand All @@ -260,15 +262,17 @@ androidComponents {
beforeVariants { variantBuilder ->
// Disables standardBenchmark
if (variantBuilder.buildType == "benchmark") {
variantBuilder.enable = variantBuilder.productFlavors.containsAll(
listOf("default" to "dev"),
)
variantBuilder.enable =
variantBuilder.productFlavors.containsAll(
listOf("default" to "dev"),
)
}
}
onVariants(selector().withFlavor("default" to "standard")) {
// Only excluding in standard flavor because this breaks
// Layout Inspector's Compose tree
it.packaging.resources.excludes.add("META-INF/*.version")
it.packaging.resources.excludes
.add("META-INF/*.version")
}
}

Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/eu/kanade/core/preference/CheckboxState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package eu.kanade.core.preference
import androidx.compose.ui.state.ToggleableState
import tachiyomi.core.common.preference.CheckboxState

fun <T> CheckboxState.TriState<T>.asToggleableState() = when (this) {
is CheckboxState.TriState.Exclude -> ToggleableState.Indeterminate
is CheckboxState.TriState.Include -> ToggleableState.On
is CheckboxState.TriState.None -> ToggleableState.Off
}
fun <T> CheckboxState.TriState<T>.asToggleableState() =
when (this) {
is CheckboxState.TriState.Exclude -> ToggleableState.Indeterminate
is CheckboxState.TriState.Include -> ToggleableState.On
is CheckboxState.TriState.None -> ToggleableState.Off
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class PreferenceMutableState<T>(
private val preference: Preference<T>,
scope: CoroutineScope,
) : MutableState<T> {

private val state = mutableStateOf(preference.get())

init {
preference.changes()
preference
.changes()
.onEach { state.value = it }
.launchIn(scope)
}
Expand All @@ -26,13 +26,9 @@ class PreferenceMutableState<T>(
preference.set(value)
}

override fun component1(): T {
return state.value
}
override fun component1(): T = state.value

override fun component2(): (T) -> Unit {
return preference::set
}
override fun component2(): (T) -> Unit = preference::set
}

fun <T> Preference<T>.asState(scope: CoroutineScope) = PreferenceMutableState(this, scope)
9 changes: 5 additions & 4 deletions app/src/main/java/eu/kanade/core/util/CollectionUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import androidx.compose.ui.util.fastForEach
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract

fun <T : R, R : Any> List<T>.insertSeparators(
generator: (T?, T?) -> R?,
): List<R> {
fun <T : R, R : Any> List<T>.insertSeparators(generator: (T?, T?) -> R?): List<R> {
if (isEmpty()) return emptyList()
val newList = mutableListOf<R>()
for (i in -1..lastIndex) {
Expand All @@ -19,7 +17,10 @@ fun <T : R, R : Any> List<T>.insertSeparators(
return newList
}

fun <E> HashSet<E>.addOrRemove(value: E, shouldAdd: Boolean) {
fun <E> HashSet<E>.addOrRemove(
value: E,
shouldAdd: Boolean,
) {
if (shouldAdd) {
add(value)
} else {
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/eu/kanade/core/util/SourceUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get

@Composable
fun ifSourcesLoaded(): Boolean {
return remember { Injekt.get<SourceManager>().isInitialized }.collectAsState().value
}
fun ifSourcesLoaded(): Boolean = remember { Injekt.get<SourceManager>().isInitialized }.collectAsState().value
1 change: 0 additions & 1 deletion app/src/main/java/eu/kanade/domain/DomainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ import uy.kohesive.injekt.api.addSingletonFactory
import uy.kohesive.injekt.api.get

class DomainModule : InjektModule {

override fun InjektRegistrar.registerInjectables() {
addSingletonFactory<CategoryRepository> { CategoryRepositoryImpl(get()) }
addFactory { GetCategories(get()) }
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/eu/kanade/domain/base/BasePreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ class BasePreferences(
val context: Context,
private val preferenceStore: PreferenceStore,
) {

fun downloadedOnly() = preferenceStore.getBoolean(
Preference.appStateKey("pref_downloaded_only"),
false,
)
fun downloadedOnly() =
preferenceStore.getBoolean(
Preference.appStateKey("pref_downloaded_only"),
false,
)

fun incognitoMode() = preferenceStore.getBoolean(Preference.appStateKey("incognito_mode"), false)

fun extensionInstaller() = ExtensionInstallerPreference(context, preferenceStore)

fun shownOnboardingFlow() = preferenceStore.getBoolean(Preference.appStateKey("onboarding_complete"), false)

enum class ExtensionInstaller(val titleRes: StringResource, val requiresSystemPermission: Boolean) {
enum class ExtensionInstaller(
val titleRes: StringResource,
val requiresSystemPermission: Boolean,
) {
LEGACY(MR.strings.ext_installer_legacy, true),
PACKAGEINSTALLER(MR.strings.ext_installer_packageinstaller, true),
SHIZUKU(MR.strings.ext_installer_shizuku, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@ class ExtensionInstallerPreference(
private val context: Context,
preferenceStore: PreferenceStore,
) : Preference<ExtensionInstaller> {

private val basePref = preferenceStore.getEnum(key(), defaultValue())

override fun key() = "extension_installer"

val entries get() = ExtensionInstaller.entries.run {
val entries get() =
ExtensionInstaller.entries.run {
if (context.hasMiuiPackageInstaller) {
filter { it != ExtensionInstaller.PACKAGEINSTALLER }
} else {
toList()
}
}

override fun defaultValue() =
if (context.hasMiuiPackageInstaller) {
filter { it != ExtensionInstaller.PACKAGEINSTALLER }
ExtensionInstaller.LEGACY
} else {
toList()
ExtensionInstaller.PACKAGEINSTALLER
}
}

override fun defaultValue() = if (context.hasMiuiPackageInstaller) {
ExtensionInstaller.LEGACY
} else {
ExtensionInstaller.PACKAGEINSTALLER
}

private fun check(value: ExtensionInstaller): ExtensionInstaller {
when (value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ import tachiyomi.domain.chapter.repository.ChapterRepository
class GetAvailableScanlators(
private val repository: ChapterRepository,
) {
private fun List<String>.cleanupAvailableScanlators(): Set<String> = mapNotNull { it.ifBlank { null } }.toSet()

private fun List<String>.cleanupAvailableScanlators(): Set<String> {
return mapNotNull { it.ifBlank { null } }.toSet()
}

suspend fun await(mangaId: Long): Set<String> {
return repository.getScanlatorsByMangaId(mangaId)
suspend fun await(mangaId: Long): Set<String> =
repository
.getScanlatorsByMangaId(mangaId)
.cleanupAvailableScanlators()
}

fun subscribe(mangaId: Long): Flow<Set<String>> {
return repository.getScanlatorsByMangaIdAsFlow(mangaId)
fun subscribe(mangaId: Long): Flow<Set<String>> =
repository
.getScanlatorsByMangaIdAsFlow(mangaId)
.map { it.cleanupAvailableScanlators() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class SetReadStatus(
private val mangaRepository: MangaRepository,
private val chapterRepository: ChapterRepository,
) {

private val mapper = { chapter: Chapter, read: Boolean ->
ChapterUpdate(
read = read,
Expand All @@ -26,55 +25,71 @@ class SetReadStatus(
)
}

suspend fun await(read: Boolean, vararg chapters: Chapter): Result = withNonCancellableContext {
val chaptersToUpdate = chapters.filter {
when (read) {
true -> !it.read
false -> it.read || it.lastPageRead > 0
suspend fun await(
read: Boolean,
vararg chapters: Chapter,
): Result =
withNonCancellableContext {
val chaptersToUpdate =
chapters.filter {
when (read) {
true -> !it.read
false -> it.read || it.lastPageRead > 0
}
}
if (chaptersToUpdate.isEmpty()) {
return@withNonCancellableContext Result.NoChapters
}
}
if (chaptersToUpdate.isEmpty()) {
return@withNonCancellableContext Result.NoChapters
}

try {
chapterRepository.updateAll(
chaptersToUpdate.map { mapper(it, read) },
)
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
return@withNonCancellableContext Result.InternalError(e)
}
try {
chapterRepository.updateAll(
chaptersToUpdate.map { mapper(it, read) },
)
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
return@withNonCancellableContext Result.InternalError(e)
}

if (read && downloadPreferences.removeAfterMarkedAsRead().get()) {
chaptersToUpdate
.groupBy { it.mangaId }
.forEach { (mangaId, chapters) ->
deleteDownload.awaitAll(
manga = mangaRepository.getMangaById(mangaId),
chapters = chapters.toTypedArray(),
)
}
}
if (read && downloadPreferences.removeAfterMarkedAsRead().get()) {
chaptersToUpdate
.groupBy { it.mangaId }
.forEach { (mangaId, chapters) ->
deleteDownload.awaitAll(
manga = mangaRepository.getMangaById(mangaId),
chapters = chapters.toTypedArray(),
)
}
}

Result.Success
}
Result.Success
}

suspend fun await(mangaId: Long, read: Boolean): Result = withNonCancellableContext {
await(
read = read,
chapters = chapterRepository
.getChapterByMangaId(mangaId)
.toTypedArray(),
)
}
suspend fun await(
mangaId: Long,
read: Boolean,
): Result =
withNonCancellableContext {
await(
read = read,
chapters =
chapterRepository
.getChapterByMangaId(mangaId)
.toTypedArray(),
)
}

suspend fun await(manga: Manga, read: Boolean) =
await(manga.id, read)
suspend fun await(
manga: Manga,
read: Boolean,
) = await(manga.id, read)

sealed interface Result {
data object Success : Result

data object NoChapters : Result
data class InternalError(val error: Throwable) : Result

data class InternalError(
val error: Throwable,
) : Result
}
}
Loading

0 comments on commit 1f08666

Please sign in to comment.