Skip to content

Commit

Permalink
Merge pull request #22 from omer358/dev
Browse files Browse the repository at this point in the history
fix #16
  • Loading branch information
omer358 authored Jun 25, 2024
2 parents 5973397 + 2af8ac6 commit 36f9225
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 57 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
.externalNativeBuild
.cxx
local.properties
app/google-services.json

# Built application files
*.apk
Expand Down
29 changes: 29 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "567382024079",
"project_id": "remember-me-bcd80",
"storage_bucket": "remember-me-bcd80.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:567382024079:android:797e9faec882ed07ec75fa",
"android_client_info": {
"package_name": "com.example.rememberme"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyBLLhJ9ymIEvsinNLYSr4lXdhO5mv0NMIE"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
4 changes: 3 additions & 1 deletion app/src/main/java/com/example/rememberme/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.example.rememberme.data.local.PeopleDatabase
import com.example.rememberme.domain.repository.PeopleRepository
import com.example.rememberme.domain.usecases.add_person.AddPersonUseCases
import com.example.rememberme.domain.usecases.add_person.ValidateFirstNameUseCase
import com.example.rememberme.domain.usecases.add_person.ValidateGenderSelectionUseCase
import com.example.rememberme.domain.usecases.add_person.ValidatePlaceUseCase
import com.example.rememberme.domain.usecases.add_person.ValidateSecondNameUseCase
import com.example.rememberme.domain.usecases.add_person.ValidateTimeUseCase
Expand Down Expand Up @@ -72,7 +73,8 @@ object AppModule {
validateFirstNameUseCase = ValidateFirstNameUseCase(),
validateSecondNameUseCase = ValidateSecondNameUseCase(),
validatePlaceUseCase = ValidatePlaceUseCase(),
validateTimeUseCase = ValidateTimeUseCase()
validateTimeUseCase = ValidateTimeUseCase(),
validateGenderSelectionUseCase = ValidateGenderSelectionUseCase()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ data class AddPersonUseCases(
val validateFirstNameUseCase: ValidateFirstNameUseCase,
val validateSecondNameUseCase: ValidateSecondNameUseCase,
val validatePlaceUseCase: ValidatePlaceUseCase,
val validateTimeUseCase: ValidateTimeUseCase
val validateTimeUseCase: ValidateTimeUseCase,
val validateGenderSelectionUseCase: ValidateGenderSelectionUseCase
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.rememberme.domain.usecases.add_person

import android.util.Log
import com.example.rememberme.domain.model.ValidationResult

class ValidateGenderSelectionUseCase {
operator fun invoke(gender: String): ValidationResult {
if (gender.isBlank()) {
Log.d(TAG, "invoke: gender is null")
return ValidationResult(successful = false, errorMessage = "please, Select the gender!")
} else {
Log.d(TAG, "invoke: gender is not null")
return ValidationResult(successful = true)
}
}

companion object {
private const val TAG = "ValidateGenderSelection"
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
@file:OptIn(ExperimentalMaterial3Api::class)
@file:OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3Api::class)

package com.example.rememberme.presentation.addperson

import android.app.DatePickerDialog
import android.app.TimePickerDialog
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.util.Log
import android.view.ContextThemeWrapper
import android.widget.DatePicker
import android.widget.TimePicker
import androidx.compose.foundation.Image
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -20,6 +22,8 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.Button
Expand Down Expand Up @@ -52,12 +56,14 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.example.rememberme.R
import com.example.rememberme.presentation.common.composables.CustomButton
import com.example.rememberme.presentation.common.composables.CustomErrorText
import com.example.rememberme.presentation.common.composables.CustomOutlinedTextField
import com.example.rememberme.ui.theme.RememberMeTheme
import kotlinx.coroutines.launch
import java.util.Calendar

@OptIn(ExperimentalMaterial3Api::class)
private const val TAG = "AddPersonScreen"
@Composable
fun AddPersonScreen(
viewModel: AddPersonViewModel = hiltViewModel(),
Expand Down Expand Up @@ -90,7 +96,7 @@ fun AddPersonScreen(
scope.launch { sheetState.show() }
},
selectedAvatarResId = selectedAvatarResId,
popUp = popUp
popUp = popUp,
)

if (showBottomSheet) {
Expand Down Expand Up @@ -121,7 +127,8 @@ fun AddPersonContent(
onSavePerson: () -> Unit,
onAvatarPickerClick: () -> Unit,
selectedAvatarResId: Int,
popUp: () -> Unit
popUp: () -> Unit,
scrollState: ScrollState = rememberScrollState()
) {
Scaffold(
topBar = {
Expand All @@ -143,6 +150,7 @@ fun AddPersonContent(
.fillMaxSize()
.padding(horizontal = 16.dp)
.padding(paddingValues)
.verticalScroll(scrollState)
) {
CustomOutlinedTextField(
value = uiState.firstName,
Expand Down Expand Up @@ -172,6 +180,7 @@ fun AddPersonContent(
)
GenderRadioButton(
selectedGender = uiState.gender,
errorMessage = uiState.genderError,
onGenderSelected = onGenderChange
)
Row(
Expand Down Expand Up @@ -323,8 +332,10 @@ fun AvatarPicker(
fun GenderRadioButton(
selectedGender: String,
onGenderSelected: (String) -> Unit,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
errorMessage: String?
) {
Log.d(TAG, "GenderRadioButton: $errorMessage")
val genderOptions = listOf("Male", "Female")
Column(modifier = modifier) {
Text("Gender", modifier = Modifier.padding(bottom = 4.dp))
Expand All @@ -344,6 +355,9 @@ fun GenderRadioButton(
}
}
}
if (errorMessage != null) {
CustomErrorText(errorText = errorMessage)
}
}
}

Expand All @@ -363,7 +377,7 @@ fun AddPersonContentPreview() {
onSavePerson = {},
onAvatarPickerClick = {},
selectedAvatarResId = R.drawable.ic_m1,
popUp = {}
popUp = {},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ data class AddPersonUiState(
val timeError: String? = null,
val note: String? = null,
val gender: String = "",
val genderError: String? = null,
val avatar: Int = R.drawable.ic_f1,
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ class AddPersonViewModel @Inject constructor(
when (event) {
is AddPersonEvents.OnFirstNameChange -> {
Log.i(TAG, "onEvent: OnFirstNameChange -> ${event.firstName}")
_uiState.value = _uiState.value.copy(firstName = event.firstName)
_uiState.value = _uiState.value.copy(firstName = event.firstName, firstNameError = null)
}

is AddPersonEvents.OnSecondNameChange -> {
Log.i(TAG, "onEvent: OnSecondNameChange -> ${event.secondName}")
_uiState.value = _uiState.value.copy(secondName = event.secondName)
_uiState.value = _uiState.value.copy(secondName = event.secondName, secondNameError = null)
}

is AddPersonEvents.OnPlaceChange -> {
Log.i(TAG, "onEvent: OnPlaceChange -> ${event.place}")
_uiState.value = _uiState.value.copy(place = event.place)
_uiState.value = _uiState.value.copy(place = event.place, placeError = null)
}

is AddPersonEvents.OnTimeChange -> {
Expand All @@ -54,7 +54,7 @@ class AddPersonViewModel @Inject constructor(

is AddPersonEvents.OnGenderChange -> {
Log.i(TAG, "onEvent: OnGenderChange -> ${event.gender}")
_uiState.value = _uiState.value.copy(gender = event.gender)
_uiState.value = _uiState.value.copy(gender = event.gender, genderError = null)
}

is AddPersonEvents.OnAvatarChange -> {
Expand All @@ -76,20 +76,24 @@ class AddPersonViewModel @Inject constructor(
addPersonUseCases.validateSecondNameUseCase(_uiState.value.secondName)
val placeResult = addPersonUseCases.validatePlaceUseCase(_uiState.value.place)
val timeResult = addPersonUseCases.validateTimeUseCase(_uiState.value.time)

val genderResult = addPersonUseCases.validateGenderSelectionUseCase(_uiState.value.gender)
Log.d(TAG, "savePerson: $genderResult")
val hasError = listOf(
firstNameResult,
secondNameResult,
placeResult,
timeResult,
genderResult
).any { !it.successful }
if (hasError) {
Log.e(TAG, "savePerson: There are some unvalidated inputs")
Log.e(TAG, "savePerson: ${_uiState.value}")
_uiState.value = _uiState.value.copy(
firstNameError = firstNameResult.errorMessage,
secondNameError = secondNameResult.errorMessage,
placeError = placeResult.errorMessage,
timeError = timeResult.errorMessage
timeError = timeResult.errorMessage,
genderError = genderResult.errorMessage
)
_isPersonSaved.value = false

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.rememberme.presentation.common.composables

import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun CustomErrorText(errorText: String){
Text(
text = errorText,
color = MaterialTheme.colorScheme.error,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.padding(start = 16.dp)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
Expand Down Expand Up @@ -46,12 +45,7 @@ fun CustomOutlinedTextField(
isError = isError,
)
if (isError && errorText != null) {
Text(
text = errorText,
color = MaterialTheme.colorScheme.error,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.padding(start = 16.dp)
)
CustomErrorText(errorText = errorText)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ import com.example.rememberme.R
import com.example.rememberme.data.FakeDataSource
import com.example.rememberme.domain.model.People
import com.example.rememberme.presentation.common.composables.PeopleListItem
import com.example.rememberme.presentation.peopleList.composable.EmptyStateScreen
import com.example.rememberme.ui.theme.RememberMeTheme

@Composable
fun PeopleScreen(
modifier: Modifier = Modifier,
viewModel: PeopleViewModel = hiltViewModel(),
navigateToDetailScreen: (Long) -> Unit,
navigateToAddNewPersonScreen:() -> Unit
navigateToAddNewPersonScreen: () -> Unit
) {
val people = viewModel.people.collectAsState(initial = emptyList())
PeopleScreenContent(people, modifier, navigateToDetailScreen, navigateToAddNewPersonScreen)
Expand Down Expand Up @@ -69,16 +70,20 @@ fun PeopleScreenContent(
}
}
) { it ->
LazyColumn(
modifier = modifier
.padding(it)
.fillMaxSize()
.testTag("PeopleListScreen")
) {
items(count = peopleState.value.size) { index ->
PeopleListItem(peopleState.value[index], { personId ->
navigateToDetailScreen(personId)
})
if (peopleState.value.isEmpty()) {
EmptyStateScreen(modifier = modifier.padding(paddingValues = it))
} else {
LazyColumn(
modifier = modifier
.padding(it)
.fillMaxSize()
.testTag("PeopleListScreen")
) {
items(count = peopleState.value.size) { index ->
PeopleListItem(peopleState.value[index], { personId ->
navigateToDetailScreen(personId)
})
}
}
}
}
Expand Down
Loading

0 comments on commit 36f9225

Please sign in to comment.