mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
Replace manual attendees
serialization with type converter
This commit is contained in:
@@ -6,6 +6,7 @@ plugins {
|
|||||||
alias(libs.plugins.android)
|
alias(libs.plugins.android)
|
||||||
alias(libs.plugins.kotlinAndroid)
|
alias(libs.plugins.kotlinAndroid)
|
||||||
alias(libs.plugins.ksp)
|
alias(libs.plugins.ksp)
|
||||||
|
alias(libs.plugins.parcelize)
|
||||||
base
|
base
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,8 +24,6 @@ import android.widget.RelativeLayout
|
|||||||
import com.google.android.material.timepicker.MaterialTimePicker
|
import com.google.android.material.timepicker.MaterialTimePicker
|
||||||
import com.google.android.material.timepicker.MaterialTimePicker.INPUT_MODE_CLOCK
|
import com.google.android.material.timepicker.MaterialTimePicker.INPUT_MODE_CLOCK
|
||||||
import com.google.android.material.timepicker.TimeFormat
|
import com.google.android.material.timepicker.TimeFormat
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.google.gson.reflect.TypeToken
|
|
||||||
import com.simplemobiletools.calendar.pro.R
|
import com.simplemobiletools.calendar.pro.R
|
||||||
import com.simplemobiletools.calendar.pro.adapters.AutoCompleteTextViewAdapter
|
import com.simplemobiletools.calendar.pro.adapters.AutoCompleteTextViewAdapter
|
||||||
import com.simplemobiletools.calendar.pro.databinding.ActivityEventBinding
|
import com.simplemobiletools.calendar.pro.databinding.ActivityEventBinding
|
||||||
@@ -171,7 +169,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
putInt(REPEAT_RULE, mRepeatRule)
|
putInt(REPEAT_RULE, mRepeatRule)
|
||||||
putLong(REPEAT_LIMIT, mRepeatLimit)
|
putLong(REPEAT_LIMIT, mRepeatLimit)
|
||||||
|
|
||||||
putString(ATTENDEES, getAllAttendees(false))
|
putParcelableArrayList(ATTENDEES, getAllAttendees(false))
|
||||||
|
|
||||||
putInt(AVAILABILITY, mAvailability)
|
putInt(AVAILABILITY, mAvailability)
|
||||||
putInt(EVENT_COLOR, mEventColor)
|
putInt(EVENT_COLOR, mEventColor)
|
||||||
@@ -213,8 +211,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
mRepeatRule = getInt(REPEAT_RULE)
|
mRepeatRule = getInt(REPEAT_RULE)
|
||||||
mRepeatLimit = getLong(REPEAT_LIMIT)
|
mRepeatLimit = getLong(REPEAT_LIMIT)
|
||||||
|
|
||||||
val token = object : TypeToken<List<Attendee>>() {}.type
|
mAttendees = getParcelableArrayList(ATTENDEES) ?: arrayListOf()
|
||||||
mAttendees = Gson().fromJson<ArrayList<Attendee>>(getString(ATTENDEES), token) ?: ArrayList()
|
|
||||||
|
|
||||||
mEventTypeId = getLong(EVENT_TYPE_ID)
|
mEventTypeId = getLong(EVENT_TYPE_ID)
|
||||||
mEventCalendarId = getInt(EVENT_CALENDAR_ID)
|
mEventCalendarId = getInt(EVENT_CALENDAR_ID)
|
||||||
@@ -507,8 +504,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
mAvailability = mEvent.availability
|
mAvailability = mEvent.availability
|
||||||
mEventColor = mEvent.color
|
mEventColor = mEvent.color
|
||||||
|
|
||||||
val token = object : TypeToken<List<Attendee>>() {}.type
|
mAttendees = mEvent.attendees.toMutableList() as ArrayList<Attendee>
|
||||||
mAttendees = Gson().fromJson<ArrayList<Attendee>>(mEvent.attendees, token) ?: ArrayList()
|
|
||||||
|
|
||||||
checkRepeatTexts(mRepeatInterval)
|
checkRepeatTexts(mRepeatInterval)
|
||||||
checkAttendees()
|
checkAttendees()
|
||||||
@@ -1310,7 +1306,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
flags = mEvent.flags.addBitIf(binding.eventAllDay.isChecked, FLAG_ALL_DAY)
|
flags = mEvent.flags.addBitIf(binding.eventAllDay.isChecked, FLAG_ALL_DAY)
|
||||||
repeatLimit = if (repeatInterval == 0) 0 else mRepeatLimit
|
repeatLimit = if (repeatInterval == 0) 0 else mRepeatLimit
|
||||||
repeatRule = mRepeatRule
|
repeatRule = mRepeatRule
|
||||||
attendees = if (mEventCalendarId == STORED_LOCALLY_ONLY) "" else getAllAttendees(true)
|
attendees = if (mEventCalendarId == STORED_LOCALLY_ONLY) emptyList() else getAllAttendees(true)
|
||||||
eventType = newEventType
|
eventType = newEventType
|
||||||
lastUpdated = System.currentTimeMillis()
|
lastUpdated = System.currentTimeMillis()
|
||||||
source = newSource
|
source = newSource
|
||||||
@@ -1817,7 +1813,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAllAttendees(isSavingEvent: Boolean): String {
|
private fun getAllAttendees(isSavingEvent: Boolean): ArrayList<Attendee> {
|
||||||
var attendees = ArrayList<Attendee>()
|
var attendees = ArrayList<Attendee>()
|
||||||
mSelectedContacts.forEach {
|
mSelectedContacts.forEach {
|
||||||
attendees.add(it)
|
attendees.add(it)
|
||||||
@@ -1839,7 +1835,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Gson().toJson(attendees)
|
return attendees
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getNames(): List<Attendee> {
|
private fun getNames(): List<Attendee> {
|
||||||
|
@@ -7,8 +7,6 @@ import android.content.Context
|
|||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.provider.CalendarContract.*
|
import android.provider.CalendarContract.*
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.google.gson.reflect.TypeToken
|
|
||||||
import com.simplemobiletools.calendar.pro.R
|
import com.simplemobiletools.calendar.pro.R
|
||||||
import com.simplemobiletools.calendar.pro.extensions.*
|
import com.simplemobiletools.calendar.pro.extensions.*
|
||||||
import com.simplemobiletools.calendar.pro.models.*
|
import com.simplemobiletools.calendar.pro.models.*
|
||||||
@@ -213,7 +211,7 @@ class CalDAVHelper(val context: Context) {
|
|||||||
val originalId = cursor.getStringValue(Events.ORIGINAL_ID)
|
val originalId = cursor.getStringValue(Events.ORIGINAL_ID)
|
||||||
val originalInstanceTime = cursor.getLongValue(Events.ORIGINAL_INSTANCE_TIME)
|
val originalInstanceTime = cursor.getLongValue(Events.ORIGINAL_INSTANCE_TIME)
|
||||||
val reminders = getCalDAVEventReminders(id)
|
val reminders = getCalDAVEventReminders(id)
|
||||||
val attendees = Gson().toJson(getCalDAVEventAttendees(id))
|
val attendees = getCalDAVEventAttendees(id)
|
||||||
val availability = cursor.getIntValue(Events.AVAILABILITY)
|
val availability = cursor.getIntValue(Events.AVAILABILITY)
|
||||||
val status = cursor.getIntValue(Events.STATUS)
|
val status = cursor.getIntValue(Events.STATUS)
|
||||||
val color = cursor.getIntValueOrNull(Events.EVENT_COLOR)
|
val color = cursor.getIntValueOrNull(Events.EVENT_COLOR)
|
||||||
@@ -394,8 +392,7 @@ class CalDAVHelper(val context: Context) {
|
|||||||
|
|
||||||
private fun setupCalDAVEventAttendees(event: Event) {
|
private fun setupCalDAVEventAttendees(event: Event) {
|
||||||
clearEventAttendees(event)
|
clearEventAttendees(event)
|
||||||
val attendees = Gson().fromJson<ArrayList<Attendee>>(event.attendees, object : TypeToken<List<Attendee>>() {}.type) ?: ArrayList()
|
event.attendees.forEach {
|
||||||
attendees.forEach {
|
|
||||||
val contentValues = ContentValues().apply {
|
val contentValues = ContentValues().apply {
|
||||||
put(Attendees.ATTENDEE_NAME, it.name)
|
put(Attendees.ATTENDEE_NAME, it.name)
|
||||||
put(Attendees.ATTENDEE_EMAIL, it.email)
|
put(Attendees.ATTENDEE_EMAIL, it.email)
|
||||||
|
@@ -3,10 +3,12 @@ package com.simplemobiletools.calendar.pro.helpers
|
|||||||
import androidx.room.TypeConverter
|
import androidx.room.TypeConverter
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
|
import com.simplemobiletools.calendar.pro.models.Attendee
|
||||||
|
|
||||||
class Converters {
|
class Converters {
|
||||||
private val gson = Gson()
|
private val gson = Gson()
|
||||||
private val stringType = object : TypeToken<List<String>>() {}.type
|
private val stringType = object : TypeToken<List<String>>() {}.type
|
||||||
|
private val attendeeType = object : TypeToken<List<Attendee>>() {}.type
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun jsonToStringList(value: String): List<String> {
|
fun jsonToStringList(value: String): List<String> {
|
||||||
@@ -25,4 +27,16 @@ class Converters {
|
|||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun stringListToJson(list: List<String>) = gson.toJson(list)
|
fun stringListToJson(list: List<String>) = gson.toJson(list)
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun attendeeListToJson(list: List<Attendee>) = gson.toJson(list)
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun jsonToAttendeeList(value: String): List<Attendee> {
|
||||||
|
return try {
|
||||||
|
gson.fromJson<ArrayList<Attendee>>(value, attendeeType) ?: ArrayList()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -249,7 +249,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||||||
curRepeatRule,
|
curRepeatRule,
|
||||||
curRepeatLimit,
|
curRepeatLimit,
|
||||||
curRepeatExceptions,
|
curRepeatExceptions,
|
||||||
"",
|
emptyList(),
|
||||||
curImportId,
|
curImportId,
|
||||||
DateTimeZone.getDefault().id,
|
DateTimeZone.getDefault().id,
|
||||||
curFlags,
|
curFlags,
|
||||||
|
@@ -2,14 +2,25 @@ package com.simplemobiletools.calendar.pro.models
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.os.Parcelable
|
||||||
import android.provider.CalendarContract
|
import android.provider.CalendarContract
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
|
import kotlinx.parcelize.Parcelize
|
||||||
|
|
||||||
data class Attendee(val contactId: Int, var name: String, val email: String, var status: Int, var photoUri: String, var isMe: Boolean, var relationship: Int) {
|
@Parcelize
|
||||||
|
data class Attendee(
|
||||||
|
val contactId: Int,
|
||||||
|
var name: String,
|
||||||
|
val email: String,
|
||||||
|
var status: Int,
|
||||||
|
var photoUri: String,
|
||||||
|
var isMe: Boolean,
|
||||||
|
var relationship: Int
|
||||||
|
) : Parcelable {
|
||||||
fun getPublicName() = name.ifEmpty { email }
|
fun getPublicName() = name.ifEmpty { email }
|
||||||
|
|
||||||
fun updateImage(context: Context, imageView: ImageView, placeholder: Drawable) {
|
fun updateImage(context: Context, imageView: ImageView, placeholder: Drawable) {
|
||||||
@@ -17,21 +28,21 @@ data class Attendee(val contactId: Int, var name: String, val email: String, var
|
|||||||
imageView.setImageDrawable(placeholder)
|
imageView.setImageDrawable(placeholder)
|
||||||
} else {
|
} else {
|
||||||
val options = RequestOptions()
|
val options = RequestOptions()
|
||||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||||
.error(placeholder)
|
.error(placeholder)
|
||||||
.centerCrop()
|
.centerCrop()
|
||||||
|
|
||||||
Glide.with(context)
|
Glide.with(context)
|
||||||
.load(photoUri)
|
.load(photoUri)
|
||||||
.transition(DrawableTransitionOptions.withCrossFade())
|
.transition(DrawableTransitionOptions.withCrossFade())
|
||||||
.placeholder(placeholder)
|
.placeholder(placeholder)
|
||||||
.apply(options)
|
.apply(options)
|
||||||
.apply(RequestOptions.circleCropTransform())
|
.apply(RequestOptions.circleCropTransform())
|
||||||
.into(imageView)
|
.into(imageView)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showStatusImage() = status == CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED ||
|
fun showStatusImage() = status == CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED ||
|
||||||
status == CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED ||
|
status == CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED ||
|
||||||
status == CalendarContract.Attendees.ATTENDEE_STATUS_TENTATIVE
|
status == CalendarContract.Attendees.ATTENDEE_STATUS_TENTATIVE
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@ data class Event(
|
|||||||
@ColumnInfo(name = "repeat_rule") var repeatRule: Int = 0,
|
@ColumnInfo(name = "repeat_rule") var repeatRule: Int = 0,
|
||||||
@ColumnInfo(name = "repeat_limit") var repeatLimit: Long = 0L,
|
@ColumnInfo(name = "repeat_limit") var repeatLimit: Long = 0L,
|
||||||
@ColumnInfo(name = "repetition_exceptions") var repetitionExceptions: List<String> = emptyList(),
|
@ColumnInfo(name = "repetition_exceptions") var repetitionExceptions: List<String> = emptyList(),
|
||||||
@ColumnInfo(name = "attendees") var attendees: String = "",
|
@ColumnInfo(name = "attendees") var attendees: List<Attendee> = emptyList(),
|
||||||
@ColumnInfo(name = "import_id") var importId: String = "",
|
@ColumnInfo(name = "import_id") var importId: String = "",
|
||||||
@ColumnInfo(name = "time_zone") var timeZone: String = "",
|
@ColumnInfo(name = "time_zone") var timeZone: String = "",
|
||||||
@ColumnInfo(name = "flags") var flags: Int = 0,
|
@ColumnInfo(name = "flags") var flags: Int = 0,
|
||||||
|
@@ -2,6 +2,7 @@ plugins {
|
|||||||
alias(libs.plugins.android).apply(false)
|
alias(libs.plugins.android).apply(false)
|
||||||
alias(libs.plugins.kotlinAndroid).apply(false)
|
alias(libs.plugins.kotlinAndroid).apply(false)
|
||||||
alias(libs.plugins.ksp).apply(false)
|
alias(libs.plugins.ksp).apply(false)
|
||||||
|
alias(libs.plugins.parcelize).apply(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Delete>("clean") {
|
tasks.register<Delete>("clean") {
|
||||||
|
@@ -45,3 +45,5 @@ room = [
|
|||||||
android = { id = "com.android.application", version.ref = "gradlePlugins-agp" }
|
android = { id = "com.android.application", version.ref = "gradlePlugins-agp" }
|
||||||
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
|
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
|
||||||
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||||
|
parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user