Skip to content

Commit

Permalink
Properly load initial data (#57)
Browse files Browse the repository at this point in the history
* Properly load initial data

* Updated dependencies
  • Loading branch information
JackEblan committed Sep 20, 2024
1 parent 115b3da commit 6b8810b
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 143 deletions.
164 changes: 85 additions & 79 deletions app/dependencies/releaseRuntimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,95 +1,99 @@
androidx.activity:activity-compose:1.9.0
androidx.activity:activity-ktx:1.9.0
androidx.activity:activity:1.9.0
androidx.activity:activity-compose:1.9.2
androidx.activity:activity-ktx:1.9.2
androidx.activity:activity:1.9.2
androidx.annotation:annotation-experimental:1.4.1
androidx.annotation:annotation-jvm:1.8.0
androidx.annotation:annotation:1.8.0
androidx.annotation:annotation-jvm:1.8.1
androidx.annotation:annotation:1.8.1
androidx.appcompat:appcompat-resources:1.6.1
androidx.arch.core:core-common:2.2.0
androidx.arch.core:core-runtime:2.2.0
androidx.autofill:autofill:1.0.0
androidx.collection:collection-jvm:1.4.0
androidx.collection:collection-ktx:1.4.0
androidx.collection:collection:1.4.0
androidx.compose.animation:animation-android:1.7.0
androidx.compose.animation:animation-core-android:1.7.0
androidx.compose.animation:animation-core:1.7.0
androidx.compose.animation:animation:1.7.0
androidx.compose.foundation:foundation-android:1.7.0
androidx.compose.foundation:foundation-layout-android:1.7.0
androidx.compose.foundation:foundation-layout:1.7.0
androidx.compose.foundation:foundation:1.7.0
androidx.collection:collection-jvm:1.4.4
androidx.collection:collection-ktx:1.4.4
androidx.collection:collection:1.4.4
androidx.compose.animation:animation-android:1.7.2
androidx.compose.animation:animation-core-android:1.7.2
androidx.compose.animation:animation-core:1.7.2
androidx.compose.animation:animation:1.7.2
androidx.compose.foundation:foundation-android:1.7.2
androidx.compose.foundation:foundation-layout-android:1.7.2
androidx.compose.foundation:foundation-layout:1.7.2
androidx.compose.foundation:foundation:1.7.2
androidx.compose.material3.adaptive:adaptive-android:1.0.0
androidx.compose.material3.adaptive:adaptive:1.0.0
androidx.compose.material3:material3-adaptive-navigation-suite-android:1.3.0
androidx.compose.material3:material3-adaptive-navigation-suite:1.3.0
androidx.compose.material3:material3-android:1.3.0
androidx.compose.material3:material3:1.3.0
androidx.compose.material:material-icons-core-android:1.7.0
androidx.compose.material:material-icons-core:1.7.0
androidx.compose.material:material-icons-extended-android:1.7.0
androidx.compose.material:material-icons-extended:1.7.0
androidx.compose.material:material-ripple-android:1.7.0
androidx.compose.material:material-ripple:1.7.0
androidx.compose.runtime:runtime-android:1.7.0
androidx.compose.runtime:runtime-saveable-android:1.7.0
androidx.compose.runtime:runtime-saveable:1.7.0
androidx.compose.runtime:runtime:1.7.0
androidx.compose.ui:ui-android:1.7.0
androidx.compose.ui:ui-geometry-android:1.7.0
androidx.compose.ui:ui-geometry:1.7.0
androidx.compose.ui:ui-graphics-android:1.7.0
androidx.compose.ui:ui-graphics:1.7.0
androidx.compose.ui:ui-text-android:1.7.0
androidx.compose.ui:ui-text:1.7.0
androidx.compose.ui:ui-tooling-preview-android:1.7.0
androidx.compose.ui:ui-tooling-preview:1.7.0
androidx.compose.ui:ui-unit-android:1.7.0
androidx.compose.ui:ui-unit:1.7.0
androidx.compose.ui:ui-util-android:1.7.0
androidx.compose.ui:ui-util:1.7.0
androidx.compose.ui:ui:1.7.0
androidx.compose:compose-bom:2024.09.00
androidx.compose.material:material-icons-core-android:1.7.2
androidx.compose.material:material-icons-core:1.7.2
androidx.compose.material:material-icons-extended-android:1.7.2
androidx.compose.material:material-icons-extended:1.7.2
androidx.compose.material:material-ripple-android:1.7.2
androidx.compose.material:material-ripple:1.7.2
androidx.compose.runtime:runtime-android:1.7.2
androidx.compose.runtime:runtime-saveable-android:1.7.2
androidx.compose.runtime:runtime-saveable:1.7.2
androidx.compose.runtime:runtime:1.7.2
androidx.compose.ui:ui-android:1.7.2
androidx.compose.ui:ui-geometry-android:1.7.2
androidx.compose.ui:ui-geometry:1.7.2
androidx.compose.ui:ui-graphics-android:1.7.2
androidx.compose.ui:ui-graphics:1.7.2
androidx.compose.ui:ui-text-android:1.7.2
androidx.compose.ui:ui-text:1.7.2
androidx.compose.ui:ui-tooling-preview-android:1.7.2
androidx.compose.ui:ui-tooling-preview:1.7.2
androidx.compose.ui:ui-unit-android:1.7.2
androidx.compose.ui:ui-unit:1.7.2
androidx.compose.ui:ui-util-android:1.7.2
androidx.compose.ui:ui-util:1.7.2
androidx.compose.ui:ui:1.7.2
androidx.compose:compose-bom:2024.09.02
androidx.concurrent:concurrent-futures:1.1.0
androidx.core:core-ktx:1.13.1
androidx.core:core-splashscreen:1.0.1
androidx.core:core:1.13.1
androidx.customview:customview-poolingcontainer:1.0.0
androidx.customview:customview:1.0.0
androidx.datastore:datastore-core:1.0.0
androidx.datastore:datastore:1.0.0
androidx.datastore:datastore-android:1.1.1
androidx.datastore:datastore-core-android:1.1.1
androidx.datastore:datastore-core-okio-jvm:1.1.1
androidx.datastore:datastore-core-okio:1.1.1
androidx.datastore:datastore-core:1.1.1
androidx.datastore:datastore:1.1.1
androidx.emoji2:emoji2:1.3.0
androidx.exifinterface:exifinterface:1.3.7
androidx.fragment:fragment:1.5.1
androidx.graphics:graphics-path:1.0.1
androidx.hilt:hilt-navigation-compose:1.2.0
androidx.hilt:hilt-navigation:1.2.0
androidx.interpolator:interpolator:1.0.0
androidx.lifecycle:lifecycle-common-java8:2.8.3
androidx.lifecycle:lifecycle-common-jvm:2.8.3
androidx.lifecycle:lifecycle-common:2.8.3
androidx.lifecycle:lifecycle-livedata-core-ktx:2.8.3
androidx.lifecycle:lifecycle-livedata-core:2.8.3
androidx.lifecycle:lifecycle-livedata:2.8.3
androidx.lifecycle:lifecycle-process:2.8.3
androidx.lifecycle:lifecycle-runtime-android:2.8.3
androidx.lifecycle:lifecycle-runtime-compose-android:2.8.3
androidx.lifecycle:lifecycle-runtime-compose:2.8.3
androidx.lifecycle:lifecycle-runtime-ktx-android:2.8.3
androidx.lifecycle:lifecycle-runtime-ktx:2.8.3
androidx.lifecycle:lifecycle-runtime:2.8.3
androidx.lifecycle:lifecycle-viewmodel-android:2.8.3
androidx.lifecycle:lifecycle-viewmodel-compose-android:2.8.3
androidx.lifecycle:lifecycle-viewmodel-compose:2.8.3
androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.3
androidx.lifecycle:lifecycle-viewmodel-savedstate:2.8.3
androidx.lifecycle:lifecycle-viewmodel:2.8.3
androidx.lifecycle:lifecycle-common-java8:2.8.6
androidx.lifecycle:lifecycle-common-jvm:2.8.6
androidx.lifecycle:lifecycle-common:2.8.6
androidx.lifecycle:lifecycle-livedata-core-ktx:2.8.6
androidx.lifecycle:lifecycle-livedata-core:2.8.6
androidx.lifecycle:lifecycle-livedata:2.8.6
androidx.lifecycle:lifecycle-process:2.8.6
androidx.lifecycle:lifecycle-runtime-android:2.8.6
androidx.lifecycle:lifecycle-runtime-compose-android:2.8.6
androidx.lifecycle:lifecycle-runtime-compose:2.8.6
androidx.lifecycle:lifecycle-runtime-ktx-android:2.8.6
androidx.lifecycle:lifecycle-runtime-ktx:2.8.6
androidx.lifecycle:lifecycle-runtime:2.8.6
androidx.lifecycle:lifecycle-viewmodel-android:2.8.6
androidx.lifecycle:lifecycle-viewmodel-compose-android:2.8.6
androidx.lifecycle:lifecycle-viewmodel-compose:2.8.6
androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.6
androidx.lifecycle:lifecycle-viewmodel-savedstate:2.8.6
androidx.lifecycle:lifecycle-viewmodel:2.8.6
androidx.loader:loader:1.0.0
androidx.navigation:navigation-common-ktx:2.8.0-beta06
androidx.navigation:navigation-common:2.8.0-beta06
androidx.navigation:navigation-compose:2.8.0-beta06
androidx.navigation:navigation-runtime-ktx:2.8.0-beta06
androidx.navigation:navigation-runtime:2.8.0-beta06
androidx.navigation:navigation-common-ktx:2.8.1
androidx.navigation:navigation-common:2.8.1
androidx.navigation:navigation-compose:2.8.1
androidx.navigation:navigation-runtime-ktx:2.8.1
androidx.navigation:navigation-runtime:2.8.1
androidx.profileinstaller:profileinstaller:1.3.1
androidx.room:room-common:2.6.1
androidx.room:room-ktx:2.6.1
Expand Down Expand Up @@ -124,17 +128,16 @@ com.google.errorprone:error_prone_annotations:2.26.0
com.google.firebase:firebase-annotations:16.2.0
com.google.firebase:firebase-appcheck-interop:17.0.0
com.google.firebase:firebase-auth-interop:19.0.2
com.google.firebase:firebase-bom:33.1.2
com.google.firebase:firebase-bom:33.3.0
com.google.firebase:firebase-common-ktx:21.0.0
com.google.firebase:firebase-common:21.0.0
com.google.firebase:firebase-components:18.0.0
com.google.firebase:firebase-database-collection:18.0.1
com.google.firebase:firebase-firestore:25.0.0
com.google.firebase:firebase-firestore:25.1.0
com.google.firebase:protolite-well-known-types:18.0.0
com.google.guava:failureaccess:1.0.1
com.google.guava:guava:32.0.1-android
com.google.guava:guava:32.1.3-android
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
com.google.j2objc:j2objc-annotations:2.8
com.google.protobuf:protobuf-javalite:4.26.1
com.google.protobuf:protobuf-kotlin-lite:4.26.1
com.squareup.okhttp3:okhttp:4.12.0
Expand All @@ -144,17 +147,20 @@ io.coil-kt:coil-base:2.6.0
io.coil-kt:coil-compose-base:2.6.0
io.coil-kt:coil-compose:2.6.0
io.coil-kt:coil:2.6.0
io.grpc:grpc-android:1.57.2
io.grpc:grpc-api:1.57.2
io.grpc:grpc-context:1.57.2
io.grpc:grpc-core:1.57.2
io.grpc:grpc-okhttp:1.57.2
io.grpc:grpc-protobuf-lite:1.57.2
io.grpc:grpc-stub:1.57.2
io.grpc:grpc-android:1.62.2
io.grpc:grpc-api:1.62.2
io.grpc:grpc-context:1.62.2
io.grpc:grpc-core:1.62.2
io.grpc:grpc-okhttp:1.62.2
io.grpc:grpc-protobuf-lite:1.62.2
io.grpc:grpc-stub:1.62.2
io.grpc:grpc-util:1.62.2
io.perfmark:perfmark-api:0.26.0
javax.inject:javax.inject:1
org.checkerframework:checker-qual:3.33.0
org.checkerframework:checker-qual:3.37.0
org.codehaus.mojo:animal-sniffer-annotations:1.23
org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.9.22
org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.22
org.jetbrains.kotlin:kotlin-stdlib-common:2.0.0
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.0
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import com.eblan.socialworkreviewer.core.data.repository.QuestionRepository
import com.eblan.socialworkreviewer.core.model.Question

class FakeQuestionRepository : QuestionRepository {
private var _questions = emptyList<Question>()
private val _questions = mutableListOf<Question>()

override suspend fun getQuestions(id: String): List<Question> {
return _questions
}

fun setQuestions(value: List<Question>) {
_questions = value
_questions.addAll(value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.eblan.socialworkreviewer.framework.countdowntimer.CountDownTimerWrapp
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
Expand All @@ -60,7 +60,13 @@ class QuestionViewModel @Inject constructor(
private val id = questionRouteData.id

private val _questionUiState = MutableStateFlow<QuestionUiState?>(null)
val questionUiState = _questionUiState.asStateFlow()
val questionUiState = _questionUiState.onStart {
getCategory()
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5_000),
initialValue = null,
)

val currentQuestionData = choiceRepository.currentQuestionData.stateIn(
scope = viewModelScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults.enterAlwaysScrollBehavior
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
Expand All @@ -65,18 +64,6 @@ import com.eblan.socialworkreviewer.core.model.QuestionSetting
import com.eblan.socialworkreviewer.core.model.Statistics
import kotlin.math.roundToInt

@Composable
internal fun LoadingOnBoardingScreen(
modifier: Modifier = Modifier,
onGetCategory: () -> Unit,
) {
LaunchedEffect(key1 = true) {
onGetCategory()
}

LoadingScreen(modifier = modifier)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun SuccessOnBoardingScreen(
Expand Down Expand Up @@ -126,12 +113,16 @@ internal fun SuccessOnBoardingScreen(
contentPadding = paddingValues,
) {
item {
Statistics(
modifier = modifier,
average = statistics.totalAverage,
totalScore = statistics.totalScore,
totalNumberOfQuestions = statistics.totalNumberOfQuestions,
)
OutlinedCard(
modifier = Modifier.padding(10.dp),
) {
Statistics(
modifier = modifier,
average = statistics.totalAverage,
totalScore = statistics.totalScore,
totalNumberOfQuestions = statistics.totalNumberOfQuestions,
)
}
}

itemsIndexed(category.questionSettings) { index, questionSetting ->
Expand Down Expand Up @@ -209,7 +200,12 @@ private fun Statistics(
totalScore: Int,
totalNumberOfQuestions: Int,
) {
Column(modifier = modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
Column(
modifier = modifier
.fillMaxWidth()
.padding(15.dp),
horizontalAlignment = Alignment.CenterHorizontally,
) {
AverageCircularProgressIndicator(
progress = { (average / 100).toFloat() },
modifier = Modifier.size(60.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ internal fun QuestionRoute(
questionUiState = questionUiState,
currentQuestionData = currentQuestionData,
countDownTime = countDownTime,
onGetCategory = viewModel::getCategory,
onAddCurrentQuestion = viewModel::addCurrentQuestion,
onUpdateChoice = viewModel::updateChoice,
onShowCorrectChoices = viewModel::showCorrectChoices,
Expand All @@ -144,7 +143,6 @@ internal fun QuestionScreen(
questionUiState: QuestionUiState?,
currentQuestionData: QuestionData,
countDownTime: CountDownTime?,
onGetCategory: () -> Unit,
onAddCurrentQuestion: (Question) -> Unit,
onUpdateChoice: (Choice) -> Unit,
onShowCorrectChoices: (questions: List<Question>) -> Unit,
Expand Down Expand Up @@ -218,10 +216,6 @@ internal fun QuestionScreen(
}
}

null -> {
LoadingOnBoardingScreen(onGetCategory = onGetCategory)
}

is QuestionUiState.QuickQuestions -> {
if (state.questions.isNotEmpty()) {
QuickQuestionsScreen(
Expand All @@ -244,6 +238,10 @@ internal fun QuestionScreen(
onQuitQuestions = onQuitQuestions,
)
}

null -> {
LoadingScreen()
}
}
}
}
Expand Down
Loading

0 comments on commit 6b8810b

Please sign in to comment.