Unverified Commit 8fef2381 authored by Lucio Maciel's avatar Lucio Maciel Committed by GitHub

Merge pull request #700 from filipedelimabrito/hotfix

[FIX][BUG] Hotfix before initial v2 release.
parents 0de209d8 7e08d07c
...@@ -135,7 +135,7 @@ object DrawableHelper { ...@@ -135,7 +135,7 @@ object DrawableHelper {
.beginConfig() .beginConfig()
.useFont(Typeface.SANS_SERIF) .useFont(Typeface.SANS_SERIF)
.endConfig() .endConfig()
.buildRound(TextHelper.getFirstCharacter(string), getAvatarBackgroundColor(string)) .buildRoundRect(TextHelper.getFirstCharacter(string), getAvatarBackgroundColor(string), 4)
} }
/** /**
......
...@@ -194,7 +194,7 @@ class LoginFragment : Fragment(), LoginView { ...@@ -194,7 +194,7 @@ class LoginFragment : Fragment(), LoginView {
private fun setupSignUpListener() { private fun setupSignUpListener() {
val signUp = getString(R.string.title_sign_up) val signUp = getString(R.string.title_sign_up)
val newToRocketChat = String.format(getString(R.string.msg_new_to_rocket_chat), signUp) val newToRocketChat = String.format(getString(R.string.msg_new_user), signUp)
text_new_to_rocket_chat.text = newToRocketChat text_new_to_rocket_chat.text = newToRocketChat
......
...@@ -3,6 +3,7 @@ package chat.rocket.android.authentication.server.presentation ...@@ -3,6 +3,7 @@ package chat.rocket.android.authentication.server.presentation
import chat.rocket.android.authentication.presentation.AuthenticationNavigator import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.helper.NetworkHelper import chat.rocket.android.helper.NetworkHelper
import chat.rocket.android.helper.UrlHelper
import chat.rocket.android.server.domain.* import chat.rocket.android.server.domain.*
import chat.rocket.android.server.infraestructure.RocketChatClientFactory import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import chat.rocket.android.util.launchUI import chat.rocket.android.util.launchUI
...@@ -25,39 +26,43 @@ class ServerPresenter @Inject constructor(private val view: ServerView, ...@@ -25,39 +26,43 @@ class ServerPresenter @Inject constructor(private val view: ServerView,
HIDE_MUTE_UNMUTE, HIDE_TYPE_RU, ACCOUNT_CUSTOM_FIELDS) HIDE_MUTE_UNMUTE, HIDE_TYPE_RU, ACCOUNT_CUSTOM_FIELDS)
fun connect(server: String) { fun connect(server: String) {
try { if (!UrlHelper.isValidUrl(server)) {
client = factory.create(server) view.showInvalidServerUrl()
} catch (exception: InvalidParameterException) { } else {
exception.message?.let { try {
view.showMessage(it) client = factory.create(server)
}.ifNull { } catch (exception: InvalidParameterException) {
view.showGenericErrorMessage() exception.message?.let {
view.showMessage(it)
}.ifNull {
view.showGenericErrorMessage()
}
return
} }
return
}
client.let { rocketChatClient -> client.let { rocketChatClient ->
launchUI(strategy) { launchUI(strategy) {
if (NetworkHelper.hasInternetAccess()) { if (NetworkHelper.hasInternetAccess()) {
view.showLoading() view.showLoading()
try { try {
val settings = rocketChatClient.settings(*settingsFilter) val settings = rocketChatClient.settings(*settingsFilter)
settingsInteractor.save(server, settings) settingsInteractor.save(server, settings)
serverInteractor.save(server) serverInteractor.save(server)
navigator.toLogin() navigator.toLogin()
} catch (exception: Exception) { } catch (exception: Exception) {
exception.message?.let { exception.message?.let {
view.showMessage(it) view.showMessage(it)
}.ifNull { }.ifNull {
view.showGenericErrorMessage() view.showGenericErrorMessage()
}
} finally {
view.hideLoading()
} }
} finally { } else {
view.hideLoading() view.showNoInternetConnection()
} }
} else {
view.showNoInternetConnection()
} }
} }
} }
......
...@@ -4,4 +4,10 @@ import chat.rocket.android.core.behaviours.InternetView ...@@ -4,4 +4,10 @@ import chat.rocket.android.core.behaviours.InternetView
import chat.rocket.android.core.behaviours.LoadingView import chat.rocket.android.core.behaviours.LoadingView
import chat.rocket.android.core.behaviours.MessageView import chat.rocket.android.core.behaviours.MessageView
interface ServerView : LoadingView, MessageView, InternetView interface ServerView : LoadingView, MessageView, InternetView {
\ No newline at end of file
/**
* Notifies the user about an invalid inputted server URL.
*/
fun showInvalidServerUrl()
}
\ No newline at end of file
...@@ -44,6 +44,8 @@ class ServerFragment : Fragment(), ServerView { ...@@ -44,6 +44,8 @@ class ServerFragment : Fragment(), ServerView {
relative_layout.viewTreeObserver.removeOnGlobalLayoutListener(layoutListener) relative_layout.viewTreeObserver.removeOnGlobalLayoutListener(layoutListener)
} }
override fun showInvalidServerUrl() = showMessage(getString(R.string.msg_invalid_server_url))
override fun showLoading() { override fun showLoading() {
enableUserInput(false) enableUserInput(false)
view_loading.setVisibility(true) view_loading.setVisibility(true)
......
...@@ -15,6 +15,7 @@ import chat.rocket.android.util.textContent ...@@ -15,6 +15,7 @@ import chat.rocket.android.util.textContent
import chat.rocket.common.util.ifNull import chat.rocket.common.util.ifNull
import chat.rocket.core.model.Message import chat.rocket.core.model.Message
import com.facebook.drawee.view.SimpleDraweeView import com.facebook.drawee.view.SimpleDraweeView
import kotlinx.android.synthetic.main.avatar.view.*
import kotlinx.android.synthetic.main.item_message.view.* import kotlinx.android.synthetic.main.item_message.view.*
class ChatRoomAdapter(private val context: Context, class ChatRoomAdapter(private val context: Context,
...@@ -43,16 +44,16 @@ class ChatRoomAdapter(private val context: Context, ...@@ -43,16 +44,16 @@ class ChatRoomAdapter(private val context: Context,
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(message: Message) = with(itemView) { fun bind(message: Message) = with(itemView) {
bindUserAvatar(message, image_user_avatar, image_unknown_user) bindUserAvatar(message, image_avatar, image_unknown_avatar)
bindUserName(message, text_user_name) bindUserName(message, text_user_name)
bindTime(message, text_message_time) bindTime(message, text_message_time)
bindContent(message, text_content) bindContent(message, text_content)
} }
private fun bindUserAvatar(message: Message, drawee: SimpleDraweeView, imageUnknownUser: ImageView) = message.sender?.username.let { private fun bindUserAvatar(message: Message, drawee: SimpleDraweeView, imageUnknownAvatar: ImageView) = message.sender?.username.let {
drawee.setImageURI(UrlHelper.getAvatarUrl(serverUrl, it.toString())) drawee.setImageURI(UrlHelper.getAvatarUrl(serverUrl, it.toString()))
}.ifNull { }.ifNull {
imageUnknownUser.setVisibility(true) imageUnknownAvatar.setVisibility(true)
} }
private fun bindUserName(message: Message, textView: TextView) = message.sender?.username.let { private fun bindUserName(message: Message, textView: TextView) = message.sender?.username.let {
......
...@@ -16,6 +16,7 @@ import chat.rocket.android.util.textContent ...@@ -16,6 +16,7 @@ import chat.rocket.android.util.textContent
import chat.rocket.common.model.BaseRoom.RoomType import chat.rocket.common.model.BaseRoom.RoomType
import chat.rocket.core.model.ChatRoom import chat.rocket.core.model.ChatRoom
import com.facebook.drawee.view.SimpleDraweeView import com.facebook.drawee.view.SimpleDraweeView
import kotlinx.android.synthetic.main.avatar.view.*
import kotlinx.android.synthetic.main.item_chat.view.* import kotlinx.android.synthetic.main.item_chat.view.*
class ChatRoomsAdapter(private val context: Context, class ChatRoomsAdapter(private val context: Context,
...@@ -38,7 +39,7 @@ class ChatRoomsAdapter(private val context: Context, ...@@ -38,7 +39,7 @@ class ChatRoomsAdapter(private val context: Context,
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(chatRoom: ChatRoom) = with(itemView) { fun bind(chatRoom: ChatRoom) = with(itemView) {
bindAvatar(chatRoom, image_user_avatar, image_room_avatar) bindAvatar(chatRoom, layout_avatar, image_avatar, image_room_avatar)
bindName(chatRoom, text_chat_name) bindName(chatRoom, text_chat_name)
bindLastMessageDateTime(chatRoom, text_last_message_date_time) bindLastMessageDateTime(chatRoom, text_last_message_date_time)
bindLastMessage(chatRoom, text_last_message) bindLastMessage(chatRoom, text_last_message)
...@@ -47,14 +48,15 @@ class ChatRoomsAdapter(private val context: Context, ...@@ -47,14 +48,15 @@ class ChatRoomsAdapter(private val context: Context,
setOnClickListener { listener(chatRoom) } setOnClickListener { listener(chatRoom) }
} }
private fun bindAvatar(chatRoom: ChatRoom, drawee: SimpleDraweeView, imageView: ImageView) { private fun bindAvatar(chatRoom: ChatRoom, avatarLayout: View, drawee: SimpleDraweeView, imageView: ImageView) {
val chatRoomName = chatRoom.name val chatRoomName = chatRoom.name
if (chatRoom.type == RoomType.ONE_TO_ONE) { if (chatRoom.type == RoomType.ONE_TO_ONE) {
val serverUrl = chatRoom.client.url drawee.setImageURI(UrlHelper.getAvatarUrl(chatRoom.client.url, chatRoomName))
drawee.setImageURI(UrlHelper.getAvatarUrl(serverUrl, chatRoomName)) imageView.setVisibility(false)
drawee.setVisibility(true) avatarLayout.setVisibility(true)
} else { } else {
imageView.setImageDrawable(DrawableHelper.getTextDrawable(chatRoomName)) imageView.setImageDrawable(DrawableHelper.getTextDrawable(chatRoomName))
avatarLayout.setVisibility(false)
imageView.setVisibility(true) imageView.setVisibility(true)
} }
} }
......
package chat.rocket.android.helper package chat.rocket.android.helper
import android.util.Patterns
object UrlHelper { object UrlHelper {
/** /**
...@@ -9,7 +11,7 @@ object UrlHelper { ...@@ -9,7 +11,7 @@ object UrlHelper {
* @param avatarName The avatar name. * @param avatarName The avatar name.
* @return The avatar URL. * @return The avatar URL.
*/ */
fun getAvatarUrl(serverUrl: String, avatarName: String): String = removeTrailingSlash(serverUrl)+ "/avatar/" + avatarName fun getAvatarUrl(serverUrl: String, avatarName: String): String = removeTrailingSlash(serverUrl) + "/avatar/" + avatarName
/** /**
* Returns the server's Terms of Service URL. * Returns the server's Terms of Service URL.
...@@ -40,4 +42,11 @@ object UrlHelper { ...@@ -40,4 +42,11 @@ object UrlHelper {
serverUrl serverUrl
} }
} }
/**
* Checks if the given URL is valid or not.
* @param url The url to check its valid.
* @return True if url is valid, false otherwise.
*/
fun isValidUrl(url: String): Boolean = Patterns.WEB_URL.matcher(url).matches()
} }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/image_avatar"
android:layout_width="40dp"
android:layout_height="40dp"
app:roundedCornerRadius="2dp" />
<!-- TODO define the correct bg color for this-->
<ImageView
android:id="@+id/image_unknown_avatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_help_black_24dp"
android:tint="@color/colorAccent"
android:visibility="gone"
tools:ignore="contentDescription" />
</LinearLayout>
\ No newline at end of file
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
android:cursorVisible="false" android:cursorVisible="false"
android:hint="@string/default_server" android:hint="@string/default_server"
android:imeOptions="actionDone" android:imeOptions="actionDone"
android:digits="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-/"
android:inputType="textUri" android:inputType="textUri"
android:paddingEnd="0dp" android:paddingEnd="0dp"
android:paddingStart="0dp" /> android:paddingStart="0dp" />
......
...@@ -18,13 +18,17 @@ ...@@ -18,13 +18,17 @@
app:layout_constraintRight_toLeftOf="@+id/middle_container" app:layout_constraintRight_toLeftOf="@+id/middle_container"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<com.facebook.drawee.view.SimpleDraweeView <include
android:id="@+id/image_user_avatar" android:id="@+id/layout_avatar"
layout="@layout/avatar"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:visibility="gone" android:visibility="gone" />
app:roundAsCircle="true" />
<!-- We need to build the avatar with initials since the server returns a SVG file with a pre defined 50x50 pixel.
TODO: check to scale the SVG file on the app and remove the view bellow (or make the server to return a jpg file.
SVG scaling with fresco is impossible: http://frescolib.org/docs/resizing.html
-->
<ImageView <ImageView
android:id="@+id/image_room_avatar" android:id="@+id/image_room_avatar"
android:layout_width="40dp" android:layout_width="40dp"
......
...@@ -9,25 +9,14 @@ ...@@ -9,25 +9,14 @@
android:layout_marginStart="@dimen/screen_edge_left_and_right_margins" android:layout_marginStart="@dimen/screen_edge_left_and_right_margins"
android:layout_marginTop="10dp"> android:layout_marginTop="10dp">
<com.facebook.drawee.view.SimpleDraweeView <include
android:id="@+id/image_user_avatar" android:id="@+id/layout_avatar"
android:layout_width="40dp" layout="@layout/avatar"
android:layout_height="40dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:roundAsCircle="true" />
<!-- TODO define the correct bg color for this-->
<ImageView
android:id="@+id/image_unknown_user"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:src="@drawable/ic_help_black_24dp" android:layout_marginTop="7dp"
android:tint="@color/colorAccent"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent" />
tools:ignore="contentDescription" />
<LinearLayout <LinearLayout
android:id="@+id/top_container" android:id="@+id/top_container"
...@@ -35,7 +24,7 @@ ...@@ -35,7 +24,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:orientation="horizontal" android:orientation="horizontal"
app:layout_constraintLeft_toRightOf="@+id/image_user_avatar"> app:layout_constraintLeft_toRightOf="@+id/layout_avatar">
<TextView <TextView
android:id="@+id/text_user_name" android:id="@+id/text_user_name"
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<!-- Regular information messages --> <!-- Regular information messages -->
<string name="msg_no_internet_connection">Sem conexão à internet</string> <string name="msg_no_internet_connection">Sem conexão à internet</string>
<string name="msg_invalid_server_url">URL de servidor inválida</string>
<string name="msg_generic_error">Desculpe, ocorreu um erro, tente novamente</string> <string name="msg_generic_error">Desculpe, ocorreu um erro, tente novamente</string>
<string name="msg_username">nome de usuário</string> <string name="msg_username">nome de usuário</string>
<string name="msg_username_or_email">nome de usuário ou email</string> <string name="msg_username_or_email">nome de usuário ou email</string>
...@@ -21,7 +22,7 @@ ...@@ -21,7 +22,7 @@
<string name="msg_name_and_surname">nome e sobrenome</string> <string name="msg_name_and_surname">nome e sobrenome</string>
<string name="msg_email">email</string> <string name="msg_email">email</string>
<string name="msg_or_continue_using_social_accounts">Ou continue através de contas sociais</string> <string name="msg_or_continue_using_social_accounts">Ou continue através de contas sociais</string>
<string name="msg_new_to_rocket_chat">Novo no Rocket Chat? %1$s</string> <string name="msg_new_user">Novo usuário? %1$s</string>
<string name="msg_new_user_agreement">Ao proceder você concorda com nossos %1$s e %2$s</string> <string name="msg_new_user_agreement">Ao proceder você concorda com nossos %1$s e %2$s</string>
<string name="msg_2fa_code">Código 2FA</string> <string name="msg_2fa_code">Código 2FA</string>
<string name="msg_invalid_2fa_code">Código 2FA inválido</string> <string name="msg_invalid_2fa_code">Código 2FA inválido</string>
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
<!-- Regular information messages --> <!-- Regular information messages -->
<string name="msg_no_internet_connection">No internet connection</string> <string name="msg_no_internet_connection">No internet connection</string>
<string name="msg_invalid_server_url">Invalid server URL</string>
<string name="msg_generic_error">Sorry, an error has occurred, please try again</string> <string name="msg_generic_error">Sorry, an error has occurred, please try again</string>
<string name="msg_username">username</string> <string name="msg_username">username</string>
<string name="msg_username_or_email">username or email</string> <string name="msg_username_or_email">username or email</string>
...@@ -22,7 +23,7 @@ ...@@ -22,7 +23,7 @@
<string name="msg_name_and_surname">name and surname</string> <string name="msg_name_and_surname">name and surname</string>
<string name="msg_email">email</string> <string name="msg_email">email</string>
<string name="msg_or_continue_using_social_accounts">Or continue using social accounts</string> <string name="msg_or_continue_using_social_accounts">Or continue using social accounts</string>
<string name="msg_new_to_rocket_chat">New to Rocket Chat? %1$s</string> <string name="msg_new_user">New user? %1$s</string>
<string name="msg_new_user_agreement">By proceeding you are agreeing to our\n%1$s and %2$s</string> <string name="msg_new_user_agreement">By proceeding you are agreeing to our\n%1$s and %2$s</string>
<string name="msg_2fa_code">2FA Code</string> <string name="msg_2fa_code">2FA Code</string>
<string name="msg_invalid_2fa_code">Invalid 2FA Code</string> <string name="msg_invalid_2fa_code">Invalid 2FA Code</string>
......
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