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

feat: 마이페이지 주소 수정 기능, 함께해요 참여자 확인하기 기능 구현 #86

Merged
Merged
Prev Previous commit
Next Next commit
feat: 마이페이지 주소 변경 기능 구현
kyujin0911 committed Jul 18, 2024
commit eed6254a6796aa9acd5833a6a88f50b052db4db4
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@
<activity android:name=".presentation.signup.location.DirectLocationActivity"
android:screenOrientation="portrait"
android:exported="false"/>
<activity android:name=".presentation.mypage.MyInfoLocationActivity"
<activity android:name=".presentation.mypage.manageinfo.MyInfoLocationActivity"
android:screenOrientation="portrait"
android:exported="false"/>
<activity
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ class SplashActivity:BaseActivity<ActivitySplashBinding>(R.layout.activity_splas
if(firstRun){
startActivity(Intent(this, IntroActivity::class.java))
finish()
}else if(jwt.isNotEmpty()&&!isFirstLogin){ //로그인 토큰 확인 필요시 해당 부분 주석
} else if(jwt.isNotEmpty()&&!isFirstLogin){ //로그인 토큰 확인 필요시 해당 부분 주석
startActivity(Intent(this,MainActivity::class.java))
finish()
} else{
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ import android.widget.Toast
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
@@ -31,7 +30,8 @@ import com.umc.ttoklip.presentation.honeytip.write.WriteHoneyTipActivity
import com.umc.ttoklip.presentation.mypage.ChooseMainInterestDialogFragment
import com.umc.ttoklip.presentation.mypage.InputIndependentCareerDialogFragment
import com.umc.ttoklip.util.uriToFile
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
@@ -77,7 +77,7 @@ class ManageMyInfoFragment :

private fun initViewListener() {
binding.manageMyInfoBackBtn.setOnClickListener {
navigator.navigateUp()
requireActivity().finish()
}


@@ -140,7 +140,9 @@ class ManageMyInfoFragment :
}

binding.manageProfileImg.setOnClickListener {

pickMultipleMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
binding.finishUpdateProfileBtn.isEnabled = true
}
validateFinishUpdateProfileBtn()

@@ -161,10 +163,12 @@ class ManageMyInfoFragment :
}
}

@OptIn(FlowPreview::class)
override fun initObserver() {
lifecycleScope.launch {
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.myPageInfo.collect {
viewModel.myPageInfo.collectLatest {
Log.d("myinfo", it.toString())
with(binding) {
inputNicknameEt.setText(it.nickname)
nickname = it.nickname
@@ -175,6 +179,7 @@ class ManageMyInfoFragment :
"${it.independentYear}년 ${it.independentMonth}개월"
}
inputAddressTv.text = it.street
viewModel.setAddress(it.street.toString(), false)
address = it.street.toString()
independentYear = it.independentYear
independentMonth = it.independentMonth
@@ -188,7 +193,7 @@ class ManageMyInfoFragment :
}
}

lifecycleScope.launch {
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.nickok.collect {
if (it) {
@@ -202,21 +207,31 @@ class ManageMyInfoFragment :
}
}

lifecycleScope.launch {
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.myPageEvent.collect {
requireActivity().finish()
}
}
}

lifecycleScope.launch {
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.toast.collect {
Toast.makeText(requireContext(), it, Toast.LENGTH_SHORT).show()
}
}
}


viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED){
viewModel.isButtonEnabled.collect{
binding.finishUpdateProfileBtn.isEnabled = it
Log.d("ise", it.toString())
}
}
}
}

