Selaa lähdekoodia

migrate generic OCS to kotlin data classes + interface

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger 3 vuotta sitten
vanhempi
commit
0c824120e3

+ 1 - 1
app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java

@@ -968,7 +968,7 @@ public class SettingsController extends BaseController {
 
 
                     @Override
                     @Override
                     public void onNext(@io.reactivex.annotations.NonNull GenericOverall genericOverall) {
                     public void onNext(@io.reactivex.annotations.NonNull GenericOverall genericOverall) {
-                        int statusCode = genericOverall.ocs.meta.statusCode;
+                        int statusCode = Objects.requireNonNull(genericOverall.getMeta()).getStatusCode();
                         if (statusCode == 200) {
                         if (statusCode == 200) {
                             dialog.dismiss();
                             dialog.dismiss();
                             Toast.makeText(context, context.getResources().getString(
                             Toast.makeText(context, context.getResources().getString(

+ 5 - 4
app/src/main/java/com/nextcloud/talk/jobs/AccountRemovalWorker.java

@@ -55,6 +55,7 @@ import javax.inject.Inject;
 import java.io.IOException;
 import java.io.IOException;
 import java.net.CookieManager;
 import java.net.CookieManager;
 import java.util.HashMap;
 import java.util.HashMap;
+import java.util.Objects;
 import java.util.zip.CRC32;
 import java.util.zip.CRC32;
 
 
 @AutoInjector(NextcloudTalkApplication.class)
 @AutoInjector(NextcloudTalkApplication.class)
@@ -104,13 +105,13 @@ public class AccountRemovalWorker extends Worker {
                             .blockingSubscribe(new Observer<GenericOverall>() {
                             .blockingSubscribe(new Observer<GenericOverall>() {
                                 @Override
                                 @Override
                                 public void onSubscribe(@NotNull Disposable d) {
                                 public void onSubscribe(@NotNull Disposable d) {
-
+                                    // unused atm
                                 }
                                 }
 
 
                                 @Override
                                 @Override
                                 public void onNext(@NotNull GenericOverall genericOverall) {
                                 public void onNext(@NotNull GenericOverall genericOverall) {
-                                    if (genericOverall.getOcs().getMeta().getStatusCode() == 200
-                                            || genericOverall.getOcs().getMeta().getStatusCode() == 202) {
+                                    if (Objects.requireNonNull(genericOverall.getMeta()).getStatusCode() == 200 ||
+                                        genericOverall.getMeta().getStatusCode() == 202) {
                                         HashMap<String, String> queryMap = new HashMap<>();
                                         HashMap<String, String> queryMap = new HashMap<>();
                                         queryMap.put("deviceIdentifier",
                                         queryMap.put("deviceIdentifier",
                                                      finalPushConfigurationState.getDeviceIdentifier());
                                                      finalPushConfigurationState.getDeviceIdentifier());
@@ -128,7 +129,7 @@ public class AccountRemovalWorker extends Worker {
 
 
                                 @Override
                                 @Override
                                 public void onComplete() {
                                 public void onComplete() {
-
+                                    // unused atm
                                 }
                                 }
                             });
                             });
                 } else {
                 } else {

+ 0 - 107
app/src/main/java/com/nextcloud/talk/models/json/generic/GenericMeta.java

@@ -1,107 +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(serializeNullObjects = true)
-public class GenericMeta {
-    @JsonField(name = "status")
-    public String status;
-
-    @JsonField(name = "statuscode")
-    public int statusCode;
-
-    @JsonField(name = "message")
-    public String message;
-
-    public String getStatus() {
-        return this.status;
-    }
-
-    public int getStatusCode() {
-        return this.statusCode;
-    }
-
-    public String getMessage() {
-        return this.message;
-    }
-
-    public void setStatus(String status) {
-        this.status = status;
-    }
-
-    public void setStatusCode(int statusCode) {
-        this.statusCode = statusCode;
-    }
-
-    public void setMessage(String message) {
-        this.message = message;
-    }
-
-    public boolean equals(final Object o) {
-        if (o == this) {
-            return true;
-        }
-        if (!(o instanceof GenericMeta)) {
-            return false;
-        }
-        final GenericMeta other = (GenericMeta) o;
-        if (!other.canEqual((Object) this)) {
-            return false;
-        }
-        final Object this$status = this.getStatus();
-        final Object other$status = other.getStatus();
-        if (this$status == null ? other$status != null : !this$status.equals(other$status)) {
-            return false;
-        }
-        if (this.getStatusCode() != other.getStatusCode()) {
-            return false;
-        }
-        final Object this$message = this.getMessage();
-        final Object other$message = other.getMessage();
-
-        return this$message == null ? other$message == null : this$message.equals(other$message);
-    }
-
-    protected boolean canEqual(final Object other) {
-        return other instanceof GenericMeta;
-    }
-
-    public int hashCode() {
-        final int PRIME = 59;
-        int result = 1;
-        final Object $status = this.getStatus();
-        result = result * PRIME + ($status == null ? 43 : $status.hashCode());
-        result = result * PRIME + this.getStatusCode();
-        final Object $message = this.getMessage();
-        result = result * PRIME + ($message == null ? 43 : $message.hashCode());
-        return result;
-    }
-
-    public String toString() {
-        return "GenericMeta(status=" + this.getStatus() + ", statusCode=" + this.getStatusCode() + ", message=" + this.getMessage() + ")";
-    }
-}

+ 41 - 0
app/src/main/java/com/nextcloud/talk/models/json/generic/GenericMeta.kt

@@ -0,0 +1,41 @@
+/*
+ * 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(serializeNullObjects = true)
+data class GenericMeta(
+    @JsonField(name = ["status"])
+    var status: String? = null,
+    @JsonField(name = ["statuscode"])
+    var statusCode: Int = 0,
+    @JsonField(name = ["message"])
+    var message: String? = null
+) : Parcelable {
+    // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
+    constructor() : this(null, 0, null)
+}

+ 0 - 41
app/src/main/java/com/nextcloud/talk/models/json/generic/GenericOCS.java

@@ -30,45 +30,4 @@ import org.parceler.Parcel;
 public class GenericOCS {
 public class GenericOCS {
     @JsonField(name = "meta")
     @JsonField(name = "meta")
     public GenericMeta meta;
     public GenericMeta meta;
-
-    public GenericMeta getMeta() {
-        return this.meta;
-    }
-
-    public void setMeta(GenericMeta meta) {
-        this.meta = meta;
-    }
-
-    public boolean equals(final Object o) {
-        if (o == this) {
-            return true;
-        }
-        if (!(o instanceof GenericOCS)) {
-            return false;
-        }
-        final GenericOCS other = (GenericOCS) o;
-        if (!other.canEqual((Object) this)) {
-            return false;
-        }
-        final Object this$meta = this.getMeta();
-        final Object other$meta = other.getMeta();
-
-        return this$meta == null ? other$meta == null : this$meta.equals(other$meta);
-    }
-
-    protected boolean canEqual(final Object other) {
-        return other instanceof GenericOCS;
-    }
-
-    public int hashCode() {
-        final int PRIME = 59;
-        int result = 1;
-        final Object $meta = this.getMeta();
-        result = result * PRIME + ($meta == null ? 43 : $meta.hashCode());
-        return result;
-    }
-
-    public String toString() {
-        return "GenericOCS(meta=" + this.getMeta() + ")";
-    }
 }
 }

+ 0 - 74
app/src/main/java/com/nextcloud/talk/models/json/generic/GenericOverall.java

@@ -1,74 +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 GenericOverall {
-    @JsonField(name = "ocs")
-    public GenericOCS ocs;
-
-    public GenericOCS getOcs() {
-        return this.ocs;
-    }
-
-    public void setOcs(GenericOCS ocs) {
-        this.ocs = ocs;
-    }
-
-    public boolean equals(final Object o) {
-        if (o == this) {
-            return true;
-        }
-        if (!(o instanceof GenericOverall)) {
-            return false;
-        }
-        final GenericOverall other = (GenericOverall) o;
-        if (!other.canEqual((Object) this)) {
-            return false;
-        }
-        final Object this$ocs = this.getOcs();
-        final Object other$ocs = other.getOcs();
-
-        return this$ocs == null ? other$ocs == null : this$ocs.equals(other$ocs);
-    }
-
-    protected boolean canEqual(final Object other) {
-        return other instanceof GenericOverall;
-    }
-
-    public int hashCode() {
-        final int PRIME = 59;
-        int result = 1;
-        final Object $ocs = this.getOcs();
-        result = result * PRIME + ($ocs == null ? 43 : $ocs.hashCode());
-        return result;
-    }
-
-    public String toString() {
-        return "GenericOverall(ocs=" + this.getOcs() + ")";
-    }
-}

+ 40 - 0
app/src/main/java/com/nextcloud/talk/models/json/generic/GenericOverall.kt

@@ -0,0 +1,40 @@
+/*
+ *
+ *   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 android.os.Parcelable
+import com.bluelinelabs.logansquare.annotation.JsonField
+import com.bluelinelabs.logansquare.annotation.JsonObject
+import kotlinx.android.parcel.Parcelize
+
+@Parcelize
+@JsonObject
+data class GenericOverall(
+    @JsonField(name = ["meta"])
+    var meta: GenericMeta? = null
+) : IGenericOCS, Parcelable {
+    // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
+    constructor() : this(null)
+
+    override fun getGenericMeta(): GenericMeta? {
+        return meta
+    }
+}

+ 24 - 0
app/src/main/java/com/nextcloud/talk/models/json/generic/IGenericOCS.kt

@@ -0,0 +1,24 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Andy Scherzinger
+ * Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
+ *
+ * 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
+
+interface IGenericOCS {
+    fun getGenericMeta(): GenericMeta?
+}

+ 10 - 2
app/src/main/java/com/nextcloud/talk/models/json/notifications/NotificationOCS.kt

@@ -24,15 +24,23 @@ package com.nextcloud.talk.models.json.notifications
 import android.os.Parcelable
 import android.os.Parcelable
 import com.bluelinelabs.logansquare.annotation.JsonField
 import com.bluelinelabs.logansquare.annotation.JsonField
 import com.bluelinelabs.logansquare.annotation.JsonObject
 import com.bluelinelabs.logansquare.annotation.JsonObject
+import com.nextcloud.talk.models.json.generic.GenericMeta
 import com.nextcloud.talk.models.json.generic.GenericOCS
 import com.nextcloud.talk.models.json.generic.GenericOCS
+import com.nextcloud.talk.models.json.generic.IGenericOCS
 import kotlinx.android.parcel.Parcelize
 import kotlinx.android.parcel.Parcelize
 
 
 @Parcelize
 @Parcelize
 @JsonObject
 @JsonObject
 data class NotificationOCS(
 data class NotificationOCS(
+    @JsonField(name = ["meta"])
+    var meta: GenericMeta?,
     @JsonField(name = ["data"])
     @JsonField(name = ["data"])
     var notification: Notification?
     var notification: Notification?
-) : GenericOCS(), Parcelable {
+) : IGenericOCS, Parcelable {
     // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
     // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
-    constructor() : this(null)
+    constructor() : this(null, null)
+
+    override fun getGenericMeta(): GenericMeta? {
+        return meta
+    }
 }
 }

+ 1 - 1
app/src/main/java/com/nextcloud/talk/ui/dialog/MessageActionsDialog.kt

@@ -318,7 +318,7 @@ class MessageActionsDialog(
                 }
                 }
 
 
                 override fun onNext(@NonNull genericOverall: GenericOverall) {
                 override fun onNext(@NonNull genericOverall: GenericOverall) {
-                    val statusCode = genericOverall.ocs.meta.statusCode
+                    val statusCode = genericOverall.meta?.statusCode
                     if (statusCode == HTTP_CREATED) {
                     if (statusCode == HTTP_CREATED) {
                         chatController.updateAdapterAfterSendReaction(message, emoji)
                         chatController.updateAdapterAfterSendReaction(message, emoji)
                     }
                     }