Skip to content

Commit

Permalink
Androapp 5155 (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosMacaneta authored and andresmr committed Feb 8, 2023
1 parent 9b5b82f commit f0d2840
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 72 deletions.
2 changes: 1 addition & 1 deletion app/src/main/assets/paperwork.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"buildTime":"2023-01-16 12:38","gitSha":"9878e2ebb"}
{"buildTime":"2023-01-19 15:55","gitSha":"7559cb026"}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class HomeActivity : AppCompatActivity(), OnOrgUnitSelectionFinished {
setContent {
val settingsUiState by viewModel.settingsUiState.collectAsState()
updateTheme(settingsUiState.transactionType)
manageStockViewModel.setThemeColor(Color(colorResource(themeColor).toArgb()))
MdcTheme {
Surface(
modifier = Modifier.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package org.dhis2.android.rtsm.ui.home.model

import androidx.compose.ui.graphics.Color
import org.dhis2.android.rtsm.R
import org.dhis2.android.rtsm.ui.home.model.ButtonVisibilityState.HIDDEN

data class ButtonUiState(
val text: Int = R.string.review,
val icon: Int = R.drawable.proceed_icon,
val visibility: ButtonVisibilityState = HIDDEN
val color: Color = Color.White,
val contentColor: Color = Color.White,
val containerColor: Color = Color.Blue,
val visible: Boolean = false
)

enum class ButtonVisibilityState {
HIDDEN,
DISABLED,
ENABLED
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package org.dhis2.android.rtsm.ui.home.screens
import android.app.Activity
import androidx.activity.result.ActivityResultLauncher
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.material.Icon
import androidx.compose.material.Scaffold
import androidx.compose.material.ScaffoldState
import androidx.compose.material.Snackbar
Expand All @@ -15,22 +15,20 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.viewmodel.compose.viewModel
import com.journeyapps.barcodescanner.ScanOptions
import kotlinx.coroutines.CoroutineScope
import org.dhis2.android.rtsm.R
import org.dhis2.android.rtsm.ui.home.HomeViewModel
import org.dhis2.android.rtsm.ui.home.model.ButtonVisibilityState.ENABLED
import org.dhis2.android.rtsm.ui.home.screens.components.Backdrop
import org.dhis2.android.rtsm.ui.managestock.ManageStockViewModel
import org.dhis2.ui.buttons.FAButton
import org.dhis2.ui.buttons.FAButtonUiModel

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun HomeScreen(
activity: Activity,
Expand All @@ -50,23 +48,24 @@ fun HomeScreen(
scaffoldState = scaffoldState,
floatingActionButton = {
AnimatedVisibility(
visible = dataEntryUiState.button.visibility == ENABLED,
visible = dataEntryUiState.button.visible,
enter = fadeIn(),
exit = fadeOut()
) {
FAButton(
modifier = Modifier,
uiModel = FAButtonUiModel(
text = dataEntryUiState.button.text,
icon = dataEntryUiState.button.icon,
contentColor = themeColor,
containerColor = Color.White,
enabled = dataEntryUiState.button.visibility == ENABLED
)
) {
if (dataEntryUiState.button.visibility == ENABLED) {
proceedAction(scope, scaffoldState)
text = dataEntryUiState.button.text,
contentColor = dataEntryUiState.button.contentColor,
containerColor = dataEntryUiState.button.containerColor,
enabled = dataEntryUiState.button.visible,
icon = {
Icon(
painter = painterResource(id = dataEntryUiState.button.icon),
contentDescription = stringResource(dataEntryUiState.button.text),
tint = dataEntryUiState.button.contentColor
)
}
) {
proceedAction(scope, scaffoldState)
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dhis2.android.rtsm.ui.managestock

import androidx.compose.ui.graphics.Color
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
Expand Down Expand Up @@ -36,7 +37,6 @@ import org.dhis2.android.rtsm.services.scheduler.BaseSchedulerProvider
import org.dhis2.android.rtsm.ui.base.ItemWatcher
import org.dhis2.android.rtsm.ui.base.SpeechRecognitionAwareViewModel
import org.dhis2.android.rtsm.ui.home.model.ButtonUiState
import org.dhis2.android.rtsm.ui.home.model.ButtonVisibilityState
import org.dhis2.android.rtsm.ui.home.model.DataEntryStep
import org.dhis2.android.rtsm.ui.home.model.DataEntryUiState
import org.dhis2.android.rtsm.utils.Utils.Companion.isValidStockOnHand
Expand Down Expand Up @@ -89,6 +89,8 @@ class ManageStockViewModel @Inject constructor(
private val _dataEntryUiState = MutableStateFlow(DataEntryUiState())
val dataEntryUiState: StateFlow<DataEntryUiState> = _dataEntryUiState

private val _themeColor = MutableStateFlow(Color.White)

init {
configureRelays()
}
Expand Down Expand Up @@ -124,6 +126,10 @@ class ManageStockViewModel @Inject constructor(
_config.value = config
}

fun setThemeColor(themeColor: Color) {
_themeColor.value = themeColor
}

private fun loadStockItems() {
search.value = transaction.value?.facility?.uid?.let {
SearchParametersModel(
Expand Down Expand Up @@ -344,27 +350,29 @@ class ManageStockViewModel @Inject constructor(
private fun updateReviewButton() {
val button: ButtonUiState = when (dataEntryUiState.value.step) {
DataEntryStep.LISTING -> {
val buttonVisibility = if (!hasData.value) {
ButtonVisibilityState.HIDDEN
} else if (canReview()) {
ButtonVisibilityState.ENABLED
} else {
ButtonVisibilityState.DISABLED
}
ButtonUiState(visibility = buttonVisibility)
val buttonVisibility = hasData.value && canReview()
ButtonUiState(
text = R.string.review,
icon = R.drawable.proceed_icon,
contentColor = _themeColor.value,
containerColor = Color.White,
visible = buttonVisibility
)
}
DataEntryStep.EDITING -> {
ButtonUiState(visibility = ButtonVisibilityState.HIDDEN)
dataEntryUiState.value.button.copy(visible = false)
}
DataEntryStep.REVIEWING -> {
ButtonUiState(
text = R.string.confirm_transaction_label,
icon = R.drawable.search,
visibility = ButtonVisibilityState.ENABLED
icon = R.drawable.confirm_review,
contentColor = Color.White,
containerColor = _themeColor.value,
visible = true
)
}
DataEntryStep.COMPLETED -> {
ButtonUiState(visibility = ButtonVisibilityState.HIDDEN)
dataEntryUiState.value.button.copy(visible = false)
}
}

Expand Down
10 changes: 10 additions & 0 deletions stock-managment/src/main/res/drawable/confirm_check.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M24,44Q19.75,44 16.1,42.475Q12.45,40.95 9.75,38.25Q7.05,35.55 5.525,31.9Q4,28.25 4,24Q4,19.8 5.525,16.15Q7.05,12.5 9.75,9.8Q12.45,7.1 16.1,5.55Q19.75,4 24,4Q27.75,4 31,5.2Q34.25,6.4 36.85,8.5L34.7,10.65Q32.5,8.9 29.8,7.95Q27.1,7 24,7Q16.75,7 11.875,11.875Q7,16.75 7,24Q7,31.25 11.875,36.125Q16.75,41 24,41Q31.25,41 36.125,36.125Q41,31.25 41,24Q41,22.5 40.775,21.075Q40.55,19.65 40.1,18.3L42.4,16Q43.2,17.85 43.6,19.85Q44,21.85 44,24Q44,28.25 42.45,31.9Q40.9,35.55 38.2,38.25Q35.5,40.95 31.85,42.475Q28.2,44 24,44ZM21.05,33.1 L12.8,24.8 15.05,22.55 21.05,28.55 41.75,7.85 44.05,10.1Z"/>
</vector>
10 changes: 10 additions & 0 deletions stock-managment/src/main/res/drawable/confirm_review.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,22Q9.925,22 8.1,21.212Q6.275,20.425 4.925,19.075Q3.575,17.725 2.788,15.9Q2,14.075 2,12Q2,9.925 2.788,8.1Q3.575,6.275 4.925,4.925Q6.275,3.575 8.1,2.787Q9.925,2 12,2Q13.625,2 15.075,2.475Q16.525,2.95 17.75,3.8L16.3,5.275Q15.35,4.675 14.275,4.337Q13.2,4 12,4Q8.675,4 6.338,6.337Q4,8.675 4,12Q4,15.325 6.338,17.663Q8.675,20 12,20Q15.325,20 17.663,17.663Q20,15.325 20,12Q20,11.55 19.95,11.1Q19.9,10.65 19.8,10.225L21.425,8.6Q21.7,9.4 21.85,10.25Q22,11.1 22,12Q22,14.075 21.212,15.9Q20.425,17.725 19.075,19.075Q17.725,20.425 15.9,21.212Q14.075,22 12,22ZM10.6,16.6 L6.35,12.35 7.75,10.95 10.6,13.8 20.6,3.775 22,5.175Z"/>
</vector>
3 changes: 1 addition & 2 deletions stock-managment/src/main/res/drawable/proceed_icon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
android:viewportHeight="16">
<path
android:pathData="M20,3.535H11V5.535H20V3.535ZM20,11.535H11V13.535H20V11.535ZM3.54,7.535L0,3.995L1.41,2.585L3.53,4.705L7.77,0.465L9.18,1.875L3.54,7.535ZM3.54,15.535L0,11.995L1.41,10.585L3.53,12.705L7.77,8.465L9.18,9.875L3.54,15.535Z"
android:fillColor="#000000"
android:fillAlpha="0.38"/>
android:fillColor="#000000"/>
</vector>
43 changes: 24 additions & 19 deletions ui-components/src/main/java/org/dhis2/ui/buttons/FAButton.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dhis2.ui.buttons

import androidx.annotation.StringRes
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
Expand All @@ -13,23 +14,24 @@ import org.dhis2.ui.R

@Composable
fun FAButton(
modifier: Modifier,
uiModel: FAButtonUiModel,
modifier: Modifier = Modifier,
@StringRes text: Int,
contentColor: Color,
containerColor: Color,
expanded: Boolean = true,
enabled: Boolean = true,
icon: @Composable
() -> Unit,
onClick: () -> Unit
) {
ExtendedFloatingActionButton(
onClick = onClick,
modifier = modifier,
expanded = uiModel.expanded,
icon = {
Icon(
painter = painterResource(id = uiModel.icon),
contentDescription = stringResource(uiModel.text)
)
},
text = { Text(text = stringResource(uiModel.text)) },
contentColor = uiModel.contentColor,
containerColor = uiModel.containerColor
expanded = expanded,
icon = icon,
text = { Text(text = stringResource(text)) },
contentColor = contentColor,
containerColor = containerColor
)
}

Expand All @@ -38,13 +40,16 @@ fun FAButton(
fun ExtendedFAButtonPreview() {
FAButton(
modifier = Modifier,
uiModel = FAButtonUiModel(
text = R.string.button_extended,
icon = R.drawable.ic_home_positive,
contentColor = Color.DarkGray,
containerColor = Color.LightGray,
expanded = true
)
text = R.string.button_extended,
contentColor = Color.DarkGray,
containerColor = Color.LightGray,
expanded = true,
icon = {
Icon(
painter = painterResource(id = R.drawable.ic_home_positive),
contentDescription = null
)
}
) {
}
}

This file was deleted.

0 comments on commit f0d2840

Please sign in to comment.