Skip to content

Commit

Permalink
Merge pull request #4937 from vector-im/feature/fga/message_bubbles
Browse files Browse the repository at this point in the history
Feature/fga/message bubbles
  • Loading branch information
bmarty authored Feb 3, 2022
2 parents dbfd7e6 + 02de636 commit 4ce1ab2
Show file tree
Hide file tree
Showing 92 changed files with 1,561 additions and 515 deletions.
1 change: 1 addition & 0 deletions changelog.d/4937.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support message bubbles in timeline.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Tint color is provided by the theme -->
<solid android:color="@android:color/black" />
<size
android:width="240dp"
android:height="44dp" />
<corners
android:bottomLeftRadius="12dp"
android:bottomRightRadius="12dp"
Expand Down
8 changes: 3 additions & 5 deletions library/ui-styles/src/main/res/drawable/file_progress_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
<shape>
<corners android:radius="8dp" />
<solid android:color="?vctr_room_active_widgets_banner_bg" />
<shape android:shape="oval">
<solid android:color="?vctr_system" />
</shape>
</item>

<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="8dp" />
<shape android:shape="oval">
<solid android:color="@color/vctr_notice_secondary_alpha12" />
</shape>
</clip>
Expand Down
6 changes: 0 additions & 6 deletions library/ui-styles/src/main/res/values-ldrtl/bools.xml

This file was deleted.

2 changes: 0 additions & 2 deletions library/ui-styles/src/main/res/values/bools.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@
<!-- Created to detect what has to be implemented (especially in the settings) -->
<bool name="false_not_implemented">false</bool>

<bool name="is_rtl">false</bool>

</resources>
1 change: 1 addition & 0 deletions library/ui-styles/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@
<attr name="vctr_presence_indicator_offline" format="color" />
<color name="vctr_presence_indicator_offline_light">@color/palette_gray_100</color>
<color name="vctr_presence_indicator_offline_dark">@color/palette_gray_450</color>

</resources>
11 changes: 11 additions & 0 deletions library/ui-styles/src/main/res/values/colors_message_bubble.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- Timeline bubble background colors -->
<attr name="vctr_message_bubble_inbound" format="color" />
<color name="vctr_message_bubble_inbound_light">#E8EDF4</color>
<color name="vctr_message_bubble_inbound_dark">#21262C</color>
<attr name="vctr_message_bubble_outbound" format="color" />
<color name="vctr_message_bubble_outbound_light">#E7F8F3</color>
<color name="vctr_message_bubble_outbound_dark">#133A34</color>
</resources>
9 changes: 9 additions & 0 deletions library/ui-styles/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<dimen name="item_decoration_left_margin">72dp</dimen>
<dimen name="item_event_message_state_size">16dp</dimen>

<dimen name="item_event_message_media_button_size">32dp</dimen>

<dimen name="chat_avatar_size">40dp</dimen>
<dimen name="member_list_avatar_size">60dp</dimen>

Expand Down Expand Up @@ -42,6 +44,7 @@

<!-- Preview Url -->
<dimen name="preview_url_view_corner_radius">8dp</dimen>
<dimen name="preview_url_view_image_max_height">160dp</dimen>

<dimen name="menu_item_icon_size">24dp</dimen>
<dimen name="menu_item_size">48dp</dimen>
Expand All @@ -52,6 +55,12 @@
<dimen name="composer_attachment_size">52dp</dimen>
<dimen name="composer_attachment_margin">1dp</dimen>


<dimen name="chat_bubble_margin_start">28dp</dimen>
<dimen name="chat_bubble_margin_end">62dp</dimen>
<dimen name="chat_bubble_fixed_size">300dp</dimen>
<dimen name="chat_bubble_corner_radius">12dp</dimen>

<!-- Onboarding -->
<item name="ftue_auth_gutter_start_percent" format="float" type="dimen">0.05</item>
<item name="ftue_auth_gutter_end_percent" format="float" type="dimen">0.95</item>
Expand Down
11 changes: 11 additions & 0 deletions library/ui-styles/src/main/res/values/stylable_message_bubble.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<declare-styleable name="MessageBubble">
<attr name="incoming_style" format="boolean" />
<attr name="show_time_overlay" format="boolean" />
<attr name="is_first" format="boolean" />
<attr name="is_last" format="boolean" />
</declare-styleable>

