-
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.
Browse files
Browse the repository at this point in the history
…2761) Co-authored-by: dogi <[email protected]>
- Loading branch information
Showing
5 changed files
with
149 additions
and
189 deletions.
There are no files selected for viewing
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
174 changes: 0 additions & 174 deletions
174
app/src/main/java/org/ole/planet/myplanet/model/RealmAchievement.java
This file was deleted.
Oops, something went wrong.
134 changes: 134 additions & 0 deletions
134
app/src/main/java/org/ole/planet/myplanet/model/RealmAchievement.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,134 @@ | ||
package org.ole.planet.myplanet.model | ||
|
||
import android.text.TextUtils | ||
import android.widget.EditText | ||
import com.google.gson.Gson | ||
import com.google.gson.JsonArray | ||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonObject | ||
import io.realm.Realm | ||
import io.realm.RealmList | ||
import io.realm.RealmObject | ||
import io.realm.annotations.PrimaryKey | ||
import org.ole.planet.myplanet.utilities.JsonUtils | ||
import org.ole.planet.myplanet.utilities.Utilities | ||
|
||
open class RealmAchievement : RealmObject() { | ||
@JvmField | ||
var achievements: RealmList<String>? = null | ||
@JvmField | ||
var references: RealmList<String>? = null | ||
@JvmField | ||
var purpose: String? = null | ||
@JvmField | ||
var achievementsHeader: String? = null | ||
@JvmField | ||
var sendToNation: String? = null | ||
private var _rev: String? = null | ||
|
||
@PrimaryKey | ||
private var _id: String? = null | ||
@JvmField | ||
var goals: 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 | ||
} | ||
|
||
fun getreferences(): RealmList<String>? { | ||
return references | ||
} | ||
|
||
val achievementsArray: JsonArray | ||
get() { | ||
val array = JsonArray() | ||
for (s in achievements!!) { | ||
val ob = Gson().fromJson(s, JsonElement::class.java) | ||
array.add(ob) | ||
} | ||
return array | ||
} | ||
|
||
fun getreferencesArray(): JsonArray { | ||
val array = JsonArray() | ||
for (s in references!!) { | ||
val ob = Gson().fromJson(s, JsonElement::class.java) | ||
array.add(ob) | ||
} | ||
return array | ||
} | ||
|
||
fun setAchievements(ac: JsonArray) { | ||
achievements = RealmList() | ||
for (el in ac) { | ||
val achi = Gson().toJson(el) | ||
if (!achievements!!.contains(achi)) achievements!!.add(achi) | ||
} | ||
} | ||
|
||
fun setreferences(of: JsonArray?) { | ||
references = RealmList() | ||
if (of == null) return | ||
for (el in of) { | ||
Utilities.log("Set references") | ||
val e = Gson().toJson(el) | ||
if (!references!!.contains(e)) references!!.add(e) | ||
} | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
fun serialize(sub: RealmAchievement): JsonObject { | ||
val `object` = JsonObject() | ||
`object`.addProperty("_id", sub.get_id()) | ||
if (!TextUtils.isEmpty(sub.get_rev())) `object`.addProperty("_rev", sub.get_rev()) | ||
`object`.addProperty("goals", sub.goals) | ||
`object`.addProperty("purpose", sub.purpose) | ||
`object`.addProperty("achievementsHeader", sub.achievementsHeader) | ||
`object`.add("references", sub.getreferencesArray()) | ||
`object`.add("achievements", sub.achievementsArray) | ||
Utilities.log(Gson().toJson(`object`)) | ||
return `object` | ||
} | ||
|
||
@JvmStatic | ||
fun createReference( | ||
name: String?, | ||
relation: EditText, | ||
phone: EditText, | ||
email: EditText | ||
): JsonObject { | ||
val ob = JsonObject() | ||
ob.addProperty("name", name) | ||
ob.addProperty("phone", phone.text.toString()) | ||
ob.addProperty("relationship", relation.text.toString()) | ||
ob.addProperty("email", email.text.toString()) | ||
return ob | ||
} | ||
|
||
fun insert(mRealm: Realm, act: JsonObject?) { | ||
var achievement = mRealm.where(RealmAchievement::class.java) | ||
.equalTo("_id", JsonUtils.getString("_id", act)).findFirst() | ||
if (achievement == null) achievement = mRealm.createObject( | ||
RealmAchievement::class.java, JsonUtils.getString("_id", act) | ||
) | ||
achievement!!.set_rev(JsonUtils.getString("_rev", act)) | ||
achievement.purpose = JsonUtils.getString("purpose", act) | ||
achievement.goals = JsonUtils.getString("goals", act) | ||
achievement.achievementsHeader = JsonUtils.getString("achievementsHeader", act) | ||
achievement.setreferences(JsonUtils.getJsonArray("references", act)) | ||
achievement.setAchievements(JsonUtils.getJsonArray("achievements", act)) | ||
} | ||
} | ||
} |
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
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