Skip to content

draft - CMP migration of feature/groups #2369

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

Draft
wants to merge 1 commit into
base: kmp-impl
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class CMPFeatureConventionPlugin : Plugin<Project> {
dependencies {
add("commonMainImplementation", project(":core:ui"))
add("commonMainImplementation", project(":core:designsystem"))
add("commonMainImplementation", project(":core:testing"))
add("commonMainImplementation", project(":core:data"))
// add("commonMainImplementation", project(":core:testing"))
// add("commonMainImplementation", project(":core:data"))

add("commonMainImplementation", libs.findLibrary("koin.compose").get())
add("commonMainImplementation", libs.findLibrary("koin.compose.viewmodel").get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ fun MifosTextFieldDropdown(
modifier: Modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp),
label: Int? = null,
labelString: String? = null,
readOnly: Boolean = false,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ import androidx.compose.material.icons.outlined.DateRange
import androidx.compose.material.icons.outlined.EventRepeat
import androidx.compose.material.icons.outlined.Group
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.outlined.HomeWork
import androidx.compose.material.icons.outlined.Mail
import androidx.compose.material.icons.outlined.Numbers
import androidx.compose.material.icons.outlined.PersonOutline
import androidx.compose.material.icons.outlined.Visibility
import androidx.compose.material.icons.outlined.VisibilityOff
import androidx.compose.material.icons.outlined.Wallet
Expand Down Expand Up @@ -152,5 +155,8 @@ object MifosIcons {
val FlashOff = Icons.Default.FlashOff
val Error2 = Icons.Filled.Error
val Notifications = Icons.Filled.Notifications
val Numbers = Icons.Outlined.Numbers
val Homework = Icons.Outlined.HomeWork
val PersonOutline = Icons.Outlined.PersonOutline
val NavigationDrawer = Icons.Default.Menu
}
65 changes: 41 additions & 24 deletions feature/groups/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,51 @@
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifos.android.feature)
alias(libs.plugins.mifos.android.library.compose)
alias(libs.plugins.mifos.android.library.jacoco)
}
alias(libs.plugins.mifos.cmp.feature)
alias(libs.plugins.mifos.kmp.koin)

// alias(libs.plugins.mifos.android.library.compose)
// alias(libs.plugins.mifos.android.library.jacoco)
}

android {
namespace = "com.mifos.feature.groups"
}

dependencies {
implementation(projects.core.domain)

// swipe refresh
implementation(libs.accompanist.swiperefresh)

// paging 3
implementation(libs.androidx.paging.runtime.ktx)
implementation(libs.androidx.paging.compose)

//DBFlow dependencies
implementation(libs.dbflow)

androidTestImplementation(libs.androidx.compose.ui.test)
debugApi(libs.androidx.compose.ui.test.manifest)

testImplementation(libs.hilt.android.testing)
testImplementation(projects.core.testing)
kotlin{
sourceSets{
commonMain.dependencies {
// implementation(projects.core.domain)
implementation(compose.material3)
implementation(compose.components.resources)
implementation(compose.ui)
implementation(projects.core.model)
// implementation(projects.core.data)
implementation(projects.core.database)
implementation(projects.core.designsystem)

}
}
}

androidTestImplementation(projects.core.testing)
}
//dependencies {
// implementation(projects.core.domain)
//
// // swipe refresh
// implementation(libs.accompanist.swiperefresh)
//
// // paging 3
// implementation(libs.androidx.paging.runtime.ktx)
// implementation(libs.androidx.paging.compose)
//
// //DBFlow dependencies
// implementation(libs.dbflow)
//
// androidTestImplementation(libs.androidx.compose.ui.test)
// debugApi(libs.androidx.compose.ui.test.manifest)
//
// testImplementation(libs.hilt.android.testing)
// testImplementation(projects.core.testing)
//
// androidTestImplementation(projects.core.testing)
//}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
*/
package com.mifos.feature.groups.createNewGroup

import android.content.Context
import android.widget.Toast

