From e4152c6a795bf311fa4500e69e2a955157ff66b5 Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Thu, 14 Dec 2023 19:11:27 +0900 Subject: [PATCH 01/19] =?UTF-8?q?[FIX]=20#292=20CourseMain=20=EC=A7=84?= =?UTF-8?q?=EC=9E=85=EC=8B=9C,=20=ED=98=84=EC=9E=AC=20=EC=9C=84=EC=B9=98?= =?UTF-8?q?=20=EB=B2=84=ED=8A=BC=20=ED=81=B4=EB=A6=AD=EC=8B=9C=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=20=EC=9A=94=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coursemain/CourseMainFragment.kt | 51 ++++++++++++++----- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt index e87a35111..770186c13 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt @@ -2,8 +2,11 @@ package com.runnect.runnect.presentation.coursemain import android.Manifest import android.content.Intent +import android.content.pm.PackageManager import android.os.Bundle import android.view.View +import android.widget.Toast +import androidx.core.content.ContextCompat import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices import com.gun0912.tedpermission.PermissionListener @@ -35,18 +38,17 @@ class CourseMainFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) init() - getCurrentLocation() + checkAndRequestLocationPermission() + initCurrentLocationButtonClickListener() drawCourseButton() } private fun init() { fusedLocation = LocationServices.getFusedLocationProviderClient(requireActivity()) - requestPermission() + initView() } private fun initView() { - - //MapFragment 추가 val fm = childFragmentManager val mapFragment = fm.findFragmentById(R.id.mapView) as MapFragment? ?: MapFragment.newInstance().also { @@ -57,9 +59,23 @@ class CourseMainFragment : } - private fun getCurrentLocation() { + private fun checkAndRequestLocationPermission() { + if (isLocationPermissionGranted()) { + if (!::naverMap.isInitialized) { + initView() + } + } else { + requestLocationPermission() + } + } + + private fun initCurrentLocationButtonClickListener() { binding.btnCurrentLocation.setOnClickListener { - cameraUpdate(currentLocation) + if (isLocationPermissionGranted()) { + cameraUpdate(currentLocation) + } else { + requestLocationPermission() + } } } @@ -103,23 +119,32 @@ class CourseMainFragment : locationOverlay.icon = OverlayImage.fromResource(R.drawable.current_location) } - private fun requestPermission() { + private fun isLocationPermissionGranted(): Boolean { + return ContextCompat.checkSelfPermission( + requireContext(), + Manifest.permission.ACCESS_FINE_LOCATION + ) == PackageManager.PERMISSION_GRANTED + } + + private fun requestLocationPermission() { TedPermission.create() .setPermissionListener(object : PermissionListener { - override fun onPermissionGranted() { //요청 승인 시 - initView() //지도 뷰 표시 + override fun onPermissionGranted() { + cameraUpdate(currentLocation) } - override fun onPermissionDenied(deniedPermissions: MutableList?) { //요청 거부 시 - naverMap.locationTrackingMode = LocationTrackingMode.None - onDestroy() //앱 종료 + override fun onPermissionDenied(deniedPermissions: MutableList?) { + Toast.makeText( + requireContext(), + "위치 권한이 거부되었습니다.", + Toast.LENGTH_SHORT + ).show() } }) .setRationaleTitle(PERMISSION_TITLE) .setRationaleMessage(PERMISSION_CONTENT) .setDeniedMessage(PERMISSION_GUIDE) .setPermissions( - Manifest.permission.POST_NOTIFICATIONS, // 러닝 시 notification icon 띄우기 Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION ) From ad6e59b5d449372cf94b9527e4877a69e31d47ec Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Thu, 14 Dec 2023 19:31:23 +0900 Subject: [PATCH 02/19] =?UTF-8?q?[MOD]=20#292=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runnect/presentation/coursemain/CourseMainFragment.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt index 770186c13..6eb234136 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt @@ -39,13 +39,13 @@ class CourseMainFragment : super.onViewCreated(view, savedInstanceState) init() checkAndRequestLocationPermission() - initCurrentLocationButtonClickListener() - drawCourseButton() } private fun init() { fusedLocation = LocationServices.getFusedLocationProviderClient(requireActivity()) initView() + initCurrentLocationButtonClickListener() + initDrawCourseButtonClickListener() } private fun initView() { @@ -79,7 +79,7 @@ class CourseMainFragment : } } - private fun drawCourseButton() { + private fun initDrawCourseButtonClickListener() { binding.btnDraw.setOnClickListener { val intent = Intent(activity, SearchActivity::class.java) intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION) From 216309ab8fc18d0a9a1767623302cc2d8566d65e Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Thu, 14 Dec 2023 20:17:53 +0900 Subject: [PATCH 03/19] =?UTF-8?q?[ADD]=20#292=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=20=EC=84=A4=EC=A0=95=20=ED=99=95=EC=9E=A5=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runnect/util/extension/PermissionExt.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt diff --git a/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt b/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt new file mode 100644 index 000000000..3479cb03e --- /dev/null +++ b/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt @@ -0,0 +1,35 @@ +package com.runnect.runnect.util.extension + +import android.Manifest +import android.content.Context +import android.widget.Toast +import com.gun0912.tedpermission.PermissionListener +import com.gun0912.tedpermission.normal.TedPermission +import com.runnect.runnect.presentation.coursemain.CourseMainFragment + +object PermissionUtil { + fun requestLocationPermission(context: Context, onPermissionGranted: () -> Unit) { + TedPermission.create() + .setPermissionListener(object : PermissionListener { + override fun onPermissionGranted() { + onPermissionGranted() + } + + override fun onPermissionDenied(deniedPermissions: MutableList?) { + Toast.makeText( + context, + "위치 권한이 거부되었습니다.", + Toast.LENGTH_SHORT + ).show() + } + }) + .setRationaleTitle(CourseMainFragment.PERMISSION_TITLE) + .setRationaleMessage(CourseMainFragment.PERMISSION_CONTENT) + .setDeniedMessage(CourseMainFragment.PERMISSION_GUIDE) + .setPermissions( + Manifest.permission.ACCESS_COARSE_LOCATION, + Manifest.permission.ACCESS_FINE_LOCATION + ) + .check() + } +} \ No newline at end of file From 83d3d3107bfa16b5d4f8156090626ec2ca1c0db5 Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Thu, 14 Dec 2023 20:19:21 +0900 Subject: [PATCH 04/19] =?UTF-8?q?[FEAT]=20#292=20=EC=BD=94=EC=8A=A4?= =?UTF-8?q?=EA=B7=B8=EB=A6=AC=EA=B8=B0=20=ED=98=84=EC=9E=AC=EC=9C=84?= =?UTF-8?q?=EC=B9=98=20=EC=8B=9C=EC=9E=91=20=EC=8B=9C=20=EA=B6=8C=ED=95=9C?= =?UTF-8?q?=20=EC=9A=94=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/search/SearchActivity.kt | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt index 0dea2a8ca..f0f46839a 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt @@ -7,7 +7,6 @@ import android.os.Bundle import android.view.KeyEvent import android.view.MotionEvent import android.view.inputmethod.EditorInfo.IME_ACTION_SEARCH -import android.view.inputmethod.InputMethodManager import android.widget.TextView import androidx.activity.viewModels import androidx.core.content.ContextCompat @@ -22,13 +21,14 @@ import com.runnect.runnect.presentation.draw.DrawActivity import com.runnect.runnect.presentation.search.adapter.SearchAdapter import com.runnect.runnect.presentation.state.UiState import com.runnect.runnect.util.callback.listener.OnSearchItemClick +import com.runnect.runnect.util.extension.PermissionUtil import com.runnect.runnect.util.extension.hideKeyboard import com.runnect.runnect.util.extension.showKeyboard import dagger.hilt.android.AndroidEntryPoint import timber.log.Timber @AndroidEntryPoint -class SearchActivity: BindingActivity(R.layout.activity_search), +class SearchActivity : BindingActivity(R.layout.activity_search), OnSearchItemClick { val viewModel: SearchViewModel by viewModels() private lateinit var searchAdapter: SearchAdapter @@ -159,7 +159,7 @@ class SearchActivity: BindingActivity(R.layout.activity_s override fun onEditorAction(v: TextView?, actionId: Int, event: KeyEvent?): Boolean { if (actionId == IME_ACTION_SEARCH) { val keyword = binding.etSearch.text - if(!keyword.isNullOrBlank()){ + if (!keyword.isNullOrBlank()) { searchKeyword(keyword.toString()) hideKeyboard(binding.etSearch) } @@ -170,7 +170,9 @@ class SearchActivity: BindingActivity(R.layout.activity_s }) binding.cvStartCurrentLocation.setOnClickListener { - startCurrentLocation() + PermissionUtil.requestLocationPermission(this) { + startCurrentLocation() + } } binding.cvStartCustomLocation.setOnClickListener { @@ -178,13 +180,19 @@ class SearchActivity: BindingActivity(R.layout.activity_s } } + private fun startCurrentLocation() { startActivity( Intent(this, DrawActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION) putExtra( EXTRA_SEARCH_RESULT, - SearchResultEntity(fullAddress = "", name = "", locationLatLng = null, mode = "currentLocation") + SearchResultEntity( + fullAddress = "", + name = "", + locationLatLng = null, + mode = "currentLocation" + ) ) } ) @@ -196,7 +204,12 @@ class SearchActivity: BindingActivity(R.layout.activity_s addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION) putExtra( EXTRA_SEARCH_RESULT, - SearchResultEntity(fullAddress = "", name = "", locationLatLng = null, mode = "customLocation") + SearchResultEntity( + fullAddress = "", + name = "", + locationLatLng = null, + mode = "customLocation" + ) ) } ) From db64608039a70de8aa989a7feeae29f02b8336a1 Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Thu, 14 Dec 2023 20:35:00 +0900 Subject: [PATCH 05/19] =?UTF-8?q?[FEAT]=20#292=20=EB=82=B4=20=EC=BD=94?= =?UTF-8?q?=EC=8A=A4=20=EC=8B=9C=EC=9E=91=20=EC=8B=9C=20=EA=B6=8C=ED=95=9C?= =?UTF-8?q?=20=EC=9A=94=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mydrawdetail/MyDrawDetailActivity.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt index 24c2eac70..1ea2e6edd 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt @@ -15,6 +15,7 @@ import com.runnect.runnect.data.dto.response.ResponseGetMyDrawDetail import com.runnect.runnect.databinding.ActivityMyDrawDetailBinding import com.runnect.runnect.presentation.MainActivity import com.runnect.runnect.presentation.countdown.CountDownActivity +import com.runnect.runnect.util.extension.PermissionUtil import com.runnect.runnect.util.extension.navigateToPreviousScreenWithAnimation import com.runnect.runnect.util.extension.setActivityDialog import dagger.hilt.android.AndroidEntryPoint @@ -40,7 +41,7 @@ class MyDrawDetailActivity : getMyDrawDetail() backButton() addObserver() - toCountDownButton() + initDrawButtonClickListener() deleteButton() } @@ -88,14 +89,21 @@ class MyDrawDetailActivity : viewModel.getMyDrawDetail(courseId = courseId) } - fun toCountDownButton() { + + private fun initDrawButtonClickListener() { binding.btnMyDrawDetailRun.setOnClickListener { - startActivity(Intent(this, CountDownActivity::class.java).apply { - putExtra(EXTRA_COURSE_DATA, viewModel.myDrawToRunData.value) - }) + PermissionUtil.requestLocationPermission(this) { + toCountDownButton() + } } } + private fun toCountDownButton() { + startActivity(Intent(this, CountDownActivity::class.java).apply { + putExtra(EXTRA_COURSE_DATA, viewModel.myDrawToRunData.value) + }) + } + fun addObserver() { observeGetResult() registerBackPressedCallback() @@ -158,7 +166,7 @@ class MyDrawDetailActivity : } } - fun deleteCourse() { + private fun deleteCourse() { viewModel.deleteMyDrawCourse(selectList) } From a45f39c92f81cefa8601399b976cda0881b72b5a Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Sat, 23 Dec 2023 14:34:03 +0900 Subject: [PATCH 06/19] =?UTF-8?q?[FIX]=20#300=20=EC=BB=A4=EC=8A=A4?= =?UTF-8?q?=ED=85=80=EB=9F=AC=EB=8B=9D=20=EC=8B=9C=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EC=97=86=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=ED=81=AC=EB=9E=98?= =?UTF-8?q?=EC=8B=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 커스텀모드에서는 departureLatLng 초기화해주는 부분이 없어서 UninitializedError 발생 --- .../com/runnect/runnect/presentation/draw/DrawActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt index 5af92a7c6..c456f4440 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt @@ -186,18 +186,18 @@ class DrawActivity : BindingActivity(R.layout.activity_draw private fun initCustomLocationMode() { isCustomLocationMode = true - with(binding) { customDepartureMarker.isVisible = true customDepartureInfoWindow.isVisible = true tvCustomDepartureGuideFrame.isVisible = true btnPreStart.setOnClickListener { + departureLatLng = getCenterPosition() isMarkerAvailable = true showDrawGuide() hideDeparture() showDrawCourse() - drawCourse(departureLatLng = getCenterPosition()) + drawCourse(departureLatLng = departureLatLng) hideFloatedDeparture() } } From 06ea7ba90281de382eeac5f432b219f8f1314f6f Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Sat, 23 Dec 2023 14:34:03 +0900 Subject: [PATCH 07/19] =?UTF-8?q?[FIX]=20#292=20=EC=BB=A4=EC=8A=A4?= =?UTF-8?q?=ED=85=80=EB=9F=AC=EB=8B=9D=20=EC=8B=9C=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EC=97=86=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=ED=81=AC=EB=9E=98?= =?UTF-8?q?=EC=8B=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 커스텀모드에서는 departureLatLng 초기화해주는 부분이 없어서 UninitializedError 발생 --- .../com/runnect/runnect/presentation/draw/DrawActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt index 5af92a7c6..c456f4440 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt @@ -186,18 +186,18 @@ class DrawActivity : BindingActivity(R.layout.activity_draw private fun initCustomLocationMode() { isCustomLocationMode = true - with(binding) { customDepartureMarker.isVisible = true customDepartureInfoWindow.isVisible = true tvCustomDepartureGuideFrame.isVisible = true btnPreStart.setOnClickListener { + departureLatLng = getCenterPosition() isMarkerAvailable = true showDrawGuide() hideDeparture() showDrawCourse() - drawCourse(departureLatLng = getCenterPosition()) + drawCourse(departureLatLng = departureLatLng) hideFloatedDeparture() } } From 3e35fbf00d594077aef8f8edb19fb095edfa4c8b Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Tue, 26 Dec 2023 19:39:09 +0900 Subject: [PATCH 08/19] =?UTF-8?q?[FEAT]=20#292=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EC=8B=9C=20=EC=8B=9C=EC=9E=91=20=EC=8B=9C?= =?UTF-8?q?=20=EA=B6=8C=ED=95=9C=20=EC=9A=94=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runnect/runnect/presentation/draw/DrawActivity.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt index c456f4440..f4f084d3e 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt @@ -20,7 +20,6 @@ import androidx.lifecycle.lifecycleScope import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices import com.google.android.material.bottomsheet.BottomSheetDialog -import com.google.android.material.internal.ViewUtils.hideKeyboard import com.naver.maps.geometry.LatLng import com.naver.maps.geometry.LatLngBounds import com.naver.maps.map.CameraAnimation @@ -47,6 +46,7 @@ import com.runnect.runnect.presentation.countdown.CountDownActivity import com.runnect.runnect.presentation.state.UiState import com.runnect.runnect.util.DepartureSetMode import com.runnect.runnect.util.custom.dialog.RequireLoginDialogFragment +import com.runnect.runnect.util.extension.PermissionUtil import com.runnect.runnect.util.extension.hideKeyboard import com.runnect.runnect.util.extension.setActivityDialog import com.runnect.runnect.util.multipart.ContentUriRequestBody @@ -308,9 +308,11 @@ class DrawActivity : BindingActivity(R.layout.activity_draw bottomSheetDialog.setContentView(bottomSheetView) btnCreateCourse.setOnClickListener { - hideKeyboard(etCourseName) - bottomSheetDialog.dismiss() - createMBR() + PermissionUtil.requestLocationPermission(this) { + hideKeyboard(etCourseName) + bottomSheetDialog.dismiss() + createMBR() + } } return bottomSheetDialog From 53f1799e07349f1bbcadc0abde2b5ed7470726ce Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Tue, 26 Dec 2023 19:48:35 +0900 Subject: [PATCH 09/19] =?UTF-8?q?[MOD]=20#292=20courseMain=20=EC=97=90?= =?UTF-8?q?=EB=8F=84=20=EA=B6=8C=ED=95=9C=20=ED=99=95=EC=9D=B8=20=ED=99=95?= =?UTF-8?q?=EC=9E=A5=ED=95=A8=EC=88=98=20=EC=A0=81=EC=9A=A9=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coursemain/CourseMainFragment.kt | 37 ++++--------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt index 6eb234136..ea840e15f 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt @@ -5,12 +5,9 @@ import android.content.Intent import android.content.pm.PackageManager import android.os.Bundle import android.view.View -import android.widget.Toast import androidx.core.content.ContextCompat import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices -import com.gun0912.tedpermission.PermissionListener -import com.gun0912.tedpermission.normal.TedPermission import com.naver.maps.geometry.LatLng import com.naver.maps.map.CameraAnimation import com.naver.maps.map.CameraUpdate @@ -24,6 +21,7 @@ import com.runnect.runnect.R import com.runnect.runnect.binding.BindingFragment import com.runnect.runnect.databinding.FragmentCourseMainBinding import com.runnect.runnect.presentation.search.SearchActivity +import com.runnect.runnect.util.extension.PermissionUtil class CourseMainFragment : @@ -65,7 +63,9 @@ class CourseMainFragment : initView() } } else { - requestLocationPermission() + PermissionUtil.requestLocationPermission(requireContext()) { + cameraUpdate(currentLocation) + } } } @@ -74,7 +74,9 @@ class CourseMainFragment : if (isLocationPermissionGranted()) { cameraUpdate(currentLocation) } else { - requestLocationPermission() + PermissionUtil.requestLocationPermission(requireContext()) { + cameraUpdate(currentLocation) + } } } } @@ -126,31 +128,6 @@ class CourseMainFragment : ) == PackageManager.PERMISSION_GRANTED } - private fun requestLocationPermission() { - TedPermission.create() - .setPermissionListener(object : PermissionListener { - override fun onPermissionGranted() { - cameraUpdate(currentLocation) - } - - override fun onPermissionDenied(deniedPermissions: MutableList?) { - Toast.makeText( - requireContext(), - "위치 권한이 거부되었습니다.", - Toast.LENGTH_SHORT - ).show() - } - }) - .setRationaleTitle(PERMISSION_TITLE) - .setRationaleMessage(PERMISSION_CONTENT) - .setDeniedMessage(PERMISSION_GUIDE) - .setPermissions( - Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.ACCESS_FINE_LOCATION - ) - .check() - } - private fun cameraUpdate(location: LatLng) { val cameraUpdate = CameraUpdate.scrollTo(LatLng(location.latitude, location.longitude)) .animate(CameraAnimation.Easing) From 648c0c155dc7038924903f114939f0973f5bb53c Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Tue, 26 Dec 2023 19:39:09 +0900 Subject: [PATCH 10/19] =?UTF-8?q?[FEAT]=20#292=20=EC=BD=94=EC=8A=A4=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5=20=EC=8B=9C=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=20=EC=9A=94=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runnect/runnect/presentation/draw/DrawActivity.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt index c456f4440..f4f084d3e 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt @@ -20,7 +20,6 @@ import androidx.lifecycle.lifecycleScope import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices import com.google.android.material.bottomsheet.BottomSheetDialog -import com.google.android.material.internal.ViewUtils.hideKeyboard import com.naver.maps.geometry.LatLng import com.naver.maps.geometry.LatLngBounds import com.naver.maps.map.CameraAnimation @@ -47,6 +46,7 @@ import com.runnect.runnect.presentation.countdown.CountDownActivity import com.runnect.runnect.presentation.state.UiState import com.runnect.runnect.util.DepartureSetMode import com.runnect.runnect.util.custom.dialog.RequireLoginDialogFragment +import com.runnect.runnect.util.extension.PermissionUtil import com.runnect.runnect.util.extension.hideKeyboard import com.runnect.runnect.util.extension.setActivityDialog import com.runnect.runnect.util.multipart.ContentUriRequestBody @@ -308,9 +308,11 @@ class DrawActivity : BindingActivity(R.layout.activity_draw bottomSheetDialog.setContentView(bottomSheetView) btnCreateCourse.setOnClickListener { - hideKeyboard(etCourseName) - bottomSheetDialog.dismiss() - createMBR() + PermissionUtil.requestLocationPermission(this) { + hideKeyboard(etCourseName) + bottomSheetDialog.dismiss() + createMBR() + } } return bottomSheetDialog From dd3bb06806f7aebb76318dbb1e214393ddf9ba0d Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Tue, 26 Dec 2023 19:48:35 +0900 Subject: [PATCH 11/19] =?UTF-8?q?[MOD]=20#292=20courseMain=20=EC=97=90?= =?UTF-8?q?=EB=8F=84=20=EA=B6=8C=ED=95=9C=20=ED=99=95=EC=9D=B8=20=ED=99=95?= =?UTF-8?q?=EC=9E=A5=ED=95=A8=EC=88=98=20=EC=A0=81=EC=9A=A9=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coursemain/CourseMainFragment.kt | 37 ++++--------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt index 6eb234136..ea840e15f 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt @@ -5,12 +5,9 @@ import android.content.Intent import android.content.pm.PackageManager import android.os.Bundle import android.view.View -import android.widget.Toast import androidx.core.content.ContextCompat import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices -import com.gun0912.tedpermission.PermissionListener -import com.gun0912.tedpermission.normal.TedPermission import com.naver.maps.geometry.LatLng import com.naver.maps.map.CameraAnimation import com.naver.maps.map.CameraUpdate @@ -24,6 +21,7 @@ import com.runnect.runnect.R import com.runnect.runnect.binding.BindingFragment import com.runnect.runnect.databinding.FragmentCourseMainBinding import com.runnect.runnect.presentation.search.SearchActivity +import com.runnect.runnect.util.extension.PermissionUtil class CourseMainFragment : @@ -65,7 +63,9 @@ class CourseMainFragment : initView() } } else { - requestLocationPermission() + PermissionUtil.requestLocationPermission(requireContext()) { + cameraUpdate(currentLocation) + } } } @@ -74,7 +74,9 @@ class CourseMainFragment : if (isLocationPermissionGranted()) { cameraUpdate(currentLocation) } else { - requestLocationPermission() + PermissionUtil.requestLocationPermission(requireContext()) { + cameraUpdate(currentLocation) + } } } } @@ -126,31 +128,6 @@ class CourseMainFragment : ) == PackageManager.PERMISSION_GRANTED } - private fun requestLocationPermission() { - TedPermission.create() - .setPermissionListener(object : PermissionListener { - override fun onPermissionGranted() { - cameraUpdate(currentLocation) - } - - override fun onPermissionDenied(deniedPermissions: MutableList?) { - Toast.makeText( - requireContext(), - "위치 권한이 거부되었습니다.", - Toast.LENGTH_SHORT - ).show() - } - }) - .setRationaleTitle(PERMISSION_TITLE) - .setRationaleMessage(PERMISSION_CONTENT) - .setDeniedMessage(PERMISSION_GUIDE) - .setPermissions( - Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.ACCESS_FINE_LOCATION - ) - .check() - } - private fun cameraUpdate(location: LatLng) { val cameraUpdate = CameraUpdate.scrollTo(LatLng(location.latitude, location.longitude)) .animate(CameraAnimation.Easing) From 9ab19a580da1d62e2899d129adc176162a8b18c3 Mon Sep 17 00:00:00 2001 From: unam Date: Mon, 1 Jan 2024 17:10:07 +0900 Subject: [PATCH 12/19] =?UTF-8?q?[FIX]=20#292=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=20=ED=97=88=EC=9A=A9=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runnect/presentation/coursemain/CourseMainFragment.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt index ea840e15f..609eb938b 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt @@ -95,8 +95,10 @@ class CourseMainFragment : naverMap.minZoom = 10.0 map.locationSource = locationSource - map.locationTrackingMode = LocationTrackingMode.Follow //위치추적 모드 Follow + if(isLocationPermissionGranted()){ + map.locationTrackingMode = LocationTrackingMode.Follow //위치추적 모드 Follow + } //네이버 맵 sdk에 위치 정보 제공 locationSource = FusedLocationSource( From 9b0cd7ab6fb403a1c7364cc9efbffe6c166b263e Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Sat, 6 Jan 2024 16:40:54 +0900 Subject: [PATCH 13/19] =?UTF-8?q?[REFACTOR]=20#292=20departureLatLng?= =?UTF-8?q?=EA=B3=BC=20=EC=97=B0=EA=B4=80=EB=90=9C=20=EA=B5=AC=EB=AC=B8=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B0=B8=EC=A1=B0=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=84=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/runnect/runnect/presentation/draw/DrawActivity.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt index f4f084d3e..ec811360c 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt @@ -192,12 +192,13 @@ class DrawActivity : BindingActivity(R.layout.activity_draw tvCustomDepartureGuideFrame.isVisible = true btnPreStart.setOnClickListener { - departureLatLng = getCenterPosition() isMarkerAvailable = true showDrawGuide() hideDeparture() showDrawCourse() - drawCourse(departureLatLng = departureLatLng) + getCenterPosition().apply { + departureLatLng = this + }.let(::drawCourse) hideFloatedDeparture() } } From 289ef2c29185c36086a01f81852c356a747dd7ce Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Sun, 7 Jan 2024 11:32:25 +0900 Subject: [PATCH 14/19] =?UTF-8?q?[CHORE]=20#292=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EB=AC=B8=EC=9E=90=EC=97=B4=20=EB=A6=AC?= =?UTF-8?q?=EC=86=8C=EC=8A=A4=20=EC=B6=94=EC=B6=9C=ED=95=B4=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/coursemain/CourseMainFragment.kt | 5 +---- .../com/runnect/runnect/util/extension/PermissionExt.kt | 9 +++++---- app/src/main/res/values/strings.xml | 6 ++++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt index 609eb938b..49adf7847 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt @@ -96,7 +96,7 @@ class CourseMainFragment : map.locationSource = locationSource - if(isLocationPermissionGranted()){ + if (isLocationPermissionGranted()) { map.locationTrackingMode = LocationTrackingMode.Follow //위치추적 모드 Follow } @@ -139,8 +139,5 @@ class CourseMainFragment : companion object { private const val LOCATION_PERMISSION_REQUEST_CODE = 1000 - const val PERMISSION_TITLE = "위치권한 요청" - const val PERMISSION_CONTENT = "코스의 출발지 설정과 러닝 트래킹을 위해 현재 위치 정보를 사용하도록 허용합니다." - const val PERMISSION_GUIDE = "권한을 허용해주세요. [설정] > [앱 및 알림] > [고급] > [앱 권한]" } } \ No newline at end of file diff --git a/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt b/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt index 3479cb03e..e65d731b9 100644 --- a/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt +++ b/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt @@ -5,6 +5,7 @@ import android.content.Context import android.widget.Toast import com.gun0912.tedpermission.PermissionListener import com.gun0912.tedpermission.normal.TedPermission +import com.runnect.runnect.R import com.runnect.runnect.presentation.coursemain.CourseMainFragment object PermissionUtil { @@ -18,14 +19,14 @@ object PermissionUtil { override fun onPermissionDenied(deniedPermissions: MutableList?) { Toast.makeText( context, - "위치 권한이 거부되었습니다.", + R.string.location_permission_denied, Toast.LENGTH_SHORT ).show() } }) - .setRationaleTitle(CourseMainFragment.PERMISSION_TITLE) - .setRationaleMessage(CourseMainFragment.PERMISSION_CONTENT) - .setDeniedMessage(CourseMainFragment.PERMISSION_GUIDE) + .setRationaleTitle(R.string.location_permission_title) + .setRationaleMessage(R.string.location_permission_content) + .setDeniedMessage(R.string.location_permission_guide) .setPermissions( Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8564f27dd..0fa72dbf1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -166,4 +166,10 @@ 나에게 최적화된 코스를 찾아보세요 최신순 스크랩순 + + + 위치 권한이 거부되었습니다. + 위치권한 요청 + 코스의 출발지 설정과 러닝 트래킹을 위해 현재 위치 정보를 사용하도록 허용합니다. + 권한을 허용해주세요. [설정] > [앱 및 알림] > [고급] > [앱 권한] \ No newline at end of file From c3bbadbb56622028d2dcc492d5764dcb8df0804c Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Sun, 7 Jan 2024 12:54:07 +0900 Subject: [PATCH 15/19] =?UTF-8?q?[REFACTOR]=20#292=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=9C=A0=ED=8B=B8=20=ED=99=95=EC=9E=A5?= =?UTF-8?q?=EC=84=B1=20=EC=9E=88=EA=B2=8C=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 권한 거부 또한 고차함수로 만들어 커스텀 가능하게 변경 - PermissionType Enum 클래스 만들어 권한 타입 관리 - 권한 타입 별로 설정 메시지 띄우는 함수 추가 --- .../coursemain/CourseMainFragment.kt | 34 +++++++++--- .../runnect/presentation/draw/DrawActivity.kt | 21 ++++++-- .../mydrawdetail/MyDrawDetailActivity.kt | 17 +++++- .../presentation/search/SearchActivity.kt | 15 +++++- .../runnect/util/extension/PermissionExt.kt | 54 ++++++++++++++----- 5 files changed, 111 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt index 49adf7847..caf790938 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.content.pm.PackageManager import android.os.Bundle import android.view.View +import android.widget.Toast import androidx.core.content.ContextCompat import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices @@ -63,19 +64,26 @@ class CourseMainFragment : initView() } } else { - PermissionUtil.requestLocationPermission(requireContext()) { - cameraUpdate(currentLocation) + context?.let { + PermissionUtil.requestLocationPermission( + it, { cameraUpdate(currentLocation) }, + { showPermissionDeniedToast() }, PermissionUtil.PermissionType.LOCATION + ) } } } + private fun initCurrentLocationButtonClickListener() { binding.btnCurrentLocation.setOnClickListener { if (isLocationPermissionGranted()) { cameraUpdate(currentLocation) } else { - PermissionUtil.requestLocationPermission(requireContext()) { - cameraUpdate(currentLocation) + context?.let { + PermissionUtil.requestLocationPermission( + it, { cameraUpdate(currentLocation) }, + { showPermissionDeniedToast() }, PermissionUtil.PermissionType.LOCATION + ) } } } @@ -124,10 +132,12 @@ class CourseMainFragment : } private fun isLocationPermissionGranted(): Boolean { - return ContextCompat.checkSelfPermission( - requireContext(), - Manifest.permission.ACCESS_FINE_LOCATION - ) == PackageManager.PERMISSION_GRANTED + return context?.let { + ContextCompat.checkSelfPermission( + it, + Manifest.permission.ACCESS_FINE_LOCATION + ) + } == PackageManager.PERMISSION_GRANTED } private fun cameraUpdate(location: LatLng) { @@ -137,6 +147,14 @@ class CourseMainFragment : } + private fun showPermissionDeniedToast() { + Toast.makeText( + context, + R.string.location_permission_denied, + Toast.LENGTH_SHORT + ).show() + } + companion object { private const val LOCATION_PERMISSION_REQUEST_CODE = 1000 } diff --git a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt index ec811360c..c4e1f13a1 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt @@ -309,16 +309,29 @@ class DrawActivity : BindingActivity(R.layout.activity_draw bottomSheetDialog.setContentView(bottomSheetView) btnCreateCourse.setOnClickListener { - PermissionUtil.requestLocationPermission(this) { - hideKeyboard(etCourseName) - bottomSheetDialog.dismiss() - createMBR() + this.let { + PermissionUtil.requestLocationPermission( + it, { + hideKeyboard(etCourseName) + bottomSheetDialog.dismiss() + createMBR() + }, + { showPermissionDeniedToast() }, PermissionUtil.PermissionType.LOCATION + ) } } return bottomSheetDialog } + private fun showPermissionDeniedToast() { + Toast.makeText( + this, + R.string.location_permission_denied, + Toast.LENGTH_SHORT + ).show() + } + private fun activateDrawCourse() { binding.btnPreStart.setOnClickListener { isMarkerAvailable = true diff --git a/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt index 1ea2e6edd..778c2f7fa 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt @@ -3,6 +3,7 @@ package com.runnect.runnect.presentation.mydrawdetail import android.content.ContentValues import android.content.Intent import android.os.Bundle +import android.widget.Toast import androidx.activity.OnBackPressedCallback import androidx.activity.viewModels import androidx.core.net.toUri @@ -92,12 +93,24 @@ class MyDrawDetailActivity : private fun initDrawButtonClickListener() { binding.btnMyDrawDetailRun.setOnClickListener { - PermissionUtil.requestLocationPermission(this) { - toCountDownButton() + + this.let { + PermissionUtil.requestLocationPermission( + it, { toCountDownButton() }, + { showPermissionDeniedToast() }, PermissionUtil.PermissionType.LOCATION + ) } } } + private fun showPermissionDeniedToast() { + Toast.makeText( + this, + R.string.location_permission_denied, + Toast.LENGTH_SHORT + ).show() + } + private fun toCountDownButton() { startActivity(Intent(this, CountDownActivity::class.java).apply { putExtra(EXTRA_COURSE_DATA, viewModel.myDrawToRunData.value) diff --git a/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt index f0f46839a..9d033da2c 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt @@ -8,6 +8,7 @@ import android.view.KeyEvent import android.view.MotionEvent import android.view.inputmethod.EditorInfo.IME_ACTION_SEARCH import android.widget.TextView +import android.widget.Toast import androidx.activity.viewModels import androidx.core.content.ContextCompat import androidx.core.view.isVisible @@ -170,8 +171,11 @@ class SearchActivity : BindingActivity(R.layout.activity_ }) binding.cvStartCurrentLocation.setOnClickListener { - PermissionUtil.requestLocationPermission(this) { - startCurrentLocation() + this.let { + PermissionUtil.requestLocationPermission( + it, { startCurrentLocation() }, + { showPermissionDeniedToast() }, PermissionUtil.PermissionType.LOCATION + ) } } @@ -180,6 +184,13 @@ class SearchActivity : BindingActivity(R.layout.activity_ } } + private fun showPermissionDeniedToast() { + Toast.makeText( + this, + R.string.location_permission_denied, + Toast.LENGTH_SHORT + ).show() + } private fun startCurrentLocation() { startActivity( diff --git a/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt b/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt index e65d731b9..8c462892c 100644 --- a/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt +++ b/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt @@ -6,10 +6,15 @@ import android.widget.Toast import com.gun0912.tedpermission.PermissionListener import com.gun0912.tedpermission.normal.TedPermission import com.runnect.runnect.R -import com.runnect.runnect.presentation.coursemain.CourseMainFragment object PermissionUtil { - fun requestLocationPermission(context: Context, onPermissionGranted: () -> Unit) { + fun requestLocationPermission( + context: Context, + onPermissionGranted: () -> Unit, + onPermissionDenied: () -> Unit, + permissionType: PermissionType + ) { + val permission = setUpPermissionByType(permissionType) TedPermission.create() .setPermissionListener(object : PermissionListener { override fun onPermissionGranted() { @@ -17,20 +22,41 @@ object PermissionUtil { } override fun onPermissionDenied(deniedPermissions: MutableList?) { - Toast.makeText( - context, - R.string.location_permission_denied, - Toast.LENGTH_SHORT - ).show() + onPermissionDenied() } }) - .setRationaleTitle(R.string.location_permission_title) - .setRationaleMessage(R.string.location_permission_content) - .setDeniedMessage(R.string.location_permission_guide) - .setPermissions( - Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.ACCESS_FINE_LOCATION - ) + .setRationaleTitle(permission.title) + .setRationaleMessage(permission.content) + .setDeniedMessage(permission.guide) + .setPermissions(*permission.permissions.toTypedArray()) .check() } + + enum class PermissionType { + LOCATION, + // 필요한 권한 있을 시 추가 + } + + data class PermissionInfo( + val permissions: List, + val title: Int, + val content: Int, + val guide: Int + ) + + private fun setUpPermissionByType(permissionType: PermissionType): PermissionInfo { + return when (permissionType) { + PermissionType.LOCATION -> { + PermissionInfo( + listOf( + Manifest.permission.ACCESS_COARSE_LOCATION, + Manifest.permission.ACCESS_FINE_LOCATION + ), + R.string.location_permission_title, + R.string.location_permission_content, + R.string.location_permission_guide + ) + } + } + } } \ No newline at end of file From fe8fdcd48a73ad1195fde1509ef3a88318e0eb5f Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Sun, 7 Jan 2024 12:56:19 +0900 Subject: [PATCH 16/19] =?UTF-8?q?[ADD]=20#292=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EA=B1=B0=EB=B6=80=20=EC=8B=9C=20=EA=B8=B0=EB=B3=B8=20=ED=86=A0?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EB=9D=84?= =?UTF-8?q?=EC=9B=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/runnect/runnect/util/extension/PermissionExt.kt | 8 +++++++- app/src/main/res/values/strings.xml | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt b/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt index 8c462892c..069465d03 100644 --- a/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt +++ b/app/src/main/java/com/runnect/runnect/util/extension/PermissionExt.kt @@ -11,7 +11,13 @@ object PermissionUtil { fun requestLocationPermission( context: Context, onPermissionGranted: () -> Unit, - onPermissionDenied: () -> Unit, + onPermissionDenied: () -> Unit = { + Toast.makeText( + context, + R.string.common_permission_denied, + Toast.LENGTH_SHORT + ).show() + }, permissionType: PermissionType ) { val permission = setUpPermissionByType(permissionType) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0fa72dbf1..1db596b9e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -167,6 +167,7 @@ 최신순 스크랩순 + 권한이 거부되었습니다. 위치 권한이 거부되었습니다. 위치권한 요청 From 49afa45a5ecf4f70a59db85488e43bfac1a649c5 Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Sun, 7 Jan 2024 13:00:12 +0900 Subject: [PATCH 17/19] =?UTF-8?q?[CHORE]=20#292=20=EC=BB=A8=EB=B2=A4?= =?UTF-8?q?=EC=85=98=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 동사 - 명사 순 --- .../runnect/presentation/coursemain/CourseMainFragment.kt | 8 ++++---- .../presentation/mydrawdetail/MyDrawDetailActivity.kt | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt index caf790938..e0418a935 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt @@ -66,7 +66,7 @@ class CourseMainFragment : } else { context?.let { PermissionUtil.requestLocationPermission( - it, { cameraUpdate(currentLocation) }, + it, { updateCamera(currentLocation) }, { showPermissionDeniedToast() }, PermissionUtil.PermissionType.LOCATION ) } @@ -77,11 +77,11 @@ class CourseMainFragment : private fun initCurrentLocationButtonClickListener() { binding.btnCurrentLocation.setOnClickListener { if (isLocationPermissionGranted()) { - cameraUpdate(currentLocation) + updateCamera(currentLocation) } else { context?.let { PermissionUtil.requestLocationPermission( - it, { cameraUpdate(currentLocation) }, + it, { updateCamera(currentLocation) }, { showPermissionDeniedToast() }, PermissionUtil.PermissionType.LOCATION ) } @@ -140,7 +140,7 @@ class CourseMainFragment : } == PackageManager.PERMISSION_GRANTED } - private fun cameraUpdate(location: LatLng) { + private fun updateCamera(location: LatLng) { val cameraUpdate = CameraUpdate.scrollTo(LatLng(location.latitude, location.longitude)) .animate(CameraAnimation.Easing) naverMap.moveCamera(cameraUpdate) diff --git a/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt index 778c2f7fa..116fed059 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt @@ -96,7 +96,7 @@ class MyDrawDetailActivity : this.let { PermissionUtil.requestLocationPermission( - it, { toCountDownButton() }, + it, { navigateToCountDown() }, { showPermissionDeniedToast() }, PermissionUtil.PermissionType.LOCATION ) } @@ -111,7 +111,7 @@ class MyDrawDetailActivity : ).show() } - private fun toCountDownButton() { + private fun navigateToCountDown() { startActivity(Intent(this, CountDownActivity::class.java).apply { putExtra(EXTRA_COURSE_DATA, viewModel.myDrawToRunData.value) }) From ee5fd14a6242ad0ed6df4bdf9ab7f723462268f7 Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Mon, 8 Jan 2024 02:47:49 +0900 Subject: [PATCH 18/19] =?UTF-8?q?[MOD]=20#292=20showToast=20Util=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runnect/presentation/coursemain/CourseMainFragment.kt | 8 ++------ .../com/runnect/runnect/presentation/draw/DrawActivity.kt | 7 ++----- .../presentation/mydrawdetail/MyDrawDetailActivity.kt | 8 ++------ .../runnect/runnect/presentation/search/SearchActivity.kt | 8 ++------ 4 files changed, 8 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt index e0418a935..b42a16085 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt @@ -5,7 +5,6 @@ import android.content.Intent import android.content.pm.PackageManager import android.os.Bundle import android.view.View -import android.widget.Toast import androidx.core.content.ContextCompat import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices @@ -23,6 +22,7 @@ import com.runnect.runnect.binding.BindingFragment import com.runnect.runnect.databinding.FragmentCourseMainBinding import com.runnect.runnect.presentation.search.SearchActivity import com.runnect.runnect.util.extension.PermissionUtil +import com.runnect.runnect.util.extension.showToast class CourseMainFragment : @@ -148,11 +148,7 @@ class CourseMainFragment : } private fun showPermissionDeniedToast() { - Toast.makeText( - context, - R.string.location_permission_denied, - Toast.LENGTH_SHORT - ).show() + showToast(getString(R.string.location_permission_denied)) } companion object { diff --git a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt index c4e1f13a1..1dda08ace 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt @@ -49,6 +49,7 @@ import com.runnect.runnect.util.custom.dialog.RequireLoginDialogFragment import com.runnect.runnect.util.extension.PermissionUtil import com.runnect.runnect.util.extension.hideKeyboard import com.runnect.runnect.util.extension.setActivityDialog +import com.runnect.runnect.util.extension.showToast import com.runnect.runnect.util.multipart.ContentUriRequestBody import dagger.hilt.android.AndroidEntryPoint import kotlinx.android.synthetic.main.custom_dialog_make_course.view.btn_run @@ -325,11 +326,7 @@ class DrawActivity : BindingActivity(R.layout.activity_draw } private fun showPermissionDeniedToast() { - Toast.makeText( - this, - R.string.location_permission_denied, - Toast.LENGTH_SHORT - ).show() + showToast(getString(R.string.location_permission_denied)) } private fun activateDrawCourse() { diff --git a/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt index 116fed059..aeb1494e9 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt @@ -3,7 +3,6 @@ package com.runnect.runnect.presentation.mydrawdetail import android.content.ContentValues import android.content.Intent import android.os.Bundle -import android.widget.Toast import androidx.activity.OnBackPressedCallback import androidx.activity.viewModels import androidx.core.net.toUri @@ -19,6 +18,7 @@ import com.runnect.runnect.presentation.countdown.CountDownActivity import com.runnect.runnect.util.extension.PermissionUtil import com.runnect.runnect.util.extension.navigateToPreviousScreenWithAnimation import com.runnect.runnect.util.extension.setActivityDialog +import com.runnect.runnect.util.extension.showToast import dagger.hilt.android.AndroidEntryPoint import kotlinx.android.synthetic.main.custom_dialog_delete.view.btn_delete_no import kotlinx.android.synthetic.main.custom_dialog_delete.view.btn_delete_yes @@ -104,11 +104,7 @@ class MyDrawDetailActivity : } private fun showPermissionDeniedToast() { - Toast.makeText( - this, - R.string.location_permission_denied, - Toast.LENGTH_SHORT - ).show() + showToast(getString(R.string.location_permission_denied)) } private fun navigateToCountDown() { diff --git a/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt index 9d033da2c..5fc459b5d 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt @@ -8,7 +8,6 @@ import android.view.KeyEvent import android.view.MotionEvent import android.view.inputmethod.EditorInfo.IME_ACTION_SEARCH import android.widget.TextView -import android.widget.Toast import androidx.activity.viewModels import androidx.core.content.ContextCompat import androidx.core.view.isVisible @@ -25,6 +24,7 @@ import com.runnect.runnect.util.callback.listener.OnSearchItemClick import com.runnect.runnect.util.extension.PermissionUtil import com.runnect.runnect.util.extension.hideKeyboard import com.runnect.runnect.util.extension.showKeyboard +import com.runnect.runnect.util.extension.showToast import dagger.hilt.android.AndroidEntryPoint import timber.log.Timber @@ -185,11 +185,7 @@ class SearchActivity : BindingActivity(R.layout.activity_ } private fun showPermissionDeniedToast() { - Toast.makeText( - this, - R.string.location_permission_denied, - Toast.LENGTH_SHORT - ).show() + showToast(getString(R.string.location_permission_denied)) } private fun startCurrentLocation() { From 9797cdbd5e7d5f02c665bb5a9d1707e3ab527c9b Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Mon, 8 Jan 2024 02:52:49 +0900 Subject: [PATCH 19/19] =?UTF-8?q?[CHORE]=20#292=20named=20Argument=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/coursemain/CourseMainFragment.kt | 12 ++++++++---- .../runnect/presentation/draw/DrawActivity.kt | 6 ++++-- .../mydrawdetail/MyDrawDetailActivity.kt | 7 ++++--- .../runnect/presentation/search/SearchActivity.kt | 6 ++++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt index b42a16085..12b398503 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/coursemain/CourseMainFragment.kt @@ -66,8 +66,10 @@ class CourseMainFragment : } else { context?.let { PermissionUtil.requestLocationPermission( - it, { updateCamera(currentLocation) }, - { showPermissionDeniedToast() }, PermissionUtil.PermissionType.LOCATION + context = it, + onPermissionGranted = { updateCamera(currentLocation) }, + onPermissionDenied = { showPermissionDeniedToast() }, + permissionType = PermissionUtil.PermissionType.LOCATION ) } } @@ -81,8 +83,10 @@ class CourseMainFragment : } else { context?.let { PermissionUtil.requestLocationPermission( - it, { updateCamera(currentLocation) }, - { showPermissionDeniedToast() }, PermissionUtil.PermissionType.LOCATION + context = it, + onPermissionGranted = { updateCamera(currentLocation) }, + onPermissionDenied = { showPermissionDeniedToast() }, + permissionType = PermissionUtil.PermissionType.LOCATION ) } } diff --git a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt index 1dda08ace..64742a410 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/draw/DrawActivity.kt @@ -312,12 +312,14 @@ class DrawActivity : BindingActivity(R.layout.activity_draw btnCreateCourse.setOnClickListener { this.let { PermissionUtil.requestLocationPermission( - it, { + context = it, + onPermissionGranted = { hideKeyboard(etCourseName) bottomSheetDialog.dismiss() createMBR() }, - { showPermissionDeniedToast() }, PermissionUtil.PermissionType.LOCATION + onPermissionDenied = { showPermissionDeniedToast() }, + permissionType = PermissionUtil.PermissionType.LOCATION ) } } diff --git a/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt index aeb1494e9..16344e6d2 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/mydrawdetail/MyDrawDetailActivity.kt @@ -93,11 +93,12 @@ class MyDrawDetailActivity : private fun initDrawButtonClickListener() { binding.btnMyDrawDetailRun.setOnClickListener { - this.let { PermissionUtil.requestLocationPermission( - it, { navigateToCountDown() }, - { showPermissionDeniedToast() }, PermissionUtil.PermissionType.LOCATION + context = it, + onPermissionGranted = { navigateToCountDown() }, + onPermissionDenied = { showPermissionDeniedToast() }, + permissionType = PermissionUtil.PermissionType.LOCATION ) } } diff --git a/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt index 5fc459b5d..7b00996db 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/search/SearchActivity.kt @@ -173,8 +173,10 @@ class SearchActivity : BindingActivity(R.layout.activity_ binding.cvStartCurrentLocation.setOnClickListener { this.let { PermissionUtil.requestLocationPermission( - it, { startCurrentLocation() }, - { showPermissionDeniedToast() }, PermissionUtil.PermissionType.LOCATION + context = it, + onPermissionGranted = { startCurrentLocation() }, + onPermissionDenied = { showPermissionDeniedToast() }, + permissionType = PermissionUtil.PermissionType.LOCATION ) } }