forked from boostcampwm-2022/android04-BEEP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issues boostcampwm-2022#287 feat: SnackBar 동작을 MainActivity 로 이동 및 To…
…ast 추가
- Loading branch information
Showing
5 changed files
with
109 additions
and
31 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
10 changes: 10 additions & 0 deletions
10
features/ui-common/src/main/java/com/lighthouse/features/common/model/MessageEvent.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,10 @@ | ||
package com.lighthouse.features.common.model | ||
|
||
import com.lighthouse.core.android.utils.resource.UIText | ||
|
||
sealed class MessageEvent { | ||
|
||
data class SnackBar(val uiText: UIText) : MessageEvent() | ||
|
||
data class Toast(val uiText: UIText) : MessageEvent() | ||
} |
56 changes: 56 additions & 0 deletions
56
features/ui-common/src/main/java/com/lighthouse/features/common/ui/MessageViewModel.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,56 @@ | ||
package com.lighthouse.features.common.ui | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.lighthouse.core.android.utils.resource.UIText | ||
import com.lighthouse.core.utils.flow.MutableEventFlow | ||
import com.lighthouse.core.utils.flow.asEventFlow | ||
import com.lighthouse.features.common.model.MessageEvent | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class MessageViewModel @Inject constructor() : ViewModel() { | ||
|
||
private val _messageFlow = MutableEventFlow<MessageEvent>() | ||
|
||
val messageFlow = _messageFlow.asEventFlow() | ||
|
||
fun sendSnackBar(@StringRes resId: Int) { | ||
viewModelScope.launch { | ||
_messageFlow.emit(MessageEvent.SnackBar(UIText.StringResource(resId))) | ||
} | ||
} | ||
|
||
fun sendSnackBar(message: String) { | ||
viewModelScope.launch { | ||
_messageFlow.emit(MessageEvent.SnackBar(UIText.DynamicString(message))) | ||
} | ||
} | ||
|
||
fun sendSnackBar(text: UIText) { | ||
viewModelScope.launch { | ||
_messageFlow.emit(MessageEvent.SnackBar(text)) | ||
} | ||
} | ||
|
||
fun sendToast(@StringRes resId: Int) { | ||
viewModelScope.launch { | ||
_messageFlow.emit(MessageEvent.Toast(UIText.StringResource(resId))) | ||
} | ||
} | ||
|
||
fun sendToast(message: String) { | ||
viewModelScope.launch { | ||
_messageFlow.emit(MessageEvent.Toast(UIText.DynamicString(message))) | ||
} | ||
} | ||
|
||
fun sendToast(text: UIText) { | ||
viewModelScope.launch { | ||
_messageFlow.emit(MessageEvent.Toast(text)) | ||
} | ||
} | ||
} |
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