Skip to content

Commit

Permalink
Update request for location permission for initial bug
Browse files Browse the repository at this point in the history
  • Loading branch information
senaaydin committed Nov 20, 2023
1 parent 5552f16 commit 14e7a90
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
6 changes: 3 additions & 3 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ kotlin {
api(libs.moko.resources)
api(libs.moko.resources.compose)

//Location
api(libs.play.services.location)
api (libs.play.services.maps)
// //Location
// api(libs.play.services.location)
// api (libs.play.services.maps)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
Expand All @@ -26,9 +25,6 @@ import com.example.moveeapp_compose_kmm.core.getPlatformContext
import com.example.moveeapp_compose_kmm.core.navigateToMap
import com.example.moveeapp_compose_kmm.core.viewModel
import com.example.moveeapp_compose_kmm.map.Map
import com.example.moveeapp_compose_kmm.permission.Permission
import com.example.moveeapp_compose_kmm.permission.isGranted
import com.example.moveeapp_compose_kmm.permission.rememberPermissionState
import com.example.moveeapp_compose_kmm.ui.components.BackPressedItem
import com.example.moveeapp_compose_kmm.ui.components.MapsMarkerDialog
import com.example.moveeapp_compose_kmm.ui.components.TextItem
Expand All @@ -45,18 +41,7 @@ class MapScreen : Screen {

val platformContext = getPlatformContext()

val permissionState = rememberPermissionState(Permission.LOCATION)
LaunchedEffect(Unit) {
permissionState.launchPermissionRequest()
}

val isGranted = permissionState.status.isGranted

LaunchedEffect(isGranted) {
if (isGranted) {
viewModel.loadForecastWithLocation()
}
}
viewModel.loadForecastWithLocation()

Scaffold(topBar = {
TopAppBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ import com.example.moveeapp_compose_kmm.MR
import com.example.moveeapp_compose_kmm.core.ifNotNull
import com.example.moveeapp_compose_kmm.domain.movie.NowPlayingMovie
import com.example.moveeapp_compose_kmm.domain.movie.PopularMovie
import com.example.moveeapp_compose_kmm.permission.Permission
import com.example.moveeapp_compose_kmm.permission.isGranted
import com.example.moveeapp_compose_kmm.permission.rememberPermissionState
import com.example.moveeapp_compose_kmm.ui.components.CardImageItem
import com.example.moveeapp_compose_kmm.ui.components.DateItem
import com.example.moveeapp_compose_kmm.ui.components.ErrorScreen
Expand Down Expand Up @@ -179,9 +182,23 @@ fun HorizontalMoviePager(
fontSize = 34.sp,
fontFamily = fontFamilyResource(MR.fonts.sfpro.bold),
textColor = MaterialTheme.colorScheme.primaryContainer,
text = stringResource( MR.strings.tab_movies))
text = stringResource(MR.strings.tab_movies)
)

val permissionState = rememberPermissionState(Permission.LOCATION) { result ->
if (result) {
onMapClick.invoke()
}
}

IconButton(
onClick = onMapClick
onClick = {
if (permissionState.status.isGranted) {
onMapClick.invoke()
} else {
permissionState.launchPermissionRequest()
}
}
) {
Surface(
modifier = Modifier.size(35.dp),
Expand Down

0 comments on commit 14e7a90

Please sign in to comment.