Skip to content

Feature:auth to cmp #2360

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

Open
wants to merge 1 commit into
base: kmp-impl
Choose a base branch
from
Open
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"))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the testing one instead of commenting


add("commonMainImplementation", libs.findLibrary("koin.compose").get())
add("commonMainImplementation", libs.findLibrary("koin.compose.viewmodel").get())
Expand Down
26 changes: 20 additions & 6 deletions feature/auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,35 @@
* 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)
}

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

dependencies {
implementation(projects.core.data)
implementation(projects.core.domain)
kotlin {
sourceSets {

commonMain.dependencies {
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(compose.material3)
implementation(compose.foundation)
implementation(compose.ui)
implementation(libs.jb.kotlin.stdlib)
implementation(libs.kotlin.reflect)
implementation(projects.core.ui)
implementation(projects.core.common)
}
}
}

dependencies {
testImplementation(libs.hilt.android.testing)
testImplementation(projects.core.testing)
implementation(projects.core.data)
implementation(projects.core.domain)

androidTestImplementation(projects.core.testing)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
*/
package com.mifos.feature.auth.login

import androidclient.feature.auth.generated.resources.Res
import androidclient.feature.auth.generated.resources.feature_auth_enter_credentials
import androidclient.feature.auth.generated.resources.feature_auth_mifos_logo
import androidclient.feature.auth.generated.resources.feature_auth_password
import androidclient.feature.auth.generated.resources.feature_auth_username
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
Expand All @@ -23,11 +28,8 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowForward
import androidx.compose.material.icons.filled.Error
import androidx.compose.material.icons.filled.Lock
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.Visibility
import androidx.compose.material.icons.filled.VisibilityOff
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.CircularProgressIndicator
Expand All @@ -50,28 +52,27 @@ 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.graphics.Color
import androidx.compose.ui.graphics.Color.Companion.DarkGray
import androidx.compose.ui.graphics.Color.Companion.White
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import com.mifos.core.designsystem.component.MifosAndroidClientIcon
import com.mifos.core.designsystem.component.MifosOutlinedTextField
import com.mifos.feature.auth.R
import org.koin.androidx.compose.koinViewModel
import com.mifos.core.designsystem.icon.MifosIcons
import org.jetbrains.compose.resources.StringResource
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.ui.tooling.preview.Preview
import org.koin.compose.viewmodel.koinViewModel

/**
* Created by Aditya Gupta on 11/02/24.
Expand All @@ -86,7 +87,7 @@ internal fun LoginScreen(
loginViewModel: LoginViewModel = koinViewModel(),
) {
val state = loginViewModel.loginUiState.collectAsState().value
val context = LocalContext.current
// val context = LocalContext.current

val snackbarHostState = remember { SnackbarHostState() }

Expand All @@ -104,16 +105,16 @@ internal fun LoginScreen(
}
var passwordVisibility: Boolean by remember { mutableStateOf(false) }

val usernameError: MutableState<Int?> = remember { mutableStateOf(null) }
val passwordError: MutableState<Int?> = remember { mutableStateOf(null) }
val usernameError: MutableState<StringResource?> = remember { mutableStateOf(null) }
val passwordError: MutableState<StringResource?> = remember { mutableStateOf(null) }

when (state) {
is LoginUiState.Empty -> {}

is LoginUiState.ShowError -> {
showDialog.value = false
LaunchedEffect(key1 = state.message) {
snackbarHostState.showSnackbar(message = context.getString(state.message))
snackbarHostState.showSnackbar(message = state.message.toString())
}
}

Expand All @@ -122,8 +123,8 @@ internal fun LoginScreen(
}

is LoginUiState.ShowValidationError -> {
usernameError.value = state.usernameError
passwordError.value = state.passwordError
usernameError.value = Res.string.feature_auth_username
passwordError.value = Res.string.feature_auth_password
}

LoginUiState.HomeActivityIntent -> {
Expand All @@ -141,7 +142,7 @@ internal fun LoginScreen(
modifier = modifier
.fillMaxSize()
.padding(16.dp),
containerColor = Color.White,
containerColor = White,
snackbarHost = { SnackbarHost(snackbarHostState) },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have to remove all explicitly defined colours like how we didit in mifos mobile

bottomBar = {
Box(
Expand Down Expand Up @@ -179,13 +180,13 @@ internal fun LoginScreen(
) {
Spacer(modifier = Modifier.height(80.dp))

MifosAndroidClientIcon(imageVector = painterResource(R.drawable.feature_auth_mifos_logo))
MifosAndroidClientIcon(imageVector = painterResource(Res.drawable.feature_auth_mifos_logo))

Text(
modifier = Modifier
.fillMaxWidth()
.padding(top = 8.dp),
text = stringResource(id = R.string.feature_auth_enter_credentials),
text = stringResource(Res.string.feature_auth_enter_credentials),
textAlign = TextAlign.Center,
style = TextStyle(
fontSize = 16.sp,
Expand All @@ -203,11 +204,11 @@ internal fun LoginScreen(
userName = value
},
icon = Icons.Filled.Person,
label = stringResource(R.string.feature_auth_username),
label = stringResource(Res.string.feature_auth_username),
error = usernameError.value?.let { it1 -> stringResource(it1) },
trailingIcon = {
if (usernameError.value != null) {
Icon(imageVector = Icons.Filled.Error, contentDescription = null)
Icon(imageVector = MifosIcons.Error, contentDescription = null)
}
Copy link

@revanthkumarJ revanthkumarJ Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for content description give any valid string instead of null

},
)
Expand All @@ -221,20 +222,20 @@ internal fun LoginScreen(
},
visualTransformation = if (passwordVisibility) VisualTransformation.None else PasswordVisualTransformation(),
icon = Icons.Filled.Lock,
label = stringResource(R.string.feature_auth_password),
label = stringResource(Res.string.feature_auth_password),
error = passwordError.value?.let { it1 -> stringResource(it1) },
trailingIcon = {
if (passwordError.value == null) {
val image = if (passwordVisibility) {
Icons.Filled.Visibility
MifosIcons.Visibility
} else {
Icons.Filled.VisibilityOff
MifosIcons.VisibilityOff
}
IconButton(onClick = { passwordVisibility = !passwordVisibility }) {
Icon(imageVector = image, null)
}
} else {
Icon(imageVector = Icons.Filled.Error, contentDescription = null)
Icon(imageVector = MifosIcons.Error, contentDescription = null)
}
},
)
Expand Down Expand Up @@ -266,7 +267,18 @@ internal fun LoginScreen(
}
}

@Preview(showSystemUi = true, device = "id:pixel_7")
// @Composable
// fun Scaffold(
// modifier: Modifier,
// containerColor: Color,
// snackbarHost: () -> SnackbarHost,
// bottomBar: () -> Unit,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can i know what is it for?

// content: @Composable () -> Unit
// ) {
// TODO("Not yet implemented")
// }

@Preview
@Composable
private fun LoginScreenPreview() {
LoginScreen({}, {}, {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
package com.mifos.feature.auth.login

import org.jetbrains.compose.resources.StringResource

/**
* Created by Aditya Gupta on 06/08/23.
*/
Expand All @@ -19,7 +21,7 @@ sealed class LoginUiState {

data object ShowProgress : LoginUiState()

data class ShowError(val message: Int) : LoginUiState()
data class ShowError(val message: StringResource) : LoginUiState()

data class ShowValidationError(val usernameError: Int? = null, val passwordError: Int? = null) :
LoginUiState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
*/
package com.mifos.feature.auth.login

import android.util.Log
import androidclient.feature.auth.generated.resources.Res
import androidclient.feature.auth.generated.resources.feature_auth_error_login_failed
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mifos.core.common.model.user.User
import com.mifos.core.common.utils.Resource
import com.mifos.core.datastore.UserPreferencesRepository
import com.mifos.core.domain.useCases.LoginUseCase
import com.mifos.core.domain.useCases.PasswordValidationUseCase
import com.mifos.core.domain.useCases.UsernameValidationUseCase
import com.mifos.core.model.objects.users.User
import com.mifos.feature.auth.R
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
Expand Down Expand Up @@ -85,17 +85,17 @@ class LoginViewModel(
viewModelScope.launch(Dispatchers.IO) {
loginUseCase(username, password).collect { result ->
when (result) {
is Resource.Error -> {
is Resource.Error<*> -> {
_loginUiState.value =
LoginUiState.ShowError(R.string.feature_auth_error_login_failed)
LoginUiState.ShowError(Res.string.feature_auth_error_login_failed)
Log.e("@@@", "login: ${result.message}")
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have removed import android.util.Log but didn't used Logger like that didn't it showing any error at Log?


is Resource.Loading -> {
is Resource.Loading<*> -> {
_loginUiState.value = LoginUiState.ShowProgress
}

is Resource.Success -> {
is Resource.Success<*> -> {
result.data?.let {
if (it.userId != null && it.authenticated == true) {
onLoginSuccessful(it, username, password)
Expand Down