Skip to content

Commit

Permalink
Validator details progress: add/remove validator + state feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
kukabi committed Feb 14, 2024
1 parent 15a8d4b commit ac620ed
Show file tree
Hide file tree
Showing 20 changed files with 601 additions and 386 deletions.
5 changes: 4 additions & 1 deletion subvt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ dependencies {
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3:1.2.0")
implementation("androidx.navigation:navigation-compose:2.7.6")
implementation("androidx.navigation:navigation-compose:2.7.7")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0")
implementation("androidx.datastore:datastore-preferences:1.0.0")
implementation("androidx.core:core-splashscreen:1.0.1")

// de/serialization
implementation("com.google.code.gson:gson:2.10.1")

// firebase
implementation(platform("com.google.firebase:firebase-bom:32.7.1"))
implementation("com.google.firebase:firebase-messaging-ktx")
Expand Down
6 changes: 6 additions & 0 deletions subvt/src/main/java/io/helikon/subvt/data/extension/Gson.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.helikon.subvt.data.extension

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

internal inline fun <reified T> Gson.fromJson(json: String) = fromJson<T>(json, object : TypeToken<T>() {}.type)

This file was deleted.

6 changes: 0 additions & 6 deletions subvt/src/main/java/io/helikon/subvt/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import dagger.hilt.InstallIn
import dagger.hilt.android.components.ViewModelComponent
import dagger.hilt.android.qualifiers.ApplicationContext
import io.helikon.subvt.data.db.SubVTDatabase
import io.helikon.subvt.data.repository.AppServiceRepository
import io.helikon.subvt.data.repository.NetworkRepository
import io.helikon.subvt.data.repository.UserPreferencesRepository

Expand All @@ -19,11 +18,6 @@ class AppModule {
@ApplicationContext context: Context,
): UserPreferencesRepository = UserPreferencesRepository(context)

@Provides
fun provideAppServiceRepository(
@ApplicationContext context: Context,
): AppServiceRepository = AppServiceRepository(context)

@Provides
fun provideNetworkRepository(
@ApplicationContext context: Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.helikon.subvt.ui.component
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
Expand Down Expand Up @@ -68,7 +69,7 @@ fun ActionButton(
}
if (isLoading) {
CircularProgressIndicator(
modifier = Modifier.width(dimensionResource(id = R.dimen.action_button_progress_width)),
modifier = Modifier.size(dimensionResource(id = R.dimen.action_button_progress_width)),
color = Color.actionButtonText(),
trackColor = Color.transparent(),
)
Expand Down
25 changes: 17 additions & 8 deletions subvt/src/main/java/io/helikon/subvt/ui/component/Snackbar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
Expand All @@ -30,6 +33,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex
import io.helikon.subvt.R
import io.helikon.subvt.ui.modifier.NoRippleInteractionSource
import io.helikon.subvt.ui.modifier.noRippleClickable
Expand All @@ -51,16 +55,21 @@ fun SnackbarScaffold(
modifier.fillMaxSize(),
) {
content()
Snackbar(
text = snackbarText,
Column(
modifier =
Modifier
.align(Alignment.BottomCenter),
isDark = isDark,
isVisible = snackbarIsVisible,
onSnackbarClick,
onSnackbarRetry,
)
.align(Alignment.BottomCenter)
.zIndex(15.0f),
) {
Snackbar(
text = snackbarText,
isDark = isDark,
isVisible = snackbarIsVisible,
onClick = onSnackbarClick,
onRetry = onSnackbarRetry,
)
Spacer(modifier = Modifier.navigationBarsPadding())
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import io.helikon.subvt.BuildConfig
import io.helikon.subvt.data.DataRequestState
import io.helikon.subvt.data.DataRequestState.Error
import io.helikon.subvt.data.DataRequestState.Idle
import io.helikon.subvt.data.DataRequestState.Loading
import io.helikon.subvt.data.DataRequestState.Success
import io.helikon.subvt.data.SubVTData
import io.helikon.subvt.data.model.app.User
import io.helikon.subvt.data.repository.AppServiceRepository
import io.helikon.subvt.data.repository.UserPreferencesRepository
import io.helikon.subvt.data.service.AppService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand All @@ -24,24 +26,28 @@ import javax.inject.Inject
class IntroductionViewModel
@Inject
constructor(
@ApplicationContext context: Context,
private val userPreferencesRepository: UserPreferencesRepository,
private val appServiceRepository: AppServiceRepository,
) : ViewModel() {
var createUserState by mutableStateOf<DataRequestState<User>>(Idle)
private set
private val appService =
AppService(
context,
"https://${BuildConfig.API_HOST}:${BuildConfig.APP_SERVICE_PORT}/",
)

fun createUser(context: Context) {
createUserState = Loading
viewModelScope.launch(Dispatchers.IO) {
val response =
try {
SubVTData.reset(context)
appServiceRepository.createUser()
appService.createUser()
} catch (error: Throwable) {
createUserState = Error(error)
return@launch
}
appServiceRepository.createUser()
if (response.isSuccess) {
response.getOrNull().let {
createUserState =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private fun NetworkSelectionScreenContent(
CircularProgressIndicator(
modifier =
Modifier
.width(dimensionResource(id = R.dimen.common_progress_width))
.size(dimensionResource(id = R.dimen.common_progress_size))
.align(Alignment.Center),
color = Color.lightGray(),
trackColor = Color.transparent(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package io.helikon.subvt.ui.screen.network.selection

import android.content.Context
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import io.helikon.subvt.BuildConfig
import io.helikon.subvt.data.DataRequestState
import io.helikon.subvt.data.model.Network
import io.helikon.subvt.data.repository.AppServiceRepository
import io.helikon.subvt.data.repository.NetworkRepository
import io.helikon.subvt.data.repository.UserPreferencesRepository
import io.helikon.subvt.data.service.AppService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
Expand All @@ -20,13 +23,18 @@ import javax.inject.Inject
class NetworkSelectionViewModel
@Inject
constructor(
@ApplicationContext context: Context,
private val userPreferencesRepository: UserPreferencesRepository,
private val appServiceRepository: AppServiceRepository,
private val networkRepository: NetworkRepository,
) : ViewModel() {
var getNetworksState by mutableStateOf<DataRequestState<List<Network>>>(DataRequestState.Idle)
private set
val networks = networkRepository.allNetworks
private val appService =
AppService(
context,
"https://${BuildConfig.API_HOST}:${BuildConfig.APP_SERVICE_PORT}/",
)

fun getNetworks() {
val networks =
Expand All @@ -44,7 +52,7 @@ class NetworkSelectionViewModel
viewModelScope.launch(Dispatchers.IO) {
val response =
try {
appServiceRepository.getNetworks()
appService.getNetworks()
} catch (error: Throwable) {
getNetworksState = DataRequestState.Error(error)
return@launch
Expand Down
Loading

0 comments on commit ac620ed

Please sign in to comment.