Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2458 from RocketChat/beta
Browse files Browse the repository at this point in the history
[RELEASE] Merge BETA into MASTER
  • Loading branch information
philipbrito authored Aug 20, 2019
2 parents 413f10c + 7025fdc commit 4e8bc44
Show file tree
Hide file tree
Showing 22 changed files with 159 additions and 48 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId "chat.rocket.android"
minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk
versionCode 2074
versionName "3.5.0"
versionCode 2075
versionName "3.5.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true

Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:sharedUserId="chat.rocket.android"
package="chat.rocket.android">

<uses-permission android:name="android.permission.INTERNET" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ class LoginPresenter @Inject constructor(
icon,
logo,
username,
thumb
thumb,
token?.userId,
token?.authToken
)
saveAccountInteractor.save(account)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ class LoginOptionsPresenter @Inject constructor(
icon,
logo,
username,
thumb
thumb,
token?.userId,
token?.authToken
)
saveAccountInteractor.save(account)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class RegisterUsernamePresenter @Inject constructor(
icon,
logo,
username,
thumb
thumb,
token?.userId,
token?.authToken
)
saveAccountInteractor.save(account)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ class SignupPresenter @Inject constructor(
icon,
logo,
me.username!!,
thumb
thumb,
token?.userId,
token?.authToken
)
saveAccountInteractor.save(account)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ class TwoFAPresenter @Inject constructor(
icon,
logo,
me.username!!,
thumb
thumb,
token?.userId,
token?.authToken
)
saveAccountInteractor.save(account)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DrawableHelper
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -143,6 +144,7 @@ class ChatRoomActivity : AppCompatActivity(), HasSupportFragmentInjector {
text_toolbar_title,
DrawableHelper.getDrawableFromId(R.drawable.ic_chatroom_toolbar_expand_more_20dp, this)
)
text_toolbar_title.movementMethod = ScrollingMovementMethod()
text_toolbar_title.setOnClickListener { listener(it) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}

private fun setReactionButtonIcon(@DrawableRes drawableId: Int) {
button_add_reaction_or_show_keyboard.setImageResource(drawableId)
button_add_reaction_or_show_keyboard.tag = drawableId
button_add_reaction_or_show_keyboard?.setImageResource(drawableId)
button_add_reaction_or_show_keyboard?.tag = drawableId
}

override fun showFileSelection(filter: Array<String>?) {
Expand Down Expand Up @@ -929,9 +929,11 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}

button_send.setOnClickListener {
var textMessage = citation ?: ""
textMessage += text_message.textContent
sendMessage(textMessage)
text_message.textContent.run {
if(this.isNotBlank()) {
sendMessage(citation ?: "" + this)
}
}
}

button_show_attachment_options.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ import chat.rocket.common.RocketChatException
import chat.rocket.common.model.RoomType
import chat.rocket.common.model.User
import chat.rocket.common.model.roomTypeOf
import chat.rocket.core.internal.realtime.createDirectMessage
import chat.rocket.core.internal.rest.createDirectMessage
import chat.rocket.core.internal.rest.me
import chat.rocket.core.internal.rest.show
import kotlinx.coroutines.withTimeout
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Named
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

