Skip to content

Commit

Permalink
Merge pull request #78 from team-JMT/feat/webview_bridge
Browse files Browse the repository at this point in the history
위치 권한 허용 수정
  • Loading branch information
soopeach authored Sep 24, 2023
2 parents e149d13 + 8042e16 commit 08b722e
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
package org.gdsc.presentation.login

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.provider.Settings
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.gdsc.domain.usecase.token.GetRefreshTokenUseCase
import org.gdsc.domain.usecase.token.PostRefreshTokenUseCase
import org.gdsc.domain.usecase.token.VerifyAccessTokenUseCase
import org.gdsc.presentation.R
import org.gdsc.presentation.view.MainActivity
import org.gdsc.presentation.view.custom.JmtAlert
import javax.inject.Inject

@AndroidEntryPoint
Expand All @@ -27,22 +38,89 @@ class SplashActivity : AppCompatActivity() {
lateinit var getRefreshTokenUseCase: GetRefreshTokenUseCase

private val DELAY_TIME = 2000L
private var accessible = false

private val locationPermissionRequest = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()
) { permissions ->

if (permissions.all { it.value }) {
Toast.makeText(this, "위치 권한이 허용되었습니다!", Toast.LENGTH_SHORT).show()

if(accessible)
moveToMain()
else
moveToLogin()
} else {
showLocationPermissionDialog()
}

}

private val openAppSettingsLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result ->
// 설정창에서 뒤로가기로 앱에 돌아오는 경우 CANCELED로 처리됨
if (result.resultCode == RESULT_OK || result.resultCode == RESULT_CANCELED) {
checkLocationRequest()
}
}

private fun checkLocationRequest() {
if (ContextCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
locationPermissionRequest.launch(
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
)
)
} else {
if(accessible)
moveToMain()
else
moveToLogin()
}
}
private fun showLocationPermissionDialog() {
JmtAlert(this)
.title("위치 권한 요청")
.content("위치 권한 설정 창으로 이동할까요?")
.multiButton {
leftButton("") {

val intent = Intent(
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.fromParts("package", packageName, null)
)
openAppSettingsLauncher.launch(intent)
}
rightButton("아니오") {
Toast.makeText(this@SplashActivity, "위치 권한이 꼭 필요합니다.", Toast.LENGTH_SHORT).show()
finish()
}
}.show()
}


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
setToFullPage()

lifecycleScope.launch {
lifecycleScope.launch(Dispatchers.Main) {

val accessible = validateToken()
accessible = async { validateToken() }.await()

delay(DELAY_TIME)

if(accessible)
moveToMain()
else
moveToLogin()
checkLocationRequest()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
package org.gdsc.presentation.view

import android.Manifest
import android.animation.Animator
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import android.view.MenuItem
import android.view.View
import android.view.animation.Animation
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import androidx.core.view.WindowCompat
import androidx.core.view.isVisible
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.setupWithNavController
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import org.gdsc.presentation.BaseActivity
import org.gdsc.presentation.R
Expand All @@ -42,64 +32,14 @@ class MainActivity : BaseActivity() {

private val myPageViewModel: MyPageViewModel by viewModels()

private val locationPermissionRequest = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()
) { permissions ->

if (permissions.all { it.value }) {
Toast.makeText(this, "위치 권한이 허용되었습니다!", Toast.LENGTH_SHORT).show()
} else {
showLocationPermissionDialog()
}

}

private fun checkLocationRequest() {
if (ContextCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
locationPermissionRequest.launch(
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
)
)
}
}

// TODO: change to JMT Dialog
private fun showLocationPermissionDialog() {
MaterialAlertDialogBuilder(this)
.setTitle("위치 권한 요청")
.setMessage("위치 권한 설정 창으로 이동할까요?")
.setPositiveButton("") { _, _ ->

startActivity(
Intent(
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.fromParts("package", packageName, null)
)
)
}
.setNegativeButton("아니요") { _, _ ->
Toast.makeText(this, "위치 권한이 꼭 필요합니다.", Toast.LENGTH_SHORT).show()
finish()
}
.show()
}

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

binding = ActivityMainBinding.inflate(layoutInflater)

checkLocationRequest()
setContentView(binding.root)
initBottomNavigationView()
setToolbar()
Expand Down

0 comments on commit 08b722e

Please sign in to comment.