migrate Status to kotlin data class

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-05-14 15:24:55 +02:00
parent 0c824120e3
commit 90b9207b1a
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
3 changed files with 61 additions and 179 deletions

View File

@ -224,7 +224,7 @@ class ServerSelectionController :
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ status: Status ->
val productName = resources!!.getString(R.string.nc_server_product_name)
val versionString: String = status.getVersion().substring(0, status.getVersion().indexOf("."))
val versionString: String = status.version!!.substring(0, status.version!!.indexOf("."))
val version: Int = versionString.toInt()
if (isServerStatusQueryable(status) && version >= MIN_SERVER_MAJOR_VERSION) {
router.pushController(
@ -237,27 +237,27 @@ class ServerSelectionController :
.pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler())
)
} else if (!status.isInstalled) {
} else if (!status.installed) {
setErrorText(
String.format(
resources!!.getString(R.string.nc_server_not_installed), productName
)
)
} else if (status.isNeedsUpgrade) {
} else if (status.needsUpgrade) {
setErrorText(
String.format(
resources!!.getString(R.string.nc_server_db_upgrade_needed),
productName
)
)
} else if (status.isMaintenance) {
} else if (status.maintenance) {
setErrorText(
String.format(
resources!!.getString(R.string.nc_server_maintenance),
productName
)
)
} else if (!status.getVersion().startsWith("13.")) {
} else if (!status.version!!.startsWith("13.")) {
setErrorText(
String.format(
resources!!.getString(R.string.nc_server_version),
@ -297,7 +297,7 @@ class ServerSelectionController :
}
private fun isServerStatusQueryable(status: Status): Boolean {
return status.isInstalled && !status.isMaintenance && !status.isNeedsUpgrade
return status.installed && !status.maintenance && !status.needsUpgrade
}
private fun setErrorText(text: String) {

View File

@ -1,173 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017 Mario Danic (mario@lovelyhq.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.json.generic;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.parceler.Parcel;
@Parcel
@JsonObject
public class Status {
@JsonField(name = "installed")
public boolean installed;
@JsonField(name = "maintenance")
public boolean maintenance;
@JsonField(name = "upgrade")
public boolean needsUpgrade;
@JsonField(name = "version")
public String version;
@JsonField(name = "versionstring")
public String versionString;
@JsonField(name = "edition")
public String edition;
@JsonField(name = "productname")
public String productName;
public boolean isInstalled() {
return this.installed;
}
public boolean isMaintenance() {
return this.maintenance;
}
public boolean isNeedsUpgrade() {
return this.needsUpgrade;
}
public String getVersion() {
return this.version;
}
public String getVersionString() {
return this.versionString;
}
public String getEdition() {
return this.edition;
}
public String getProductName() {
return this.productName;
}
public void setInstalled(boolean installed) {
this.installed = installed;
}
public void setMaintenance(boolean maintenance) {
this.maintenance = maintenance;
}
public void setNeedsUpgrade(boolean needsUpgrade) {
this.needsUpgrade = needsUpgrade;
}
public void setVersion(String version) {
this.version = version;
}
public void setVersionString(String versionString) {
this.versionString = versionString;
}
public void setEdition(String edition) {
this.edition = edition;
}
public void setProductName(String productName) {
this.productName = productName;
}
public boolean equals(final Object o) {
if (o == this) {
return true;
}
if (!(o instanceof Status)) {
return false;
}
final Status other = (Status) o;
if (!other.canEqual((Object) this)) {
return false;
}
if (this.isInstalled() != other.isInstalled()) {
return false;
}
if (this.isMaintenance() != other.isMaintenance()) {
return false;
}
if (this.isNeedsUpgrade() != other.isNeedsUpgrade()) {
return false;
}
final Object this$version = this.getVersion();
final Object other$version = other.getVersion();
if (this$version == null ? other$version != null : !this$version.equals(other$version)) {
return false;
}
final Object this$versionString = this.getVersionString();
final Object other$versionString = other.getVersionString();
if (this$versionString == null ? other$versionString != null : !this$versionString.equals(other$versionString)) {
return false;
}
final Object this$edition = this.getEdition();
final Object other$edition = other.getEdition();
if (this$edition == null ? other$edition != null : !this$edition.equals(other$edition)) {
return false;
}
final Object this$productName = this.getProductName();
final Object other$productName = other.getProductName();
return this$productName == null ? other$productName == null : this$productName.equals(other$productName);
}
protected boolean canEqual(final Object other) {
return other instanceof Status;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + (this.isInstalled() ? 79 : 97);
result = result * PRIME + (this.isMaintenance() ? 79 : 97);
result = result * PRIME + (this.isNeedsUpgrade() ? 79 : 97);
final Object $version = this.getVersion();
result = result * PRIME + ($version == null ? 43 : $version.hashCode());
final Object $versionString = this.getVersionString();
result = result * PRIME + ($versionString == null ? 43 : $versionString.hashCode());
final Object $edition = this.getEdition();
result = result * PRIME + ($edition == null ? 43 : $edition.hashCode());
final Object $productName = this.getProductName();
result = result * PRIME + ($productName == null ? 43 : $productName.hashCode());
return result;
}
public String toString() {
return "Status(installed=" + this.isInstalled() + ", maintenance=" + this.isMaintenance() + ", needsUpgrade=" + this.isNeedsUpgrade() + ", version=" + this.getVersion() + ", versionString=" + this.getVersionString() + ", edition=" + this.getEdition() + ", productName=" + this.getProductName() + ")";
}
}

View File

@ -0,0 +1,55 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* @author Andy Scherzinger
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2017 Mario Danic (mario@lovelyhq.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.json.generic
import android.os.Parcelable
import com.bluelinelabs.logansquare.annotation.JsonField
import com.bluelinelabs.logansquare.annotation.JsonObject
import kotlinx.android.parcel.Parcelize
@Parcelize
@JsonObject
data class Status(
@JsonField(name = ["installed"])
var installed: Boolean = false,
@JsonField(name = ["maintenance"])
var maintenance: Boolean = false,
@JsonField(name = ["upgrade"])
var needsUpgrade: Boolean = false,
@JsonField(name = ["version"])
var version: String? = null,
@JsonField(name = ["versionstring"])
var versionString: String? = null,
@JsonField(name = ["edition"])
var edition: String? = null,
@JsonField(name = ["productname"])
var productName: String? = null
) : Parcelable {
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this(false, false, false, null, null, null, null)
}