mirror of
https://github.com/etesync/android
synced 2024-11-22 07:58:09 +00:00
Move CollectionInfo and SyncEntry to the journalmanager module.
This commit is contained in:
parent
09e2a9255a
commit
df94fde5ff
@ -133,7 +133,7 @@ dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation "org.jetbrains.anko:anko-commons:0.10.4"
|
||||
|
||||
implementation "com.etesync:journalmanager:1.0.1"
|
||||
implementation "com.etesync:journalmanager:1.0.2"
|
||||
|
||||
def acraVersion = '5.3.0'
|
||||
implementation "ch.acra:acra-mail:$acraVersion"
|
||||
|
@ -9,40 +9,18 @@
|
||||
package com.etesync.syncadapter.model
|
||||
|
||||
import android.content.ContentValues
|
||||
import com.etesync.journalmanager.Constants
|
||||
import com.etesync.journalmanager.JournalManager
|
||||
import com.etesync.syncadapter.model.ServiceDB.Collections
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.annotations.Expose
|
||||
import java.io.Serializable
|
||||
|
||||
class CollectionInfo : Serializable {
|
||||
class CollectionInfo : com.etesync.journalmanager.model.CollectionInfo() {
|
||||
@Deprecated("")
|
||||
var id: Long = 0
|
||||
|
||||
var serviceID: Int = 0
|
||||
|
||||
// FIXME: Shouldn't be exposed, as it's already saved in the journal. We just expose it for when we save for db.
|
||||
@Expose
|
||||
var version = -1
|
||||
|
||||
@Expose
|
||||
var type: Type? = null
|
||||
|
||||
var uid: String? = null
|
||||
|
||||
@Expose
|
||||
var displayName: String? = null
|
||||
@Expose
|
||||
var description: String? = null
|
||||
@Expose
|
||||
var color: Int? = null
|
||||
|
||||
@Expose
|
||||
var timeZone: String? = null
|
||||
|
||||
@Expose
|
||||
var selected: Boolean = false
|
||||
fun getServiceEntity(data: MyEntityDataStore): ServiceEntity {
|
||||
return data.findByKey(ServiceEntity::class.java, serviceID)
|
||||
}
|
||||
|
||||
enum class Type {
|
||||
ADDRESS_BOOK,
|
||||
@ -50,38 +28,18 @@ class CollectionInfo : Serializable {
|
||||
TASKS,
|
||||
}
|
||||
|
||||
init {
|
||||
version = Constants.CURRENT_VERSION
|
||||
}
|
||||
|
||||
fun updateFromJournal(journal: JournalManager.Journal) {
|
||||
uid = journal.uid!!
|
||||
version = journal.version
|
||||
}
|
||||
|
||||
fun isOfTypeService(service: String): Boolean {
|
||||
return service == type.toString()
|
||||
}
|
||||
|
||||
fun getServiceEntity(data: MyEntityDataStore): ServiceEntity {
|
||||
return data.findByKey(ServiceEntity::class.java, serviceID)
|
||||
}
|
||||
|
||||
fun toJson(): String {
|
||||
return GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(this, CollectionInfo::class.java)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "CollectionInfo(serviceID=" + this.serviceID + ", version=" + this.version + ", type=" + this.type + ", uid=" + this.uid + ", displayName=" + this.displayName + ", description=" + this.description + ", color=" + this.color + ", timeZone=" + this.timeZone + ", selected=" + this.selected + ")"
|
||||
}
|
||||
var enumType: Type?
|
||||
get() = if (super.type != null) Type.valueOf(super.type!!) else null
|
||||
set(value) {
|
||||
super.type = value?.name
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun defaultForServiceType(service: Type): CollectionInfo {
|
||||
val info = CollectionInfo()
|
||||
info.displayName = "Default"
|
||||
info.selected = true
|
||||
info.type = service
|
||||
info.enumType = service
|
||||
|
||||
return info
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.etesync.syncadapter.model;
|
||||
|
||||
import com.etesync.journalmanager.model.SyncEntry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.requery.Column;
|
||||
@ -11,11 +13,9 @@ import io.requery.Generated;
|
||||
import io.requery.Index;
|
||||
import io.requery.Key;
|
||||
import io.requery.ManyToOne;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.PostLoad;
|
||||
import io.requery.ReferentialAction;
|
||||
import io.requery.Table;
|
||||
import io.requery.sql.EntityDataStore;
|
||||
|
||||
public class JournalModel {
|
||||
@Entity
|
||||
|
@ -92,7 +92,7 @@ public class ServiceDB {
|
||||
db.beginTransactionNonExclusive();
|
||||
|
||||
// iterate through all tables
|
||||
Cursor cursorTables = db.query("sqlite_master", new String[]{"name"}, "type='table'", null, null, null, null);
|
||||
Cursor cursorTables = db.query("sqlite_master", new String[]{"name"}, "enumType='table'", null, null, null, null);
|
||||
while (cursorTables.moveToNext()) {
|
||||
String table = cursorTables.getString(0);
|
||||
sb.append(table).append("\n");
|
||||
|
@ -1,52 +0,0 @@
|
||||
package com.etesync.syncadapter.model
|
||||
|
||||
import com.etesync.syncadapter.GsonHelper
|
||||
import com.etesync.journalmanager.Crypto
|
||||
import com.etesync.journalmanager.JournalEntryManager
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
class SyncEntry : Serializable {
|
||||
val content: String
|
||||
val action: Actions
|
||||
|
||||
enum class Actions constructor(private val text: String) {
|
||||
ADD("ADD"),
|
||||
CHANGE("CHANGE"),
|
||||
DELETE("DELETE");
|
||||
|
||||
override fun toString(): String {
|
||||
return text
|
||||
}
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
this.content = ""
|
||||
this.action = Actions.ADD
|
||||
}
|
||||
|
||||
constructor(content: String, action: Actions) {
|
||||
this.content = content
|
||||
this.action = action
|
||||
}
|
||||
|
||||
fun isAction(action: Actions): Boolean {
|
||||
return this.action == action
|
||||
}
|
||||
|
||||
fun toJson(): String {
|
||||
return GsonHelper.gson.toJson(this, this.javaClass)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun fromJournalEntry(crypto: Crypto.CryptoManager, entry: JournalEntryManager.Entry): SyncEntry {
|
||||
return fromJson(entry.getContent(crypto))
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun fromJson(json: String): SyncEntry {
|
||||
return GsonHelper.gson.fromJson(json, SyncEntry::class.java)
|
||||
}
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ import java.util.logging.Level
|
||||
|
||||
|
||||
/**
|
||||
* Account authenticator for the main DAVx5 account type.
|
||||
* Account authenticator for the main DAVx5 account enumType.
|
||||
*
|
||||
* Gets started when a DAVx5 account is removed, too, so it also watches for account removals
|
||||
* and contains the corresponding cleanup code.
|
||||
|
@ -24,7 +24,7 @@ import com.etesync.journalmanager.Exceptions
|
||||
import com.etesync.journalmanager.JournalEntryManager
|
||||
import com.etesync.syncadapter.log.Logger
|
||||
import com.etesync.syncadapter.model.CollectionInfo
|
||||
import com.etesync.syncadapter.model.SyncEntry
|
||||
import com.etesync.journalmanager.model.SyncEntry
|
||||
import com.etesync.syncadapter.resource.LocalCalendar
|
||||
import com.etesync.syncadapter.resource.LocalEvent
|
||||
import com.etesync.syncadapter.utils.EventEmailInvitation
|
||||
|
@ -24,7 +24,7 @@ import com.etesync.journalmanager.Exceptions
|
||||
import com.etesync.journalmanager.JournalEntryManager
|
||||
import com.etesync.syncadapter.log.Logger
|
||||
import com.etesync.syncadapter.model.CollectionInfo
|
||||
import com.etesync.syncadapter.model.SyncEntry
|
||||
import com.etesync.journalmanager.model.SyncEntry
|
||||
import com.etesync.syncadapter.resource.LocalAddress
|
||||
import com.etesync.syncadapter.resource.LocalAddressBook
|
||||
import com.etesync.syncadapter.resource.LocalContact
|
||||
|
@ -82,7 +82,7 @@ class CachedJournalFetcher {
|
||||
}
|
||||
}
|
||||
|
||||
return journals.filter { it.second?.type == serviceType }
|
||||
return journals.filter { it.second?.enumType == serviceType }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,10 @@ import com.etesync.syncadapter.Constants.KEY_ACCOUNT
|
||||
import com.etesync.journalmanager.Crypto
|
||||
import com.etesync.journalmanager.Exceptions
|
||||
import com.etesync.journalmanager.JournalEntryManager
|
||||
import com.etesync.journalmanager.model.SyncEntry
|
||||
import com.etesync.syncadapter.log.Logger
|
||||
import com.etesync.syncadapter.model.*
|
||||
import com.etesync.syncadapter.model.SyncEntry.Actions.ADD
|
||||
import com.etesync.journalmanager.model.SyncEntry.Actions.ADD
|
||||
import com.etesync.syncadapter.resource.*
|
||||
import com.etesync.syncadapter.ui.AccountsActivity
|
||||
import com.etesync.syncadapter.ui.DebugInfoActivity
|
||||
|
@ -19,7 +19,7 @@ import com.etesync.syncadapter.R
|
||||
import com.etesync.journalmanager.JournalEntryManager
|
||||
import com.etesync.syncadapter.log.Logger
|
||||
import com.etesync.syncadapter.model.CollectionInfo
|
||||
import com.etesync.syncadapter.model.SyncEntry
|
||||
import com.etesync.journalmanager.model.SyncEntry
|
||||
import com.etesync.syncadapter.resource.LocalTask
|
||||
import com.etesync.syncadapter.resource.LocalTaskList
|
||||
import okhttp3.HttpUrl
|
||||
|
@ -171,17 +171,17 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
||||
when (item.itemId) {
|
||||
R.id.create_calendar -> {
|
||||
info = CollectionInfo()
|
||||
info.type = CollectionInfo.Type.CALENDAR
|
||||
info.enumType = CollectionInfo.Type.CALENDAR
|
||||
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account, info))
|
||||
}
|
||||
R.id.create_tasklist -> {
|
||||
info = CollectionInfo()
|
||||
info.type = CollectionInfo.Type.TASKS
|
||||
info.enumType = CollectionInfo.Type.TASKS
|
||||
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account, info))
|
||||
}
|
||||
R.id.create_addressbook -> {
|
||||
info = CollectionInfo()
|
||||
info.type = CollectionInfo.Type.ADDRESS_BOOK
|
||||
info.enumType = CollectionInfo.Type.ADDRESS_BOOK
|
||||
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account, info))
|
||||
}
|
||||
R.id.install_opentasks -> {
|
||||
@ -395,7 +395,7 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
|
||||
}
|
||||
|
||||
val vColor = v.findViewById<View>(R.id.color)
|
||||
if (info.type == CollectionInfo.Type.ADDRESS_BOOK) {
|
||||
if (info.enumType == CollectionInfo.Type.ADDRESS_BOOK) {
|
||||
vColor.visibility = View.GONE
|
||||
} else {
|
||||
vColor.setBackgroundColor(info.color ?: LocalCalendar.defaultColor)
|
||||
|
@ -37,7 +37,7 @@ class CollectionMembersActivity : BaseActivity(), Refreshable {
|
||||
setTitle(R.string.collection_members_title)
|
||||
|
||||
val colorSquare = findViewById<View>(R.id.color)
|
||||
when (info.type) {
|
||||
when (info.enumType) {
|
||||
CollectionInfo.Type.CALENDAR -> {
|
||||
colorSquare.setBackgroundColor(info.color ?: LocalCalendar.defaultColor)
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ open class CreateCollectionActivity : BaseActivity() {
|
||||
setContentView(R.layout.activity_create_collection)
|
||||
|
||||
val displayName = findViewById<View>(R.id.display_name) as EditText
|
||||
when (info.type) {
|
||||
when (info.enumType) {
|
||||
CollectionInfo.Type.CALENDAR -> {
|
||||
setTitle(R.string.create_calendar)
|
||||
displayName.setHint(R.string.create_calendar_display_name_hint)
|
||||
@ -114,7 +114,7 @@ open class CreateCollectionActivity : BaseActivity() {
|
||||
info.description = StringUtils.trimToNull(edit.text.toString())
|
||||
|
||||
if (ok) {
|
||||
when (info.type) {
|
||||
when (info.enumType) {
|
||||
CollectionInfo.Type.CALENDAR, CollectionInfo.Type.TASKS -> {
|
||||
val view = findViewById<View>(R.id.color)
|
||||
info.color = (view.background as ColorDrawable).color
|
||||
|
@ -89,13 +89,13 @@ class CreateCollectionFragment : DialogFragment(), LoaderManager.LoaderCallbacks
|
||||
val data = (context.applicationContext as App).data
|
||||
|
||||
// 1. find service ID
|
||||
when (info.type){
|
||||
when (info.enumType){
|
||||
CollectionInfo.Type.ADDRESS_BOOK -> authority = App.addressBooksAuthority
|
||||
CollectionInfo.Type.CALENDAR -> authority = CalendarContract.AUTHORITY
|
||||
CollectionInfo.Type.TASKS -> authority = TaskProvider.ProviderName.OpenTasks.authority
|
||||
}
|
||||
|
||||
val serviceEntity = JournalModel.Service.fetchOrCreate(data, account.name, info.type)
|
||||
val serviceEntity = JournalModel.Service.fetchOrCreate(data, account.name, info.enumType)
|
||||
info.serviceID = serviceEntity.id
|
||||
|
||||
val settings = AccountSettings(context, account)
|
||||
|
@ -31,7 +31,7 @@ class EditCollectionActivity : CreateCollectionActivity() {
|
||||
|
||||
setTitle(R.string.edit_collection)
|
||||
|
||||
when (info.type) {
|
||||
when (info.enumType) {
|
||||
CollectionInfo.Type.CALENDAR -> {
|
||||
val colorSquare = findViewById<View>(R.id.color)
|
||||
colorSquare.setBackgroundColor(info.color ?: LocalCalendar.defaultColor)
|
||||
|
@ -25,7 +25,7 @@ import com.etesync.syncadapter.Constants
|
||||
import com.etesync.syncadapter.R
|
||||
import com.etesync.syncadapter.model.CollectionInfo
|
||||
import com.etesync.syncadapter.model.JournalEntity
|
||||
import com.etesync.syncadapter.model.SyncEntry
|
||||
import com.etesync.journalmanager.model.SyncEntry
|
||||
import com.etesync.syncadapter.resource.*
|
||||
import com.etesync.syncadapter.ui.journalviewer.ListEntriesFragment.Companion.setJournalEntryView
|
||||
import com.etesync.syncadapter.utils.EventEmailInvitation
|
||||
@ -102,7 +102,7 @@ class JournalItemActivity : BaseActivity(), Refreshable {
|
||||
|
||||
fun restoreItem(item: MenuItem) {
|
||||
// FIXME: This code makes the assumption that providers are all available. May not be true for tasks, and potentially others too.
|
||||
when (info.type) {
|
||||
when (info.enumType) {
|
||||
CollectionInfo.Type.CALENDAR -> {
|
||||
val provider = contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI)!!
|
||||
val localCalendar = LocalCalendar.findByName(account, provider, LocalCalendar.Factory, info.uid!!)!!
|
||||
@ -159,7 +159,7 @@ class JournalItemActivity : BaseActivity(), Refreshable {
|
||||
private class TabsAdapter(fm: FragmentManager, private val context: Context, private val info: CollectionInfo, private val syncEntry: SyncEntry) : FragmentPagerAdapter(fm) {
|
||||
|
||||
override fun getCount(): Int {
|
||||
// FIXME: Make it depend on info type (only have non-raw for known types)
|
||||
// FIXME: Make it depend on info enumType (only have non-raw for known types)
|
||||
return 2
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ class JournalItemActivity : BaseActivity(), Refreshable {
|
||||
info = arguments!!.getSerializable(Constants.KEY_COLLECTION_INFO) as CollectionInfo
|
||||
syncEntry = arguments!!.getSerializable(KEY_SYNC_ENTRY) as SyncEntry
|
||||
|
||||
when (info.type) {
|
||||
when (info.enumType) {
|
||||
CollectionInfo.Type.ADDRESS_BOOK -> {
|
||||
v = inflater.inflate(R.layout.contact_info, container, false)
|
||||
asyncTask = loadContactTask(v)
|
||||
|
@ -60,7 +60,7 @@ class ViewCollectionActivity : BaseActivity(), Refreshable {
|
||||
isOwner = journalEntity!!.isOwner(account.name)
|
||||
|
||||
val colorSquare = findViewById<View>(R.id.color)
|
||||
when (info.type) {
|
||||
when (info.enumType) {
|
||||
CollectionInfo.Type.CALENDAR -> {
|
||||
colorSquare.setBackgroundColor(info.color ?: LocalCalendar.defaultColor)
|
||||
}
|
||||
@ -176,7 +176,7 @@ class ViewCollectionActivity : BaseActivity(), Refreshable {
|
||||
entryCount = data.count(EntryEntity::class.java).where(EntryEntity.JOURNAL.eq(journalEntity)).get().value()
|
||||
var count: Long = -1
|
||||
|
||||
when (info.type) {
|
||||
when (info.enumType) {
|
||||
CollectionInfo.Type.CALENDAR -> {
|
||||
try {
|
||||
val providerClient = contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI)
|
||||
@ -237,7 +237,7 @@ class ViewCollectionActivity : BaseActivity(), Refreshable {
|
||||
if (result == null) {
|
||||
stats.text = "Stats loading error."
|
||||
} else {
|
||||
when (info.type) {
|
||||
when (info.enumType) {
|
||||
CollectionInfo.Type.CALENDAR -> {
|
||||
stats.text = String.format(Locale.getDefault(), "Events: %d, Journal entries: %d",
|
||||
result, entryCount)
|
||||
|
@ -43,13 +43,13 @@ class ImportActivity : BaseActivity(), SelectImportMethod, ResultFragment.OnImpo
|
||||
}
|
||||
|
||||
override fun importAccount() {
|
||||
if (info.type == CollectionInfo.Type.CALENDAR) {
|
||||
if (info.enumType == CollectionInfo.Type.CALENDAR) {
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(android.R.id.content,
|
||||
LocalCalendarImportFragment.newInstance(account, info))
|
||||
.addToBackStack(LocalCalendarImportFragment::class.java.name)
|
||||
.commit()
|
||||
} else if (info.type == CollectionInfo.Type.ADDRESS_BOOK) {
|
||||
} else if (info.enumType == CollectionInfo.Type.ADDRESS_BOOK) {
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(android.R.id.content,
|
||||
LocalContactImportFragment.newInstance(account, info))
|
||||
@ -144,7 +144,7 @@ class ImportActivity : BaseActivity(), SelectImportMethod, ResultFragment.OnImpo
|
||||
text.setText(R.string.import_button_local)
|
||||
card.setOnClickListener { mSelectImportMethod!!.importAccount() }
|
||||
|
||||
if ((activity as ImportActivity).info.type == CollectionInfo.Type.TASKS) {
|
||||
if ((activity as ImportActivity).info.enumType == CollectionInfo.Type.TASKS) {
|
||||
card.visibility = View.GONE
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ class ImportFragment : DialogFragment() {
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
intent.action = Intent.ACTION_GET_CONTENT
|
||||
|
||||
when (info.type) {
|
||||
when (info.enumType) {
|
||||
CollectionInfo.Type.CALENDAR -> intent.type = "text/calendar"
|
||||
CollectionInfo.Type.TASKS -> intent.type = "text/calendar"
|
||||
CollectionInfo.Type.ADDRESS_BOOK -> intent.type = "text/x-vcard"
|
||||
@ -215,7 +215,7 @@ class ImportFragment : DialogFragment() {
|
||||
val context = context!!
|
||||
val importReader = InputStreamReader(inputStream)
|
||||
|
||||
if (info.type == CollectionInfo.Type.CALENDAR) {
|
||||
if (info.enumType == CollectionInfo.Type.CALENDAR) {
|
||||
val events = Event.eventsFromReader(importReader, null)
|
||||
importReader.close()
|
||||
|
||||
@ -268,7 +268,7 @@ class ImportFragment : DialogFragment() {
|
||||
|
||||
entryProcessed()
|
||||
}
|
||||
} else if (info.type == CollectionInfo.Type.TASKS) {
|
||||
} else if (info.enumType == CollectionInfo.Type.TASKS) {
|
||||
val tasks = Task.tasksFromReader(importReader)
|
||||
importReader.close()
|
||||
|
||||
@ -317,7 +317,7 @@ class ImportFragment : DialogFragment() {
|
||||
|
||||
entryProcessed()
|
||||
}
|
||||
} else if (info.type == CollectionInfo.Type.ADDRESS_BOOK) {
|
||||
} else if (info.enumType == CollectionInfo.Type.ADDRESS_BOOK) {
|
||||
val uidToLocalId = HashMap<String?, Long>()
|
||||
val downloader = ContactsSyncManager.ResourceDownloader(context)
|
||||
val contacts = Contact.fromReader(importReader, downloader)
|
||||
|
@ -224,7 +224,7 @@ class LocalContactImportFragment : Fragment() {
|
||||
private val accountResolver: AccountResolver
|
||||
|
||||
/**
|
||||
* Provide a reference to the type of views that you are using (custom ViewHolder)
|
||||
* Provide a reference to the enumType of views that you are using (custom ViewHolder)
|
||||
*/
|
||||
class ViewHolder(v: View, onAccountSelected: OnAccountSelected) : RecyclerView.ViewHolder(v) {
|
||||
internal val titleTextView: TextView
|
||||
|
@ -19,6 +19,7 @@ import android.widget.ArrayAdapter
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.ListFragment
|
||||
import com.etesync.journalmanager.model.SyncEntry
|
||||
import com.etesync.syncadapter.App
|
||||
import com.etesync.syncadapter.R
|
||||
import com.etesync.syncadapter.model.*
|
||||
@ -139,7 +140,7 @@ class ListEntriesFragment : ListFragment(), AdapterView.OnItemClickListener {
|
||||
// FIXME: hacky way to make it show sensible info
|
||||
val fullContent = syncEntry.content
|
||||
var prefix = ""
|
||||
when (info.type) {
|
||||
when (info.enumType) {
|
||||
CollectionInfo.Type.CALENDAR, CollectionInfo.Type.TASKS -> {
|
||||
prefix = "SUMMARY:"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user