Commit 689cffce authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Adds the rocket.chat domain for avoid typing it

parent 4b1f0c9e
package chat.rocket.android.authentication.server.ui package chat.rocket.android.authentication.server.ui
import android.os.Bundle import android.os.Bundle
import android.text.SpannableStringBuilder
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
...@@ -11,6 +12,7 @@ import android.widget.ScrollView ...@@ -11,6 +12,7 @@ import android.widget.ScrollView
import android.widget.Toast import android.widget.Toast
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.core.text.color
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
...@@ -51,6 +53,8 @@ class ServerFragment : Fragment(), ServerView { ...@@ -51,6 +53,8 @@ class ServerFragment : Fragment(), ServerView {
lateinit var analyticsManager: AnalyticsManager lateinit var analyticsManager: AnalyticsManager
private var deepLinkInfo: LoginDeepLinkInfo? = null private var deepLinkInfo: LoginDeepLinkInfo? = null
private var protocol = "https://" private var protocol = "https://"
private var isDomainAppended = false
private var appendedText = ""
private lateinit var serverUrlDisposable: Disposable private lateinit var serverUrlDisposable: Disposable
private val layoutListener = ViewTreeObserver.OnGlobalLayoutListener { private val layoutListener = ViewTreeObserver.OnGlobalLayoutListener {
if (KeyboardHelper.isSoftKeyboardShown(scroll_view.rootView)) { if (KeyboardHelper.isSoftKeyboardShown(scroll_view.rootView)) {
...@@ -131,7 +135,7 @@ class ServerFragment : Fragment(), ServerView { ...@@ -131,7 +135,7 @@ class ServerFragment : Fragment(), ServerView {
} }
private fun setupOnClickListener() = private fun setupOnClickListener() =
ui { _ -> ui {
button_connect.setOnClickListener { button_connect.setOnClickListener {
presenter.checkServer("$protocol${text_server_url.textContent.sanitize()}") presenter.checkServer("$protocol${text_server_url.textContent.sanitize()}")
} }
...@@ -244,17 +248,42 @@ class ServerFragment : Fragment(), ServerView { ...@@ -244,17 +248,42 @@ class ServerFragment : Fragment(), ServerView {
private fun subscribeEditText() { private fun subscribeEditText() {
serverUrlDisposable = text_server_url.asObservable() serverUrlDisposable = text_server_url.asObservable()
.filter { it.isNotBlank() } .filter { it.isNotBlank() }
.subscribe { .subscribe { processUserInput(it.toString()) }
if ("$protocol${it.toString()}".isValidUrl()) {
enableButtonConnect()
} else {
disableButtonConnect()
}
}
} }
private fun unsubscribeEditText() = serverUrlDisposable.dispose() private fun unsubscribeEditText() = serverUrlDisposable.dispose()
private fun processUserInput(text: String) {
if (text.last().toString() == "." && !isDomainAppended) {
addDomain()
} else if (isDomainAppended && text != appendedText) {
removeDomain()
}
if ("$protocol$text".isValidUrl()) {
enableButtonConnect()
} else {
disableButtonConnect()
}
}
private fun addDomain() {
val cursorPosition = text_server_url.length()
text_server_url.append(SpannableStringBuilder()
.color(R.color.colorAuthenticationSecondaryText) { append("rocket.chat") })
text_server_url.setSelection(cursorPosition)
appendedText = text_server_url.text.toString()
isDomainAppended = true
}
private fun removeDomain() {
text_server_url.setText(
text_server_url.text.toString().substring(0, text_server_url.selectionEnd)
)
text_server_url.setSelection(text_server_url.length())
isDomainAppended = false
}
private fun enableUserInput() { private fun enableUserInput() {
enableButtonConnect() enableButtonConnect()
text_server_url.isEnabled = true text_server_url.isEnabled = true
......
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