From d45fc1e245e025c8c5d6c380a73fd99d67bc8622 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 22 Jan 2023 11:04:50 -0500 Subject: [PATCH] Move more models to domain module --- .../eu/kanade/data/source/SourceMapper.kt | 2 +- .../data/source/SourceRepositoryImpl.kt | 4 +- .../source/interactor/GetEnabledSources.kt | 6 +- .../interactor/GetLanguagesWithSources.kt | 2 +- .../interactor/GetSourcesWithFavoriteCount.kt | 2 +- .../GetSourcesWithNonLibraryManga.kt | 2 +- .../domain/source/interactor/ToggleSource.kt | 2 +- .../source/interactor/ToggleSourcePin.kt | 2 +- .../eu/kanade/domain/source/model/Source.kt | 76 ++----------------- .../source/repository/SourceRepository.kt | 4 +- .../browse/MigrateSourceScreen.kt | 2 +- .../browse/SourcesFilterScreen.kt | 2 +- .../presentation/browse/SourcesScreen.kt | 4 +- .../browse/components/BaseSourceItem.kt | 2 +- .../browse/components/BrowseIcons.kt | 3 +- .../settings/screen/ClearDatabaseScreen.kt | 4 +- .../sources/MigrateSourceScreenModel.kt | 2 +- .../browse/source/SourcesFilterScreenModel.kt | 2 +- .../ui/browse/source/SourcesScreenModel.kt | 4 +- .../java/tachiyomi/domain/source/model/Pin.kt | 42 ++++++++++ .../tachiyomi/domain/source/model/Source.kt | 25 ++++++ .../domain/source/model/SourceWithCount.kt | 2 +- 22 files changed, 100 insertions(+), 96 deletions(-) create mode 100644 domain/src/main/java/tachiyomi/domain/source/model/Pin.kt create mode 100644 domain/src/main/java/tachiyomi/domain/source/model/Source.kt rename {app/src/main/java/eu/kanade => domain/src/main/java/tachiyomi}/domain/source/model/SourceWithCount.kt (82%) diff --git a/app/src/main/java/eu/kanade/data/source/SourceMapper.kt b/app/src/main/java/eu/kanade/data/source/SourceMapper.kt index b752ffdd0..509cfa33a 100644 --- a/app/src/main/java/eu/kanade/data/source/SourceMapper.kt +++ b/app/src/main/java/eu/kanade/data/source/SourceMapper.kt @@ -1,8 +1,8 @@ package eu.kanade.data.source -import eu.kanade.domain.source.model.Source import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.SourceManager +import tachiyomi.domain.source.model.Source import tachiyomi.domain.source.model.SourceData val sourceMapper: (eu.kanade.tachiyomi.source.Source) -> Source = { source -> diff --git a/app/src/main/java/eu/kanade/data/source/SourceRepositoryImpl.kt b/app/src/main/java/eu/kanade/data/source/SourceRepositoryImpl.kt index 28a1742da..9f30c2913 100644 --- a/app/src/main/java/eu/kanade/data/source/SourceRepositoryImpl.kt +++ b/app/src/main/java/eu/kanade/data/source/SourceRepositoryImpl.kt @@ -1,8 +1,6 @@ package eu.kanade.data.source -import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.model.SourcePagingSourceType -import eu.kanade.domain.source.model.SourceWithCount import eu.kanade.domain.source.repository.SourceRepository import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.LocalSource @@ -11,6 +9,8 @@ import eu.kanade.tachiyomi.source.model.FilterList import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import tachiyomi.data.DatabaseHandler +import tachiyomi.domain.source.model.Source +import tachiyomi.domain.source.model.SourceWithCount class SourceRepositoryImpl( private val sourceManager: SourceManager, diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt b/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt index ab09bd88e..a95752384 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt @@ -1,14 +1,14 @@ package eu.kanade.domain.source.interactor -import eu.kanade.domain.source.model.Pin -import eu.kanade.domain.source.model.Pins -import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.repository.SourceRepository import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.source.LocalSource import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged +import tachiyomi.domain.source.model.Pin +import tachiyomi.domain.source.model.Pins +import tachiyomi.domain.source.model.Source class GetEnabledSources( private val repository: SourceRepository, diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/GetLanguagesWithSources.kt b/app/src/main/java/eu/kanade/domain/source/interactor/GetLanguagesWithSources.kt index ce6a4288d..fe623f9c8 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/GetLanguagesWithSources.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/GetLanguagesWithSources.kt @@ -1,11 +1,11 @@ package eu.kanade.domain.source.interactor -import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.repository.SourceRepository import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.util.system.LocaleHelper import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine +import tachiyomi.domain.source.model.Source class GetLanguagesWithSources( private val repository: SourceRepository, diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithFavoriteCount.kt b/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithFavoriteCount.kt index c04acab1d..dbfe73deb 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithFavoriteCount.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithFavoriteCount.kt @@ -1,10 +1,10 @@ package eu.kanade.domain.source.interactor -import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.repository.SourceRepository import eu.kanade.domain.source.service.SourcePreferences import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine +import tachiyomi.domain.source.model.Source import java.text.Collator import java.util.Collections import java.util.Locale diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithNonLibraryManga.kt b/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithNonLibraryManga.kt index 593f70ba7..604e9119c 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithNonLibraryManga.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithNonLibraryManga.kt @@ -1,8 +1,8 @@ package eu.kanade.domain.source.interactor -import eu.kanade.domain.source.model.SourceWithCount import eu.kanade.domain.source.repository.SourceRepository import kotlinx.coroutines.flow.Flow +import tachiyomi.domain.source.model.SourceWithCount class GetSourcesWithNonLibraryManga( private val repository: SourceRepository, diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSource.kt b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSource.kt index e69e76dab..9eb0ab8e6 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSource.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSource.kt @@ -1,8 +1,8 @@ package eu.kanade.domain.source.interactor -import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.core.preference.getAndSet +import tachiyomi.domain.source.model.Source class ToggleSource( private val preferences: SourcePreferences, diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSourcePin.kt b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSourcePin.kt index 6f79035e5..532ce669c 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSourcePin.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSourcePin.kt @@ -1,8 +1,8 @@ package eu.kanade.domain.source.interactor -import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.core.preference.getAndSet +import tachiyomi.domain.source.model.Source class ToggleSourcePin( private val preferences: SourcePreferences, diff --git a/app/src/main/java/eu/kanade/domain/source/model/Source.kt b/app/src/main/java/eu/kanade/domain/source/model/Source.kt index a840065d9..0e3919718 100644 --- a/app/src/main/java/eu/kanade/domain/source/model/Source.kt +++ b/app/src/main/java/eu/kanade/domain/source/model/Source.kt @@ -4,77 +4,13 @@ import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.asImageBitmap import androidx.core.graphics.drawable.toBitmap import eu.kanade.tachiyomi.extension.ExtensionManager +import tachiyomi.domain.source.model.Source import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -data class Source( - val id: Long, - val lang: String, - val name: String, - val supportsLatest: Boolean, - val isStub: Boolean, - val pin: Pins = Pins.unpinned, - val isUsedLast: Boolean = false, -) { - - val visualName: String - get() = when { - lang.isEmpty() -> name - else -> "$name (${lang.uppercase()})" - } - - val icon: ImageBitmap? - get() { - return Injekt.get().getAppIconForSource(id) - ?.toBitmap() - ?.asImageBitmap() - } - - val key: () -> String = { - when { - isUsedLast -> "$id-lastused" - else -> "$id" - } +val Source.icon: ImageBitmap? + get() { + return Injekt.get().getAppIconForSource(id) + ?.toBitmap() + ?.asImageBitmap() } -} - -sealed class Pin(val code: Int) { - object Unpinned : Pin(0b00) - object Pinned : Pin(0b01) - object Actual : Pin(0b10) -} - -inline fun Pins(builder: Pins.PinsBuilder.() -> Unit = {}): Pins { - return Pins.PinsBuilder().apply(builder).flags() -} - -fun Pins(vararg pins: Pin) = Pins { - pins.forEach { +it } -} - -data class Pins(val code: Int = Pin.Unpinned.code) { - - operator fun contains(pin: Pin): Boolean = pin.code and code == pin.code - - operator fun plus(pin: Pin): Pins = Pins(code or pin.code) - - operator fun minus(pin: Pin): Pins = Pins(code xor pin.code) - - companion object { - val unpinned = Pins(Pin.Unpinned) - - val pinned = Pins(Pin.Pinned, Pin.Actual) - } - - class PinsBuilder(var code: Int = 0) { - operator fun Pin.unaryPlus() { - this@PinsBuilder.code = code or this@PinsBuilder.code - } - - operator fun Pin.unaryMinus() { - this@PinsBuilder.code = code or this@PinsBuilder.code - } - - fun flags(): Pins = Pins(code) - } -} diff --git a/app/src/main/java/eu/kanade/domain/source/repository/SourceRepository.kt b/app/src/main/java/eu/kanade/domain/source/repository/SourceRepository.kt index c49a04e7d..5b6c2b215 100644 --- a/app/src/main/java/eu/kanade/domain/source/repository/SourceRepository.kt +++ b/app/src/main/java/eu/kanade/domain/source/repository/SourceRepository.kt @@ -1,10 +1,10 @@ package eu.kanade.domain.source.repository -import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.model.SourcePagingSourceType -import eu.kanade.domain.source.model.SourceWithCount import eu.kanade.tachiyomi.source.model.FilterList import kotlinx.coroutines.flow.Flow +import tachiyomi.domain.source.model.Source +import tachiyomi.domain.source.model.SourceWithCount interface SourceRepository { diff --git a/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt index a808d7edd..79353fedd 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt @@ -23,7 +23,6 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import eu.kanade.domain.source.interactor.SetMigrateSorting -import eu.kanade.domain.source.model.Source import eu.kanade.presentation.browse.components.BaseSourceItem import eu.kanade.presentation.browse.components.SourceIcon import eu.kanade.presentation.components.Badge @@ -40,6 +39,7 @@ import eu.kanade.presentation.util.topSmallPaddingValues import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrateSourceState import eu.kanade.tachiyomi.util.system.copyToClipboard +import tachiyomi.domain.source.model.Source @Composable fun MigrateSourceScreen( diff --git a/app/src/main/java/eu/kanade/presentation/browse/SourcesFilterScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/SourcesFilterScreen.kt index 65b5bf908..a4f187e4e 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/SourcesFilterScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/SourcesFilterScreen.kt @@ -8,7 +8,6 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource -import eu.kanade.domain.source.model.Source import eu.kanade.presentation.browse.components.BaseSourceItem import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.components.EmptyScreen @@ -18,6 +17,7 @@ import eu.kanade.presentation.more.settings.widget.SwitchPreferenceWidget import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.browse.source.SourcesFilterState import eu.kanade.tachiyomi.util.system.LocaleHelper +import tachiyomi.domain.source.model.Source @Composable fun SourcesFilterScreen( diff --git a/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt index c37719c2a..7fb065785 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt @@ -21,8 +21,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import eu.kanade.domain.source.model.Pin -import eu.kanade.domain.source.model.Source import eu.kanade.presentation.browse.components.BaseSourceItem import eu.kanade.presentation.components.EmptyScreen import eu.kanade.presentation.components.LoadingScreen @@ -36,6 +34,8 @@ import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.ui.browse.source.SourcesState import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceScreenModel.Listing import eu.kanade.tachiyomi.util.system.LocaleHelper +import tachiyomi.domain.source.model.Pin +import tachiyomi.domain.source.model.Source @Composable fun SourcesScreen( diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/BaseSourceItem.kt b/app/src/main/java/eu/kanade/presentation/browse/components/BaseSourceItem.kt index 97ba0f483..e5cc18ba3 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/components/BaseSourceItem.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/components/BaseSourceItem.kt @@ -9,10 +9,10 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextOverflow -import eu.kanade.domain.source.model.Source import eu.kanade.presentation.util.padding import eu.kanade.presentation.util.secondaryItemAlpha import eu.kanade.tachiyomi.util.system.LocaleHelper +import tachiyomi.domain.source.model.Source @Composable fun BaseSourceItem( diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt index 45526d5df..5f5c703ad 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt @@ -27,12 +27,13 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import androidx.core.graphics.drawable.toBitmap import coil.compose.AsyncImage -import eu.kanade.domain.source.model.Source +import eu.kanade.domain.source.model.icon import eu.kanade.presentation.util.rememberResourceBitmapPainter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.util.lang.withIOContext +import tachiyomi.domain.source.model.Source private val defaultModifier = Modifier .height(40.dp) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/ClearDatabaseScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/ClearDatabaseScreen.kt index f09ac28b6..bb67ae5f7 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/ClearDatabaseScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/ClearDatabaseScreen.kt @@ -35,8 +35,6 @@ import cafe.adriel.voyager.core.screen.uniqueScreenKey import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow import eu.kanade.domain.source.interactor.GetSourcesWithNonLibraryManga -import eu.kanade.domain.source.model.Source -import eu.kanade.domain.source.model.SourceWithCount import eu.kanade.presentation.browse.components.SourceIcon import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.components.AppBarActions @@ -54,6 +52,8 @@ import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.update import tachiyomi.data.Database +import tachiyomi.domain.source.model.Source +import tachiyomi.domain.source.model.SourceWithCount import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrateSourceScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrateSourceScreenModel.kt index 3e1952fb3..eee8c1a43 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrateSourceScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrateSourceScreenModel.kt @@ -4,7 +4,6 @@ import cafe.adriel.voyager.core.model.StateScreenModel import cafe.adriel.voyager.core.model.coroutineScope import eu.kanade.domain.source.interactor.GetSourcesWithFavoriteCount import eu.kanade.domain.source.interactor.SetMigrateSorting -import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.system.logcat @@ -16,6 +15,7 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.update import logcat.LogPriority +import tachiyomi.domain.source.model.Source import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesFilterScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesFilterScreenModel.kt index 2754cee6a..d06cc1eca 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesFilterScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesFilterScreenModel.kt @@ -5,13 +5,13 @@ import cafe.adriel.voyager.core.model.coroutineScope import eu.kanade.domain.source.interactor.GetLanguagesWithSources import eu.kanade.domain.source.interactor.ToggleLanguage import eu.kanade.domain.source.interactor.ToggleSource -import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.service.SourcePreferences import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch +import tachiyomi.domain.source.model.Source import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesScreenModel.kt index 0f5b72414..e571e2390 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesScreenModel.kt @@ -7,8 +7,6 @@ import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.source.interactor.GetEnabledSources import eu.kanade.domain.source.interactor.ToggleSource import eu.kanade.domain.source.interactor.ToggleSourcePin -import eu.kanade.domain.source.model.Pin -import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.presentation.browse.SourceUiModel import eu.kanade.tachiyomi.util.lang.launchIO @@ -19,6 +17,8 @@ import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.update import logcat.LogPriority +import tachiyomi.domain.source.model.Pin +import tachiyomi.domain.source.model.Source import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.util.TreeMap diff --git a/domain/src/main/java/tachiyomi/domain/source/model/Pin.kt b/domain/src/main/java/tachiyomi/domain/source/model/Pin.kt new file mode 100644 index 000000000..07361a509 --- /dev/null +++ b/domain/src/main/java/tachiyomi/domain/source/model/Pin.kt @@ -0,0 +1,42 @@ +package tachiyomi.domain.source.model + +sealed class Pin(val code: Int) { + object Unpinned : Pin(0b00) + object Pinned : Pin(0b01) + object Actual : Pin(0b10) +} + +inline fun Pins(builder: Pins.PinsBuilder.() -> Unit = {}): Pins { + return Pins.PinsBuilder().apply(builder).flags() +} + +fun Pins(vararg pins: Pin) = Pins { + pins.forEach { +it } +} + +data class Pins(val code: Int = Pin.Unpinned.code) { + + operator fun contains(pin: Pin): Boolean = pin.code and code == pin.code + + operator fun plus(pin: Pin): Pins = Pins(code or pin.code) + + operator fun minus(pin: Pin): Pins = Pins(code xor pin.code) + + companion object { + val unpinned = Pins(Pin.Unpinned) + + val pinned = Pins(Pin.Pinned, Pin.Actual) + } + + class PinsBuilder(var code: Int = 0) { + operator fun Pin.unaryPlus() { + this@PinsBuilder.code = code or this@PinsBuilder.code + } + + operator fun Pin.unaryMinus() { + this@PinsBuilder.code = code or this@PinsBuilder.code + } + + fun flags(): Pins = Pins(code) + } +} diff --git a/domain/src/main/java/tachiyomi/domain/source/model/Source.kt b/domain/src/main/java/tachiyomi/domain/source/model/Source.kt new file mode 100644 index 000000000..4dfb988a1 --- /dev/null +++ b/domain/src/main/java/tachiyomi/domain/source/model/Source.kt @@ -0,0 +1,25 @@ +package tachiyomi.domain.source.model + +data class Source( + val id: Long, + val lang: String, + val name: String, + val supportsLatest: Boolean, + val isStub: Boolean, + val pin: Pins = Pins.unpinned, + val isUsedLast: Boolean = false, +) { + + val visualName: String + get() = when { + lang.isEmpty() -> name + else -> "$name (${lang.uppercase()})" + } + + val key: () -> String = { + when { + isUsedLast -> "$id-lastused" + else -> "$id" + } + } +} diff --git a/app/src/main/java/eu/kanade/domain/source/model/SourceWithCount.kt b/domain/src/main/java/tachiyomi/domain/source/model/SourceWithCount.kt similarity index 82% rename from app/src/main/java/eu/kanade/domain/source/model/SourceWithCount.kt rename to domain/src/main/java/tachiyomi/domain/source/model/SourceWithCount.kt index 67a224ce8..02270c3c2 100644 --- a/app/src/main/java/eu/kanade/domain/source/model/SourceWithCount.kt +++ b/domain/src/main/java/tachiyomi/domain/source/model/SourceWithCount.kt @@ -1,4 +1,4 @@ -package eu.kanade.domain.source.model +package tachiyomi.domain.source.model data class SourceWithCount( val source: Source,