-
Notifications
You must be signed in to change notification settings - Fork 4
create location screen #44
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
composeApp/src/commonMain/kotlin/org/example/project/data/dto/DistrictDto.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.example.project.data.dto | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class DistrictDto( | ||
| @SerialName("id") val id: String, | ||
| @SerialName("name") val name: String, | ||
| @SerialName("governorateId") val governorateId: String | ||
| ) | ||
10 changes: 10 additions & 0 deletions
10
composeApp/src/commonMain/kotlin/org/example/project/data/dto/GovernoratesDto.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package org.example.project.data.dto | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class GovernoratesDto( | ||
| @SerialName("id") val id: String, | ||
| @SerialName("name") val name: String | ||
| ) |
32 changes: 32 additions & 0 deletions
32
...seApp/src/commonMain/kotlin/org/example/project/data/repository/LocationRepositoryImpl.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package org.example.project.data.repository | ||
|
|
||
| import io.ktor.client.HttpClient | ||
| import io.ktor.client.request.get | ||
| import io.ktor.client.call.body | ||
| import org.example.project.data.dto.DistrictDto | ||
| import org.example.project.data.dto.GovernoratesDto | ||
| import org.example.project.data.repository.mapper.toDistrict | ||
| import org.example.project.data.repository.mapper.toGovernorates | ||
| import org.example.project.data.utils.NetworkConstants.DISTRICT_ENDPOINT | ||
| import org.example.project.data.utils.NetworkConstants.GOVERNORATES_ENDPOINT | ||
| import org.example.project.data.utils.NetworkConstants.LOCATION_PATH | ||
| import org.example.project.domain.entity.District | ||
| import org.example.project.domain.entity.Governorates | ||
| import org.example.project.domain.repository.LocationRepository | ||
|
|
||
| class LocationRepositoryImpl( | ||
| private val httpClient: HttpClient | ||
| ) : LocationRepository { | ||
|
|
||
| override suspend fun getAllGovernorates(): List<Governorates> { | ||
| val response = httpClient.get("/$LOCATION_PATH/$GOVERNORATES_ENDPOINT") | ||
| val body: List<GovernoratesDto> = response.body() | ||
| return body.toGovernorates() | ||
| } | ||
|
|
||
| override suspend fun getDistrictsByGovernorateId(governorateId: String): List<District> { | ||
| val response = httpClient.get("/$LOCATION_PATH/$DISTRICT_ENDPOINT/$governorateId") | ||
| val body: List<DistrictDto> = response.body() | ||
| return body.toDistrict() | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
composeApp/src/commonMain/kotlin/org/example/project/data/repository/mapper/District.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.example.project.data.repository.mapper | ||
|
|
||
| import org.example.project.data.dto.DistrictDto | ||
| import org.example.project.domain.entity.District | ||
|
|
||
| fun List<DistrictDto>.toDistrict(): List<District> { | ||
| return map { dto -> | ||
| District( | ||
| id = dto.id, | ||
| name = dto.name, | ||
| governorateId = dto.governorateId | ||
| ) | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
composeApp/src/commonMain/kotlin/org/example/project/data/repository/mapper/Gavernorate.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package org.example.project.data.repository.mapper | ||
|
|
||
| import org.example.project.data.dto.GovernoratesDto | ||
| import org.example.project.domain.entity.Governorates | ||
|
|
||
| fun List<GovernoratesDto>.toGovernorates(): List<Governorates> { | ||
| return map { dto -> | ||
| Governorates( | ||
| id = dto.id, | ||
| name = dto.name | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 8 additions & 5 deletions
13
composeApp/src/commonMain/kotlin/org/example/project/di/CraftoModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| package org.example.project.di | ||
|
|
||
| import org.koin.core.annotation.ComponentScan | ||
| import org.example.project.data.repository.LocationRepositoryImpl | ||
| import org.example.project.domain.repository.LocationRepository | ||
| import org.koin.core.annotation.Module | ||
| import org.koin.dsl.module | ||
|
|
||
| @Module | ||
| @ComponentScan("org.example.project") | ||
| class CraftoModule | ||
| class CraftoModule { | ||
| val module = module { | ||
| single<LocationRepository> { LocationRepositoryImpl(get()) } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
composeApp/src/commonMain/kotlin/org/example/project/di/ViewModelModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.example.project.di | ||
|
|
||
| import org.example.project.presentation.screens.setupScreens.location.LocationViewModel | ||
| import org.koin.core.module.dsl.viewModel | ||
| import org.koin.dsl.module | ||
|
|
||
| class ViewModelModule { | ||
| val module = module { | ||
| viewModel { LocationViewModel(get()) } | ||
| } | ||
| } |
10 changes: 7 additions & 3 deletions
10
composeApp/src/commonMain/kotlin/org/example/project/di/initKoin.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,16 @@ | ||
| package org.example.project.di | ||
|
|
||
| import org.example.project.di.NetworkModule | ||
| import org.example.project.di.ViewModelModule | ||
| import org.koin.core.context.startKoin | ||
| import org.koin.dsl.KoinAppDeclaration | ||
| import org.koin.ksp.generated.module | ||
|
|
||
| fun initKoin(config: KoinAppDeclaration? = null) { | ||
| startKoin { | ||
| config?.invoke(this) | ||
| modules(CraftoModule().module, NetworkModule().module) | ||
| modules( | ||
| CraftoModule().module, | ||
| ViewModelModule().module, | ||
| NetworkModule().module | ||
| ) | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
composeApp/src/commonMain/kotlin/org/example/project/domain/entity/District.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package org.example.project.domain.entity | ||
|
|
||
| data class District( | ||
| val id: String, | ||
| val name: String, | ||
| val governorateId: String | ||
norhanadel367 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
6 changes: 6 additions & 0 deletions
6
composeApp/src/commonMain/kotlin/org/example/project/domain/entity/Governorates.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package org.example.project.domain.entity | ||
|
|
||
| data class Governorates( | ||
| val id: String, | ||
| val name: String | ||
| ) |
9 changes: 9 additions & 0 deletions
9
composeApp/src/commonMain/kotlin/org/example/project/domain/repository/LocationRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package org.example.project.domain.repository | ||
|
|
||
| import org.example.project.domain.entity.District | ||
| import org.example.project.domain.entity.Governorates | ||
|
|
||
| interface LocationRepository { | ||
| suspend fun getAllGovernorates(): List<Governorates> | ||
| suspend fun getDistrictsByGovernorateId(governorateId: String): List<District> | ||
| } |
23 changes: 23 additions & 0 deletions
23
.../src/commonMain/kotlin/org/example/project/presentation/components/DetailLocationInput.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package org.example.project.presentation.components | ||
|
|
||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import org.example.project.presentation.designsystem.components.TextField | ||
| import org.jetbrains.compose.resources.stringResource | ||
| import crafto.composeapp.generated.resources.Res | ||
| import crafto.composeapp.generated.resources.enter_detailed_location | ||
|
|
||
| @Composable | ||
| fun DetailLocationInput( | ||
| text: String, | ||
| onTextChange: (String) -> Unit, | ||
| modifier: Modifier = Modifier | ||
| ) { | ||
| TextField( | ||
| hint = stringResource(Res.string.enter_detailed_location), | ||
| text = text, | ||
| onTextChange = onTextChange, | ||
| modifier = modifier.fillMaxWidth() | ||
| ) | ||
| } |
57 changes: 57 additions & 0 deletions
57
.../src/commonMain/kotlin/org/example/project/presentation/components/DropdownBottomSheet.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package org.example.project.presentation.components | ||
|
|
||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.layout.* | ||
| import androidx.compose.foundation.lazy.LazyColumn | ||
| import androidx.compose.foundation.lazy.items | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.unit.dp | ||
| import org.example.project.presentation.designsystem.components.BottomSheet | ||
| import org.example.project.presentation.designsystem.textstyle.AppTheme | ||
| import org.jetbrains.compose.resources.painterResource | ||
| import org.jetbrains.compose.resources.stringResource | ||
| import crafto.composeapp.generated.resources.Res | ||
| import crafto.composeapp.generated.resources.alt_arrow_down | ||
| import crafto.composeapp.generated.resources.down_arrow | ||
|
|
||
| @Composable | ||
| fun <T> DropdownBottomSheet( | ||
| show: Boolean, | ||
| items: List<T>, | ||
| itemLabel: (T) -> String, | ||
| onDismiss: () -> Unit, | ||
| onSelect: (T) -> Unit | ||
| ) { | ||
| if (show && items.isNotEmpty()) { | ||
| BottomSheet(onDismissRequest = onDismiss) { | ||
| LazyColumn { | ||
| items(items) { item -> | ||
| Row( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .clickable { onSelect(item) } | ||
| .padding(16.dp), | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| horizontalArrangement = Arrangement.spacedBy(8.dp) | ||
| ) { | ||
| Text( | ||
| text = itemLabel(item), | ||
| style = AppTheme.textStyle.body.medium, | ||
| color = AppTheme.craftoColors.shade.primary, | ||
| modifier = Modifier.weight(1f) | ||
| ) | ||
| Icon( | ||
| painter = painterResource(Res.drawable.alt_arrow_down), | ||
| contentDescription = stringResource(Res.string.down_arrow), | ||
| tint = AppTheme.craftoColors.shade.secondary | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
74 changes: 74 additions & 0 deletions
74
...App/src/commonMain/kotlin/org/example/project/presentation/components/DropdownSelector.kt
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the file name is Location, but it has GovernorateSelector and DetailLocationInput, I don't get the idea of the file, if you use them as reusable components for the location screen, you can have them in 2 different files, of have a meaningful file name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package org.example.project.presentation.components | ||
|
|
||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.interaction.MutableInteractionSource | ||
| import androidx.compose.foundation.layout.* | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.semantics.Role | ||
| import androidx.compose.ui.semantics.role | ||
| import androidx.compose.ui.semantics.semantics | ||
| import androidx.compose.ui.unit.dp | ||
| import org.example.project.presentation.designsystem.components.TextField | ||
| import org.example.project.presentation.designsystem.textstyle.AppTheme | ||
| import org.jetbrains.compose.resources.DrawableResource | ||
| import org.jetbrains.compose.resources.painterResource | ||
| import org.jetbrains.compose.resources.stringResource | ||
| import crafto.composeapp.generated.resources.* | ||
|
|
||
| @Composable | ||
| fun DropdownSelector( | ||
| text: String, | ||
| hint: String, | ||
| icon: DrawableResource, | ||
| hasSelection: Boolean, | ||
| onClick: () -> Unit, | ||
| modifier: Modifier = Modifier | ||
| ) { | ||
| Row( | ||
| modifier = modifier | ||
| .fillMaxWidth() | ||
| .height(48.dp) | ||
| .background( | ||
| color = AppTheme.craftoColors.background.card, | ||
| shape = RoundedCornerShape(AppTheme.craftoRadius.lg) | ||
| ) | ||
| .clickable( | ||
| onClick = onClick, | ||
| indication = null, | ||
| interactionSource = remember { MutableInteractionSource() } | ||
| ) | ||
| .semantics { role = Role.Button }, | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| horizontalArrangement = Arrangement.spacedBy(8.dp) | ||
| ) { | ||
| TextField( | ||
norhanadel367 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| hint = hint, | ||
| text = text, | ||
| onTextChange = {}, | ||
| readOnlyMode = true, | ||
| enabledState = false, | ||
| startIcon = { | ||
| Icon( | ||
| painter = painterResource(icon), | ||
| contentDescription = null, | ||
| tint = if (hasSelection) AppTheme.craftoColors.shade.primary | ||
| else AppTheme.craftoColors.shade.tertiary | ||
| ) | ||
| }, | ||
| endIcon = { | ||
| Icon( | ||
| painter = painterResource(Res.drawable.alt_arrow_down), | ||
| contentDescription = stringResource(Res.string.dropdown_icon), | ||
| tint = if (hasSelection) AppTheme.craftoColors.shade.primary | ||
| else AppTheme.craftoColors.shade.tertiary | ||
| ) | ||
| } | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.