mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 00:37:03 +05:30
refactor(android): remove TwoPaneLayoutPostActions
This commit is contained in:
parent
37d0614830
commit
4d260933c0
5 changed files with 13 additions and 62 deletions
|
@ -15,7 +15,7 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||||
import com.deliveryhero.whetstone.activity.ContributesActivityInjector
|
import com.deliveryhero.whetstone.activity.ContributesActivityInjector
|
||||||
import dev.msfjarvis.claw.android.ui.screens.LobstersPostsScreen
|
import dev.msfjarvis.claw.android.ui.screens.LobstersPostsScreen
|
||||||
import dev.msfjarvis.claw.android.ui.screens.TwoPaneLayout
|
import dev.msfjarvis.claw.android.ui.screens.TabletScreen
|
||||||
|
|
||||||
@ContributesActivityInjector
|
@ContributesActivityInjector
|
||||||
class MainActivity : BaseActivity() {
|
class MainActivity : BaseActivity() {
|
||||||
|
@ -36,7 +36,7 @@ class MainActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
TwoPaneLayout(
|
TabletScreen(
|
||||||
urlLauncher = urlLauncher,
|
urlLauncher = urlLauncher,
|
||||||
htmlConverter = htmlConverter,
|
htmlConverter = htmlConverter,
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
|
|
@ -8,9 +8,7 @@ package dev.msfjarvis.claw.android.ui
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.navigation.NavController
|
|
||||||
import com.slack.eithernet.ApiResult
|
import com.slack.eithernet.ApiResult
|
||||||
import dev.msfjarvis.claw.android.ui.navigation.Comments
|
|
||||||
import dev.msfjarvis.claw.android.viewmodel.ClawViewModel
|
import dev.msfjarvis.claw.android.viewmodel.ClawViewModel
|
||||||
import dev.msfjarvis.claw.common.posts.PostActions
|
import dev.msfjarvis.claw.common.posts.PostActions
|
||||||
import dev.msfjarvis.claw.common.urllauncher.UrlLauncher
|
import dev.msfjarvis.claw.common.urllauncher.UrlLauncher
|
||||||
|
@ -22,8 +20,8 @@ import java.net.HttpURLConnection
|
||||||
fun PostActions(
|
fun PostActions(
|
||||||
context: Context,
|
context: Context,
|
||||||
urlLauncher: UrlLauncher,
|
urlLauncher: UrlLauncher,
|
||||||
navController: NavController,
|
|
||||||
viewModel: ClawViewModel,
|
viewModel: ClawViewModel,
|
||||||
|
viewComments: (String) -> Unit,
|
||||||
): PostActions {
|
): PostActions {
|
||||||
return object : PostActions {
|
return object : PostActions {
|
||||||
override fun viewPost(postId: String, postUrl: String, commentsUrl: String) {
|
override fun viewPost(postId: String, postUrl: String, commentsUrl: String) {
|
||||||
|
@ -33,7 +31,7 @@ fun PostActions(
|
||||||
|
|
||||||
override fun viewComments(postId: String) {
|
override fun viewComments(postId: String) {
|
||||||
viewModel.markPostAsRead(postId)
|
viewModel.markPostAsRead(postId)
|
||||||
navController.navigate(Comments(postId))
|
viewComments(postId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun viewCommentsPage(post: UIPost) {
|
override fun viewCommentsPage(post: UIPost) {
|
||||||
|
@ -70,57 +68,6 @@ fun PostActions(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TwoPaneLayoutPostActions(
|
|
||||||
context: Context,
|
|
||||||
urlLauncher: UrlLauncher,
|
|
||||||
viewModel: ClawViewModel,
|
|
||||||
setSelectedPost: (String) -> Unit,
|
|
||||||
): PostActions {
|
|
||||||
return object : PostActions {
|
|
||||||
override fun viewPost(postId: String, postUrl: String, commentsUrl: String) {
|
|
||||||
viewModel.markPostAsRead(postId)
|
|
||||||
urlLauncher.openUri(postUrl.ifEmpty { commentsUrl })
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun viewComments(postId: String) {
|
|
||||||
viewModel.markPostAsRead(postId)
|
|
||||||
setSelectedPost(postId)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun viewCommentsPage(post: UIPost) {
|
|
||||||
urlLauncher.openUri(post.commentsUrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toggleSave(post: UIPost) {
|
|
||||||
viewModel.toggleSave(post)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun share(post: UIPost) {
|
|
||||||
val sendIntent =
|
|
||||||
Intent().apply {
|
|
||||||
action = Intent.ACTION_SEND
|
|
||||||
putExtra(Intent.EXTRA_TEXT, post.url.ifEmpty { post.commentsUrl })
|
|
||||||
putExtra(Intent.EXTRA_TITLE, post.title)
|
|
||||||
type = "text/plain"
|
|
||||||
}
|
|
||||||
val shareIntent = Intent.createChooser(sendIntent, null)
|
|
||||||
context.startActivity(shareIntent)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isPostRead(post: UIPost): Boolean = viewModel.isPostRead(post)
|
|
||||||
|
|
||||||
override fun isPostSaved(post: UIPost): Boolean = viewModel.isPostSaved(post)
|
|
||||||
|
|
||||||
override suspend fun getComments(postId: String): UIPost {
|
|
||||||
return viewModel.getPostComments(postId)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getLinkMetadata(url: String): LinkMetadata {
|
|
||||||
return viewModel.getLinkMetadata(url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an [ApiResult.Failure.HttpFailure] to a scoped down error with a more useful user-facing
|
* Convert an [ApiResult.Failure.HttpFailure] to a scoped down error with a more useful user-facing
|
||||||
* message.
|
* message.
|
||||||
|
|
|
@ -109,7 +109,9 @@ fun LobstersPostsScreen(
|
||||||
val currentDestination = navBackStackEntry?.destination
|
val currentDestination = navBackStackEntry?.destination
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
val snackbarHostState = remember { SnackbarHostState() }
|
val snackbarHostState = remember { SnackbarHostState() }
|
||||||
val postActions = remember { PostActions(context, urlLauncher, navController, viewModel) }
|
val postActions = remember {
|
||||||
|
PostActions(context, urlLauncher, viewModel) { navController.navigate(Comments(it)) }
|
||||||
|
}
|
||||||
val hazeState = remember { HazeState() }
|
val hazeState = remember { HazeState() }
|
||||||
|
|
||||||
val hottestPosts = viewModel.hottestPosts.collectAsLazyPagingItems()
|
val hottestPosts = viewModel.hottestPosts.collectAsLazyPagingItems()
|
||||||
|
|
|
@ -39,7 +39,9 @@ fun SearchScreen(
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
val postActions = remember { PostActions(context, urlLauncher, navController, viewModel) }
|
val postActions = remember {
|
||||||
|
PostActions(context, urlLauncher, viewModel) { navController.navigate(Comments(it)) }
|
||||||
|
}
|
||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
val searchResults = viewModel.searchResults.collectAsLazyPagingItems()
|
val searchResults = viewModel.searchResults.collectAsLazyPagingItems()
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ import androidx.navigation.compose.rememberNavController
|
||||||
import androidx.paging.compose.collectAsLazyPagingItems
|
import androidx.paging.compose.collectAsLazyPagingItems
|
||||||
import com.deliveryhero.whetstone.compose.injectedViewModel
|
import com.deliveryhero.whetstone.compose.injectedViewModel
|
||||||
import dev.msfjarvis.claw.android.R
|
import dev.msfjarvis.claw.android.R
|
||||||
import dev.msfjarvis.claw.android.ui.TwoPaneLayoutPostActions
|
import dev.msfjarvis.claw.android.ui.PostActions
|
||||||
import dev.msfjarvis.claw.android.ui.lists.NetworkPosts
|
import dev.msfjarvis.claw.android.ui.lists.NetworkPosts
|
||||||
import dev.msfjarvis.claw.android.ui.navigation.Comments
|
import dev.msfjarvis.claw.android.ui.navigation.Comments
|
||||||
import dev.msfjarvis.claw.android.ui.navigation.User
|
import dev.msfjarvis.claw.android.ui.navigation.User
|
||||||
|
@ -60,7 +60,7 @@ private fun ThreePaneScaffoldNavigator<*>.isDetailExpanded() =
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun TwoPaneLayout(
|
fun TabletScreen(
|
||||||
urlLauncher: UrlLauncher,
|
urlLauncher: UrlLauncher,
|
||||||
htmlConverter: HTMLConverter,
|
htmlConverter: HTMLConverter,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
@ -80,7 +80,7 @@ fun TwoPaneLayout(
|
||||||
}
|
}
|
||||||
|
|
||||||
val postActions = remember {
|
val postActions = remember {
|
||||||
TwoPaneLayoutPostActions(context, urlLauncher, viewModel) {
|
PostActions(context, urlLauncher, viewModel) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
navigator.navigateTo(pane = ListDetailPaneScaffoldRole.Detail, contentKey = Comments(it))
|
navigator.navigateTo(pane = ListDetailPaneScaffoldRole.Detail, contentKey = Comments(it))
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue