-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate realmCourseActivity to kotlin
- Loading branch information
Showing
2 changed files
with
78 additions
and
135 deletions.
There are no files selected for viewing
135 changes: 0 additions & 135 deletions
135
app/src/main/java/org/ole/planet/myplanet/model/RealmCourseActivity.java
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
app/src/main/java/org/ole/planet/myplanet/model/RealmCourseActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} |