Skip to content

Commit

Permalink
Androapp 4925 (#18)
Browse files Browse the repository at this point in the history
* Implement table structure for data entry

* Initialize ManageStockViewModel.kt to get data entry into table

* stock table label

* update

* loading ManageStockViewModel.kt for data entry

* building table for data entry

* updade

* Removing initialization by SavedStateHandle, removing init method to initialize data

* Resolving merge

* Resolving code style

* update

* update

* adding test dependency

* resolving tests

* update

* resolving code style

* resolving manage stock view model unit test

* initializing transaction

* update

* resolving code style

* removing stock management

* Insert table into main content

* moving table, methods and removing unnecessary vars

* fixing code style

* removing form dependency

* removing hardcoded appconfig

* removing commend and make proceed button go to review

* resolving code style

* Changing text color

* calling mdc theme as parent of the tree component

* moving mapTableModel to ManageStockViewModel.kt

* implementing mapTableModel to ManageStockViewModel.kt

* Removing mdctheme

* Resolving code style
  • Loading branch information
CarlosMacaneta authored and andresmr committed Feb 8, 2023
1 parent 3317b88 commit a1ca9f3
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 444 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":"2022-10-31 16:18","gitSha":"7207ba675"}
{"buildTime":"2022-11-04 14:26","gitSha":"23b3563f0"}
18 changes: 18 additions & 0 deletions commons/src/main/res/drawable/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="500"
android:viewportHeight="500">
<group android:translateX="150"
android:translateY="159">
<path
android:fillColor="#0080d4"
android:pathData="M191.73,60,109,6.34a19.73,19.73,0,0,0-20.32,0L8.31,58.43a12,12,0,0,0-0.25,20.63L88.6,134a19.37,19.37,0,0,0,20.37 0.25l82.76-53.65a11.88,11.88,0,0,0,0-20.59Zm-91,61.45a4.29,4.29,0,0,1-3.49-0.05l-77-52.49L97,19.13a4.76,4.76,0,0,1,3.74,0L179.6,70.28Z" />
<path
android:fillColor="#0080d4"
android:pathData="M88.66,47.82 L45.1,76.06l13.61,9.33L97,60.61a4.76,4.76 0,0 1,3.74 0l39.37,25.52 14,-9.06L109,47.82A19.76,19.76 0,0 0,88.66 47.82Z" />
<path
android:fillColor="#0080d4"
android:pathData="M191.73,101.46l-8.62,-5.59 -14.05,9.06 10.53,6.83 -78.91,51.15a4.37,4.37 0,0 1,-3.49 0l-77,-52.5 10,-6.47L16.55,94.57 8.31,99.91a12,12 0,0 0,-0.25 20.63L88.6,175.46a19.34,19.34 0,0 0,20.37 0.24l82.75,-53.65a11.88,11.88 0,0 0,0 -20.59Z" />
</group>
</vector>
4 changes: 2 additions & 2 deletions stock-managment/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ android {

dependencies {

implementation project(":form")
implementation project(":commons")
implementation project(":compose-table")

// DHIS2 Android SDK
// remove the no-op version of Flipper added by DHIS2 Android SDK to avoid duplicates
Expand Down Expand Up @@ -187,7 +187,7 @@ dependencies {

androidTestImplementation "androidx.test.ext:junit:$libraries.junit_ext"
androidTestImplementation "androidx.test.espresso:espresso-core:$libraries.espresso_core"

androidTestImplementation "androidx.arch.core:core-testing:$libraries.android_core_testing"

//Serialization library
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:${libraries.kotlinxserialization}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.res.colorResource
import androidx.core.content.ContextCompat.startActivity
import androidx.lifecycle.Observer
import androidx.work.WorkInfo
import com.google.android.material.composethemeadapter.MdcTheme
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
Expand All @@ -29,15 +28,18 @@ import org.dhis2.android.rtsm.commons.Constants.INTENT_EXTRA_APP_CONFIG
import org.dhis2.android.rtsm.data.AppConfig
import org.dhis2.android.rtsm.data.TransactionType
import org.dhis2.android.rtsm.ui.home.screens.HomeScreen
import org.dhis2.android.rtsm.ui.managestock.ManageStockActivity
import org.dhis2.android.rtsm.ui.managestock.ManageStockViewModel
import org.dhis2.android.rtsm.ui.reviewstock.ReviewStockActivity
import org.dhis2.android.rtsm.utils.NetworkUtils
import org.dhis2.commons.filters.FilterManager
import org.dhis2.commons.orgunitselector.OnOrgUnitSelectionFinished
import org.hisp.dhis.android.core.organisationunit.OrganisationUnit

@AndroidEntryPoint
class HomeActivity : AppCompatActivity(), OnOrgUnitSelectionFinished {

private val viewModel: HomeViewModel by viewModels()
private val manageStockViewModel: ManageStockViewModel by viewModels()
private var themeColor = R.color.colorPrimary
private lateinit var filterManager: FilterManager
private var orgUnitList = listOf<OrganisationUnit>()
Expand All @@ -46,23 +48,32 @@ class HomeActivity : AppCompatActivity(), OnOrgUnitSelectionFinished {
super.onCreate(savedInstanceState)

viewModel.orgUnitList.observe(
this,
Observer {
orgUnitList = it
}
)
this
) {
orgUnitList = it
}
filterManager = FilterManager.getInstance()
intent.getParcelableExtra<AppConfig>(INTENT_EXTRA_APP_CONFIG)
?.let { manageStockViewModel.setConfig(it) }

setContent {
Surface(
modifier = Modifier.fillMaxSize()
) {
updateTheme(viewModel.transactionType.collectAsState().value)
HomeScreen(
this, viewModel, Color(colorResource(themeColor).toArgb()),
supportFragmentManager, this@HomeActivity,
{ scope, scaffold -> navigateToManageStock(scope, scaffold) }
) { scope, scaffold -> synchronizeData(scope, scaffold) }
updateTheme(viewModel.transactionType.collectAsState().value)
MdcTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = Color(colorResource(themeColor).toArgb())
) {
HomeScreen(
this,
viewModel,
manageStockViewModel,
Color(colorResource(themeColor).toArgb()),
supportFragmentManager,
this@HomeActivity,
{ scope, scaffold -> navigateToReviewStock(scope, scaffold) },
{ scope, scaffold -> synchronizeData(scope, scaffold) }
)
}
}
}
}
Expand Down Expand Up @@ -152,7 +163,7 @@ class HomeActivity : AppCompatActivity(), OnOrgUnitSelectionFinished {
}
}

private fun navigateToManageStock(
private fun navigateToReviewStock(
scope: CoroutineScope,
scaffoldState: ScaffoldState
) {
Expand All @@ -165,11 +176,10 @@ class HomeActivity : AppCompatActivity(), OnOrgUnitSelectionFinished {
return
}
startActivity(
this.baseContext,
ManageStockActivity
.getManageStockActivityIntent(
ReviewStockActivity
.getReviewStockActivityIntent(
this.baseContext,
viewModel.getData(),
manageStockViewModel.getData(),
intent.getParcelableExtra(INTENT_EXTRA_APP_CONFIG)
).apply {
this.addFlags(FLAG_ACTIVITY_NEW_TASK)
Expand All @@ -180,7 +190,7 @@ class HomeActivity : AppCompatActivity(), OnOrgUnitSelectionFinished {

companion object {
@JvmStatic
fun getHomeActivityIntent(context: Context, config: AppConfig): Intent? {
fun getHomeActivityIntent(context: Context, config: AppConfig): Intent {
val intent = Intent(context, HomeActivity::class.java)
intent.putExtra(INTENT_EXTRA_APP_CONFIG, config)
return intent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import org.dhis2.android.rtsm.R
import org.dhis2.android.rtsm.ui.home.HomeActivity
import org.dhis2.android.rtsm.ui.home.HomeViewModel
import org.dhis2.android.rtsm.ui.home.screens.components.Backdrop
import org.dhis2.android.rtsm.ui.managestock.ManageStockViewModel

@Composable
fun HomeScreen(
activity: Activity,
viewModel: HomeViewModel = viewModel(),
manageStockViewModel: ManageStockViewModel = viewModel(),
themeColor: Color,
supportFragmentManager: FragmentManager,
homeContext: HomeActivity,
Expand Down Expand Up @@ -68,6 +70,7 @@ fun HomeScreen(
Backdrop(
activity,
viewModel,
manageStockViewModel,
themeColor,
supportFragmentManager,
homeContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.viewmodel.compose.viewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.dhis2.android.rtsm.data.TransactionType
import org.dhis2.android.rtsm.ui.home.HomeActivity
import org.dhis2.android.rtsm.ui.home.HomeViewModel
import org.dhis2.android.rtsm.ui.managestock.ManageStockViewModel

@SuppressLint("CoroutineCreationDuringComposition")
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun Backdrop(
activity: Activity,
viewModel: HomeViewModel = viewModel(),
viewModel: HomeViewModel,
manageStockViewModel: ManageStockViewModel,
themeColor: Color,
supportFragmentManager: FragmentManager,
homeContext: HomeActivity,
Expand Down Expand Up @@ -67,7 +68,7 @@ fun Backdrop(
},
backLayerBackgroundColor = themeColor,
backLayerContent = {
val height = FilterList(
val height = filterList(
viewModel,
themeColor,
supportFragmentManager,
Expand All @@ -81,7 +82,15 @@ fun Backdrop(
},
frontLayerElevation = 5.dp,
frontLayerContent = {
MainContent(backdropState, isFrontLayerDisabled, themeColor)
MainContent(
backdropState,
isFrontLayerDisabled,
themeColor,
viewModel,
manageStockViewModel,
hasFacilitySelected,
hasDestinationSelected
)
},
scaffoldState = backdropState,
gesturesEnabled = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fun DropdownComponent(
unfocusedBorderColor = Color.White
),
interactionSource = interactionSource,
textStyle = LocalTextStyle.current.copy(fontSize = 14.sp)
textStyle = LocalTextStyle.current.copy(fontSize = 14.sp, color = Color.Black)
)

MaterialTheme(shapes = MaterialTheme.shapes.copy(medium = RoundedCornerShape(16.dp))) {
Expand Down Expand Up @@ -283,7 +283,7 @@ fun DropdownComponentFacilities(
unfocusedBorderColor = Color.White
),
interactionSource = interactionSource,
textStyle = LocalTextStyle.current.copy(fontSize = 14.sp)
textStyle = LocalTextStyle.current.copy(fontSize = 14.sp, color = Color.Black)
)

MaterialTheme(shapes = MaterialTheme.shapes.copy(medium = RoundedCornerShape(16.dp))) {
Expand Down Expand Up @@ -413,7 +413,7 @@ fun DropdownComponentDistributedTo(
unfocusedBorderColor = Color.White
),
interactionSource = interactionSource,
textStyle = LocalTextStyle.current.copy(fontSize = 14.sp)
textStyle = LocalTextStyle.current.copy(fontSize = 14.sp, color = Color.Black)
)

MaterialTheme(shapes = MaterialTheme.shapes.copy(medium = RoundedCornerShape(16.dp))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.hisp.dhis.android.core.option.Option
import org.hisp.dhis.android.core.organisationunit.OrganisationUnit

@Composable
fun FilterList(
fun filterList(
viewModel: HomeViewModel,
themeColor: Color,
supportFragmentManager: FragmentManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Text
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -39,19 +40,26 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import kotlinx.coroutines.launch
import org.dhis2.android.rtsm.R
import org.dhis2.android.rtsm.data.TransactionType
import org.dhis2.android.rtsm.ui.home.HomeViewModel
import org.dhis2.android.rtsm.ui.managestock.ManageStockViewModel
import org.dhis2.android.rtsm.ui.managestock.components.ManageStockTable
import timber.log.Timber

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun MainContent(
backdropState: BackdropScaffoldState,
isFrontLayerDisabled: Boolean?,
themeColor: Color
themeColor: Color,
viewModel: HomeViewModel,
manageStockViewModel: ManageStockViewModel,
hasFacilitySelected: Boolean,
hasDestinationSelected: Boolean?
) {
val scope = rememberCoroutineScope()
val resource = painterResource(R.drawable.ic_arrow_up)
Expand Down Expand Up @@ -187,7 +195,24 @@ fun MainContent(
}

Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(text = "Table content", textAlign = TextAlign.Center)
if (viewModel.toolbarTitle.collectAsState().value.name
== TransactionType.DISTRIBUTION.name
) {
if (hasFacilitySelected && hasDestinationSelected == true) {
updateTableState(manageStockViewModel, viewModel)
ManageStockTable(manageStockViewModel)
}
} else if (hasFacilitySelected) {
updateTableState(manageStockViewModel, viewModel)
ManageStockTable(manageStockViewModel)
}
}
}
}

private fun updateTableState(
manageStockViewModel: ManageStockViewModel,
viewModel: HomeViewModel
) {
manageStockViewModel.setup(viewModel.getData())
}
Loading

0 comments on commit a1ca9f3

Please sign in to comment.