Created
March 18, 2020 12:53
-
-
Save FunkyMuse/005d2b736d58c27174a30ab76785484f to your computer and use it in GitHub Desktop.
RealmKeyHelper
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
class KeyHelper<E : RealmModel?>(var classFrom: Class<E>) { | |
fun getIds(db: Realm, idName: String): IdModel { | |
val idHelper = RealmIdModel() | |
val currentID = db.where(classFrom).max(idName) | |
if (currentID == null) { | |
idHelper.nextID = 1 | |
} else { | |
idHelper.nextID = currentID.toInt() + 1 | |
} | |
currentID?.let { | |
idHelper.currentID = it.toInt() | |
} | |
return idHelper | |
} | |
} | |
data class RealmIdModel(var currentID:Int=0, var nextID:Int=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment