Skip to content

Commit

Permalink
Implement status infos on chat view
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Scherzinger <[email protected]>
  • Loading branch information
AndyScherzinger committed Jul 27, 2023
1 parent 8513a32 commit 4073164
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 11 deletions.
56 changes: 51 additions & 5 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import android.view.animation.LinearInterpolator
import android.widget.AbsListView
import android.widget.FrameLayout
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.LinearLayout
Expand All @@ -81,6 +82,7 @@ import android.widget.RelativeLayout
import android.widget.RelativeLayout.BELOW
import android.widget.RelativeLayout.LayoutParams
import android.widget.SeekBar
import android.widget.TextView
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog
Expand Down Expand Up @@ -178,6 +180,7 @@ import com.nextcloud.talk.signaling.SignalingMessageReceiver
import com.nextcloud.talk.signaling.SignalingMessageSender
import com.nextcloud.talk.translate.ui.TranslateActivity
import com.nextcloud.talk.ui.MicInputCloud
import com.nextcloud.talk.ui.StatusDrawable
import com.nextcloud.talk.ui.bottom.sheet.ProfileBottomSheet
import com.nextcloud.talk.ui.dialog.AttachmentDialog
import com.nextcloud.talk.ui.dialog.MessageActionsDialog
Expand Down Expand Up @@ -1568,10 +1571,24 @@ class ChatActivity :
private fun setIcon(drawable: Drawable?) {
supportActionBar?.let {
val avatarSize = (it.height / TOOLBAR_AVATAR_RATIO).roundToInt()

val size = DisplayUtils.convertDpToPixel(STATUS_SIZE_IN_DP, context)
if (drawable != null && avatarSize > 0) {
val bitmap = drawable.toBitmap(avatarSize, avatarSize)
it.setIcon(BitmapDrawable(resources, bitmap))
val status = StatusDrawable(
currentConversation!!.status,
null,
size,
viewThemeUtils.platform.getScheme(binding.chatToolbar.context).surface,
binding.chatToolbar.context
)
binding.chatToolbar.findViewById<ImageView>(R.id.chat_toolbar_avatar)
.setImageDrawable(BitmapDrawable(resources, bitmap))
binding.chatToolbar.findViewById<ImageView>(R.id.chat_toolbar_status)
.setImageDrawable(status)
binding.chatToolbar.findViewById<ImageView>(R.id.chat_toolbar_status).contentDescription =
currentConversation?.status
binding.chatToolbar.findViewById<FrameLayout>(R.id.chat_toolbar_avatar_container)
.visibility = View.VISIBLE
} else {
Log.d(TAG, "loadAvatarForStatusBar avatarSize <= 0")
}
Expand Down Expand Up @@ -1600,6 +1617,8 @@ class ChatActivity :
.diskCachePolicy(CachePolicy.DISABLED)
.build()
)
} else {
binding.chatToolbar.findViewById<FrameLayout>(R.id.chat_toolbar_avatar_container).visibility = View.GONE
}
}

Expand Down Expand Up @@ -2643,17 +2662,42 @@ class ChatActivity :
}

private fun setActionBarTitle() {
supportActionBar?.title =
val title = binding.chatToolbar.findViewById<TextView>(R.id.chat_toolbar_title)
viewThemeUtils.platform.colorTextView(title, ColorRole.ON_SURFACE)

title.text =
if (currentConversation?.displayName != null) {
try {
" " + EmojiCompat.get().process(currentConversation?.displayName as CharSequence).toString()
EmojiCompat.get().process(currentConversation?.displayName as CharSequence).toString()
} catch (e: java.lang.IllegalStateException) {
" " + currentConversation?.displayName
currentConversation?.displayName
error(e)
}
} else {
""
}

val statusMessageView = binding.chatToolbar.findViewById<TextView>(R.id.chat_toolbar_status_message)
if (currentConversation?.type == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) {
var statusMessage = ""
if (currentConversation?.statusIcon != null) {
statusMessage += currentConversation?.statusIcon
}

if (currentConversation?.statusMessage != null) {
statusMessage += currentConversation?.statusMessage
}

if (statusMessage.isNotEmpty()) {
viewThemeUtils.platform.colorTextView(statusMessageView, ColorRole.ON_SURFACE)
statusMessageView.text = statusMessage
statusMessageView.visibility = View.VISIBLE
} else {
statusMessageView.visibility = View.GONE
}
} else {
statusMessageView.visibility = View.GONE
}
}

public override fun onDestroy() {
Expand Down Expand Up @@ -3320,6 +3364,7 @@ class ChatActivity :
}

loadAvatarForStatusBar()
setActionBarTitle()
}

if (CapabilitiesUtilNew.isAbleToCall(conversationUser)) {
Expand Down Expand Up @@ -4145,6 +4190,7 @@ class ChatActivity :
private const val GROUPED_MESSAGES_THRESHOLD = 4
private const val GROUPED_MESSAGES_SAME_AUTHOR_THRESHOLD = 5
private const val TOOLBAR_AVATAR_RATIO = 1.5
private const val STATUS_SIZE_IN_DP = 9f
private const val HTTP_CODE_NOT_MODIFIED = 304
private const val HTTP_CODE_PRECONDITION_FAILED = 412
private const val QUOTED_MESSAGE_IMAGE_MAX_HEIGHT = 96f
Expand Down
64 changes: 61 additions & 3 deletions app/src/main/res/layout/activity_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
android:id="@+id/chat_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/chat_toolbar"
android:layout_width="match_parent"
Expand All @@ -45,9 +46,66 @@
android:theme="?attr/actionBarPopupTheme"
app:layout_scrollFlags="scroll|enterAlways"
app:navigationIconTint="@color/fontAppbar"
app:popupTheme="@style/appActionBarPopupMenu"
app:titleTextColor="@color/fontAppbar"
tools:title="@string/nc_app_product_name" />
app:popupTheme="@style/appActionBarPopupMenu">

<FrameLayout
android:id="@+id/chat_toolbar_avatar_container"
android:layout_width="46dp"
android:layout_height="46dp"
android:layout_marginEnd="@dimen/standard_half_margin"
android:visibility="gone"
tools:visibility="visible">

<ImageView
android:id="@+id/chat_toolbar_avatar"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_gravity="start|center_vertical"
android:contentDescription="@null"
tools:src="@drawable/ic_avatar_group" />

<ImageView
android:id="@+id/chat_toolbar_status"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_gravity="end|bottom"
android:contentDescription="@null"
tools:src="@drawable/online_status" />

</FrameLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">

<TextView
android:id="@+id/chat_toolbar_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:text="@string/nc_app_product_name"
android:textColor="@color/fontAppbar"
android:textSize="22sp" />

<androidx.emoji2.widget.EmojiTextView
android:id="@+id/chat_toolbar_status_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:text="@string/nc_app_product_name"
android:textColor="@color/fontAppbar"
android:textSize="12sp"
android:visibility="gone"
tools:text="Offline"
tools:visibility="visible" />

</LinearLayout>

</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>

<RelativeLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@

<ImageView
android:id="@+id/user_status_image"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_width="wrap_content"
android:layout_height="14dp"
android:layout_gravity="bottom|end"
android:contentDescription="@string/nc_account_chooser_active_user"
tools:src="@drawable/emoji_one_category_smileysandpeople"/>
tools:src="@drawable/emoji_one_category_smileysandpeople" />
</FrameLayout>

<RelativeLayout
Expand Down

0 comments on commit 4073164

Please sign in to comment.