companion object {
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ class ManageMyInfoViewModel @Inject constructor(

val toast = MutableSharedFlow<String>()

private val _isButtonEnabled = MutableStateFlow<Boolean>(false)
private val _isButtonEnabled = MutableStateFlow<Boolean>(true)
val isButtonEnabled: StateFlow<Boolean> get() = _isButtonEnabled

private var isRequireNickCheck = false
@@ -55,29 +55,52 @@ class ManageMyInfoViewModel @Inject constructor(
private var editedIndependentYear = -1
private var editedIndependentMonth = -1

private val _isAddressEdit = MutableStateFlow(false)
val isAddressEdit = _isAddressEdit.asStateFlow()

sealed class Event {
object EditMyPageInfo : Event()
}

fun setIsAddressEdit(isEdit: Boolean){
this._isAddressEdit.value = isEdit
_isButtonEnabled.value = true
Log.d("isbutton", isButtonEnabled.value.toString())
}

fun setAddress(address: String, isInputDirect: Boolean){
if(isInputDirect){
_myPageInfo.value = _myPageInfo.value.copy().apply { street = address }
} else {
this.address.value = address
}
}

fun editNickname(nickname: String) {
if (isAddressEdit.value){
return
}
isRequireNickCheck = nickname != _myPageInfo.value.nickname
_isButtonEnabled.value = isRequireNickCheck
Log.d("editNickname", _isButtonEnabled.value.toString())
editedNickname = nickname
Log.d("isRequireNickCheck", isRequireNickCheck.toString())
}

fun editCategory(category: List<String>) {
if (isAddressEdit.value){
return
}
editedCategory = category
if (!isRequireNickCheck) {
_isButtonEnabled.value = category != _myPageInfo.value.interests.map { it.categoryName }
}
}

fun editAddress(address: String) {
editedAddress = address
}

fun editIndependentCareer(independentYear: Int, independentMonth: Int) {
if (isAddressEdit.value){
return
}
editedIndependentYear = independentYear
editedIndependentMonth = independentMonth
if (!isRequireNickCheck) {
@@ -86,7 +109,7 @@ class ManageMyInfoViewModel @Inject constructor(
}
}

fun setIsButtonEnabled() {
private fun setIsButtonEnabled() {
if (editedNickname != _myPageInfo.value.nickname) {
_isButtonEnabled.value = true
}
@@ -120,6 +143,9 @@ class ManageMyInfoViewModel @Inject constructor(
}

fun getMyPageInfo() {
if(isAddressEdit.value) {
return
}
viewModelScope.launch(Dispatchers.IO) {
repository.getMyPageInfo().onSuccess {
_myPageInfo.emit(it)
@@ -179,7 +205,7 @@ class ManageMyInfoViewModel @Inject constructor(
fun fetchReverseGeocoding(coords: LatLng, output: String) {
viewModelScope.launch {
naverRepository.fetchReverseGeocodingInfo(
"127.123456,37.123456",
"${coords.longitude}, ${coords.latitude}",
output
).onSuccess {
Log.d("gc", it.toString())
@@ -197,6 +223,8 @@ class ManageMyInfoViewModel @Inject constructor(
" " + land.number1 + "-" + land.number2
}
}
_myPageInfo.value = _myPageInfo.value.copy().apply { street = address.value }
Log.d("address value", address.value)
}
}
}
Original file line number Diff line number Diff line change
@@ -3,57 +3,110 @@ package com.umc.ttoklip.presentation.mypage.manageinfo
import android.Manifest
import android.content.pm.PackageManager
import android.util.Log
import androidx.core.app.ActivityCompat
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraUpdate
import com.umc.ttoklip.R
import com.umc.ttoklip.databinding.FragmentMyHomeTownAddressBinding
import com.umc.ttoklip.presentation.base.BaseFragment

class MyHomeTownAddressFragment : BaseFragment<FragmentMyHomeTownAddressBinding>(R.layout.fragment_my_home_town_address) {
class MyHomeTownAddressFragment :
BaseFragment<FragmentMyHomeTownAddressBinding>(R.layout.fragment_my_home_town_address) {
private val viewModel: ManageMyInfoViewModel by activityViewModels()
private val navigator by lazy {
findNavController()
}
private val LOCATION_PERMISSION_REQUEST_CODE: Int = 5000
private val PERMISSIONS = arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
)
private lateinit var fusedLocationClient: FusedLocationProviderClient
override fun initObserver() {
private val requestPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()
) { permissions ->
permissions.entries.forEach { (permission, isGranted) ->
when {
isGranted -> {
//getLastKnownLocation()
}
else -> {
// 권한이 거부된 경우에 대한 처리
Log.d("PermissionDenied", "Permission $permission was denied")
}
}
}
}

override fun initObserver() {
// Observe ViewModel live data here
}

override fun initView() {
binding.vm = viewModel
fusedLocationClient = LocationServices.getFusedLocationProviderClient(requireActivity())
getLastKnownLocation()

// 권한 요청 로직을 수정하여, 권한이 부여되지 않은 경우에만 요청
val requestList = permissions.filter { permission ->
ContextCompat.checkSelfPermission(requireContext(), permission) != PackageManager.PERMISSION_GRANTED
}

if (requestList.isNotEmpty()) {
requestPermissionLauncher.launch(requestList.toTypedArray())
} else {
// 모든 권한이 이미 부여된 경우
//getLastKnownLocation()
}

binding.gpsBtn.setOnClickListener {
navigator.navigate(R.id.action_myHomeTownAddressFragment_to_myInfoLocationFragment)
}

binding.myHometownAddressBackBtn.setOnClickListener {
navigator.navigateUp()
}

binding.finishAddressBtn.setOnClickListener {
val inputDirectText = binding.inputDirectAddressEt.text.toString()
if(inputDirectText.isNotEmpty()){
viewModel.setAddress(inputDirectText, true)
}
viewModel.setIsAddressEdit(true)
navigator.popBackStack(R.id.manageMyInfoFragment, false)
}
}

private fun getLastKnownLocation() {
if (ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) == PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.ACCESS_COARSE_LOCATION
) == PackageManager.PERMISSION_GRANTED
) {
ActivityCompat.requestPermissions(requireActivity(), PERMISSIONS, LOCATION_PERMISSION_REQUEST_CODE)
}
fusedLocationClient.lastLocation
.addOnSuccessListener { location ->
if (location != null) {
val latLng = LatLng(location.latitude, location.longitude)
viewModel.fetchReverseGeocoding(latLng, "json")
} else {
fusedLocationClient.lastLocation
.addOnSuccessListener { location ->
if (location != null) {
val latLng = LatLng(location.latitude, location.longitude)
viewModel.fetchReverseGeocoding(latLng, "json")
} else {
Log.d("getLastKnownLocation", "Location is null")
}
}
}
.addOnFailureListener { exception ->
Log.d("getLastKnownLocation", exception.message.toString())
}
.addOnFailureListener { exception ->
Log.d("getLastKnownLocation", exception.message.toString())
}
} else {
// 권한이 여전히 부여되지 않은 경우
Log.d("getLastKnownLocation", "Location permission not granted")
}
}

companion object {
val permissions = arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
)
}
}
}
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import android.widget.SeekBar
import com.umc.ttoklip.R
import com.umc.ttoklip.databinding.ActivityMyHomtownAddressBinding
import com.umc.ttoklip.presentation.base.BaseActivity
import com.umc.ttoklip.presentation.mypage.MyInfoLocationActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Loading