├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .github ├── renovate.json └── workflows │ └── build.yml ├── .gitignore ├── src ├── main │ └── java │ │ └── com │ │ └── todoist │ │ └── pojo │ │ ├── StatsDay.kt │ │ ├── Thumbnail.kt │ │ ├── Feature.kt │ │ ├── StatsWeek.kt │ │ ├── HabitPushNotifications.kt │ │ ├── Tooltips.kt │ │ ├── QuickAddCustomization.kt │ │ ├── NavigationCustomization.kt │ │ ├── NotificationFeature.kt │ │ ├── Stats.kt │ │ ├── TzInfo.kt │ │ ├── CompletedInfo.kt │ │ ├── Features.kt │ │ ├── Model.kt │ │ ├── WorkspaceUser.kt │ │ ├── Event.kt │ │ ├── Filter.kt │ │ ├── Label.kt │ │ ├── Note.kt │ │ ├── UserSettings.kt │ │ ├── EventExtraData.kt │ │ ├── Section.kt │ │ ├── UserPlan.kt │ │ ├── Sanitizers.kt │ │ ├── Due.kt │ │ ├── Reminder.kt │ │ ├── Colors.kt │ │ ├── Collaborator.kt │ │ ├── FileAttachment.kt │ │ ├── Workspace.kt │ │ ├── User.kt │ │ ├── Avatar.kt │ │ ├── Item.kt │ │ ├── Project.kt │ │ ├── ViewOption.kt │ │ ├── LiveNotification.kt │ │ └── Person.kt └── test │ └── java │ └── com │ └── todoist │ └── pojo │ └── PersonTest.kt ├── LICENSE ├── README.md ├── gradlew.bat └── gradlew /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Doist/TodoistPojos/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "github>doist/renovate-config:kotlin-base" 4 | ], 5 | "enabled": false 6 | } 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | *.ipr 4 | *.iws 5 | classes 6 | out 7 | .gradle 8 | build 9 | local.properties 10 | .DS_Store 11 | Thumbs.db 12 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/StatsDay.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class StatsDay(open var date: String, open var totalCompleted: Int) 4 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Thumbnail.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Thumbnail(open val url: String, open val width: Int, open val height: Int) 4 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Feature.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Feature( 4 | open val name: String, 5 | open val shown: Boolean, 6 | ) 7 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/StatsWeek.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class StatsWeek(open var from: String, open var to: String, open var totalCompleted: Int) 4 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/HabitPushNotifications.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class HabitPushNotifications(open val features: List) 4 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Tooltips.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Tooltips( 4 | open val scheduled: Set = emptySet(), 5 | open val seen: Set = emptySet() 6 | ) 7 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/QuickAddCustomization.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class QuickAddCustomization( 4 | open val features: List, 5 | open val isLabelsShown: Boolean 6 | ) 7 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/NavigationCustomization.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class NavigationCustomization( 4 | open val features: List, 5 | open val isCountsShown: Boolean 6 | ) 7 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/NotificationFeature.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class NotificationFeature( 4 | open val name: String, 5 | open val enabled: Boolean, 6 | open val sendAt: String?, 7 | ) 8 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Stats.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Stats( 4 | open var completedCount: Int, 5 | open var daysItems: List, 6 | open var weekItems: List 7 | ) 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/TzInfo.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class TzInfo( 4 | open var text: String?, 5 | open var timezone: String, 6 | open var minutes: Int, 7 | open var hours: Int, 8 | open var isDst: Boolean, 9 | var gmtString: String? 10 | ) 11 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/CompletedInfo.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class CompletedInfo( 4 | open val projectId: String?, 5 | open val sectionId: String?, 6 | open val itemId: String?, 7 | open val completedItems: Int, 8 | open val archivedSections: Int? 9 | ) 10 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Features.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Features( 4 | open var text: String?, 5 | open var isBeta: Boolean, 6 | open var isDateistInlineDisabled: Boolean, 7 | open var dateistLang: String?, 8 | open var isGoldThemeEnabled: Boolean, 9 | open var isAutoAcceptInvitesDisabled: Boolean, 10 | open var isTeamsFlagEnabled: Boolean, 11 | ) 12 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Model.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Model(open var id: String, open var isDeleted: Boolean) { 4 | override fun equals(other: Any?) = when { 5 | this === other -> true 6 | other == null || javaClass != other.javaClass -> false 7 | else -> id == (other as Model).id 8 | } 9 | 10 | override fun hashCode() = id.hashCode() 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/WorkspaceUser.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class WorkspaceUser( 4 | id: String, 5 | open var workspaceId: String, 6 | open var email: String, 7 | open var fullName: String?, 8 | open var timeZone: String?, 9 | open var imageId: String?, 10 | open var workspaceRole: Workspace.Role, 11 | isDeleted: Boolean, 12 | ) : Model(id, isDeleted) 13 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Event.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Event( 4 | open var parentProjectId: String?, 5 | open var parentItemId: String?, 6 | open var eventType: String?, 7 | open var objectType: String?, 8 | open var objectId: String?, 9 | open var initiatorId: String?, 10 | open var eventDate: Long?, 11 | open var eventExtraData: E?, 12 | open var id: String 13 | ) 14 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Filter.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Filter @JvmOverloads constructor( 4 | id: String, 5 | open var name: String, 6 | open var color: String = Colors.DEFAULT_COLOR_NAME, 7 | open var query: String, 8 | open var itemOrder: Int, 9 | open var isFavorite: Boolean, 10 | isDeleted: Boolean = false 11 | ) : Model(id, isDeleted) { 12 | companion object { 13 | @JvmStatic 14 | fun sanitizeName(name: String): String = name.trim() 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Label.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Label @JvmOverloads constructor( 4 | id: String, 5 | open var name: String, 6 | open var color: String = Colors.DEFAULT_COLOR_NAME, 7 | open var itemOrder: Int, 8 | open var isFavorite: Boolean, 9 | isDeleted: Boolean = false 10 | ) : Model(id, isDeleted) { 11 | companion object { 12 | @JvmStatic 13 | fun sanitizeName(name: String): String = 14 | Sanitizers.LABEL_NAME_INVALID_PATTERN.matcher(name.trim()) 15 | .replaceAll(Sanitizers.REPLACEMENT) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | pull_request: 5 | branches: [ main ] 6 | push: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | timeout-minutes: 10 13 | steps: 14 | - name: Checkout repo 15 | uses: actions/checkout@v3 16 | 17 | - name: Setup Java 18 | uses: actions/setup-java@v3 19 | with: 20 | distribution: "adopt" 21 | java-version: "11" 22 | 23 | - name: Setup Gradle 24 | uses: gradle/actions/setup-gradle@v4 25 | 26 | - name: Run build 27 | run: ./gradlew build 28 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Note.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Note @JvmOverloads constructor( 4 | id: String, 5 | open var v2Id: String? = null, 6 | open var content: String?, 7 | open var postedAt: Long = System.currentTimeMillis(), 8 | open var postedUid: String, 9 | open var uidsToNotify: Set = emptySet(), 10 | open var fileAttachment: F? = null, 11 | open var reactions: Map> = emptyMap(), 12 | open var projectId: String?, 13 | open var itemId: String?, 14 | open var isArchived: Boolean = false, 15 | isDeleted: Boolean = false 16 | ) : Model(id, isDeleted) 17 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/UserSettings.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class UserSettings< 4 | Q : QuickAddCustomization, 5 | N : NavigationCustomization, 6 | P : HabitPushNotifications, 7 | >( 8 | open val reminderPush: Boolean, 9 | open val reminderDesktop: Boolean, 10 | open val reminderEmail: Boolean, 11 | open val completedSoundDesktop: Boolean, 12 | open val completedSoundMobile: Boolean, 13 | open val resetRecurringSubtasks: Boolean, 14 | open val quickAddCustomization: Q?, 15 | open val navigationCustomization: N?, 16 | open val habitPushNotifications: P?, 17 | ) 18 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/EventExtraData.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class EventExtraData( 4 | open var content: String?, 5 | open var lastContent: String?, 6 | open var description: String?, 7 | open var lastDescription: String?, 8 | open var dueDate: Long?, 9 | open var lastDueDate: Long?, 10 | open var responsibleUid: String?, 11 | open var lastResponsibleUid: String?, 12 | open var name: String?, 13 | open var lastName: String?, 14 | open var parentProjectName: String?, 15 | open var parentProjectColor: String?, 16 | open var parentItemContent: String?, 17 | open var noteCount: Int?, 18 | open var subTasksReset: Int?, 19 | ) 20 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Section.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Section @JvmOverloads constructor( 4 | id: String, 5 | open var v2Id: String? = null, 6 | open var name: String, 7 | open var projectId: String, 8 | open var sectionOrder: Int = 0, 9 | open var isCollapsed: Boolean = false, 10 | open var addedAt: Long = 0, 11 | open var isArchived: Boolean = false, 12 | open var archivedAt: Long? = null, 13 | isDeleted: Boolean = false 14 | ) : Model(id, isDeleted) { 15 | companion object { 16 | const val DEFAULT_CHILD_ORDER = 1 17 | const val MIN_DEPTH = 0 18 | 19 | @JvmStatic 20 | fun sanitizeName(name: String): String = 21 | Sanitizers.SECTION_NAME_INVALID_PATTERN.matcher(name.trim()) 22 | .replaceAll(Sanitizers.REPLACEMENT) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/UserPlan.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | interface UserPlan { 4 | val planName: String 5 | val maxProjects: Int 6 | val maxTasks: Int 7 | val maxSections: Int 8 | val maxFilters: Int 9 | val maxLabels: Int 10 | val maxCollaborators: Int 11 | val maxRemindersTime: Int 12 | val maxRemindersLocation: Int 13 | val uploadLimitMb: Int 14 | val weeklyTrends: Boolean 15 | val customizationColor: Boolean 16 | val automaticBackups: Boolean 17 | val emailForwarding: Boolean 18 | val calendarFeeds: Boolean 19 | val templates: Boolean 20 | val activityLog: Boolean 21 | val activityLogLimit: Int 22 | val comments: Boolean 23 | val reminders: Boolean 24 | val labels: Boolean 25 | val filters: Boolean 26 | val completedTasks: Boolean 27 | val uploads: Boolean 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Sanitizers.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | import java.util.regex.Pattern 4 | 5 | object Sanitizers { 6 | const val WORKSPACE_NAME_INVALID_CHARACTERS = "[#\"()|&!,]+" 7 | const val PROJECT_NAME_INVALID_CHARACTERS = "#\"()|&!," 8 | const val SECTION_NAME_INVALID_CHARACTERS = "/\"()|&!," 9 | const val LABEL_NAME_INVALID_CHARACTERS = "@\"\\s()|&!," 10 | 11 | @JvmField 12 | val WORKSPACE_NAME_INVALID_PATTERN: Pattern = 13 | Pattern.compile("[$WORKSPACE_NAME_INVALID_CHARACTERS]+") 14 | 15 | @JvmField 16 | val PROJECT_NAME_INVALID_PATTERN: Pattern = 17 | Pattern.compile("[$PROJECT_NAME_INVALID_CHARACTERS]+") 18 | 19 | @JvmField 20 | val SECTION_NAME_INVALID_PATTERN: Pattern = 21 | Pattern.compile("[$SECTION_NAME_INVALID_CHARACTERS]+") 22 | 23 | @JvmField 24 | val LABEL_NAME_INVALID_PATTERN: Pattern = Pattern.compile("[$LABEL_NAME_INVALID_CHARACTERS]+") 25 | 26 | const val REPLACEMENT = "_" 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/todoist/pojo/PersonTest.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertEquals 5 | 6 | class PersonTest { 7 | @Test 8 | fun getDefaultAvatarText() { 9 | listOf( 10 | Triple("First Last", "test@doist.com", "FL"), 11 | Triple("Not capitalized", "test@doist.com", "NC"), 12 | Triple(" White\n\nSpace ", "test@doist.com", "WS"), 13 | Triple("ã ž", "test@doist.com", "ÃŽ"), 14 | Triple("Ludwig van Beethoven", "test@doist.com", "LB"), 15 | Triple("[Spe-cial], (Chars)", "test@doist.com", "SC"), 16 | Triple("\u00A0NO-BREAK\u00A0SPACE\u00A0", "test@doist.com", "NS"), 17 | Triple("Mononym", "test@doist.com", "M"), 18 | Triple("Q", "test@doist.com", "Q"), 19 | Triple(" ", "test@doist.com", "T"), 20 | ).forEach { (fullName, email, defaultAvatarText) -> 21 | assertEquals(defaultAvatarText, Person.getDefaultAvatarText(fullName, email)) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Due.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Due( 4 | open val date: String, 5 | open val timezone: String?, 6 | open val string: String?, 7 | open val lang: String, 8 | open val isRecurring: Boolean 9 | ) { 10 | 11 | override fun equals(other: Any?): Boolean { 12 | if (this === other) { 13 | return true 14 | } 15 | if (other == null || javaClass != other.javaClass) { 16 | return false 17 | } 18 | 19 | val d = other as Due 20 | return date == d.date && timezone == d.timezone && string == d.string && lang == d.lang 21 | && isRecurring == d.isRecurring 22 | } 23 | 24 | override fun hashCode(): Int { 25 | var hash = 23 26 | hash = 31 * hash + date.hashCode() 27 | hash = 31 * hash + (timezone?.hashCode() ?: 0) 28 | hash = 31 * hash + string.hashCode() 29 | hash = 31 * hash + lang.hashCode() 30 | hash = 31 * hash + if (isRecurring) 1231 else 1237 31 | return hash 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Doist 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Reminder.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Reminder @JvmOverloads constructor( 4 | id: String, 5 | open var v2Id: String? = null, 6 | open var type: String?, 7 | /** Exclusive to reminders of type [.TYPE_ABSOLUTE]. */ 8 | open var due: D?, 9 | /** Exclusive to reminders of type [.TYPE_RELATIVE]. */ 10 | open var minuteOffset: Int?, 11 | /** Exclusive to reminders of type [.TYPE_LOCATION]. */ 12 | open var name: String?, 13 | /** Exclusive to reminders of type [.TYPE_LOCATION]. */ 14 | open var locLat: Double?, 15 | /** Exclusive to reminders of type [.TYPE_LOCATION]. */ 16 | open var locLong: Double?, 17 | /** Exclusive to reminders of type [.TYPE_LOCATION]. */ 18 | open var radius: Int?, 19 | /** Exclusive to reminders of type [.TYPE_LOCATION]. */ 20 | open var locTrigger: String?, 21 | open var notifyUid: String?, 22 | open var itemId: String, 23 | isDeleted: Boolean = false 24 | ) : Model(id, isDeleted) { 25 | open val isAbsolute get() = TYPE_ABSOLUTE == type 26 | open val isRelative get() = TYPE_RELATIVE == type 27 | open val isLocation get() = TYPE_LOCATION == type 28 | 29 | companion object { 30 | const val TYPE_ABSOLUTE = "absolute" 31 | const val TYPE_RELATIVE = "relative" 32 | const val TYPE_LOCATION = "location" 33 | 34 | const val DEFAULT_MINUTE_OFFSET = 30 35 | 36 | const val LOC_TRIGGER_ON_ENTER = "on_enter" 37 | const val LOC_TRIGGER_ON_LEAVE = "on_leave" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Colors.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | /** 4 | * Available colors, as ARGB ints. 5 | */ 6 | object Colors { 7 | const val BERRY_RED = 0xFFB8255Fu 8 | const val RED = 0xFFDB4035u 9 | const val ORANGE = 0xFFFF9933u 10 | const val YELLOW = 0xFFFAD000u 11 | const val OLIVE_GREEN = 0xFFAFB83Bu 12 | const val LIME_GREEN = 0xFF7ECC49u 13 | const val GREEN = 0xFF299438u 14 | const val MINT_GREEN = 0xFF6ACCBCu 15 | const val TEAL = 0xFF158FADu 16 | const val SKY_BLUE = 0xFF14AAF5u 17 | const val LIGHT_BLUE = 0xFF96C3EBu 18 | const val BLUE = 0xFF4073FFu 19 | const val GRAPE = 0xFF884DFFu 20 | const val VIOLET = 0xFFAF38EBu 21 | const val LAVENDER = 0xFFEB96EBu 22 | const val MAGENTA = 0xFFE05194u 23 | const val SALMON = 0xFFFF8D85u 24 | const val CHARCOAL = 0xFF808080u 25 | const val GRAY = 0xFFB8B8B8u 26 | const val TAUPE = 0xFFCCAC93u 27 | 28 | const val DEFAULT_COLOR_ID = 48 // GRAY. 29 | const val DEFAULT_COLOR_NAME = "grey" 30 | 31 | private val COLORS = uintArrayOf( 32 | BERRY_RED, RED, ORANGE, YELLOW, OLIVE_GREEN, LIME_GREEN, GREEN, MINT_GREEN, TEAL, 33 | SKY_BLUE, LIGHT_BLUE, BLUE, GRAPE, VIOLET, LAVENDER, MAGENTA, SALMON, CHARCOAL, 34 | GRAY, TAUPE 35 | ).toIntArray() 36 | 37 | fun getColor(colorId: Int): Int { 38 | // Color ids start at 30. Subtract that value, so it can be mapped to the array's index. 39 | val colorIndex = colorId - 30 40 | return if (colorIndex >= 0 && colorIndex < COLORS.size) COLORS[colorIndex] else GRAY.toInt() 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Collaborator.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Collaborator @JvmOverloads constructor( 4 | id: String, 5 | email: String, 6 | fullName: String = "", 7 | imageId: String? = null, 8 | isDeleted: Boolean = false 9 | ) : Person(id, email, fullName, imageId, isDeleted) { 10 | sealed class Role(protected open val key: String) { 11 | object Creator : Role("CREATOR") 12 | 13 | object Admin : Role("ADMIN") 14 | 15 | object ReadWrite : Role("READ_WRITE") 16 | 17 | object ReadAndComment : Role("READ_AND_COMMENT") 18 | 19 | object ReadOnly : Role("READ_ONLY") 20 | 21 | data class Unknown(override val key: String) : Role(key) 22 | 23 | object Invalid : Role("INVALID") 24 | 25 | override fun toString() = key 26 | 27 | companion object { 28 | fun get(typeKey: String?): Role { 29 | val upperCasedKey = typeKey?.uppercase() 30 | return when { 31 | upperCasedKey.isNullOrEmpty() -> Invalid 32 | upperCasedKey == Creator.key -> Creator 33 | upperCasedKey == Admin.key -> Admin 34 | upperCasedKey == ReadWrite.key -> ReadWrite 35 | upperCasedKey == ReadAndComment.key -> ReadAndComment 36 | upperCasedKey == ReadOnly.key -> ReadOnly 37 | else -> Unknown(typeKey) 38 | } 39 | } 40 | } 41 | } 42 | 43 | companion object { 44 | const val STATE_ACTIVE = "active" 45 | const val STATE_INVITED = "invited" 46 | const val STATE_DELETED = "deleted" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/FileAttachment.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class FileAttachment( 4 | open var resourceType: String?, 5 | open var fileUrl: String?, 6 | open var fileName: String?, 7 | open var fileType: String?, 8 | open var uploadState: String?, 9 | open var fileSize: Long?, 10 | open var fileDuration: Long?, 11 | open var image: String?, 12 | open var imageWidth: Int?, 13 | open var imageHeight: Int?, 14 | open var url: String?, 15 | open var title: String?, 16 | open var description: String? 17 | ) { 18 | val isUploadCompleted get() = uploadState == UPLOAD_STATE_COMPLETED 19 | val isUploadCanceled get() = uploadState == UPLOAD_STATE_CANCELED 20 | val isUploadPending get() = uploadState == UPLOAD_STATE_PENDING 21 | 22 | companion object { 23 | const val RESOURCE_TYPE_FILE = "file" 24 | const val RESOURCE_TYPE_IMAGE = "image" 25 | const val RESOURCE_TYPE_VIDEO = "video" 26 | const val RESOURCE_TYPE_AUDIO = "audio" 27 | const val RESOURCE_TYPE_WEBSITE = "website" 28 | 29 | /** 30 | * The upload is currently pending, meaning it's waiting for upload, currently being 31 | * uploaded, or the upload failed but the user hasn't chosen to retry or cancel. 32 | */ 33 | const val UPLOAD_STATE_PENDING = "pending" 34 | 35 | /** 36 | * The upload has been successfully completed. 37 | */ 38 | const val UPLOAD_STATE_COMPLETED = "completed" 39 | 40 | /** 41 | * The upload has failed and the user chose to cancel it. 42 | */ 43 | const val UPLOAD_STATE_CANCELED = "canceled" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Workspace.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Workspace( 4 | id: String, 5 | open var name: String, 6 | open var description: String?, 7 | open var role: Role, 8 | open var linkSharingEnabled: Boolean?, 9 | open var inviteCode: String?, 10 | open var logoBig: String?, 11 | open var logoMedium: String?, 12 | open var logoSmall: String?, 13 | open var logoS640: String?, 14 | open var createdAt: Long, 15 | open var isCollapsed: Boolean, 16 | isDeleted: Boolean, 17 | ) : Model(id, isDeleted) { 18 | sealed class Role(protected open val key: String) { 19 | object Admin : Role("ADMIN") 20 | 21 | object Member : Role("MEMBER") 22 | 23 | object Guest : Role("GUEST") 24 | 25 | data class Unknown(override val key: String) : Role(key) 26 | 27 | object Invalid : Role("INVALID") 28 | 29 | override fun toString() = key 30 | 31 | companion object { 32 | fun get(typeKey: String?): Role { 33 | val upperCasedKey = typeKey?.uppercase() 34 | return when { 35 | upperCasedKey.isNullOrEmpty() -> Invalid 36 | upperCasedKey == Admin.key -> Admin 37 | upperCasedKey == Member.key -> Member 38 | upperCasedKey == Guest.key -> Guest 39 | else -> Unknown(typeKey) 40 | } 41 | } 42 | } 43 | } 44 | 45 | companion object { 46 | fun sanitizeName(name: String): String = 47 | Sanitizers.WORKSPACE_NAME_INVALID_PATTERN.matcher(name.trim()) 48 | .replaceAll(Sanitizers.REPLACEMENT) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/User.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class User( 4 | id: String, 5 | email: String, 6 | fullName: String, 7 | imageId: String?, 8 | open var apiToken: String?, 9 | open var tzInfo: T?, 10 | open var isPremium: Boolean, 11 | open var premiumUntil: Long?, 12 | open var freeTrialExpires: Long?, 13 | open var startPage: String?, 14 | open var startDay: Int?, 15 | open var weekendStartDay: Int?, 16 | open var nextWeek: Int?, 17 | open var teamInboxId: String?, 18 | open var shareLimit: Int?, 19 | open var karma: Long?, 20 | open var karmaTrend: String?, 21 | open var isKarmaDisabled: Boolean, 22 | open var isKarmaVacation: Boolean, 23 | open var autoReminder: Int?, 24 | open var themeId: String?, 25 | open var features: F?, 26 | open var businessAccountId: String?, 27 | open var dailyGoal: Int?, 28 | open var weeklyGoal: Int?, 29 | open var daysOff: IntArray?, 30 | open var uniquePrefix: Long?, 31 | open var hasPassword: Boolean, 32 | open var verificationStatus: VerificationStatus, 33 | open var multiFactorAuthEnabled: Boolean, 34 | ) : Person(id, email, fullName, imageId, false) { 35 | enum class VerificationStatus(private val key: String) { 36 | VERIFIED("verified"), 37 | VERIFIED_BY_THIRD_PARTY("verified_by_third_party"), 38 | UNVERIFIED("unverified"), 39 | LEGACY("legacy"), 40 | BLOCKED("blocked"); 41 | 42 | override fun toString() = key 43 | 44 | companion object { 45 | fun get(statusKey: String): VerificationStatus = values().first { it.key == statusKey } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Avatar.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | enum class Avatar constructor(private val size: Int, private val arg: String) { 4 | // In ascending order of size. 5 | SMALL(35, "small"), 6 | MEDIUM(60, "medium"), 7 | BIG(195, "big"), 8 | HUGE(640, "s640"); 9 | 10 | fun getUrl(imageId: String?): String? { 11 | return if (imageId != null) { 12 | "https://dcff1xvirvpfp.cloudfront.net/${imageId}_${getForSize(size).arg}.jpg" 13 | } else { 14 | null 15 | } 16 | } 17 | 18 | companion object { 19 | /** 20 | * Returns the first [Avatar] to be larger than `size`. If none exist, returns the largest 21 | * one. 22 | */ 23 | @JvmStatic 24 | fun getForSize(size: Int) = values().firstOrNull { it.size >= size } ?: values().last() 25 | 26 | /** 27 | * Returns an array of [Avatar] ordered by how optimal they are. The first should be the 28 | * best, followed by larger sizes and finally the smaller ones. 29 | */ 30 | @JvmStatic 31 | fun getOrderedForSize(size: Int): Array { 32 | val bestAvatar = getForSize(size) 33 | val bestOrdinal = bestAvatar.ordinal 34 | 35 | return arrayListOf().apply { 36 | add(0, bestAvatar) 37 | 38 | for (i in 1 until values().size) { 39 | val prevOrdinal = this[i - 1].ordinal 40 | val ordinal = when { 41 | prevOrdinal >= bestOrdinal -> { 42 | prevOrdinal + if (prevOrdinal < values().lastIndex) 1 else -1 43 | } 44 | else -> { 45 | prevOrdinal - 1 46 | } 47 | } 48 | add(i, values()[ordinal]) 49 | } 50 | }.toTypedArray() 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Item.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Item @JvmOverloads constructor( 4 | id: String, 5 | open var v2Id: String? = null, 6 | open var content: String, 7 | open var description: String? = null, 8 | open var projectId: String, 9 | open var v2ProjectId: String? = null, 10 | priority: Int, 11 | due: D?, 12 | open var sectionId: String?, 13 | open var v2SectionId: String? = null, 14 | open var parentId: String?, 15 | open var v2ParentId: String? = null, 16 | open var childOrder: Int = DEFAULT_CHILD_ORDER, 17 | open var dayOrder: Int = DEFAULT_DAY_ORDER, 18 | open var isChecked: Boolean = false, 19 | open var isCollapsed: Boolean = false, 20 | open var assignedByUid: String?, 21 | open var responsibleUid: String?, 22 | open var labels: Set = emptySet(), 23 | open var addedAt: Long, 24 | open var addedByUid: String?, 25 | open var completedAt: Long? = null, 26 | isDeleted: Boolean = false 27 | ) : Model(id, isDeleted) { 28 | 29 | /** 30 | * Returns the priority within the bounds defined by [MIN_PRIORITY] and [MAX_PRIORITY]. 31 | */ 32 | open var priority: Int = priority 33 | get() = field.coerceIn(MIN_PRIORITY, MAX_PRIORITY) 34 | set(value) { 35 | if (field != value) { 36 | field = value 37 | dayOrder = DEFAULT_DAY_ORDER 38 | } 39 | } 40 | 41 | /** 42 | * Sets the due date, with the side effect of resetting the day order to its default value of 43 | * [DEFAULT_DAY_ORDER]. 44 | */ 45 | open var due: D? = due 46 | set(value) { 47 | if (field != value) { 48 | field = value 49 | dayOrder = DEFAULT_DAY_ORDER 50 | } 51 | } 52 | 53 | companion object { 54 | const val DEFAULT_CHILD_ORDER = 1 55 | const val MIN_DEPTH = 0 56 | const val MAX_DEPTH = 4 57 | const val MIN_PRIORITY = 1 58 | const val MAX_PRIORITY = 4 59 | const val DEFAULT_DAY_ORDER = -1 60 | const val MAX_LABEL_COUNT = 100 61 | const val MAX_CONTENT_CHAR_COUNT = 500 62 | const val MAX_DESCRIPTION_CHAR_COUNT = 16384 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Project.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Project @JvmOverloads constructor( 4 | id: String, 5 | open var v2Id: String? = null, 6 | open var name: String, 7 | open var workspaceId: String? = null, 8 | open var description: String? = null, 9 | open var isInviteOnly: Boolean = false, 10 | open var status: Status = Status.Planned, 11 | open var color: String = Colors.DEFAULT_COLOR_NAME, 12 | open var viewStyle: String = VIEW_STYLE_DEFAULT, 13 | open var parentId: String?, 14 | open var childOrder: Int, 15 | open var isCollapsed: Boolean = false, 16 | open var isInbox: Boolean = false, 17 | open var isTeamInbox: Boolean = false, 18 | open var isShared: Boolean = false, 19 | open var isFavorite: Boolean, 20 | open var isArchived: Boolean = false, 21 | isDeleted: Boolean = false 22 | ) : Model(id, isDeleted) { 23 | sealed class Status(protected open val key: String) { 24 | object Planned : Status("PLANNED") 25 | 26 | object InProgress : Status("IN_PROGRESS") 27 | 28 | object Paused : Status("PAUSED") 29 | 30 | object Completed : Status("COMPLETED") 31 | 32 | object Canceled : Status("CANCELED") 33 | 34 | data class Unknown(override val key: String) : Status(key) 35 | 36 | object Invalid : Status("INVALID") 37 | 38 | override fun toString() = key 39 | 40 | companion object { 41 | fun get(typeKey: String?): Status { 42 | val upperCasedKey = typeKey?.uppercase() 43 | return when { 44 | upperCasedKey.isNullOrEmpty() -> Invalid 45 | upperCasedKey == Planned.key -> Planned 46 | upperCasedKey == InProgress.key -> InProgress 47 | upperCasedKey == Paused.key -> Paused 48 | upperCasedKey == Completed.key -> Completed 49 | upperCasedKey == Canceled.key -> Canceled 50 | else -> Unknown(typeKey) 51 | } 52 | } 53 | } 54 | } 55 | 56 | companion object { 57 | const val VIEW_STYLE_LIST = "list" 58 | const val VIEW_STYLE_BOARD = "board" 59 | const val VIEW_STYLE_DEFAULT = VIEW_STYLE_LIST 60 | 61 | const val DEFAULT_CHILD_ORDER = 1 62 | const val MIN_DEPTH = 0 63 | const val MAX_DEPTH = 3 64 | 65 | @JvmStatic 66 | fun sanitizeName(name: String): String = 67 | Sanitizers.PROJECT_NAME_INVALID_PATTERN.matcher(name.trim()) 68 | .replaceAll(Sanitizers.REPLACEMENT) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > **Warning** — Not actively maintained. 2 | 3 | # TodoistPojos 4 | 5 | TodoistPojos is a JVM project which provides the base POJOs (in Kotlin) for most [Todoist API](https://developer.todoist.com/sync/v8/) objects. 6 | 7 | The naming follows the same as the API, both for classes, variables and methods, with very few helper methods added. 8 | 9 | ## Usage 10 | 11 | These models are usable out of the box. All models and their properties are open to allow subclassing and overriding. 12 | 13 | ## General considerations 14 | 15 | ### Temporary ids 16 | 17 | Temporary ids are negative `long` values. Regular ids start at 0 and go up from there. The API supports any type of value for temporary ids, so special `String` values would also work. However, this would require an additional field to hold the temporary id, additional logic, and seems completely unecessary for most usages. 18 | 19 | The generation of temporary ids is up to the host application, but the algorithm can be really simple: start at -1 and go down from there. An Android application could use something like the following: 20 | 21 | ```kotlin 22 | @Synchronized 23 | fun getNextTempId(context: Context): Long { 24 | val preferences = context.getSharedPreferences("todoist_temp_ids", MODE_PRIVATE) 25 | val id = preferences.getLong("temp_id", 0) - 1 26 | preferences.edit().apply { 27 | if (id > Long.MIN_VALUE) { 28 | // Save decremented temp id. 29 | putLong("temp_id", id) 30 | } else { 31 | // Restart from -1 in next call. 32 | remove("temp_id") 33 | } 34 | apply() 35 | } 36 | 37 | return id 38 | } 39 | ``` 40 | 41 | ## License 42 | 43 | Copyright (c) 2016 Doist 44 | 45 | Permission is hereby granted, free of charge, to any person obtaining 46 | a copy of this software and associated documentation files (the 47 | "Software"), to deal in the Software without restriction, including 48 | without limitation the rights to use, copy, modify, merge, publish, 49 | distribute, sublicense, and/or sell copies of the Software, and to 50 | permit persons to whom the Software is furnished to do so, subject to 51 | the following conditions: 52 | 53 | The above copyright notice and this permission notice shall be 54 | included in all copies or substantial portions of the Software. 55 | 56 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 57 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 58 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 59 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 60 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 61 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 62 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 63 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/ViewOption.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | import java.util.Locale 4 | 5 | open class ViewOption( 6 | id: String, 7 | open var viewType: Type, 8 | open var objectId: String?, 9 | open var sortedBy: Sort?, 10 | open var sortOrder: SortOrder?, 11 | open var groupedBy: Group?, 12 | open var filteredBy: String?, 13 | open var viewMode: ViewMode, 14 | isDeleted: Boolean 15 | ) : Model(id, isDeleted) { 16 | sealed class Type(protected open val key: String) { 17 | object Today : Type("TODAY") 18 | 19 | object Project : Type("PROJECT") 20 | 21 | object Label : Type("LABEL") 22 | 23 | object Filter : Type("FILTER") 24 | 25 | data class Unknown(override val key: String) : Type(key) 26 | 27 | object Invalid : Type("INVALID") 28 | 29 | override fun toString() = key 30 | 31 | companion object { 32 | fun get(typeKey: String?) = when { 33 | typeKey.isNullOrEmpty() -> Invalid 34 | typeKey == Today.key -> Today 35 | typeKey == Project.key -> Project 36 | typeKey == Label.key -> Label 37 | typeKey == Filter.key -> Filter 38 | else -> Unknown(typeKey) 39 | } 40 | } 41 | } 42 | 43 | enum class Sort(private val key: String) { 44 | ALPHABETICALLY("ALPHABETICALLY"), 45 | ASSIGNEE("ASSIGNEE"), 46 | ADDED_DATE("ADDED_DATE"), 47 | DUE_DATE("DUE_DATE"), 48 | PRIORITY("PRIORITY"), 49 | PROJECT("PROJECT"), 50 | WORKSPACE("WORKSPACE"); 51 | 52 | override fun toString() = key 53 | 54 | companion object { 55 | fun get(sortKey: String?): Sort? = values().find { it.key == sortKey } 56 | } 57 | } 58 | 59 | enum class SortOrder(private val key: String) { 60 | ASC("ASC"), 61 | DESC("DESC"); 62 | 63 | override fun toString() = key 64 | 65 | companion object { 66 | fun get(sortKey: String?): SortOrder? = values().find { it.key == sortKey } 67 | } 68 | } 69 | 70 | enum class Group(private val key: String) { 71 | ASSIGNEE("ASSIGNEE"), 72 | ADDED_DATE("ADDED_DATE"), 73 | DUE_DATE("DUE_DATE"), 74 | LABEL("LABEL"), 75 | PRIORITY("PRIORITY"), 76 | PROJECT("PROJECT"), 77 | WORKSPACE("WORKSPACE"); 78 | 79 | override fun toString() = key 80 | 81 | companion object { 82 | fun get(groupKey: String?): Group? = values().find { it.key == groupKey } 83 | } 84 | } 85 | 86 | enum class ViewMode(private val key: String) { 87 | LIST("LIST"), 88 | BOARD("BOARD"); 89 | 90 | override fun toString() = key 91 | 92 | companion object { 93 | fun get(viewKey: String?): ViewMode = 94 | values().find { it.key == viewKey?.uppercase(Locale.getDefault()) } ?: LIST 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/LiveNotification.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class LiveNotification( 4 | id: String, 5 | var notificationType: String, 6 | open var createdAt: Long, 7 | open var isUnread: Boolean, 8 | // Optional fields, not set in all types. 9 | open var fromUid: String?, 10 | open var projectId: String?, 11 | open var projectName: String?, 12 | open var invitationId: String?, 13 | open var invitationSecret: String?, 14 | open var state: String?, 15 | open var itemId: String?, 16 | open var itemContent: String?, 17 | open var responsibleUid: String?, 18 | open var noteId: String?, 19 | open var noteContent: String?, 20 | open var removedUid: String?, 21 | open var fromUser: C?, 22 | open var accountName: String?, 23 | // Optional fields used in Karma notifications (which are set depends on the karma level). 24 | open var karmaLevel: Int?, 25 | open var completedTasks: Int?, 26 | open var completedInDays: Int?, 27 | open var completedLastMonth: Int?, 28 | open var topProcent: Double?, 29 | open var dateReached: Long?, 30 | open var promoImg: String?, 31 | isDeleted: Boolean 32 | ) : Model(id, isDeleted) { 33 | open val isInvitation 34 | get() = notificationType == TYPE_SHARE_INVITATION_SENT || 35 | notificationType == TYPE_BIZ_INVITATION_CREATED 36 | 37 | open val isStatePending get() = state != STATE_ACCEPTED && state != STATE_REJECTED 38 | 39 | companion object { 40 | const val TYPE_SHARE_INVITATION_SENT = "share_invitation_sent" 41 | const val TYPE_SHARE_INVITATION_ACCEPTED = "share_invitation_accepted" 42 | const val TYPE_SHARE_INVITATION_REJECTED = "share_invitation_rejected" 43 | const val TYPE_USER_LEFT_PROJECT = "user_left_project" 44 | const val TYPE_USER_REMOVED_FROM_PROJECT = "user_removed_from_project" 45 | const val TYPE_NOTE_ADDED = "note_added" 46 | const val TYPE_ITEM_ASSIGNED = "item_assigned" 47 | const val TYPE_ITEM_COMPLETED = "item_completed" 48 | const val TYPE_ITEM_UNCOMPLETED = "item_uncompleted" 49 | const val TYPE_KARMA_LEVEL = "karma_level" 50 | 51 | const val TYPE_BIZ_POLICY_DISALLOWED_INVITATION = "biz_policy_disallowed_invitation" 52 | const val TYPE_BIZ_POLICY_REJECTED_INVITATION = "biz_policy_rejected_invitation" 53 | const val TYPE_BIZ_TRIAL_WILL_END = "biz_trial_will_end" 54 | const val TYPE_BIZ_PAYMENT_FAILED = "biz_payment_failed" 55 | const val TYPE_BIZ_ACCOUNT_DISABLED = "biz_account_disabled" 56 | const val TYPE_BIZ_INVITATION_CREATED = "biz_invitation_created" 57 | const val TYPE_BIZ_INVITATION_ACCEPTED = "biz_invitation_accepted" 58 | const val TYPE_BIZ_INVITATION_REJECTED = "biz_invitation_rejected" 59 | 60 | const val STATE_INVITED = "invited" 61 | const val STATE_ACCEPTED = "accepted" 62 | const val STATE_REJECTED = "rejected" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if %ERRORLEVEL% equ 0 goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if %ERRORLEVEL% equ 0 goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /src/main/java/com/todoist/pojo/Person.kt: -------------------------------------------------------------------------------- 1 | package com.todoist.pojo 2 | 3 | open class Person( 4 | id: String, 5 | open var email: String, 6 | open var fullName: String = "", 7 | open var imageId: String?, 8 | isDeleted: Boolean 9 | ) : Model(id, isDeleted) { 10 | val defaultAvatarText get() = getDefaultAvatarText(fullName, email) 11 | 12 | fun getDefaultAvatarColorInt(useLightColors: Boolean) = 13 | getDefaultAvatarColorInt(email, useLightColors) 14 | 15 | companion object { 16 | // Matches special characters commonly found in name fields. 17 | private val ESCAPE_PATTERN = Regex("""[().,\-_\[\]'"]""") 18 | 19 | private val LIGHT_AVATAR_COLORS = uintArrayOf( 20 | 0XFFE9952Cu, 21 | 0XFFE16B2Du, 22 | 0XFFD84B40u, 23 | 0XFFE8435Au, 24 | 0XFFE5198Au, 25 | 0XFFAD3889u, 26 | 0XFF86389Cu, 27 | 0XFF98BE2Fu, 28 | 0XFF5D9D50u, 29 | 0XFF5F9F85u, 30 | 0XFF5BBCB6u, 31 | 0XFF32A3BFu, 32 | 0XFF2BAFEBu, 33 | 0XFF2D88C3u, 34 | 0XFF3863CCu, 35 | 0XFF5E5E5Eu 36 | ).toIntArray() 37 | 38 | private val DARK_AVATAR_COLORS = uintArrayOf( 39 | 0XFFFCC652u, 40 | 0XFFE9952Cu, 41 | 0XFFE16B2Du, 42 | 0XFFD84B40u, 43 | 0XFFE8435Au, 44 | 0XFFE5198Au, 45 | 0XFFAD3889u, 46 | 0XFFA8A8A8u, 47 | 0XFF98BE2Fu, 48 | 0XFF5D9D50u, 49 | 0XFF5F9F85u, 50 | 0XFF5BBCB6u, 51 | 0XFF32A3BFu, 52 | 0XFF2BAFEBu, 53 | 0XFF2D88C3u 54 | ).toIntArray() 55 | 56 | @JvmStatic 57 | fun getDefaultAvatarColorInt(email: String, useLightColors: Boolean): Int { 58 | val atIndex = email.indexOf('@') 59 | if (atIndex <= 0) return 0xFF000000u.toInt() 60 | 61 | val colors = if (useLightColors) LIGHT_AVATAR_COLORS else DARK_AVATAR_COLORS 62 | val index = (email[0].code + email[atIndex - 1].code) % colors.size 63 | return colors[index] 64 | } 65 | 66 | @JvmStatic 67 | fun getDefaultAvatarText(fullName: String?, email: String?): String { 68 | val escapedName = fullName?.replace(ESCAPE_PATTERN, "")?.trim().orEmpty() 69 | if (escapedName.isBlank()) { 70 | return getEmailInitials(email) 71 | } 72 | 73 | val first = escapedName[0].uppercaseChar() 74 | val lastSpace = escapedName.indexOfLast { it.isWhitespace() } 75 | val last = 76 | if (lastSpace != -1) escapedName[lastSpace + 1].uppercaseChar().toString() else "" 77 | return first + last 78 | } 79 | 80 | private fun getEmailInitials(email: String?): String { 81 | val validEmail = email ?: "?" 82 | return buildString { 83 | val emailInitials = validEmail.substringBefore("@") 84 | .split(".") 85 | .filter { it.isNotEmpty() } 86 | .map { emailPart -> emailPart.first().uppercase() } 87 | append(emailInitials.firstOrNull().orEmpty()) 88 | if (emailInitials.size > 1) { 89 | append(emailInitials.lastOrNull().orEmpty()) 90 | } 91 | } 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Stop when "xargs" is not available. 209 | if ! command -v xargs >/dev/null 2>&1 210 | then 211 | die "xargs is not available" 212 | fi 213 | 214 | # Use "xargs" to parse quoted args. 215 | # 216 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 217 | # 218 | # In Bash we could simply go: 219 | # 220 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 221 | # set -- "${ARGS[@]}" "$@" 222 | # 223 | # but POSIX shell has neither arrays nor command substitution, so instead we 224 | # post-process each arg (as a line of input to sed) to backslash-escape any 225 | # character that might be a shell metacharacter, then use eval to reverse 226 | # that process (while maintaining the separation between arguments), and wrap 227 | # the whole thing up as a single "set" statement. 228 | # 229 | # This will of course break if any of these variables contains a newline or 230 | # an unmatched quote. 231 | # 232 | 233 | eval "set -- $( 234 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 235 | xargs -n1 | 236 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 237 | tr '\n' ' ' 238 | )" '"$@"' 239 | 240 | exec "$JAVACMD" "$@" 241 | --------------------------------------------------------------------------------