From 889fe15507fa3bcf623d067abdd8ef1397817e4b Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 30 Nov 2023 21:11:36 +0300 Subject: [PATCH] actions: refactor `RealmApkLog` model to kotlin (fixes #2756) (#2760) Co-authored-by: dogi --- app/build.gradle | 4 +- .../ole/planet/myplanet/MainApplication.java | 12 +- .../planet/myplanet/model/RealmApkLog.java | 135 ------------------ .../ole/planet/myplanet/model/RealmApkLog.kt | 90 ++++++++++++ 4 files changed, 98 insertions(+), 143 deletions(-) delete mode 100644 app/src/main/java/org/ole/planet/myplanet/model/RealmApkLog.java create mode 100644 app/src/main/java/org/ole/planet/myplanet/model/RealmApkLog.kt diff --git a/app/build.gradle b/app/build.gradle index fc8af2840f..19e4ee5de8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1170 - versionName "0.11.70" + versionCode 1171 + versionName "0.11.71" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/MainApplication.java b/app/src/main/java/org/ole/planet/myplanet/MainApplication.java index 8e2eba4200..a6a1c37650 100644 --- a/app/src/main/java/org/ole/planet/myplanet/MainApplication.java +++ b/app/src/main/java/org/ole/planet/myplanet/MainApplication.java @@ -186,13 +186,13 @@ public void handleUncaughtException(Throwable e) { RealmApkLog log = mRealm.createObject(RealmApkLog.class, UUID.randomUUID().toString()); RealmUserModel model = new UserProfileDbHandler(this).getUserModel(); if (model != null) { - log.setParentCode(model.getParentCode()); - log.setCreatedOn(model.getPlanetCode()); + log.parentCode = model.getParentCode(); + log.createdOn = model.getPlanetCode(); } - log.setTime(new Date().getTime() + ""); - log.setPage(""); - log.setVersion(VersionUtils.getVersionName(this)); - log.setType(RealmApkLog.ERROR_TYPE_CRASH); + log.time = new Date().getTime() + ""; + log.page = ""; + log.version = VersionUtils.getVersionName(this); + log.type = RealmApkLog.ERROR_TYPE_CRASH; log.setError(e); mRealm.commitTransaction(); Intent homeIntent = new Intent(Intent.ACTION_MAIN); diff --git a/app/src/main/java/org/ole/planet/myplanet/model/RealmApkLog.java b/app/src/main/java/org/ole/planet/myplanet/model/RealmApkLog.java deleted file mode 100644 index 3643903f00..0000000000 --- a/app/src/main/java/org/ole/planet/myplanet/model/RealmApkLog.java +++ /dev/null @@ -1,135 +0,0 @@ -package org.ole.planet.myplanet.model; - -import android.content.Context; - -import com.google.gson.JsonObject; - -import org.ole.planet.myplanet.utilities.NetworkUtils; - -import io.realm.RealmObject; -import io.realm.annotations.Ignore; -import io.realm.annotations.PrimaryKey; - -public class RealmApkLog extends RealmObject { - @Ignore - public static final String ERROR_TYPE_EXCEPTION = "exception"; - @Ignore - public static final String ERROR_TYPE_CRASH = "crash"; - @Ignore - public static final String ERROR_TYPE_ANR = "AnR"; - @PrimaryKey - private String id; - private String type; - private String _rev; - private String error; - private String page; - private String parentCode; - private String version; - private String createdOn; - private String time; - - public String getId() { - return id; - } - - public String getParentCode() { - return parentCode; - } - - public void setParentCode(String parentCode) { - this.parentCode = parentCode; - } - - public String getCreatedOn() { - return createdOn; - } - - public void setCreatedOn(String createdOn) { - this.createdOn = createdOn; - } - - public String getTime() { - return time; - } - - public void setTime(String time) { - this.time = time; - } - - public void setId(String id) { - this.id = id; - } - - public String get_rev() { - return _rev; - } - - public void set_rev(String _rev) { - this._rev = _rev; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getError() { - return error; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public static JsonObject serialize(RealmApkLog log, Context context) { - JsonObject object = new JsonObject(); - object.addProperty("type", log.getType()); - object.addProperty("error", log.getError()); - object.addProperty("page", log.getPage()); - object.addProperty("time", log.getTime()); - object.addProperty("version", log.getVersion()); - object.addProperty("createdOn", log.getCreatedOn()); - object.addProperty("androidId", log.getCreatedOn()); - object.addProperty("createdOn", log.getCreatedOn()); - object.addProperty("androidId", NetworkUtils.getUniqueIdentifier()); - object.addProperty("deviceName", NetworkUtils.getDeviceName()); - object.addProperty("customDeviceName", NetworkUtils.getCustomDeviceName(context)); - object.addProperty("parentCode", log.getParentCode()); - return object; - } - - public void setError(Throwable e) { - - this.error += "--------- Stack trace ---------\n\n"; - appendReport(e); - this.error += "--------- Cause ---------\n\n"; - Throwable cause = e.getCause(); - appendReport(cause); - } - - private void appendReport(Throwable cause) { - if (cause != null) { - this.error += cause.toString() + "\n\n"; - StackTraceElement[] arr = cause.getStackTrace(); - for (int i = 0; i < arr.length; i++) { - this.error += " " + arr[i].toString() + "\n"; - } - } - this.error += "-------------------------------\n\n"; - } - - public String getPage() { - return page; - } - - public void setPage(String page) { - this.page = page; - } -} diff --git a/app/src/main/java/org/ole/planet/myplanet/model/RealmApkLog.kt b/app/src/main/java/org/ole/planet/myplanet/model/RealmApkLog.kt new file mode 100644 index 0000000000..f7698e4969 --- /dev/null +++ b/app/src/main/java/org/ole/planet/myplanet/model/RealmApkLog.kt @@ -0,0 +1,90 @@ +package org.ole.planet.myplanet.model + +import android.content.Context +import com.google.gson.JsonObject +import io.realm.RealmObject +import io.realm.annotations.Ignore +import io.realm.annotations.PrimaryKey +import org.ole.planet.myplanet.utilities.NetworkUtils + +open class RealmApkLog : RealmObject() { + @PrimaryKey + var id: String? = null + @JvmField + var type: String? = null + private var _rev: String? = null + @JvmField + var error: String? = null + @JvmField + var page: String? = null + @JvmField + var parentCode: String? = null + @JvmField + var version: String? = null + @JvmField + var createdOn: String? = null + @JvmField + var time: String? = null + fun get_rev(): String? { + return _rev + } + + fun set_rev(_rev: String?) { + this._rev = _rev + } + + fun setError(e: Throwable) { + error += "--------- Stack trace ---------\n\n" + appendReport(e) + error += "--------- Cause ---------\n\n" + val cause = e.cause + appendReport(cause) + } + + private fun appendReport(cause: Throwable?) { + if (cause != null) { + error += """ + $cause + + + """.trimIndent() + val arr = cause.stackTrace + for (i in arr.indices) { + error += """ ${arr[i]} +""" + } + } + error += "-------------------------------\n\n" + } + + companion object { + @JvmField + @Ignore + val ERROR_TYPE_EXCEPTION = "exception" + + @JvmField + @Ignore + val ERROR_TYPE_CRASH = "crash" + + @JvmField + @Ignore + val ERROR_TYPE_ANR = "AnR" + @JvmStatic + fun serialize(log: RealmApkLog, context: Context?): JsonObject { + val `object` = JsonObject() + `object`.addProperty("type", log.type) + `object`.addProperty("error", log.error) + `object`.addProperty("page", log.page) + `object`.addProperty("time", log.time) + `object`.addProperty("version", log.version) + `object`.addProperty("createdOn", log.createdOn) + `object`.addProperty("androidId", log.createdOn) + `object`.addProperty("createdOn", log.createdOn) + `object`.addProperty("androidId", NetworkUtils.getUniqueIdentifier()) + `object`.addProperty("deviceName", NetworkUtils.getDeviceName()) + `object`.addProperty("customDeviceName", NetworkUtils.getCustomDeviceName(context)) + `object`.addProperty("parentCode", log.parentCode) + return `object` + } + } +} \ No newline at end of file