diff --git a/app/build.gradle b/app/build.gradle index b1e14a7bf371a1c48584a7ec4a8c53227889b417..eae273369413a9fc59f26e2da044c759be19723e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,6 +47,10 @@ android { packagingOptions { exclude 'META-INF/core.kotlin_module' } + + lintOptions{ + disable 'MissingTranslation' + } } dependencies { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 89d8c80eed866795c4ddbbc1ba10bfd8789d0eba..a18f46305ff1a4ceef2dc2c1a306532829784438 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,7 +5,6 @@ <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.VIBRATE" /> - <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission diff --git a/app/src/main/java/chat/rocket/android/authentication/server/presentation/VersionCheckView.kt b/app/src/main/java/chat/rocket/android/authentication/server/presentation/VersionCheckView.kt index b8f62db71c490b3010d6ccd09efcefb0427167bb..4efdf60b1391168ad59d25aa45172cf1442365eb 100644 --- a/app/src/main/java/chat/rocket/android/authentication/server/presentation/VersionCheckView.kt +++ b/app/src/main/java/chat/rocket/android/authentication/server/presentation/VersionCheckView.kt @@ -11,8 +11,19 @@ interface VersionCheckView { */ fun blockAndAlertNotRequiredVersion() + /** + * Alerts the user that an error has occurred while checking the server version + * This is optional. + */ + fun errorCheckingServerVersion() {} + /** * Do some action if version is ok. This is optional. */ fun versionOk() {} + + /** + * Alters the user this protocol is invalid. This is optional. + */ + fun errorInvalidProtocol() {} } \ No newline at end of file diff --git a/app/src/main/java/chat/rocket/android/authentication/server/ui/ServerFragment.kt b/app/src/main/java/chat/rocket/android/authentication/server/ui/ServerFragment.kt index 70e1125bd6c283e3bc7ec09e5cbcddb8532effdc..593169eb3c5e8deb9474783e866bae4ee85b7169 100644 --- a/app/src/main/java/chat/rocket/android/authentication/server/ui/ServerFragment.kt +++ b/app/src/main/java/chat/rocket/android/authentication/server/ui/ServerFragment.kt @@ -8,6 +8,8 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.ViewTreeObserver +import android.widget.AdapterView +import android.widget.ArrayAdapter import chat.rocket.android.BuildConfig import chat.rocket.android.R import chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo @@ -38,6 +40,8 @@ class ServerFragment : Fragment(), ServerView { } } + private var protocol = "https://" + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) AndroidSupportInjection.inject(this) @@ -55,9 +59,40 @@ class ServerFragment : Fragment(), ServerView { deepLinkInfo?.let { val uri = Uri.parse(it.url) - uri?.let { text_server_protocol.hintContent = it.host } + uri?.let { text_server_url.hintContent = it.host } presenter.deepLink(it) } + + text_server_protocol.adapter = ArrayAdapter<String>(activity, + android.R.layout.simple_dropdown_item_1line, arrayOf("https://", "http://")) + text_server_protocol.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { + when(position) { + 0 -> { + protocol = "https://" + } + 1 -> { + ui{ + AlertDialog.Builder(it) + .setTitle(R.string.msg_warning) + .setMessage(R.string.msg_http_insecure) + .setPositiveButton(R.string.msg_proceed) { _, _ -> + protocol = "http://" + } + .setNegativeButton(R.string.msg_cancel) { _, _ -> + text_server_protocol.setSelection(0) + } + .setCancelable(false) + .create() + .show() + } + } + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + } + } } override fun onDestroyView() { @@ -129,13 +164,23 @@ class ServerFragment : Fragment(), ServerView { performConnect() } + override fun errorCheckingServerVersion() { + hideLoading() + showMessage(R.string.msg_error_checking_server_version) + } + + override fun errorInvalidProtocol() { + hideLoading() + showMessage(R.string.msg_invalid_server_protocol) + } + private fun performConnect() { ui { deepLinkInfo?.let { presenter.deepLink(it) }.ifNull { val url = text_server_url.textContent.ifEmpty(text_server_url.hintContent) - presenter.connect(text_server_protocol.textContent + url) + presenter.connect("${protocol}${url.sanitize()}") } } } @@ -149,7 +194,7 @@ class ServerFragment : Fragment(), ServerView { ui { button_connect.setOnClickListener { val url = text_server_url.textContent.ifEmpty(text_server_url.hintContent) - presenter.checkServer(text_server_protocol.textContent + url) + presenter.checkServer("${protocol}${url.sanitize()}") } } } diff --git a/app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt b/app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt index 76bccc5faac11ce14e05084350a9ec4a08576bcb..23708703de4fb113ee91367faa607f21dbe0d5f7 100644 --- a/app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt +++ b/app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt @@ -1,19 +1,15 @@ package chat.rocket.android.chatroom.ui -import android.Manifest import android.app.Activity import android.content.ClipData import android.content.ClipboardManager import android.content.Context import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.os.Handler import android.support.annotation.DrawableRes -import android.support.v4.app.ActivityCompat import android.support.v4.app.Fragment -import android.support.v4.content.ContextCompat import android.support.v7.widget.DefaultItemAnimator import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView @@ -468,29 +464,11 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR override fun showFileSelection(filter: Array<String>) { ui { - if (ContextCompat.checkSelfPermission(it, Manifest.permission.READ_EXTERNAL_STORAGE) - != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(it, - arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), - 1) - } else { - val intent = Intent(Intent.ACTION_GET_CONTENT) - intent.type = "*/*" - intent.putExtra(Intent.EXTRA_MIME_TYPES, filter) - startActivityForResult(intent, REQUEST_CODE_FOR_PERFORM_SAF) - } - } - } - - override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { - when (requestCode) { - 1 -> { - if (!(grantResults.isNotEmpty() && grantResults.first() == PackageManager.PERMISSION_GRANTED)) { - handler.postDelayed({ - ui { hideAttachmentOptions() } - }, 400) - } - } + val intent = Intent(Intent.ACTION_GET_CONTENT) + intent.type = "*/*" + intent.putExtra(Intent.EXTRA_MIME_TYPES, filter) + intent.addCategory(Intent.CATEGORY_OPENABLE) + startActivityForResult(intent, REQUEST_CODE_FOR_PERFORM_SAF) } } diff --git a/app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsPresenter.kt b/app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsPresenter.kt index 629625cc7e69a8f5f0d74ab3c96992ca1a7dd01a..979ca4b80ea1ccdbb5c9ea9b8a9826cf0d0257ed 100644 --- a/app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsPresenter.kt +++ b/app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsPresenter.kt @@ -118,6 +118,7 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView, type = RoomType.DIRECT_MESSAGE, user = SimpleUser(username = it.username, name = it.name, id = null), name = it.name ?: "", + status = null, fullName = it.name, readonly = false, updatedAt = null, @@ -144,6 +145,7 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView, type = it.type, user = it.user, name = it.name ?: "", + status = null, fullName = it.fullName, readonly = it.readonly, updatedAt = it.updatedAt, @@ -349,6 +351,7 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView, type = room.type, user = room.user ?: user, name = room.name ?: name, + status = null, fullName = room.fullName ?: fullName, readonly = room.readonly, updatedAt = room.updatedAt ?: updatedAt, @@ -382,6 +385,7 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView, type = subscription.type, user = subscription.user ?: user, name = subscription.name, + status = null, fullName = subscription.fullName ?: fullName, readonly = subscription.readonly ?: readonly, updatedAt = subscription.updatedAt ?: updatedAt, diff --git a/app/src/main/java/chat/rocket/android/server/infraestructure/ConnectionManager.kt b/app/src/main/java/chat/rocket/android/server/infraestructure/ConnectionManager.kt index 5a6cdcc9a0b9425ea3ce3e5883db9adb47efcc74..5eadf79377aaf068653e28f79949deec91787075 100644 --- a/app/src/main/java/chat/rocket/android/server/infraestructure/ConnectionManager.kt +++ b/app/src/main/java/chat/rocket/android/server/infraestructure/ConnectionManager.kt @@ -2,15 +2,15 @@ package chat.rocket.android.server.infraestructure import chat.rocket.common.model.BaseRoom import chat.rocket.core.RocketChatClient +import chat.rocket.core.internal.realtime.subscribeSubscriptions +import chat.rocket.core.internal.realtime.subscribeRooms +import chat.rocket.core.internal.realtime.subscribeUserData +import chat.rocket.core.internal.realtime.subscribeRoomMessages import chat.rocket.core.internal.realtime.unsubscribe import chat.rocket.core.internal.realtime.socket.connect import chat.rocket.core.internal.realtime.socket.disconnect import chat.rocket.core.internal.realtime.socket.model.State import chat.rocket.core.internal.realtime.socket.model.StreamMessage -import chat.rocket.core.internal.realtime.subscribeRoomMessages -import chat.rocket.core.internal.realtime.subscribeRooms -import chat.rocket.core.internal.realtime.subscribeSubscriptions -import chat.rocket.core.internal.realtime.subscribeUserDataChanges import chat.rocket.core.internal.rest.chatRooms import chat.rocket.core.model.Message import chat.rocket.core.model.Myself @@ -60,7 +60,7 @@ class ConnectionManager(internal val client: RocketChatClient) { Timber.d("Subscribed to rooms: $id") roomsId = id } - client.subscribeUserDataChanges { _, id -> + client.subscribeUserData { _, id -> Timber.d("Subscribed to the user: $id") userId = id } diff --git a/app/src/main/java/chat/rocket/android/server/presentation/CheckServerPresenter.kt b/app/src/main/java/chat/rocket/android/server/presentation/CheckServerPresenter.kt index 1dd0b7462b52ed9e08c9f1b4cc03aeedf37e14c4..b5ebbe0f5f26369ef3e6cec8917b375d87eb2f3f 100644 --- a/app/src/main/java/chat/rocket/android/server/presentation/CheckServerPresenter.kt +++ b/app/src/main/java/chat/rocket/android/server/presentation/CheckServerPresenter.kt @@ -7,6 +7,7 @@ import chat.rocket.android.server.infraestructure.RocketChatClientFactory import chat.rocket.android.util.VersionInfo import chat.rocket.android.util.extensions.launchUI import chat.rocket.android.util.retryIO +import chat.rocket.common.RocketChatInvalidProtocolException import chat.rocket.core.RocketChatClient import chat.rocket.core.internal.rest.serverInfo import kotlinx.coroutines.experimental.Deferred @@ -42,6 +43,14 @@ abstract class CheckServerPresenter constructor(private val strategy: CancelStra } } catch (ex: Exception) { Timber.d(ex, "Error getting server info") + when(ex) { + is RocketChatInvalidProtocolException -> { + view.errorInvalidProtocol() + } + else -> { + view.errorCheckingServerVersion() + } + } } } } diff --git a/app/src/main/java/chat/rocket/android/util/extensions/String.kt b/app/src/main/java/chat/rocket/android/util/extensions/String.kt index c3eebead0b7b1dbe0e855d26a0b9f0b05bb5afd9..f593dcaa7d7b212509c02a14cd3a4e9fdff43dee 100644 --- a/app/src/main/java/chat/rocket/android/util/extensions/String.kt +++ b/app/src/main/java/chat/rocket/android/util/extensions/String.kt @@ -4,12 +4,17 @@ import android.util.Patterns fun String.removeTrailingSlash(): String { return if (isNotEmpty() && this[length - 1] == '/') { - this.replace("/+$", "") + this.substring(0, length - 1) } else { this } } +fun String.sanitize(): String { + val tmp = this.trim() + return tmp.removeTrailingSlash() +} + fun String.avatarUrl(avatar: String, isGroupOrChannel: Boolean = false, format: String = "jpeg"): String { return if (isGroupOrChannel) { "${removeTrailingSlash()}/avatar/%23${avatar.removeTrailingSlash()}?format=$format" diff --git a/app/src/main/res/layout/fragment_authentication_server.xml b/app/src/main/res/layout/fragment_authentication_server.xml index c3c57ecec94e93c404198929711c1be5e0a99d45..dd827ed8480902e8f6085c56f1b5499adf71e645 100644 --- a/app/src/main/res/layout/fragment_authentication_server.xml +++ b/app/src/main/res/layout/fragment_authentication_server.xml @@ -18,24 +18,30 @@ android:id="@+id/text_server_url" style="@style/Authentication.EditText" android:layout_below="@id/text_headline" - android:layout_marginStart="-4dp" + android:layout_marginStart="-6dp" android:layout_marginTop="32dp" - android:layout_toEndOf="@id/text_server_protocol" + android:layout_toEndOf="@id/protocol_container" android:cursorVisible="false" android:hint="@string/default_server" android:imeOptions="actionDone" - android:digits="0123456789abcdefghijklmnopqrstuvwxyz.-/:" - android:inputType="textUri" - android:paddingEnd="0dp" - android:paddingStart="4dp" /> + android:inputType="text|textUri" + android:paddingEnd="0dp" /> - <TextView - android:id="@+id/text_server_protocol" - style="@style/Authentication.TextView" + <FrameLayout + android:id="@+id/protocol_container" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:background="@drawable/style_edit_text_authentication" + android:layout_marginStart="@dimen/screen_edge_left_and_right_margins" android:layout_below="@id/text_headline" - android:layout_marginTop="32dp" - android:gravity="center_vertical" - android:text="@string/default_protocol" /> + android:layout_marginTop="32dp"> + <Spinner + android:id="@+id/text_server_protocol" + android:spinnerMode="dropdown" + android:layout_width="120dp" + android:layout_height="50dp" + android:backgroundTint="@color/actionMenuColor" /> + </FrameLayout> <com.wang.avi.AVLoadingIndicatorView android:id="@+id/view_loading" diff --git a/app/src/main/res/values-hi-rIN/strings.xml b/app/src/main/res/values-hi-rIN/strings.xml index a5da355f9d6b85d66d8590c043b4e4eeef83b49d..5291b658f4392823c25acb43818b095cc7440644 100644 --- a/app/src/main/res/values-hi-rIN/strings.xml +++ b/app/src/main/res/values-hi-rIN/strings.xml @@ -1,4 +1,6 @@ -<resources> +<resources + xmlns:tools="http://schemas.android.com/tools" + tools:ignore="MissingTranslation"> <!-- Titles --> <string name="title_sign_in_your_server">अपने सरà¥à¤µà¤° में साइन इन करें</string> diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 5d240b4d7f81718a3c504f987784b43b19f3a0b1..2fb1eee3bb30152bca69c018d5f21e19bd01a074 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -89,6 +89,12 @@ <string name="msg_ver_not_minimum"> Parece que a versão do seu servidor está abaixo da mÃnima requerida %1$s.\nPor favor, atualize seus servidores antes de continuar! </string> + <string name="msg_proceed">CONTINUAR</string> + <string name="msg_cancel">CANCELAR</string> + <string name="msg_warning">AVISO</string> + <string name="msg_http_insecure">Usando HTTP, você estará conectando a um servidor não seguro, não recomendamos sua utilização.</string> + <string name="msg_error_checking_server_version">Ocorreu um erro verificando a versão do servidor, por favor tente novamente</string> + <string name="msg_invalid_server_protocol">O protocolo selecionado não é suportado pelo servidor, por favor utilize HTTPS e tente novamente</string> <!-- System messages --> <string name="message_room_name_changed">Nome da sala alterado para: %1$s por %2$s</string> @@ -130,12 +136,12 @@ <string name="max_file_size_exceeded">Tamanho de arquivo (%1$d bytes) excedeu tamanho máximo de upload (%2$d bytes)</string> <!-- Socket status --> - <string name="status_connected">conectado</string> - <string name="status_disconnected">desconetado</string> - <string name="status_connecting">conectando</string> - <string name="status_authenticating">autenticando</string> - <string name="status_disconnecting">desconectando</string> - <string name="status_waiting">conectando em %d segundos</string> + <string name="status_connected">Conectado</string> + <string name="status_disconnected">Desconetado</string> + <string name="status_connecting">Conectando</string> + <string name="status_authenticating">Autenticando</string> + <string name="status_disconnecting">Desconectando</string> + <string name="status_waiting">Conectando em %d segundos</string> <!--Suggestions--> <string name="suggest_all_description">Notifica todos nesta sala</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index af9cef020d834638157c748eb03623b0eb59d29a..d79430627e566f08ab890fe1099f9b9a3e42a705 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -90,6 +90,12 @@ <string name="msg_ver_not_minimum"> Looks like your server version is below the minimum required version %1$s.\nPlease upgrade your server to login! </string> + <string name="msg_proceed">PROCEED</string> + <string name="msg_cancel">CANCEL</string> + <string name="msg_warning">WARNING</string> + <string name="msg_http_insecure">When using HTTP, you\'re connecting to an insecure server. We don\'t recommend you doing that.</string> + <string name="msg_error_checking_server_version">An error has occurred while checking your server version, please try again</string> + <string name="msg_invalid_server_protocol">The selected protocol is not accepted by this server, try using HTTPS</string> <!-- System messages --> <string name="message_room_name_changed">Room name changed to: %1$s by %2$s</string> @@ -131,12 +137,12 @@ <string name="max_file_size_exceeded">File size %1$d bytes exceeded max upload size of %2$d bytes</string> <!-- Socket status --> - <string name="status_connected">connected</string> - <string name="status_disconnected">disconnected</string> - <string name="status_connecting">connecting</string> - <string name="status_authenticating">authenticating</string> - <string name="status_disconnecting">disconnecting</string> - <string name="status_waiting">connecting in %d seconds</string> + <string name="status_connected">Connected</string> + <string name="status_disconnected">Disconnected</string> + <string name="status_connecting">Connecting</string> + <string name="status_authenticating">Authenticating</string> + <string name="status_disconnecting">Disconnecting</string> + <string name="status_waiting">Connecting in %d seconds</string> <!--Suggestions--> <string name="suggest_all_description">Notify all in this room</string>