Skip to content

Commit

Permalink
Replace region preference with room, PR review improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
RajashekarRaju committed Aug 18, 2024
1 parent ff4314e commit 5e05345
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.developersbreach.composeactors.data.datasource.database.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.developersbreach.composeactors.data.datasource.database.entity.UserRegionEntity

@Dao
interface UserRegionDao {

@Update(onConflict = OnConflictStrategy.REPLACE)
fun editUserRegion(userRegionEntity: UserRegionEntity)

@Query("SELECT * FROM user_region_table")
fun getSavedUserRegion(): LiveData<UserRegionEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.developersbreach.composeactors.data.datasource.database.entity

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "user_region_table")
data class UserRegionEntity(

@PrimaryKey
@ColumnInfo(name = "user_region_country_code")
val countryCode: Int,

@ColumnInfo(name = "user_region_country_name")
val countryName: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Close
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Popup
import com.developersbreach.composeactors.R
import java.util.*
import com.developersbreach.composeactors.utils.getCountryListWithCode

@Composable
fun RegionEditDialog(popupState: MutableState<Boolean>, onRegionSelect: (String, String) -> Unit) {
fun RegionEditDialog(
popupState: MutableState<Boolean>,
onRegionSelect: (String, String) -> Unit
) {
if (popupState.value) {
val regions = getCountryListWithCode()
Popup(alignment = Alignment.Center, onDismissRequest = { popupState.value = false }) {
Expand Down Expand Up @@ -98,7 +102,7 @@ fun Header(popupState: MutableState<Boolean>) {
style = MaterialTheme.typography.subtitle1
)
Image(
painter = painterResource(id = R.drawable.ic_close),
imageVector = Icons.Rounded.Close,
contentDescription = stringResource(R.string.close_pop_up_icon),
modifier = Modifier.clickable {
popupState.value = false
Expand All @@ -107,17 +111,6 @@ fun Header(popupState: MutableState<Boolean>) {
}
}

private fun getCountryListWithCode(): List<String> {
val region = arrayListOf<String>()
val isoCountryCodes: Array<String> = Locale.getISOCountries()
for (countryCode in isoCountryCodes) {
val locale = Locale("", countryCode)
val countryName: String = locale.displayCountry
region.add("$countryCode,$countryName")
}
return region
}

@Composable
fun DropdownMenuItem(
text: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,15 @@ fun getMovieRuntimeFormatted(
val hours: Int? = runtime?.div(60)
val minutes: Int? = runtime?.rem(60)
return "${hours}h:${minutes}m"
}

fun getCountryListWithCode(): List<String> {
val region = arrayListOf<String>()
val isoCountryCodes: Array<String> = Locale.getISOCountries()
for (countryCode in isoCountryCodes) {
val locale = Locale("", countryCode)
val countryName: String = locale.displayCountry
region.add("$countryCode,$countryName")
}
return region
}
10 changes: 0 additions & 10 deletions app/src/main/res/drawable/ic_close.xml

This file was deleted.

0 comments on commit 5e05345

Please sign in to comment.