-
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.
Browse files
Browse the repository at this point in the history
* [FEATURE] 공유하기 암시적 인텐트 수신 기능 구현 * [FIX] 설정 화면에서 로그아웃 후 로그인 화면에서 뒤로가기 클릭시 로그인 화면이 종료되지 않는 문제 수정 * [CHORE] ktlint 적용
- Loading branch information
Showing
9 changed files
with
132 additions
and
11 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
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 pokitmons.pokit | ||
|
||
import android.content.ClipData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.update | ||
import kotlinx.coroutines.launch | ||
import pokitmons.pokit.core.feature.flow.EventFlow | ||
import pokitmons.pokit.core.feature.flow.MutableEventFlow | ||
import pokitmons.pokit.core.feature.flow.asEventFlow | ||
import pokitmons.pokit.home.model.ClipboardLinkManager | ||
import pokitmons.pokit.home.model.PendingSharedLinkManager | ||
import pokitmons.pokit.navigation.Login | ||
import pokitmons.pokit.navigation.ROUTE_WITHOUT_LOGIN | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class MainViewModel @Inject constructor() : ViewModel() { | ||
private val _currentRoute: MutableStateFlow<String> = MutableStateFlow(Login.route) | ||
val currentRoute: StateFlow<String> = _currentRoute.asStateFlow() | ||
|
||
private val _navigationEvent: MutableEventFlow<NavigationEvent> = MutableEventFlow() | ||
val navigationEvent: EventFlow<NavigationEvent> = _navigationEvent.asEventFlow() | ||
|
||
fun setCurrentRoute(route: String) { | ||
_currentRoute.update { route } | ||
} | ||
|
||
fun setClipData(clipData: ClipData): Boolean { | ||
if (clipData.itemCount == 0) return false | ||
val clipboardTextData = clipData.getItemAt(0).text.toString() | ||
|
||
if (!ClipboardLinkManager.checkUrlIsValid(clipboardTextData)) return false | ||
|
||
ClipboardLinkManager.setClipboardLink(clipboardTextData) | ||
return true | ||
} | ||
|
||
fun setSharedLinkUrl(url: String) { | ||
if (currentRoute.value in ROUTE_WITHOUT_LOGIN) { | ||
PendingSharedLinkManager.setSharedLink(url) | ||
} else { | ||
viewModelScope.launch { | ||
_navigationEvent.emit(NavigationEvent.AddLink(url)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
sealed class NavigationEvent { | ||
data class AddLink(val url: String) : NavigationEvent() | ||
} |
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
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/home/src/main/java/pokitmons/pokit/home/model/PendingSharedLinkManager.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 pokitmons.pokit.home.model | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import pokitmons.pokit.core.feature.flow.EventFlow | ||
import pokitmons.pokit.core.feature.flow.MutableEventFlow | ||
import pokitmons.pokit.core.feature.flow.asEventFlow | ||
|
||
object PendingSharedLinkManager { | ||
private val _sharedLinkUrl: MutableEventFlow<String> = MutableEventFlow() | ||
val sharedLinkUrl: EventFlow<String> = _sharedLinkUrl.asEventFlow() | ||
|
||
fun setSharedLink(linkUrl: String) { | ||
CoroutineScope(Dispatchers.IO).launch { | ||
_sharedLinkUrl.emit(linkUrl) | ||
} | ||
} | ||
} |
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