Skip to content

Commit

Permalink
refactor: migrate to compose 1.7 (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkFood02 committed Sep 26, 2024
1 parent d219307 commit 8140df4
Show file tree
Hide file tree
Showing 19 changed files with 275 additions and 325 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ android {
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
signingConfig = signingConfigs.getByName("release")
}
all {
signingConfig = signingConfigs.getByName("release")
}
}
applicationVariants.all {
outputs.all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import kotlinx.coroutines.launch
import me.ash.reader.domain.model.feed.Feed
import me.ash.reader.ui.component.FeedIcon
import me.ash.reader.ui.component.base.RYExtensibleVisibility
Expand All @@ -40,6 +41,7 @@ fun FeedItem(
isExpanded: () -> Boolean,
feedOptionViewModel: FeedOptionViewModel = hiltViewModel(),
onClick: () -> Unit = {},
onLongClick: () -> Unit = {}
) {
val view = LocalView.current
val scope = rememberCoroutineScope()
Expand All @@ -56,8 +58,11 @@ fun FeedItem(
onClick()
},
onLongClick = {
onLongClick()
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP)
feedOptionViewModel.showDrawer(scope, feed.id)
scope.launch {
feedOptionViewModel.fetchFeed(feedId = feed.id)
}
}
)
.padding(horizontal = 14.dp)
Expand Down
38 changes: 24 additions & 14 deletions app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.KeyboardArrowRight
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.rounded.Add
import androidx.compose.material.icons.rounded.Refresh
import androidx.compose.material.icons.rounded.UnfoldLess
import androidx.compose.material.icons.rounded.UnfoldMore
import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -53,6 +55,7 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import androidx.work.WorkInfo
import kotlinx.coroutines.launch
import me.ash.reader.R
import me.ash.reader.infrastructure.preference.LocalFeedsFilterBarFilled
import me.ash.reader.infrastructure.preference.LocalFeedsFilterBarPadding
Expand Down Expand Up @@ -123,7 +126,8 @@ fun FeedsPage(
val newVersion = LocalNewVersionNumber.current
val skipVersion = LocalSkipVersionNumber.current
val currentVersion = remember { context.getCurrentVersion() }
val listState = if (groupWithFeedList.isNotEmpty()) feedsUiState.listState else rememberLazyListState()
val listState =
if (groupWithFeedList.isNotEmpty()) feedsUiState.listState else rememberLazyListState()

val owner = LocalLifecycleOwner.current
var isSyncing by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -179,6 +183,8 @@ fun FeedsPage(
}
hasGroupVisible = false
}
val groupDrawerState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)
val feedDrawerState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)

