Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANDROAPP-5575-mobile-ui-Create-InputFileResource-component #94

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
a8db5bf
add:[ANDROAPP-5575] Component added, screen added
DavidAparicioAlbaAsenjo Oct 5, 2023
7c3d54b
add: [ANDROAPP-5575] onClicks added
DavidAparicioAlbaAsenjo Oct 5, 2023
2dfcf5a
update: [ANDROAPP-5575] primary and secondary button moved outside of…
DavidAparicioAlbaAsenjo Oct 5, 2023
1923f40
update: [ANDROAPP-5575] String added, fileName and fileWeight to Muta…
DavidAparicioAlbaAsenjo Oct 6, 2023
457c217
update: [ANDROAPP-5575] Code formatted
DavidAparicioAlbaAsenjo Oct 6, 2023
9301807
add: [ANDROAPP-5575] Tests added, component state can be managed exte…
DavidAparicioAlbaAsenjo Oct 10, 2023
bbfc12b
update: [ANDROAPP-5575] Supporting text added, modifier added, input …
DavidAparicioAlbaAsenjo Oct 10, 2023
a4f6db3
update: [ANDROAPP-5575] Code formatted
DavidAparicioAlbaAsenjo Oct 10, 2023
ab7e83e
update: [ANDROAPP-5575] Icon changed, disabled mode added, progress b…
DavidAparicioAlbaAsenjo Oct 13, 2023
d4f2aef
update: [ANDROAPP-5575] Code formatted
DavidAparicioAlbaAsenjo Oct 16, 2023
7a8cc6e
update: [ANDROAPP-5575] helper removed, Text added, using buttonblock…
DavidAparicioAlbaAsenjo Oct 17, 2023
37364aa
update: [ANDROAPP-5575] Tests fixed
DavidAparicioAlbaAsenjo Oct 17, 2023
438dd2a
update: [ANDROAPP-5575] Progress indicator spacing modified
DavidAparicioAlbaAsenjo Oct 18, 2023
5ef16f3
update: [ANDROAPP-5575] Modify color instead
DavidAparicioAlbaAsenjo Oct 18, 2023
4ecbdb0
update: [ANDROAPP-5575] code formatted
DavidAparicioAlbaAsenjo Oct 18, 2023
aad5921
update: [ANDROAPP-5575] code formatted after rebase
DavidAparicioAlbaAsenjo Oct 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.hisp.dhis.common.screens.InputCoordinateScreen
import org.hisp.dhis.common.screens.InputDateTimeScreen
import org.hisp.dhis.common.screens.InputDropDownScreen
import org.hisp.dhis.common.screens.InputEmailScreen
import org.hisp.dhis.common.screens.InputFileResourceScreen
import org.hisp.dhis.common.screens.InputIntegerScreen
import org.hisp.dhis.common.screens.InputLetterScreen
import org.hisp.dhis.common.screens.InputLinkScreen
Expand Down Expand Up @@ -87,7 +88,7 @@ fun App() {

@Composable
fun Main() {
val currentScreen = remember { mutableStateOf(Components.INPUT_BARCODE) }
val currentScreen = remember { mutableStateOf(Components.INPUT_FILE_RESOURCE) }
var expanded by remember { mutableStateOf(false) }

Column(
Expand Down Expand Up @@ -182,6 +183,7 @@ fun Main() {
Components.INPUT_POLYGON -> InputPolygonScreen()
Components.INPUT_ORG_UNIT -> InputOrgUnitScreen()
Components.IMAGE_BLOCK -> ImageBlockScreen()
Components.INPUT_FILE_RESOURCE -> InputFileResourceScreen()
Components.INPUT_DROPDOWN -> InputDropDownScreen()
Components.INPUT_DATE_TIME -> InputDateTimeScreen()
Components.INPUT_COORDINATE -> InputCoordinateScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ enum class Components(val label: String) {
INPUT_POLYGON("Input Polygon"),
INPUT_ORG_UNIT("Input Org. Unit"),
IMAGE_BLOCK("Image Block"),
INPUT_FILE_RESOURCE("Input File Resource"),
INPUT_DROPDOWN("Input Dropdown"),
INPUT_DATE_TIME("Input Date Time"),
INPUT_COORDINATE("Input Coordinate"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.hisp.dhis.common.screens

import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer
import org.hisp.dhis.mobile.ui.designsystem.component.InputFileResource
import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState
import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState
import org.hisp.dhis.mobile.ui.designsystem.resource.provideStringResource

@Composable
fun InputFileResourceScreen() {
ColumnComponentContainer(
title = "Input File Component",
) {
val currentFileName: MutableState<String?> =
mutableStateOf("filename.extension")
val currentFileWeight: MutableState<String?> =
mutableStateOf("524kb")
val currentFileName2: MutableState<String?> =
mutableStateOf("filename.extension")
val currentFileWeight2: MutableState<String?> =
mutableStateOf("524kb")

InputFileResource(
title = "Label",
buttonText = provideStringResource("add_file"),
fileName = currentFileName,
fileWeight = currentFileWeight,
onSelectFile = {
currentFileName.value = "file"
currentFileWeight.value = "weight"
},
onUploadFile = {},
)
InputFileResource(
title = "Label",
buttonText = provideStringResource("add_file"),
fileName = currentFileName,
fileWeight = currentFileWeight,
uploadFileState = UploadFileState.UPLOADING,
inputShellState = InputShellState.FOCUSED,
onSelectFile = {},
onUploadFile = {},
)
InputFileResource(
title = "Label",
buttonText = provideStringResource("add_file"),
fileName = currentFileName2,
fileWeight = currentFileWeight2,
uploadFileState = UploadFileState.LOADED,
onSelectFile = {},
onUploadFile = {},
)
InputFileResource(
title = "Label",
buttonText = provideStringResource("add_file"),
fileName = currentFileName,
fileWeight = currentFileWeight,
inputShellState = InputShellState.DISABLED,
onSelectFile = {
currentFileName.value = "file"
currentFileWeight.value = "weight"
},
onUploadFile = {},
)
InputFileResource(
title = "Label",
buttonText = provideStringResource("add_file"),
fileName = currentFileName,
fileWeight = currentFileWeight,
inputShellState = InputShellState.DISABLED,
uploadFileState = UploadFileState.LOADED,
onSelectFile = {
currentFileName.value = "file"
currentFileWeight.value = "weight"
},
onUploadFile = {},
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
package org.hisp.dhis.mobile.ui.designsystem.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Cancel
import androidx.compose.material.icons.outlined.FileDownload
import androidx.compose.material.icons.outlined.FileUpload
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.ADD
import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.LOADED
import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.UPLOADING
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing
import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor

const val INPUT_FILE_TEST_TAG = "INPUT_FILE_RESOURCE_"
const val CLEAR_BUTTON_TEST_TAG = "CLEAR_BUTTON"
const val UPLOAD_BUTTON_TEST_TAG = "UPLOAD_BUTTON"
const val ADD_BUTTON_TEST_TAG = "ADD_BUTTON"
const val PROGRESS_INDICATOR_TEST_TAG = "PROGRESS_INDICATOR"
const val UPLOAD_TEXT_FILE_NAME_TEST_TAG = "UPLOAD_TEXT_FILE_NAME"
const val UPLOAD_TEXT_FILE_WEIGHT_TEST_TAG = "UPLOAD_TEXT_FILE_WEIGHT"
const val SUPPORTING_TEXT_TEST_TAG = "SUPPORTING_TEXT"

@Composable
fun InputFileResource(
title: String,
buttonText: String,
fileName: MutableState<String?> = mutableStateOf(null),
fileWeight: MutableState<String?> = mutableStateOf(null),
onSelectFile: () -> Unit,
onUploadFile: () -> Unit,
onClear: () -> Unit = {},
uploadFileState: UploadFileState = ADD,
inputShellState: InputShellState = InputShellState.UNFOCUSED,
supportingText: List<SupportingTextData>? = null,
modifier: Modifier = Modifier,
) {
var currentState by remember {
mutableStateOf(uploadFileState)
}

val primaryButton: @Composable (() -> Unit)? = if (currentState == LOADED && inputShellState != InputShellState.DISABLED) {
{
IconButton(
modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + CLEAR_BUTTON_TEST_TAG),
icon = {
Icon(
imageVector = Icons.Outlined.Cancel,
contentDescription = "Icon Button",
)
},
onClick = {
currentState = ADD
onClear.invoke()
},
)
}
} else {
null
}

val secondaryButton: @Composable (() -> Unit)? =
if (currentState == LOADED) {
{
SquareIconButton(
modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + UPLOAD_BUTTON_TEST_TAG),
icon = {
Icon(
imageVector = Icons.Outlined.FileDownload,
contentDescription = "Download Icon Button",
)
},
) {
currentState = UPLOADING
onUploadFile.invoke()
}
}
} else {
null
}

InputShell(
title,
state = inputShellState,
supportingText = {
supportingText?.forEach { label ->
SupportingText(
label.text,
label.state,
modifier = modifier.testTag(INPUT_FILE_TEST_TAG + SUPPORTING_TEXT_TEST_TAG),
)
}
},
inputField = {
when (currentState) {
ADD -> {
ButtonBlock(
primaryButton = {
Button(
enabled = inputShellState != InputShellState.DISABLED,
modifier = Modifier
.testTag(INPUT_FILE_TEST_TAG + ADD_BUTTON_TEST_TAG)
.padding(end = Spacing.Spacing16)
.fillMaxWidth(),
style = ButtonStyle.KEYBOARDKEY,
text = buttonText,
icon = {
Icon(
imageVector = Icons.Outlined.FileUpload,
contentDescription = "Upload Icon Button",
)
},
) {
currentState = LOADED
onSelectFile.invoke()
}
},
)
}
UPLOADING -> {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center,
) {
Box(
Modifier
.padding(top = Spacing.Spacing8, bottom = Spacing.Spacing8)
.size(Spacing.Spacing48),
) {
ProgressIndicator(
modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + PROGRESS_INDICATOR_TEST_TAG),
type = ProgressIndicatorType.CIRCULAR,
)
}
}
}
LOADED -> {
Row(
verticalAlignment = Alignment.CenterVertically,
) {
fileName.value?.let {
Text(
text = it,
color = if (inputShellState != InputShellState.DISABLED) TextColor.OnSurface else TextColor.OnDisabledSurface,
maxLines = 1,
DavidAparicioAlbaAsenjo marked this conversation as resolved.
Show resolved Hide resolved
modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_NAME_TEST_TAG),
)
}
fileWeight.value?.let {
Text(
text = " $it",
color = TextColor.OnDisabledSurface,
maxLines = 1,
modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_WEIGHT_TEST_TAG),
)
}
}
}
}
},
primaryButton = primaryButton,
secondaryButton = secondaryButton,
modifier = modifier,
)
}

enum class UploadFileState {
ADD,
UPLOADING,
LOADED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<string name="show_fields">Show fields</string>
<string name="hide_fields">Hide fields</string>
<string name="action_next">Next</string>
<string name="add_file">Add file</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="enter_phone_number">Enter phone number</string>
Expand Down
Loading
Loading