class ChatRoomsPresenter @Inject constructor(
private val view: ChatRoomsView,
Expand Down Expand Up @@ -140,8 +138,11 @@ class ChatRoomsPresenter @Inject constructor(
} else {
retryIO("createDirectMessage($name)") {
withTimeout(10000) {
createDirectMessage(name)
FetchChatRoomsInteractor(client, dbManager).refreshChatRooms()
try {
client.createDirectMessage(name)
} catch (ex: Exception) {
Timber.e(ex)
}
}
}
val fromTo = mutableListOf(myself.id, id).apply {
Expand All @@ -153,6 +154,8 @@ class ChatRoomsPresenter @Inject constructor(
id
}

FetchChatRoomsInteractor(client, dbManager).refreshChatRooms()

navigator.toChatRoom(
chatRoomId = id,
chatRoomName = roomName,
Expand Down Expand Up @@ -190,10 +193,4 @@ class ChatRoomsPresenter @Inject constructor(
}
return null
}

private suspend fun createDirectMessage(name: String): Boolean = suspendCoroutine { cont ->
client.createDirectMessage(name) { success, _ ->
cont.resume(success)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package chat.rocket.android.main.presentation

import chat.rocket.android.authentication.domain.model.DeepLinkInfo
import chat.rocket.android.core.behaviours.AppLanguageView
import chat.rocket.android.helper.UserHelper
import chat.rocket.android.push.GroupedPush
import chat.rocket.android.server.domain.GetCurrentLanguageInteractor
import chat.rocket.android.server.domain.RefreshPermissionsInteractor
import chat.rocket.android.server.domain.RefreshSettingsInteractor
import chat.rocket.android.server.domain.*
import chat.rocket.android.server.domain.model.Account
import chat.rocket.android.server.infrastructure.ConnectionManagerFactory
import chat.rocket.android.util.extensions.avatarUrl
import chat.rocket.android.util.extensions.serverLogoUrl
import javax.inject.Inject
import javax.inject.Named

Expand All @@ -16,10 +18,16 @@ class MainPresenter @Inject constructor(
private val appLanguageView: AppLanguageView,
private val refreshSettingsInteractor: RefreshSettingsInteractor,
private val refreshPermissionsInteractor: RefreshPermissionsInteractor,
private val getSettingsInteractor: GetSettingsInteractor,
private val connectionManagerFactory: ConnectionManagerFactory,
private var getLanguageInteractor: GetCurrentLanguageInteractor,
private val groupedPush: GroupedPush
private val groupedPush: GroupedPush,
private val tokenRepository: TokenRepository,
private val userHelper: UserHelper,
private val saveAccountInteractor: SaveAccountInteractor,
private val removeAccountInteractor: RemoveAccountInteractor
) {

fun connect() = currentServer?.let {
refreshSettingsInteractor.refreshAsync(it)
refreshPermissionsInteractor.refreshAsync(it)
Expand All @@ -44,4 +52,39 @@ class MainPresenter @Inject constructor(
}
}
}

fun removeOldAccount() = currentServer?.let {
removeAccountInteractor.remove(currentServer)
}

fun saveNewAccount() {
currentServer?.let { currentServer ->
with(getSettingsInteractor.get(currentServer)) {
val icon = favicon()?.let {
currentServer.serverLogoUrl(it)
}
val logo = wideTile()?.let {
currentServer.serverLogoUrl(it)
}
val token = tokenRepository.get(currentServer)
val thumb = currentServer.avatarUrl(
userHelper.username() ?: "",
token?.userId,
token?.authToken
)

val account = Account(
siteName() ?: currentServer,
currentServer,
icon,
logo,
userHelper.username() ?: "",
thumb,
token?.userId,
token?.authToken
)
saveAccountInteractor.save(account)
}
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class MainActivity : AppCompatActivity(), HasActivityInjector,
with(presenter) {
connect()
getAppLanguage()
removeOldAccount()
saveNewAccount()
intent.getStringExtra(INTENT_CHAT_ROOM_ID).let {
clearNotificationsForChatRoom(it)
showChatList(it, deepLinkInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ProfilePresenter @Inject constructor(
username = username
)
}
view.showProfileUpdateSuccessfullyMessage()
view.onProfileUpdatedSuccessfully(email, name, username)
view.showProfile(
user.status.toString(),
serverUrl.avatarUrl(user.username!!, token?.userId, token?.authToken),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ interface ProfileView : TokenView, LoadingView, MessageView {
fun reloadUserAvatar(avatarUrl: String)

/**
* Shows a profile update successfully message
* It is called when the user profile was updated successfully.
*/
fun showProfileUpdateSuccessfullyMessage()
fun onProfileUpdatedSuccessfully(
updatedEmail: String,
updatedName: String,
updatedUserName: String
)
}
53 changes: 41 additions & 12 deletions app/src/main/java/chat/rocket/android/profile/ui/ProfileFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,13 @@ class ProfileFragment : Fragment(), ProfileView, ActionMode.Callback {

override fun reloadUserAvatar(avatarUrl: String) {
Fresco.getImagePipeline().evictFromCache(avatarUrl.toUri())
image_avatar.setImageURI(avatarUrl)
image_avatar?.setImageURI(avatarUrl)
}

override fun showProfileUpdateSuccessfullyMessage() {
override fun onProfileUpdatedSuccessfully(updatedEmail: String, updatedName: String, updatedUserName: String) {
currentEmail = updatedEmail
currentName = updatedName
currentUsername = updatedUserName
showMessage(getString(R.string.msg_profile_updated_successfully))
}

Expand Down Expand Up @@ -190,22 +193,22 @@ class ProfileFragment : Fragment(), ProfileView, ActionMode.Callback {
override fun onActionItemClicked(mode: ActionMode, menuItem: MenuItem): Boolean {
return when (menuItem.itemId) {
R.id.action_update_profile -> {
presenter.updateUserProfile(
text_email.textContent,
text_name.textContent,
text_username.textContent
)
updateProfile()
mode.finish()
true
}
else -> {
false
}
else -> false
}
}

override fun onDestroyActionMode(mode: ActionMode) {
actionMode = null
if (text_email.textContent != currentEmail
|| text_username.textContent != currentUsername
|| text_name.textContent != currentName
) {
showChangesNotSavedDialog()
}
}

private fun setupToolbar() {
Expand Down Expand Up @@ -287,8 +290,8 @@ class ProfileFragment : Fragment(), ProfileView, ActionMode.Callback {
text_email.asObservable()
) { text_name, text_username, text_email ->
return@combineLatest (text_name.toString() != currentName ||
text_username.toString() != currentUsername ||
text_email.toString() != currentEmail)
text_username.toString() != currentUsername ||
text_email.toString() != currentEmail)
}.subscribe { isValid ->
activity?.invalidateOptionsMenu()
if (isValid) {
Expand Down Expand Up @@ -375,4 +378,30 @@ class ProfileFragment : Fragment(), ProfileView, ActionMode.Callback {
}
}
}

private fun showChangesNotSavedDialog() {
context?.let {
val builder = AlertDialog.Builder(it)
builder.setMessage(R.string.msg_changes_not_saved)
.setPositiveButton(R.string.msg_save) { _, _ ->
updateProfile()
}
.setNegativeButton(android.R.string.cancel) { _, _ ->
text_email.setText(currentEmail)
text_username.setText(currentUsername)
text_name.setText(currentName)
}
.create()
.show()
}

}

private fun updateProfile() {
presenter.updateUserProfile(
text_email.textContent,
text_name.textContent,
text_username.textContent
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import se.ansman.kotshi.JsonSerializable
data class Account(
val serverName: String?,
val serverUrl: String,
val serverLogo: String?,
val serverBg: String?,
val serverLogoUrl: String?,
val serverBackgroundImageUrl: String?,
val userName: String,
val avatar: String?
val userAvatarUrl: String?,
val authToken: String?,
val userId: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ServerViewHolder(itemView: View, private val currentServerUrl: String) :

fun bind(account: Account) {
with(itemView) {
Glide.with(context).load(account.serverLogo).into(image_server)
Glide.with(context).load(account.serverLogoUrl).into(image_server)
text_server_name.text = account.serverName ?: account.serverUrl
text_server_url.text = account.serverUrl
image_check.isInvisible = currentServerUrl != account.serverUrl
Expand Down
Loading

0 comments on commit 4e8bc44

Please sign in to comment.