Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move back button #1454

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import io.ashdavies.http.ProvideHttpClient
import io.ashdavies.http.publicStorage
import io.ashdavies.io.resolveCacheDir
import io.ashdavies.material.dynamicColorScheme
import io.ashdavies.party.config.rememberCircuit
import io.ashdavies.party.circuit.rememberCircuit
import io.ashdavies.party.home.HomeScreen
import io.ashdavies.party.material.ProvideLocalWindowSizeClass
import io.ashdavies.playground.BuildConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.ashdavies.party.config
package io.ashdavies.party.circuit

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
Expand All @@ -17,7 +17,6 @@ import io.ashdavies.content.reportFullyDrawn
import io.ashdavies.http.DefaultHttpConfiguration
import io.ashdavies.http.LocalHttpClient
import io.ashdavies.identity.IdentityManager
import io.ashdavies.party.coroutines.rememberRetainedCoroutineScope
import io.ashdavies.party.events.paging.rememberEventPager
import io.ashdavies.party.gallery.File
import io.ashdavies.party.gallery.GalleryPresenter
Expand All @@ -37,7 +36,6 @@ import io.ashdavies.party.upcoming.UpcomingEventsScreen
import io.ashdavies.playground.PlaygroundDatabase
import io.ashdavies.sql.LocalTransacter
import io.ktor.client.HttpClient
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import io.ashdavies.party.events.Event as DatabaseEvent

Expand All @@ -46,7 +44,6 @@ public fun rememberCircuit(
platformContext: PlatformContext,
eventPager: Pager<String, DatabaseEvent> = rememberEventPager(),
playgroundDatabase: PlaygroundDatabase = LocalTransacter.current as PlaygroundDatabase,
coroutineScope: CoroutineScope = rememberRetainedCoroutineScope(),
): Circuit = remember(platformContext) {
val identityManager = IdentityManager(platformContext, playgroundDatabase.credentialQueries)
val imageManager = ImageManager(platformContext, playgroundDatabase.imageQueries)
Expand All @@ -57,15 +54,15 @@ public fun rememberCircuit(
Circuit.Builder()
.addCircuit<HomeScreen, HomeScreen.State>(
presenterFactory = { _, navigator, _ ->
presenterOf { HomePresenter(identityManager, coroutineScope, navigator) }
presenterOf { HomePresenter(identityManager, navigator) }
},
uiFactory = { state, modifier ->
HomeScreen(state, modifier, platformContext::reportFullyDrawn)
},
)
.addCircuit<UpcomingEventsScreen, UpcomingEventsScreen.State>(
presenterFactory = { _, _, _ ->
presenterOf { UpcomingEventsPresenter(eventPager, coroutineScope) }
presenterOf { UpcomingEventsPresenter(eventPager) }
},
uiFactory = { state, modifier ->
UpcomingEventsScreen(state, modifier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material.icons.outlined.MyLocation
import androidx.compose.material3.Card
Expand All @@ -27,6 +26,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImage
import io.ashdavies.party.material.BackButton
import io.ashdavies.party.material.LocalWindowSizeClass
import io.ashdavies.party.material.padding
import io.ashdavies.party.material.spacing
Expand Down Expand Up @@ -56,12 +56,7 @@ internal fun EventsDetailPane(
},
navigationIcon = {
if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) {
IconButton(onClick = onBackClick) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = null,
)
}
BackButton(onBackClick)
}
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import com.slack.circuit.foundation.onNavEvent
import com.slack.circuit.retained.rememberRetained
Expand All @@ -12,17 +13,16 @@ import com.slack.circuit.runtime.screen.Screen
import io.ashdavies.identity.IdentityManager
import io.ashdavies.identity.IdentityState
import io.ashdavies.party.upcoming.UpcomingEventsScreen
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

@Composable
internal fun HomePresenter(
identityManager: IdentityManager,
coroutineScope: CoroutineScope,
navigator: Navigator,
): HomeScreen.State {
val identityState by identityManager.state.collectAsState(IdentityState.Unauthenticated)
var screen by rememberRetained { mutableStateOf<Screen>(UpcomingEventsScreen) }
val coroutineScope = rememberCoroutineScope()

return HomeScreen.State(
identityState = identityState,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.ashdavies.party.material

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
internal fun BackButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
contentDescription: String? = null,
) {
IconButton(
onClick = onClick,
modifier = modifier,
) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = contentDescription,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import io.ashdavies.party.events.EventsTopBar
import io.ashdavies.party.events.daysUntilCfpEnd
import io.ashdavies.party.material.padding
import io.ashdavies.party.material.spacing
import io.ashdavies.party.material.values
import io.ashdavies.placeholder.PlaceholderHighlight
import io.ashdavies.placeholder.fade
import io.ashdavies.placeholder.placeholder
Expand Down Expand Up @@ -80,12 +81,15 @@ internal fun UpcomingEventsPane(
EventFailure(state.errorMessage)
}

LazyColumn(Modifier.fillMaxSize()) {
LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = MaterialTheme.spacing.large.values,
verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.large.vertical),
) {
itemsIndexed(state.itemList) { index, item ->
val itemModifier = Modifier
.animateItem() // TODO Slow animation on addition
.fillMaxWidth()
.padding(MaterialTheme.spacing.large)
.clip(MaterialTheme.shapes.medium)

when (item) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.ashdavies.party.upcoming

import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.paging.Pager
import androidx.paging.cachedIn
import androidx.paging.compose.collectAsLazyPagingItems
Expand All @@ -9,13 +10,12 @@ import io.ashdavies.party.events.Event
import io.ashdavies.party.events.paging.errorMessage
import io.ashdavies.party.events.paging.isRefreshing
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.CoroutineScope

@Composable
internal fun UpcomingEventsPresenter(
eventPager: Pager<String, Event>,
coroutineScope: CoroutineScope,
): UpcomingEventsScreen.State {
val coroutineScope = rememberCoroutineScope()
val pagingItems = rememberRetained(coroutineScope) {
eventPager.flow.cachedIn(coroutineScope)
}.collectAsLazyPagingItems()
Expand All @@ -28,8 +28,8 @@ internal fun UpcomingEventsPresenter(
isRefreshing = pagingItems.loadState.isRefreshing,
errorMessage = pagingItems.loadState.errorMessage,
) { event ->
if (event is UpcomingEventsScreen.Event.Refresh) {
pagingItems.refresh()
when (event) {
is UpcomingEventsScreen.Event.Refresh -> pagingItems.refresh()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import io.ashdavies.http.ProvideHttpClient
import io.ashdavies.http.publicStorage
import io.ashdavies.io.resolveCacheDir
import io.ashdavies.material.dynamicColorScheme
import io.ashdavies.party.config.rememberCircuit
import io.ashdavies.party.circuit.rememberCircuit
import io.ashdavies.party.home.HomeScreen
import io.ashdavies.party.material.ProvideLocalWindowSizeClass
import io.ashdavies.playground.BuildConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@ public interface RemoteConfig {
public suspend fun RemoteConfig.getBoolean(key: String): Boolean {
return getValue(key) { it.asBoolean() }
}

public suspend fun RemoteConfig.getString(key: String): String {
return getValue(key) { it.asString() }
}
Loading