Skip to content

Commit

Permalink
Update Compose, AGP and other dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinokuni committed Sep 22, 2024
1 parent 7471948 commit 60f15a5
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 293 deletions.
12 changes: 0 additions & 12 deletions app/src/main/java/com/readrops/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBarDefaults
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.graphics.toArgb
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager
Expand Down Expand Up @@ -78,16 +74,8 @@ class MainActivity : ComponentActivity(), KoinComponent {
ReadropsTheme(
useDarkTheme = useDarkTheme
) {
val navigationBarElevation = NavigationBarDefaults.Elevation

enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT),
navigationBarStyle = SystemBarStyle.light(
MaterialTheme.colorScheme.surfaceColorAtElevation(navigationBarElevation)
.toArgb(),
MaterialTheme.colorScheme.surfaceColorAtElevation(navigationBarElevation)
.toArgb()
)
)

Navigator(
Expand Down
267 changes: 121 additions & 146 deletions app/src/main/java/com/readrops/app/timelime/TimelineTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ import androidx.compose.material3.SnackbarResult
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.pulltorefresh.PullToRefreshContainer
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.material3.rememberDrawerState
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
Expand Down Expand Up @@ -96,7 +94,6 @@ object TimelineTab : Tab {
val items = state.itemState.collectAsLazyPagingItems()

val lazyListState = rememberLazyListState()
val pullToRefreshState = rememberPullToRefreshState()
val snackbarHostState = remember { SnackbarHostState() }
val topAppBarState = rememberTopAppBarState()
val topAppBarScrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(topAppBarState)
Expand All @@ -113,22 +110,6 @@ object TimelineTab : Tab {
}
}

LaunchedEffect(state.isRefreshing) {
if (state.isRefreshing) {
pullToRefreshState.startRefresh()
} else {
pullToRefreshState.endRefresh()
}
}

// Material3 pull to refresh doesn't have a onRefresh callback,
// so we need to listen to the internal state change to trigger the refresh
LaunchedEffect(pullToRefreshState.isRefreshing) {
if (pullToRefreshState.isRefreshing && !state.isRefreshing) {
screenModel.refreshTimeline(context)
}
}

LaunchedEffect(state.scrollToTop) {
if (state.scrollToTop) {
lazyListState.scrollToItem(0)
Expand Down Expand Up @@ -190,60 +171,6 @@ object TimelineTab : Tab {
}
}

when (val dialog = state.dialog) {
is DialogState.ConfirmDialog -> {
TwoChoicesDialog(
title = stringResource(R.string.mark_all_articles_read),
text = stringResource(R.string.mark_all_articles_read_question),
icon = painterResource(id = R.drawable.ic_rss_feed_grey),
confirmText = stringResource(id = R.string.validate),
dismissText = stringResource(id = R.string.cancel),
onDismiss = { screenModel.closeDialog() },
onConfirm = {
screenModel.closeDialog()
screenModel.setAllItemsRead()
}
)
}

is DialogState.FilterSheet -> {
FilterBottomSheet(
filters = state.filters,
onSetShowReadItems = {
screenModel.setShowReadItemsState(!state.filters.showReadItems)
},
onSetOrderField = {
screenModel.setOrderFieldState(
if (state.filters.orderField == OrderField.ID) {
OrderField.DATE
} else {
OrderField.ID
}
)
},
onSetOrderType = {
screenModel.setOrderTypeState(
if (state.filters.orderType == OrderType.DESC) {
OrderType.ASC
} else {
OrderType.DESC
}
)
},
onDismiss = { screenModel.closeDialog() }
)
}

is DialogState.ErrorList -> {
ErrorListDialog(
errorResult = dialog.errorResult,
onDismiss = { screenModel.closeDialog(dialog) }
)
}

null -> {}
}

ModalNavigationDrawer(
drawerState = drawerState,
drawerContent = {
Expand Down Expand Up @@ -346,7 +273,6 @@ object TimelineTab : Tab {
modifier = Modifier
.padding(paddingValues)
.fillMaxSize()
.nestedScroll(pullToRefreshState.nestedScrollConnection)
.nestedScroll(topAppBarScrollBehavior.nestedScrollConnection)
) {
when {
Expand All @@ -368,86 +294,135 @@ object TimelineTab : Tab {
}

else -> {
if (items.itemCount > 0) {
MarkItemsRead(
lazyListState = lazyListState,
items = items,
markReadOnScroll = state.markReadOnScroll,
screenModel = screenModel
)

LazyColumn(
state = lazyListState,
contentPadding = PaddingValues(
vertical = if (state.itemSize == TimelineItemSize.COMPACT) {
0.dp
} else {
MaterialTheme.spacing.shortSpacing
}
),
verticalArrangement = Arrangement.spacedBy(
if (state.itemSize == TimelineItemSize.COMPACT) {
0.dp
} else
MaterialTheme.spacing.shortSpacing
PullToRefreshBox(
isRefreshing = state.isRefreshing,
onRefresh = { screenModel.refreshTimeline(context) },
) {
if (items.itemCount > 0) {
MarkItemsRead(
lazyListState = lazyListState,
items = items,
markReadOnScroll = state.markReadOnScroll,
screenModel = screenModel
)
) {
items(
count = items.itemCount,
key = items.itemKey { it.item.id },
) { itemCount ->
val itemWithFeed = items[itemCount]

if (itemWithFeed != null) {
TimelineItem(
itemWithFeed = itemWithFeed,
onClick = {
screenModel.setItemRead(itemWithFeed.item)
navigator.push(ItemScreen(itemWithFeed.item.id))
},
onFavorite = {
screenModel.updateStarState(itemWithFeed.item)
},
onShare = {
screenModel.shareItem(
itemWithFeed.item,
context
)
},
onSetReadState = {
screenModel.updateItemReadState(itemWithFeed.item)
},
size = state.itemSize
)

LazyColumn(
state = lazyListState,
contentPadding = PaddingValues(
vertical = if (state.itemSize == TimelineItemSize.COMPACT) {
0.dp
} else {
MaterialTheme.spacing.shortSpacing
}
),
verticalArrangement = Arrangement.spacedBy(
if (state.itemSize == TimelineItemSize.COMPACT) {
0.dp
} else
MaterialTheme.spacing.shortSpacing
)
) {
items(
count = items.itemCount,
key = items.itemKey { it.item.id },
) { itemCount ->
val itemWithFeed = items[itemCount]

if (itemWithFeed != null) {
TimelineItem(
itemWithFeed = itemWithFeed,
onClick = {
screenModel.setItemRead(itemWithFeed.item)
navigator.push(ItemScreen(itemWithFeed.item.id))
},
onFavorite = {
screenModel.updateStarState(itemWithFeed.item)
},
onShare = {
screenModel.shareItem(
itemWithFeed.item,
context
)
},
onSetReadState = {
screenModel.updateItemReadState(itemWithFeed.item)
},
size = state.itemSize
)
}
}
}
} else {
// Empty lazyColumn to let the pull to refresh be usable
// when no items are displayed
LazyColumn(
modifier = Modifier.fillMaxSize()
) {}

Placeholder(
text = stringResource(R.string.no_article),
painter = painterResource(R.drawable.ic_timeline),
)
}

PullToRefreshContainer(
state = pullToRefreshState,
modifier = Modifier.align(Alignment.TopCenter)
)
} else {
// Empty lazyColumn to let the pull to refresh be usable
// when the no item placeholder is displayed
LazyColumn(
modifier = Modifier.fillMaxSize()
) {}

PullToRefreshContainer(
state = pullToRefreshState,
modifier = Modifier.align(Alignment.TopCenter)
)

Placeholder(
text = stringResource(R.string.no_article),
painter = painterResource(R.drawable.ic_timeline),
)
}
}
}
}
}

when (val dialog = state.dialog) {
is DialogState.ConfirmDialog -> {
TwoChoicesDialog(
title = stringResource(R.string.mark_all_articles_read),
text = stringResource(R.string.mark_all_articles_read_question),
icon = painterResource(id = R.drawable.ic_rss_feed_grey),
confirmText = stringResource(id = R.string.validate),
dismissText = stringResource(id = R.string.cancel),
onDismiss = { screenModel.closeDialog() },
onConfirm = {
screenModel.closeDialog()
screenModel.setAllItemsRead()
}
)
}

is DialogState.FilterSheet -> {
FilterBottomSheet(
filters = state.filters,
onSetShowReadItems = {
screenModel.setShowReadItemsState(!state.filters.showReadItems)
},
onSetOrderField = {
screenModel.setOrderFieldState(
if (state.filters.orderField == OrderField.ID) {
OrderField.DATE
} else {
OrderField.ID
}
)
},
onSetOrderType = {
screenModel.setOrderTypeState(
if (state.filters.orderType == OrderType.DESC) {
OrderType.ASC
} else {
OrderType.DESC
}
)
},
onDismiss = { screenModel.closeDialog() }
)
}

is DialogState.ErrorList -> {
ErrorListDialog(
errorResult = dialog.errorResult,
onDismiss = { screenModel.closeDialog(dialog) }
)
}

null -> {}
}
}
}

Expand Down
Loading

0 comments on commit 60f15a5

Please sign in to comment.