Skip to content

Commit

Permalink
[MOD/#58] Timber 로그 치환
Browse files Browse the repository at this point in the history
  • Loading branch information
Eouls committed Sep 24, 2024
1 parent 7b3d57e commit 8d56aac
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.launch
import timber.log.Timber
import umc.everyones.lck.data.dto.response.home.HomeTodayMatchResponseDto
import umc.everyones.lck.domain.model.response.home.HomeTodayMatchModel
import umc.everyones.lck.domain.repository.TestRepository
Expand All @@ -33,10 +34,10 @@ class HomeViewModel @Inject constructor( // @Inject : 의존성 주입을 받겠
fun fetchHomeTodayMatchInformation(){
viewModelScope.launch {
repository.fetchHomeTodayMatchInformation().onSuccess {response ->
Log.d("fetchHomeTodayMatchInformation", response.toString())
Timber.d("fetchHomeTodayMatchInformation", response.toString())
_matchData.value = response
}.onFailure {
Log.d("fetchHomeTodayMatchInformation", it.stackTraceToString())
Timber.d("fetchHomeTodayMatchInformation", it.stackTraceToString())
_matchData.value = null // 실패시 null 처리
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber
import umc.everyones.lck.R
import umc.everyones.lck.databinding.FragmentTodayMatchLckMatchBinding
import umc.everyones.lck.domain.model.response.match.TodayMatchInformationModel
Expand Down Expand Up @@ -37,7 +38,7 @@ class TodayMatchLckMatchFragment : BaseFragment<FragmentTodayMatchLckMatchBindin
}

override fun initView() {
Log.d("TodayMatchLckMatchFragment", "initView called")
Timber.d("TodayMatchLckMatchFragment", "initView called")
viewModel.fetchTodayMatchInformation()
}
private fun updateMatchContent(matchResponses: List<TodayMatchInformationModel.MatchResponsesModel>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import timber.log.Timber
import umc.everyones.lck.domain.model.response.match.MatchTodayMatchModel
import umc.everyones.lck.domain.model.response.match.TodayMatchInformationModel
import umc.everyones.lck.domain.repository.match.TodayMatchRepository
Expand All @@ -21,10 +22,10 @@ class TodayMatchLckMatchViewModel @Inject constructor(
fun fetchTodayMatchInformation(){
viewModelScope.launch {
repository.fetchTodayMatchInformation().onSuccess {response ->
Log.d("fetchTodayMatchInformation", response.toString())
Timber.d("fetchTodayMatchInformation", response.toString())
_matchData.value = response
}.onFailure {
Log.d("fetchTodayMatchInformation", it.stackTraceToString())
Timber.d("fetchTodayMatchInformation", it.stackTraceToString())
_matchData.value = null // 실패 시 null 처리
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber
import umc.everyones.lck.R
import umc.everyones.lck.databinding.FragmentTodayMatchLckPogBinding
import umc.everyones.lck.domain.model.response.match.CommonTodayMatchPogModel
Expand All @@ -26,20 +27,20 @@ class TodayMatchLckPogFragment : BaseFragment<FragmentTodayMatchLckPogBinding>(R
// 세트 수를 받아와서 탭 레이아웃 설정
viewModel.setCount.observe(viewLifecycleOwner) { setCountModel ->
lckPogMatchRVA.updateSetCount(setCountModel.setCount)
Log.d("TodayMatchLckPogFragment", "Set Count: ${setCountModel.setCount}")
Timber.d("TodayMatchLckPogFragment", "Set Count: ${setCountModel.setCount}")
}
// 각 세트의 POG 데이터를 관찰하여 리사이클러뷰 업데이트
viewModel.setPogData.observe(viewLifecycleOwner) { pogData ->
pogData?.let {
lckPogMatchRVA.updatePlayers(listOf(CommonTodayMatchPogModel(it.id, it.name, it.profileImageUrl, it.seasonInfo, it.matchNumber, it.matchDate, tabIndex)))
Log.d("TodayMatchLckPogFragment", "Set POG Data: $pogData")
Timber.d("TodayMatchLckPogFragment", "Set POG Data: $pogData")
}
}
// 매치 POG 데이터를 관찰하여 리사이클러뷰 업데이트
viewModel.matchPogData.observe(viewLifecycleOwner) { pogData ->
pogData?.let {
lckPogMatchRVA.updatePlayers(listOf(CommonTodayMatchPogModel(it.id, it.name, it.profileImageUrl, it.seasonInfo, it.matchNumber, it.matchDate, tabIndex)))
Log.d("TodayMatchLckPogFragment", "Match POG Data: $pogData")
Timber.d("TodayMatchLckPogFragment", "Match POG Data: $pogData")
}
}
// ViewModel의 matchData를 관찰하여 matchId를 가져와서 사용
Expand All @@ -63,12 +64,12 @@ class TodayMatchLckPogFragment : BaseFragment<FragmentTodayMatchLckPogBinding>(R
} else {
viewModel.fetchTodayMatchMatchPog(matchId)
}
Log.d("TodayMatchLckPogFragment", "Tab selected: $tabIndex")
Timber.d("TodayMatchLckPogFragment", "Tab selected: $tabIndex")
}

// 세트 수를 가져오기 위해 matchId를 사용
viewModel.fetchTodayMatchSetCount(matchId)
Log.d("TodayMatchLckPogFragment", "Match ID: $matchId")
Timber.d("TodayMatchLckPogFragment", "Match ID: $matchId")
viewModel.updateSelectedTab(0)
}
}
Expand All @@ -83,7 +84,7 @@ class TodayMatchLckPogFragment : BaseFragment<FragmentTodayMatchLckPogBinding>(R
setCount = 1, // 초기값
onTabSelected = { tabIndex ->
viewModel.updateSelectedTab(tabIndex)
Log.d("frtabIndex", tabIndex.toString())
Timber.d("frtabIndex", tabIndex.toString())
}
)
binding.rvTodayMatchLckPogContainer.layoutManager = LinearLayoutManager(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import timber.log.Timber
import umc.everyones.lck.domain.model.request.match.CommonPogModel
import umc.everyones.lck.domain.model.response.match.CommonTodayMatchPogModel
import umc.everyones.lck.domain.model.response.match.TodayMatchSetCountModel
Expand All @@ -28,7 +29,7 @@ class TodayMatchLckPogViewModel @Inject constructor(

fun updateSelectedTab(tabIndex: Int) {
_selectedTabIndex.value = tabIndex
Log.d("tabIndex", tabIndex.toString())
Timber.d("tabIndex", tabIndex.toString())
}
// 세트 수를 저장하는 LiveData
private val _setCount = MutableLiveData<TodayMatchSetCountModel>()
Expand All @@ -38,10 +39,10 @@ class TodayMatchLckPogViewModel @Inject constructor(
fun fetchTodayMatchSetPog(setIndex: Int, matchId: Long) {
viewModelScope.launch {
repository.fetchTodayMatchSetPog(setIndex, CommonPogModel(matchId)).onSuccess { response ->
Log.d("fetchTodayMatchSetPog", response.toString())
Timber.d("fetchTodayMatchSetPog", response.toString())
_setPogData.value = response // 데이터를 LiveData에 저장
}.onFailure {
Log.d("fetchTodayMatchSetPog", it.stackTraceToString())
Timber.d("fetchTodayMatchSetPog", it.stackTraceToString())
}
}
}
Expand All @@ -50,10 +51,10 @@ class TodayMatchLckPogViewModel @Inject constructor(
fun fetchTodayMatchMatchPog(matchId: Long) {
viewModelScope.launch {
repository.fetchTodayMatchMatchPog(CommonPogModel(matchId)).onSuccess { response ->
Log.d("fetchTodayMatchMatchPog", response.toString())
Timber.d("fetchTodayMatchMatchPog", response.toString())
_matchPogData.value = response // 데이터를 LiveData에 저장
}.onFailure {
Log.d("fetchTodayMatchMatchPog", it.stackTraceToString())
Timber.d("fetchTodayMatchMatchPog", it.stackTraceToString())
}
}
}
Expand All @@ -62,10 +63,10 @@ class TodayMatchLckPogViewModel @Inject constructor(
fun fetchTodayMatchSetCount(matchId: Long) {
viewModelScope.launch {
repository.fetchTodayMatchSetCount(matchId).onSuccess { response ->
Log.d("fetchTodayMatchSetCount", response.toString())
Timber.d("fetchTodayMatchSetCount", response.toString())
_setCount.value = response
}.onFailure {
Log.d("fetchTodayMatchSetCount", it.stackTraceToString())
Timber.d("fetchTodayMatchSetCount", it.stackTraceToString())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.coroutines.launch
import org.json.JSONException
import org.json.JSONObject
import retrofit2.HttpException
import timber.log.Timber
import umc.everyones.lck.domain.model.request.match.VoteMatchModel
import umc.everyones.lck.domain.model.request.match.VoteMatchPogModel
import umc.everyones.lck.domain.model.response.match.CommonVotePogModel
Expand All @@ -32,21 +33,21 @@ class TodayMatchPredictionViewModel @Inject constructor(
fun fetchTodayMatchVoteMatch(matchId: Long) {
viewModelScope.launch {
repository.fetchTodayMatchVoteMatch(matchId).onSuccess { response ->
Log.d("fetchTodayMatchVoteMatch", response.toString())
Timber.d("fetchTodayMatchVoteMatch", response.toString())
_matchData.value = response
}.onFailure {
Log.d("fetchTodayMatchVoteMatch", it.stackTraceToString())
Timber.d("fetchTodayMatchVoteMatch", it.stackTraceToString())
}
}
}
// 투표를 처리하는 함수
fun voteMatch(matchId: Long, teamId: Int) {
viewModelScope.launch {
repository.voteMatch(VoteMatchModel(matchId, teamId)).onSuccess { response ->
Log.d("voteMatch", response.toString())
Timber.d("voteMatch", response.toString())
_voteResponse.value = response.message // API에서 전달된 메시지를 ViewModel에 저장
}.onFailure { exception ->
Log.d("voteMatch", exception.stackTraceToString())
Timber.d("voteMatch", exception.stackTraceToString())
_voteResponse.value = getErrorMessageFromException(exception) // 예외 메시지 처리
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearSnapHelper
import androidx.recyclerview.widget.RecyclerView
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber
import umc.everyones.lck.R
import umc.everyones.lck.databinding.FragmentTodayMatchTodayPogBinding
import umc.everyones.lck.domain.model.response.match.PogPlayerTodayMatchModel
Expand Down Expand Up @@ -60,7 +61,7 @@ class TodayMatchTodayPogFragment : BaseFragment<FragmentTodayMatchTodayPogBindin
matchData?.let {
// seasonName과 서수를 포함한 matchNumber 설정
binding.tvTodayMatchTodayPogDate.text = "${it.seasonName} ${it.matchNumber.toOrdinal()} Match"
Log.d("Season", it.seasonName)
Timber.d("Season", it.seasonName)
}
})
}
Expand All @@ -73,7 +74,7 @@ class TodayMatchTodayPogFragment : BaseFragment<FragmentTodayMatchTodayPogBindin

val matchId = arguments?.getLong("matchId") ?: return
viewModel.fetchTodayMatchSetCount(matchId)
Log.d("TodayMatchTodayPogFragment", "matchId: $matchId") // matchId 로그 출력
Timber.d("TodayMatchTodayPogFragment", "matchId: $matchId") // matchId 로그 출력
todayViewModel.fetchTodayMatchVoteMatch(matchId)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.coroutines.launch
import org.json.JSONException
import org.json.JSONObject
import retrofit2.HttpException
import timber.log.Timber
import umc.everyones.lck.domain.model.request.match.VoteMatchPogModel
import umc.everyones.lck.domain.model.request.match.VoteSetPogModel
import umc.everyones.lck.domain.model.response.match.PogPlayerTodayMatchModel
Expand Down Expand Up @@ -108,29 +109,29 @@ class TodayMatchTodayPogViewModel @Inject constructor(
// Map을 LiveData로 업데이트
_pogDataMapLiveData.value = pogDataMap.toMap()
}.onFailure {
Log.d("fetchTodayMatchVoteSetPog", it.stackTraceToString())
Timber.d("fetchTodayMatchVoteSetPog", it.stackTraceToString())
}
}
}
// 매치별 POG 데이터를 불러오는 함수
fun fetchTodayMatchVoteMatchPog(matchId: Long) {
viewModelScope.launch {
repository.fetchTodayMatchVoteMatchPog(matchId).onSuccess { response ->
Log.d("fetchTodayMatchVoteMatchPog", response.toString())
Timber.d("fetchTodayMatchVoteMatchPog", response.toString())
_matchPogData.value = response
}.onFailure {
Log.d("fetchTodayMatchVoteMatchPog", it.stackTraceToString())
Timber.d("fetchTodayMatchVoteMatchPog", it.stackTraceToString())
}
}
}
// 세트 POG에 투표하는 함수
fun voteSetPog(matchId: Long, setIndex: Int, playerId: Int) {
viewModelScope.launch {
repository.voteSetPog(VoteSetPogModel(matchId, setIndex, playerId)).onSuccess { response ->
Log.d("voteSetPog", response.toString())
Timber.d("voteSetPog", response.toString())
_voteResponse.value = "투표 되었습니다!"
}.onFailure { exception ->
Log.d("voteSetPog", exception.stackTraceToString())
Timber.d("voteSetPog", exception.stackTraceToString())
_voteResponse.value = getErrorMessageFromException(exception)
}
}
Expand All @@ -139,10 +140,10 @@ class TodayMatchTodayPogViewModel @Inject constructor(
fun voteMatchPog(matchId: Long, playerId: Int) {
viewModelScope.launch {
repository.voteMatchPog(VoteMatchPogModel(matchId, playerId)).onSuccess { response ->
Log.d("voteMatchPog", response.toString())
Timber.d("voteMatchPog", response.toString())
_voteResponse.value = "투표 되었습니다!"
}.onFailure { exception ->
Log.d("voteMatchPog", exception.stackTraceToString())
Timber.d("voteMatchPog", exception.stackTraceToString())
_voteResponse.value = getErrorMessageFromException(exception)
}
}
Expand All @@ -151,10 +152,10 @@ class TodayMatchTodayPogViewModel @Inject constructor(
fun fetchTodayMatchSetCount(matchId: Long) {
viewModelScope.launch {
repository.fetchTodayMatchSetCount(matchId).onSuccess { response ->
Log.d("fetchTodayMatchSetCount", response.toString())
Timber.d("fetchTodayMatchSetCount", response.toString())
_setCount.value = response
}.onFailure {
Log.d("fetchTodayMatchSetCount", it.stackTraceToString())
Timber.d("fetchTodayMatchSetCount", it.stackTraceToString())
}
}
}
Expand Down

0 comments on commit 8d56aac

Please sign in to comment.