Skip to content

Commit

Permalink
Merge pull request #76 from Team-Umbba/feat/#73
Browse files Browse the repository at this point in the history
[Feat/#73] 로그아웃 API 연결
  • Loading branch information
ss99x2002 authored Jul 18, 2023
2 parents d5e2698 + bd7c08c commit 3c17f71
Show file tree
Hide file tree
Showing 20 changed files with 117 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ data class ListQuestionAnswerResponseDto(
data class QnaData(
@SerialName("qna_id")
val qnaId: Long?,
@SerialName("index")
val index: Int?,
@SerialName("section")
val section: String?,
@SerialName("topic")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sopt.umbba_android.data.model.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class LogOutResponseDto(
@SerialName("status")
val status: Int,
@SerialName("message")
val message: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ data class QuestionAnswerResponseDto(
data class QnaData(
@SerialName("qna_id")
val qnaId: Long?,
@SerialName("index")
val index: Int?,
@SerialName("section")
val section: String?,
@SerialName("topic")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.sopt.umbba_android.data.repository

import com.sopt.umbba_android.data.datasource.SettingRemoteDataSource
import com.sopt.umbba_android.data.model.response.LogOutResponseDto
import com.sopt.umbba_android.domain.repository.SettingRepository
import timber.log.Timber

class SettingRepositoryImpl(private val settingRemoteDataSource: SettingRemoteDataSource) :
SettingRepository {
override suspend fun logout() {
TODO("Not yet implemented")
}
override suspend fun logout():Result<LogOutResponseDto> =
runCatching {
settingRemoteDataSource.logout()
}.onSuccess {
Timber.e("로그아웃 성공")
}.onFailure {
Timber.e("로그아웃 실패")
}

override suspend fun deleteAccount() {
TODO("Not yet implemented")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.sopt.umbba_android.data.service

import com.sopt.umbba_android.data.model.response.LogOutResponseDto
import retrofit2.http.PATCH

interface SettingService {
suspend fun logout()
@PATCH("/log-out")
suspend fun logout(): LogOutResponseDto
suspend fun deleteAccount()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.sopt.umbba_android.domain.repository

import com.sopt.umbba_android.data.model.response.LogOutResponseDto

interface SettingRepository {
suspend fun logout()
suspend fun logout():Result<LogOutResponseDto>
suspend fun deleteAccount()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
super.onCreate(savedInstanceState)
initView()
setBottomNav()
getToken()
}

private fun getToken(){
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Log.e("hyeon", "Fetching FCM registration token failed", task.exception)
return@OnCompleteListener
}
// Get new FCM registration token
val token = task.result
Log.e("hyeon", token.toString())
})
}

private fun initView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import com.sopt.umbba_android.util.binding.BindingActivity

class AnswerActivity : BindingActivity<ActivityAnswerBinding>(R.layout.activity_answer),
View.OnClickListener {
private val answerViewModel: AnswerViewModel by viewModels { ViewModelFactory(this) }
private val viewModel: AnswerViewModel by viewModels { ViewModelFactory(this) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.clickListener = this
binding.vm = answerViewModel
binding.vm = viewModel
setQuestionTitle()
}

override fun onClick(view: View?) {
when (view?.id) {
R.id.iv_qna_back -> showBackDialog()
R.id.iv_check -> {
if (!answerViewModel.answer.value.isNullOrBlank()) {
if (!viewModel.answer.value.isNullOrBlank()) {
showConfirmDialog()
}
}
Expand All @@ -40,8 +40,8 @@ class AnswerActivity : BindingActivity<ActivityAnswerBinding>(R.layout.activity_
with(binding) {
tvQuestion.text = intent.getStringExtra("question")
tvTopic.text = intent.getStringExtra("topic")
val appbarTitle = intent.getStringExtra("section").toString()
layoutAppbar.titleText = appbarTitle
viewModel.appbarTitle.value = intent.getStringExtra("section")
layoutAppbar.titleText = viewModel.appbarTitle.value
Log.e("hyeon", intent.getStringExtra("section").toString())
}
}
Expand All @@ -53,7 +53,7 @@ class AnswerActivity : BindingActivity<ActivityAnswerBinding>(R.layout.activity_
putString("question", intent.getStringExtra("question"))
putString("topic", intent.getStringExtra("topic"))
putString("section", intent.getStringExtra("section"))
putString("answer", answerViewModel.answer.value)
putString("answer", viewModel.answer.value)
} // 이 부분은 변수 안쓰고.. 코드 쓰고 싶음 (일단 서버연결 완료되면 해보고, 테스트도 해보자잉)
confirmDialog.apply {
arguments = bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ConfirmAnswerDialogFragment : DialogFragment() {
Toast.makeText(requireActivity(), "답변이 전송되었습니다.", Toast.LENGTH_SHORT).show()
answerViewModel.postAnswer(AnswerRequestDto(arguments?.getString("answer")))
Log.e("hyeon", "answer 값은 = ${arguments?.getString("answer")}")
AnswerActivity().finish()
activity?.finish()
dismiss()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ class QuestionAnswerActivity :
private fun observeQnaViewFlag() {
val qnaId = intent.getLongExtra("questionId", -1)
Log.e("hyeon", "qnaId activity에서" + qnaId.toString())
if (qnaId == -1.toLong()) {
if (qnaId == -1L) {
viewModel.getQuestionAnswer()
viewModel.isBeforeList.value = false
observeQnaResponse()
} else {
viewModel.getListQuestionAnswer(qnaId)
viewModel.isBeforeList.value = true
observeListQnaResponse()
}
}
Expand Down Expand Up @@ -143,7 +145,7 @@ class QuestionAnswerActivity :
with(binding) {
tvAnswerOther.setLayerType(View.LAYER_TYPE_SOFTWARE, null).apply {
if (isBlur) tvAnswerOther.paint.maskFilter =
BlurMaskFilter(13f, BlurMaskFilter.Blur.NORMAL)
BlurMaskFilter(16f, BlurMaskFilter.Blur.NORMAL)
else tvAnswerOther.paint.maskFilter = null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import androidx.lifecycle.ViewModel

class AnswerViewModel : ViewModel() {
var answer = MutableLiveData<String>()
var appbarTitle = MutableLiveData<String>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class QuestionAnswerViewModel(private val questionAnswerRepositoryImpl: Question
var isOpponentAnswer = MutableLiveData<Boolean?>()

var appbarSection = MutableLiveData<String>()
var isBeforeList = MutableLiveData(false)
var qnaId = MutableLiveData<Long>(-1)

var isBeforeList = MutableLiveData<Boolean?>()

fun getQuestionAnswer() {
viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ package com.sopt.umbba_android.presentation.setting

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.activity.viewModels
import com.sopt.umbba_android.R
import com.sopt.umbba_android.databinding.ActivityManageAccountBinding
import com.sopt.umbba_android.presentation.login.LoginActivity
import com.sopt.umbba_android.presentation.setting.viewmodel.ManageAccountViewModel
import com.sopt.umbba_android.util.ViewModelFactory
import com.sopt.umbba_android.util.binding.BindingActivity

class ManageAccountActivity :
BindingActivity<ActivityManageAccountBinding>(R.layout.activity_manage_account),
View.OnClickListener {
private val manageAccountViewModel by viewModels<ManageAccountViewModel>()
private val viewModel: ManageAccountViewModel by viewModels { ViewModelFactory(this) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.clickListener = this
setClickEvent()
observeResponseStatus()
}

override fun onClick(view: View?) {
Expand All @@ -25,10 +30,20 @@ class ManageAccountActivity :
}
}

private fun observeResponseStatus() {
viewModel.responseStatus.observe(this@ManageAccountActivity) {
if (it == 200) {
val intent = Intent(this, LoginActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
}
}
}

private fun setClickEvent() {
with(binding) {
clLogout.setOnClickListener {
manageAccountViewModel.logout()
viewModel.logout()
}
clDeleteAccount.setOnClickListener {
startActivity(Intent(this@ManageAccountActivity, DeleteAccountActivity::class.java))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
package com.sopt.umbba_android.presentation.setting

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.view.View
import androidx.core.content.ContextCompat
import com.sopt.umbba_android.R
import com.sopt.umbba_android.databinding.FragmentSettingBinding
import com.sopt.umbba_android.util.binding.BindingFragment
import com.sopt.umbba_android.util.fcm.MyFirebaseMessagingService

class SettingFragment : BindingFragment<FragmentSettingBinding>(R.layout.fragment_setting) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setClickEvent()
checkNotificationPermission()
setSwitchNotification()
}

private fun setSwitchNotification() {
binding.switchNotification.setOnCheckedChangeListener { buttonView, isChecked ->
MyFirebaseMessagingService().isSwitchChecked.value = isChecked
}
}

private fun checkNotificationPermission() {
MyFirebaseMessagingService().isSwitchChecked.value = (ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED)
binding.switchNotification.isChecked = MyFirebaseMessagingService().isSwitchChecked.value!!
}

private fun setClickEvent() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
package com.sopt.umbba_android.presentation.setting.viewmodel

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.sopt.umbba_android.data.repository.SettingRepositoryImpl
import kotlinx.coroutines.launch

class ManageAccountViewModel(private val settingRepositoryImpl: SettingRepositoryImpl) :
ViewModel() {
fun logout() {

var responseStatus = MutableLiveData<Int>()
fun logout(): Int? {
viewModelScope.launch {
settingRepositoryImpl.logout()
.onSuccess { response ->
Log.e("hyeon", "logout 성공")
responseStatus.value = response.status
}.onFailure { error ->
Log.e("hyeon", "logout 실패 " + error.message)
responseStatus.value = -1
}
}
return responseStatus.value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ import com.sopt.umbba_android.data.datasource.HomeRemoteDataSource
import com.sopt.umbba_android.data.datasource.ListRemoteDataSource
import com.sopt.umbba_android.data.datasource.LoginRemoteDataSource
import com.sopt.umbba_android.data.datasource.QuestionAnswerRemoteDataSource
import com.sopt.umbba_android.data.model.ServicePool
import com.sopt.umbba_android.data.repository.HomeRepositoryImpl
import com.sopt.umbba_android.data.repository.ListRepositoryImpl
import com.sopt.umbba_android.data.repository.LoginRepositoryImpl
import com.sopt.umbba_android.data.repository.QuestionAnswerRepositoryImpl
import com.sopt.umbba_android.data.service.LoginService
import com.sopt.umbba_android.presentation.home.viewmodel.HomeViewModel
import com.sopt.umbba_android.presentation.list.viewmodel.ListViewModel
import com.sopt.umbba_android.presentation.login.viewmodel.LoginViewModel
import com.sopt.umbba_android.presentation.qna.viewmodel.AnswerViewModel
import com.sopt.umbba_android.presentation.qna.viewmodel.ConfirmAnswerDialogFragmentViewModel
import com.sopt.umbba_android.presentation.qna.viewmodel.QuestionAnswerViewModel
import com.sopt.umbba_android.presentation.setting.viewmodel.ManageAccountViewModel

class ViewModelFactory(private val context: Context) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
Expand Down Expand Up @@ -55,14 +54,6 @@ class ViewModelFactory(private val context: Context) : ViewModelProvider.Factory
)
) as T
}

if (modelClass.isAssignableFrom(LoginViewModel::class.java)) {
return LoginViewModel(
LoginRepositoryImpl(
LoginRemoteDataSource()
)
) as T
}
throw IllegalArgumentException("Unknown ViewModel Class")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.lifecycle.MutableLiveData
import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.messaging.FirebaseMessaging
import com.google.firebase.messaging.FirebaseMessagingService
Expand All @@ -17,6 +17,8 @@ import com.sopt.umbba_android.presentation.qna.QuestionAnswerActivity
import timber.log.Timber

class MyFirebaseMessagingService : FirebaseMessagingService() {
var isSwitchChecked = MutableLiveData<Boolean>(false)

override fun onNewToken(token: String) {
super.onNewToken(token)
Timber.tag("hyeon").e("fcm token : " + token)
Expand All @@ -26,7 +28,15 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
super.onMessageReceived(message)
Timber.tag("hyeon").e(message.notification.toString())
Timber.tag("hyeon").e(message.data.toString())
createNotification(message)
setNotificationOnOff(isSwitchChecked.value!!, message)
}

private fun setNotificationOnOff(isSwitchChecked: Boolean, message: RemoteMessage) {
if (isSwitchChecked) {
createNotification(message)
} else {
Log.e("hyeon", "알림 끈 상태")
}
}

private fun createNotification(message: RemoteMessage) {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:titleText="@{``}"
app:visibleCheck="@{true}" />

<TextView
Expand Down
Loading

0 comments on commit 3c17f71

Please sign in to comment.