mirror of https://github.com/tasks/tasks
Convert ChipListCache to Kotlin
parent
14f46f0688
commit
e97e0d3a22
@ -1,15 +1,10 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@Deprecated("use coroutines")
|
||||
class CaldavDaoBlocking @Inject constructor(private val dao: CaldavDao) {
|
||||
fun subscribeToCalendars(): LiveData<List<CaldavCalendar>> {
|
||||
return dao.subscribeToCalendars()
|
||||
}
|
||||
|
||||
fun getCalendars(): List<CaldavCalendar> = runBlocking {
|
||||
dao.getCalendars()
|
||||
}
|
||||
|
@ -1,15 +1,10 @@
|
||||
package org.tasks.data
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@Deprecated("use coroutines")
|
||||
class TagDataDaoBlocking @Inject constructor(private val dao: TagDataDao) {
|
||||
fun subscribeToTags(): LiveData<List<TagData>> {
|
||||
return dao.subscribeToTags()
|
||||
}
|
||||
|
||||
fun tagDataOrderedByName(): List<TagData> = runBlocking {
|
||||
dao.tagDataOrderedByName()
|
||||
}
|
||||
|
@ -1,76 +0,0 @@
|
||||
package org.tasks.ui;
|
||||
|
||||
import com.todoroo.astrid.api.CaldavFilter;
|
||||
import com.todoroo.astrid.api.Filter;
|
||||
import com.todoroo.astrid.api.GtasksFilter;
|
||||
import com.todoroo.astrid.api.TagFilter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import org.tasks.LocalBroadcastManager;
|
||||
import org.tasks.data.CaldavCalendar;
|
||||
import org.tasks.data.CaldavDaoBlocking;
|
||||
import org.tasks.data.GoogleTaskList;
|
||||
import org.tasks.data.GoogleTaskListDaoBlocking;
|
||||
import org.tasks.data.TagData;
|
||||
import org.tasks.data.TagDataDaoBlocking;
|
||||
|
||||
@Singleton
|
||||
public class ChipListCache {
|
||||
|
||||
private final Map<String, GtasksFilter> googleTaskLists = new HashMap<>();
|
||||
private final Map<String, CaldavFilter> caldavCalendars = new HashMap<>();
|
||||
private final Map<String, TagFilter> tagDatas = new HashMap<>();
|
||||
private final LocalBroadcastManager localBroadcastManager;
|
||||
|
||||
@Inject
|
||||
ChipListCache(
|
||||
GoogleTaskListDaoBlocking googleTaskListDao,
|
||||
CaldavDaoBlocking caldavDao,
|
||||
TagDataDaoBlocking tagDataDao,
|
||||
LocalBroadcastManager localBroadcastManager) {
|
||||
this.localBroadcastManager = localBroadcastManager;
|
||||
|
||||
googleTaskListDao.subscribeToLists().observeForever(this::updateGoogleTaskLists);
|
||||
caldavDao.subscribeToCalendars().observeForever(this::updateCaldavCalendars);
|
||||
tagDataDao.subscribeToTags().observeForever(this::updateTags);
|
||||
}
|
||||
|
||||
private void updateGoogleTaskLists(List<GoogleTaskList> updated) {
|
||||
googleTaskLists.clear();
|
||||
for (GoogleTaskList update : updated) {
|
||||
googleTaskLists.put(update.getRemoteId(), new GtasksFilter(update));
|
||||
}
|
||||
localBroadcastManager.broadcastRefresh();
|
||||
}
|
||||
|
||||
private void updateCaldavCalendars(List<CaldavCalendar> updated) {
|
||||
caldavCalendars.clear();
|
||||
for (CaldavCalendar update : updated) {
|
||||
caldavCalendars.put(update.getUuid(), new CaldavFilter(update));
|
||||
}
|
||||
localBroadcastManager.broadcastRefresh();
|
||||
}
|
||||
|
||||
private void updateTags(List<TagData> updated) {
|
||||
tagDatas.clear();
|
||||
for (TagData update : updated) {
|
||||
tagDatas.put(update.getRemoteId(), new TagFilter(update));
|
||||
}
|
||||
localBroadcastManager.broadcastRefresh();
|
||||
}
|
||||
|
||||
Filter getGoogleTaskList(String googleTaskList) {
|
||||
return googleTaskLists.get(googleTaskList);
|
||||
}
|
||||
|
||||
Filter getCaldavList(String caldav) {
|
||||
return caldavCalendars.get(caldav);
|
||||
}
|
||||
|
||||
TagFilter getTag(String tag) {
|
||||
return tagDatas.get(tag);
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package org.tasks.ui
|
||||
|
||||
import com.todoroo.astrid.api.CaldavFilter
|
||||
import com.todoroo.astrid.api.Filter
|
||||
import com.todoroo.astrid.api.GtasksFilter
|
||||
import com.todoroo.astrid.api.TagFilter
|
||||
import org.tasks.LocalBroadcastManager
|
||||
import org.tasks.data.*
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class ChipListCache @Inject internal constructor(
|
||||
googleTaskListDao: GoogleTaskListDao,
|
||||
caldavDao: CaldavDao,
|
||||
tagDataDao: TagDataDao,
|
||||
private val localBroadcastManager: LocalBroadcastManager) {
|
||||
|
||||
private val googleTaskLists: MutableMap<String?, GtasksFilter> = HashMap()
|
||||
private val caldavCalendars: MutableMap<String?, CaldavFilter> = HashMap()
|
||||
private val tagDatas: MutableMap<String?, TagFilter> = HashMap()
|
||||
private fun updateGoogleTaskLists(updated: List<GoogleTaskList>) {
|
||||
googleTaskLists.clear()
|
||||
for (update in updated) {
|
||||
googleTaskLists[update.remoteId] = GtasksFilter(update)
|
||||
}
|
||||
localBroadcastManager.broadcastRefresh()
|
||||
}
|
||||
|
||||
private fun updateCaldavCalendars(updated: List<CaldavCalendar>) {
|
||||
caldavCalendars.clear()
|
||||
for (update in updated) {
|
||||
caldavCalendars[update.uuid] = CaldavFilter(update)
|
||||
}
|
||||
localBroadcastManager.broadcastRefresh()
|
||||
}
|
||||
|
||||
private fun updateTags(updated: List<TagData>) {
|
||||
tagDatas.clear()
|
||||
for (update in updated) {
|
||||
tagDatas[update.remoteId] = TagFilter(update)
|
||||
}
|
||||
localBroadcastManager.broadcastRefresh()
|
||||
}
|
||||
|
||||
fun getGoogleTaskList(googleTaskList: String?): Filter? {
|
||||
return googleTaskLists[googleTaskList]
|
||||
}
|
||||
|
||||
fun getCaldavList(caldav: String?): Filter? {
|
||||
return caldavCalendars[caldav]
|
||||
}
|
||||
|
||||
fun getTag(tag: String?): TagFilter? {
|
||||
return tagDatas[tag]
|
||||
}
|
||||
|
||||
init {
|
||||
googleTaskListDao.subscribeToLists().observeForever { updated: List<GoogleTaskList> -> updateGoogleTaskLists(updated) }
|
||||
caldavDao.subscribeToCalendars().observeForever { updated: List<CaldavCalendar> -> updateCaldavCalendars(updated) }
|
||||
tagDataDao.subscribeToTags().observeForever { updated: List<TagData> -> updateTags(updated) }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue