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

Add recommended and minimum required version checks

parent feafda0f
......@@ -30,12 +30,16 @@ android {
buildTypes {
release {
buildConfigField "String", "REQUIRED_SERVER_VERSION", '"0.62.0"'
buildConfigField "String", "RECOMMENDED_SERVER_VERSION", '"0.63.0"'
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
buildConfigField "String", "REQUIRED_SERVER_VERSION", '"0.62.0"'
buildConfigField "String", "RECOMMENDED_SERVER_VERSION", '"0.63.0"'
applicationIdSuffix ".dev"
}
}
......
package chat.rocket.android.authentication.login.presentation
import chat.rocket.android.BuildConfig
import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.helper.NetworkHelper
......@@ -268,17 +269,33 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
private fun checkServerInfo() {
launchUI(strategy) {
val serverInfo = client.serverInfo()
val isNiceVersion = isRequiredVersionOk(serverInfo.version)
if (isNiceVersion) {
Timber.i("Your version is nice! (Requires: 0.62.0, Yours: ${serverInfo.version})")
val thisServerVersion = serverInfo.version
val isRequiredVersion = isRequiredServerVersion(thisServerVersion)
val isRecommendedVersion = isRecommendedServerVersion(thisServerVersion)
if (isRequiredVersion) {
if (isRecommendedVersion) {
view.alertNotRecommendedVersion()
} else {
Timber.i("Your version is nice! (Requires: 0.62.0, Yours: $thisServerVersion)")
}
} else {
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 isRequiredServerVersion(version: String): Boolean {
return isMinimumVersion(version, getVersionDistilled(BuildConfig.REQUIRED_SERVER_VERSION))
}
private fun isRecommendedServerVersion(version: String): Boolean {
return isMinimumVersion(version, getVersionDistilled(BuildConfig.RECOMMENDED_SERVER_VERSION))
}
private fun isRequiredVersionOk(version: String): Boolean {
val required = getVersionDistilled("0.62.0")
private fun isMinimumVersion(version: String, required: VersionInfo): Boolean {
val thisVersion = getVersionDistilled(version)
with(thisVersion) {
if (major < required.major) {
......
......@@ -186,4 +186,14 @@ interface LoginView : LoadingView, MessageView, InternetView {
* Alerts the user about a wrong inputted password.
*/
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 {
text_password.requestFocus()
}
override fun alertNotRecommendedVersion() {
}
override fun blockAndAlertNotRequiredVersion() {
}
private fun showRemainingSocialAccountsView() {
social_accounts_container.postDelayed({
(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