Skip to content

Commit

Permalink
Migrate to Compose 1.7 (#845)
Browse files Browse the repository at this point in the history
* refactor: migrate to compose 1.7 (wip)

* feat(ui): migrate to swipe
  • Loading branch information
JunkFood02 authored Sep 29, 2024
1 parent d219307 commit 5eb0edc
Show file tree
Hide file tree
Showing 21 changed files with 320 additions and 750 deletions.
4 changes: 4 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 Expand Up @@ -151,6 +154,7 @@ dependencies {
implementation(libs.readability4j)
implementation(libs.rome)
implementation(libs.telephoto)
implementation(libs.swipe)
implementation(libs.okhttp)
implementation(libs.okhttp.coroutines)
implementation(libs.retrofit)
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
59 changes: 40 additions & 19 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 @@ -162,6 +166,7 @@ fun FeedsPage(
is GroupFeedsView.Group -> {
groupsVisible[groupWithFeed.group.id] = true
}

else -> {}
}
}
Expand All @@ -174,12 +179,17 @@ fun FeedsPage(
is GroupFeedsView.Group -> {
groupsVisible[groupWithFeed.group.id] = false
}

else -> {}
}
}
hasGroupVisible = false
}

val groupDrawerState =
rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)
val feedDrawerState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)

LaunchedEffect(Unit) {
feedsViewModel.fetchAccount()
}
Expand Down Expand Up @@ -231,7 +241,7 @@ fun FeedsPage(
}
},
content = {
LazyColumn (
LazyColumn(
state = listState
) {
item {
Expand Down Expand Up @@ -303,7 +313,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 All @@ -321,10 +331,16 @@ fun FeedsPage(
groupWithFeed.group.id,
groupListExpand::value
).not()
hasGroupVisible = if (groupsVisible[groupWithFeed.group.id] == true) {
true
} else {
groupsVisible.any { it.value }
hasGroupVisible =
if (groupsVisible[groupWithFeed.group.id] == true) {
true
} else {
groupsVisible.any { it.value }
}
},
onLongClick = {
scope.launch {
groupDrawerState.show()
}
}
) {
Expand All @@ -351,17 +367,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 @@ -390,8 +410,9 @@ fun FeedsPage(
)

SubscribeDialog(subscribeViewModel = subscribeViewModel)
GroupOptionDrawer()
FeedOptionDrawer()

GroupOptionDrawer(drawerState = groupDrawerState)
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
Loading

0 comments on commit 5eb0edc

Please sign in to comment.