Resolve review comments for BrowseSourceScreens (#7912)

This commit is contained in:
Andreas 2022-08-31 22:47:07 +02:00 committed by GitHub
parent 504844a892
commit 2f26982e34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 56 additions and 71 deletions

View File

@ -4,17 +4,14 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.platform.LocalUriHandler
import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.presentation.browse.components.BrowseLatestToolbar import eu.kanade.presentation.browse.components.BrowseLatestToolbar
import eu.kanade.presentation.components.Scaffold import eu.kanade.presentation.components.Scaffold
import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter
import eu.kanade.tachiyomi.ui.more.MoreController import eu.kanade.tachiyomi.ui.more.MoreController
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
@Composable @Composable
fun BrowseLatestScreen( fun BrowseLatestScreen(
@ -22,21 +19,16 @@ fun BrowseLatestScreen(
navigateUp: () -> Unit, navigateUp: () -> Unit,
onMangaClick: (Manga) -> Unit, onMangaClick: (Manga) -> Unit,
onMangaLongClick: (Manga) -> Unit, onMangaLongClick: (Manga) -> Unit,
onWebViewClick: () -> Unit,
) { ) {
val columns by presenter.getColumnsPreferenceForCurrentOrientation() val columns by presenter.getColumnsPreferenceForCurrentOrientation()
val context = LocalContext.current
val uriHandler = LocalUriHandler.current val uriHandler = LocalUriHandler.current
val onHelpClick = { val onHelpClick = {
uriHandler.openUri(LocalSource.HELP_URL) uriHandler.openUri(LocalSource.HELP_URL)
} }
val onWebViewClick = f@{
val source = presenter.source as? HttpSource ?: return@f
val intent = WebViewActivity.newIntent(context, source.baseUrl, source.id, source.name)
context.startActivity(intent)
}
Scaffold( Scaffold(
topBar = { scrollBehavior -> topBar = { scrollBehavior ->
BrowseLatestToolbar( BrowseLatestToolbar(

View File

@ -34,12 +34,10 @@ import eu.kanade.presentation.components.Scaffold
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter
import eu.kanade.tachiyomi.ui.browse.source.browse.NoResultsException import eu.kanade.tachiyomi.ui.browse.source.browse.NoResultsException
import eu.kanade.tachiyomi.ui.library.setting.LibraryDisplayMode import eu.kanade.tachiyomi.ui.library.setting.LibraryDisplayMode
import eu.kanade.tachiyomi.ui.more.MoreController import eu.kanade.tachiyomi.ui.more.MoreController
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.widget.EmptyView import eu.kanade.tachiyomi.widget.EmptyView
@Composable @Composable
@ -50,6 +48,7 @@ fun BrowseSourceScreen(
onFabClick: () -> Unit, onFabClick: () -> Unit,
onMangaClick: (Manga) -> Unit, onMangaClick: (Manga) -> Unit,
onMangaLongClick: (Manga) -> Unit, onMangaLongClick: (Manga) -> Unit,
onWebViewClick: () -> Unit,
) { ) {
val columns by presenter.getColumnsPreferenceForCurrentOrientation() val columns by presenter.getColumnsPreferenceForCurrentOrientation()
@ -57,19 +56,12 @@ fun BrowseSourceScreen(
val snackbarHostState = remember { SnackbarHostState() } val snackbarHostState = remember { SnackbarHostState() }
val context = LocalContext.current
val uriHandler = LocalUriHandler.current val uriHandler = LocalUriHandler.current
val onHelpClick = { val onHelpClick = {
uriHandler.openUri(LocalSource.HELP_URL) uriHandler.openUri(LocalSource.HELP_URL)
} }
val onWebViewClick = f@{
val source = presenter.source as? HttpSource ?: return@f
val intent = WebViewActivity.newIntent(context, source.baseUrl, source.id, source.name)
context.startActivity(intent)
}
Scaffold( Scaffold(
topBar = { scrollBehavior -> topBar = { scrollBehavior ->
BrowseSourceToolbar( BrowseSourceToolbar(

View File

@ -1,8 +1,11 @@
package eu.kanade.presentation.browse package eu.kanade.presentation.browse
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.glance.LocalContext
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
@Composable @Composable
fun SourceSearchScreen( fun SourceSearchScreen(
@ -11,6 +14,8 @@ fun SourceSearchScreen(
onFabClick: () -> Unit, onFabClick: () -> Unit,
onClickManga: (Manga) -> Unit, onClickManga: (Manga) -> Unit,
) { ) {
val context = LocalContext.current
BrowseSourceScreen( BrowseSourceScreen(
presenter = presenter, presenter = presenter,
navigateUp = navigateUp, navigateUp = navigateUp,
@ -18,5 +23,10 @@ fun SourceSearchScreen(
onFabClick = onFabClick, onFabClick = onFabClick,
onMangaClick = onClickManga, onMangaClick = onClickManga,
onMangaLongClick = onClickManga, onMangaLongClick = onClickManga,
onWebViewClick = f@{
val source = presenter.source as? HttpSource ?: return@f
val intent = WebViewActivity.newIntent(context, source.baseUrl, source.id, source.name)
context.startActivity(intent)
},
) )
} }

View File

@ -42,19 +42,19 @@ fun BrowseLatestToolbar(
AppBarActions( AppBarActions(
actions = listOf( actions = listOf(
AppBar.Action( AppBar.Action(
title = "display_mode", title = stringResource(id = R.string.action_display_mode),
icon = Icons.Filled.ViewModule, icon = Icons.Filled.ViewModule,
onClick = { selectingDisplayMode = true }, onClick = { selectingDisplayMode = true },
), ),
if (source is LocalSource) { if (source is LocalSource) {
AppBar.Action( AppBar.Action(
title = "help", title = stringResource(id = R.string.label_help),
icon = Icons.Outlined.Help, icon = Icons.Outlined.Help,
onClick = onHelpClick, onClick = onHelpClick,
) )
} else { } else {
AppBar.Action( AppBar.Action(
title = "webview", title = stringResource(id = R.string.action_web_view),
icon = Icons.Outlined.Public, icon = Icons.Outlined.Public,
onClick = onWebViewClick, onClick = onWebViewClick,
) )

View File

@ -1,42 +1,33 @@
package eu.kanade.presentation.browse.components package eu.kanade.presentation.browse.components
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ViewModule import androidx.compose.material.icons.filled.ViewModule
import androidx.compose.material.icons.outlined.Check import androidx.compose.material.icons.outlined.Check
import androidx.compose.material.icons.outlined.Clear
import androidx.compose.material.icons.outlined.Help import androidx.compose.material.icons.outlined.Help
import androidx.compose.material.icons.outlined.Public import androidx.compose.material.icons.outlined.Public
import androidx.compose.material.icons.outlined.Search import androidx.compose.material.icons.outlined.Search
import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.ImeAction
import eu.kanade.presentation.browse.BrowseSourceState import eu.kanade.presentation.browse.BrowseSourceState
import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.components.AppBar
import eu.kanade.presentation.components.AppBarActions import eu.kanade.presentation.components.AppBarActions
import eu.kanade.presentation.components.DropdownMenu import eu.kanade.presentation.components.DropdownMenu
import eu.kanade.presentation.components.SearchToolbar
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.ui.library.setting.LibraryDisplayMode import eu.kanade.tachiyomi.ui.library.setting.LibraryDisplayMode
import kotlinx.coroutines.delay
@Composable @Composable
fun BrowseSourceToolbar( fun BrowseSourceToolbar(
@ -95,24 +86,24 @@ fun BrowseSourceRegularToolbar(
AppBarActions( AppBarActions(
actions = listOf( actions = listOf(
AppBar.Action( AppBar.Action(
title = "search", title = stringResource(id = R.string.action_search),
icon = Icons.Outlined.Search, icon = Icons.Outlined.Search,
onClick = onSearchClick, onClick = onSearchClick,
), ),
AppBar.Action( AppBar.Action(
title = "display_mode", title = stringResource(id = R.string.action_display_mode),
icon = Icons.Filled.ViewModule, icon = Icons.Filled.ViewModule,
onClick = { selectingDisplayMode = true }, onClick = { selectingDisplayMode = true },
), ),
if (source is LocalSource) { if (source is LocalSource) {
AppBar.Action( AppBar.Action(
title = "help", title = stringResource(id = R.string.label_help),
icon = Icons.Outlined.Help, icon = Icons.Outlined.Help,
onClick = onHelpClick, onClick = onHelpClick,
) )
} else { } else {
AppBar.Action( AppBar.Action(
title = "webview", title = stringResource(id = R.string.action_web_view),
icon = Icons.Outlined.Public, icon = Icons.Outlined.Public,
onClick = onWebViewClick, onClick = onWebViewClick,
) )
@ -174,41 +165,17 @@ fun BrowseSourceSearchToolbar(
onSearchClick: () -> Unit, onSearchClick: () -> Unit,
scrollBehavior: TopAppBarScrollBehavior, scrollBehavior: TopAppBarScrollBehavior,
) { ) {
val focusRequester = remember { FocusRequester() } SearchToolbar(
AppBar( searchQuery = searchQuery,
navigateUp = navigateUp, onChangeSearchQuery = onSearchQueryChanged,
titleContent = { keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
BasicTextField( keyboardActions = KeyboardActions(
value = searchQuery, onSearch = {
onValueChange = onSearchQueryChanged, onSearchClick()
modifier = Modifier },
.fillMaxWidth() ),
.focusRequester(focusRequester), onClickCloseSearch = navigateUp,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search), onClickResetSearch = onResetClick,
keyboardActions = KeyboardActions(
onSearch = {
onSearchClick()
},
),
cursorBrush = SolidColor(MaterialTheme.colorScheme.onSurface),
)
},
actions = {
AppBarActions(
actions = listOf(
AppBar.Action(
title = "clear",
icon = Icons.Outlined.Clear,
onClick = onResetClick,
),
),
)
},
scrollBehavior = scrollBehavior, scrollBehavior = scrollBehavior,
) )
LaunchedEffect(Unit) {
// TODO: https://issuetracker.google.com/issues/204502668
delay(100)
focusRequester.requestFocus()
}
} }

View File

@ -7,6 +7,8 @@ import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.statusBars import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Close import androidx.compose.material.icons.filled.Close
@ -220,6 +222,8 @@ fun AppBarActions(
fun SearchToolbar( fun SearchToolbar(
searchQuery: String, searchQuery: String,
onChangeSearchQuery: (String) -> Unit, onChangeSearchQuery: (String) -> Unit,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
onClickCloseSearch: () -> Unit, onClickCloseSearch: () -> Unit,
onClickResetSearch: () -> Unit, onClickResetSearch: () -> Unit,
incognitoMode: Boolean = false, incognitoMode: Boolean = false,
@ -236,6 +240,8 @@ fun SearchToolbar(
.fillMaxWidth() .fillMaxWidth()
.focusRequester(focusRequester), .focusRequester(focusRequester),
textStyle = MaterialTheme.typography.bodyMedium.copy(color = MaterialTheme.colorScheme.onBackground), textStyle = MaterialTheme.typography.bodyMedium.copy(color = MaterialTheme.colorScheme.onBackground),
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
singleLine = true, singleLine = true,
cursorBrush = SolidColor(MaterialTheme.colorScheme.onBackground), cursorBrush = SolidColor(MaterialTheme.colorScheme.onBackground),
) )

View File

@ -4,6 +4,7 @@ import android.os.Bundle
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.LocalContext
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.model.Source
import eu.kanade.presentation.browse.BrowseSourceScreen import eu.kanade.presentation.browse.BrowseSourceScreen
@ -12,11 +13,13 @@ import eu.kanade.presentation.components.ChangeCategoryDialog
import eu.kanade.presentation.components.DuplicateMangaDialog import eu.kanade.presentation.components.DuplicateMangaDialog
import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.base.controller.FullComposeController import eu.kanade.tachiyomi.ui.base.controller.FullComposeController
import eu.kanade.tachiyomi.ui.base.controller.pushController import eu.kanade.tachiyomi.ui.base.controller.pushController
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter.Dialog import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter.Dialog
import eu.kanade.tachiyomi.ui.category.CategoryController import eu.kanade.tachiyomi.ui.category.CategoryController
import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchIO
open class BrowseSourceController(bundle: Bundle) : open class BrowseSourceController(bundle: Bundle) :
@ -41,6 +44,7 @@ open class BrowseSourceController(bundle: Bundle) :
@Composable @Composable
override fun ComposeContent() { override fun ComposeContent() {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val context = LocalContext.current
BrowseSourceScreen( BrowseSourceScreen(
presenter = presenter, presenter = presenter,
@ -58,6 +62,11 @@ open class BrowseSourceController(bundle: Bundle) :
} }
} }
}, },
onWebViewClick = f@{
val source = presenter.source as? HttpSource ?: return@f
val intent = WebViewActivity.newIntent(context, source.baseUrl, source.id, source.name)
context.startActivity(intent)
},
) )
val onDismissRequest = { presenter.dialog = null } val onDismissRequest = { presenter.dialog = null }

View File

@ -3,17 +3,20 @@ package eu.kanade.tachiyomi.ui.browse.source.latest
import android.os.Bundle import android.os.Bundle
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.LocalContext
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import eu.kanade.domain.source.model.Source import eu.kanade.domain.source.model.Source
import eu.kanade.presentation.browse.BrowseLatestScreen import eu.kanade.presentation.browse.BrowseLatestScreen
import eu.kanade.presentation.browse.components.RemoveMangaDialog import eu.kanade.presentation.browse.components.RemoveMangaDialog
import eu.kanade.presentation.components.ChangeCategoryDialog import eu.kanade.presentation.components.ChangeCategoryDialog
import eu.kanade.presentation.components.DuplicateMangaDialog import eu.kanade.presentation.components.DuplicateMangaDialog
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.base.controller.pushController import eu.kanade.tachiyomi.ui.base.controller.pushController
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter
import eu.kanade.tachiyomi.ui.category.CategoryController import eu.kanade.tachiyomi.ui.category.CategoryController
import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchIO
/** /**
@ -32,6 +35,7 @@ class LatestUpdatesController(bundle: Bundle) : BrowseSourceController(bundle) {
@Composable @Composable
override fun ComposeContent() { override fun ComposeContent() {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val context = LocalContext.current
BrowseLatestScreen( BrowseLatestScreen(
presenter = presenter, presenter = presenter,
@ -47,6 +51,11 @@ class LatestUpdatesController(bundle: Bundle) : BrowseSourceController(bundle) {
} }
} }
}, },
onWebViewClick = f@{
val source = presenter.source as? HttpSource ?: return@f
val intent = WebViewActivity.newIntent(context, source.baseUrl, source.id, source.name)
context.startActivity(intent)
},
) )
val onDismissRequest = { presenter.dialog = null } val onDismissRequest = { presenter.dialog = null }