Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
android:name=".OndoseeApplication"
Expand Down
1 change: 1 addition & 0 deletions feature/main/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ dependencies {
implementation(libs.accompanist.permission)
implementation(libs.haze)
implementation(libs.androidx.constraintlayout.compose)
implementation(libs.location)
}
1 change: 1 addition & 0 deletions feature/main/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>
33 changes: 31 additions & 2 deletions feature/main/src/main/java/com/ohnalmwo/main/MainScreen.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.ohnalmwo.main

import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand All @@ -8,8 +12,14 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.core.app.ActivityCompat
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.isGranted
import com.google.accompanist.permissions.rememberPermissionState
import com.google.accompanist.permissions.shouldShowRationale
import com.google.android.gms.location.LocationServices
import com.ohnalmwo.main.component.LoadingComponent
import com.ohnalmwo.main.component.MainComponent
import com.ohnalmwo.main.component.TutorialDialog
Expand All @@ -18,6 +28,7 @@ import com.ohnalmwo.main.viewmodel.MainViewModel
import com.ohnalmwo.ui.rememberFlowWithLifecycle
import dev.chrisbanes.haze.HazeState

@OptIn(ExperimentalPermissionsApi::class)
@Composable
fun MainRoute(
hazeState: HazeState,
Expand All @@ -26,9 +37,26 @@ fun MainRoute(
) {
val state by viewModel.state.collectAsStateWithLifecycle()
val effect = rememberFlowWithLifecycle(viewModel.effect)
val findLocationPermissionState = rememberPermissionState(Manifest.permission.ACCESS_FINE_LOCATION)
val context = LocalContext.current
val locationClient = remember { LocationServices.getFusedLocationProviderClient(context) }
var userLocation by remember { mutableStateOf<Pair<Double, Double>?>(null) }

LaunchedEffect(Unit) {
viewModel.getWeatherSignificant(x = 126.85250, y = 35.15944)
if (ActivityCompat.checkSelfPermission(
context,
Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED
) {
locationClient.lastLocation.addOnSuccessListener { location ->
location?.let {
userLocation = it.latitude to it.longitude
viewModel.getWeatherSignificant(x = it.longitude, y = it.latitude)
}
}
} else {
findLocationPermissionState.launchPermissionRequest()
}
viewModel.getSavedLocations()
viewModel.getTutorialDialogState()
}
Expand All @@ -42,6 +70,7 @@ fun MainRoute(
}

MainScreen(
context = context,
hazeState = hazeState,
state = state,
onDismissClick = viewModel::setTutorialDialogState,
Expand All @@ -51,12 +80,12 @@ fun MainRoute(

@Composable
fun MainScreen(
context: Context,
hazeState: HazeState,
state: MainState,
onDismissClick: (Boolean) -> Unit,
navigateToLocation: () -> Unit
) {
val context = LocalContext.current
val motionScene = remember {
context.resources
.openRawResource(R.raw.motion_scene)
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ kotlinxSerializationJson = "1.7.1"
ksp = "2.0.10-1.0.24"
lint = "31.6.0-rc01"
lifecycle-runtime-ktx = "2.8.4"
location = "21.0.1"
lottie = "6.5.0"
material = "1.2.1"
okhttp = "4.12.0"
Expand Down Expand Up @@ -120,6 +121,7 @@ kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime",
kotlinx-immutable = { group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable", version.ref = "kotlinxImmutable" }
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
lint-api = { group = "com.android.tools.lint", name = "lint-api", version.ref = "lint" }
location = { group = "com.google.android.gms", name = "play-services-location", version.ref = "location"}
lottie-compose = { group = "com.airbnb.android", name = "lottie-compose", version.ref = "lottie" }
okhttp3 = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp"}
okhttp-logging = { group = "com.squareup.okhttp3", name = "logging-interceptor", version.ref = "okhttp" }
Expand Down