Skip to content

Commit

Permalink
feat: 읽을 수 없는 쪽지 삭제
Browse files Browse the repository at this point in the history
* refactor: 쪽지 폴링 로직 수정

* style: 코드 정리

* feat: 주변 쪽지를 모두 읽을 수 있는 쪽지로 변경

* feat: 변수명 변경

* feat: 사용하지 않는 drawable 삭제

* feat: 오타 수정
  • Loading branch information
briandr97 authored Nov 16, 2023
1 parent fd4e0d5 commit d4b823d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,15 @@ class DefaultNaverMapSettingDelegate() : NaverMapSettingDelegate, DefaultLifecyc
override fun addLetter(letter: LetterPreview, action: (id: Long) -> Unit) {
Marker().apply {
position = LatLng(letter.coordinate.latitude, letter.coordinate.longitude)
icon = selectLetterIcon(letter.isNearBy)
if (letter.isNearBy) {
setOnSingleClickListener {
action(letter.id)
}
icon = OverlayImage.fromResource(R.drawable.ic_letter)
setOnSingleClickListener {
action(letter.id)
}
map = naverMap
letterMarkers.add(this)
}
}

private fun selectLetterIcon(isNearBy: Boolean): OverlayImage {
return if (isNearBy) {
OverlayImage.fromResource(R.drawable.ic_letter)
} else {
OverlayImage.fromResource(R.drawable.ic_letter_preview)
}
}

override fun removeLetters() {
letterMarkers.forEach { letterMarker ->
letterMarker.map = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class OnAdventureActivity :
private fun subscribe() {
viewModel.startCoordinate.observe(this) {
beginAdventure(it)
viewModel.fetchLetters()
}
viewModel.adventure.observe(this) {
isAdventureDone(it.adventureStatus)
Expand All @@ -125,11 +126,11 @@ class OnAdventureActivity :
viewModel.isSendLetterSuccess.observe(this) {
supportFragmentManager.findFragmentByTag(LetterSendDialog.TAG)?.onDestroyView()
when (it) {
true -> { binding.root.showSnackbar(getString(R.string.OnAdventure_send_letter_success)) }
false -> { binding.root.showSnackbar(getString(R.string.OnAdventure_send_letter_fail)) }
true -> binding.root.showSnackbar(getString(R.string.OnAdventure_send_letter_success))
false -> binding.root.showSnackbar(getString(R.string.OnAdventure_send_letter_fail))
}
}
viewModel.letters.observe(this) {
viewModel.nearbyLetters.observe(this) {
drawLetters(it)
}
viewModel.letter.observe(this) {
Expand All @@ -149,8 +150,7 @@ class OnAdventureActivity :
}

OnAdventureViewModel.TRY_COUNT_OVER -> showToast(getString(R.string.onAdventure_try_count_over))

DataThrowable.NETWORK_THROWABLE_CODE -> { showToast(getString(R.string.network_error_message)) }
DataThrowable.NETWORK_THROWABLE_CODE -> showToast(getString(R.string.network_error_message))

else -> shortSnackbar(throwable.message ?: return@observe)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.now.naaga.presentation.onadventure
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import androidx.lifecycle.map
import androidx.lifecycle.viewModelScope
import com.now.domain.model.Adventure
Expand Down Expand Up @@ -47,19 +46,8 @@ class OnAdventureViewModel @Inject constructor(
private val _lastHint = MutableLiveData<Hint>()
val lastHint: LiveData<Hint> = _lastHint

val letters: LiveData<List<LetterPreview>> = liveData {
while (true) {
myCoordinate.value?.let { coordinate ->
emit(
letterRepository.fetchNearbyLetters(
latitude = coordinate.latitude,
longitude = coordinate.longitude,
).map { it.copy(isNearBy = coordinate.isNearBy(it.coordinate)) },
)
} ?: emit(emptyList())
delay(5000)
}
}
private val _nearbyLetters = MutableLiveData<List<LetterPreview>>()
val nearbyLetters: LiveData<List<LetterPreview>> = _nearbyLetters

private val _letter = MutableLiveData<LetterUiModel>()
val letter: LiveData<LetterUiModel> = _letter
Expand Down Expand Up @@ -102,6 +90,22 @@ class OnAdventureViewModel @Inject constructor(
}
}

fun fetchLetters() {
viewModelScope.launch {
while (true) {
val coordinate = requireNotNull(myCoordinate.value) { "나의 좌표가 null 입니다." }
runCatching {
letterRepository.fetchNearbyLetters(coordinate.latitude, coordinate.longitude)
}.onSuccess {
_nearbyLetters.value = it
}.onFailure {
setThrowable(it)
}
delay(5000L)
}
}
}

fun openHint() {
if (isAllHintsUsed()) {
setThrowable(hintThrowable)
Expand Down Expand Up @@ -148,11 +152,13 @@ class OnAdventureViewModel @Inject constructor(
_adventure.value = adventure.value?.copy(adventureStatus = AdventureStatus.DONE)
_throwable.value = throwable
}

NOT_ARRIVED -> {
val currentRemainingTryCount = adventure.value?.remainingTryCount ?: return
_adventure.value = adventure.value?.copy(remainingTryCount = currentRemainingTryCount - 1)
_throwable.value = throwable
}

else -> {
_throwable.value = throwable
}
Expand Down
14 changes: 0 additions & 14 deletions android/app/src/main/res/drawable/ic_letter_preview.xml

This file was deleted.

2 changes: 1 addition & 1 deletion android/domain/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ tasks {
test {
useJUnitPlatform()
}
}
}

0 comments on commit d4b823d

Please sign in to comment.