From be2f6b4960c8d4533b2710af00d2f136fb2890e6 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 30 Nov 2023 16:48:33 +0300 Subject: [PATCH] migrate realmCourseActivity to kotlin --- .../myplanet/model/RealmCourseActivity.java | 135 ------------------ .../myplanet/model/RealmCourseActivity.kt | 78 ++++++++++ 2 files changed, 78 insertions(+), 135 deletions(-) delete mode 100644 app/src/main/java/org/ole/planet/myplanet/model/RealmCourseActivity.java create mode 100644 app/src/main/java/org/ole/planet/myplanet/model/RealmCourseActivity.kt diff --git a/app/src/main/java/org/ole/planet/myplanet/model/RealmCourseActivity.java b/app/src/main/java/org/ole/planet/myplanet/model/RealmCourseActivity.java deleted file mode 100644 index b130b63e8b..0000000000 --- a/app/src/main/java/org/ole/planet/myplanet/model/RealmCourseActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package org.ole.planet.myplanet.model; - -import com.google.gson.JsonObject; - -import org.ole.planet.myplanet.utilities.NetworkUtils; - -import java.util.Date; -import java.util.UUID; - -import io.realm.Realm; -import io.realm.RealmObject; -import io.realm.annotations.PrimaryKey; - -public class RealmCourseActivity extends RealmObject { - @PrimaryKey - private String id; - private String _id; - - private String createdOn; - - private String _rev; - - private long time; - - private String title; - - private String courseId; - - private String parentCode; - - private String type; - - private String user; - private String androidId; - - public String getCreatedOn() { - return createdOn; - } - - public void setCreatedOn(String createdOn) { - this.createdOn = createdOn; - } - - public String get_rev() { - return _rev; - } - - public void set_rev(String _rev) { - this._rev = _rev; - } - - public long getTime() { - return time; - } - - public void setTime(long time) { - this.time = time; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getCourseId() { - return courseId; - } - - public void setCourseId(String courseId) { - this.courseId = courseId; - } - - public String get_id() { - return _id; - } - - public void set_id(String _id) { - this._id = _id; - } - - public String getParentCode() { - return parentCode; - } - - public void setParentCode(String parentCode) { - this.parentCode = parentCode; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - } - - public static void createActivity(Realm realm, RealmUserModel userModel, RealmMyCourse course) { - if (!realm.isInTransaction()) realm.beginTransaction(); - RealmCourseActivity activity = realm.createObject(RealmCourseActivity.class, UUID.randomUUID().toString()); - activity.setType("visit"); - activity.setTitle(course.getCourseTitle()); - activity.setCourseId(course.getCourseId()); - activity.setTime(new Date().getTime()); - activity.setParentCode(userModel.getParentCode()); - activity.setCreatedOn(userModel.getPlanetCode()); - activity.setCreatedOn(userModel.getPlanetCode()); - activity.setUser(userModel.getName()); - realm.commitTransaction(); - } - - public static JsonObject serializeSerialize(RealmCourseActivity realm_courseActivities) { - JsonObject ob = new JsonObject(); - ob.addProperty("user", realm_courseActivities.getUser()); - ob.addProperty("courseId", realm_courseActivities.getCourseId()); - ob.addProperty("type", realm_courseActivities.getType()); - ob.addProperty("title", realm_courseActivities.getTitle()); - ob.addProperty("time", realm_courseActivities.getTime()); - ob.addProperty("createdOn", realm_courseActivities.getCreatedOn()); - ob.addProperty("parentCode", realm_courseActivities.getParentCode()); - ob.addProperty("androidId", NetworkUtils.getUniqueIdentifier()); - ob.addProperty("deviceName", NetworkUtils.getDeviceName()); - return ob; - } -} diff --git a/app/src/main/java/org/ole/planet/myplanet/model/RealmCourseActivity.kt b/app/src/main/java/org/ole/planet/myplanet/model/RealmCourseActivity.kt new file mode 100644 index 0000000000..52f25d026c --- /dev/null +++ b/app/src/main/java/org/ole/planet/myplanet/model/RealmCourseActivity.kt @@ -0,0 +1,78 @@ +package org.ole.planet.myplanet.model + +import com.google.gson.JsonObject +import io.realm.Realm +import io.realm.RealmObject +import io.realm.annotations.PrimaryKey +import org.ole.planet.myplanet.utilities.NetworkUtils +import java.util.Date +import java.util.UUID + +open class RealmCourseActivity : RealmObject() { + @PrimaryKey + private var _id: String? = null + @JvmField + var createdOn: String? = null + private var _rev: String? = null + @JvmField + var time: Long = 0 + @JvmField + var title: String? = null + @JvmField + var courseId: String? = null + @JvmField + var parentCode: String? = null + @JvmField + var type: String? = null + @JvmField + var user: String? = null + fun get_rev(): String? { + return _rev + } + + fun set_rev(_rev: String?) { + this._rev = _rev + } + + fun get_id(): String? { + return _id + } + + fun set_id(_id: String?) { + this._id = _id + } + + companion object { + @JvmStatic + fun createActivity(realm: Realm, userModel: RealmUserModel, course: RealmMyCourse) { + if (!realm.isInTransaction) realm.beginTransaction() + val activity = realm.createObject( + RealmCourseActivity::class.java, UUID.randomUUID().toString() + ) + activity.type = "visit" + activity.title = course.courseTitle + activity.courseId = course.courseId + activity.time = Date().time + activity.parentCode = userModel.parentCode + activity.createdOn = userModel.planetCode + activity.createdOn = userModel.planetCode + activity.user = userModel.name + realm.commitTransaction() + } + + @JvmStatic + fun serializeSerialize(realm_courseActivities: RealmCourseActivity): JsonObject { + val ob = JsonObject() + ob.addProperty("user", realm_courseActivities.user) + ob.addProperty("courseId", realm_courseActivities.courseId) + ob.addProperty("type", realm_courseActivities.type) + ob.addProperty("title", realm_courseActivities.title) + ob.addProperty("time", realm_courseActivities.time) + ob.addProperty("createdOn", realm_courseActivities.createdOn) + ob.addProperty("parentCode", realm_courseActivities.parentCode) + ob.addProperty("androidId", NetworkUtils.getUniqueIdentifier()) + ob.addProperty("deviceName", NetworkUtils.getDeviceName()) + return ob + } + } +} \ No newline at end of file