Commit 3e9e5475 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Get own current status.

parent 6f0cc896
...@@ -106,19 +106,21 @@ object DrawableHelper { ...@@ -106,19 +106,21 @@ object DrawableHelper {
* @return The user status drawable. * @return The user status drawable.
*/ */
fun getUserStatusDrawable(userStatus: UserStatus, context: Context): Drawable { fun getUserStatusDrawable(userStatus: UserStatus, context: Context): Drawable {
val userStatusDrawable = getDrawableFromId(R.drawable.ic_user_status_black, context).mutate() return when (userStatus) {
wrapDrawable(userStatusDrawable) is UserStatus.Online -> {
when (userStatus) { getDrawableFromId(R.drawable.ic_status_online_24dp, context)
is UserStatus.Online -> tintDrawable(userStatusDrawable, context, R.color.colorUserStatusOnline) }
is UserStatus.Busy -> tintDrawable(userStatusDrawable, context, R.color.colorUserStatusBusy) is UserStatus.Away -> {
is UserStatus.Away -> tintDrawable(userStatusDrawable, context, R.color.colorUserStatusAway) getDrawableFromId(R.drawable.ic_status_away_24dp, context)
is UserStatus.Offline -> tintDrawable(userStatusDrawable, context, R.color.colorUserStatusOffline) }
else -> tintDrawable(userStatusDrawable, context, R.color.colorUserStatusOffline) is UserStatus.Busy -> {
getDrawableFromId(R.drawable.ic_status_busy_24dp, context)
}
else -> getDrawableFromId(R.drawable.ic_status_invisible_24dp, context)
} }
return userStatusDrawable
} }
// TODO Why we need to UserStatus? // TODO Why we need two UserStatus?
/** /**
* Returns the user status drawable. * Returns the user status drawable.
......
...@@ -54,9 +54,7 @@ class MainPresenter @Inject constructor( ...@@ -54,9 +54,7 @@ class MainPresenter @Inject constructor(
checkServerInfo() checkServerInfo()
launchUI(strategy) { launchUI(strategy) {
try { try {
val me = client.me() val model = navHeaderMapper.mapToViewModel(client.me())
val model = navHeaderMapper.mapToViewModel(me)
saveAccount(model) saveAccount(model)
view.setupNavHeader(model, getAccountsInteractor.get()) view.setupNavHeader(model, getAccountsInteractor.get())
} catch (ex: Exception) { } catch (ex: Exception) {
...@@ -77,11 +75,17 @@ class MainPresenter @Inject constructor( ...@@ -77,11 +75,17 @@ class MainPresenter @Inject constructor(
} }
} }
private suspend fun saveAccount(me: NavHeaderViewModel) { private suspend fun saveAccount(viewModel: NavHeaderViewModel) {
val icon = settings.favicon()?.let { val icon = settings.favicon()?.let {
UrlHelper.getServerLogoUrl(currentServer, it) UrlHelper.getServerLogoUrl(currentServer, it)
} }
val account = Account(currentServer, icon, me.serverLogo, me.username, me.avatar) val account = Account(
currentServer,
icon,
viewModel.serverLogo,
viewModel.userDisplayName,
viewModel.userAvatar
)
saveAccountInteractor.save(account) saveAccountInteractor.save(account)
} }
......
...@@ -18,10 +18,10 @@ interface MainView : MessageView, VersionCheckView { ...@@ -18,10 +18,10 @@ interface MainView : MessageView, VersionCheckView {
/** /**
* Setups the navigation header. * Setups the navigation header.
* *
* @param model The [NavHeaderViewModel]. * @param viewModel The [NavHeaderViewModel].
* @param accounts The list of accounts. * @param accounts The list of accounts.
*/ */
fun setupNavHeader(model: NavHeaderViewModel, accounts: List<Account>) fun setupNavHeader(viewModel: NavHeaderViewModel, accounts: List<Account>)
fun closeServerSelection() fun closeServerSelection()
} }
\ No newline at end of file
...@@ -92,13 +92,19 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, HasSupp ...@@ -92,13 +92,19 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, HasSupp
} }
} }
override fun setupNavHeader(model: NavHeaderViewModel, accounts: List<Account>) { override fun setupNavHeader(viewModel: NavHeaderViewModel, accounts: List<Account>) {
Timber.d("Setting up nav header: $model") Timber.d("Setting up nav header: $viewModel")
with(headerLayout) { with(headerLayout) {
text_user_name.text = model.username image_user_status.setImageDrawable(
text_server_url.text = model.server DrawableHelper.getUserStatusDrawable(
image_avatar.setImageURI(model.avatar) viewModel.userStatus!!,
server_logo.setImageURI(model.serverLogo) this.context
)
)
text_user_name.text = viewModel.userDisplayName
text_server_url.text = viewModel.serverUrl
image_avatar.setImageURI(viewModel.userAvatar)
server_logo.setImageURI(viewModel.serverLogo)
setupAccountsList(headerLayout, accounts) setupAccountsList(headerLayout, accounts)
} }
} }
......
package chat.rocket.android.main.viewmodel package chat.rocket.android.main.viewmodel
import chat.rocket.common.model.UserStatus
data class NavHeaderViewModel( data class NavHeaderViewModel(
val username: String, val userDisplayName: String,
val server: String, val userStatus: UserStatus?,
val avatar: String?, val userAvatar: String?,
val serverUrl: String,
val serverLogo: String? val serverLogo: String?
) )
\ No newline at end of file
...@@ -5,21 +5,24 @@ import chat.rocket.android.server.domain.* ...@@ -5,21 +5,24 @@ import chat.rocket.android.server.domain.*
import chat.rocket.core.model.Myself import chat.rocket.core.model.Myself
import javax.inject.Inject import javax.inject.Inject
class NavHeaderViewModelMapper @Inject constructor(serverInteractor: GetCurrentServerInteractor, class NavHeaderViewModelMapper @Inject constructor(
getSettingsInteractor: GetSettingsInteractor) { serverInteractor: GetCurrentServerInteractor,
getSettingsInteractor: GetSettingsInteractor
) {
private val currentServer = serverInteractor.get()!! private val currentServer = serverInteractor.get()!!
private var settings: PublicSettings = getSettingsInteractor.get(currentServer) private var settings: PublicSettings = getSettingsInteractor.get(currentServer)
fun mapToViewModel(me: Myself): NavHeaderViewModel { fun mapToViewModel(me: Myself): NavHeaderViewModel {
val username = mapUsername(me) val displayName = mapDisplayName(me)
val thumb = me.username?.let { UrlHelper.getAvatarUrl(currentServer, it) } val status = me.status
val avatar = me.username?.let { UrlHelper.getAvatarUrl(currentServer, it) }
val image = settings.wideTile() ?: settings.faviconLarge() val image = settings.wideTile() ?: settings.faviconLarge()
val logo = image?.let { UrlHelper.getServerLogoUrl(currentServer, it) } val logo = image?.let { UrlHelper.getServerLogoUrl(currentServer, it) }
return NavHeaderViewModel(username, currentServer, thumb, logo) return NavHeaderViewModel(displayName, status, avatar, currentServer, logo)
} }
private fun mapUsername(me: Myself): String { private fun mapDisplayName(me: Myself): String {
val username = me.username val username = me.username
val realName = me.name val realName = me.name
val senderName = if (settings.useRealName()) realName else username val senderName = if (settings.useRealName()) realName else username
......
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
android:id="@+id/image_user_status" android:id="@+id/image_user_status"
android:layout_width="14dp" android:layout_width="14dp"
android:layout_height="14dp" android:layout_height="14dp"
android:src="@drawable/ic_status_online_24dp"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />
<TextView <TextView
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment