Migrate SettingsMainController to Compose

This commit is contained in:
arkon 2022-04-26 22:41:42 -04:00
parent 2752540330
commit a4a4503311
6 changed files with 122 additions and 76 deletions

View file

@ -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.Row
@ -17,6 +17,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import eu.kanade.presentation.components.LinkIcon
import eu.kanade.presentation.components.PreferenceRow
import eu.kanade.presentation.more.LogoHeader
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.updater.RELEASE_URL

View file

@ -1,4 +1,4 @@
package eu.kanade.presentation.more
package eu.kanade.presentation.more.about
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme

View file

@ -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,
)

View file

@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.more
import androidx.compose.runtime.Composable
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.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper

View file

@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.more
import androidx.compose.runtime.Composable
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.ui.base.controller.BasicComposeController

View file

@ -4,88 +4,96 @@ import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
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.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.base.controller.BasicComposeController
import eu.kanade.tachiyomi.ui.base.controller.pushController
import eu.kanade.tachiyomi.ui.setting.search.SettingsSearchController
import eu.kanade.tachiyomi.util.preference.iconRes
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
import uy.kohesive.injekt.injectLazy
class SettingsMainController : SettingsController() {
class SettingsMainController : BasicComposeController() {
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
titleRes = R.string.label_settings
private val preferences: PreferencesHelper by injectLazy()
val tintColor = context.getResourceColor(R.attr.colorAccent)
override fun getTitle() = resources?.getString(R.string.label_settings)
preference {
iconRes = R.drawable.ic_tune_24dp
iconTint = tintColor
titleRes = R.string.pref_category_general
onClick { router.pushController(SettingsGeneralController()) }
}
preference {
iconRes = R.drawable.ic_palette_24dp
iconTint = tintColor
titleRes = R.string.pref_category_appearance
onClick { router.pushController(SettingsAppearanceController()) }
}
preference {
iconRes = R.drawable.ic_library_outline_24dp
iconTint = tintColor
titleRes = R.string.pref_category_library
onClick { router.pushController(SettingsLibraryController()) }
}
preference {
iconRes = R.drawable.ic_chrome_reader_mode_24dp
iconTint = tintColor
titleRes = R.string.pref_category_reader
onClick { router.pushController(SettingsReaderController()) }
}
preference {
iconRes = R.drawable.ic_get_app_24dp
iconTint = tintColor
titleRes = R.string.pref_category_downloads
onClick { router.pushController(SettingsDownloadController()) }
}
preference {
iconRes = R.drawable.ic_sync_24dp
iconTint = tintColor
titleRes = R.string.pref_category_tracking
onClick { router.pushController(SettingsTrackingController()) }
}
preference {
iconRes = R.drawable.ic_browse_outline_24dp
iconTint = tintColor
titleRes = R.string.browse
onClick { router.pushController(SettingsBrowseController()) }
}
preference {
iconRes = R.drawable.ic_settings_backup_restore_24dp
iconTint = tintColor
titleRes = R.string.label_backup
onClick { router.pushController(SettingsBackupController()) }
}
preference {
iconRes = R.drawable.ic_security_24dp
iconTint = tintColor
titleRes = R.string.pref_category_security
onClick { router.pushController(SettingsSecurityController()) }
}
preference {
iconRes = R.drawable.ic_code_24dp
iconTint = tintColor
titleRes = R.string.pref_category_advanced
onClick { router.pushController(SettingsAdvancedController()) }
}
@Composable
override fun ComposeContent(nestedScrollInterop: NestedScrollConnection) {
val settingsSections = listOf(
SettingsSection(
titleRes = R.string.pref_category_general,
painter = rememberVectorPainter(Icons.Outlined.Tune),
onClick = { router.pushController(SettingsGeneralController()) },
),
SettingsSection(
titleRes = R.string.pref_category_appearance,
painter = rememberVectorPainter(Icons.Outlined.Palette),
onClick = { router.pushController(SettingsAppearanceController()) },
),
SettingsSection(
titleRes = R.string.pref_category_library,
painter = painterResource(R.drawable.ic_library_outline_24dp),
onClick = { router.pushController(SettingsLibraryController()) },
),
SettingsSection(
titleRes = R.string.pref_category_reader,
painter = rememberVectorPainter(Icons.Outlined.ChromeReaderMode),
onClick = { router.pushController(SettingsReaderController()) },
),
SettingsSection(
titleRes = R.string.pref_category_downloads,
painter = rememberVectorPainter(Icons.Outlined.GetApp),
onClick = { router.pushController(SettingsDownloadController()) },
),
SettingsSection(
titleRes = R.string.pref_category_tracking,
painter = rememberVectorPainter(Icons.Outlined.Sync),
onClick = { router.pushController(SettingsTrackingController()) },
),
SettingsSection(
titleRes = R.string.browse,
painter = painterResource(R.drawable.ic_browse_outline_24dp),
onClick = { router.pushController(SettingsBrowseController()) },
),
SettingsSection(
titleRes = R.string.label_backup,
painter = rememberVectorPainter(Icons.Outlined.SettingsBackupRestore),
onClick = { router.pushController(SettingsBackupController()) },
),
SettingsSection(
titleRes = R.string.pref_category_security,
painter = rememberVectorPainter(Icons.Outlined.Security),
onClick = { router.pushController(SettingsSecurityController()) },
),
SettingsSection(
titleRes = R.string.pref_category_advanced,
painter = rememberVectorPainter(Icons.Outlined.Code),
onClick = { router.pushController(SettingsAdvancedController()) },
),
)
SettingsMainScreen(
nestedScrollInterop = nestedScrollInterop,
sections = settingsSections,
)
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
// Inflate menu
inflater.inflate(R.menu.settings_main, menu)
// Initialize search option.