Commit 41e265b9 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Add recommended and minimum required version checks

parent feafda0f
...@@ -30,12 +30,16 @@ android { ...@@ -30,12 +30,16 @@ android {
buildTypes { buildTypes {
release { release {
buildConfigField "String", "REQUIRED_SERVER_VERSION", '"0.62.0"'
buildConfigField "String", "RECOMMENDED_SERVER_VERSION", '"0.63.0"'
signingConfig signingConfigs.release signingConfig signingConfigs.release
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
debug { debug {
buildConfigField "String", "REQUIRED_SERVER_VERSION", '"0.62.0"'
buildConfigField "String", "RECOMMENDED_SERVER_VERSION", '"0.63.0"'
applicationIdSuffix ".dev" applicationIdSuffix ".dev"
} }
} }
......
package chat.rocket.android.authentication.login.presentation package chat.rocket.android.authentication.login.presentation
import chat.rocket.android.BuildConfig
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
...@@ -268,17 +269,33 @@ class LoginPresenter @Inject constructor(private val view: LoginView, ...@@ -268,17 +269,33 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
private fun checkServerInfo() { private fun checkServerInfo() {
launchUI(strategy) { launchUI(strategy) {
val serverInfo = client.serverInfo() val serverInfo = client.serverInfo()
val isNiceVersion = isRequiredVersionOk(serverInfo.version) val thisServerVersion = serverInfo.version
if (isNiceVersion) { val isRequiredVersion = isRequiredServerVersion(thisServerVersion)
Timber.i("Your version is nice! (Requires: 0.62.0, Yours: ${serverInfo.version})") val isRecommendedVersion = isRecommendedServerVersion(thisServerVersion)
if (isRequiredVersion) {
if (isRecommendedVersion) {
view.alertNotRecommendedVersion()
} else {
Timber.i("Your version is nice! (Requires: 0.62.0, Yours: $thisServerVersion)")
}
} else { } else {
Timber.i("Oops. Looks like your server is out-of-date! Please, upgrade your server for a better experience!") if (!isRecommendedVersion) {
view.blockAndAlertNotRequiredVersion()
Timber.i("Oops. Looks like your server is out-of-date! Please, upgrade your server for a better experience!")
}
} }
} }
} }
private fun isRequiredVersionOk(version: String): Boolean { private fun isRequiredServerVersion(version: String): Boolean {
val required = getVersionDistilled("0.62.0") return isMinimumVersion(version, getVersionDistilled(BuildConfig.REQUIRED_SERVER_VERSION))
}
private fun isRecommendedServerVersion(version: String): Boolean {
return isMinimumVersion(version, getVersionDistilled(BuildConfig.RECOMMENDED_SERVER_VERSION))
}
private fun isMinimumVersion(version: String, required: VersionInfo): Boolean {
val thisVersion = getVersionDistilled(version) val thisVersion = getVersionDistilled(version)
with(thisVersion) { with(thisVersion) {
if (major < required.major) { if (major < required.major) {
......
...@@ -186,4 +186,14 @@ interface LoginView : LoadingView, MessageView, InternetView { ...@@ -186,4 +186,14 @@ interface LoginView : LoadingView, MessageView, InternetView {
* Alerts the user about a wrong inputted password. * Alerts the user about a wrong inputted password.
*/ */
fun alertWrongPassword() fun alertWrongPassword()
/**
* Alerts the user about the server version not meeting the recommended server version.
*/
fun alertNotRecommendedVersion()
/**
* Block user to proceed and alert him due to server having an unsupported server version.
*/
fun blockAndAlertNotRequiredVersion()
} }
\ No newline at end of file
...@@ -289,6 +289,14 @@ class LoginFragment : Fragment(), LoginView { ...@@ -289,6 +289,14 @@ class LoginFragment : Fragment(), LoginView {
text_password.requestFocus() text_password.requestFocus()
} }
override fun alertNotRecommendedVersion() {
}
override fun blockAndAlertNotRequiredVersion() {
}
private fun showRemainingSocialAccountsView() { private fun showRemainingSocialAccountsView() {
social_accounts_container.postDelayed({ social_accounts_container.postDelayed({
(0..social_accounts_container.childCount) (0..social_accounts_container.childCount)
......
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