mirror of https://github.com/tasks/tasks
Convert TagData to data class
parent
eea944cc7b
commit
ad833b5f49
@ -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,126 +1,37 @@
|
|||||||
package org.tasks.data.entity
|
package org.tasks.data.entity
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.os.Parcel
|
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.Ignore
|
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
|
import kotlinx.parcelize.Parcelize
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.Transient
|
import kotlinx.serialization.Transient
|
||||||
import org.tasks.data.LABEL
|
import org.tasks.data.LABEL
|
||||||
import org.tasks.data.NO_ORDER
|
import org.tasks.data.NO_ORDER
|
||||||
|
import org.tasks.data.UUIDHelper
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
@Serializable
|
@Serializable
|
||||||
@Entity(tableName = "tagdata")
|
@Entity(tableName = "tagdata")
|
||||||
class TagData : Parcelable {
|
data class TagData(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
@ColumnInfo(name = "_id")
|
@ColumnInfo(name = "_id")
|
||||||
@Transient
|
@Transient
|
||||||
var id: Long? = null
|
val id: Long? = null,
|
||||||
|
|
||||||
@ColumnInfo(name = "remoteId")
|
@ColumnInfo(name = "remoteId")
|
||||||
var remoteId: String? = Task.NO_UUID
|
val remoteId: String? = UUIDHelper.newUUID(),
|
||||||
|
|
||||||
@ColumnInfo(name = "name")
|
@ColumnInfo(name = "name")
|
||||||
var name: String? = ""
|
val name: String? = "",
|
||||||
|
|
||||||
@ColumnInfo(name = "color")
|
@ColumnInfo(name = "color")
|
||||||
private var color: Int? = 0
|
val color: Int? = 0,
|
||||||
|
|
||||||
@ColumnInfo(name = "tagOrdering")
|
@ColumnInfo(name = "tagOrdering")
|
||||||
var tagOrdering: String? = "[]"
|
val tagOrdering: String? = "[]",
|
||||||
|
|
||||||
@ColumnInfo(name = "td_icon")
|
@ColumnInfo(name = "td_icon")
|
||||||
private var icon: Int? = -1
|
private val icon: Int? = -1,
|
||||||
|
|
||||||
@ColumnInfo(name = "td_order")
|
@ColumnInfo(name = "td_order")
|
||||||
var order = NO_ORDER
|
val order: Int = NO_ORDER,
|
||||||
|
) : Parcelable {
|
||||||
@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
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("RedundantNullableReturnType")
|
@Suppress("RedundantNullableReturnType")
|
||||||
fun getIcon(): Int? = icon ?: LABEL
|
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…
Reference in New Issue