* DROID-439 App | Relations refactoring, use SearchObjects for object types (#2592) * DROID-446 Objects | Enhancement | Store relation links and process its updates (#2597) * DROID-456 Tech | Remove deprecated API for creating object types (#2601) * DROID-455 Object types | Enhancement Get object type list from ObjectSearch on Global search screen (#2602) * DROID-459 Sets | Refactoring | Use relations links instead of relations for building search params to get data view data (#2603) * DROID-458 Objects | Refactoring | Integrate new api for creating objets (#2604) * DROID-464 Relations | Refactoring | New API for creating a relation from scratch - for data view or for an object (#2605) * DROID-467 Relations | Refactoring | New API for creating options - for tags and statuses (#2607) * DROID-470 Relations | Refactoring | New API for removing any relation from an object or from a data view (#2608) * DROID-460 Tech | Object relations list (#2610) * DROID-486 Sets | Refactoring | Displaying and controlling visibility of data view relations (#2611) * DROID-500 Relations | Refactoring | Extend API of ObjectStore to be able to get a relation by its id (#2619) * DROID-459 Sets | Fix | Get relations from store by id and not by key (#2618) * DROID-489 Tech | Relations as object, add relationKey to relation connected screens (#2622) * DROID-490 Sets | Refactoring | Displaying relation values for current object in bottom sheet cells (#2629) * DROID-505 Relations | Refactoring | New interface for relations store (#2633) * DROID-509 Relations | Refactoring | Bind new relations store with subscription container (#2635) * DROID-507 Tech | MW , migration + relation links (#2636) * DROID-507 Tech | MW , migration + relation links, fixes (#2637) * DROID-517 Sets | Fix | Provide correct keys for data view search-and-subscribe query (#2641) * DROID-409 Relations | Refactoring | Use relation key instead of id when creating new relation (#2642) * DROID-521 Sets & Objects | Refactoring | Add relation to a data view or to an object from existing relations (#2644) * DROID-522 Relations | Refactoring | Add objects to relations with object format (#2645) * DROID-523 Object types | Refactoring | Implement global store for object types (#2646) * DROID-527 Object types | Refactoring | Integrate global store for object types (#2647) * DROID-531 Relations | Refactoring | Parse tag and status relations values (#2649) * DROID-535 Tech | Integrate new MW lib with migration fixes (#2653) * DROID-535 Tech | MW integration fixes (#2660) * DROID-559 Relations | Refactoring | Parse tag and status values in editor (#2662) * DROID-560 Relations | Refactoring | Integrate new lib with fixes (#2663) * DROID-561 Relations | Refactoring | Parsing tag and status values in dv (#2665) * DROID-562 Dashboard | Refactoring | Use store of object types as object type provider for favorites tab on dashboard (#2667) * DROID-567 Relations | Refactoring | Suggest available options to populate a relation (#2671) * DROID-604 Relations | Refactoring | Use details from Object.CreateRelation.Response to populate relation store (#2705) * DROID-603 Relations | Refactoring | Creating relation options + Deleting relation from object (#2706) * DROID-619 Relations | Refactoring | Migrate data view sorts and filters to the new relation-as-object paradigm (#2711) * DROID-622 Relations | Tech | Update MW to 0.24.0-rc1 (#2714) * DROID-598 Sets | Refactoring | Provide relation format for date filters (#2715) * DROID-625 Protocol | Enhancement | Integrate v0.24.0-rc2 (#2718)
303 lines
10 KiB
Kotlin
303 lines
10 KiB
Kotlin
package com.anytypeio.anytype.core_ui.extensions
|
|
|
|
import android.content.Context
|
|
import android.graphics.drawable.Drawable
|
|
import android.webkit.MimeTypeMap
|
|
import androidx.annotation.ColorRes
|
|
import androidx.annotation.DrawableRes
|
|
import androidx.annotation.StringRes
|
|
import androidx.core.content.ContextCompat
|
|
import com.anytypeio.anytype.core_models.DVSortType
|
|
import com.anytypeio.anytype.core_models.RelationFormat
|
|
import com.anytypeio.anytype.core_ui.R
|
|
import com.anytypeio.anytype.core_utils.const.MimeTypes
|
|
import com.anytypeio.anytype.presentation.objects.ObjectLayoutView
|
|
import com.anytypeio.anytype.presentation.sets.model.ColumnView
|
|
|
|
fun Context.drawable(
|
|
@DrawableRes id: Int
|
|
): Drawable =
|
|
ContextCompat.getDrawable(this, id) ?: throw IllegalArgumentException("Resource not found")
|
|
|
|
fun Context.color(
|
|
@ColorRes id: Int
|
|
) = ContextCompat.getColor(this, id)
|
|
|
|
fun Context.avatarColor(
|
|
position: Int
|
|
): Int {
|
|
val colors = resources.obtainTypedArray(R.array.avatar_colors)
|
|
val color = colors.getColor(position, 0)
|
|
colors.recycle()
|
|
return color
|
|
}
|
|
|
|
fun Context.formatIcon(
|
|
format: ColumnView.Format
|
|
): Drawable = drawable(
|
|
when (format) {
|
|
ColumnView.Format.SHORT_TEXT -> R.drawable.ic_text
|
|
ColumnView.Format.LONG_TEXT -> R.drawable.ic_text
|
|
ColumnView.Format.NUMBER -> R.drawable.ic_number
|
|
ColumnView.Format.STATUS -> R.drawable.ic_select
|
|
ColumnView.Format.DATE -> R.drawable.ic_date
|
|
ColumnView.Format.FILE -> R.drawable.ic_file
|
|
ColumnView.Format.CHECKBOX -> R.drawable.ic_checkbox
|
|
ColumnView.Format.URL -> R.drawable.ic_url
|
|
ColumnView.Format.EMAIL -> R.drawable.ic_email
|
|
ColumnView.Format.PHONE -> R.drawable.ic_phone
|
|
ColumnView.Format.EMOJI -> R.drawable.ic_person
|
|
//todo Add proper icon for object
|
|
ColumnView.Format.OBJECT -> R.drawable.ic_multiselect
|
|
ColumnView.Format.TAG -> R.drawable.ic_multiselect
|
|
else -> {
|
|
// TODO
|
|
R.drawable.circle_solid_default
|
|
}
|
|
}
|
|
)
|
|
|
|
fun ColumnView.Format.relationIcon(isMedium: Boolean = false): Int = when (this) {
|
|
ColumnView.Format.SHORT_TEXT, ColumnView.Format.LONG_TEXT -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_text_48
|
|
else
|
|
R.drawable.ic_relation_text_32
|
|
}
|
|
ColumnView.Format.NUMBER -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_number_48
|
|
else
|
|
R.drawable.ic_relation_number_32
|
|
}
|
|
ColumnView.Format.STATUS -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_status_48
|
|
else
|
|
R.drawable.ic_relation_status_32
|
|
}
|
|
ColumnView.Format.DATE -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_date_48
|
|
else
|
|
R.drawable.ic_relation_date_32
|
|
}
|
|
ColumnView.Format.FILE -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_attachment_48
|
|
else
|
|
R.drawable.ic_relation_attachment_32
|
|
}
|
|
ColumnView.Format.CHECKBOX -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_checkbox_48
|
|
else
|
|
R.drawable.ic_relation_checkbox_32
|
|
}
|
|
ColumnView.Format.URL -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_url_48
|
|
else
|
|
R.drawable.ic_relation_url_32
|
|
}
|
|
ColumnView.Format.EMAIL -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_email_48
|
|
else
|
|
R.drawable.ic_relation_email_32
|
|
}
|
|
ColumnView.Format.PHONE -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_phone_number_48
|
|
else
|
|
R.drawable.ic_relation_phone_number_32
|
|
}
|
|
ColumnView.Format.EMOJI -> R.drawable.ic_relation_object_32
|
|
ColumnView.Format.OBJECT -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_object_48
|
|
else
|
|
R.drawable.ic_relation_object_32
|
|
}
|
|
ColumnView.Format.TAG -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_tag_48
|
|
else
|
|
R.drawable.ic_relation_tag_32
|
|
}
|
|
else -> {
|
|
// TODO
|
|
R.drawable.circle_solid_default
|
|
}
|
|
}
|
|
|
|
fun ColumnView.Format.relationIconSmall(): Int? = when (this) {
|
|
ColumnView.Format.SHORT_TEXT -> R.drawable.ic_relation_format_text_small
|
|
ColumnView.Format.LONG_TEXT -> R.drawable.ic_relation_format_text_small
|
|
ColumnView.Format.NUMBER -> R.drawable.ic_relation_format_number_small
|
|
ColumnView.Format.STATUS -> R.drawable.ic_relation_format_status_small
|
|
ColumnView.Format.DATE -> R.drawable.ic_relation_format_date_small
|
|
ColumnView.Format.FILE -> R.drawable.ic_relation_format_attachment_small
|
|
ColumnView.Format.CHECKBOX -> R.drawable.ic_relation_format_checkbox_small
|
|
ColumnView.Format.URL -> R.drawable.ic_relation_format_url_small
|
|
ColumnView.Format.EMAIL -> R.drawable.ic_relation_format_email_small
|
|
ColumnView.Format.PHONE -> R.drawable.ic_relation_format_phone_number_small
|
|
ColumnView.Format.OBJECT -> R.drawable.ic_relation_format_object_small
|
|
ColumnView.Format.TAG -> R.drawable.ic_relation_format_tag_small
|
|
else -> null
|
|
}
|
|
|
|
fun RelationFormat.icon(isMedium: Boolean = false): Int = when (this) {
|
|
RelationFormat.SHORT_TEXT, RelationFormat.LONG_TEXT -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_text_48
|
|
else
|
|
R.drawable.ic_relation_text_32
|
|
}
|
|
RelationFormat.NUMBER -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_number_48
|
|
else
|
|
R.drawable.ic_relation_number_32
|
|
}
|
|
RelationFormat.STATUS -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_status_48
|
|
else
|
|
R.drawable.ic_relation_status_32
|
|
}
|
|
RelationFormat.DATE -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_date_48
|
|
else
|
|
R.drawable.ic_relation_date_32
|
|
}
|
|
RelationFormat.FILE -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_attachment_48
|
|
else
|
|
R.drawable.ic_relation_attachment_32
|
|
}
|
|
RelationFormat.CHECKBOX -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_checkbox_48
|
|
else
|
|
R.drawable.ic_relation_checkbox_32
|
|
}
|
|
RelationFormat.URL -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_url_48
|
|
else
|
|
R.drawable.ic_relation_url_32
|
|
}
|
|
RelationFormat.EMAIL -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_email_48
|
|
else
|
|
R.drawable.ic_relation_email_32
|
|
}
|
|
RelationFormat.PHONE -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_phone_number_48
|
|
else
|
|
R.drawable.ic_relation_phone_number_32
|
|
}
|
|
RelationFormat.EMOJI -> R.drawable.ic_relation_object_32
|
|
RelationFormat.OBJECT -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_object_48
|
|
else
|
|
R.drawable.ic_relation_object_32
|
|
}
|
|
RelationFormat.TAG -> {
|
|
if (isMedium)
|
|
R.drawable.ic_relation_tag_48
|
|
else
|
|
R.drawable.ic_relation_tag_32
|
|
}
|
|
else -> {
|
|
// TODO
|
|
R.drawable.circle_solid_default
|
|
}
|
|
}
|
|
|
|
fun DVSortType.text(format: RelationFormat): Int = when (format) {
|
|
RelationFormat.TAG, RelationFormat.STATUS -> {
|
|
if (this == DVSortType.ASC)
|
|
R.string.sort_from_first_to_last
|
|
else
|
|
R.string.sort_from_last_to_first
|
|
}
|
|
RelationFormat.NUMBER, RelationFormat.DATE -> {
|
|
if (this == DVSortType.ASC)
|
|
R.string.sort_from_one_to_nine
|
|
else
|
|
R.string.sort_from_nine_to_one
|
|
}
|
|
RelationFormat.CHECKBOX -> {
|
|
if (this == DVSortType.ASC)
|
|
R.string.sort_from_unchecked_to_checked
|
|
else
|
|
R.string.sort_from_checked_to_unchecked
|
|
}
|
|
else -> {
|
|
if (this == DVSortType.ASC)
|
|
R.string.sort_from_a_to_z
|
|
else
|
|
R.string.sort_from_z_to_a
|
|
}
|
|
}
|
|
|
|
fun String?.getMimeIcon(name: String?): Int {
|
|
val extension = MimeTypeMap.getFileExtensionFromUrl(name)
|
|
var mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
|
if (mime.isNullOrBlank()) {
|
|
mime = this
|
|
}
|
|
return when (MimeTypes.category(mime)) {
|
|
MimeTypes.Category.PDF -> R.drawable.ic_mime_pdf
|
|
MimeTypes.Category.IMAGE -> R.drawable.ic_mime_image
|
|
MimeTypes.Category.AUDIO -> R.drawable.ic_mime_music
|
|
MimeTypes.Category.TEXT -> R.drawable.ic_mime_text
|
|
MimeTypes.Category.VIDEO -> R.drawable.ic_mime_video
|
|
MimeTypes.Category.ARCHIVE -> R.drawable.ic_mime_archive
|
|
MimeTypes.Category.TABLE -> R.drawable.ic_mime_table
|
|
MimeTypes.Category.PRESENTATION -> R.drawable.ic_mime_presentation
|
|
MimeTypes.Category.OTHER -> R.drawable.ic_mime_other
|
|
}
|
|
}
|
|
|
|
fun ObjectLayoutView.getName(): Int? = when (this) {
|
|
is ObjectLayoutView.Basic -> R.string.name_layout_basic
|
|
is ObjectLayoutView.Image -> null
|
|
is ObjectLayoutView.Note -> R.string.name_layout_note
|
|
is ObjectLayoutView.Profile -> R.string.name_layout_profile
|
|
is ObjectLayoutView.Set -> R.string.name_layout_set
|
|
is ObjectLayoutView.Todo -> R.string.name_layout_todo
|
|
is ObjectLayoutView.Dashboard -> null
|
|
is ObjectLayoutView.Database -> null
|
|
is ObjectLayoutView.File -> null
|
|
is ObjectLayoutView.ObjectType -> null
|
|
is ObjectLayoutView.Relation -> null
|
|
is ObjectLayoutView.Space -> null
|
|
is ObjectLayoutView.Bookmark -> null
|
|
}
|
|
|
|
@StringRes
|
|
fun RelationFormat.getPrettyName(): Int = when (this) {
|
|
RelationFormat.LONG_TEXT -> R.string.relation_format_long_text
|
|
RelationFormat.SHORT_TEXT -> R.string.relation_format_short_text
|
|
RelationFormat.NUMBER -> R.string.relation_format_number
|
|
RelationFormat.STATUS -> R.string.relation_format_status
|
|
RelationFormat.TAG -> R.string.relation_format_tag
|
|
RelationFormat.DATE -> R.string.relation_format_date
|
|
RelationFormat.FILE -> R.string.relation_format_file
|
|
RelationFormat.CHECKBOX -> R.string.relation_format_checkbox
|
|
RelationFormat.URL -> R.string.relation_format_url
|
|
RelationFormat.EMAIL -> R.string.relation_format_email
|
|
RelationFormat.PHONE -> R.string.relation_format_phone
|
|
RelationFormat.EMOJI -> R.string.relation_format_emoji
|
|
RelationFormat.OBJECT -> R.string.relation_format_object
|
|
RelationFormat.RELATIONS -> R.string.relation_format_relation
|
|
RelationFormat.UNDEFINED -> R.string.undefined
|
|
} |