Skip to content

Commit

Permalink
feat(main): support default event.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed May 9, 2024
1 parent 9da41d4 commit 2c6af9f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
3 changes: 2 additions & 1 deletion androidApp/app.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
BASE_URL=https://cms4partners-ce427.nw.r.appspot.com
FIREBASE_PROJECT_ID=open-feedback-42
FIREBASE_APP_ID=1:635903227116:android:ffbe1750162d4b01b1e1c9
FIREBASE_API_KEY=AIzaSyDVVFO767y1cfp38D_rveqPm0XEaWrzFiA
FIREBASE_API_KEY=AIzaSyDVVFO767y1cfp38D_rveqPm0XEaWrzFiA
DEFAULT_EVENT=devfest-lille-2024
2 changes: 2 additions & 0 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ android {
stringBuildConfigField("FIREBASE_PROJECT_ID", appProps)
stringBuildConfigField("FIREBASE_APP_ID", appProps)
stringBuildConfigField("FIREBASE_API_KEY", appProps)
stringBuildConfigField("DEFAULT_EVENT", appProps)
}
getByName("debug") {
stringBuildConfigField("BASE_URL", appProps)
Expand All @@ -59,6 +60,7 @@ android {
stringBuildConfigField("FIREBASE_PROJECT_ID", appProps)
stringBuildConfigField("FIREBASE_APP_ID", appProps)
stringBuildConfigField("FIREBASE_API_KEY", appProps)
stringBuildConfigField("DEFAULT_EVENT", appProps)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class MainActivity : ComponentActivity() {
val reportSubject = stringResource(Resource.string.text_report_subject)
val reportAppTarget = stringResource(Resource.string.text_report_app_target)
Main(
defaultEvent = BuildConfig.DEFAULT_EVENT,
openfeedbackFirebaseConfig = openfeedbackFirebaseConfig,
launchUrl = { launchUrl(it) },
onContactExportClicked = { export ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface EventRepository {
suspend fun fetchAndStoreEventList()
fun events(): Flow<EventItemListUi>
fun currentEvent(): Flow<EventInfoUi?>
fun isInitialized(): Boolean
fun isInitialized(defaultEvent: String? = null): Boolean
fun saveEventId(eventId: String)
fun deleteEventId()

Expand All @@ -40,11 +40,16 @@ class EventRepositoryImpl(
override fun events(): Flow<EventItemListUi> = eventDao.fetchEventList()
override fun currentEvent(): Flow<EventInfoUi?> = eventDao.fetchCurrentEvent()

override fun isInitialized(): Boolean = try {
override fun isInitialized(defaultEvent: String?): Boolean = try {
eventDao.getEventId()
true
} catch (_: EventSavedException) {
false
if (defaultEvent != null) {
eventDao.insertEventId(defaultEvent)
true
} else {
false
}
}

override fun saveEventId(eventId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ val mainModule = module {
speakersModule
)
viewModel { MainNavigationViewModel(get(), get()) }
viewModel { MainViewModel(get()) }
viewModel { parameters -> MainViewModel(parameters.get(), get()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import kotlinx.coroutines.FlowPreview
import org.gdglille.devfest.android.theme.m3.style.Conferences4HallTheme
import org.gdglille.devfest.models.ui.ExportNetworkingUi
import org.koin.androidx.compose.koinViewModel
import org.koin.core.parameter.parametersOf

@Suppress("LongMethod", "UnusedPrivateMember")
@ExperimentalCoroutinesApi
@FlowPreview
@Composable
fun Main(
defaultEvent: String?,
openfeedbackFirebaseConfig: OpenFeedbackFirebaseConfig,
launchUrl: (String) -> Unit,
onContactExportClicked: (ExportNetworkingUi) -> Unit,
Expand All @@ -25,7 +27,7 @@ fun Main(
onScheduleStarted: () -> Unit,
onProfileCreated: () -> Unit,
navController: NavHostController,
viewModel: MainViewModel = koinViewModel()
viewModel: MainViewModel = koinViewModel(parameters = { parametersOf(defaultEvent) })
) {
Conferences4HallTheme {
val uiState = viewModel.uiState.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ sealed class MainUiState {
data class Success(val startDestination: String) : MainUiState()
}

class MainViewModel(private val repository: EventRepository) : ViewModel() {
val uiState: StateFlow<MainUiState> = flow { emit(repository.isInitialized()) }
class MainViewModel(
defaultEvent: String?,
private val repository: EventRepository
) : ViewModel() {
val uiState: StateFlow<MainUiState> = flow { emit(repository.isInitialized(defaultEvent)) }
.map { MainUiState.Success(if (it) Screen.ScheduleList.route else Screen.EventList.route) }
.stateIn(
scope = viewModelScope,
Expand Down

0 comments on commit 2c6af9f

Please sign in to comment.