-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: solve kotlin 2.0 issue due to expect-actual operator for value …
…class
- Loading branch information
1 parent
bbb55a6
commit 803e682
Showing
22 changed files
with
279 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
package id.gdg.app.ui | ||
|
||
import id.gdg.app.ui.state.EventDetailUiModel | ||
|
||
sealed class AppRouter(val route: String) { | ||
|
||
data object Splash : AppRouter("splash") | ||
data object Onboarding : AppRouter("onboarding") | ||
data object Home : AppRouter("home") | ||
data object Splash : AppRouter(SplashRoute) | ||
data object Onboarding : AppRouter(OnboardingRoute) | ||
data object Home : AppRouter(HomeRoute) | ||
|
||
data class EventDetail(val eventId: Int) : AppRouter(EventDetailRoute) | ||
|
||
companion object { | ||
val SplashRoute get() = "splash" | ||
val OnboardingRoute get() = "onboarding" | ||
|
||
val HomeRoute get() = "home" | ||
|
||
// SAMPAH | ||
val EventDetailRoute get() = "detail/{$ArgumentEventId}" | ||
fun constructEventDetailRoute(eventId: String) = EventDetailRoute | ||
.replace("{$ArgumentEventId}", eventId) | ||
|
||
val ArgumentEventId get() = "eventId" | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
app/src/commonMain/kotlin/id/gdg/app/ui/screen/EventDetailScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package id.gdg.app.ui.screen | ||
|
||
import androidx.compose.animation.AnimatedVisibility | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import id.gdg.app.AppViewModel | ||
import id.gdg.app.ui.AppEvent | ||
|
||
@Composable | ||
fun EventDetailScreen(viewModel: AppViewModel, eventId: String) { | ||
val eventDetailUiState by viewModel.eventDetailUiState.collectAsState() | ||
|
||
LaunchedEffect(Unit) { | ||
if (eventId.isNotEmpty()) { | ||
viewModel.sendEvent(AppEvent.EventDetail(eventId.toInt())) | ||
} | ||
} | ||
|
||
Box { | ||
AnimatedVisibility(eventDetailUiState.state.isLoading) { | ||
CircularProgressIndicator() | ||
} | ||
|
||
when { | ||
eventDetailUiState.state.isSuccess -> { | ||
Text(text = "${eventDetailUiState.detail}") | ||
} | ||
eventDetailUiState.state.isFail -> { | ||
Row { | ||
Text("gagal loading nih, refresh yuk") | ||
Button( | ||
onClick = {} | ||
) { | ||
Text("Refresh") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
91 changes: 88 additions & 3 deletions
91
app/src/commonMain/kotlin/id/gdg/app/ui/screen/MainScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,116 @@ | ||
package id.gdg.app.ui.screen | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.unit.dp | ||
import id.gdg.app.AppViewModel | ||
import id.gdg.app.ui.AppEvent | ||
import id.gdg.app.ui.screen.content.PreviousEventContent | ||
import id.gdg.app.ui.screen.content.UpcomingEventContent | ||
import id.gdg.app.ui.state.ChapterUiModel | ||
import id.gdg.ui.TwoPanelScaffold | ||
import id.gdg.ui.TwoPanelScaffoldAnimationSpec | ||
import id.gdg.ui.androidx.compose.material3.windowsizeclass.CommonWindowSizeClass | ||
import id.gdg.ui.androidx.compose.material3.windowsizeclass.CommonWindowWidthSizeClass | ||
import id.gdg.ui.androidx.compose.material3.windowsizeclass.LocalWindowSizeClass | ||
|
||
@Composable | ||
fun MainScreen(viewModel: AppViewModel) { | ||
fun MainScreen( | ||
viewModel: AppViewModel, | ||
navigateToDetailScreen: (String) -> Unit | ||
) { | ||
val chapterUiState by viewModel.chapterUiState.collectAsState() | ||
var selectedEventId by rememberSaveable { mutableStateOf("") } | ||
|
||
val windowSizeClazz: CommonWindowSizeClass = LocalWindowSizeClass.current | ||
var hasDetailOpened: Boolean? by rememberSaveable { mutableStateOf(null) } | ||
var showSidePanel by rememberSaveable { | ||
mutableStateOf(hasDetailOpened != null).also { | ||
println("showsidepanel: ${it.value}") | ||
} | ||
} | ||
|
||
LaunchedEffect(Unit) { | ||
viewModel.sendEvent(AppEvent.InitialContent) | ||
} | ||
|
||
LaunchedEffect(windowSizeClazz) { | ||
hasDetailOpened = | ||
hasDetailOpened.takeIf { windowSizeClazz.widthSizeClass != CommonWindowWidthSizeClass.Compact } | ||
println("hasdetail: $hasDetailOpened") | ||
println("apaini: ${windowSizeClazz.widthSizeClass != CommonWindowWidthSizeClass.Compact}") | ||
showSidePanel = hasDetailOpened != null | ||
} | ||
|
||
TwoPanelScaffold( | ||
panelVisibility = showSidePanel, | ||
animationSpec = TwoPanelScaffoldAnimationSpec( | ||
finishedListener = { fraction -> if (fraction == 1f) hasDetailOpened = null } | ||
), | ||
body = { | ||
MainScreenView( | ||
chapterUiState = chapterUiState, | ||
onEventDetailClicked = { | ||
// If the screen size is compact (or mobile device screen size), then | ||
// navigate to detail page with router. Otherwise, render the [panel]. | ||
if (windowSizeClazz.widthSizeClass == CommonWindowWidthSizeClass.Compact) { | ||
navigateToDetailScreen(it) | ||
return@MainScreenView | ||
} | ||
|
||
selectedEventId = it | ||
hasDetailOpened = true | ||
showSidePanel = true | ||
}, | ||
onRefreshPreviousContentClicked = { | ||
viewModel.sendEvent(AppEvent.FetchPreviousEvent) | ||
} | ||
) | ||
}, | ||
panel = { | ||
Surface(tonalElevation = 1.dp) { | ||
if (hasDetailOpened != null) { | ||
EventDetailScreen( | ||
viewModel = viewModel, | ||
eventId = selectedEventId | ||
) | ||
} | ||
} | ||
} | ||
) | ||
} | ||
|
||
@Composable | ||
fun MainScreenView( | ||
chapterUiState: ChapterUiModel, | ||
onEventDetailClicked: (String) -> Unit, | ||
onRefreshPreviousContentClicked: () -> Unit | ||
) { | ||
Column { | ||
UpcomingEventContent(chapterUiState.upcomingEvent) | ||
|
||
Button( | ||
onClick = { | ||
onEventDetailClicked("60014") | ||
} | ||
) { | ||
Text("Show Detail") | ||
} | ||
|
||
PreviousEventContent( | ||
data = chapterUiState.previousEvents, | ||
onRefreshContent = { | ||
viewModel.sendEvent(AppEvent.FetchPreviousEvent) | ||
onRefreshPreviousContentClicked() | ||
} | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,37 @@ | ||
@file:Suppress("FunctionName") | ||
|
||
package id.gdg.app | ||
|
||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.foundation.layout.BoxWithConstraints | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.DpSize | ||
import androidx.compose.ui.window.ComposeUIViewController | ||
import id.gdg.app.ui.AppContent | ||
import id.gdg.ui.DarkColorPalette | ||
import id.gdg.ui.LightColorPalette | ||
import id.gdg.ui.androidx.compose.material3.windowsizeclass.LocalWindowSizeClass | ||
import id.gdg.ui.androidx.compose.material3.windowsizeclass.CommonWindowSizeClass | ||
import id.gdg.ui.androidx.compose.material3.windowsizeclass.calculateWindowSizeClass | ||
|
||
fun MainViewController() = ComposeUIViewController { | ||
BoxWithConstraints { | ||
val colors = if (isSystemInDarkTheme()) DarkColorPalette else LightColorPalette | ||
val windowSizeClass: CommonWindowSizeClass = calculateWindowSizeClass(DpSize(maxWidth, maxHeight)) | ||
|
||
fun MainViewController() = ComposeUIViewController { App() } | ||
CompositionLocalProvider(LocalWindowSizeClass provides windowSizeClass) { | ||
MaterialTheme(colorScheme = colors) { | ||
Surface( | ||
modifier = Modifier.fillMaxSize(), | ||
color = MaterialTheme.colorScheme.background | ||
) { | ||
AppContent() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
...in/kotlin/id/gdg/ui/androidx/compose/material3/windowsizeclass/WindowHeightSizeClasses.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...ndroidMain/kotlin/id/gdg/ui/androidx/compose/material3/windowsizeclass/WindowSizeClass.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.