Convert TagData to data class

pull/2906/head
Alex Baker 6 months ago
parent eea944cc7b
commit ad833b5f49

@ -1,9 +1,9 @@
package com.todoroo.astrid.sync
import com.todoroo.astrid.dao.TaskDao
import org.tasks.data.entity.Task
import org.tasks.data.entity.TagData
import org.tasks.data.dao.TagDataDao
import org.tasks.data.entity.TagData
import org.tasks.data.entity.Task
import org.tasks.injection.InjectingTestCase
import javax.inject.Inject
@ -21,9 +21,8 @@ open class NewSyncTestCase : InjectingTestCase() {
}
suspend fun createTagData(): TagData {
val tag = TagData()
tag.name = "new tag"
tagDataDao.createNew(tag)
val tag = TagData(name = "new tag")
tagDataDao.insert(tag)
return tag
}

@ -10,10 +10,9 @@ import org.junit.Assert.assertTrue
import org.junit.Test
import org.tasks.data.dao.TagDao
import org.tasks.data.dao.TagDataDao
import org.tasks.data.entity.TagData
import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule
import org.tasks.makers.TagDataMaker.NAME
import org.tasks.makers.TagDataMaker.newTagData
import org.tasks.makers.TagMaker.TAGDATA
import org.tasks.makers.TagMaker.TAGUID
import org.tasks.makers.TagMaker.TASK
@ -31,13 +30,13 @@ class TagDataDaoTest : InjectingTestCase() {
@Test
fun tagDataOrderedByNameIgnoresNullNames() = runBlocking {
tagDataDao.createNew(newTagData(with(NAME, null as String?)))
tagDataDao.insert(TagData(name = null))
assertTrue(tagDataDao.tagDataOrderedByName().isEmpty())
}
@Test
fun tagDataOrderedByNameIgnoresEmptyNames() = runBlocking {
tagDataDao.createNew(newTagData(with(NAME, "")))
tagDataDao.insert(TagData(name = ""))
assertTrue(tagDataDao.tagDataOrderedByName().isEmpty())
}
@ -48,20 +47,19 @@ class TagDataDaoTest : InjectingTestCase() {
@Test
fun getTagWithCaseFixesCase() = runBlocking {
tagDataDao.createNew(newTagData(with(NAME, "Derp")))
tagDataDao.insert(TagData(name = "Derp"))
assertEquals("Derp", tagDataDao.getTagWithCase("derp"))
}
@Test
fun getTagsByName() = runBlocking {
val tagData = newTagData(with(NAME, "Derp"))
tagDataDao.createNew(tagData)
val tagData = TagData(name = "Derp").let { it.copy(id = tagDataDao.insert(it)) }
assertEquals(listOf(tagData), tagDataDao.getTags(listOf("Derp")))
}
@Test
fun getTagsByNameCaseSensitive() = runBlocking {
tagDataDao.createNew(newTagData(with(NAME, "Derp")))
tagDataDao.insert(TagData(name = "Derp"))
assertTrue(tagDataDao.getTags(listOf("derp")).isEmpty())
}
@ -71,10 +69,8 @@ class TagDataDaoTest : InjectingTestCase() {
val taskTwo = newTask()
taskDao.createNew(taskOne)
taskDao.createNew(taskTwo)
val tagOne = newTagData(with(NAME, "one"))
val tagTwo = newTagData(with(NAME, "two"))
tagDataDao.createNew(tagOne)
tagDataDao.createNew(tagTwo)
val tagOne = TagData(name = "one").let { it.copy(id = tagDataDao.insert(it)) }
val tagTwo = TagData(name = "two").let { it.copy(id = tagDataDao.insert(it)) }
tagDao.insert(newTag(with(TAGDATA, tagOne), with(TASK, taskOne)))
tagDao.insert(newTag(with(TAGDATA, tagTwo), with(TASK, taskTwo)))
assertEquals(listOf(tagOne), tagDataDao.getTagDataForTask(taskOne.id))
@ -83,8 +79,8 @@ class TagDataDaoTest : InjectingTestCase() {
@Test
fun getEmptyTagSelections() = runBlocking {
val selections = tagDataDao.getTagSelections(listOf(1L))
assertTrue(selections.first!!.isEmpty())
assertTrue(selections.second!!.isEmpty())
assertTrue(selections.first.isEmpty())
assertTrue(selections.second.isEmpty())
}
@Test
@ -99,7 +95,7 @@ class TagDataDaoTest : InjectingTestCase() {
fun getEmptyPartialSelections() = runBlocking {
newTag(1, "tag1")
newTag(2, "tag1")
assertTrue(tagDataDao.getTagSelections(listOf(1L, 2L)).first!!.isEmpty())
assertTrue(tagDataDao.getTagSelections(listOf(1L, 2L)).first.isEmpty())
}
@Test
@ -113,15 +109,15 @@ class TagDataDaoTest : InjectingTestCase() {
fun getEmptyCommonSelections() = runBlocking {
newTag(1, "tag1")
newTag(2, "tag2")
assertTrue(tagDataDao.getTagSelections(listOf(1L, 2L)).second!!.isEmpty())
assertTrue(tagDataDao.getTagSelections(listOf(1L, 2L)).second.isEmpty())
}
@Test
fun getSelectionsWithNoTags() = runBlocking {
newTag(1)
val selections = tagDataDao.getTagSelections(listOf(1L))
assertTrue(selections.first!!.isEmpty())
assertTrue(selections.second!!.isEmpty())
assertTrue(selections.first.isEmpty())
assertTrue(selections.second.isEmpty())
}
@Test
@ -130,7 +126,7 @@ class TagDataDaoTest : InjectingTestCase() {
newTag(2)
val selections = tagDataDao.getTagSelections(listOf(1L, 2L))
assertEquals(setOf("tag1"), selections.first)
assertTrue(selections.second!!.isEmpty())
assertTrue(selections.second.isEmpty())
}
private suspend fun newTag(taskId: Long, vararg tags: String) {

@ -13,9 +13,9 @@ import org.tasks.data.dao.TagDao
import org.tasks.data.dao.TagDataDao
import org.tasks.data.dao.UpgraderDao
import org.tasks.data.entity.CaldavTask
import org.tasks.data.entity.TagData
import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule
import org.tasks.makers.TagDataMaker
import org.tasks.makers.TagMaker
import org.tasks.makers.TaskMaker
import javax.inject.Inject
@ -34,10 +34,10 @@ class UpgraderDaoTests : InjectingTestCase() {
fun getCaldavTasksWithTags() = runBlocking {
val task = TaskMaker.newTask(MakeItEasy.with(TaskMaker.ID, 1L))
taskDao.createNew(task)
val one = TagDataMaker.newTagData()
val two = TagDataMaker.newTagData()
tagDataDao.createNew(one)
tagDataDao.createNew(two)
val one = TagData()
val two = TagData()
tagDataDao.insert(one)
tagDataDao.insert(two)
tagDao.insert(TagMaker.newTag(MakeItEasy.with(TagMaker.TASK, task), MakeItEasy.with(TagMaker.TAGDATA, one)))
tagDao.insert(TagMaker.newTag(MakeItEasy.with(TagMaker.TASK, task), MakeItEasy.with(TagMaker.TAGDATA, two)))
caldavDao.insert(CaldavTask(task = task.id, calendar = "calendar"))
@ -48,8 +48,8 @@ class UpgraderDaoTests : InjectingTestCase() {
fun ignoreNonCaldavTaskWithTags() = runBlocking {
val task = TaskMaker.newTask(MakeItEasy.with(TaskMaker.ID, 1L))
taskDao.createNew(task)
val tag = TagDataMaker.newTagData()
tagDataDao.createNew(tag)
val tag = TagData()
tagDataDao.insert(tag)
tagDao.insert(TagMaker.newTag(MakeItEasy.with(TagMaker.TASK, task), MakeItEasy.with(TagMaker.TAGDATA, tag)))
assertTrue(upgraderDao.tasksWithTags().isEmpty())
}
@ -58,7 +58,7 @@ class UpgraderDaoTests : InjectingTestCase() {
fun ignoreCaldavTaskWithoutTags() = runBlocking {
val task = TaskMaker.newTask(MakeItEasy.with(TaskMaker.ID, 1L))
taskDao.createNew(task)
tagDataDao.createNew(TagDataMaker.newTagData())
tagDataDao.insert(TagData())
caldavDao.insert(CaldavTask(task = task.id, calendar = "calendar"))
assertTrue(upgraderDao.tasksWithTags().isEmpty())
}

@ -20,14 +20,13 @@ import org.tasks.data.dao.TagDao
import org.tasks.data.dao.TagDataDao
import org.tasks.data.entity.Alarm
import org.tasks.data.entity.Alarm.Companion.TYPE_SNOOZE
import org.tasks.data.entity.TagData
import org.tasks.data.entity.Task
import org.tasks.injection.ProductionModule
import org.tasks.makers.CaldavTaskMaker
import org.tasks.makers.CaldavTaskMaker.CALENDAR
import org.tasks.makers.CaldavTaskMaker.REMOTE_ID
import org.tasks.makers.CaldavTaskMaker.newCaldavTask
import org.tasks.makers.TagDataMaker.NAME
import org.tasks.makers.TagDataMaker.newTagData
import org.tasks.makers.TagMaker.TAGDATA
import org.tasks.makers.TagMaker.TASK
import org.tasks.makers.TagMaker.newTag
@ -93,8 +92,7 @@ class OpenTasksPropertiesTests : OpenTasksTest() {
@Test
fun matchExistingTag() = runBlocking {
val (_, list) = withVtodo(ONE_TAG)
val tag = newTagData(with(NAME, "Tag1"))
tagDataDao.createNew(tag)
val tag = TagData(name = "Tag1").let { it.copy(id = tagDataDao.insert(it)) }
synchronizer.sync()
@ -304,9 +302,9 @@ class OpenTasksPropertiesTests : OpenTasksTest() {
}
private suspend fun insertTag(task: Task, name: String) =
newTagData(with(NAME, name))
.apply { tagDataDao.createNew(this) }
.let { tagDao.insert(newTag(with(TASK, task), with(TAGDATA, it))) }
TagData(name = name)
.apply { tagDataDao.insert(this) }
.let { tagDao.insert(newTag(with(TASK, task), with(TAGDATA, it))) }
companion object {
private val CHICAGO = TimeZone.getTimeZone("America/Chicago")

@ -1,15 +1,15 @@
package com.todoroo.astrid.api
import org.tasks.data.sql.Criterion.Companion.and
import org.tasks.data.sql.Join.Companion.inner
import org.tasks.data.sql.QueryTemplate
import com.todoroo.andlib.utility.AndroidUtilities
import org.tasks.data.entity.Task
import kotlinx.parcelize.Parcelize
import org.tasks.data.NO_COUNT
import org.tasks.data.dao.TaskDao.TaskCriteria.activeAndVisible
import org.tasks.data.entity.Tag
import org.tasks.data.entity.TagData
import org.tasks.data.dao.TaskDao.TaskCriteria.activeAndVisible
import org.tasks.data.entity.Task
import org.tasks.data.sql.Criterion.Companion.and
import org.tasks.data.sql.Join.Companion.inner
import org.tasks.data.sql.QueryTemplate
@Parcelize
data class TagFilter(
@ -35,7 +35,7 @@ data class TagFilter(
get() = tagData.getIcon()!!
override val tint: Int
get() = tagData.getColor()!!
get() = tagData.color ?: 0
val uuid: String
get() = tagData.remoteId!!

@ -199,12 +199,8 @@ class TaskCreator @Inject constructor(
suspend fun createTags(task: Task) {
for (tag in task.tags) {
var tagData = tagDataDao.getTagByName(tag)
if (tagData == null) {
tagData = TagData()
tagData.name = tag
tagDataDao.createNew(tagData)
}
val tagData = tagDataDao.getTagByName(tag)
?: TagData(name = tag).also { tagDataDao.insert(it) }
tagDao.insert(Tag(task, tagData))
}
}

@ -18,21 +18,21 @@ import org.tasks.caldav.iCalendar
import org.tasks.caldav.iCalendar.Companion.fromVtodo
import org.tasks.caldav.iCalendar.Companion.order
import org.tasks.caldav.iCalendar.Companion.parent
import org.tasks.data.dao.CaldavDao
import org.tasks.data.entity.CaldavTask
import org.tasks.data.CaldavTaskContainer
import org.tasks.data.entity.Filter
import org.tasks.data.Location
import org.tasks.data.dao.CaldavDao
import org.tasks.data.dao.FilterDao
import org.tasks.data.dao.GoogleTaskListDao
import org.tasks.data.Location
import org.tasks.data.dao.LocationDao
import org.tasks.data.entity.Tag
import org.tasks.data.dao.TagDao
import org.tasks.data.entity.TagData
import org.tasks.data.dao.TagDataDao
import org.tasks.data.dao.TaskAttachmentDao
import org.tasks.data.dao.UpgraderDao
import org.tasks.data.dao.UserActivityDao
import org.tasks.data.entity.CaldavTask
import org.tasks.data.entity.Filter
import org.tasks.data.entity.Tag
import org.tasks.data.entity.TagData
import org.tasks.preferences.DefaultFilterProvider
import org.tasks.preferences.Preferences
import org.tasks.time.DateTimeUtils2.currentTimeMillis
@ -151,8 +151,9 @@ class Upgrader @Inject constructor(
)
}
for (tagData in tagDataDao.getAll()) {
tagData.setColor(getAndroidColor(tagData.getColor()!!))
tagDataDao.update(tagData)
tagDataDao.update(
tagData.copy(color = getAndroidColor(tagData.color ?: 0))
)
}
for (filter in filterDao.getFilters()) {
filterDao.update(

@ -16,14 +16,13 @@ import com.google.android.material.textfield.TextInputLayout
import com.todoroo.astrid.activity.MainActivity
import com.todoroo.astrid.activity.TaskListFragment
import com.todoroo.astrid.api.TagFilter
import org.tasks.data.UUIDHelper
import dagger.hilt.android.AndroidEntryPoint
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.Strings.isNullOrEmpty
import org.tasks.data.dao.TagDao
import org.tasks.data.entity.TagData
import org.tasks.data.dao.TagDataDao
import org.tasks.data.entity.TagData
import org.tasks.databinding.ActivityTagSettingsBinding
import org.tasks.extensions.Context.hideKeyboard
import org.tasks.themes.CustomIcons
@ -38,19 +37,17 @@ class TagSettingsActivity : BaseListSettingsActivity() {
private lateinit var name: TextInputEditText
private lateinit var nameLayout: TextInputLayout
private var isNewTag = false
private lateinit var tagData: TagData
private val isNewTag: Boolean
get() = tagData.id == null
override val defaultIcon: Int = CustomIcons.LABEL
override fun onCreate(savedInstanceState: Bundle?) {
tagData = intent.getParcelableExtra(EXTRA_TAG_DATA)
?: TagData().apply {
isNewTag = true
remoteId = UUIDHelper.newUUID()
}
tagData = intent.getParcelableExtra(EXTRA_TAG_DATA) ?: TagData()
super.onCreate(savedInstanceState)
if (savedInstanceState == null) {
selectedColor = tagData.getColor()!!
selectedColor = tagData.color ?: 0
selectedIcon = tagData.getIcon()!!
}
name.setText(tagData.name)
@ -87,23 +84,37 @@ class TagSettingsActivity : BaseListSettingsActivity() {
return
}
if (isNewTag) {
tagData.name = newName
tagData.setColor(selectedColor)
tagData.setIcon(selectedIcon)
tagDataDao.createNew(tagData)
localBroadcastManager.broadcastRefresh()
setResult(Activity.RESULT_OK, Intent().putExtra(MainActivity.OPEN_FILTER, TagFilter(tagData)))
tagData
.copy(
name = newName,
color = selectedColor,
icon = selectedIcon,
)
.let { it.copy(id = tagDataDao.insert(it)) }
.let {
localBroadcastManager.broadcastRefresh()
setResult(
Activity.RESULT_OK,
Intent().putExtra(MainActivity.OPEN_FILTER, TagFilter(it))
)
}
} else if (hasChanges()) {
tagData.name = newName
tagData.setColor(selectedColor)
tagData.setIcon(selectedIcon)
tagDataDao.update(tagData)
tagDao.rename(tagData.remoteId!!, newName)
localBroadcastManager.broadcastRefresh()
setResult(
Activity.RESULT_OK,
Intent(TaskListFragment.ACTION_RELOAD)
.putExtra(MainActivity.OPEN_FILTER, TagFilter(tagData)))
tagData
.copy(
name = newName,
color = selectedColor,
icon = selectedIcon,
)
.let {
tagDataDao.update(it)
tagDao.rename(it.remoteId!!, newName)
localBroadcastManager.broadcastRefresh()
setResult(
Activity.RESULT_OK,
Intent(TaskListFragment.ACTION_RELOAD)
.putExtra(MainActivity.OPEN_FILTER, TagFilter(it))
)
}
}
finish()
}
@ -112,7 +123,7 @@ class TagSettingsActivity : BaseListSettingsActivity() {
return if (isNewTag) {
selectedColor >= 0 || selectedIcon >= 0 || !isNullOrEmpty(newName)
} else {
selectedColor != tagData.getColor()
selectedColor != (tagData.color ?: 0)
|| selectedIcon != tagData.getIcon()
|| newName != tagData.name
}

@ -97,8 +97,9 @@ class TasksJsonImporter @Inject constructor(
findTagData(tagData)?.let {
return@forEach
}
tagData.setColor(themeToColor(context, version, tagData.getColor()!!))
tagDataDao.createNew(tagData)
tagDataDao.insert(
tagData.copy(color = themeToColor(context, version, tagData.color ?: 0))
)
}
backupContainer.googleTaskAccounts?.forEach { googleTaskAccount ->
if (caldavDao.getAccount(TYPE_GOOGLE_TASKS, googleTaskAccount.account!!) == null) {

@ -133,9 +133,10 @@ class iCalendar @Inject constructor(
val existing = tags.map(TagData::name)
val toCreate = categories subtract existing
for (name in toCreate) {
val tag = TagData(name)
tagDataDao.createNew(tag)
tags.add(tag)
tags.add(
TagData(name = name)
.let { it.copy(id = tagDataDao.insert(it)) }
)
}
return tags
}

@ -38,7 +38,7 @@ fun TagsRow(
R.drawable.ic_outline_label_24px
),
name = tag.name,
theme = tag.getColor()!!,
theme = tag.color ?: 0,
showText = true,
showIcon = true,
onClick = onClick,
@ -74,10 +74,11 @@ fun SingleTag() {
MdcTheme {
TagsRow(
tags = listOf(
TagData("Home").apply {
setIcon(1062)
setColor(ColorProvider.BLUE_500)
}
TagData(
name = "Home",
icon = 1062,
color = ColorProvider.BLUE_500
)
),
colorProvider = { it },
onClick = {},
@ -92,11 +93,11 @@ fun BunchOfTags() {
MdcTheme {
TagsRow(
tags = listOf(
TagData("One"),
TagData("Two"),
TagData("Three"),
TagData("Four"),
TagData("Five"),
TagData(name = "One"),
TagData(name = "Two"),
TagData(name = "Three"),
TagData(name = "Four"),
TagData(name = "Five"),
),
colorProvider = { it },
onClick = {},
@ -111,10 +112,11 @@ fun TagWithReallyLongName() {
MdcTheme {
TagsRow(
tags = listOf(
TagData("This is a tag with a really really long name").apply {
setIcon(1062)
setColor(ColorProvider.BLUE_500)
}
TagData(
name = "This is a tag with a really really long name",
icon = 1062,
color = ColorProvider.BLUE_500
)
),
colorProvider = { it },
onClick = {},

@ -103,8 +103,8 @@ class TagPickerActivity : ThemedInjectingAppCompatActivity() {
} /* handleBackPressed */
private fun getColor(tagData: TagData): Color {
if (tagData.getColor() != 0) {
val themeColor = colorProvider.getThemeColor(tagData.getColor()!!, true)
if ((tagData.color ?: 0) != 0) {
val themeColor = colorProvider.getThemeColor(tagData.color ?: 0, true)
if (inventory.purchasedThemes() || themeColor.isFree) {
return Color(themeColor.primaryColor)
}

@ -9,8 +9,8 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import org.tasks.data.entity.TagData
import org.tasks.data.dao.TagDataDao
import org.tasks.data.entity.TagData
import org.tasks.data.searchTags
import javax.inject.Inject
@ -90,8 +90,8 @@ class TagPickerViewModel @Inject constructor(
suspend fun toggle(tagData: TagData, checked: Boolean): ToggleableState {
var tagData = tagData
if (tagData.id == null) {
tagData = TagData(tagData.name)
tagDataDao.createNew(tagData)
tagData = TagData(name = tagData.name)
.let { it.copy(id = tagDataDao.insert(it)) }
}
partiallySelected.remove(tagData)
return if (checked) {
@ -104,9 +104,10 @@ class TagPickerViewModel @Inject constructor(
}
suspend fun createNew(name: String) {
val tagData = TagData(name)
tagDataDao.createNew(tagData)
selected.add(tagData)
selected.add(
TagData(name = name)
.let { it.copy(id = tagDataDao.insert(it)) }
)
search("")
}
}

@ -1,25 +0,0 @@
package org.tasks.makers
import com.natpryce.makeiteasy.Instantiator
import com.natpryce.makeiteasy.Property
import com.natpryce.makeiteasy.Property.newProperty
import com.natpryce.makeiteasy.PropertyLookup
import com.natpryce.makeiteasy.PropertyValue
import org.tasks.data.entity.TagData
import org.tasks.makers.Maker.make
object TagDataMaker {
val NAME: Property<TagData, String> = newProperty()
val UID: Property<TagData, String?> = newProperty()
private val instantiator = Instantiator { lookup: PropertyLookup<TagData> ->
val tagData = TagData()
tagData.name = lookup.valueOf(NAME, "tag")
tagData.remoteId = lookup.valueOf(UID, null as String?)
tagData
}
fun newTagData(vararg properties: PropertyValue<in TagData?, *>): TagData {
return make(instantiator, *properties)
}
}

@ -1,7 +1,6 @@
package org.tasks.sync.microsoft
import com.natpryce.makeiteasy.MakeItEasy.with
import org.tasks.data.entity.Task
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
@ -9,10 +8,10 @@ import org.junit.Test
import org.tasks.Freeze.Companion.freezeAt
import org.tasks.TestUtilities.withTZ
import org.tasks.data.entity.CaldavTask
import org.tasks.data.entity.TagData
import org.tasks.data.entity.Task
import org.tasks.makers.CaldavTaskMaker.REMOTE_ID
import org.tasks.makers.CaldavTaskMaker.newCaldavTask
import org.tasks.makers.TagDataMaker.NAME
import org.tasks.makers.TagDataMaker.newTagData
import org.tasks.makers.TaskMaker.COMPLETION_TIME
import org.tasks.makers.TaskMaker.DESCRIPTION
import org.tasks.makers.TaskMaker.DUE_TIME
@ -100,8 +99,8 @@ class ConvertToMicrosoftTests {
val remote = newTask().toRemote(
newCaldavTask(),
listOf(
newTagData(with(NAME, "tag1")),
newTagData(with(NAME, "tag2")),
TagData(name = "tag1"),
TagData(name = "tag2"),
)
)
assertEquals(listOf("tag1", "tag2"), remote.categories)

@ -9,7 +9,6 @@ import androidx.room.Update
import kotlinx.coroutines.flow.Flow
import org.tasks.data.NO_ORDER
import org.tasks.data.TagFilters
import org.tasks.data.UUIDHelper
import org.tasks.data.db.DbUtils
import org.tasks.data.entity.Tag
import org.tasks.data.entity.TagData
@ -130,13 +129,6 @@ abstract class TagDataDao {
@Insert
abstract suspend fun insert(tags: Iterable<Tag>)
suspend fun createNew(tag: TagData) {
if (Task.isUuidEmpty(tag.remoteId)) {
tag.remoteId = UUIDHelper.newUUID()
}
tag.id = insert(tag)
}
@Query("SELECT tagdata.*, COUNT(tasks._id) AS count"
+ " FROM tagdata"
+ " LEFT JOIN tags ON tags.tag_uid = tagdata.remoteId"

@ -1,126 +1,37 @@
package org.tasks.data.entity
import android.annotation.SuppressLint
import android.os.Parcel
import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import org.tasks.data.LABEL
import org.tasks.data.NO_ORDER
import org.tasks.data.UUIDHelper
@Parcelize
@Serializable
@Entity(tableName = "tagdata")
class TagData : Parcelable {
data class TagData(
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "_id")
@Transient
var id: Long? = null
val id: Long? = null,
@ColumnInfo(name = "remoteId")
var remoteId: String? = Task.NO_UUID
val remoteId: String? = UUIDHelper.newUUID(),
@ColumnInfo(name = "name")
var name: String? = ""
val name: String? = "",
@ColumnInfo(name = "color")
private var color: Int? = 0
val color: Int? = 0,
@ColumnInfo(name = "tagOrdering")
var tagOrdering: String? = "[]"
val tagOrdering: String? = "[]",
@ColumnInfo(name = "td_icon")
private var icon: Int? = -1
private val icon: Int? = -1,
@ColumnInfo(name = "td_order")
var order = NO_ORDER
@Ignore
constructor(name: String?) {
this.name = name
}
constructor()
@SuppressLint("ParcelClassLoader")
@Ignore
private constructor(parcel: Parcel) {
with(parcel) {
id = readValue(null) as Long?
remoteId = readString()
name = readString()
color = readInt()
tagOrdering = readString()
icon = readInt()
order = readInt()
}
}
@Suppress("RedundantNullableReturnType")
fun getColor(): Int? = color ?: 0
fun setColor(color: Int?) {
this.color = color
}
val order: Int = NO_ORDER,
) : Parcelable {
@Suppress("RedundantNullableReturnType")
fun getIcon(): Int? = icon ?: LABEL
fun setIcon(icon: Int?) {
this.icon = icon
}
override fun describeContents() = 0
override fun writeToParcel(dest: Parcel, flags: Int) {
with(dest) {
writeValue(id)
writeString(remoteId)
writeString(name)
writeInt(color!!)
writeString(tagOrdering)
writeInt(getIcon()!!)
writeInt(order)
}
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is TagData) return false
if (id != other.id) return false
if (remoteId != other.remoteId) return false
if (name != other.name) return false
if (color != other.color) return false
if (tagOrdering != other.tagOrdering) return false
if (icon != other.icon) return false
if (order != other.order) return false
return true
}
override fun hashCode(): Int {
var result = id?.hashCode() ?: 0
result = 31 * result + (remoteId?.hashCode() ?: 0)
result = 31 * result + (name?.hashCode() ?: 0)
result = 31 * result + (color ?: 0)
result = 31 * result + (tagOrdering?.hashCode() ?: 0)
result = 31 * result + (icon ?: 0)
result = 31 * result + order
return result
}
override fun toString(): String =
"TagData(id=$id, remoteId=$remoteId, name=$name, color=$color, tagOrdering=$tagOrdering, icon=$icon, order=$order)"
companion object {
@JvmField val CREATOR: Parcelable.Creator<TagData> = object : Parcelable.Creator<TagData> {
override fun createFromParcel(source: Parcel): TagData = TagData(source)
override fun newArray(size: Int): Array<TagData?> = arrayOfNulls(size)
}
}
}
}

Loading…
Cancel
Save