LaunchedEffect(Unit) {
feedsViewModel.fetchAccount()
Expand Down Expand Up @@ -231,7 +237,7 @@ fun FeedsPage(
}
},
content = {
LazyColumn (
LazyColumn(
state = listState
) {
item {
Expand Down Expand Up @@ -303,7 +309,7 @@ fun FeedsPage(
is GroupFeedsView.Group -> {
Spacer(modifier = Modifier.height(16.dp))

if (groupWithFeed.group.id != defaultGroupId || groupWithFeed.group.feeds > 0) {
if (groupWithFeed.group.id != defaultGroupId || groupWithFeed.group.feeds > 0) {
GroupItem(
isExpanded = {
groupsVisible.getOrPut(
Expand Down Expand Up @@ -351,17 +357,21 @@ fun FeedsPage(
groupWithFeed.feed.groupId,
groupListExpand::value
)
},
) {
filterChange(
navController = navController,
homeViewModel = homeViewModel,
filterState = filterUiState.copy(
group = null,
feed = groupWithFeed.feed,
}, onClick = {
filterChange(
navController = navController,
homeViewModel = homeViewModel,
filterState = filterUiState.copy(
group = null,
feed = groupWithFeed.feed,
)
)
)
}
}, onLongClick = {
scope.launch {
feedDrawerState.show()
}
}
)
}
}
}
Expand Down Expand Up @@ -391,7 +401,7 @@ fun FeedsPage(

SubscribeDialog(subscribeViewModel = subscribeViewModel)
GroupOptionDrawer()
FeedOptionDrawer()
FeedOptionDrawer(drawerState = feedDrawerState)

AccountsTab(
visible = accountTabVisible,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fun GroupItem(
isExpanded: () -> Boolean,
groupOptionViewModel: GroupOptionViewModel = hiltViewModel(),
onExpanded: () -> Unit = {},
onLongClick: () -> Unit = {},
groupOnClick: () -> Unit = {},
) {
val view = LocalView.current
Expand All @@ -57,7 +58,8 @@ fun GroupItem(
},
onLongClick = {
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP)
groupOptionViewModel.showDrawer(scope, group.id)
groupOptionViewModel.fetchGroup(groupId = group.id)
onLongClick()
}
)
.padding(top = 22.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import me.ash.reader.ui.ext.showToast
fun ClearFeedDialog(
feedName: String,
feedOptionViewModel: FeedOptionViewModel = hiltViewModel(),
onConfirm: () -> Unit = {}
) {
val context = LocalContext.current
val feedOptionUiState = feedOptionViewModel.feedOptionUiState.collectAsStateValue()
Expand Down Expand Up @@ -47,7 +48,7 @@ fun ClearFeedDialog(
onClick = {
feedOptionViewModel.clearFeed {
feedOptionViewModel.hideClearDialog()
feedOptionViewModel.hideDrawer(scope)
onConfirm()
context.showToast(toastString)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import me.ash.reader.ui.ext.showToast
fun DeleteFeedDialog(
feedName: String,
feedOptionViewModel: FeedOptionViewModel = hiltViewModel(),
onConfirm: () -> Unit,
) {
val context = LocalContext.current
val feedOptionUiState = feedOptionViewModel.feedOptionUiState.collectAsStateValue()
Expand Down Expand Up @@ -47,7 +48,7 @@ fun DeleteFeedDialog(
onClick = {
feedOptionViewModel.delete {
feedOptionViewModel.hideDeleteDialog()
feedOptionViewModel.hideDrawer(scope)
onConfirm()
context.showToast(toastString)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalBottomSheetState
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.CreateNewFolder
import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -39,9 +42,9 @@ import me.ash.reader.ui.ext.roundClick
import me.ash.reader.ui.ext.showToast
import me.ash.reader.ui.page.home.feeds.FeedOptionView

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun FeedOptionDrawer(
drawerState: ModalBottomSheetState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden),
feedOptionViewModel: FeedOptionViewModel = hiltViewModel(),
content: @Composable () -> Unit = {},
) {
Expand All @@ -54,14 +57,15 @@ fun FeedOptionDrawer(
val feed = feedOptionUiState.feed
val toastString = stringResource(R.string.rename_toast, feedOptionUiState.newName)

BackHandler(feedOptionUiState.drawerState.isVisible) {

BackHandler(drawerState.isVisible) {
scope.launch {
feedOptionUiState.drawerState.hide()
drawerState.hide()
}
}

BottomDrawer(
drawerState = feedOptionUiState.drawerState,
drawerState = drawerState,
sheetContent = {
Column(modifier = Modifier.navigationBarsPadding()) {
Column(
Expand Down Expand Up @@ -132,9 +136,13 @@ fun FeedOptionDrawer(
content()
}

DeleteFeedDialog(feedName = feed?.name ?: "")
DeleteFeedDialog(
feedName = feed?.name ?: "",
onConfirm = { scope.launch { drawerState.hide() } })

ClearFeedDialog(feedName = feed?.name ?: "")
ClearFeedDialog(
feedName = feed?.name ?: "",
onConfirm = { scope.launch { drawerState.hide() } })

TextFieldDialog(
visible = feedOptionUiState.newGroupDialogVisible,
Expand Down Expand Up @@ -164,7 +172,7 @@ fun FeedOptionDrawer(
},
onConfirm = {
feedOptionViewModel.renameFeed()
feedOptionViewModel.hideDrawer(scope)
scope.launch { drawerState.hide() }
context.showToast(toastString)
}
)
Expand All @@ -180,7 +188,7 @@ fun FeedOptionDrawer(
},
onConfirm = {
feedOptionViewModel.changeFeedUrl()
feedOptionViewModel.hideDrawer(scope)
scope.launch { drawerState.hide() }
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package me.ash.reader.ui.page.home.feeds.drawer.feed
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalBottomSheetState
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.ui.unit.Density
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
Expand Down Expand Up @@ -49,7 +50,7 @@ class FeedOptionViewModel @Inject constructor(
}
}

private suspend fun fetchFeed(feedId: String) {
suspend fun fetchFeed(feedId: String) {
val feed = rssService.get().findFeedById(feedId)
_feedOptionUiState.update {
it.copy(
Expand All @@ -59,17 +60,6 @@ class FeedOptionViewModel @Inject constructor(
}
}

fun showDrawer(scope: CoroutineScope, feedId: String) {
scope.launch {
fetchFeed(feedId)
_feedOptionUiState.value.drawerState.show()
}
}

fun hideDrawer(scope: CoroutineScope) {
scope.launch { _feedOptionUiState.value.drawerState.hide() }
}

fun showNewGroupDialog() {
_feedOptionUiState.update {
it.copy(
Expand All @@ -95,9 +85,12 @@ class FeedOptionViewModel @Inject constructor(
fun addNewGroup() {
if (_feedOptionUiState.value.newGroupContent.isNotBlank()) {
applicationScope.launch {
selectedGroup(rssService.get().addGroup(
destFeed = _feedOptionUiState.value.feed,
newGroupName = _feedOptionUiState.value.newGroupContent))
selectedGroup(
rssService.get().addGroup(
destFeed = _feedOptionUiState.value.feed,
newGroupName = _feedOptionUiState.value.newGroupContent
)
)
hideNewGroupDialog()
}
}
Expand Down Expand Up @@ -244,9 +237,7 @@ class FeedOptionViewModel @Inject constructor(
}
}

@OptIn(ExperimentalMaterialApi::class)
data class FeedOptionUiState(
var drawerState: ModalBottomSheetState = ModalBottomSheetState(ModalBottomSheetValue.Hidden),
val feed: Feed? = null,
val selectedGroupId: String = "",
val newGroupContent: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import me.ash.reader.ui.ext.showToast
fun AllAllowNotificationDialog(
groupName: String,
groupOptionViewModel: GroupOptionViewModel = hiltViewModel(),
onConfirm: () -> Unit,
) {
val context = LocalContext.current
val groupOptionUiState = groupOptionViewModel.groupOptionUiState.collectAsStateValue()
Expand Down Expand Up @@ -48,7 +49,7 @@ fun AllAllowNotificationDialog(
onClick = {
groupOptionViewModel.allAllowNotification(true) {
groupOptionViewModel.hideAllAllowNotificationDialog()
groupOptionViewModel.hideDrawer(scope)
onConfirm()
context.showToast(allowToastString)
}
}
Expand All @@ -63,7 +64,7 @@ fun AllAllowNotificationDialog(
onClick = {
groupOptionViewModel.allAllowNotification(false) {
groupOptionViewModel.hideAllAllowNotificationDialog()
groupOptionViewModel.hideDrawer(scope)
onConfirm()
context.showToast(denyToastString)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package me.ash.reader.ui.page.home.feeds.drawer.group

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.DriveFileMove
import androidx.compose.material.icons.outlined.DriveFileMove
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
Expand All @@ -20,6 +19,7 @@ import me.ash.reader.ui.ext.showToast
fun AllMoveToGroupDialog(
groupName: String,
groupOptionViewModel: GroupOptionViewModel = hiltViewModel(),
onConfirm: () -> Unit,
) {
val context = LocalContext.current
val groupOptionUiState = groupOptionViewModel.groupOptionUiState.collectAsStateValue()
Expand Down Expand Up @@ -57,7 +57,7 @@ fun AllMoveToGroupDialog(
onClick = {
groupOptionViewModel.allMoveToGroup {
groupOptionViewModel.hideAllMoveToGroupDialog()
groupOptionViewModel.hideDrawer(scope)
onConfirm()
context.showToast(toastString)
}
}
Expand Down
Loading

0 comments on commit 8140df4

Please sign in to comment.