mirror of
https://github.com/etesync/android
synced 2024-12-23 07:08:16 +00:00
Sync collections and show them in the account page.
This commit is contained in:
parent
2c0e14d3a3
commit
608f1ff371
@ -51,13 +51,13 @@ 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): List<Collection> {
|
fun collectionList(colMgr: CollectionManager, withDeleted: Boolean = false): List<Collection> {
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun collectionSet(colMgr: CollectionManager, collection: Collection) {
|
fun collectionSet(colMgr: CollectionManager, collection: Collection) {
|
||||||
@ -74,13 +74,13 @@ class EtebaseLocalCache private constructor(context: Context, username: String)
|
|||||||
colDir.deleteRecursively()
|
colDir.deleteRecursively()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun itemList(itemMgr: ItemManager, colUid: String): List<Item> {
|
fun itemList(itemMgr: ItemManager, colUid: String, withDeleted: Boolean = false): List<Item> {
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun itemSet(itemMgr: ItemManager, colUid: String, item: Item) {
|
fun itemSet(itemMgr: ItemManager, colUid: String, item: Item) {
|
||||||
|
@ -22,6 +22,7 @@ import androidx.core.app.NotificationManagerCompat
|
|||||||
import androidx.core.util.Pair
|
import androidx.core.util.Pair
|
||||||
import at.bitfire.ical4android.CalendarStorageException
|
import at.bitfire.ical4android.CalendarStorageException
|
||||||
import at.bitfire.vcard4android.ContactsStorageException
|
import at.bitfire.vcard4android.ContactsStorageException
|
||||||
|
import com.etebase.client.FetchOptions
|
||||||
import com.etesync.syncadapter.*
|
import com.etesync.syncadapter.*
|
||||||
import com.etesync.journalmanager.Crypto
|
import com.etesync.journalmanager.Crypto
|
||||||
import com.etesync.journalmanager.Exceptions
|
import com.etesync.journalmanager.Exceptions
|
||||||
@ -208,30 +209,59 @@ abstract class SyncAdapterService : Service() {
|
|||||||
val settings = AccountSettings(context, account)
|
val settings = AccountSettings(context, account)
|
||||||
val httpClient = HttpClient.Builder(context, settings).setForeground(false).build()
|
val httpClient = HttpClient.Builder(context, settings).setForeground(false).build()
|
||||||
|
|
||||||
val journalsManager = JournalManager(httpClient.okHttpClient, settings.uri?.toHttpUrlOrNull()!!)
|
if (settings.isLegacy) {
|
||||||
|
val journalsManager = JournalManager(httpClient.okHttpClient, settings.uri?.toHttpUrlOrNull()!!)
|
||||||
|
|
||||||
var journals = journalFetcher.list(journalsManager, settings, serviceType)
|
var journals = journalFetcher.list(journalsManager, settings, serviceType)
|
||||||
|
|
||||||
if (journals.isEmpty()) {
|
if (journals.isEmpty()) {
|
||||||
journals = LinkedList()
|
journals = LinkedList()
|
||||||
try {
|
try {
|
||||||
val info = CollectionInfo.defaultForServiceType(serviceType)
|
val info = CollectionInfo.defaultForServiceType(serviceType)
|
||||||
val uid = JournalManager.Journal.genUid()
|
val uid = JournalManager.Journal.genUid()
|
||||||
info.uid = uid
|
info.uid = uid
|
||||||
val crypto = Crypto.CryptoManager(info.version, settings.password(), uid)
|
val crypto = Crypto.CryptoManager(info.version, settings.password(), uid)
|
||||||
val journal = JournalManager.Journal(crypto, info.toJson(), uid)
|
val journal = JournalManager.Journal(crypto, info.toJson(), uid)
|
||||||
journalsManager.create(journal)
|
journalsManager.create(journal)
|
||||||
journals.add(Pair(journal, info))
|
journals.add(Pair(journal, info))
|
||||||
} catch (e: Exceptions.AssociateNotAllowedException) {
|
} catch (e: Exceptions.AssociateNotAllowedException) {
|
||||||
// Skip for now
|
// Skip for now
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
legacySaveCollections(journals)
|
||||||
|
|
||||||
|
httpClient.close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
val etebaseLocalCache = EtebaseLocalCache.getInstance(context, account.name)
|
||||||
|
synchronized(etebaseLocalCache) {
|
||||||
|
val etebase = EtebaseLocalCache.getEtebase(context, httpClient.okHttpClient, settings)
|
||||||
|
val colMgr = etebase.collectionManager
|
||||||
|
var stoken = etebaseLocalCache.loadStoken()
|
||||||
|
var done = false
|
||||||
|
while (!done) {
|
||||||
|
val colList = colMgr.list(FetchOptions().stoken(stoken))
|
||||||
|
for (col in colList.data) {
|
||||||
|
etebaseLocalCache.collectionSet(colMgr, col)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (col in colList.removedMemberships) {
|
||||||
|
etebaseLocalCache.collectionUnset(colMgr, col.uid())
|
||||||
|
}
|
||||||
|
|
||||||
|
stoken = colList.stoken
|
||||||
|
done = colList.isDone
|
||||||
|
etebaseLocalCache.saveStoken(stoken!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
saveCollections(journals)
|
|
||||||
httpClient.close()
|
httpClient.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveCollections(journals: Iterable<Pair<JournalManager.Journal, CollectionInfo>>) {
|
private fun legacySaveCollections(journals: Iterable<Pair<JournalManager.Journal, CollectionInfo>>) {
|
||||||
val data = (context.applicationContext as App).data
|
val data = (context.applicationContext as App).data
|
||||||
val service = JournalModel.Service.fetchOrCreate(data, account.name, serviceType)
|
val service = JournalModel.Service.fetchOrCreate(data, account.name, serviceType)
|
||||||
|
|
||||||
|
@ -373,7 +373,9 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
|||||||
val isReadOnly = accessLevel == "ro"
|
val isReadOnly = accessLevel == "ro"
|
||||||
val isAdmin = accessLevel == "adm"
|
val isAdmin = accessLevel == "adm"
|
||||||
|
|
||||||
CollectionListItemInfo(it.uid, type, meta.name, meta.description ?: "", parseColor(meta.color), isReadOnly, isAdmin, null)
|
val metaColor = meta.color
|
||||||
|
val color = if (metaColor != null && metaColor != "") parseColor(metaColor) else null
|
||||||
|
CollectionListItemInfo(it.uid, type, meta.name, meta.description ?: "", color, isReadOnly, isAdmin, null)
|
||||||
}.filterNotNull()
|
}.filterNotNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,12 +425,13 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
|||||||
}
|
}
|
||||||
|
|
||||||
val etebaseLocalCache = EtebaseLocalCache.getInstance(context, account.name)
|
val etebaseLocalCache = EtebaseLocalCache.getInstance(context, account.name)
|
||||||
val etebase = EtebaseLocalCache.getEtebase(context, settings)
|
val httpClient = HttpClient.Builder(context).build().okHttpClient
|
||||||
|
val etebase = EtebaseLocalCache.getEtebase(context, httpClient, settings)
|
||||||
val colMgr = etebase.collectionManager
|
val colMgr = etebase.collectionManager
|
||||||
|
|
||||||
info.carddav = AccountInfo.ServiceInfo()
|
info.carddav = AccountInfo.ServiceInfo()
|
||||||
info.carddav!!.refreshing = ContentResolver.isSyncActive(account, App.addressBooksAuthority)
|
info.carddav!!.refreshing = ContentResolver.isSyncActive(account, App.addressBooksAuthority)
|
||||||
info.carddav!!.infos = getCollections(etebaseLocalCache, colMgr, CollectionInfo.Type.TASKS)
|
info.carddav!!.infos = getCollections(etebaseLocalCache, colMgr, CollectionInfo.Type.ADDRESS_BOOK)
|
||||||
|
|
||||||
val accountManager = AccountManager.get(context)
|
val accountManager = AccountManager.get(context)
|
||||||
for (addrBookAccount in accountManager.getAccountsByType(App.addressBookAccountType)) {
|
for (addrBookAccount in accountManager.getAccountsByType(App.addressBookAccountType)) {
|
||||||
@ -443,7 +446,7 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
|||||||
|
|
||||||
info.caldav = AccountInfo.ServiceInfo()
|
info.caldav = AccountInfo.ServiceInfo()
|
||||||
info.caldav!!.refreshing = ContentResolver.isSyncActive(account, CalendarContract.AUTHORITY)
|
info.caldav!!.refreshing = ContentResolver.isSyncActive(account, CalendarContract.AUTHORITY)
|
||||||
info.caldav!!.infos = getCollections(etebaseLocalCache, colMgr, CollectionInfo.Type.TASKS)
|
info.caldav!!.infos = getCollections(etebaseLocalCache, colMgr, CollectionInfo.Type.CALENDAR)
|
||||||
|
|
||||||
info.taskdav = AccountInfo.ServiceInfo()
|
info.taskdav = AccountInfo.ServiceInfo()
|
||||||
info.taskdav!!.refreshing = OPENTASK_PROVIDERS.any {
|
info.taskdav!!.refreshing = OPENTASK_PROVIDERS.any {
|
||||||
|
Loading…
Reference in New Issue
Block a user