mirror of
https://github.com/etesync/android
synced 2024-12-23 15:18:14 +00:00
requery: use our own data store class.
This commit is contained in:
parent
d8600f2f04
commit
a74f188b3b
@ -152,6 +152,7 @@ dependencies {
|
|||||||
implementation "io.requery:requery-android:$requeryVersion"
|
implementation "io.requery:requery-android:$requeryVersion"
|
||||||
implementation "io.requery:requery-kotlin:$requeryVersion"
|
implementation "io.requery:requery-kotlin:$requeryVersion"
|
||||||
kapt "io.requery:requery-processor:$requeryVersion"
|
kapt "io.requery:requery-processor:$requeryVersion"
|
||||||
|
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||||
|
|
||||||
def spongyCastleVersion = "1.54.0.0"
|
def spongyCastleVersion = "1.54.0.0"
|
||||||
implementation "com.madgag.spongycastle:core:$spongyCastleVersion"
|
implementation "com.madgag.spongycastle:core:$spongyCastleVersion"
|
||||||
|
@ -51,13 +51,13 @@ class App : Application() {
|
|||||||
* `@Provides @Singleton`.
|
* `@Provides @Singleton`.
|
||||||
*/
|
*/
|
||||||
// override onUpgrade to handle migrating to a new version
|
// override onUpgrade to handle migrating to a new version
|
||||||
val data: EntityDataStore<Persistable>
|
val data: MyEntityDataStore
|
||||||
get() = initDataStore()
|
get() = initDataStore()
|
||||||
|
|
||||||
fun initDataStore(): EntityDataStore<Persistable> {
|
fun initDataStore(): MyEntityDataStore {
|
||||||
val source = MyDatabaseSource(this, Models.DEFAULT, 4)
|
val source = MyDatabaseSource(this, Models.DEFAULT, 4)
|
||||||
val configuration = source.configuration
|
val configuration = source.configuration
|
||||||
return EntityDataStore(configuration)
|
return MyEntityDataStore(configuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("HardwareIds")
|
@SuppressLint("HardwareIds")
|
||||||
|
@ -65,7 +65,7 @@ class CollectionInfo : Serializable {
|
|||||||
return service == type.toString()
|
return service == type.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getServiceEntity(data: EntityDataStore<Persistable>): ServiceEntity {
|
fun getServiceEntity(data: MyEntityDataStore): ServiceEntity {
|
||||||
return data.findByKey(ServiceEntity::class.java, serviceID)
|
return data.findByKey(ServiceEntity::class.java, serviceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,14 +60,14 @@ public class JournalModel {
|
|||||||
this.deleted = false;
|
this.deleted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Journal(EntityDataStore<Persistable> data, CollectionInfo info) {
|
public Journal(MyEntityDataStore data, CollectionInfo info) {
|
||||||
this();
|
this();
|
||||||
this.info = info;
|
this.info = info;
|
||||||
this.uid = info.getUid();
|
this.uid = info.getUid();
|
||||||
this.serviceModel = info.getServiceEntity(data);
|
this.serviceModel = info.getServiceEntity(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<JournalEntity> getJournals(EntityDataStore<Persistable> data, ServiceEntity serviceEntity) {
|
public static List<JournalEntity> getJournals(MyEntityDataStore data, ServiceEntity serviceEntity) {
|
||||||
List<JournalEntity> ret = data.select(JournalEntity.class).where(JournalEntity.SERVICE_MODEL.eq(serviceEntity).and(JournalEntity.DELETED.eq(false))).get().toList();
|
List<JournalEntity> ret = data.select(JournalEntity.class).where(JournalEntity.SERVICE_MODEL.eq(serviceEntity).and(JournalEntity.DELETED.eq(false))).get().toList();
|
||||||
for (JournalEntity journal : ret) {
|
for (JournalEntity journal : ret) {
|
||||||
// FIXME: For some reason this isn't always being called, manually do it here.
|
// FIXME: For some reason this isn't always being called, manually do it here.
|
||||||
@ -76,7 +76,7 @@ public class JournalModel {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JournalEntity fetch(EntityDataStore<Persistable> data, ServiceEntity serviceEntity, String uid) {
|
public static JournalEntity fetch(MyEntityDataStore data, ServiceEntity serviceEntity, String uid) {
|
||||||
JournalEntity ret = data.select(JournalEntity.class).where(JournalEntity.SERVICE_MODEL.eq(serviceEntity).and(JournalEntity.UID.eq(uid))).limit(1).get().firstOrNull();
|
JournalEntity ret = data.select(JournalEntity.class).where(JournalEntity.SERVICE_MODEL.eq(serviceEntity).and(JournalEntity.UID.eq(uid))).limit(1).get().firstOrNull();
|
||||||
if (ret != null) {
|
if (ret != null) {
|
||||||
// FIXME: For some reason this isn't always being called, manually do it here.
|
// FIXME: For some reason this isn't always being called, manually do it here.
|
||||||
@ -85,7 +85,7 @@ public class JournalModel {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JournalEntity fetchOrCreate(EntityDataStore<Persistable> data, CollectionInfo collection) {
|
public static JournalEntity fetchOrCreate(MyEntityDataStore data, CollectionInfo collection) {
|
||||||
JournalEntity journalEntity = fetch(data, collection.getServiceEntity(data), collection.getUid());
|
JournalEntity journalEntity = fetch(data, collection.getServiceEntity(data), collection.getUid());
|
||||||
if (journalEntity == null) {
|
if (journalEntity == null) {
|
||||||
journalEntity = new JournalEntity(data, collection);
|
journalEntity = new JournalEntity(data, collection);
|
||||||
@ -95,7 +95,7 @@ public class JournalModel {
|
|||||||
return journalEntity;
|
return journalEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLastUid(EntityDataStore<Persistable> data) {
|
public String getLastUid(MyEntityDataStore data) {
|
||||||
EntryEntity last = data.select(EntryEntity.class).where(EntryEntity.JOURNAL.eq(this)).orderBy(EntryEntity.ID.desc()).limit(1).get().firstOrNull();
|
EntryEntity last = data.select(EntryEntity.class).where(EntryEntity.JOURNAL.eq(this)).orderBy(EntryEntity.ID.desc()).limit(1).get().firstOrNull();
|
||||||
if (last != null) {
|
if (last != null) {
|
||||||
return last.getUid();
|
return last.getUid();
|
||||||
@ -144,7 +144,7 @@ public class JournalModel {
|
|||||||
@Index(value = "service_unique_together")
|
@Index(value = "service_unique_together")
|
||||||
CollectionInfo.Type type;
|
CollectionInfo.Type type;
|
||||||
|
|
||||||
public static ServiceEntity fetchOrCreate(EntityDataStore<Persistable> data, String account, CollectionInfo.Type type) {
|
public static ServiceEntity fetchOrCreate(MyEntityDataStore data, String account, CollectionInfo.Type type) {
|
||||||
ServiceEntity service = data.select(ServiceEntity.class).where(ServiceEntity.ACCOUNT.eq(account).and(ServiceEntity.TYPE.eq(type))).limit(1).get().firstOrNull();
|
ServiceEntity service = data.select(ServiceEntity.class).where(ServiceEntity.ACCOUNT.eq(account).and(ServiceEntity.TYPE.eq(type))).limit(1).get().firstOrNull();
|
||||||
if (service == null) {
|
if (service == null) {
|
||||||
// If our first time, create service and a journal
|
// If our first time, create service and a journal
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.etesync.syncadapter.model
|
||||||
|
|
||||||
|
import io.requery.Persistable
|
||||||
|
import io.requery.sql.Configuration
|
||||||
|
import io.requery.sql.EntityDataStore
|
||||||
|
|
||||||
|
class MyEntityDataStore(configuration: Configuration): EntityDataStore<Persistable>(configuration) {
|
||||||
|
|
||||||
|
}
|
@ -28,8 +28,6 @@ import com.etesync.syncadapter.resource.*
|
|||||||
import com.etesync.syncadapter.ui.AccountsActivity
|
import com.etesync.syncadapter.ui.AccountsActivity
|
||||||
import com.etesync.syncadapter.ui.DebugInfoActivity
|
import com.etesync.syncadapter.ui.DebugInfoActivity
|
||||||
import com.etesync.syncadapter.ui.ViewCollectionActivity
|
import com.etesync.syncadapter.ui.ViewCollectionActivity
|
||||||
import io.requery.Persistable
|
|
||||||
import io.requery.sql.EntityDataStore
|
|
||||||
import org.jetbrains.anko.defaultSharedPreferences
|
import org.jetbrains.anko.defaultSharedPreferences
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
import java.io.FileNotFoundException
|
import java.io.FileNotFoundException
|
||||||
@ -54,7 +52,7 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
|
|
||||||
private val crypto: Crypto.CryptoManager
|
private val crypto: Crypto.CryptoManager
|
||||||
|
|
||||||
private val data: EntityDataStore<Persistable>
|
private val data: MyEntityDataStore
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remote CTag (uuid of the last entry on the server). We update it when we fetch/push and save when everything works.
|
* remote CTag (uuid of the last entry on the server). We update it when we fetch/push and save when everything works.
|
||||||
|
@ -16,15 +16,14 @@ import com.etesync.syncadapter.journalmanager.JournalManager
|
|||||||
import com.etesync.syncadapter.model.CollectionInfo
|
import com.etesync.syncadapter.model.CollectionInfo
|
||||||
import com.etesync.syncadapter.model.JournalEntity
|
import com.etesync.syncadapter.model.JournalEntity
|
||||||
import com.etesync.syncadapter.model.JournalModel
|
import com.etesync.syncadapter.model.JournalModel
|
||||||
import io.requery.Persistable
|
import com.etesync.syncadapter.model.MyEntityDataStore
|
||||||
import io.requery.sql.EntityDataStore
|
|
||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
import org.jetbrains.anko.doAsync
|
import org.jetbrains.anko.doAsync
|
||||||
import org.jetbrains.anko.uiThread
|
import org.jetbrains.anko.uiThread
|
||||||
import java.util.concurrent.Future
|
import java.util.concurrent.Future
|
||||||
|
|
||||||
class CollectionMembersListFragment : ListFragment(), AdapterView.OnItemClickListener, Refreshable {
|
class CollectionMembersListFragment : ListFragment(), AdapterView.OnItemClickListener, Refreshable {
|
||||||
private lateinit var data: EntityDataStore<Persistable>
|
private lateinit var data: MyEntityDataStore
|
||||||
private lateinit var account: Account
|
private lateinit var account: Account
|
||||||
private lateinit var info: CollectionInfo
|
private lateinit var info: CollectionInfo
|
||||||
private lateinit var journalEntity: JournalEntity
|
private lateinit var journalEntity: JournalEntity
|
||||||
|
@ -24,15 +24,13 @@ import com.etesync.syncadapter.R
|
|||||||
import com.etesync.syncadapter.model.*
|
import com.etesync.syncadapter.model.*
|
||||||
import com.etesync.syncadapter.ui.JournalItemActivity
|
import com.etesync.syncadapter.ui.JournalItemActivity
|
||||||
import com.etesync.syncadapter.ui.ViewCollectionActivity
|
import com.etesync.syncadapter.ui.ViewCollectionActivity
|
||||||
import io.requery.Persistable
|
|
||||||
import io.requery.sql.EntityDataStore
|
|
||||||
import org.jetbrains.anko.doAsync
|
import org.jetbrains.anko.doAsync
|
||||||
import org.jetbrains.anko.uiThread
|
import org.jetbrains.anko.uiThread
|
||||||
import java.util.concurrent.Future
|
import java.util.concurrent.Future
|
||||||
|
|
||||||
class ListEntriesFragment : ListFragment(), AdapterView.OnItemClickListener {
|
class ListEntriesFragment : ListFragment(), AdapterView.OnItemClickListener {
|
||||||
|
|
||||||
private lateinit var data: EntityDataStore<Persistable>
|
private lateinit var data: MyEntityDataStore
|
||||||
private lateinit var account: Account
|
private lateinit var account: Account
|
||||||
private lateinit var info: CollectionInfo
|
private lateinit var info: CollectionInfo
|
||||||
private var journalEntity: JournalEntity? = null
|
private var journalEntity: JournalEntity? = null
|
||||||
|
Loading…
Reference in New Issue
Block a user