</resources>
1 change: 1 addition & 0 deletions library/ui-styles/src/main/res/values/styles_progress.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<style name="Widget.Vector.ProgressBar.Horizontal.File">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">@drawable/file_progress_bar</item>
<item name="android:progressBackgroundTint">?android:colorBackground</item>
<item name="android:minHeight">10dp</item>
<item name="android:maxHeight">40dp</item>
</style>
Expand Down
23 changes: 17 additions & 6 deletions library/ui-styles/src/main/res/values/styles_timeline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@
<style name="TimelineContentStubBaseParams">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginStart">8dp</item>
<item name="android:layout_marginLeft">8dp</item>
<item name="android:layout_marginEnd">8dp</item>
<item name="android:layout_marginRight">8dp</item>
<item name="android:layout_marginBottom">4dp</item>
<item name="android:layout_marginTop">4dp</item>
</style>

<style name="TimelineContentStubContainerParams">
<item name="android:paddingStart">8dp</item>
<item name="android:paddingEnd">8dp</item>
<item name="android:paddingTop">4dp</item>
<item name="android:paddingBottom">4dp</item>
</style>

<style name="TimelineContentMediaPillStyle">
<item name="android:paddingStart">8dp</item>
<item name="android:paddingEnd">8dp</item>
<item name="android:paddingTop">6dp</item>
<item name="android:paddingBottom">6dp</item>
<item name="minHeight">48dp</item>
<item name="android:background">@drawable/bg_media_pill</item>
<item name="android:backgroundTint">?vctr_content_quinary</item>
</style>

</resources>
2 changes: 2 additions & 0 deletions library/ui-styles/src/main/res/values/theme_dark.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<item name="vctr_waiting_background_color">@color/vctr_waiting_background_color_dark</item>
<item name="vctr_chat_effect_snow_background">@color/vctr_chat_effect_snow_background_dark</item>
<item name="vctr_toolbar_background">@color/element_system_dark</item>
<item name="vctr_message_bubble_inbound">@color/vctr_message_bubble_inbound_dark</item>
<item name="vctr_message_bubble_outbound">@color/vctr_message_bubble_outbound_dark</item>

<!-- room message colors -->
<item name="vctr_notice_secondary">#61708B</item>
Expand Down
2 changes: 2 additions & 0 deletions library/ui-styles/src/main/res/values/theme_light.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<item name="vctr_waiting_background_color">@color/vctr_waiting_background_color_light</item>
<item name="vctr_chat_effect_snow_background">@color/vctr_chat_effect_snow_background_light</item>
<item name="vctr_toolbar_background">@color/element_background_light</item>
<item name="vctr_message_bubble_inbound">@color/vctr_message_bubble_inbound_light</item>
<item name="vctr_message_bubble_outbound">@color/vctr_message_bubble_outbound_light</item>

