-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 #19869 from wordpress-mobile/move-site-menu-items-…
…to-viewmodel-slice Update: MySiteViewModel Architecture
- Loading branch information
Showing
87 changed files
with
4,463 additions
and
5,786 deletions.
There are no files selected for viewing
37 changes: 0 additions & 37 deletions
37
WordPress/src/main/java/org/wordpress/android/ui/mysite/AccountDataSource.kt
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
WordPress/src/main/java/org/wordpress/android/ui/mysite/AccountDataViewModelSlice.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,61 @@ | ||
package org.wordpress.android.ui.mysite | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.cancel | ||
import kotlinx.coroutines.launch | ||
import org.wordpress.android.fluxc.store.AccountStore | ||
import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper | ||
import org.wordpress.android.ui.mysite.MySiteUiState.PartialState.AccountData | ||
import org.wordpress.android.util.BuildConfigWrapper | ||
import javax.inject.Inject | ||
|
||
class AccountDataViewModelSlice @Inject constructor( | ||
private val accountStore: AccountStore, | ||
private val buildConfigWrapper: BuildConfigWrapper, | ||
private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper | ||
) { | ||
private lateinit var scope: CoroutineScope | ||
|
||
private val _isRefreshing = MutableLiveData<Boolean>() | ||
val isRefreshing: LiveData<Boolean> = _isRefreshing | ||
|
||
private val _uiModel = MutableLiveData<AccountData?>() | ||
val uiModel: LiveData<AccountData?> = _uiModel | ||
|
||
fun initialize(scope: CoroutineScope) { | ||
this.scope = scope | ||
} | ||
|
||
fun onResume() { | ||
scope.launch { | ||
if(!shouldBuildCard()) _uiModel.postValue(null) | ||
_isRefreshing.postValue(true) | ||
val account = accountStore.account | ||
account?.let { | ||
val url = account.avatarUrl.orEmpty() | ||
val name =account.displayName?.ifEmpty { | ||
account.userName.orEmpty() | ||
}.orEmpty() | ||
_uiModel.postValue(AccountData(url, name)) | ||
}?: { | ||
_uiModel.postValue(null) | ||
} | ||
_isRefreshing.postValue(false) | ||
} | ||
} | ||
|
||
fun onRefresh() { | ||
onResume() | ||
} | ||
|
||
fun onCleared() { | ||
scope.cancel() | ||
} | ||
|
||
private fun shouldBuildCard(): Boolean { | ||
return (!buildConfigWrapper.isJetpackApp | ||
&& jetpackFeatureRemovalPhaseHelper.shouldRemoveJetpackFeatures()) | ||
} | ||
} |
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
Oops, something went wrong.