Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Runnect/Runnect-Android
Browse files Browse the repository at this point in the history
…into feature/feat-get-user-profile
  • Loading branch information
sxunea committed Jan 10, 2024
2 parents 77db0a1 + 8327d2b commit b9df77d
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ 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 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
Expand All @@ -21,6 +21,8 @@ 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
import com.runnect.runnect.util.extension.showToast


class CourseMainFragment :
Expand All @@ -35,18 +37,17 @@ class CourseMainFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
init()
getCurrentLocation()
drawCourseButton()
checkAndRequestLocationPermission()
}

private fun init() {
fusedLocation = LocationServices.getFusedLocationProviderClient(requireActivity())
requestPermission()
initView()
initCurrentLocationButtonClickListener()
initDrawCourseButtonClickListener()
}

private fun initView() {

//MapFragment 추가
val fm = childFragmentManager
val mapFragment = fm.findFragmentById(R.id.mapView) as MapFragment?
?: MapFragment.newInstance().also {
Expand All @@ -57,13 +58,42 @@ class CourseMainFragment :
}


private fun getCurrentLocation() {
private fun checkAndRequestLocationPermission() {
if (isLocationPermissionGranted()) {
if (!::naverMap.isInitialized) {
initView()
}
} else {
context?.let {
PermissionUtil.requestLocationPermission(
context = it,
onPermissionGranted = { updateCamera(currentLocation) },
onPermissionDenied = { showPermissionDeniedToast() },
permissionType = PermissionUtil.PermissionType.LOCATION
)
}
}
}


private fun initCurrentLocationButtonClickListener() {
binding.btnCurrentLocation.setOnClickListener {
cameraUpdate(currentLocation)
if (isLocationPermissionGranted()) {
updateCamera(currentLocation)
} else {
context?.let {
PermissionUtil.requestLocationPermission(
context = it,
onPermissionGranted = { updateCamera(currentLocation) },
onPermissionDenied = { showPermissionDeniedToast() },
permissionType = PermissionUtil.PermissionType.LOCATION
)
}
}
}
}

private fun drawCourseButton() {
private fun initDrawCourseButtonClickListener() {
binding.btnDraw.setOnClickListener {
val intent = Intent(activity, SearchActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
Expand All @@ -77,8 +107,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(
Expand All @@ -103,40 +135,27 @@ class CourseMainFragment :
locationOverlay.icon = OverlayImage.fromResource(R.drawable.current_location)
}

private fun requestPermission() {
TedPermission.create()
.setPermissionListener(object : PermissionListener {
override fun onPermissionGranted() { //요청 승인 시
initView() //지도 뷰 표시
}

override fun onPermissionDenied(deniedPermissions: MutableList<String>?) { //요청 거부 시
naverMap.locationTrackingMode = LocationTrackingMode.None
onDestroy() //앱 종료
}
})
.setRationaleTitle(PERMISSION_TITLE)
.setRationaleMessage(PERMISSION_CONTENT)
.setDeniedMessage(PERMISSION_GUIDE)
.setPermissions(
Manifest.permission.POST_NOTIFICATIONS, // 러닝 시 notification icon 띄우기
Manifest.permission.ACCESS_COARSE_LOCATION,
private fun isLocationPermissionGranted(): Boolean {
return context?.let {
ContextCompat.checkSelfPermission(
it,
Manifest.permission.ACCESS_FINE_LOCATION
)
.check()
} == 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)

}

private fun showPermissionDeniedToast() {
showToast(getString(R.string.location_permission_denied))
}

companion object {
private const val LOCATION_PERMISSION_REQUEST_CODE = 1000
const val PERMISSION_TITLE = "위치권한 요청"
const val PERMISSION_CONTENT = "코스의 출발지 설정과 러닝 트래킹을 위해 현재 위치 정보를 사용하도록 허용합니다."
const val PERMISSION_GUIDE = "권한을 허용해주세요. [설정] > [앱 및 알림] > [고급] > [앱 권한]"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,8 +46,10 @@ 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.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
Expand Down Expand Up @@ -186,7 +187,6 @@ class DrawActivity : BindingActivity<ActivityDrawBinding>(R.layout.activity_draw

private fun initCustomLocationMode() {
isCustomLocationMode = true

with(binding) {
customDepartureMarker.isVisible = true
customDepartureInfoWindow.isVisible = true
Expand All @@ -197,7 +197,9 @@ class DrawActivity : BindingActivity<ActivityDrawBinding>(R.layout.activity_draw
showDrawGuide()
hideDeparture()
showDrawCourse()
drawCourse(departureLatLng = getCenterPosition())
getCenterPosition().apply {
departureLatLng = this
}.let(::drawCourse)
hideFloatedDeparture()
}
}
Expand Down Expand Up @@ -308,14 +310,27 @@ class DrawActivity : BindingActivity<ActivityDrawBinding>(R.layout.activity_draw
bottomSheetDialog.setContentView(bottomSheetView)

btnCreateCourse.setOnClickListener {
hideKeyboard(etCourseName)
bottomSheetDialog.dismiss()
createMBR()
this.let {
PermissionUtil.requestLocationPermission(
context = it,
onPermissionGranted = {
hideKeyboard(etCourseName)
bottomSheetDialog.dismiss()
createMBR()
},
onPermissionDenied = { showPermissionDeniedToast() },
permissionType = PermissionUtil.PermissionType.LOCATION
)
}
}

return bottomSheetDialog
}

private fun showPermissionDeniedToast() {
showToast(getString(R.string.location_permission_denied))
}

private fun activateDrawCourse() {
binding.btnPreStart.setOnClickListener {
isMarkerAvailable = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ 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 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
Expand All @@ -40,7 +42,7 @@ class MyDrawDetailActivity :
getMyDrawDetail()
backButton()
addObserver()
toCountDownButton()
initDrawButtonClickListener()
deleteButton()
}

Expand Down Expand Up @@ -88,14 +90,30 @@ 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)
})
this.let {
PermissionUtil.requestLocationPermission(
context = it,
onPermissionGranted = { navigateToCountDown() },
onPermissionDenied = { showPermissionDeniedToast() },
permissionType = PermissionUtil.PermissionType.LOCATION
)
}
}
}

private fun showPermissionDeniedToast() {
showToast(getString(R.string.location_permission_denied))
}

private fun navigateToCountDown() {
startActivity(Intent(this, CountDownActivity::class.java).apply {
putExtra(EXTRA_COURSE_DATA, viewModel.myDrawToRunData.value)
})
}

fun addObserver() {
observeGetResult()
registerBackPressedCallback()
Expand Down Expand Up @@ -158,7 +176,7 @@ class MyDrawDetailActivity :
}
}

fun deleteCourse() {
private fun deleteCourse() {
viewModel.deleteMyDrawCourse(selectList)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,13 +21,15 @@ 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 com.runnect.runnect.util.extension.showToast
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber

@AndroidEntryPoint
class SearchActivity: BindingActivity<ActivitySearchBinding>(R.layout.activity_search),
class SearchActivity : BindingActivity<ActivitySearchBinding>(R.layout.activity_search),
OnSearchItemClick {
val viewModel: SearchViewModel by viewModels()
private lateinit var searchAdapter: SearchAdapter
Expand Down Expand Up @@ -159,7 +160,7 @@ class SearchActivity: BindingActivity<ActivitySearchBinding>(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)
}
Expand All @@ -170,21 +171,37 @@ class SearchActivity: BindingActivity<ActivitySearchBinding>(R.layout.activity_s
})

binding.cvStartCurrentLocation.setOnClickListener {
startCurrentLocation()
this.let {
PermissionUtil.requestLocationPermission(
context = it,
onPermissionGranted = { startCurrentLocation() },
onPermissionDenied = { showPermissionDeniedToast() },
permissionType = PermissionUtil.PermissionType.LOCATION
)
}
}

binding.cvStartCustomLocation.setOnClickListener {
startCustomLocation()
}
}

private fun showPermissionDeniedToast() {
showToast(getString(R.string.location_permission_denied))
}

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"
)
)
}
)
Expand All @@ -196,7 +213,12 @@ class SearchActivity: BindingActivity<ActivitySearchBinding>(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"
)
)
}
)
Expand Down
Loading

0 comments on commit b9df77d

Please sign in to comment.