Skip to content
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

[#1] 스플래시 화면 작성 #2

Merged
merged 2 commits into from
Sep 26, 2024
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
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ android {
}

dependencies {
// activity
implementation(libs.androidx.activity.ktx)

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
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:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -10,10 +14,9 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.VisitKorea"
tools:targetApi="31">
android:theme="@style/Theme.VisitKorea">
<activity
android:name=".presentation.main.MainActivity"
android:name=".presentation.splash.SplashActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.VisitKorea">
Expand All @@ -23,6 +26,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".presentation.main.MainActivity"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import kr.ksw.visitkorea.presentation.ui.theme.VisitKoreaTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
VisitKoreaTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package kr.ksw.visitkorea.presentation.splash

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.sp
import androidx.core.content.ContextCompat
import kr.ksw.visitkorea.R
import kr.ksw.visitkorea.presentation.main.MainActivity
import kr.ksw.visitkorea.presentation.ui.theme.VisitKoreaTheme

class SplashActivity : ComponentActivity() {

private val locationPermissionLauncher = registerForActivityResult(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Permission grant 요청하는 부분을 액티비티에 넣는것보다는 뷰모델이나 다른 클래스에서 하는게 좀더 코드의 책임 측면에서 좋을 것 같은데 한번 리서치를 해보면 좋을거 같아요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 알겠습니다. ViewModel을 만들지 말지 고민하다가 만들지 않았는데... Splash 화면에서 해야할 것들이 좀 더 있을거같아 만드는게 나을거같습니다. 감사합니다!

ActivityResultContracts.RequestMultiplePermissions()
) { permissionMap ->
if(permissionMap[Manifest.permission.ACCESS_COARSE_LOCATION] != true &&
permissionMap[Manifest.permission.ACCESS_FINE_LOCATION] != true) {
Toast.makeText(
this@SplashActivity,
getString(R.string.location_permission_denied_toast),
Toast.LENGTH_SHORT
).show()
}
startMainActivity()
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
VisitKoreaTheme {
Surface {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Splash Screen",
fontSize = 24.sp
)
}
}
}
}
checkPermission()
}

private fun checkPermission() {
if(ContextCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED) {
startMainActivity()
} else {
locationPermissionLauncher.launch(arrayOf(
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION
))
}
}

private fun startMainActivity() {
startActivity(Intent(
this,
MainActivity::class.java
).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
})
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

영문 string이 없으면 아마도 안드로이드스튜디오에서 경고를 보낼 거 같은데 영문추가도 고려해 보시면 좋을 것 같아요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 알겠습니다!

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<resources>
<string name="app_name">VisitKorea</string>

<string name="location_permission_denied_toast">위치 기반으로 검색하기 위해선 권한이 필요합니다.</string>
</resources>
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ junit = "4.13.2"
junitVersion = "1.2.1"
espressoCore = "3.6.1"
lifecycleRuntimeKtx = "2.8.6"
activity = "1.9.2"
activityCompose = "1.9.2"
composeBom = "2024.09.02"

Expand Down Expand Up @@ -35,6 +36,8 @@ androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-man
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }

androidx-activity-ktx = { group = "androidx.activity", name = "activity-ktx", version.ref = "activity" }

androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }

Expand Down
Loading