-
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.
Merge pull request #46 from Nexters/feature/fix-detail
λν μΌ μμ
- Loading branch information
Showing
27 changed files
with
301 additions
and
251 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Ready Story</title> | ||
</head> | ||
<script type="text/javascript"> | ||
|
||
var broswerInfo = navigator.userAgent; | ||
alert(broswerInfo); | ||
</script> | ||
<body> | ||
|
||
<h1 id="sample-title">Sample for the injected local js file.</h1> | ||
<script type="text/javascript" src="sample.js"></script> | ||
</body> | ||
</html> |
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
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
110 changes: 73 additions & 37 deletions
110
presentation/src/main/java/com/keyme/presentation/myprofile/MyProfileViewModel.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 |
---|---|---|
@@ -1,76 +1,112 @@ | ||
package com.keyme.presentation.myprofile | ||
|
||
import com.keyme.domain.entity.member.Member | ||
import com.keyme.domain.entity.onApiError | ||
import com.keyme.domain.entity.onFailure | ||
import com.keyme.domain.entity.onSuccess | ||
import com.keyme.domain.entity.response.MemberStatistics | ||
import com.keyme.domain.usecase.GetMyCharacterUseCase | ||
import com.keyme.domain.usecase.GetMyStatisticsUseCase | ||
import com.keyme.domain.usecase.GetOnboardingKeymeTestUseCase | ||
import com.keyme.presentation.BaseViewModel | ||
import com.keyme.presentation.UiEvent | ||
import com.keyme.presentation.utils.KeymeLinkUtil | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.cancelAndJoin | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.combine | ||
import kotlinx.coroutines.flow.stateIn | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.suspendCancellableCoroutine | ||
import javax.inject.Inject | ||
import kotlin.coroutines.resume | ||
|
||
@HiltViewModel | ||
class MyProfileViewModel @Inject constructor( | ||
private val getMyCharacterUseCase: GetMyCharacterUseCase, | ||
private val getMyStatisticsUseCase: GetMyStatisticsUseCase, | ||
private val getOnboardingKeymeTestUseCase: GetOnboardingKeymeTestUseCase, | ||
) : BaseViewModel() { | ||
private val _mySimilarStatisticsState = MutableStateFlow(MemberStatistics()) | ||
val mySimilarStatisticsState = _mySimilarStatisticsState.asStateFlow() | ||
|
||
private val _mySimilarStatisticsState = MutableStateFlow(MemberStatistics()) | ||
private val _myDifferentStatisticsState = MutableStateFlow(MemberStatistics()) | ||
val myDifferentStatisticsState = _myDifferentStatisticsState.asStateFlow() | ||
|
||
private val _myProfileUiState = MutableStateFlow(MyProfileUiState()) | ||
val myProfileUiState = _myProfileUiState.asStateFlow() | ||
|
||
val myCharacterState = getMyCharacterUseCase().stateIn( | ||
started = SharingStarted.WhileSubscribed(5000L), | ||
initialValue = Member.EMPTY, | ||
val myProfileUiState = combine( | ||
getMyCharacterUseCase(), | ||
_mySimilarStatisticsState, | ||
_myDifferentStatisticsState, | ||
) { myCharacter, similarStatistics, differentStatistics -> | ||
if (statisticsEmpty(similarStatistics, differentStatistics)) { | ||
MyProfileUiState.EmptyStatistics( | ||
myCharacter = myCharacter, | ||
testLink = KeymeLinkUtil.getTestLink(getTestForShare().testId), | ||
) | ||
} else { | ||
MyProfileUiState.Statistics( | ||
myCharacter = myCharacter, | ||
similar = _mySimilarStatisticsState.value, | ||
different = _myDifferentStatisticsState.value, | ||
) | ||
} | ||
}.stateIn( | ||
started = SharingStarted.Eagerly, | ||
initialValue = MyProfileUiState.EmptyStatistics(), | ||
scope = baseViewModelScope, | ||
) | ||
|
||
init { | ||
showToolTip() | ||
loadMyStatistics() | ||
} | ||
|
||
private fun loadMyStatistics() { | ||
apiCall(apiRequest = { getMyStatisticsUseCase.invoke(type = MemberStatistics.StatisticsType.SIMILAR) }) { | ||
_mySimilarStatisticsState.value = it | ||
} | ||
apiCall(apiRequest = { getMyStatisticsUseCase.invoke(type = MemberStatistics.StatisticsType.DIFFERENT) }) { | ||
_myDifferentStatisticsState.value = it | ||
private suspend fun getTestForShare() = suspendCancellableCoroutine { continuation -> | ||
apiCall(apiRequest = { getOnboardingKeymeTestUseCase() }) { | ||
continuation.resume(it) | ||
} | ||
} | ||
|
||
private var toolTipTimerJob: Job? = null | ||
|
||
fun showToolTip() { | ||
if (_myProfileUiState.value.showToolTip.not()) { | ||
_myProfileUiState.value = _myProfileUiState.value.copy(showToolTip = true) | ||
|
||
toolTipTimerJob = baseViewModelScope.launch { | ||
delay(3000L) | ||
dismissToolTip() | ||
} | ||
} | ||
private fun statisticsEmpty( | ||
similarStatistics: MemberStatistics, | ||
differentStatistics: MemberStatistics, | ||
): Boolean { | ||
return similarStatistics.results.isEmpty() || differentStatistics.results.isEmpty() | ||
} | ||
|
||
fun dismissToolTip() { | ||
_myProfileUiState.value = _myProfileUiState.value.copy(showToolTip = false) | ||
|
||
private fun loadMyStatistics() { | ||
baseViewModelScope.launch { | ||
toolTipTimerJob?.cancelAndJoin() | ||
toolTipTimerJob = null | ||
getMyStatisticsUseCase(type = MemberStatistics.StatisticsType.SIMILAR) | ||
.onSuccess { | ||
_mySimilarStatisticsState.value = it | ||
}.onApiError { code, message -> | ||
_mySimilarStatisticsState.value = MemberStatistics() | ||
}.onFailure { | ||
baseViewModelScope.launch { | ||
uiEventManager.onEvent(UiEvent.Toast(it.message ?: "")) | ||
} | ||
} | ||
|
||
getMyStatisticsUseCase(type = MemberStatistics.StatisticsType.DIFFERENT) | ||
.onSuccess { | ||
_myDifferentStatisticsState.value = it | ||
}.onApiError { code, message -> | ||
_myDifferentStatisticsState.value = MemberStatistics() | ||
}.onFailure { | ||
baseViewModelScope.launch { | ||
uiEventManager.onEvent(UiEvent.Toast(it.message ?: "")) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
data class MyProfileUiState(val showToolTip: Boolean = false) | ||
sealed class MyProfileUiState(open val myCharacter: Member) { | ||
data class EmptyStatistics( | ||
override val myCharacter: Member = Member.EMPTY, | ||
val testLink: String = "", | ||
) : MyProfileUiState(myCharacter) | ||
|
||
data class Statistics( | ||
override val myCharacter: Member = Member.EMPTY, | ||
val similar: MemberStatistics, | ||
val different: MemberStatistics, | ||
) : MyProfileUiState(myCharacter) | ||
} |
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
Oops, something went wrong.