-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adding a typing message notification view at the bottom of the timeline in rooms. Signed-off-by: Ahmed Radhouane Belkilani <[email protected]>
- Loading branch information
1 parent
924a4f8
commit da9fdf1
Showing
16 changed files
with
319 additions
and
9 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
.idea/shelf/Uncommitted_changes_before_rebase__Default_Changelist_.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Typing notifications moved from the header to the bottom of the timeline. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
vector/src/main/java/im/vector/app/core/ui/views/TypingMessageAvatar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.core.ui.views | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import android.widget.LinearLayout | ||
import im.vector.app.core.utils.DimensionConverter | ||
import im.vector.app.features.home.AvatarRenderer | ||
import org.matrix.android.sdk.api.session.room.sender.SenderInfo | ||
import org.matrix.android.sdk.api.util.toMatrixItem | ||
|
||
class TypingMessageAvatar @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyleAttr: Int = 0 | ||
) : LinearLayout(context, attrs, defStyleAttr) { | ||
|
||
companion object { | ||
const val AVATAR_SIZE_DP = 24 | ||
const val OVERLAP_FACT0R = -3 // =~ 30% to left | ||
} | ||
|
||
fun render(typingUsers: List<SenderInfo>, avatarRender: AvatarRenderer) { | ||
removeAllViews() | ||
for ((index, value) in typingUsers.withIndex()) { | ||
val avatar = ImageView(context) | ||
avatar.id = View.generateViewId() | ||
val layoutParams = MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) | ||
if (index != 0) layoutParams.marginStart = DimensionConverter(resources).dpToPx(AVATAR_SIZE_DP / OVERLAP_FACT0R) | ||
layoutParams.width = DimensionConverter(resources).dpToPx(AVATAR_SIZE_DP) | ||
layoutParams.height = DimensionConverter(resources).dpToPx(AVATAR_SIZE_DP) | ||
avatar.layoutParams = layoutParams | ||
avatarRender.render(value.toMatrixItem(), avatar) | ||
addView(avatar) | ||
} | ||
} | ||
|
||
override fun onDetachedFromWindow() { | ||
super.onDetachedFromWindow() | ||
removeAllViews() | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
vector/src/main/java/im/vector/app/core/ui/views/TypingMessageDotsView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.core.ui.views | ||
|
||
import android.animation.ValueAnimator | ||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.Gravity | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.LinearLayout | ||
import androidx.annotation.DrawableRes | ||
import androidx.appcompat.widget.AppCompatImageView | ||
import androidx.core.view.setMargins | ||
import im.vector.app.R | ||
|
||
class TypingMessageDotsView(context: Context, attrs: AttributeSet) : | ||
LinearLayout(context, attrs) { | ||
|
||
companion object { | ||
const val DEFAULT_CIRCLE_DURATION = 1000L | ||
const val DEFAULT_START_ANIM_CIRCLE_DURATION = 300L | ||
const val DEFAULT_MAX_ALPHA = 1f | ||
const val DEFAULT_MIN_ALPHA = .5f | ||
const val DEFAULT_DOTS_MARGIN = 5 | ||
const val DEFAULT_DOTS_COUNT = 3 | ||
} | ||
|
||
private val circles = mutableListOf<View>() | ||
|
||
init { | ||
orientation = HORIZONTAL | ||
gravity = Gravity.CENTER | ||
setCircles() | ||
} | ||
|
||
private fun setCircles() { | ||
circles.clear() | ||
removeAllViews() | ||
for (i in 0 until DEFAULT_DOTS_COUNT) { | ||
val view = obtainCircle(R.drawable.ic_typing_dot) | ||
addView(view) | ||
circles.add(view) | ||
} | ||
} | ||
|
||
private fun obtainCircle(@DrawableRes imageCircle: Int): View { | ||
val image = AppCompatImageView(context) | ||
image.id = View.generateViewId() | ||
val params = MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) | ||
params.setMargins(DEFAULT_DOTS_MARGIN) | ||
image.layoutParams = params | ||
image.setImageResource(imageCircle) | ||
image.adjustViewBounds = false | ||
return image | ||
} | ||
|
||
override fun onAttachedToWindow() { | ||
super.onAttachedToWindow() | ||
circles.forEachIndexed { index, circle -> animateCircle(index, circle) } | ||
} | ||
|
||
private fun animateCircle(index: Int, circle: View) { | ||
val animator = ValueAnimator.ofFloat(DEFAULT_MAX_ALPHA, DEFAULT_MIN_ALPHA) | ||
animator.duration = DEFAULT_CIRCLE_DURATION | ||
animator.startDelay = DEFAULT_START_ANIM_CIRCLE_DURATION * index | ||
animator.repeatCount = ValueAnimator.INFINITE | ||
animator.addUpdateListener { | ||
circle.alpha = it.animatedValue as Float | ||
} | ||
animator.start() | ||
} | ||
|
||
override fun onDetachedFromWindow() { | ||
super.onDetachedFromWindow() | ||
circles.forEach { it.clearAnimation() } | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
vector/src/main/java/im/vector/app/core/ui/views/TypingMessageView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.core.ui.views | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import im.vector.app.R | ||
import im.vector.app.databinding.TypingMessageLayoutBinding | ||
import im.vector.app.features.home.AvatarRenderer | ||
import im.vector.app.features.home.room.typing.TypingHelper | ||
import org.matrix.android.sdk.api.session.room.sender.SenderInfo | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class TypingMessageView @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyleAttr: Int = 0) : ConstraintLayout(context, attrs, defStyleAttr) { | ||
|
||
val views: TypingMessageLayoutBinding | ||
|
||
@Inject | ||
lateinit var typingHelper: TypingHelper | ||
|
||
init { | ||
inflate(context, R.layout.typing_message_layout, this) | ||
views = TypingMessageLayoutBinding.bind(this) | ||
} | ||
|
||
fun render(typingUsers: List<SenderInfo>, avatarRender: AvatarRenderer) { | ||
views.usersName.text = typingHelper.getNotificationTypingMessage(typingUsers) | ||
views.avatars.render(typingUsers, avatarRender) | ||
} | ||
|
||
override fun onDetachedFromWindow() { | ||
super.onDetachedFromWindow() | ||
removeAllViews() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="7dp" | ||
android:height="6dp" | ||
android:viewportWidth="7" | ||
android:viewportHeight="6"> | ||
<path | ||
android:pathData="M3.22495,3.00004m-2.9,0a2.9,2.9 0,1 1,5.8 0a2.9,2.9 0,1 1,-5.8 0" | ||
android:fillColor="#8D99A5"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.