feat(reactions): double-tap to react and configurable message swipe actions

Add two reaction UX improvements on top of the send-reaction feature:

- Double-tap a message bubble to send the configured default reaction
  emoji. A single GestureDetector on the item root now handles tap,
  double-tap and long-press, leaving child view touch handling intact.

- Configurable per-direction message swipe actions (none, react, reply,
  copy, forward, delete) via a new MessageItemTouchCallback that always
  snaps the row back after a swipe. Adds a settings screen for the swipe
  actions and a default-reaction emoji picker, backed by new preferences.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
octoshrimpy
2026-06-14 11:52:14 -04:00
parent 88b57ee9d0
commit 5b29290ce1
18 changed files with 584 additions and 19 deletions
@@ -53,6 +53,7 @@ import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.constraintlayout.widget.ConstraintSet
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
@@ -107,6 +108,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
@Inject lateinit var chipsAdapter: ChipsAdapter
@Inject lateinit var dateFormatter: DateFormatter
@Inject lateinit var messageAdapter: MessagesAdapter
@Inject lateinit var messageSwipeCallback: MessageItemTouchCallback
@Inject lateinit var navigator: Navigator
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
@@ -149,6 +151,8 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
override val reactionClickIntent: Subject<Long> by lazy { messageAdapter.reactionClicks }
override val reactionPickerIntent: Observable<Long> by lazy { messageAdapter.reactionPickerIntent }
override val sendReactionIntent: Subject<Pair<Long, String>> = PublishSubject.create()
override val doubleTapMessageIntent: Observable<Long> by lazy { messageAdapter.doubleTapIntent }
override val swipeMessageIntent: Observable<Pair<Long, Int>> by lazy { messageSwipeCallback.swipes }
override val speechRecogniserIntent by lazy { binding.speechToTextIcon.clicks() }
override val shadeIntent by lazy { binding.shadeBackground.clicks() }
override val recordAudioStartStopRecording: Subject<Boolean> = PublishSubject.create()
@@ -205,6 +209,9 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
binding.messageList.setHasFixedSize(true)
binding.messageList.adapter = messageAdapter
messageSwipeCallback.adapter = messageAdapter
ItemTouchHelper(messageSwipeCallback).attachToRecyclerView(binding.messageList)
binding.messageAttachments.adapter = composeAttachmentAdapter
binding.message.supportsInputContent = true
@@ -25,12 +25,18 @@ import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
import dev.octoshrimpy.quik.injection.ViewModelKey
import dev.octoshrimpy.quik.injection.scope.ActivityScope
import dev.octoshrimpy.quik.model.Attachment
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Named
@Module
class ComposeActivityModule {
@Provides
@ActivityScope
fun provideCompositeDisposableLifecycle(): CompositeDisposable = CompositeDisposable()
@Provides
@Named("query")
fun provideQuery(activity: ComposeActivity): String = activity.intent.extras?.getString("query") ?: ""
@@ -80,6 +80,8 @@ interface ComposeView : QkView<ComposeState> {
val reactionClickIntent: Subject<Long>
val reactionPickerIntent: Observable<Long> // message ID to react to
val sendReactionIntent: Subject<Pair<Long, String>> // (messageId, emoji)
val doubleTapMessageIntent: Observable<Long> // message ID
val swipeMessageIntent: Observable<Pair<Long, Int>> // (messageId, direction)
val speechRecogniserIntent: Observable<*>
val shadeIntent: Observable<Unit>
val recordAudioStartStopRecording: Subject<Boolean>
@@ -29,6 +29,7 @@ import android.widget.Toast
import androidx.core.content.FileProvider
import androidx.core.content.getSystemService
import androidx.core.net.toFile
import androidx.recyclerview.widget.ItemTouchHelper
import com.google.android.exoplayer2.util.MimeTypes
import com.moez.QKSMS.common.QkMediaPlayer
import com.moez.QKSMS.contentproviders.MmsPartProvider
@@ -821,6 +822,54 @@ class ComposeViewModel @Inject constructor(
messageRepo.sendNewMessages(subId, addresses, body, emptyList(), sendAsGroup)
}
// Double-tap a message sends the configured default reaction
view.doubleTapMessageIntent
.observeOn(AndroidSchedulers.mainThread())
.filter {
when {
!permissionManager.isDefaultSms() -> { view.requestDefaultSms(); false }
!permissionManager.hasSendSms() -> { view.requestSmsPermission(); false }
else -> true
}
}
.observeOn(Schedulers.io())
.withLatestFrom(state, conversation) { messageId, state, conversation ->
Triple(messageId, state, conversation)
}
.autoDisposable(view.scope())
.subscribe { (messageId, state, conversation) ->
val targetMessage = messageRepo.getMessage(messageId) ?: return@subscribe
val addresses = conversation.recipients.map { it.address }
if (addresses.isEmpty()) return@subscribe
val subId = state.subscription?.subscriptionId ?: -1
val sendAsGroup = addresses.size > 1
val emoji = prefs.defaultReactionEmoji.get()
val body = reactions.buildReactionBody(emoji, targetMessage)
messageRepo.sendNewMessages(subId, addresses, body, emptyList(), sendAsGroup)
}
// Configurable message swipe actions
view.swipeMessageIntent
.observeOn(AndroidSchedulers.mainThread())
.autoDisposable(view.scope())
.subscribe { (messageId, direction) ->
val message = messageRepo.getMessage(messageId) ?: return@subscribe
val action = if (direction == ItemTouchHelper.RIGHT) prefs.messageSwipeRight.get()
else prefs.messageSwipeLeft.get()
when (action) {
Preferences.MESSAGE_SWIPE_ACTION_REACT -> view.showReactionPicker(messageId)
Preferences.MESSAGE_SWIPE_ACTION_REPLY -> view.focusMessage()
Preferences.MESSAGE_SWIPE_ACTION_COPY ->
ClipboardUtils.copy(context, message.getText(false))
Preferences.MESSAGE_SWIPE_ACTION_FORWARD ->
navigator.showCompose(message.getText(false))
Preferences.MESSAGE_SWIPE_ACTION_DELETE -> view.showDeleteDialog(listOf(messageId))
}
}
// Set the current conversation
Observables
.combineLatest(
@@ -0,0 +1,160 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.feature.compose
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import androidx.core.graphics.drawable.toBitmap
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.util.Colors
import dev.octoshrimpy.quik.common.util.extensions.dpToPx
import dev.octoshrimpy.quik.util.Preferences
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.Observables
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import javax.inject.Inject
import kotlin.math.max
import kotlin.math.min
class MessageItemTouchCallback @Inject constructor(
colors: Colors,
disposables: CompositeDisposable,
prefs: Preferences,
private val context: Context
) : ItemTouchHelper.SimpleCallback(0, 0) {
val swipes: Subject<Pair<Long, Int>> = PublishSubject.create()
/**
* Setting the adapter allows us to animate back to the original position
*/
var adapter: RecyclerView.Adapter<*>? = null
private val backgroundPaint = Paint()
private var rightAction = 0
private var swipeRightIcon: Bitmap? = null
private var leftAction = 0
private var swipeLeftIcon: Bitmap? = null
private val iconLength = 24.dpToPx(context)
init {
disposables += colors.themeObservable()
.doOnNext { theme -> backgroundPaint.color = theme.theme }
.subscribeOn(Schedulers.io())
.subscribe()
disposables += Observables
.combineLatest(prefs.messageSwipeRight.asObservable(), prefs.messageSwipeLeft.asObservable(), colors.themeObservable()
) { right, left, theme ->
rightAction = right
swipeRightIcon = iconForAction(right, theme.textPrimary)
leftAction = left
swipeLeftIcon = iconForAction(left, theme.textPrimary)
setDefaultSwipeDirs((if (right == Preferences.MESSAGE_SWIPE_ACTION_NONE) 0 else ItemTouchHelper.RIGHT)
or (if (left == Preferences.MESSAGE_SWIPE_ACTION_NONE) 0 else ItemTouchHelper.LEFT))
}
.subscribeOn(Schedulers.io())
.subscribe()
}
override fun onMove(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder
): Boolean {
return false
}
override fun onChildDraw(
c: Canvas,
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
dX: Float,
dY: Float,
actionState: Int,
isCurrentlyActive: Boolean
) {
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
val itemView = viewHolder.itemView
if (dX > 0) {
c.drawRect(itemView.left.toFloat(), itemView.top.toFloat(),
dX, itemView.bottom.toFloat(), backgroundPaint)
swipeRightIcon?.let { icon ->
val availablePx = dX.toInt() - iconLength
if (availablePx > 0) {
val src = Rect(0, 0, min(availablePx, icon.width), icon.height)
val dstTop = itemView.top + (itemView.bottom - itemView.top - icon.height) / 2
val dst = Rect(iconLength, dstTop, iconLength + src.width(), dstTop + src.height())
c.drawBitmap(icon, src, dst, null)
}
}
} else if (dX < 0) {
c.drawRect(itemView.right.toFloat() + dX, itemView.top.toFloat(),
itemView.right.toFloat(), itemView.bottom.toFloat(), backgroundPaint)
swipeLeftIcon?.let { icon ->
val availablePx = -dX.toInt() - iconLength
if (availablePx > 0) {
val src = Rect(max(0, icon.width - availablePx), 0, icon.width, icon.height)
val dstTop = itemView.top + (itemView.bottom - itemView.top - icon.height) / 2
val dst = Rect(itemView.right - iconLength - src.width(), dstTop,
itemView.right - iconLength, dstTop + src.height())
c.drawBitmap(icon, src, dst, null)
}
}
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
}
}
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
swipes.onNext(Pair(viewHolder.itemId, direction))
// Messages are never archived/removed by a swipe, so always snap back to neutral
adapter?.notifyItemChanged(viewHolder.adapterPosition)
}
private fun iconForAction(action: Int, tint: Int): Bitmap? {
val res = when (action) {
Preferences.MESSAGE_SWIPE_ACTION_REACT -> R.drawable.message_emoji
Preferences.MESSAGE_SWIPE_ACTION_REPLY -> R.drawable.ic_reply_white_24dp
Preferences.MESSAGE_SWIPE_ACTION_COPY -> R.drawable.ic_content_copy_black_24dp
Preferences.MESSAGE_SWIPE_ACTION_FORWARD -> R.drawable.ic_forward_black_24dp
Preferences.MESSAGE_SWIPE_ACTION_DELETE -> R.drawable.ic_delete_white_24dp
else -> null
}
return res?.let(context.resources::getDrawable)
?.apply { setTint(tint) }
?.toBitmap(iconLength, iconLength)
}
}
@@ -32,7 +32,9 @@ import android.text.style.ClickableSpan
import android.text.style.StyleSpan
import android.text.style.URLSpan
import android.text.util.Linkify
import android.view.GestureDetector
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
@@ -112,6 +114,7 @@ class MessagesAdapter @Inject constructor(
val partContextMenuRegistrar: Subject<View> = PublishSubject.create()
val reactionClicks: Subject<Long> = PublishSubject.create()
val reactionPickerIntent: Subject<Long> = PublishSubject.create()
val doubleTapIntent: Subject<Long> = PublishSubject.create()
var data: Pair<Conversation, RealmResults<Message>>? = null
set(value) {
@@ -170,30 +173,43 @@ class MessagesAdapter @Inject constructor(
partContextMenuRegistrar.onNext(parts)
return QkViewHolder(view).apply {
view.setOnClickListener {
getItem(adapterPosition)?.let {
when (toggleSelection(it.id, false)) {
true -> view.isActivated = isSelected(it.id)
false -> {
expanded[it.id] = status.visibility != View.VISIBLE
notifyItemChanged(adapterPosition)
val holder = this
// A single GestureDetector on the item root handles tap / double-tap / long-press.
// Child views (links, images, parts) keep handling their own touch events.
val gestureDetector = GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() {
// must return true so the detector receives the subsequent events
override fun onDown(e: MotionEvent): Boolean = true
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
getItem(holder.adapterPosition)?.let {
when (toggleSelection(it.id, false)) {
true -> view.isActivated = isSelected(it.id)
false -> {
expanded[it.id] = status.visibility != View.VISIBLE
notifyItemChanged(holder.adapterPosition)
}
}
}
return true
}
}
view.setOnLongClickListener {
getItem(adapterPosition)?.let {
// If a selection is already active, keep extending it (multi-select).
// Otherwise, long-press opens the emoji reaction picker for this message.
// Selection mode remains reachable via the toolbar (select all) once active.
if (toggleSelection(it.id, false)) {
view.isActivated = isSelected(it.id)
} else {
reactionPickerIntent.onNext(it.id)
override fun onDoubleTap(e: MotionEvent): Boolean {
getItem(holder.adapterPosition)?.let { doubleTapIntent.onNext(it.id) }
return true
}
override fun onLongPress(e: MotionEvent) {
getItem(holder.adapterPosition)?.let {
// If a selection is already active, keep extending it (multi-select).
// Otherwise, long-press opens the emoji reaction picker for this message.
// Selection mode remains reachable via the toolbar (select all) once active.
if (toggleSelection(it.id, false)) view.isActivated = isSelected(it.id)
else reactionPickerIntent.onNext(it.id)
}
}
true
}
})
view.setOnTouchListener { _, e -> gestureDetector.onTouchEvent(e) }
}
}
@@ -47,6 +47,7 @@ import dev.octoshrimpy.quik.common.widget.PreferenceView
import dev.octoshrimpy.quik.common.widget.TextInputDialog
import dev.octoshrimpy.quik.databinding.SettingsControllerBinding
import dev.octoshrimpy.quik.feature.settings.about.AboutController
import dev.octoshrimpy.quik.feature.settings.swipe.MessageSwipeActionsController
import dev.octoshrimpy.quik.feature.settings.swipe.SwipeActionsController
import dev.octoshrimpy.quik.feature.themepicker.ThemePickerController
import dev.octoshrimpy.quik.injection.appComponent
@@ -76,10 +77,16 @@ class SettingsController : QkController<SettingsControllerBinding, SettingsView,
TextInputDialog(activity!!, context.getString(R.string.settings_signature_title), signatureSubject::onNext)
}
private val defaultReactionDialog: TextInputDialog by lazy {
TextInputDialog(activity!!, context.getString(R.string.settings_default_reaction_title),
defaultReactionSubject::onNext)
}
private val viewQksmsPlusSubject: Subject<Unit> = PublishSubject.create()
private val startTimeSelectedSubject: Subject<Pair<Int, Int>> = PublishSubject.create()
private val endTimeSelectedSubject: Subject<Pair<Int, Int>> = PublishSubject.create()
private val signatureSubject: Subject<String> = PublishSubject.create()
private val defaultReactionSubject: Subject<String> = PublishSubject.create()
private val progressAnimator by lazy { ObjectAnimator.ofInt(binding.syncingProgress, "progress", 0, 0) }
@@ -138,6 +145,8 @@ class SettingsController : QkController<SettingsControllerBinding, SettingsView,
override fun signatureChanged(): Observable<String> = signatureSubject
override fun defaultReactionChanged(): Observable<String> = defaultReactionSubject.hide()
override fun mmsSizeSelected(): Observable<Int> = mmsSizeDialog.adapter.menuItemClicks
override fun messageLinkHandlingSelected(): Observable<Int> = messageLinkHandlingDialog.adapter.menuItemClicks
@@ -166,6 +175,8 @@ class SettingsController : QkController<SettingsControllerBinding, SettingsView,
binding.signature.summary = state.signature.takeIf { it.isNotBlank() }
?: context.getString(R.string.settings_signature_summary)
binding.defaultReaction.summary = state.defaultReactionEmoji
binding.textSize.summary = state.textSizeSummary
textSizeDialog.adapter.selectedItem = state.textSizeId
@@ -238,6 +249,8 @@ class SettingsController : QkController<SettingsControllerBinding, SettingsView,
override fun showSignatureDialog(signature: String) = signatureDialog.setText(signature).show()
override fun showDefaultReactionDialog(current: String) = defaultReactionDialog.setText(current).show()
override fun showMmsSizePicker() = mmsSizeDialog.show(activity!!)
override fun showMessageLinkHandlingDialogPicker() = messageLinkHandlingDialog.show(activity!!)
@@ -248,6 +261,12 @@ class SettingsController : QkController<SettingsControllerBinding, SettingsView,
.popChangeHandler(QkChangeHandler()))
}
override fun showMessageSwipeActions() {
router.pushController(RouterTransaction.with(MessageSwipeActionsController())
.pushChangeHandler(QkChangeHandler())
.popChangeHandler(QkChangeHandler()))
}
override fun showThemePicker() {
router.pushController(RouterTransaction.with(ThemePickerController())
.pushChangeHandler(QkChangeHandler())
@@ -96,6 +96,9 @@ class SettingsPresenter @Inject constructor(
disposables += prefs.signature.asObservable()
.subscribe { signature -> newState { copy(signature = signature) } }
disposables += prefs.defaultReactionEmoji.asObservable()
.subscribe { emoji -> newState { copy(defaultReactionEmoji = emoji) } }
val textSizeLabels = context.resources.getStringArray(R.array.text_sizes)
disposables += prefs.textSize.asObservable()
.subscribe { textSize ->
@@ -182,6 +185,10 @@ class SettingsPresenter @Inject constructor(
R.id.swipeActions -> view.showSwipeActions()
R.id.messageSwipeActions -> view.showMessageSwipeActions()
R.id.defaultReaction -> view.showDefaultReactionDialog(prefs.defaultReactionEmoji.get())
R.id.delayed -> view.showDelayDurationDialog()
R.id.delivery -> prefs.delivery.set(!prefs.delivery.get())
@@ -276,6 +283,11 @@ class SettingsPresenter @Inject constructor(
.autoDisposable(view.scope())
.subscribe()
view.defaultReactionChanged()
.doOnNext(prefs.defaultReactionEmoji::set)
.autoDisposable(view.scope())
.subscribe()
view.mmsSizeSelected()
.autoDisposable(view.scope())
.subscribe(prefs.mmsSize::set)
@@ -36,6 +36,7 @@ data class SettingsState(
val deliveryEnabled: Boolean = false,
val unreadAtTopEnabled: Boolean = false,
val signature: String = "",
val defaultReactionEmoji: String = Preferences.DEFAULT_REACTION_EMOJI,
val textSizeSummary: String = "",
val textSizeId: Int = Preferences.TEXT_SIZE_NORMAL,
val systemFontEnabled: Boolean = false,
@@ -32,6 +32,7 @@ interface SettingsView : QkViewContract<SettingsState> {
fun textSizeSelected(): Observable<Int>
fun sendDelaySelected(): Observable<Int>
fun signatureChanged(): Observable<String>
fun defaultReactionChanged(): Observable<String>
fun mmsSizeSelected(): Observable<Int>
fun messageLinkHandlingSelected(): Observable<Int>
@@ -42,9 +43,11 @@ interface SettingsView : QkViewContract<SettingsState> {
fun showTextSizePicker()
fun showDelayDurationDialog()
fun showSignatureDialog(signature: String)
fun showDefaultReactionDialog(current: String)
fun showMmsSizePicker()
fun showMessageLinkHandlingDialogPicker()
fun showSwipeActions()
fun showMessageSwipeActions()
fun showThemePicker()
fun showAbout()
}
@@ -0,0 +1,106 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.feature.settings.swipe
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import com.jakewharton.rxbinding2.view.clicks
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.autoDisposable
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.QkDialog
import dev.octoshrimpy.quik.common.base.QkController
import dev.octoshrimpy.quik.common.util.Colors
import dev.octoshrimpy.quik.common.util.extensions.animateLayoutChanges
import dev.octoshrimpy.quik.common.util.extensions.setBackgroundTint
import dev.octoshrimpy.quik.common.util.extensions.setTint
import dev.octoshrimpy.quik.databinding.SwipeActionsControllerBinding
import dev.octoshrimpy.quik.injection.appComponent
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import javax.inject.Inject
class MessageSwipeActionsController : QkController<SwipeActionsControllerBinding, MessageSwipeActionsView, MessageSwipeActionsState, MessageSwipeActionsPresenter>(), MessageSwipeActionsView {
override fun inflateBinding(inflater: LayoutInflater, container: ViewGroup): SwipeActionsControllerBinding =
SwipeActionsControllerBinding.inflate(inflater, container, false)
@Inject override lateinit var presenter: MessageSwipeActionsPresenter
@Inject lateinit var actionsDialog: QkDialog
@Inject lateinit var colors: Colors
/**
* Allows us to subscribe to [actionClicks] more than once
*/
private val actionClicks: Subject<MessageSwipeActionsView.Action> = PublishSubject.create()
init {
appComponent.inject(this)
actionsDialog.adapter.setData(R.array.settings_message_swipe_actions)
}
override fun onViewCreated() {
colors.theme().let { theme ->
binding.rightIcon.setBackgroundTint(theme.theme)
binding.rightIcon.setTint(theme.textPrimary)
binding.leftIcon.setBackgroundTint(theme.theme)
binding.leftIcon.setTint(theme.textPrimary)
}
binding.right.postDelayed({ binding.right.animateLayoutChanges = true }, 100)
binding.left.postDelayed({ binding.left.animateLayoutChanges = true }, 100)
Observable.merge(
binding.right.clicks().map { MessageSwipeActionsView.Action.RIGHT },
binding.left.clicks().map { MessageSwipeActionsView.Action.LEFT })
.autoDisposable(scope())
.subscribe(actionClicks)
}
override fun onAttach(view: View) {
super.onAttach(view)
presenter.bindIntents(this)
setTitle(R.string.settings_message_swipe_actions)
showBackButton(true)
}
override fun actionClicks(): Observable<MessageSwipeActionsView.Action> = actionClicks
override fun actionSelected(): Observable<Int> = actionsDialog.adapter.menuItemClicks
override fun showSwipeActions(selected: Int) {
actionsDialog.adapter.selectedItem = selected
activity?.let(actionsDialog::show)
}
override fun render(state: MessageSwipeActionsState) {
binding.rightIcon.isVisible = state.rightIcon != 0
binding.rightIcon.setImageResource(state.rightIcon)
binding.rightLabel.text = state.rightLabel
binding.leftIcon.isVisible = state.leftIcon != 0
binding.leftIcon.setImageResource(state.leftIcon)
binding.leftLabel.text = state.leftLabel
}
}
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.feature.settings.swipe
import android.content.Context
import androidx.annotation.DrawableRes
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.autoDisposable
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.base.QkPresenter
import dev.octoshrimpy.quik.util.Preferences
import io.reactivex.rxkotlin.plusAssign
import javax.inject.Inject
class MessageSwipeActionsPresenter @Inject constructor(
context: Context,
private val prefs: Preferences
) : QkPresenter<MessageSwipeActionsView, MessageSwipeActionsState>(MessageSwipeActionsState()) {
init {
val actionLabels = context.resources.getStringArray(R.array.settings_message_swipe_actions)
disposables += prefs.messageSwipeRight.asObservable()
.subscribe { action -> newState { copy(rightLabel = actionLabels[action], rightIcon = iconForAction(action)) } }
disposables += prefs.messageSwipeLeft.asObservable()
.subscribe { action -> newState { copy(leftLabel = actionLabels[action], leftIcon = iconForAction(action)) } }
}
override fun bindIntents(view: MessageSwipeActionsView) {
super.bindIntents(view)
view.actionClicks()
.map { action ->
when (action) {
MessageSwipeActionsView.Action.RIGHT -> prefs.messageSwipeRight.get()
MessageSwipeActionsView.Action.LEFT -> prefs.messageSwipeLeft.get()
}
}
.autoDisposable(view.scope())
.subscribe(view::showSwipeActions)
view.actionSelected()
.withLatestFrom(view.actionClicks()) { actionId, action ->
when (action) {
MessageSwipeActionsView.Action.RIGHT -> prefs.messageSwipeRight.set(actionId)
MessageSwipeActionsView.Action.LEFT -> prefs.messageSwipeLeft.set(actionId)
}
}
.autoDisposable(view.scope())
.subscribe()
}
@DrawableRes
private fun iconForAction(action: Int) = when (action) {
Preferences.MESSAGE_SWIPE_ACTION_REACT -> R.drawable.message_emoji
Preferences.MESSAGE_SWIPE_ACTION_REPLY -> R.drawable.ic_reply_white_24dp
Preferences.MESSAGE_SWIPE_ACTION_COPY -> R.drawable.ic_content_copy_black_24dp
Preferences.MESSAGE_SWIPE_ACTION_FORWARD -> R.drawable.ic_forward_black_24dp
Preferences.MESSAGE_SWIPE_ACTION_DELETE -> R.drawable.ic_delete_white_24dp
else -> 0
}
}
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.feature.settings.swipe
import androidx.annotation.DrawableRes
import dev.octoshrimpy.quik.R
data class MessageSwipeActionsState(
@DrawableRes val rightIcon: Int = R.drawable.message_emoji,
val rightLabel: String = "",
@DrawableRes val leftIcon: Int = R.drawable.ic_reply_white_24dp,
val leftLabel: String = ""
)
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.feature.settings.swipe
import dev.octoshrimpy.quik.common.base.QkViewContract
import io.reactivex.Observable
interface MessageSwipeActionsView : QkViewContract<MessageSwipeActionsState> {
enum class Action { LEFT, RIGHT }
fun actionClicks(): Observable<Action>
fun actionSelected(): Observable<Int>
fun showSwipeActions(selected: Int)
}
@@ -41,6 +41,7 @@ import dev.octoshrimpy.quik.feature.conversationinfo.injection.ConversationInfoC
import dev.octoshrimpy.quik.feature.messageutils.MessageUtilsController
import dev.octoshrimpy.quik.feature.settings.SettingsController
import dev.octoshrimpy.quik.feature.settings.about.AboutController
import dev.octoshrimpy.quik.feature.settings.swipe.MessageSwipeActionsController
import dev.octoshrimpy.quik.feature.settings.swipe.SwipeActionsController
import dev.octoshrimpy.quik.feature.themepicker.injection.ThemePickerComponent
import dev.octoshrimpy.quik.feature.widget.WidgetAdapter
@@ -74,6 +75,8 @@ interface AppComponent {
fun inject(controller: SettingsController)
fun inject(controller: SwipeActionsController)
fun inject(controller: MessageSwipeActionsController)
fun inject(dialog: QkDialog)
fun inject(service: WidgetAdapter)