Skip to content

Commit

Permalink
resolves #6
Browse files Browse the repository at this point in the history
  • Loading branch information
omer358 committed Jun 22, 2024
1 parent eb2dafb commit 485caba
Show file tree
Hide file tree
Showing 17 changed files with 417 additions and 26 deletions.
8 changes: 4 additions & 4 deletions .idea/appInsightsSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
// 1, "John", secondName = "Doe", place = "", time = "", gender = "",avatar= R.drawable.ic_m3,),
// People(1, "John", secondName = "Doe", place = "", time = "", gender = "",avatar= R.drawable.ic_m3,)
// )
// peopleRepository.insertPeople(peopleList[0])
// peopleRepository.insertPeople(peopleList[1])
// peopleRepository.insertNewPerson(peopleList[0])
// peopleRepository.insertNewPerson(peopleList[1])
//
// // Act
// val result = peopleRepository.getAllPeople()
Expand All @@ -52,10 +52,10 @@
//// val person = People(1, "John", secondName = "Doe", place = "", time = "", gender = "",avatar= R.drawable.ic_m3,)
////
//// // Act
//// peopleRepository.insertPeople(person)
//// peopleRepository.insertNewPerson(person)
////
//// // Assert
//// Mockito.verify(peopleDao, Mockito.times(1)).insertPeople(person)
//// Mockito.verify(peopleDao, Mockito.times(1)).insertNewPerson(person)
//// }
////
//// @Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PeopleRepositoryImpl(
return peopleDao.getAllPeople()
}

