Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
.externalNativeBuild
.cxx
local.properties
key.jks
/app/release/app-release.apk
/app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ class SocialRepository(private val tokenStorage: TokenStorage) {

suspend fun getFriendsData() = client.getFriends("Bearer ${tokenStorage.getAccessToken().toString()}")

suspend fun patchApproveFriend(
request: RequestFriend
){
try {
suspend fun patchApproveFriend(request: RequestFriend): Boolean {
return try {
val response = client.patchApprove("Bearer ${tokenStorage.getAccessToken().toString()}", friend = request)
// 응답 처리
if (response.isSuccess) {
Log.d("친구승인 성공!", response.message)
Log.d("SocialRepository", "친구승인 성공: ${response.message}")
true // 성공하면 true 반환
} else {
Log.d("친구승인 실패!", response.message)
Log.d("SocialRepository", "친구승인 실패: ${response.message}")
false // 실패하면 false 반환
}
} catch (e: Exception) {
e.printStackTrace()
Log.d("친구승인 실패!", e.message.toString())

false // 예외 발생 시 false 반환
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,65 @@ import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.provider.Settings
import android.util.Log
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.app.ActivityCompat.shouldShowRequestPermissionRationale
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import androidx.lifecycle.viewModelScope
import com.google.android.material.snackbar.Snackbar
import com.google.firebase.messaging.FirebaseMessaging
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.toyou.toyouandroid.R
import com.toyou.toyouandroid.presentation.base.MainActivity
import com.toyou.toyouandroid.utils.TokenStorage
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber

class MyFirebaseMessagingService : FirebaseMessagingService() {


private lateinit var tokenStorage: TokenStorage
private var sharedPreferences: SharedPreferences? = null

override fun onCreate() {
super.onCreate()
// TokenStorage 초기화
tokenStorage = TokenStorage(applicationContext)

sharedPreferences = getSharedPreferences("FCM_PREFERENCES", Context.MODE_PRIVATE)
}

override fun onNewToken(token: String) {
super.onNewToken(token)
Log.d("FCM Token", "FCM 토큰: $token")

Timber.d("FCM 토큰: %s", token)
tokenStorage.saveFcmToken(token)
Log.d("FCM Token 저장", "토큰이 저장되었습니다: $token")
Timber.d("토큰이 저장되었습니다: %s", token)

// 구독 여부가 저장되어 있으면 구독
val isSubscribed = sharedPreferences?.getBoolean("isSubscribed", true)
if (isSubscribed == true) {
subscribeToTopic()
}
}

fun subscribeToTopic() {
FirebaseMessaging.getInstance().subscribeToTopic("allUsers")
.addOnCompleteListener { task ->
if (task.isSuccessful) {
Log.d("FCM", "topic 구독 성공'")
Timber.d("topic 구독 성공")
sharedPreferences?.edit()?.putBoolean("isSubscribed", true)?.apply()
} else {
Log.e("FCM",task.exception.toString())
Timber.e(task.exception, "구독 실패")
}
}
}

/*FirebaseMessaging.getInstance().unsubscribeFromTopic("alarm")
fun unsubscribeFromTopic() {
FirebaseMessaging.getInstance().unsubscribeFromTopic("allUsers")
.addOnCompleteListener { task ->
if (task.isSuccessful) {
Log.d("FCM", "topic 구독 취소 성공")
Timber.d("topic 구독 취소 성공")
sharedPreferences?.edit()?.putBoolean("isSubscribed", false)?.apply()
} else {
Log.e("FCM", task.exception.toString())
Timber.e(task.exception, "구독 취소 실패")
}
}*/

}
}

override fun onMessageReceived(remoteMessage: RemoteMessage) {
Expand All @@ -77,7 +77,7 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
sendNotification(it.title, it.body)
}
} else {
Log.d("FCM", "알림 권한이 없어 알림을 표시할 수 없습니다.")
Timber.tag("FCM").d("알림 권한이 없어 알림을 표시할 수 없습니다.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import com.toyou.toyouandroid.data.onboarding.service.AuthService
import com.toyou.toyouandroid.network.NetworkModule
import com.toyou.toyouandroid.presentation.fragment.notice.NoticeDialog
import com.toyou.toyouandroid.presentation.fragment.notice.NoticeDialogViewModel
import com.toyou.toyouandroid.presentation.fragment.onboarding.AuthViewModelFactory
import com.toyou.toyouandroid.presentation.fragment.home.HomeViewModel
import com.toyou.toyouandroid.presentation.viewmodel.HomeViewModelFactory
import com.toyou.toyouandroid.presentation.viewmodel.UserViewModel
import com.toyou.toyouandroid.presentation.viewmodel.UserViewModelFactory
import com.toyou.toyouandroid.utils.TokenManager
Expand Down Expand Up @@ -53,18 +53,14 @@ class HomeOptionFragment : Fragment() {

homeOptionViewModel = ViewModelProvider(
this,
AuthViewModelFactory(
authService,
tokenStorage,
HomeViewModelFactory(
tokenManager
)
)[HomeOptionViewModel::class.java]

homeViewModel = ViewModelProvider(
this,
AuthViewModelFactory(
authService,
tokenStorage,
HomeViewModelFactory(
tokenManager
)
)[HomeViewModel::class.java]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavController
import androidx.navigation.Navigation
Expand All @@ -29,12 +28,12 @@ import com.toyou.toyouandroid.data.onboarding.service.AuthService
import com.toyou.toyouandroid.data.record.service.RecordService
import com.toyou.toyouandroid.domain.record.RecordRepository
import com.toyou.toyouandroid.network.NetworkModule
import com.toyou.toyouandroid.presentation.fragment.notice.NoticeViewModelFactory
import com.toyou.toyouandroid.presentation.fragment.onboarding.AuthViewModelFactory
import com.toyou.toyouandroid.presentation.viewmodel.NoticeViewModelFactory
import com.toyou.toyouandroid.presentation.fragment.record.CardInfoViewModel
import com.toyou.toyouandroid.presentation.fragment.record.RecordViewModelFactory
import com.toyou.toyouandroid.presentation.viewmodel.RecordViewModelFactory
import com.toyou.toyouandroid.presentation.viewmodel.CardViewModel
import com.toyou.toyouandroid.presentation.viewmodel.CardViewModelFactory
import com.toyou.toyouandroid.presentation.viewmodel.HomeViewModelFactory
import com.toyou.toyouandroid.presentation.viewmodel.UserViewModel
import com.toyou.toyouandroid.presentation.viewmodel.UserViewModelFactory
import com.toyou.toyouandroid.utils.TokenManager
Expand Down Expand Up @@ -70,8 +69,10 @@ class HomeFragment : Fragment() {
val tokenStorage = TokenStorage(requireContext())
val authService = NetworkModule.getClient().create(AuthService::class.java)
val tokenManager = TokenManager(authService, tokenStorage)

val noticeService = AuthNetworkModule.getClient().create(NoticeService::class.java)
val noticeRepository = NoticeRepository(noticeService)

val recordService = AuthNetworkModule.getClient().create(RecordService::class.java)
val recordRepository = RecordRepository(recordService)

Expand All @@ -82,7 +83,7 @@ class HomeFragment : Fragment() {

viewModel = ViewModelProvider(
this,
AuthViewModelFactory(authService, tokenStorage, tokenManager)
HomeViewModelFactory(tokenManager)
)[HomeViewModel::class.java]

binding.lifecycleOwner = viewLifecycleOwner
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.toyou.toyouandroid.presentation.fragment.mypage

import android.content.ContentValues.TAG
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.graphics.Color
import android.net.Uri
import android.os.Bundle
Expand All @@ -19,11 +21,13 @@ import com.toyou.toyouandroid.databinding.FragmentMypageBinding
import com.toyou.toyouandroid.presentation.base.MainActivity
import com.toyou.toyouandroid.presentation.fragment.onboarding.SignupNicknameViewModel
import com.toyou.toyouandroid.data.onboarding.service.AuthService
import com.toyou.toyouandroid.network.AuthNetworkModule
import com.toyou.toyouandroid.network.NetworkModule
import com.toyou.toyouandroid.presentation.fragment.onboarding.AuthViewModelFactory
import com.toyou.toyouandroid.presentation.viewmodel.AuthViewModelFactory
import com.toyou.toyouandroid.presentation.fragment.home.HomeViewModel
import com.toyou.toyouandroid.presentation.viewmodel.HomeViewModelFactory
import com.toyou.toyouandroid.utils.TokenManager
import com.toyou.toyouandroid.utils.ViewModelManager
import com.toyou.toyouandroid.presentation.viewmodel.ViewModelManager
import com.toyou.toyouandroid.utils.TokenStorage
import com.toyou.toyouandroid.utils.TutorialStorage
import timber.log.Timber
Expand All @@ -44,11 +48,15 @@ class MypageFragment : Fragment() {

private lateinit var homeViewModel: HomeViewModel

private var sharedPreferences: SharedPreferences? = null

private val mypageViewModel: MypageViewModel by activityViewModels {
val tokenStorage = TokenStorage(requireContext())
val authService: AuthService = NetworkModule.getClient().create(AuthService::class.java)
val tokenManager = TokenManager(authService, tokenStorage)
AuthViewModelFactory(authService, tokenStorage, tokenManager)

val authService2: AuthService = AuthNetworkModule.getClient().create(AuthService::class.java)
AuthViewModelFactory(authService2, tokenStorage, tokenManager)
}

override fun onCreateView(
Expand All @@ -64,13 +72,13 @@ class MypageFragment : Fragment() {

homeViewModel = ViewModelProvider(
this,
AuthViewModelFactory(
authService,
tokenStorage,
HomeViewModelFactory(
tokenManager
)
)[HomeViewModel::class.java]

sharedPreferences = requireActivity().getSharedPreferences("FCM_PREFERENCES", Context.MODE_PRIVATE)

return binding.root
}

Expand All @@ -96,30 +104,24 @@ class MypageFragment : Fragment() {
}

binding.mypageOpinion.setOnClickListener {
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse("https://forms.gle/fJweAP16cT4Tc3cA6")
startActivity(i)
redirectLink("https://forms.gle/fJweAP16cT4Tc3cA6")
}

binding.mypageOpinionBtn.setOnClickListener{
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse("https://forms.gle/fJweAP16cT4Tc3cA6")
startActivity(i)
redirectLink("https://forms.gle/fJweAP16cT4Tc3cA6")
}

binding.mypageContact.setOnClickListener {
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse("http://pf.kakao.com/_xiuPIn/chat")
startActivity(i)
redirectLink("http://pf.kakao.com/_xiuPIn/chat")
}

binding.mypageContactBtn.setOnClickListener{
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse("http://pf.kakao.com/_xiuPIn/chat")
startActivity(i)
redirectLink("http://pf.kakao.com/_xiuPIn/chat")
}

binding.mypageTermsOfUse.setOnClickListener {}
binding.mypageTermsOfUse.setOnClickListener {
redirectLink("https://sumptuous-metacarpal-d3a.notion.site/1437c09ca64e80fb88f6d8ab881ffee3")
}

// 사용자 닉네임 설정
nicknameViewModel.nickname.observe(viewLifecycleOwner) { nickname ->
Expand Down Expand Up @@ -147,6 +149,8 @@ class MypageFragment : Fragment() {
mypageViewModel.setLogoutSuccess(false)
viewModelManager.resetAllViewModels()

Timber.d("로그아웃 후 로그인 화면으로 이동")

navController.navigate(R.id.action_navigation_mypage_to_login_fragment)
}
}
Expand Down Expand Up @@ -203,12 +207,12 @@ class MypageFragment : Fragment() {
}
else {
Timber.tag(TAG).i("연결 끊기 성공. SDK에서 토큰 삭제 됨")
//mypageViewModel.fcmTokenDelete(nicknameViewModel.nickname.toString())
}
}

// 회원 탈퇴 후 튜토리얼 다시 보이도록 설정
TutorialStorage(requireContext()).setTutorialNotShown()
sharedPreferences?.edit()?.putBoolean("isSubscribed", true)?.apply()

mypageViewModel.kakaoSignOut()
mypageDialog?.dismiss()
Expand Down Expand Up @@ -236,6 +240,11 @@ class MypageFragment : Fragment() {
mypageDialog?.dismiss()
}

private fun redirectLink(uri: String) {
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse(uri)
startActivity(i)
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ class MypageViewModel(
_logoutSuccess.value = true
tokenStorage.clearTokens()
} else {
val errorMessage = response.errorBody()?.string() ?: "Unknown error"
val errorMessage = response.errorBody()?.string() ?: "Unknown error: ${response.message()}"
Timber.e("API Error: $errorMessage")
_logoutSuccess.value = false
tokenManager.refreshToken(
onSuccess = { kakaoLogout() },
onFailure = { Timber.e("Failed to refresh token and kakao logout") }
)

// 토큰 만료 시 토큰 갱신 후 로그아웃 재시도
if (response.code() == 401) {
tokenManager.refreshToken(
onSuccess = { kakaoLogout() }, // 토큰 갱신 후 로그아웃 재시도
onFailure = { Timber.e("Failed to refresh token and kakao logout") }
)
} else {
_logoutSuccess.value = false
}
}
}

Expand Down
Loading