Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
0488863a
Commit
0488863a
authored
Apr 18, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do version check when entering server url
parent
7b7997d5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
11 deletions
+67
-11
ServerPresenter.kt
...oid/authentication/server/presentation/ServerPresenter.kt
+15
-2
ServerView.kt
.../android/authentication/server/presentation/ServerView.kt
+1
-1
VersionCheckView.kt
...id/authentication/server/presentation/VersionCheckView.kt
+5
-0
ServerFragment.kt
...rocket/android/authentication/server/ui/ServerFragment.kt
+42
-5
CheckServerPresenter.kt
...ocket/android/server/presentation/CheckServerPresenter.kt
+4
-3
No files found.
app/src/main/java/chat/rocket/android/authentication/server/presentation/ServerPresenter.kt
View file @
0488863a
...
...
@@ -7,9 +7,10 @@ import chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.server.domain.GetAccountsInteractor
import
chat.rocket.android.server.domain.RefreshSettingsInteractor
import
chat.rocket.android.server.domain.SaveCurrentServerInteractor
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.server.presentation.CheckServerPresenter
import
chat.rocket.android.util.extensions.isValidUrl
import
chat.rocket.android.util.extensions.launchUI
import
chat.rocket.common.util.ifNull
import
javax.inject.Inject
class
ServerPresenter
@Inject
constructor
(
private
val
view
:
ServerView
,
...
...
@@ -17,7 +18,18 @@ class ServerPresenter @Inject constructor(private val view: ServerView,
private
val
navigator
:
AuthenticationNavigator
,
private
val
serverInteractor
:
SaveCurrentServerInteractor
,
private
val
refreshSettingsInteractor
:
RefreshSettingsInteractor
,
private
val
getAccountsInteractor
:
GetAccountsInteractor
)
{
private
val
getAccountsInteractor
:
GetAccountsInteractor
,
factory
:
RocketChatClientFactory
)
:
CheckServerPresenter
(
strategy
,
factory
,
view
)
{
fun
checkServer
(
server
:
String
)
{
if
(!
server
.
isValidUrl
())
{
view
.
showInvalidServerUrlMessage
()
}
else
{
view
.
showLoading
()
checkServerInfo
(
server
)
}
}
fun
connect
(
server
:
String
)
{
connectToServer
(
server
)
{
...
...
@@ -39,6 +51,7 @@ class ServerPresenter @Inject constructor(private val view: ServerView,
view
.
showLoading
()
try
{
checkServerInfo
(
server
)
refreshSettingsInteractor
.
refresh
(
server
)
serverInteractor
.
save
(
server
)
block
()
...
...
app/src/main/java/chat/rocket/android/authentication/server/presentation/ServerView.kt
View file @
0488863a
...
...
@@ -3,7 +3,7 @@ package chat.rocket.android.authentication.server.presentation
import
chat.rocket.android.core.behaviours.LoadingView
import
chat.rocket.android.core.behaviours.MessageView
interface
ServerView
:
LoadingView
,
MessageView
{
interface
ServerView
:
LoadingView
,
MessageView
,
VersionCheckView
{
/**
* Shows an invalid server URL message.
...
...
app/src/main/java/chat/rocket/android/authentication/server/presentation/VersionCheckView.kt
View file @
0488863a
...
...
@@ -10,4 +10,9 @@ interface VersionCheckView {
* Block user to proceed and alert him due to server having an unsupported server version.
*/
fun
blockAndAlertNotRequiredVersion
()
/**
* Do some action if version is ok. This is optional.
*/
fun
versionOk
()
{}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/server/ui/ServerFragment.kt
View file @
0488863a
package
chat.rocket.android.authentication.server.ui
import
android.app.AlertDialog
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewTreeObserver
import
chat.rocket.android.BuildConfig
import
chat.rocket.android.R
import
chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo
import
chat.rocket.android.authentication.server.presentation.ServerPresenter
...
...
@@ -17,7 +19,8 @@ import kotlinx.android.synthetic.main.fragment_authentication_server.*
import
javax.inject.Inject
class
ServerFragment
:
Fragment
(),
ServerView
{
@Inject
lateinit
var
presenter
:
ServerPresenter
@Inject
lateinit
var
presenter
:
ServerPresenter
private
var
deepLinkInfo
:
LoginDeepLinkInfo
?
=
null
private
val
layoutListener
=
ViewTreeObserver
.
OnGlobalLayoutListener
{
text_server_url
.
isCursorVisible
=
KeyboardHelper
.
isSoftKeyboardShown
(
relative_layout
.
rootView
)
...
...
@@ -74,7 +77,7 @@ class ServerFragment : Fragment(), ServerView {
}
}
override
fun
showMessage
(
resId
:
Int
){
override
fun
showMessage
(
resId
:
Int
)
{
ui
{
showToast
(
resId
)
}
...
...
@@ -90,15 +93,49 @@ class ServerFragment : Fragment(), ServerView {
showMessage
(
getString
(
R
.
string
.
msg_generic_error
))
}
override
fun
alertNotRecommendedVersion
()
{
ui
{
hideLoading
()
AlertDialog
.
Builder
(
it
)
.
setMessage
(
getString
(
R
.
string
.
msg_ver_not_recommended
,
BuildConfig
.
RECOMMENDED_SERVER_VERSION
))
.
setPositiveButton
(
R
.
string
.
msg_ok
,
{
_
,
_
->
val
url
=
text_server_url
.
textContent
.
ifEmpty
(
text_server_url
.
hintContent
)
presenter
.
connect
(
text_server_protocol
.
textContent
+
url
)
})
.
create
()
.
show
()
}
}
override
fun
blockAndAlertNotRequiredVersion
()
{
ui
{
hideLoading
()
AlertDialog
.
Builder
(
it
)
.
setMessage
(
getString
(
R
.
string
.
msg_ver_not_minimum
,
BuildConfig
.
REQUIRED_SERVER_VERSION
))
.
setPositiveButton
(
R
.
string
.
msg_ok
,
null
)
.
create
()
.
show
()
}
}
override
fun
versionOk
()
{
ui
{
val
url
=
text_server_url
.
textContent
.
ifEmpty
(
text_server_url
.
hintContent
)
presenter
.
connect
(
text_server_protocol
.
textContent
+
url
)
}
}
private
fun
enableUserInput
(
value
:
Boolean
)
{
button_connect
.
isEnabled
=
value
text_server_url
.
isEnabled
=
value
}
private
fun
setupOnClickListener
()
{
button_connect
.
setOnClickListener
{
val
url
=
text_server_url
.
textContent
.
ifEmpty
(
text_server_url
.
hintContent
)
presenter
.
connect
(
text_server_protocol
.
textContent
+
url
)
ui
{
button_connect
.
setOnClickListener
{
val
url
=
text_server_url
.
textContent
.
ifEmpty
(
text_server_url
.
hintContent
)
presenter
.
checkServer
(
text_server_protocol
.
textContent
+
url
)
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/presentation/CheckServerPresenter.kt
View file @
0488863a
...
...
@@ -18,17 +18,18 @@ abstract class CheckServerPresenter constructor(private val strategy: CancelStra
private
val
factory
:
RocketChatClientFactory
,
private
val
view
:
VersionCheckView
)
{
private
lateinit
var
currentServer
:
String
private
val
client
:
RocketChatClient
by
lazy
{
factory
.
create
(
currentServer
)
}
private
lateinit
var
client
:
RocketChatClient
internal
fun
checkServerInfo
(
serverUrl
:
String
):
Job
{
return
launchUI
(
strategy
)
{
try
{
currentServer
=
serverUrl
client
=
factory
.
create
(
currentServer
)
val
version
=
checkServerVersion
(
serverUrl
).
await
()
when
(
version
)
{
is
Version
.
VersionOk
->
{
Timber
.
i
(
"Your version is nice! (Requires: 0.62.0, Yours: ${version.version})"
)
view
.
versionOk
()
}
is
Version
.
RecommendedVersionWarning
->
{
Timber
.
i
(
"Your server ${version.version} is bellow recommended version ${BuildConfig.RECOMMENDED_SERVER_VERSION}"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment