-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
Commits
Show all changes
2 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 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 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 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
83 changes: 83 additions & 0 deletions
83
app/src/main/java/kr/ksw/visitkorea/presentation/splash/SplashActivity.kt
This file contains 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,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( | ||
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 | ||
}) | ||
} | ||
} |
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. 영문 string이 없으면 아마도 안드로이드스튜디오에서 경고를 보낼 거 같은데 영문추가도 고려해 보시면 좋을 것 같아요. 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. 네 알겠습니다! |
This file contains 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,3 +1,5 @@ | ||
<resources> | ||
<string name="app_name">VisitKorea</string> | ||
|
||
<string name="location_permission_denied_toast">위치 기반으로 검색하기 위해선 권한이 필요합니다.</string> | ||
</resources> |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Permission grant 요청하는 부분을 액티비티에 넣는것보다는 뷰모델이나 다른 클래스에서 하는게 좀더 코드의 책임 측면에서 좋을 것 같은데 한번 리서치를 해보면 좋을거 같아요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 알겠습니다. ViewModel을 만들지 말지 고민하다가 만들지 않았는데... Splash 화면에서 해야할 것들이 좀 더 있을거같아 만드는게 나을거같습니다. 감사합니다!