Unverified Commit c53b4e73 authored by Rafael Kellermann Streit's avatar Rafael Kellermann Streit Committed by GitHub

Merge pull request #1483 from RocketChat/fix/cannot-change-server

[FIX] Cannot change server
parents 71652d27 bd5ed027
...@@ -69,16 +69,34 @@ class MainPresenter @Inject constructor( ...@@ -69,16 +69,34 @@ class MainPresenter @Inject constructor(
fun toCreateChannel() = navigator.toCreateChannel() fun toCreateChannel() = navigator.toCreateChannel()
fun loadServerAccounts() {
launchUI(strategy) {
try {
view.setupServerAccountList(getAccountsInteractor.get())
} catch (ex: Exception) {
when (ex) {
is RocketChatAuthException -> logout()
else -> {
Timber.d(ex, "Error loading serve accounts")
ex.message?.let {
view.showMessage(it)
}.ifNull {
view.showGenericErrorMessage()
}
}
}
}
}
}
fun loadCurrentInfo() { fun loadCurrentInfo() {
checkServerInfo(currentServer) checkServerInfo(currentServer)
launchUI(strategy) { launchUI(strategy) {
try { try {
val me = retryIO("me") { val me = retryIO("me") { client.me() }
client.me()
}
val model = navHeaderMapper.mapToUiModel(me) val model = navHeaderMapper.mapToUiModel(me)
saveAccount(model) saveAccount(model)
view.setupNavHeader(model, getAccountsInteractor.get()) view.setupUserAccountInfo(model)
} catch (ex: Exception) { } catch (ex: Exception) {
when (ex) { when (ex) {
is RocketChatAuthException -> { is RocketChatAuthException -> {
...@@ -208,8 +226,6 @@ class MainPresenter @Inject constructor( ...@@ -208,8 +226,6 @@ class MainPresenter @Inject constructor(
} }
} }
private suspend fun updateMyself(myself: Myself) { private fun updateMyself(myself: Myself) =
val model = navHeaderMapper.mapToUiModel(myself) view.setupUserAccountInfo(navHeaderMapper.mapToUiModel(myself))
view.setupNavHeader(model, getAccountsInteractor.get())
}
} }
\ No newline at end of file
...@@ -16,17 +16,24 @@ interface MainView : MessageView, VersionCheckView { ...@@ -16,17 +16,24 @@ interface MainView : MessageView, VersionCheckView {
fun showUserStatus(userStatus: UserStatus) fun showUserStatus(userStatus: UserStatus)
/** /**
* Setups the navigation header. * Setups the user account info (displayed in the nav. header)
* *
* @param uiModel The [NavHeaderUiModel]. * @param uiModel The [NavHeaderUiModel].
* @param accounts The list of accounts.
*/ */
fun setupNavHeader(uiModel: NavHeaderUiModel, accounts: List<Account>) fun setupUserAccountInfo(uiModel: NavHeaderUiModel)
/**
* Setups the server account list.
*
* @param serverAccountList The list of server accounts.
*/
fun setupServerAccountList(serverAccountList: List<Account>)
fun closeServerSelection() fun closeServerSelection()
fun invalidateToken(token: String) fun invalidateToken(token: String)
fun showProgress() fun showProgress()
fun hideProgress() fun hideProgress()
} }
\ No newline at end of file
...@@ -10,7 +10,6 @@ import androidx.appcompat.app.AppCompatActivity ...@@ -10,7 +10,6 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import android.view.Gravity import android.view.Gravity
import android.view.MenuItem import android.view.MenuItem
import android.view.View
import androidx.annotation.IdRes import androidx.annotation.IdRes
import androidx.drawerlayout.widget.DrawerLayout import androidx.drawerlayout.widget.DrawerLayout
import chat.rocket.android.BuildConfig import chat.rocket.android.BuildConfig
...@@ -56,6 +55,7 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, ...@@ -56,6 +55,7 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
private var expanded = false private var expanded = false
private val headerLayout by lazy { view_navigation.getHeaderView(0) } private val headerLayout by lazy { view_navigation.getHeaderView(0) }
private var chatRoomId: String? = null private var chatRoomId: String? = null
private var progressDialog : ProgressDialog? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this) AndroidInjection.inject(this)
...@@ -75,6 +75,7 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, ...@@ -75,6 +75,7 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
chatRoomId = intent.getStringExtra(INTENT_CHAT_ROOM_ID) chatRoomId = intent.getStringExtra(INTENT_CHAT_ROOM_ID)
presenter.connect() presenter.connect()
presenter.loadServerAccounts()
presenter.loadCurrentInfo() presenter.loadCurrentInfo()
setupToolbar() setupToolbar()
setupNavigationView() setupNavigationView()
...@@ -119,8 +120,7 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, ...@@ -119,8 +120,7 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
} }
} }
override fun setupNavHeader(uiModel: NavHeaderUiModel, accounts: List<Account>) { override fun setupUserAccountInfo(uiModel: NavHeaderUiModel) {
Timber.d("Setting up nav header: $uiModel")
with(headerLayout) { with(headerLayout) {
with(uiModel) { with(uiModel) {
if (userStatus != null) { if (userStatus != null) {
...@@ -139,10 +139,43 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, ...@@ -139,10 +139,43 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
} }
text_server_url.text = uiModel.serverUrl text_server_url.text = uiModel.serverUrl
} }
setupAccountsList(headerLayout, accounts)
} }
} }
override fun setupServerAccountList(serverAccountList: List<Account>) {
accounts_list.layoutManager = LinearLayoutManager(this)
accounts_list.adapter = AccountsAdapter(serverAccountList, object : Selector {
override fun onStatusSelected(userStatus: UserStatus) {
presenter.changeDefaultStatus(userStatus)
}
override fun onAccountSelected(serverUrl: String) {
presenter.changeServer(serverUrl)
}
override fun onAddedAccountSelected() {
presenter.addNewServer()
}
})
headerLayout.account_container.setOnClickListener {
it.image_account_expand.rotateBy(180f)
if (expanded) {
accounts_list.fadeOut()
} else {
accounts_list.fadeIn()
}
expanded = !expanded
}
headerLayout.image_avatar.setOnClickListener {
view_navigation.menu.findItem(R.id.action_update_profile).isChecked = true
presenter.toUserProfile()
drawer_layout.closeDrawer(Gravity.START)
}
}
override fun closeServerSelection() { override fun closeServerSelection() {
view_navigation.getHeaderView(0).account_container.performClick() view_navigation.getHeaderView(0).account_container.performClick()
} }
...@@ -174,9 +207,8 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, ...@@ -174,9 +207,8 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
.show() .show()
} }
override fun invalidateToken(token: String) { override fun invalidateToken(token: String) =
FirebaseInstanceId.getInstance().deleteToken(token, FirebaseMessaging.INSTANCE_ID_SCOPE) FirebaseInstanceId.getInstance().deleteToken(token, FirebaseMessaging.INSTANCE_ID_SCOPE)
}
override fun showMessage(resId: Int) = showToast(resId) override fun showMessage(resId: Int) = showToast(resId)
...@@ -221,57 +253,14 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, ...@@ -221,57 +253,14 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
} }
} }
private fun setupAccountsList(header: View, accounts: List<Account>) { fun getDrawerLayout(): DrawerLayout = drawer_layout
accounts_list.layoutManager = LinearLayoutManager(this)
accounts_list.adapter = AccountsAdapter(accounts, object : Selector {
override fun onStatusSelected(userStatus: UserStatus) {
presenter.changeDefaultStatus(userStatus)
}
override fun onAccountSelected(serverUrl: String) {
presenter.changeServer(serverUrl)
}
override fun onAddedAccountSelected() {
presenter.addNewServer()
}
})
header.account_container.setOnClickListener { fun openDrawer() = drawer_layout.openDrawer(Gravity.START)
header.image_account_expand.rotateBy(180f)
if (expanded) {
accounts_list.fadeOut()
} else {
accounts_list.fadeIn()
}
expanded = !expanded fun closeDrawer() = drawer_layout.closeDrawer(Gravity.START)
}
header.image_avatar.setOnClickListener {
view_navigation.menu.findItem(R.id.action_update_profile).isChecked = true
presenter.toUserProfile()
drawer_layout.closeDrawer(Gravity.START)
}
}
fun getDrawerLayout(): DrawerLayout {
return drawer_layout
}
fun openDrawer() {
drawer_layout.openDrawer(Gravity.START)
}
fun closeDrawer() {
drawer_layout.closeDrawer(Gravity.START)
}
fun setCheckedNavDrawerItem(@IdRes item: Int) { fun setCheckedNavDrawerItem(@IdRes item: Int) = view_navigation.setCheckedItem(item)
view_navigation.setCheckedItem(item)
}
private var progressDialog : ProgressDialog? = null
override fun showProgress() { override fun showProgress() {
progressDialog = ProgressDialog.show(this, getString(R.string.app_name), getString(R.string.msg_log_out), true, false) progressDialog = ProgressDialog.show(this, getString(R.string.app_name), getString(R.string.msg_log_out), true, false)
} }
......
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