LocalEtebaseCache: create a shared collection + meta type.

pull/131/head
Tom Hacohen 4 years ago
parent 608f1ff371
commit 2069e9b215

@ -51,13 +51,15 @@ class EtebaseLocalCache private constructor(context: Context, username: String)
return if (stokenFile.exists()) stokenFile.readText() else null return if (stokenFile.exists()) stokenFile.readText() else null
} }
fun collectionList(colMgr: CollectionManager, withDeleted: Boolean = false): List<Collection> { fun collectionList(colMgr: CollectionManager, withDeleted: Boolean = false): List<CachedCollection> {
return colsDir.list().map { return colsDir.list().map {
val colDir = File(colsDir, it) val colDir = File(colsDir, it)
val colFile = File(colDir, "col") val colFile = File(colDir, "col")
val content = colFile.readBytes() val content = colFile.readBytes()
colMgr.cacheLoad(content) colMgr.cacheLoad(content)
}.filter { withDeleted || !it.isDeleted } }.filter { withDeleted || !it.isDeleted }.map{
CachedCollection(it, it.meta)
}
} }
fun collectionSet(colMgr: CollectionManager, collection: Collection) { fun collectionSet(colMgr: CollectionManager, collection: Collection) {
@ -74,13 +76,15 @@ class EtebaseLocalCache private constructor(context: Context, username: String)
colDir.deleteRecursively() colDir.deleteRecursively()
} }
fun itemList(itemMgr: ItemManager, colUid: String, withDeleted: Boolean = false): List<Item> { fun itemList(itemMgr: ItemManager, colUid: String, withDeleted: Boolean = false): List<CachedItem> {
val itemsDir = getCollectionItemsDir(colUid) val itemsDir = getCollectionItemsDir(colUid)
return itemsDir.list().map { return itemsDir.list().map {
val itemFile = File(itemsDir, it) val itemFile = File(itemsDir, it)
val content = itemFile.readBytes() val content = itemFile.readBytes()
itemMgr.cacheLoad(content) itemMgr.cacheLoad(content)
}.filter { withDeleted || !it.isDeleted } }.filter { withDeleted || !it.isDeleted }.map {
CachedItem(it, it.meta)
}
} }
fun itemSet(itemMgr: ItemManager, colUid: String, item: Item) { fun itemSet(itemMgr: ItemManager, colUid: String, item: Item) {
@ -117,3 +121,7 @@ class EtebaseLocalCache private constructor(context: Context, username: String)
} }
} }
} }
data class CachedCollection(val col: Collection, val meta: CollectionMetadata)
data class CachedItem(val item: Item, val meta: ItemMetadata)

@ -369,13 +369,13 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
return@map null return@map null
} }
val accessLevel = it.accessLevel val accessLevel = it.col.accessLevel
val isReadOnly = accessLevel == "ro" val isReadOnly = accessLevel == "ro"
val isAdmin = accessLevel == "adm" val isAdmin = accessLevel == "adm"
val metaColor = meta.color val metaColor = meta.color
val color = if (metaColor != null && metaColor != "") parseColor(metaColor) else null val color = if (metaColor != null && metaColor != "") parseColor(metaColor) else null
CollectionListItemInfo(it.uid, type, meta.name, meta.description ?: "", color, isReadOnly, isAdmin, null) CollectionListItemInfo(it.col.uid, type, meta.name, meta.description ?: "", color, isReadOnly, isAdmin, null)
}.filterNotNull() }.filterNotNull()
} }

Loading…
Cancel
Save