import androidclient.feature.groups.generated.resources.Res
import androidclient.feature.groups.generated.resources.feature_groups_activation_date
import androidclient.feature.groups.generated.resources.feature_groups_active
import androidclient.feature.groups.generated.resources.feature_groups_create_new_group
import androidclient.feature.groups.generated.resources.feature_groups_dismiss
import androidclient.feature.groups.generated.resources.feature_groups_external_id
import androidclient.feature.groups.generated.resources.feature_groups_groups
import androidclient.feature.groups.generated.resources.feature_groups_name
import androidclient.feature.groups.generated.resources.feature_groups_office_name_mandatory
import androidclient.feature.groups.generated.resources.feature_groups_select_date
import androidclient.feature.groups.generated.resources.feature_groups_submit
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
Expand Down Expand Up @@ -50,12 +60,8 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.text.intl.Locale
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.mifos.core.designsystem.component.MifosCircularProgress
Expand All @@ -65,12 +71,10 @@ import com.mifos.core.designsystem.component.MifosScaffold
import com.mifos.core.designsystem.component.MifosSweetError
import com.mifos.core.designsystem.component.MifosTextFieldDropdown
import com.mifos.core.model.objects.responses.SaveResponse
import com.mifos.feature.groups.R
import com.mifos.room.entities.group.GroupPayloadEntity
import com.mifos.room.entities.organisation.OfficeEntity
import org.koin.androidx.compose.koinViewModel
import java.text.SimpleDateFormat
import java.util.Locale
import org.jetbrains.compose.resources.stringResource
import org.koin.compose.viewmodel.koinViewModel

/**
* Created by Pronay Sarker on 30/06/2024 (7:53 AM)
Expand Down Expand Up @@ -113,7 +117,7 @@ internal fun CreateNewGroupScreen(

MifosScaffold(
modifier = modifier,
title = stringResource(id = R.string.feature_groups_create_new_group),
title = stringResource(Res.string.feature_groups_create_new_group),
onBackPressed = {},
snackbarHostState = snackbarHostState,
) { paddingValues ->
Expand All @@ -125,7 +129,7 @@ internal fun CreateNewGroupScreen(
when (uiState) {
is CreateNewGroupUiState.ShowFetchingError -> {
MifosSweetError(
message = uiState.message,
message = stringResource(uiState.message),
onclick = { onRetry.invoke() },
)
}
Expand Down Expand Up @@ -181,6 +185,7 @@ private fun CreateNewGroupContent(
val density = LocalDensity.current
val scrollState = rememberScrollState()
var officeId by rememberSaveable { mutableIntStateOf(0) }
//todo
var activationDate by rememberSaveable { mutableLongStateOf(System.currentTimeMillis()) }
var submittedOnDate by rememberSaveable { mutableLongStateOf(System.currentTimeMillis()) }

Expand Down Expand Up @@ -222,15 +227,15 @@ private fun CreateNewGroupContent(
submitDatePicker = false
activationDatePicker = false
},
) { Text(stringResource(id = R.string.feature_groups_select_date)) }
) { Text(stringResource(androidclient.feature.groups.generated.resources.Res.string.feature_groups_select_date)) }
},
dismissButton = {
TextButton(
onClick = {
activationDatePicker = false
submitDatePicker = false
},
) { Text(stringResource(id = R.string.feature_groups_dismiss)) }
) { Text(stringResource(Res.string.feature_groups_dismiss)) }
},
) {
DatePicker(state = if (submitDatePicker) sumittedDatePickerState else activateDatePickerState)
Expand All @@ -247,7 +252,7 @@ private fun CreateNewGroupContent(
MifosOutlinedTextField(
value = groupName,
onValueChange = { groupName = it },
label = stringResource(id = R.string.feature_groups_name),
label = stringResource(Res.string.feature_groups_name),
error = null,
)

Expand All @@ -264,13 +269,14 @@ private fun CreateNewGroupContent(
officeId = it
}
},
label = R.string.feature_groups_office_name_mandatory,
labelString = stringResource(Res.string.feature_groups_office_name_mandatory),
options = officeList.map { it.name.toString() },
readOnly = true,
)

Spacer(modifier = Modifier.height(16.dp))

//todo use kotlin
MifosDatePickerTextField(
value = SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()).format(
submittedOnDate,
Expand All @@ -286,7 +292,7 @@ private fun CreateNewGroupContent(
MifosOutlinedTextField(
value = externalId,
onValueChange = { externalId = it },
label = stringResource(id = R.string.feature_groups_external_id),
label = stringResource(Res.string.feature_groups_external_id),
error = null,
)

Expand All @@ -303,7 +309,7 @@ private fun CreateNewGroupContent(
checked = isActive,
onCheckedChange = { isActive = !isActive },
)
Text(text = stringResource(id = R.string.feature_groups_active))
Text(text = stringResource(Res.string.feature_groups_active))
}

AnimatedVisibility(
Expand All @@ -323,7 +329,8 @@ private fun CreateNewGroupContent(
value = SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()).format(
activationDate,
),
label = stringResource(R.string.feature_groups_activation_date),

label = stringResource(Res.string.feature_groups_activation_date),
openDatePicker = {
activationDatePicker = true
},
Expand Down Expand Up @@ -384,11 +391,11 @@ private fun CreateNewGroupContent(
// }
},
) {
Text(text = stringResource(id = R.string.feature_groups_submit))
Text(text = stringResource(Res.string.feature_groups_submit))
}
}
}

// todo move into viewmodels
private fun validateFields(groupName: String, officeName: String, context: Context): Boolean {
return when {
groupName.isEmpty() -> {
Expand Down Expand Up @@ -431,27 +438,27 @@ private fun validateFields(groupName: String, officeName: String, context: Conte
}
}

private class CreateNewGroupScreenPreviewProvider : PreviewParameterProvider<CreateNewGroupUiState> {
override val values: Sequence<CreateNewGroupUiState>
get() = sequenceOf(
CreateNewGroupUiState.ShowProgressbar,
CreateNewGroupUiState.ShowOffices(listOf()),
CreateNewGroupUiState.ShowFetchingError("Failed to fetch Offices"),
CreateNewGroupUiState.ShowGroupCreatedSuccessfully(saveResponse = SaveResponse()),
)
}

@Composable
@Preview(showSystemUi = true)
private fun PreviewCreateNewGroupScreen(
@PreviewParameter(CreateNewGroupScreenPreviewProvider::class) createNewGroupUiState: CreateNewGroupUiState,
) {
CreateNewGroupScreen(
uiState = createNewGroupUiState,
onRetry = {},
invokeGroupCreation = {},
onGroupCreated = { _ ->
},
getResponse = { "" },
)
}
//private class CreateNewGroupScreenPreviewProvider : PreviewParameterProvider<CreateNewGroupUiState> {
// override val values: Sequence<CreateNewGroupUiState>
// get() = sequenceOf(
// CreateNewGroupUiState.ShowProgressbar,
// CreateNewGroupUiState.ShowOffices(listOf()),
// CreateNewGroupUiState.ShowFetchingError("Failed to fetch Offices"),
// CreateNewGroupUiState.ShowGroupCreatedSuccessfully(saveResponse = SaveResponse()),
// )
//}
//
//@Composable
//@Preview(showSystemUi = true)
//private fun PreviewCreateNewGroupScreen(
// @PreviewParameter(CreateNewGroupScreenPreviewProvider::class) createNewGroupUiState: CreateNewGroupUiState,
//) {
// CreateNewGroupScreen(
// uiState = createNewGroupUiState,
// onRetry = {},
// invokeGroupCreation = {},
// onGroupCreated = { _ ->
// },
// getResponse = { "" },
// )
//}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package com.mifos.feature.groups.createNewGroup

import com.mifos.core.model.objects.responses.SaveResponse
import com.mifos.room.entities.organisation.OfficeEntity
import org.jetbrains.compose.resources.StringResource

/**
* Created by Aditya Gupta on 10/08/23.
Expand All @@ -19,7 +20,7 @@ sealed class CreateNewGroupUiState {

data object ShowProgressbar : CreateNewGroupUiState()

data class ShowFetchingError(val message: String) : CreateNewGroupUiState()
data class ShowFetchingError(val message: StringResource) : CreateNewGroupUiState()

data class ShowOffices(val offices: List<OfficeEntity>) : CreateNewGroupUiState()

Expand Down
Loading
Loading