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

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

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

@ -1,15 +1,15 @@
package com.todoroo.astrid.api 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 com.todoroo.andlib.utility.AndroidUtilities
import org.tasks.data.entity.Task
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import org.tasks.data.NO_COUNT 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.Tag
import org.tasks.data.entity.TagData 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 @Parcelize
data class TagFilter( data class TagFilter(
@ -35,7 +35,7 @@ data class TagFilter(
get() = tagData.getIcon()!! get() = tagData.getIcon()!!
override val tint: Int override val tint: Int
get() = tagData.getColor()!! get() = tagData.color ?: 0
val uuid: String val uuid: String
get() = tagData.remoteId!! get() = tagData.remoteId!!

@ -199,12 +199,8 @@ class TaskCreator @Inject constructor(
suspend fun createTags(task: Task) { suspend fun createTags(task: Task) {
for (tag in task.tags) { for (tag in task.tags) {
var tagData = tagDataDao.getTagByName(tag) val tagData = tagDataDao.getTagByName(tag)
if (tagData == null) { ?: TagData(name = tag).also { tagDataDao.insert(it) }
tagData = TagData()
tagData.name = tag
tagDataDao.createNew(tagData)
}
tagDao.insert(Tag(task, tagData)) 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.fromVtodo
import org.tasks.caldav.iCalendar.Companion.order import org.tasks.caldav.iCalendar.Companion.order
import org.tasks.caldav.iCalendar.Companion.parent 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.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.FilterDao
import org.tasks.data.dao.GoogleTaskListDao import org.tasks.data.dao.GoogleTaskListDao
import org.tasks.data.Location
import org.tasks.data.dao.LocationDao import org.tasks.data.dao.LocationDao
import org.tasks.data.entity.Tag
import org.tasks.data.dao.TagDao import org.tasks.data.dao.TagDao
import org.tasks.data.entity.TagData
import org.tasks.data.dao.TagDataDao import org.tasks.data.dao.TagDataDao
import org.tasks.data.dao.TaskAttachmentDao import org.tasks.data.dao.TaskAttachmentDao
import org.tasks.data.dao.UpgraderDao import org.tasks.data.dao.UpgraderDao
import org.tasks.data.dao.UserActivityDao 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.DefaultFilterProvider
import org.tasks.preferences.Preferences import org.tasks.preferences.Preferences
import org.tasks.time.DateTimeUtils2.currentTimeMillis import org.tasks.time.DateTimeUtils2.currentTimeMillis
@ -151,8 +151,9 @@ class Upgrader @Inject constructor(
) )
} }
for (tagData in tagDataDao.getAll()) { for (tagData in tagDataDao.getAll()) {
tagData.setColor(getAndroidColor(tagData.getColor()!!)) tagDataDao.update(
tagDataDao.update(tagData) tagData.copy(color = getAndroidColor(tagData.color ?: 0))
)
} }
for (filter in filterDao.getFilters()) { for (filter in filterDao.getFilters()) {
filterDao.update( filterDao.update(

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

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

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

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

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

@ -9,8 +9,8 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.tasks.data.entity.TagData
import org.tasks.data.dao.TagDataDao import org.tasks.data.dao.TagDataDao
import org.tasks.data.entity.TagData
import org.tasks.data.searchTags import org.tasks.data.searchTags
import javax.inject.Inject import javax.inject.Inject
@ -90,8 +90,8 @@ class TagPickerViewModel @Inject constructor(
suspend fun toggle(tagData: TagData, checked: Boolean): ToggleableState { suspend fun toggle(tagData: TagData, checked: Boolean): ToggleableState {
var tagData = tagData var tagData = tagData
if (tagData.id == null) { if (tagData.id == null) {
tagData = TagData(tagData.name) tagData = TagData(name = tagData.name)
tagDataDao.createNew(tagData) .let { it.copy(id = tagDataDao.insert(it)) }
} }
partiallySelected.remove(tagData) partiallySelected.remove(tagData)
return if (checked) { return if (checked) {
@ -104,9 +104,10 @@ class TagPickerViewModel @Inject constructor(
} }
suspend fun createNew(name: String) { suspend fun createNew(name: String) {
val tagData = TagData(name) selected.add(
tagDataDao.createNew(tagData) TagData(name = name)
selected.add(tagData) .let { it.copy(id = tagDataDao.insert(it)) }
)
search("") 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 package org.tasks.sync.microsoft
import com.natpryce.makeiteasy.MakeItEasy.with import com.natpryce.makeiteasy.MakeItEasy.with
import org.tasks.data.entity.Task
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
@ -9,10 +8,10 @@ import org.junit.Test
import org.tasks.Freeze.Companion.freezeAt import org.tasks.Freeze.Companion.freezeAt
import org.tasks.TestUtilities.withTZ import org.tasks.TestUtilities.withTZ
import org.tasks.data.entity.CaldavTask 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.REMOTE_ID
import org.tasks.makers.CaldavTaskMaker.newCaldavTask 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.COMPLETION_TIME
import org.tasks.makers.TaskMaker.DESCRIPTION import org.tasks.makers.TaskMaker.DESCRIPTION
import org.tasks.makers.TaskMaker.DUE_TIME import org.tasks.makers.TaskMaker.DUE_TIME
@ -100,8 +99,8 @@ class ConvertToMicrosoftTests {
val remote = newTask().toRemote( val remote = newTask().toRemote(
newCaldavTask(), newCaldavTask(),
listOf( listOf(
newTagData(with(NAME, "tag1")), TagData(name = "tag1"),
newTagData(with(NAME, "tag2")), TagData(name = "tag2"),
) )
) )
assertEquals(listOf("tag1", "tag2"), remote.categories) assertEquals(listOf("tag1", "tag2"), remote.categories)

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

@ -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…
Cancel
Save