mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
chore: WIP compose library page
This commit is contained in:
parent
6a680facd5
commit
d655c3e09a
14 changed files with 200 additions and 3 deletions
|
@ -17,12 +17,14 @@ import yokai.presentation.theme.YokaiTheme
|
||||||
abstract class BaseComposeController(bundle: Bundle? = null) :
|
abstract class BaseComposeController(bundle: Bundle? = null) :
|
||||||
BaseController(bundle) {
|
BaseController(bundle) {
|
||||||
|
|
||||||
|
override val shouldHideLegacyAppBar = true
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup,
|
container: ViewGroup,
|
||||||
savedViewState: Bundle?
|
savedViewState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
hideLegacyAppBar()
|
setAppBarVisibility()
|
||||||
return ComposeView(container.context).apply {
|
return ComposeView(container.context).apply {
|
||||||
layoutParams = ViewGroup.LayoutParams(
|
layoutParams = ViewGroup.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
|
|
@ -25,6 +25,8 @@ import kotlinx.coroutines.cancel
|
||||||
abstract class BaseController(bundle: Bundle? = null) :
|
abstract class BaseController(bundle: Bundle? = null) :
|
||||||
Controller(bundle), BackHandlerControllerInterface, BaseControllerPreferenceControllerCommonInterface {
|
Controller(bundle), BackHandlerControllerInterface, BaseControllerPreferenceControllerCommonInterface {
|
||||||
|
|
||||||
|
abstract val shouldHideLegacyAppBar: Boolean
|
||||||
|
|
||||||
lateinit var viewScope: CoroutineScope
|
lateinit var viewScope: CoroutineScope
|
||||||
var isDragging = false
|
var isDragging = false
|
||||||
|
|
||||||
|
@ -58,6 +60,10 @@ abstract class BaseController(bundle: Bundle? = null) :
|
||||||
|
|
||||||
open fun onViewCreated(view: View) { }
|
open fun onViewCreated(view: View) { }
|
||||||
|
|
||||||
|
internal fun setAppBarVisibility() {
|
||||||
|
if (shouldHideLegacyAppBar) hideLegacyAppBar() else showLegacyAppBar()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
||||||
if (type.isEnter && !isControllerVisible) {
|
if (type.isEnter && !isControllerVisible) {
|
||||||
view?.alpha = 0f
|
view?.alpha = 0f
|
||||||
|
|
|
@ -20,11 +20,13 @@ import eu.kanade.tachiyomi.util.view.isControllerVisible
|
||||||
abstract class BaseLegacyController<VB : ViewBinding>(bundle: Bundle? = null) :
|
abstract class BaseLegacyController<VB : ViewBinding>(bundle: Bundle? = null) :
|
||||||
BaseController(bundle) {
|
BaseController(bundle) {
|
||||||
|
|
||||||
|
override val shouldHideLegacyAppBar = false
|
||||||
|
|
||||||
lateinit var binding: VB
|
lateinit var binding: VB
|
||||||
val isBindingInitialized get() = this::binding.isInitialized
|
val isBindingInitialized get() = this::binding.isInitialized
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View {
|
||||||
showLegacyAppBar()
|
setAppBarVisibility()
|
||||||
binding = createBinding(inflater)
|
binding = createBinding(inflater)
|
||||||
binding.root.backgroundColor = binding.root.context.getResourceColor(R.attr.background)
|
binding.root.backgroundColor = binding.root.context.getResourceColor(R.attr.background)
|
||||||
return binding.root
|
return binding.root
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package eu.kanade.tachiyomi.ui.library
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.ui.base.controller.BaseComposeController
|
||||||
|
import uy.kohesive.injekt.Injekt
|
||||||
|
import uy.kohesive.injekt.api.get
|
||||||
|
import yokai.domain.ui.UiPreferences
|
||||||
|
import yokai.presentation.library.LibraryScreen
|
||||||
|
|
||||||
|
class LibraryComposeController(
|
||||||
|
bundle: Bundle? = null,
|
||||||
|
val uiPreferences: UiPreferences = Injekt.get(),
|
||||||
|
val preferences: PreferencesHelper = Injekt.get(),
|
||||||
|
) : BaseComposeController(bundle) {
|
||||||
|
override val shouldHideLegacyAppBar = false
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
override fun ScreenContent() {
|
||||||
|
LibraryScreen()
|
||||||
|
}
|
||||||
|
}
|
|
@ -85,6 +85,7 @@ import eu.kanade.tachiyomi.ui.base.SmallToolbarInterface
|
||||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.BaseLegacyController
|
import eu.kanade.tachiyomi.ui.base.controller.BaseLegacyController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||||
|
import eu.kanade.tachiyomi.ui.library.LibraryComposeController
|
||||||
import eu.kanade.tachiyomi.ui.library.LibraryController
|
import eu.kanade.tachiyomi.ui.library.LibraryController
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
|
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
|
||||||
import eu.kanade.tachiyomi.ui.more.AboutController
|
import eu.kanade.tachiyomi.ui.more.AboutController
|
||||||
|
@ -538,7 +539,7 @@ open class MainActivity : BaseActivity<MainActivityBinding>() {
|
||||||
if (currentRoot?.tag()?.toIntOrNull() != id) {
|
if (currentRoot?.tag()?.toIntOrNull() != id) {
|
||||||
setRoot(
|
setRoot(
|
||||||
when (id) {
|
when (id) {
|
||||||
R.id.nav_library -> LibraryController()
|
R.id.nav_library -> if (basePreferences.composeLibrary().get()) LibraryComposeController() else LibraryController()
|
||||||
R.id.nav_recents -> RecentsController()
|
R.id.nav_recents -> RecentsController()
|
||||||
else -> BrowseController()
|
else -> BrowseController()
|
||||||
},
|
},
|
||||||
|
|
|
@ -394,6 +394,10 @@ class SettingsAdvancedController : SettingsLegacyController() {
|
||||||
|
|
||||||
onClick { LibraryUpdateJob.startNow(context, target = Target.TRACKING) }
|
onClick { LibraryUpdateJob.startNow(context, target = Target.TRACKING) }
|
||||||
}
|
}
|
||||||
|
switchPreference {
|
||||||
|
bindTo(basePreferences.composeLibrary())
|
||||||
|
title = context.getString(MR.strings.pref_use_compose_library).addBetaTag(context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
preferenceCategory {
|
preferenceCategory {
|
||||||
|
|
|
@ -49,4 +49,6 @@ class BasePreferences(private val preferenceStore: PreferenceStore) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hardwareBitmapThreshold() = preferenceStore.getInt("pref_hardware_bitmap_threshold", GLUtil.SAFE_TEXTURE_LIMIT)
|
fun hardwareBitmapThreshold() = preferenceStore.getInt("pref_hardware_bitmap_threshold", GLUtil.SAFE_TEXTURE_LIMIT)
|
||||||
|
|
||||||
|
fun composeLibrary() = preferenceStore.getBoolean("pref_use_compose_library", false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,7 @@ fun YokaiScaffold(
|
||||||
scrollBehavior = scrollBehaviorOrDefault,
|
scrollBehavior = scrollBehaviorOrDefault,
|
||||||
actions = actions,
|
actions = actions,
|
||||||
)
|
)
|
||||||
|
AppBarType.NONE -> {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
snackbarHost = snackbarHost,
|
snackbarHost = snackbarHost,
|
||||||
|
@ -115,6 +116,8 @@ fun getTopAppBarColor(title: String): Pair<Color, Color> {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class AppBarType {
|
enum class AppBarType {
|
||||||
|
// FIXME: Delete "NONE" later
|
||||||
|
NONE,
|
||||||
SMALL,
|
SMALL,
|
||||||
LARGE,
|
LARGE,
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package yokai.presentation.library
|
||||||
|
|
||||||
|
import androidx.compose.foundation.lazy.grid.items
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import yokai.presentation.AppBarType
|
||||||
|
import yokai.presentation.YokaiScaffold
|
||||||
|
import yokai.presentation.library.components.LazyLibraryGrid
|
||||||
|
import yokai.util.Screen
|
||||||
|
|
||||||
|
class LibraryScreen : Screen() {
|
||||||
|
@Composable
|
||||||
|
override fun Content() {
|
||||||
|
val columns = 3 // FIXME: Retrieve from preferences
|
||||||
|
val items = (0..100).toList()
|
||||||
|
YokaiScaffold(
|
||||||
|
onNavigationIconClicked = {},
|
||||||
|
appBarType = AppBarType.NONE,
|
||||||
|
) { contentPadding ->
|
||||||
|
LazyLibraryGrid(
|
||||||
|
columns = columns,
|
||||||
|
contentPadding = contentPadding,
|
||||||
|
) {
|
||||||
|
items(
|
||||||
|
items = items,
|
||||||
|
contentType = { "library_grid_item" }
|
||||||
|
) {
|
||||||
|
Text("Hello world! ($it)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package yokai.presentation.library.components
|
||||||
|
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
object CommonMangaItemDefaults {
|
||||||
|
val GridHorizontalSpacer = 4.dp
|
||||||
|
val GridVerticalSpacer = 4.dp
|
||||||
|
|
||||||
|
@Suppress("ConstPropertyName")
|
||||||
|
const val BrowseFavoriteCoverAlpha = 0.34f
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package yokai.presentation.library.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.lazy.grid.GridCells
|
||||||
|
import androidx.compose.foundation.lazy.grid.LazyGridScope
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import yokai.presentation.core.components.FastScrollLazyVerticalGrid
|
||||||
|
import yokai.presentation.core.util.plus
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
internal fun LazyLibraryGrid(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
columns: Int,
|
||||||
|
contentPadding: PaddingValues,
|
||||||
|
content: LazyGridScope.() -> Unit,
|
||||||
|
) {
|
||||||
|
FastScrollLazyVerticalGrid(
|
||||||
|
columns = if (columns == 0) GridCells.Adaptive(128.dp) else GridCells.Fixed(columns),
|
||||||
|
modifier = modifier,
|
||||||
|
contentPadding = contentPadding + PaddingValues(8.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(CommonMangaItemDefaults.GridVerticalSpacer),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(CommonMangaItemDefaults.GridHorizontalSpacer),
|
||||||
|
content = content,
|
||||||
|
)
|
||||||
|
}
|
|
@ -166,6 +166,8 @@
|
||||||
<string name="tracking_status">Tracking status</string>
|
<string name="tracking_status">Tracking status</string>
|
||||||
<string name="ungrouped">Ungrouped</string>
|
<string name="ungrouped">Ungrouped</string>
|
||||||
|
|
||||||
|
<string name="pref_use_compose_library">Use experimental compose library</string>
|
||||||
|
|
||||||
<!-- Library Sort -->
|
<!-- Library Sort -->
|
||||||
<string name="sort_by">Sort by</string>
|
<string name="sort_by">Sort by</string>
|
||||||
<string name="total_chapters">Total chapters</string>
|
<string name="total_chapters">Total chapters</string>
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package yokai.presentation.core.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.lazy.grid.GridCells
|
||||||
|
import androidx.compose.foundation.lazy.grid.LazyGridScope
|
||||||
|
import androidx.compose.foundation.lazy.grid.LazyGridState
|
||||||
|
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||||
|
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun FastScrollLazyVerticalGrid(
|
||||||
|
columns: GridCells,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
state: LazyGridState = rememberLazyGridState(),
|
||||||
|
thumbAllowed: () -> Boolean = { true },
|
||||||
|
thumbColor: Color = MaterialTheme.colorScheme.primary,
|
||||||
|
contentPadding: PaddingValues = PaddingValues(0.dp),
|
||||||
|
topContentPadding: Dp = Dp.Hairline,
|
||||||
|
bottomContentPadding: Dp = Dp.Hairline,
|
||||||
|
endContentPadding: Dp = Dp.Hairline,
|
||||||
|
reverseLayout: Boolean = false,
|
||||||
|
verticalArrangement: Arrangement.Vertical =
|
||||||
|
if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
|
||||||
|
horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
|
||||||
|
userScrollEnabled: Boolean = true,
|
||||||
|
content: LazyGridScope.() -> Unit,
|
||||||
|
) {
|
||||||
|
VerticalGridFastScroller(
|
||||||
|
state = state,
|
||||||
|
columns = columns,
|
||||||
|
arrangement = horizontalArrangement,
|
||||||
|
contentPadding = contentPadding,
|
||||||
|
modifier = modifier,
|
||||||
|
thumbAllowed = thumbAllowed,
|
||||||
|
thumbColor = thumbColor,
|
||||||
|
topContentPadding = topContentPadding,
|
||||||
|
bottomContentPadding = bottomContentPadding,
|
||||||
|
endContentPadding = endContentPadding,
|
||||||
|
) {
|
||||||
|
LazyVerticalGrid(
|
||||||
|
columns = columns,
|
||||||
|
state = state,
|
||||||
|
contentPadding = contentPadding,
|
||||||
|
reverseLayout = reverseLayout,
|
||||||
|
verticalArrangement = verticalArrangement,
|
||||||
|
horizontalArrangement = horizontalArrangement,
|
||||||
|
userScrollEnabled = userScrollEnabled,
|
||||||
|
content = content,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package yokai.presentation.core.util
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.layout.calculateEndPadding
|
||||||
|
import androidx.compose.foundation.layout.calculateStartPadding
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.ReadOnlyComposable
|
||||||
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
@ReadOnlyComposable
|
||||||
|
operator fun PaddingValues.plus(other: PaddingValues): PaddingValues {
|
||||||
|
val layoutDirection = LocalLayoutDirection.current
|
||||||
|
return PaddingValues(
|
||||||
|
start = calculateStartPadding(layoutDirection) +
|
||||||
|
other.calculateStartPadding(layoutDirection),
|
||||||
|
end = calculateEndPadding(layoutDirection) +
|
||||||
|
other.calculateEndPadding(layoutDirection),
|
||||||
|
top = calculateTopPadding() + other.calculateTopPadding(),
|
||||||
|
bottom = calculateBottomPadding() + other.calculateBottomPadding(),
|
||||||
|
)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue