Skip to content

Commit

Permalink
Show bottom sheet to add new feeds on Android - #91
Browse files Browse the repository at this point in the history
  • Loading branch information
prof18 committed Jan 7, 2024
1 parent 5a84f13 commit 13a59e5
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ class MainActivity : ComponentActivity() {
onSettingsButtonClicked = {
navController.navigate(Screen.Settings.name)
},
onAddFeedClick = {
navController.navigate(Screen.AddFeed.name)
},
onImportExportClick = {
navController.navigate(Screen.ImportExport.name)
},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.material.pullrefresh.PullRefreshState
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalDrawerSheet
import androidx.compose.material3.ModalNavigationDrawer
Expand Down Expand Up @@ -57,6 +58,7 @@ import com.prof18.feedflow.domain.model.InProgressFeedUpdateStatus
import com.prof18.feedflow.domain.model.NoFeedSourcesStatus
import com.prof18.feedflow.home.components.FeedItemImage
import com.prof18.feedflow.home.components.HomeAppBar
import com.prof18.feedflow.home.components.NoFeedsBottomSheet
import com.prof18.feedflow.presentation.HomeViewModel
import com.prof18.feedflow.presentation.preview.feedItemsForPreview
import com.prof18.feedflow.ui.components.FeedSourceLogoImage
Expand All @@ -79,6 +81,8 @@ import org.koin.compose.koinInject
internal fun HomeScreen(
windowSizeClass: WindowSizeClass,
onSettingsButtonClicked: () -> Unit,
onAddFeedClick: () -> Unit,
onImportExportClick: () -> Unit = {},
) {
val homeViewModel = koinViewModel<HomeViewModel>()

Expand Down Expand Up @@ -137,6 +141,8 @@ internal fun HomeScreen(
}
}
},
onAddFeedClick = onAddFeedClick,
onImportExportClick = onImportExportClick,
)
} else {
ModalNavigationDrawer(
Expand Down Expand Up @@ -181,6 +187,8 @@ internal fun HomeScreen(
}
}
},
onAddFeedClick = onAddFeedClick,
onImportExportClick = onImportExportClick,
)
}
}
Expand Down Expand Up @@ -230,6 +238,8 @@ internal fun HomeScreen(
onDrawerMenuClick = {
isDrawerMenuFullVisible = !isDrawerMenuFullVisible
},
onAddFeedClick = onAddFeedClick,
onImportExportClick = onImportExportClick,
)
}
}
Expand Down Expand Up @@ -272,6 +282,8 @@ internal fun HomeScreen(
feedState = feedState,
pullRefreshState = pullRefreshState,
currentFeedFilter = currentFeedFilter,
onAddFeedClick = onAddFeedClick,
onImportExportClick = onImportExportClick,
)
}
}
Expand All @@ -286,6 +298,7 @@ private fun FeedSourceImage(imageUrl: String) {
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Suppress("LongMethod", "LongParameterList")
@Composable
private fun HomeScaffold(
Expand All @@ -302,6 +315,8 @@ private fun HomeScaffold(
showDrawerMenu: Boolean = false,
isDrawerMenuOpen: Boolean = false,
onSettingsButtonClicked: () -> Unit,
onAddFeedClick: () -> Unit,
onImportExportClick: () -> Unit = {},
onDrawerMenuClick: () -> Unit = {},
) {
val context = LocalContext.current
Expand Down Expand Up @@ -350,6 +365,18 @@ private fun HomeScaffold(
contentWindowInsets = WindowInsets(0, 0, 0, 0),
snackbarHost = { SnackbarHost(snackbarHostState) },
) { padding ->
var showBottomSheet by remember { mutableStateOf(false) }

if (showBottomSheet) {
NoFeedsBottomSheet(
onDismissRequest = {
showBottomSheet = false
},
onAddFeedClick = onAddFeedClick,
onImportExportClick = onImportExportClick,
)
}

HomeScreenContent(
paddingValues = padding,
loadingState = loadingState,
Expand All @@ -371,7 +398,7 @@ private fun HomeScaffold(
homeViewModel.markAsRead(feedInfo.id)
},
onAddFeedClick = {
onSettingsButtonClicked()
showBottomSheet = true
},
requestMoreItems = {
homeViewModel.requestNewFeedsPage()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.prof18.feedflow.home.components

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SheetState
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.prof18.feedflow.MR
import com.prof18.feedflow.ui.style.Spacing
import dev.icerock.moko.resources.compose.stringResource
import md_theme_dark_background
import md_theme_light_background

@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun NoFeedsBottomSheet(
sheetState: SheetState = rememberModalBottomSheetState(),
onDismissRequest: () -> Unit,
onAddFeedClick: () -> Unit,
onImportExportClick: () -> Unit
) {
ModalBottomSheet(
containerColor = if (isSystemInDarkTheme()) {
md_theme_dark_background
} else {
md_theme_light_background
},
onDismissRequest = onDismissRequest,
sheetState = sheetState
) {
Column {
Text(
modifier = Modifier
.padding(horizontal = Spacing.regular),
text = stringResource(MR.strings.no_feed_modal_title),
style = MaterialTheme.typography.titleMedium,
)

Text(
modifier = Modifier
.padding(vertical = Spacing.regular)
.padding(horizontal = Spacing.regular),
text = stringResource(MR.strings.no_feed_modal_message),
style = MaterialTheme.typography.bodyMedium,
)

Button(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = Spacing.regular),
onClick = {
onDismissRequest()
onAddFeedClick()
},
) {
Text(
stringResource(MR.strings.add_feed),
)
}

Button(
modifier = Modifier
.fillMaxWidth()
.padding(top = Spacing.regular)
.padding(bottom = Spacing.medium)
.padding(horizontal = Spacing.regular),
onClick = {
onDismissRequest()
onImportExportClick()
},
) {
Text(
stringResource(MR.strings.import_export_opml),
)
}
}
}
}

0 comments on commit 13a59e5

Please sign in to comment.