I am making an android application. And I need to update data in real time with relationships. How can i do this? In the backend, the column with relations was removed from the checkbox.
class AlarmBackendlessHelpers {
private val alarmData: IDataStore = Backendless.Data.of(Alarm::class.java)
var alarmList: ArrayList<Alarm> = ArrayList()
private val rtHandlers: EventHandler<Alarm> = alarmData.rt()
var ownerId: String = UserIdStorageFactory.instance().storage.get()
fun enableRealTime(
adapter: AlarmsRecyclerViewAdapter
) {
rtHandlers.addCreateListener("ownerId = '$ownerId'", object : AsyncCallback<Alarm> {
override fun handleResponse(response: Alarm?) {
if (response != null) {
alarmList.add(response)
adapter.setArrayList(alarmList)
Log.e("back", response.toString())
}
}
override fun handleFault(fault: BackendlessFault?) {
Log.e("back", fault!!.message)
}
})
rtHandlers.addUpdateListener("ownerId = '$ownerId'", object : AsyncCallback<Alarm> {
override fun handleResponse(response: Alarm?) {
for (i in alarmList.indices) {
if (alarmList[i].objectId == response?.objectId) {
if (response != null) {
alarmList[i] = response
}
}
}
adapter.setArrayList(alarmList)
Log.e("back", response!!.toString())
}
override fun handleFault(fault: BackendlessFault?) {
Log.e("back", fault!!.message)
}
})
rtHandlers.addDeleteListener("ownerId = '$ownerId'", object : AsyncCallback<Alarm> {
override fun handleResponse(response: Alarm?) {
val iterator: MutableIterator<*> = alarmList.iterator()
while (iterator.hasNext()) {
val alarm: Alarm = iterator.next() as Alarm
if (alarm.objectId == response?.objectId) {
iterator.remove()
}
}
Log.e("back", response!!.toString())
adapter.setArrayList(alarmList)
}
override fun handleFault(fault: BackendlessFault?) {
Log.e("back", fault!!.message)
}
})
}
fun getAlarm(
adapter: AlarmsRecyclerViewAdapter
) {
val queryBuilder = DataQueryBuilder.create()
queryBuilder.setPageSize(100)
queryBuilder.setSortBy("created")
queryBuilder.addRelated("groupUsers")
queryBuilder.whereClause = "ownerId = '$ownerId'"
alarmData.find(queryBuilder, object : AsyncCallback<List<Alarm>> {
override fun handleResponse(response: List<Alarm>?) {
// pBar.progressBar(false, mBinding.progressBar, mBinding.alarmListView)
if (response != null) {
alarmList = ArrayList(response)
adapter.setArrayList(alarmList)
Log.e("back", response.toString())
}
}
override fun handleFault(fault: BackendlessFault?) {
}
})
}
fun getAlarmRing(
objectId: String
): Alarm {
var mAlarm = Alarm()
alarmData.findById(objectId, object : AsyncCallback<Alarm> {
override fun handleResponse(response: Alarm?) {
// pBar.progressBar(false, mBinding.progressBar, mBinding.alarmListView)
if (response != null) {
mAlarm = response
Log.e("back", response.toString())
}
}
override fun handleFault(fault: BackendlessFault?) {
}
})
return mAlarm
}
}