-
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
Co-authored-by: dogi <[email protected]>
- Loading branch information
Showing
5 changed files
with
103 additions
and
140 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
127 changes: 0 additions & 127 deletions
127
app/src/main/java/org/ole/planet/myplanet/model/RealmMyLife.java
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
app/src/main/java/org/ole/planet/myplanet/model/RealmMyLife.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,88 @@ | ||
package org.ole.planet.myplanet.model | ||
|
||
import android.content.SharedPreferences | ||
import io.realm.Realm | ||
import io.realm.RealmObject | ||
import io.realm.annotations.PrimaryKey | ||
|
||
open class RealmMyLife : RealmObject { | ||
@PrimaryKey | ||
private var _id: String? = null | ||
@JvmField | ||
var imageId: String? = null | ||
@JvmField | ||
var userId: String? = null | ||
@JvmField | ||
var title: String? = null | ||
@JvmField | ||
var isVisible = false | ||
@JvmField | ||
var weight = 0 | ||
|
||
constructor(imageId: String?, userId: String?, title: String?) { | ||
this.imageId = imageId | ||
this.userId = userId | ||
this.title = title | ||
isVisible = true | ||
} | ||
|
||
constructor() | ||
|
||
fun get_id(): String? { | ||
return _id | ||
} | ||
|
||
fun set_id(_id: String?) { | ||
this._id = _id | ||
} | ||
|
||
companion object { | ||
fun getMyLifeByUserId(mRealm: Realm, settings: SharedPreferences): List<RealmMyLife> { | ||
val userId = settings.getString("userId", "--") | ||
return getMyLifeByUserId(mRealm, userId) | ||
} | ||
|
||
@JvmStatic | ||
fun getMyLifeByUserId(mRealm: Realm, userId: String?): List<RealmMyLife> { | ||
return mRealm.where(RealmMyLife::class.java).equalTo("userId", userId).findAll() | ||
.sort("weight") | ||
} | ||
|
||
fun createMyLife(myLife: RealmMyLife, mRealm: Realm, _id: String?) { | ||
if (!mRealm.isInTransaction) mRealm.beginTransaction() | ||
myLife.set_id(_id) | ||
mRealm.commitTransaction() | ||
} | ||
|
||
@JvmStatic | ||
fun updateWeight(weight: Int, _id: String?, realm: Realm, userId: String?) { | ||
realm.executeTransaction { realm -> | ||
var currentWeight = -1 | ||
val myLifeList = getMyLifeByUserId(realm, userId) | ||
for (item in myLifeList) { | ||
if (item.get_id()!!.contains(_id!!)) { | ||
currentWeight = item.weight | ||
item.weight = weight | ||
} | ||
} | ||
for (item in myLifeList) { | ||
if (currentWeight != -1 && item.weight == weight && !item.get_id()!!.contains(_id!!)) { | ||
item.weight = currentWeight | ||
} | ||
} | ||
} | ||
} | ||
|
||
@JvmStatic | ||
fun updateVisibility(isVisible: Boolean, _id: String?, realm: Realm, userId: String?) { | ||
realm.executeTransaction { realm -> | ||
val myLifeList = getMyLifeByUserId(realm, userId) | ||
for (item in myLifeList) { | ||
if (item.get_id()!!.contains(_id!!)) { | ||
item.isVisible = isVisible | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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