-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d2133b
commit 9294c06
Showing
7 changed files
with
169 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
feature/sent/src/main/java/com/susu/feature/envelopesearch/SentEnvelopeSearchContract.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.susu.feature.envelopesearch | ||
|
||
import com.susu.core.model.Envelope | ||
import com.susu.core.ui.base.SideEffect | ||
import com.susu.core.ui.base.UiState | ||
import kotlinx.collections.immutable.PersistentList | ||
import kotlinx.collections.immutable.persistentListOf | ||
|
||
data class EnvelopeSearchState( | ||
val searchKeyword: String = "", | ||
val recentSearchKeywordList: PersistentList<String> = persistentListOf(), | ||
val envelopeList: PersistentList<Envelope> = persistentListOf(), | ||
) : UiState | ||
|
||
sealed interface EnvelopeSearchEffect : SideEffect { | ||
data object PopBackStack : EnvelopeSearchEffect | ||
data class NavigateEnvelopDetail(val envelope: Envelope) : EnvelopeSearchEffect | ||
data object FocusClear : EnvelopeSearchEffect | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
feature/sent/src/main/java/com/susu/feature/envelopesearch/SentEnvelopeSearchViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.susu.feature.envelopesearch | ||
|
||
import androidx.lifecycle.viewModelScope | ||
import com.susu.core.ui.base.BaseViewModel | ||
import com.susu.domain.usecase.enveloperecentsearch.DeleteEnvelopeRecentSearchUseCase | ||
import com.susu.domain.usecase.enveloperecentsearch.GetEnvelopeRecentSearchListUseCase | ||
import com.susu.domain.usecase.enveloperecentsearch.UpsertEnvelopeRecentSearchUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.collections.immutable.persistentListOf | ||
import kotlinx.collections.immutable.toPersistentList | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class EnvelopeSearchViewModel @Inject constructor( | ||
private val getEnvelopeRecentSearchUserCase: GetEnvelopeRecentSearchListUseCase, | ||
private val deleteEnvelopeRecentSearchUseCase: DeleteEnvelopeRecentSearchUseCase, | ||
private val upsertEnvelopeRecentSearchUseCase: UpsertEnvelopeRecentSearchUseCase, | ||
) : BaseViewModel<EnvelopeSearchState, EnvelopeSearchEffect>(EnvelopeSearchState()) { | ||
|
||
fun getEnvelopeRecentSearchList() { | ||
viewModelScope.launch { | ||
getEnvelopeRecentSearchUserCase().onSuccess(::updateRecentSearchList) | ||
} | ||
} | ||
|
||
fun deleteEnvelopeRecentSearch(search: String) { | ||
viewModelScope.launch { | ||
deleteEnvelopeRecentSearchUseCase(search).onSuccess(::updateRecentSearchList) | ||
} | ||
} | ||
|
||
fun upsertEnvelopeRecentSearch(search: String) { | ||
viewModelScope.launch { | ||
upsertEnvelopeRecentSearchUseCase(search).onSuccess(::updateRecentSearchList) | ||
} | ||
} | ||
|
||
fun updateSearchKeyword(search: String) = intent { | ||
copy( | ||
searchKeyword = search, | ||
envelopeList = if (search.isBlank()) persistentListOf() else envelopeList, | ||
) | ||
} | ||
|
||
fun getEnvelopeList(search: String) = viewModelScope.launch { | ||
// TODO: 친구 검색 -> 결과가 있으면 봉투 검색 | ||
// TODO: 카테고리 검색 -> 결과가 있으면 봉투 검색 | ||
} | ||
|
||
private fun updateRecentSearchList(searchList: List<String>) { | ||
intent { | ||
copy(recentSearchKeywordList = searchList.toPersistentList()) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters