Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val dbVersion = dbVersionRepository.findOne(realm, AppConfig.DB_VERSION_KEY)
- if(dbVersion == null) {
- val result = dbVersionRepository.saveOrUpdate(realm, DbVersion(bo.phoneBookVersion))
- Log.d("TAG", result.toString())
- } else {
- dbVersion.apply {
- version = bo.phoneBookVersion
- dbVersionRepository.saveOrUpdate(realm, this)
- }
- }
- if(bo.entryList.isNotEmpty()) {
- when (bo.loadType) {
- ResponseType.FULL -> {
- repository.deleteAll(realm)
- bo.entryList.forEach { realmList.add(entryMapper.toRealmObject(realm, it)) }
- }
- ResponseType.PARTIAL -> {
- bo.entryList.filter { entryBO -> entryBO.action == EntryAction.ADD }
- .forEach { realmList.add(entryMapper.toRealmObject(realm, it)) }
- bo.entryList.filter { entryBO -> entryBO.action == EntryAction.MOD }
- .forEach {
- val entryToModify = repository.findOne(realm, it.phoneNumber)
- entryToModify?.address = it.address
- entryToModify?.division = it.division
- entryToModify?.emailaddress = it.emailAddress
- entryToModify?.fullname = it.fullname
- entryToModify?.picture = it.picture
- }
- bo.entryList.filter { entryBO -> entryBO.action == EntryAction.DEL }
- .forEach { repository.delete(realm, it.phoneNumber) }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement