mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 12:01:52 +01:00
Migrate SettingsMainController to Compose
This commit is contained in:
parent
2752540330
commit
a4a4503311
@ -1,4 +1,4 @@
|
|||||||
package eu.kanade.presentation.more
|
package eu.kanade.presentation.more.about
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
@ -17,6 +17,7 @@ import androidx.compose.ui.res.painterResource
|
|||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import eu.kanade.presentation.components.LinkIcon
|
import eu.kanade.presentation.components.LinkIcon
|
||||||
import eu.kanade.presentation.components.PreferenceRow
|
import eu.kanade.presentation.components.PreferenceRow
|
||||||
|
import eu.kanade.presentation.more.LogoHeader
|
||||||
import eu.kanade.tachiyomi.BuildConfig
|
import eu.kanade.tachiyomi.BuildConfig
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.updater.RELEASE_URL
|
import eu.kanade.tachiyomi.data.updater.RELEASE_URL
|
@ -1,4 +1,4 @@
|
|||||||
package eu.kanade.presentation.more
|
package eu.kanade.presentation.more.about
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
@ -0,0 +1,37 @@
|
|||||||
|
package eu.kanade.presentation.more.settings
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
|
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
||||||
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import eu.kanade.presentation.components.PreferenceRow
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SettingsMainScreen(
|
||||||
|
nestedScrollInterop: NestedScrollConnection,
|
||||||
|
sections: List<SettingsSection>,
|
||||||
|
) {
|
||||||
|
LazyColumn(
|
||||||
|
modifier = Modifier.nestedScroll(nestedScrollInterop),
|
||||||
|
) {
|
||||||
|
sections.map {
|
||||||
|
item {
|
||||||
|
PreferenceRow(
|
||||||
|
title = stringResource(it.titleRes),
|
||||||
|
painter = it.painter,
|
||||||
|
onClick = it.onClick,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class SettingsSection(
|
||||||
|
@StringRes val titleRes: Int,
|
||||||
|
val painter: Painter,
|
||||||
|
val onClick: () -> Unit,
|
||||||
|
)
|
@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.more
|
|||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
||||||
import eu.kanade.presentation.more.AboutScreen
|
import eu.kanade.presentation.more.about.AboutScreen
|
||||||
import eu.kanade.tachiyomi.BuildConfig
|
import eu.kanade.tachiyomi.BuildConfig
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.more
|
|||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
||||||
import eu.kanade.presentation.more.LicensesScreen
|
import eu.kanade.presentation.more.about.LicensesScreen
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.BasicComposeController
|
import eu.kanade.tachiyomi.ui.base.controller.BasicComposeController
|
||||||
|
|
||||||
|
@ -4,88 +4,96 @@ import android.view.Menu
|
|||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.ChromeReaderMode
|
||||||
|
import androidx.compose.material.icons.outlined.Code
|
||||||
|
import androidx.compose.material.icons.outlined.GetApp
|
||||||
|
import androidx.compose.material.icons.outlined.Palette
|
||||||
|
import androidx.compose.material.icons.outlined.Security
|
||||||
|
import androidx.compose.material.icons.outlined.SettingsBackupRestore
|
||||||
|
import androidx.compose.material.icons.outlined.Sync
|
||||||
|
import androidx.compose.material.icons.outlined.Tune
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.graphics.vector.rememberVectorPainter
|
||||||
|
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import eu.kanade.presentation.more.settings.SettingsMainScreen
|
||||||
|
import eu.kanade.presentation.more.settings.SettingsSection
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.ui.base.controller.BasicComposeController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.pushController
|
import eu.kanade.tachiyomi.ui.base.controller.pushController
|
||||||
import eu.kanade.tachiyomi.ui.setting.search.SettingsSearchController
|
import eu.kanade.tachiyomi.ui.setting.search.SettingsSearchController
|
||||||
import eu.kanade.tachiyomi.util.preference.iconRes
|
import uy.kohesive.injekt.injectLazy
|
||||||
import eu.kanade.tachiyomi.util.preference.iconTint
|
|
||||||
import eu.kanade.tachiyomi.util.preference.onClick
|
|
||||||
import eu.kanade.tachiyomi.util.preference.preference
|
|
||||||
import eu.kanade.tachiyomi.util.preference.titleRes
|
|
||||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
|
||||||
|
|
||||||
class SettingsMainController : SettingsController() {
|
class SettingsMainController : BasicComposeController() {
|
||||||
|
|
||||||
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
titleRes = R.string.label_settings
|
|
||||||
|
|
||||||
val tintColor = context.getResourceColor(R.attr.colorAccent)
|
override fun getTitle() = resources?.getString(R.string.label_settings)
|
||||||
|
|
||||||
preference {
|
@Composable
|
||||||
iconRes = R.drawable.ic_tune_24dp
|
override fun ComposeContent(nestedScrollInterop: NestedScrollConnection) {
|
||||||
iconTint = tintColor
|
val settingsSections = listOf(
|
||||||
titleRes = R.string.pref_category_general
|
SettingsSection(
|
||||||
onClick { router.pushController(SettingsGeneralController()) }
|
titleRes = R.string.pref_category_general,
|
||||||
}
|
painter = rememberVectorPainter(Icons.Outlined.Tune),
|
||||||
preference {
|
onClick = { router.pushController(SettingsGeneralController()) },
|
||||||
iconRes = R.drawable.ic_palette_24dp
|
),
|
||||||
iconTint = tintColor
|
SettingsSection(
|
||||||
titleRes = R.string.pref_category_appearance
|
titleRes = R.string.pref_category_appearance,
|
||||||
onClick { router.pushController(SettingsAppearanceController()) }
|
painter = rememberVectorPainter(Icons.Outlined.Palette),
|
||||||
}
|
onClick = { router.pushController(SettingsAppearanceController()) },
|
||||||
preference {
|
),
|
||||||
iconRes = R.drawable.ic_library_outline_24dp
|
SettingsSection(
|
||||||
iconTint = tintColor
|
titleRes = R.string.pref_category_library,
|
||||||
titleRes = R.string.pref_category_library
|
painter = painterResource(R.drawable.ic_library_outline_24dp),
|
||||||
onClick { router.pushController(SettingsLibraryController()) }
|
onClick = { router.pushController(SettingsLibraryController()) },
|
||||||
}
|
),
|
||||||
preference {
|
SettingsSection(
|
||||||
iconRes = R.drawable.ic_chrome_reader_mode_24dp
|
titleRes = R.string.pref_category_reader,
|
||||||
iconTint = tintColor
|
painter = rememberVectorPainter(Icons.Outlined.ChromeReaderMode),
|
||||||
titleRes = R.string.pref_category_reader
|
onClick = { router.pushController(SettingsReaderController()) },
|
||||||
onClick { router.pushController(SettingsReaderController()) }
|
),
|
||||||
}
|
SettingsSection(
|
||||||
preference {
|
titleRes = R.string.pref_category_downloads,
|
||||||
iconRes = R.drawable.ic_get_app_24dp
|
painter = rememberVectorPainter(Icons.Outlined.GetApp),
|
||||||
iconTint = tintColor
|
onClick = { router.pushController(SettingsDownloadController()) },
|
||||||
titleRes = R.string.pref_category_downloads
|
),
|
||||||
onClick { router.pushController(SettingsDownloadController()) }
|
SettingsSection(
|
||||||
}
|
titleRes = R.string.pref_category_tracking,
|
||||||
preference {
|
painter = rememberVectorPainter(Icons.Outlined.Sync),
|
||||||
iconRes = R.drawable.ic_sync_24dp
|
onClick = { router.pushController(SettingsTrackingController()) },
|
||||||
iconTint = tintColor
|
),
|
||||||
titleRes = R.string.pref_category_tracking
|
SettingsSection(
|
||||||
onClick { router.pushController(SettingsTrackingController()) }
|
titleRes = R.string.browse,
|
||||||
}
|
painter = painterResource(R.drawable.ic_browse_outline_24dp),
|
||||||
preference {
|
onClick = { router.pushController(SettingsBrowseController()) },
|
||||||
iconRes = R.drawable.ic_browse_outline_24dp
|
),
|
||||||
iconTint = tintColor
|
SettingsSection(
|
||||||
titleRes = R.string.browse
|
titleRes = R.string.label_backup,
|
||||||
onClick { router.pushController(SettingsBrowseController()) }
|
painter = rememberVectorPainter(Icons.Outlined.SettingsBackupRestore),
|
||||||
}
|
onClick = { router.pushController(SettingsBackupController()) },
|
||||||
preference {
|
),
|
||||||
iconRes = R.drawable.ic_settings_backup_restore_24dp
|
SettingsSection(
|
||||||
iconTint = tintColor
|
titleRes = R.string.pref_category_security,
|
||||||
titleRes = R.string.label_backup
|
painter = rememberVectorPainter(Icons.Outlined.Security),
|
||||||
onClick { router.pushController(SettingsBackupController()) }
|
onClick = { router.pushController(SettingsSecurityController()) },
|
||||||
}
|
),
|
||||||
preference {
|
SettingsSection(
|
||||||
iconRes = R.drawable.ic_security_24dp
|
titleRes = R.string.pref_category_advanced,
|
||||||
iconTint = tintColor
|
painter = rememberVectorPainter(Icons.Outlined.Code),
|
||||||
titleRes = R.string.pref_category_security
|
onClick = { router.pushController(SettingsAdvancedController()) },
|
||||||
onClick { router.pushController(SettingsSecurityController()) }
|
),
|
||||||
}
|
)
|
||||||
preference {
|
|
||||||
iconRes = R.drawable.ic_code_24dp
|
SettingsMainScreen(
|
||||||
iconTint = tintColor
|
nestedScrollInterop = nestedScrollInterop,
|
||||||
titleRes = R.string.pref_category_advanced
|
sections = settingsSections,
|
||||||
onClick { router.pushController(SettingsAdvancedController()) }
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
// Inflate menu
|
|
||||||
inflater.inflate(R.menu.settings_main, menu)
|
inflater.inflate(R.menu.settings_main, menu)
|
||||||
|
|
||||||
// Initialize search option.
|
// Initialize search option.
|
||||||
|
Loading…
Reference in New Issue
Block a user