Add unread count to scroll to bottom button

This commit is contained in:
Niels Andriesse 2021-06-24 10:04:43 +10:00
parent 311a298c0c
commit 201b8c8e68
5 changed files with 54 additions and 10 deletions

View File

@ -7,6 +7,7 @@ import android.database.Cursor
import android.graphics.Rect import android.graphics.Rect
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.util.TypedValue
import android.view.* import android.view.*
import android.widget.RelativeLayout import android.widget.RelativeLayout
import androidx.loader.app.LoaderManager import androidx.loader.app.LoaderManager
@ -30,6 +31,7 @@ import org.thoughtcrime.securesms.conversation.v2.input_bar.mentions.MentionCand
import org.thoughtcrime.securesms.conversation.v2.menus.ConversationActionModeCallback import org.thoughtcrime.securesms.conversation.v2.menus.ConversationActionModeCallback
import org.thoughtcrime.securesms.conversation.v2.menus.ConversationMenuHelper import org.thoughtcrime.securesms.conversation.v2.menus.ConversationMenuHelper
import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageView import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageView
import org.thoughtcrime.securesms.database.Database
import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.database.DraftDatabase import org.thoughtcrime.securesms.database.DraftDatabase
import org.thoughtcrime.securesms.database.DraftDatabase.Drafts import org.thoughtcrime.securesms.database.DraftDatabase.Drafts
@ -100,6 +102,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
restoreDraftIfNeeded() restoreDraftIfNeeded()
addOpenGroupGuidelinesIfNeeded() addOpenGroupGuidelinesIfNeeded()
scrollToBottomButton.setOnClickListener { conversationRecyclerView.smoothScrollToPosition(0) } scrollToBottomButton.setOnClickListener { conversationRecyclerView.smoothScrollToPosition(0) }
updateUnreadCount()
} }
private fun setUpRecyclerView() { private fun setUpRecyclerView() {
@ -319,6 +322,15 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
(scrollButtonFullVisibilityThreshold - scrollButtonNoVisibilityThreshold) (scrollButtonFullVisibilityThreshold - scrollButtonNoVisibilityThreshold)
val alpha = max(min(rawAlpha, 1.0f), 0.0f) val alpha = max(min(rawAlpha, 1.0f), 0.0f)
scrollToBottomButton.alpha = alpha scrollToBottomButton.alpha = alpha
updateUnreadCount()
}
private fun updateUnreadCount() {
val unreadCount = DatabaseFactory.getMmsSmsDatabase(this).getUnreadCount(threadID)
val formattedUnreadCount = if (unreadCount < 100) unreadCount.toString() else "99+"
unreadCountTextView.text = formattedUnreadCount
val textSize = if (unreadCount < 100) 12.0f else 9.0f
unreadCountTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize)
} }
// endregion // endregion

View File

@ -5,6 +5,7 @@ import android.util.AttributeSet
import android.util.Log import android.util.Log
import android.view.MotionEvent import android.view.MotionEvent
import android.view.VelocityTracker import android.view.VelocityTracker
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.activity_conversation_v2.* import kotlinx.android.synthetic.main.activity_conversation_v2.*
import org.thoughtcrime.securesms.loki.utilities.disableClipping import org.thoughtcrime.securesms.loki.utilities.disableClipping
@ -33,6 +34,8 @@ class ConversationRecyclerView : RecyclerView {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
bottomOffset += dy // FIXME: Not sure this is fully accurate, but it seems close enough bottomOffset += dy // FIXME: Not sure this is fully accurate, but it seems close enough
val layoutManager = recyclerView.layoutManager as LinearLayoutManager
Log.d("Test", "${layoutManager.findFirstVisibleItemPosition()}")
delegate?.handleConversationRecyclerViewBottomOffsetChanged(abs(bottomOffset)) delegate?.handleConversationRecyclerViewBottomOffsetChanged(abs(bottomOffset))
} }
}) })

View File

@ -73,21 +73,48 @@
<RelativeLayout <RelativeLayout
android:id="@+id/scrollToBottomButton" android:id="@+id/scrollToBottomButton"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="50dp"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_marginRight="12dp" android:layout_marginRight="12dp"
android:layout_marginBottom="72dp" android:layout_marginBottom="72dp"
android:alpha="0" android:alpha="1">
android:background="@drawable/view_scroll_to_bottom_button_background">
<ImageView <RelativeLayout
android:layout_width="16dp" android:layout_width="40dp"
android:layout_height="16dp" android:layout_height="40dp"
android:src="@drawable/ic_chevron_up" android:layout_centerHorizontal="true"
android:layout_centerInParent="true" android:layout_alignParentBottom="true"
android:rotation="180" android:background="@drawable/view_scroll_to_bottom_button_background">
app:tint="@color/text" />
<ImageView
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_chevron_up"
android:layout_centerInParent="true"
android:rotation="180"
app:tint="@color/text" />
</RelativeLayout>
<RelativeLayout
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:background="@drawable/circle_tintable"
android:backgroundTint="@color/conversation_unread_count_indicator_background">
<TextView
android:id="@+id/unreadCountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="@dimen/very_small_font_size"
android:textColor="@color/text"
android:text="8" />
</RelativeLayout>
</RelativeLayout> </RelativeLayout>

View File

@ -31,6 +31,7 @@
<color name="link_preview_background">#0F000000</color> <color name="link_preview_background">#0F000000</color>
<color name="scroll_to_bottom_button_background">#FCFCFC</color> <color name="scroll_to_bottom_button_background">#FCFCFC</color>
<color name="scroll_to_bottom_button_border">#99000000</color> <color name="scroll_to_bottom_button_border">#99000000</color>
<color name="conversation_unread_count_indicator_background">#E0E0E0</color>
<color name="default_background_start">#ffffff</color> <color name="default_background_start">#ffffff</color>
<color name="default_background_end">#fcfcfc</color> <color name="default_background_end">#fcfcfc</color>

View File

@ -38,6 +38,7 @@
<color name="link_preview_background">#000000</color> <color name="link_preview_background">#000000</color>
<color name="scroll_to_bottom_button_background">#171717</color> <color name="scroll_to_bottom_button_background">#171717</color>
<color name="scroll_to_bottom_button_border">#99FFFFFF</color> <color name="scroll_to_bottom_button_border">#99FFFFFF</color>
<color name="conversation_unread_count_indicator_background">#1F1F1F</color>
<array name="profile_picture_placeholder_colors"> <array name="profile_picture_placeholder_colors">
<item>#5ff8b0</item> <item>#5ff8b0</item>