Skip to content

Commit

Permalink
Add reactions overlay to reply bottom sheets.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal authored and cody-signal committed Jul 26, 2022
1 parent b183a38 commit c0f00ef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.viewModels
Expand All @@ -15,6 +16,7 @@ import org.thoughtcrime.securesms.components.FixedRoundedCornerBottomSheetDialog
import org.thoughtcrime.securesms.recipients.RecipientId
import org.thoughtcrime.securesms.stories.viewer.page.StoryViewerPageViewModel
import org.thoughtcrime.securesms.stories.viewer.reply.BottomSheetBehaviorDelegate
import org.thoughtcrime.securesms.stories.viewer.reply.reaction.OnReactionSentView
import org.thoughtcrime.securesms.util.BottomSheetUtil.requireCoordinatorLayout
import org.thoughtcrime.securesms.util.LifecycleDisposable
import kotlin.math.min
Expand Down Expand Up @@ -46,6 +48,8 @@ class StoryGroupReplyBottomSheetDialogFragment : FixedRoundedCornerBottomSheetDi
private var shouldShowFullScreen = false
private var initialParentHeight = 0

private lateinit var reactionView: OnReactionSentView

private val storyViewerPageViewModel: StoryViewerPageViewModel by viewModels(
ownerProducer = { requireParentFragment() }
)
Expand All @@ -62,6 +66,10 @@ class StoryGroupReplyBottomSheetDialogFragment : FixedRoundedCornerBottomSheetDi
.commitAllowingStateLoss()
}

reactionView = OnReactionSentView(requireContext())
val container = view.rootView.findViewById<FrameLayout>(R.id.container)
container.addView(reactionView)

val bottomSheetBehavior = (requireDialog() as BottomSheetDialog).behavior
bottomSheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) = Unit
Expand Down Expand Up @@ -112,6 +120,10 @@ class StoryGroupReplyBottomSheetDialogFragment : FixedRoundedCornerBottomSheetDi
requireView().invalidate()
}

override fun onReactionEmojiSelected(emoji: String) {
reactionView.playForEmoji(emoji)
}

companion object {
private const val ARG_STORY_ID = "arg.story.id"
private const val ARG_GROUP_RECIPIENT_ID = "arg.group.recipient.id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ class StoryGroupReplyFragment :

override fun onReactionSelected(emoji: String) {
dialog.dismiss()
findListener<Callback>()?.onReactionEmojiSelected(emoji)
sendReaction(emoji)
}

Expand Down Expand Up @@ -541,5 +542,6 @@ class StoryGroupReplyFragment :
interface Callback {
fun onStartDirectReply(recipientId: RecipientId)
fun requestFullScreen(fullscreen: Boolean)
fun onReactionEmojiSelected(emoji: String)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.core.view.ViewCompat
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.DialogFragment
Expand All @@ -17,11 +18,13 @@ import com.google.android.material.tabs.TabLayoutMediator
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.components.FixedRoundedCornerBottomSheetDialogFragment
import org.thoughtcrime.securesms.recipients.RecipientId
import org.thoughtcrime.securesms.stories.viewer.page.StoryViewerPageFragment
import org.thoughtcrime.securesms.stories.viewer.page.StoryViewerPageViewModel
import org.thoughtcrime.securesms.stories.viewer.reply.BottomSheetBehaviorDelegate
import org.thoughtcrime.securesms.stories.viewer.reply.StoryViewsAndRepliesPagerChild
import org.thoughtcrime.securesms.stories.viewer.reply.StoryViewsAndRepliesPagerParent
import org.thoughtcrime.securesms.stories.viewer.reply.group.StoryGroupReplyFragment
import org.thoughtcrime.securesms.stories.viewer.reply.reaction.OnReactionSentView
import org.thoughtcrime.securesms.util.BottomSheetUtil.requireCoordinatorLayout
import org.thoughtcrime.securesms.util.LifecycleDisposable
import kotlin.math.min
Expand Down Expand Up @@ -67,13 +70,19 @@ class StoryViewsAndRepliesDialogFragment : FixedRoundedCornerBottomSheetDialogFr
private val onPageChangeCallback = PageChangeCallback()
private val lifecycleDisposable = LifecycleDisposable()

private lateinit var reactionView: OnReactionSentView

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.stories_views_and_replies_fragment, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
pager = view.findViewById(R.id.pager)

reactionView = OnReactionSentView(requireContext())
val container = pager.rootView.findViewById<FrameLayout>(R.id.container)
container.addView(reactionView)

val bottomSheetBehavior = (requireDialog() as BottomSheetDialog).behavior
bottomSheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) = Unit
Expand Down Expand Up @@ -149,6 +158,10 @@ class StoryViewsAndRepliesDialogFragment : FixedRoundedCornerBottomSheetDialogFr
requireView().invalidate()
}

override fun onReactionEmojiSelected(emoji: String) {
reactionView.playForEmoji(emoji)
}

private inner class PageChangeCallback : ViewPager2.OnPageChangeCallback() {
override fun onPageScrollStateChanged(state: Int) {
if (state == ViewPager2.SCROLL_STATE_IDLE) {
Expand Down

0 comments on commit c0f00ef

Please sign in to comment.