Minor cleanup

This commit is contained in:
arkon 2022-05-15 17:03:57 -04:00
parent d61bfd7caf
commit 9f42306f79
18 changed files with 40 additions and 70 deletions

View file

@ -1,4 +1,4 @@
package eu.kanade.presentation.extension package eu.kanade.presentation.browse
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.combinedClickable
@ -47,15 +47,15 @@ import eu.kanade.presentation.util.topPaddingValues
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.Extension
import eu.kanade.tachiyomi.extension.model.InstallStep import eu.kanade.tachiyomi.extension.model.InstallStep
import eu.kanade.tachiyomi.ui.browse.extension.ExtensionPresenter
import eu.kanade.tachiyomi.ui.browse.extension.ExtensionState import eu.kanade.tachiyomi.ui.browse.extension.ExtensionState
import eu.kanade.tachiyomi.ui.browse.extension.ExtensionUiModel import eu.kanade.tachiyomi.ui.browse.extension.ExtensionUiModel
import eu.kanade.tachiyomi.ui.browse.extension.ExtensionsPresenter
import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.LocaleHelper
@Composable @Composable
fun ExtensionScreen( fun ExtensionScreen(
nestedScrollInterop: NestedScrollConnection, nestedScrollInterop: NestedScrollConnection,
presenter: ExtensionPresenter, presenter: ExtensionsPresenter,
onLongClickItem: (Extension) -> Unit, onLongClickItem: (Extension) -> Unit,
onClickItemCancel: (Extension) -> Unit, onClickItemCancel: (Extension) -> Unit,
onInstallExtension: (Extension.Available) -> Unit, onInstallExtension: (Extension.Available) -> Unit,
@ -112,6 +112,7 @@ fun ExtensionContent(
) { ) {
val (trustState, setTrustState) = remember { mutableStateOf<Extension.Untrusted?>(null) } val (trustState, setTrustState) = remember { mutableStateOf<Extension.Untrusted?>(null) }
LazyColumn( LazyColumn(
modifier = Modifier.nestedScroll(nestedScrollInterop),
contentPadding = WindowInsets.navigationBars.asPaddingValues() + topPaddingValues, contentPadding = WindowInsets.navigationBars.asPaddingValues() + topPaddingValues,
) { ) {
items( items(

View file

@ -41,14 +41,14 @@ import eu.kanade.presentation.util.plus
import eu.kanade.presentation.util.topPaddingValues import eu.kanade.presentation.util.topPaddingValues
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.ui.browse.source.SourcePresenter
import eu.kanade.tachiyomi.ui.browse.source.SourceState import eu.kanade.tachiyomi.ui.browse.source.SourceState
import eu.kanade.tachiyomi.ui.browse.source.SourcesPresenter
import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.LocaleHelper
@Composable @Composable
fun SourceScreen( fun SourcesScreen(
nestedScrollInterop: NestedScrollConnection, nestedScrollInterop: NestedScrollConnection,
presenter: SourcePresenter, presenter: SourcesPresenter,
onClickItem: (Source) -> Unit, onClickItem: (Source) -> Unit,
onClickDisable: (Source) -> Unit, onClickDisable: (Source) -> Unit,
onClickLatest: (Source) -> Unit, onClickLatest: (Source) -> Unit,
@ -86,8 +86,7 @@ fun SourceList(
val (sourceState, setSourceState) = remember { mutableStateOf<Source?>(null) } val (sourceState, setSourceState) = remember { mutableStateOf<Source?>(null) }
LazyColumn( LazyColumn(
modifier = Modifier modifier = Modifier.nestedScroll(nestedScrollConnection),
.nestedScroll(nestedScrollConnection),
contentPadding = WindowInsets.navigationBars.asPaddingValues() + topPaddingValues, contentPadding = WindowInsets.navigationBars.asPaddingValues() + topPaddingValues,
) { ) {
items( items(

View file

@ -54,7 +54,7 @@ import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.security.Security import java.security.Security
open class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
private val preferences: PreferencesHelper by injectLazy() private val preferences: PreferencesHelper by injectLazy()

View file

@ -70,7 +70,7 @@ class AppModule(val app: Application) : InjektModule {
addSingletonFactory { PreferencesHelper(app) } addSingletonFactory { PreferencesHelper(app) }
addSingletonFactory { DatabaseHelper(app, get()) } addSingletonFactory { DatabaseHelper(get()) }
addSingletonFactory { ChapterCache(app) } addSingletonFactory { ChapterCache(app) }

View file

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.data.database package eu.kanade.tachiyomi.data.database
import android.content.Context
import androidx.sqlite.db.SupportSQLiteOpenHelper import androidx.sqlite.db.SupportSQLiteOpenHelper
import com.pushtorefresh.storio.sqlite.impl.DefaultStorIOSQLite import com.pushtorefresh.storio.sqlite.impl.DefaultStorIOSQLite
import eu.kanade.tachiyomi.data.database.mappers.CategoryTypeMapping import eu.kanade.tachiyomi.data.database.mappers.CategoryTypeMapping
@ -25,8 +24,7 @@ import eu.kanade.tachiyomi.data.database.queries.TrackQueries
/** /**
* This class provides operations to manage the database through its interfaces. * This class provides operations to manage the database through its interfaces.
*/ */
open class DatabaseHelper( class DatabaseHelper(
context: Context,
openHelper: SupportSQLiteOpenHelper, openHelper: SupportSQLiteOpenHelper,
) : ) :
MangaQueries, ChapterQueries, TrackQueries, CategoryQueries, MangaCategoryQueries, HistoryQueries { MangaQueries, ChapterQueries, TrackQueries, CategoryQueries, MangaCategoryQueries, HistoryQueries {

View file

@ -14,7 +14,7 @@ import rx.Observable
import tachiyomi.source.model.ChapterInfo import tachiyomi.source.model.ChapterInfo
import tachiyomi.source.model.MangaInfo import tachiyomi.source.model.MangaInfo
open class SourceManager(private val context: Context) { class SourceManager(private val context: Context) {
private val sourcesMap = mutableMapOf<Long, Source>() private val sourcesMap = mutableMapOf<Long, Source>()
private val stubSourcesMap = mutableMapOf<Long, StubSource>() private val stubSourcesMap = mutableMapOf<Long, StubSource>()
@ -28,7 +28,7 @@ open class SourceManager(private val context: Context) {
createInternalSources().forEach { registerSource(it) } createInternalSources().forEach { registerSource(it) }
} }
open fun get(sourceKey: Long): Source? { fun get(sourceKey: Long): Source? {
return sourcesMap[sourceKey] return sourcesMap[sourceKey]
} }

View file

@ -19,9 +19,9 @@ import eu.kanade.tachiyomi.databinding.PagerControllerBinding
import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.RootController
import eu.kanade.tachiyomi.ui.base.controller.RxController import eu.kanade.tachiyomi.ui.base.controller.RxController
import eu.kanade.tachiyomi.ui.base.controller.TabbedController import eu.kanade.tachiyomi.ui.base.controller.TabbedController
import eu.kanade.tachiyomi.ui.browse.extension.ExtensionController import eu.kanade.tachiyomi.ui.browse.extension.ExtensionsController
import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrationSourcesController import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrationSourcesController
import eu.kanade.tachiyomi.ui.browse.source.SourceController import eu.kanade.tachiyomi.ui.browse.source.SourcesController
import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.MainActivity
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -125,8 +125,8 @@ class BrowseController :
override fun configureRouter(router: Router, position: Int) { override fun configureRouter(router: Router, position: Int) {
if (!router.hasRootController()) { if (!router.hasRootController()) {
val controller: Controller = when (position) { val controller: Controller = when (position) {
SOURCES_CONTROLLER -> SourceController() SOURCES_CONTROLLER -> SourcesController()
EXTENSIONS_CONTROLLER -> ExtensionController() EXTENSIONS_CONTROLLER -> ExtensionsController()
MIGRATION_CONTROLLER -> MigrationSourcesController() MIGRATION_CONTROLLER -> MigrationSourcesController()
else -> error("Wrong position $position") else -> error("Wrong position $position")
} }

View file

@ -8,7 +8,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.ControllerChangeType
import eu.kanade.presentation.extension.ExtensionScreen import eu.kanade.presentation.browse.ExtensionScreen
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.Extension
import eu.kanade.tachiyomi.ui.base.controller.ComposeController import eu.kanade.tachiyomi.ui.base.controller.ComposeController
@ -20,11 +20,7 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import reactivecircus.flowbinding.appcompat.queryTextChanges import reactivecircus.flowbinding.appcompat.queryTextChanges
/** class ExtensionsController : ComposeController<ExtensionsPresenter>() {
* Controller to manage the catalogues available in the app.
*/
open class ExtensionController :
ComposeController<ExtensionPresenter>() {
private var query = "" private var query = ""
@ -32,11 +28,9 @@ open class ExtensionController :
setHasOptionsMenu(true) setHasOptionsMenu(true)
} }
override fun getTitle(): String? = override fun getTitle() = applicationContext?.getString(R.string.label_extensions)
applicationContext?.getString(R.string.label_extensions)
override fun createPresenter(): ExtensionPresenter = override fun createPresenter() = ExtensionsPresenter()
ExtensionPresenter()
@Composable @Composable
override fun ComposeContent(nestedScrollInterop: NestedScrollConnection) { override fun ComposeContent(nestedScrollInterop: NestedScrollConnection) {

View file

@ -26,14 +26,11 @@ import rx.Observable
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
/** class ExtensionsPresenter(
* Presenter of [ExtensionController].
*/
open class ExtensionPresenter(
private val extensionManager: ExtensionManager = Injekt.get(), private val extensionManager: ExtensionManager = Injekt.get(),
private val getExtensionUpdates: GetExtensionUpdates = Injekt.get(), private val getExtensionUpdates: GetExtensionUpdates = Injekt.get(),
private val getExtensions: GetExtensions = Injekt.get(), private val getExtensions: GetExtensions = Injekt.get(),
) : BasePresenter<ExtensionController>() { ) : BasePresenter<ExtensionsController>() {
private val _query: MutableStateFlow<String> = MutableStateFlow("") private val _query: MutableStateFlow<String> = MutableStateFlow("")

View file

@ -9,7 +9,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.model.Source
import eu.kanade.presentation.browse.SourceScreen import eu.kanade.presentation.browse.SourcesScreen
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.base.controller.SearchableComposeController import eu.kanade.tachiyomi.ui.base.controller.SearchableComposeController
@ -21,11 +21,7 @@ import eu.kanade.tachiyomi.ui.browse.source.latest.LatestUpdatesController
import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.MainActivity
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
/** class SourcesController : SearchableComposeController<SourcesPresenter>() {
* This controller shows and manages the different catalogues enabled by the user.
* This controller should only handle UI actions, IO actions should be done by [SourcePresenter]
*/
class SourceController : SearchableComposeController<SourcePresenter>() {
private val preferences: PreferencesHelper by injectLazy() private val preferences: PreferencesHelper by injectLazy()
@ -33,15 +29,13 @@ class SourceController : SearchableComposeController<SourcePresenter>() {
setHasOptionsMenu(true) setHasOptionsMenu(true)
} }
override fun getTitle(): String? = override fun getTitle() = resources?.getString(R.string.label_sources)
resources?.getString(R.string.label_sources)
override fun createPresenter(): SourcePresenter = override fun createPresenter() = SourcesPresenter()
SourcePresenter()
@Composable @Composable
override fun ComposeContent(nestedScrollInterop: NestedScrollConnection) { override fun ComposeContent(nestedScrollInterop: NestedScrollConnection) {
SourceScreen( SourcesScreen(
nestedScrollInterop = nestedScrollInterop, nestedScrollInterop = nestedScrollInterop,
presenter = presenter, presenter = presenter,
onClickItem = { source -> onClickItem = { source ->
@ -57,6 +51,7 @@ class SourceController : SearchableComposeController<SourcePresenter>() {
presenter.togglePin(source) presenter.togglePin(source)
}, },
) )
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
(activity as? MainActivity)?.ready = true (activity as? MainActivity)?.ready = true
} }

View file

@ -18,15 +18,11 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.util.TreeMap import java.util.TreeMap
/** class SourcesPresenter(
* Presenter of [SourceController]
* Function calls should be done from here. UI calls should be done from the controller.
*/
class SourcePresenter(
private val getEnabledSources: GetEnabledSources = Injekt.get(), private val getEnabledSources: GetEnabledSources = Injekt.get(),
private val toggleSource: ToggleSource = Injekt.get(), private val toggleSource: ToggleSource = Injekt.get(),
private val toggleSourcePin: ToggleSourcePin = Injekt.get(), private val toggleSourcePin: ToggleSourcePin = Injekt.get(),
) : BasePresenter<SourceController>() { ) : BasePresenter<SourcesController>() {
private val _state: MutableStateFlow<SourceState> = MutableStateFlow(SourceState.Loading) private val _state: MutableStateFlow<SourceState> = MutableStateFlow(SourceState.Loading)
val state: StateFlow<SourceState> = _state.asStateFlow() val state: StateFlow<SourceState> = _state.asStateFlow()
@ -42,9 +38,9 @@ class SourcePresenter(
} }
} }
private suspend fun collectLatestSources(sources: List<Source>) { private fun collectLatestSources(sources: List<Source>) {
val map = TreeMap<String, MutableList<Source>> { d1, d2 -> val map = TreeMap<String, MutableList<Source>> { d1, d2 ->
// Catalogues without a lang defined will be placed at the end // Sources without a lang defined will be placed at the end
when { when {
d1 == LAST_USED_KEY && d2 != LAST_USED_KEY -> -1 d1 == LAST_USED_KEY && d2 != LAST_USED_KEY -> -1
d2 == LAST_USED_KEY && d1 != LAST_USED_KEY -> 1 d2 == LAST_USED_KEY && d1 != LAST_USED_KEY -> 1

View file

@ -60,9 +60,6 @@ import kotlinx.coroutines.flow.onEach
import logcat.LogPriority import logcat.LogPriority
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
/**
* Controller to manage the catalogues available in the app.
*/
open class BrowseSourceController(bundle: Bundle) : open class BrowseSourceController(bundle: Bundle) :
SearchableNucleusController<SourceControllerBinding, BrowseSourcePresenter>(bundle), SearchableNucleusController<SourceControllerBinding, BrowseSourcePresenter>(bundle),
FabController, FabController,

View file

@ -53,9 +53,6 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.util.Date import java.util.Date
/**
* Presenter of [BrowseSourceController].
*/
open class BrowseSourcePresenter( open class BrowseSourcePresenter(
private val sourceId: Long, private val sourceId: Long,
searchQuery: String? = null, searchQuery: String? = null,

View file

@ -4,7 +4,7 @@ import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.util.lang.awaitSingle import eu.kanade.tachiyomi.util.lang.awaitSingle
open class SourcePager(val source: CatalogueSource, val query: String, val filters: FilterList) : Pager() { class SourcePager(val source: CatalogueSource, val query: String, val filters: FilterList) : Pager() {
override suspend fun requestNextPage() { override suspend fun requestNextPage() {
val page = currentPage val page = currentPage

View file

@ -92,7 +92,7 @@ open class GlobalSearchPresenter(
} }
/** /**
* Returns a list of enabled sources ordered by language and name, with pinned catalogues * Returns a list of enabled sources ordered by language and name, with pinned sources
* prioritized. * prioritized.
* *
* @return list containing enabled sources. * @return list containing enabled sources.

View file

@ -17,7 +17,7 @@ import kotlin.math.abs
/** /**
* Implementation of a [RecyclerView] used by the webtoon reader. * Implementation of a [RecyclerView] used by the webtoon reader.
*/ */
open class WebtoonRecyclerView @JvmOverloads constructor( class WebtoonRecyclerView @JvmOverloads constructor(
context: Context, context: Context,
attrs: AttributeSet? = null, attrs: AttributeSet? = null,
defStyle: Int = 0, defStyle: Int = 0,

View file

@ -6,11 +6,7 @@ import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
/** class SettingsSearchPresenter : BasePresenter<SettingsSearchController>() {
* Presenter of [SettingsSearchController]
* Function calls should be done from here. UI calls should be done from the controller.
*/
open class SettingsSearchPresenter : BasePresenter<SettingsSearchController>() {
val preferences: PreferencesHelper = Injekt.get() val preferences: PreferencesHelper = Injekt.get()

View file

@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.util.system
import android.content.Context import android.content.Context
import androidx.core.os.LocaleListCompat import androidx.core.os.LocaleListCompat
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.browse.source.SourcePresenter import eu.kanade.tachiyomi.ui.browse.source.SourcesPresenter
import java.util.Locale import java.util.Locale
/** /**
@ -16,8 +16,8 @@ object LocaleHelper {
*/ */
fun getSourceDisplayName(lang: String?, context: Context): String { fun getSourceDisplayName(lang: String?, context: Context): String {
return when (lang) { return when (lang) {
SourcePresenter.LAST_USED_KEY -> context.getString(R.string.last_used_source) SourcesPresenter.LAST_USED_KEY -> context.getString(R.string.last_used_source)
SourcePresenter.PINNED_KEY -> context.getString(R.string.pinned_sources) SourcesPresenter.PINNED_KEY -> context.getString(R.string.pinned_sources)
"other" -> context.getString(R.string.other_source) "other" -> context.getString(R.string.other_source)
"all" -> context.getString(R.string.all_lang) "all" -> context.getString(R.string.all_lang)
else -> getDisplayName(lang) else -> getDisplayName(lang)