<!-- room message colors -->
<item name="vctr_notice_secondary">#61708B</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@ data class PreviewUrlData(
// Value of field "og:description"
val description: String?,
// Value of field "og:image"
val mxcUrl: String?
val mxcUrl: String?,
// Value of field "og:image:width"
val imageWidth: Int?,
// Value of field "og:image:height"
val imageHeight: Int?
)
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal class RealmSessionStoreMigration @Inject constructor(
) : RealmMigration {

companion object {
const val SESSION_STORE_SCHEMA_VERSION = 23L
const val SESSION_STORE_SCHEMA_VERSION = 24L
}

/**
Expand Down Expand Up @@ -93,6 +93,7 @@ internal class RealmSessionStoreMigration @Inject constructor(
if (oldVersion <= 20) migrateTo21(realm)
if (oldVersion <= 21) migrateTo22(realm)
if (oldVersion <= 22) migrateTo23(realm)
if (oldVersion <= 23) migrateTo24(realm)
}

private fun migrateTo1(realm: DynamicRealm) {
Expand Down Expand Up @@ -479,4 +480,13 @@ internal class RealmSessionStoreMigration @Inject constructor(
}
?.addRealmObjectField(EventEntityFields.THREAD_SUMMARY_LATEST_MESSAGE.`$`, eventEntity)
}

private fun migrateTo24(realm: DynamicRealm) {
Timber.d("Step 23 -> 24")
realm.schema.get("PreviewUrlCacheEntity")
?.addField(PreviewUrlCacheEntityFields.IMAGE_WIDTH, Int::class.java)
?.setNullable(PreviewUrlCacheEntityFields.IMAGE_WIDTH, true)
?.addField(PreviewUrlCacheEntityFields.IMAGE_HEIGHT, Int::class.java)
?.setNullable(PreviewUrlCacheEntityFields.IMAGE_HEIGHT, true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ internal open class PreviewUrlCacheEntity(
var title: String? = null,
var description: String? = null,
var mxcUrl: String? = null,

var imageWidth: Int? = null,
var imageHeight: Int? = null,
var lastUpdatedTimestamp: Long = 0L
) : RealmObject() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ internal class DefaultGetPreviewUrlTask @Inject constructor(

override suspend fun execute(params: GetPreviewUrlTask.Params): PreviewUrlData {
return when (params.cacheStrategy) {
CacheStrategy.NoCache -> doRequest(params.url, params.timestamp)
is CacheStrategy.TtlCache -> doRequestWithCache(
CacheStrategy.NoCache -> doRequest(params.url, params.timestamp)
is CacheStrategy.TtlCache -> doRequestWithCache(
params.url,
params.timestamp,
params.cacheStrategy.validityDurationInMillis,
Expand Down Expand Up @@ -77,7 +77,9 @@ internal class DefaultGetPreviewUrlTask @Inject constructor(
siteName = (get("og:site_name") as? String)?.unescapeHtml(),
title = (get("og:title") as? String)?.unescapeHtml(),
description = (get("og:description") as? String)?.unescapeHtml(),
mxcUrl = get("og:image") as? String
mxcUrl = get("og:image") as? String,
imageHeight = (get("og:image:height") as? Double)?.toInt(),
imageWidth = (get("og:image:width") as? Double)?.toInt(),
)
}

Expand Down Expand Up @@ -114,7 +116,8 @@ internal class DefaultGetPreviewUrlTask @Inject constructor(
previewUrlCacheEntity.title = data.title
previewUrlCacheEntity.description = data.description
previewUrlCacheEntity.mxcUrl = data.mxcUrl

previewUrlCacheEntity.imageHeight = data.imageHeight
previewUrlCacheEntity.imageWidth = data.imageWidth
previewUrlCacheEntity.lastUpdatedTimestamp = Date().time
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ internal fun PreviewUrlCacheEntity.toDomain() = PreviewUrlData(
siteName = siteName,
title = title,
description = description,
mxcUrl = mxcUrl
mxcUrl = mxcUrl,
imageWidth = imageWidth,
imageHeight = imageHeight
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package im.vector.app.core.resources

import android.content.res.Resources
import android.text.TextUtils
import android.view.View
import androidx.core.os.ConfigurationCompat
import java.util.Locale
import javax.inject.Inject
Expand All @@ -29,3 +31,7 @@ class LocaleProvider @Inject constructor(private val resources: Resources) {
}

fun LocaleProvider.isEnglishSpeaking() = current().language.startsWith("en")

fun LocaleProvider.getLayoutDirectionFromCurrentLocale() = TextUtils.getLayoutDirectionFromLocale(current())

fun LocaleProvider.isRTL() = getLayoutDirectionFromCurrentLocale() == View.LAYOUT_DIRECTION_RTL
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,28 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
(0 until modelCache.size).forEach { position ->
val event = currentSnapshot[position]
val nextEvent = currentSnapshot.nextOrNull(position)
val prevEvent = currentSnapshot.prevOrNull(position)
val nextDisplayableEvent = currentSnapshot.subList(position + 1, currentSnapshot.size).firstOrNull {
timelineEventVisibilityHelper.shouldShowEvent(
timelineEvent = it,
highlightedEventId = partialState.highlightedEventId,
isFromThreadTimeline = partialState.isFromThreadTimeline(),
rootThreadEventId = partialState.rootThreadEventId)
}
// Should be build if not cached or if model should be refreshed
if (modelCache[position] == null || modelCache[position]?.isCacheable(partialState) == false) {
val prevEvent = currentSnapshot.prevOrNull(position)
val prevDisplayableEvent = currentSnapshot.subList(0, position).lastOrNull {
timelineEventVisibilityHelper.shouldShowEvent(
timelineEvent = it,
highlightedEventId = partialState.highlightedEventId,
isFromThreadTimeline = partialState.isFromThreadTimeline(),
rootThreadEventId = partialState.rootThreadEventId)
}
val nextDisplayableEvent = currentSnapshot.subList(position + 1, currentSnapshot.size).firstOrNull {
timelineEventVisibilityHelper.shouldShowEvent(
timelineEvent = it,
highlightedEventId = partialState.highlightedEventId,
isFromThreadTimeline = partialState.isFromThreadTimeline(),
rootThreadEventId = partialState.rootThreadEventId)
}
val timelineEventsGroup = timelineEventsGroups.getOrNull(event)
val params = TimelineItemFactoryParams(
event = event,
prevEvent = prevEvent,
prevDisplayableEvent = prevDisplayableEvent,
nextEvent = nextEvent,
nextDisplayableEvent = nextDisplayableEvent,
partialState = partialState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class EncryptedItemFactory @Inject constructor(private val messageInformationDat
callback = params.callback,
threadDetails = threadDetails)
return MessageTextItem_()
.layout(informationData.messageLayout.layoutRes)
.leftGuideline(avatarSizeProvider.leftGuideline)
.highlighted(params.isHighlighted)
.attributes(attributes)
Expand Down
Loading

0 comments on commit 4ce1ab2

Please sign in to comment.