Skip to content

Commit

Permalink
actions: refactor RealmApkLog model to kotlin (fixes #2756) (#2760)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Nov 30, 2023
1 parent 49ecde8 commit 889fe15
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 143 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/org/ole/planet/myplanet/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
135 changes: 0 additions & 135 deletions app/src/main/java/org/ole/planet/myplanet/model/RealmApkLog.java

This file was deleted.

90 changes: 90 additions & 0 deletions app/src/main/java/org/ole/planet/myplanet/model/RealmApkLog.kt
Original file line number Diff line number Diff line change
@@ -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`
}
}
}

0 comments on commit 889fe15

Please sign in to comment.