override suspend fun insertPeople(people: People) {
override suspend fun insertNewPerson(people: People) {
peopleDao.insert(people)
}

Expand Down
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.people.GetAllPeople
import com.example.rememberme.domain.usecases.people.GetPersonById
import com.example.rememberme.domain.usecases.people.InsertNewPerson
import com.example.rememberme.domain.usecases.people.PeopleUseCases
import com.example.rememberme.utils.Constants.PEOPLE_DATABASE_NAME
import com.example.remindme.database.PeopleDao
Expand Down Expand Up @@ -54,7 +55,8 @@ object AppModule {
): PeopleUseCases {
return PeopleUseCases(
getAllPeople = GetAllPeople(peopleRepository),
getPersonById = GetPersonById(peopleRepository)
getPersonById = GetPersonById(peopleRepository),
insertPerson = InsertNewPerson(peopleRepository)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlinx.coroutines.flow.Flow

interface PeopleRepository {
fun getAllPeople(): Flow<List<People>>
suspend fun insertPeople(people: People)
suspend fun insertNewPerson(people: People)
suspend fun deletePeople(people: People)
suspend fun updatePeople(people: People)
suspend fun deleteAllPeople()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.rememberme.domain.usecases.people

import com.example.rememberme.domain.model.People
import com.example.rememberme.domain.repository.PeopleRepository

class InsertNewPerson(
private val peopleRepository: PeopleRepository
) {
suspend operator fun invoke(person: People) {
peopleRepository.insertNewPerson(person)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package com.example.rememberme.domain.usecases.people

data class PeopleUseCases(
val getAllPeople: GetAllPeople,
val getPersonById: GetPersonById
val getPersonById: GetPersonById,
val insertPerson: InsertNewPerson
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.rememberme.presentation.addperson
sealed class AddPersonEvents {
data class OnFirstNameChange(val firstName: String) : AddPersonEvents()
data class OnSecondNameChange(val secondName: String) : AddPersonEvents()
data class OnPlaceChange(val place: String) : AddPersonEvents()
data class OnTimeChange(val time: String) : AddPersonEvents()
data class OnNoteChange(val note: String?) : AddPersonEvents()
data class OnGenderChange(val gender: String) : AddPersonEvents()
data class OnAvatarChange(val avatar: String) : AddPersonEvents()
data object OnSavePerson : AddPersonEvents()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
@file:OptIn(ExperimentalMaterial3Api::class)

package com.example.rememberme.presentation.addperson

import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.example.rememberme.presentation.common.composables.CustomButton
import com.example.rememberme.presentation.common.composables.CustomOutlinedTextField
import com.example.rememberme.ui.theme.RememberMeTheme

@Composable
fun AddPersonScreen(
viewModel: AddPersonViewModel = hiltViewModel(),
popUp: () -> Unit,
) {
val uiState = viewModel.uiState.collectAsState().value

AddPersonContent(
uiState,
onFirstNameChange = { viewModel.onEvent(AddPersonEvents.OnFirstNameChange(it)) },
onSecondNameChange = { viewModel.onEvent(AddPersonEvents.OnSecondNameChange(it)) },
onPlaceChange = { viewModel.onEvent(AddPersonEvents.OnPlaceChange(it)) },
onTimeChange = { viewModel.onEvent(AddPersonEvents.OnTimeChange(it)) },
onNoteChange = { viewModel.onEvent(AddPersonEvents.OnNoteChange(it)) },
onGenderChange = { viewModel.onEvent(AddPersonEvents.OnGenderChange(it)) },
onAvatarChange = { viewModel.onEvent(AddPersonEvents.OnAvatarChange(it)) },
onSavePerson = { viewModel.onEvent(AddPersonEvents.OnSavePerson) },
popUp = popUp
)
}

@Composable
fun AddPersonContent(
uiState: AddPersonUiState,
onFirstNameChange: (String) -> Unit,
onSecondNameChange: (String) -> Unit,
onPlaceChange: (String) -> Unit,
onTimeChange: (String) -> Unit,
onNoteChange: (String) -> Unit,
onGenderChange: (String) -> Unit,
onAvatarChange: (String) -> Unit,
onSavePerson: () -> Unit,
popUp: () -> Unit
) {
Scaffold(
topBar = {
TopAppBar(
title = {
Text(text = "Add Person")
},
navigationIcon = {
IconButton(onClick = { popUp() }) {
Icon(imageVector = Icons.AutoMirrored.Default.ArrowBack, contentDescription = null)
}
}
)
}
) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 8.dp)
.padding(paddingValues = it)
) {
CustomOutlinedTextField(
value = uiState.firstName,
onValueChange = onFirstNameChange,
label = "First Name"
)
CustomOutlinedTextField(
value = uiState.secondName,
onValueChange = onSecondNameChange,
label = "Second Name"
)
CustomOutlinedTextField(
value = uiState.place,
onValueChange = onPlaceChange,
label = "Meeting Place"
)
CustomOutlinedTextField(
value = uiState.time,
onValueChange = onTimeChange,
label = "Meeting Time"
)
GenderRadioButton(
selectedGender = uiState.gender,
onGenderSelected = onGenderChange
)
CustomOutlinedTextField(
value = uiState.avatar.toString(),
onValueChange = onAvatarChange,
label = "Avatar"
)
CustomOutlinedTextField(
value = uiState.note ?: "",
onValueChange = onNoteChange,
label = "Note"
)
CustomButton(
onClick = onSavePerson,
text = "Save"
)
}
}
}


@Composable
fun GenderRadioButton(
selectedGender: String,
onGenderSelected: (String) -> Unit,
modifier: Modifier = Modifier
) {
val genderOptions = listOf("Male", "Female")
Column(modifier = modifier) {
Text("Gender", modifier = Modifier.padding(bottom = 4.dp))
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier.fillMaxWidth()
){
genderOptions.forEach { gender ->
Row(
verticalAlignment = Alignment.CenterVertically,
) {
RadioButton(
selected = (gender == selectedGender),
onClick = { onGenderSelected(gender) }
)
Text(text = gender, modifier = Modifier.padding(start = 4.dp))
}
}
}
}
}

@Preview(showBackground = true)
@Preview(uiMode = UI_MODE_NIGHT_YES)
@Composable
fun AddPersonContentPreview() {
RememberMeTheme {
AddPersonContent(
uiState = AddPersonUiState(),
onFirstNameChange = {},
onSecondNameChange = {},
onPlaceChange = {},
onTimeChange = {},
onNoteChange = {},
onGenderChange = {},
onAvatarChange = {},
onSavePerson = {},
popUp = {}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.rememberme.presentation.addperson

data class AddPersonUiState(
val firstName: String = "",
val secondName: String = "",
val place: String = "",
val time: String = "",
val note: String? = null,
val gender: String = "",
val avatar: String = ""
)
Loading

0 comments on commit 485caba

Please sign in to comment.