mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
attachment context menu for save, share, forward and open externally
remove share icons from audio and file attachment types add forward and open externally to gallery menu so it matches attachment context menu new icon/button for resend message
This commit is contained in:
@@ -39,7 +39,7 @@ import javax.inject.Inject
|
||||
|
||||
data class MenuItem(val title: String, val actionId: Int)
|
||||
|
||||
class MenuItemAdapter @Inject constructor(private val context: Context, private val colors: Colors) : QkAdapter<MenuItem>() {
|
||||
class MenuItemAdapter @Inject constructor(private val context: Context, private val colors: Colors) : QkAdapter<MenuItem, QkViewHolder>() {
|
||||
|
||||
val menuItemClicks: Subject<Int> = PublishSubject.create()
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import io.reactivex.disposables.Disposable
|
||||
* Base RecyclerView.Adapter that provides some convenience when creating a new Adapter, such as
|
||||
* data list handing and item animations
|
||||
*/
|
||||
abstract class FlowableAdapter<T> : QkAdapter<T>() {
|
||||
abstract class FlowableAdapter<T> : QkAdapter<T, QkViewHolder>() {
|
||||
|
||||
var flowable: Flowable<List<T>>? = null
|
||||
set(value) {
|
||||
|
||||
@@ -30,7 +30,7 @@ import io.reactivex.subjects.Subject
|
||||
* Base RecyclerView.Adapter that provides some convenience when creating a new Adapter, such as
|
||||
* data list handing and item animations
|
||||
*/
|
||||
abstract class QkAdapter<T> : RecyclerView.Adapter<QkViewHolder>() {
|
||||
abstract class QkAdapter<T, VHT : RecyclerView.ViewHolder> : RecyclerView.Adapter<VHT>() {
|
||||
|
||||
var data: List<T> = ArrayList()
|
||||
set(value) {
|
||||
|
||||
@@ -22,6 +22,6 @@ import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.android.extensions.LayoutContainer
|
||||
|
||||
class QkViewHolder(view: View) : RecyclerView.ViewHolder(view), LayoutContainer {
|
||||
open class QkViewHolder(view: View) : RecyclerView.ViewHolder(view), LayoutContainer {
|
||||
override val containerView: View = view
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package dev.octoshrimpy.quik.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.util.AttributeSet
|
||||
import android.view.ContextMenu
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dev.octoshrimpy.quik.common.base.QkAdapter
|
||||
import dev.octoshrimpy.quik.common.base.QkViewHolder
|
||||
import dev.octoshrimpy.quik.model.MmsPart
|
||||
|
||||
open class QkContextMenuRecyclerView<ADAPTER_VALUE_TYPE, VIEW_HOLDER_VALUE_TYPE> : RecyclerView {
|
||||
class ViewHolder<VIEW_HOLDER_VALUE_TYPE>(view: View) : QkViewHolder(view) {
|
||||
init { itemView.isLongClickable = true }
|
||||
var contextMenuValue: VIEW_HOLDER_VALUE_TYPE? = null
|
||||
}
|
||||
|
||||
abstract class Adapter<
|
||||
ADAPTER_VALUE_TYPE,
|
||||
T,
|
||||
VHT : RecyclerView.ViewHolder
|
||||
> : QkAdapter<T, VHT>() {
|
||||
var contextMenuValue: ADAPTER_VALUE_TYPE? = null
|
||||
}
|
||||
|
||||
private var contextMenuInfo: ContextMenuInfo<
|
||||
ADAPTER_VALUE_TYPE,
|
||||
VIEW_HOLDER_VALUE_TYPE
|
||||
>? = null
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
|
||||
: super(context, attrs, defStyleAttr)
|
||||
|
||||
override fun getContextMenuInfo() = contextMenuInfo
|
||||
|
||||
override fun getChildViewHolder(child: View): ViewHolder<VIEW_HOLDER_VALUE_TYPE>? {
|
||||
return super.getChildViewHolder(child) as ViewHolder<VIEW_HOLDER_VALUE_TYPE>
|
||||
}
|
||||
|
||||
override fun showContextMenuForChild(originalView: View): Boolean {
|
||||
saveContextMenuInfo(originalView)
|
||||
return super.showContextMenuForChild(originalView)
|
||||
}
|
||||
|
||||
override fun showContextMenuForChild(originalView: View, x: Float, y: Float): Boolean {
|
||||
saveContextMenuInfo(originalView)
|
||||
return super.showContextMenuForChild(originalView, x, y)
|
||||
}
|
||||
|
||||
private fun saveContextMenuInfo(originalView: View) {
|
||||
contextMenuInfo = ContextMenuInfo(
|
||||
(adapter as Adapter<ADAPTER_VALUE_TYPE, *, *>)?.contextMenuValue,
|
||||
getChildViewHolder(originalView)?.contextMenuValue,
|
||||
this,
|
||||
originalView,
|
||||
getChildAdapterPosition(originalView),
|
||||
getChildItemId(originalView)
|
||||
)
|
||||
}
|
||||
|
||||
class ContextMenuInfo<ADAPTER_VALUE_TYPE, VIEW_HOLDER_VALUE_TYPE>(
|
||||
val adapterValue: ADAPTER_VALUE_TYPE?,
|
||||
val viewHolderValue: VIEW_HOLDER_VALUE_TYPE?,
|
||||
val recyclerView: QkContextMenuRecyclerView<ADAPTER_VALUE_TYPE, VIEW_HOLDER_VALUE_TYPE>,
|
||||
val itemView: View,
|
||||
val adapterPosition: Int,
|
||||
val childItemStableId: Long
|
||||
) : ContextMenu.ContextMenuInfo
|
||||
}
|
||||
|
||||
class QkContextMenuRecyclerViewLongMmsPart : QkContextMenuRecyclerView<Long, MmsPart> {
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
|
||||
: super(context, attrs, defStyleAttr)
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class QkDialog(private val context: Activity) : AlertDialog(context) {
|
||||
view.subtitle.isVisible = !value.isNullOrBlank()
|
||||
}
|
||||
|
||||
var adapter: QkAdapter<*>? = null
|
||||
var adapter: QkAdapter<*, *>? = null
|
||||
set(value) {
|
||||
field = value
|
||||
view.list.isVisible = value != null
|
||||
|
||||
@@ -28,7 +28,7 @@ import dev.octoshrimpy.quik.common.base.QkViewHolder
|
||||
import dev.octoshrimpy.quik.manager.ChangelogManager
|
||||
import kotlinx.android.synthetic.main.changelog_list_item.*
|
||||
|
||||
class ChangelogAdapter(private val context: Context) : QkAdapter<ChangelogAdapter.ChangelogItem>() {
|
||||
class ChangelogAdapter(private val context: Context) : QkAdapter<ChangelogAdapter.ChangelogItem, QkViewHolder>() {
|
||||
|
||||
data class ChangelogItem(val type: Int, val label: String)
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ import javax.inject.Inject
|
||||
|
||||
class AttachmentAdapter @Inject constructor(
|
||||
private val context: Context
|
||||
) : QkAdapter<Attachment>() {
|
||||
) : QkAdapter<Attachment, QkViewHolder>() {
|
||||
|
||||
companion object {
|
||||
private const val VIEW_TYPE_FILE = 0
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.provider.ContactsContract
|
||||
import android.provider.MediaStore
|
||||
import android.speech.RecognizerIntent
|
||||
import android.text.format.DateFormat
|
||||
import android.view.ContextMenu
|
||||
import android.view.GestureDetector
|
||||
import android.view.GestureDetector.SimpleOnGestureListener
|
||||
import android.view.Menu
|
||||
@@ -67,19 +68,53 @@ import dev.octoshrimpy.quik.common.util.extensions.setTint
|
||||
import dev.octoshrimpy.quik.common.util.extensions.setVisible
|
||||
import dev.octoshrimpy.quik.common.util.extensions.showKeyboard
|
||||
import dev.octoshrimpy.quik.common.widget.QkEditText
|
||||
import dev.octoshrimpy.quik.extensions.mapNotNull
|
||||
import dev.octoshrimpy.quik.feature.compose.editing.ChipsAdapter
|
||||
import dev.octoshrimpy.quik.feature.contacts.ContactsActivity
|
||||
import dev.octoshrimpy.quik.model.Attachment
|
||||
import dev.octoshrimpy.quik.model.Recipient
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.compose_activity.*
|
||||
import kotlinx.android.synthetic.main.compose_activity.attach
|
||||
import kotlinx.android.synthetic.main.compose_activity.attachAFileIcon
|
||||
import kotlinx.android.synthetic.main.compose_activity.attachAFileLabel
|
||||
import kotlinx.android.synthetic.main.compose_activity.attaching
|
||||
import kotlinx.android.synthetic.main.compose_activity.attachingBackground
|
||||
import kotlinx.android.synthetic.main.compose_activity.camera
|
||||
import kotlinx.android.synthetic.main.compose_activity.cameraLabel
|
||||
import kotlinx.android.synthetic.main.compose_activity.chips
|
||||
import kotlinx.android.synthetic.main.compose_activity.composeBar
|
||||
import kotlinx.android.synthetic.main.compose_activity.contact
|
||||
import kotlinx.android.synthetic.main.compose_activity.contactLabel
|
||||
import kotlinx.android.synthetic.main.compose_activity.contentView
|
||||
import kotlinx.android.synthetic.main.compose_activity.counter
|
||||
import kotlinx.android.synthetic.main.compose_activity.gallery
|
||||
import kotlinx.android.synthetic.main.compose_activity.galleryLabel
|
||||
import kotlinx.android.synthetic.main.compose_activity.loading
|
||||
import kotlinx.android.synthetic.main.compose_activity.message
|
||||
import kotlinx.android.synthetic.main.compose_activity.messageList
|
||||
import kotlinx.android.synthetic.main.compose_activity.messagesEmpty
|
||||
import kotlinx.android.synthetic.main.compose_activity.noValidRecipients
|
||||
import kotlinx.android.synthetic.main.compose_activity.parts
|
||||
import kotlinx.android.synthetic.main.compose_activity.schedule
|
||||
import kotlinx.android.synthetic.main.compose_activity.scheduleLabel
|
||||
import kotlinx.android.synthetic.main.compose_activity.scheduledCancel
|
||||
import kotlinx.android.synthetic.main.compose_activity.scheduledGroup
|
||||
import kotlinx.android.synthetic.main.compose_activity.scheduledTime
|
||||
import kotlinx.android.synthetic.main.compose_activity.send
|
||||
import kotlinx.android.synthetic.main.compose_activity.sendAsGroup
|
||||
import kotlinx.android.synthetic.main.compose_activity.sendAsGroupBackground
|
||||
import kotlinx.android.synthetic.main.compose_activity.sendAsGroupSwitch
|
||||
import kotlinx.android.synthetic.main.compose_activity.sim
|
||||
import kotlinx.android.synthetic.main.compose_activity.simIndex
|
||||
import kotlinx.android.synthetic.main.compose_activity.toolbarSubtitle
|
||||
import kotlinx.android.synthetic.main.compose_activity.toolbarTitle
|
||||
import kotlinx.android.synthetic.main.main_activity.toolbar
|
||||
import kotlinx.coroutines.reactive.publish
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
@@ -97,13 +132,15 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
override val chipDeletedIntent: Subject<Recipient> by lazy { chipsAdapter.chipDeleted }
|
||||
override val menuReadyIntent: Observable<Unit> = menu.map { Unit }
|
||||
override val optionsItemIntent: Subject<Int> = PublishSubject.create()
|
||||
override val contextItemIntent: Subject<MenuItem> = PublishSubject.create()
|
||||
override val scheduleAction: Subject<Boolean> = PublishSubject.create()
|
||||
override val sendAsGroupIntent by lazy { sendAsGroupBackground.clicks() }
|
||||
override val messageClickIntent: Subject<Long> by lazy { messageAdapter.clicks }
|
||||
override val messagePartClickIntent: Subject<Long> by lazy { messageAdapter.partClicks }
|
||||
override val messagePartContextMenuRegistrar: Subject<View> by lazy { messageAdapter.partContextMenuRegistrar }
|
||||
override val messagesSelectedIntent by lazy { messageAdapter.selectionChanges }
|
||||
override val cancelSendingIntent: Subject<Long> by lazy { messageAdapter.cancelSending }
|
||||
override val sendNowIntent: Subject<Long> by lazy { messageAdapter.sendNow }
|
||||
override val cancelSendingIntent: Subject<Long> by lazy { messageAdapter.cancelSendingClicks }
|
||||
override val sendNowIntent: Subject<Long> by lazy { messageAdapter.sendNowClicks }
|
||||
override val resendIntent: Subject<Long> by lazy { messageAdapter.resendClicks }
|
||||
override val attachmentDeletedIntent: Subject<Attachment> by lazy { attachmentAdapter.attachmentDeleted }
|
||||
override val textChangedIntent by lazy { message.textChanges() }
|
||||
override val attachIntent by lazy { Observable.merge(attach.clicks(), attachingBackground.clicks()) }
|
||||
@@ -170,7 +207,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
messageList.setHasFixedSize(true)
|
||||
messageList.adapter = messageAdapter
|
||||
|
||||
attachments.adapter = attachmentAdapter
|
||||
parts.adapter = attachmentAdapter
|
||||
|
||||
message.supportsInputContent = true
|
||||
|
||||
@@ -218,6 +255,12 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
}
|
||||
})
|
||||
|
||||
// context menu registration for message parts
|
||||
messagePartContextMenuRegistrar
|
||||
.mapNotNull { it }
|
||||
.autoDisposable(scope())
|
||||
.subscribe { registerForContextMenu(it) }
|
||||
|
||||
window.callback = ComposeWindowCallback(window.callback, this)
|
||||
}
|
||||
|
||||
@@ -293,7 +336,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
scheduledGroup.isVisible = state.scheduled != 0L
|
||||
scheduledTime.text = dateFormatter.getScheduledTimestamp(state.scheduled)
|
||||
|
||||
attachments.setVisible(state.attachments.isNotEmpty())
|
||||
parts.setVisible(state.attachments.isNotEmpty())
|
||||
attachmentAdapter.data = state.attachments
|
||||
|
||||
attach.animate().rotation(if (state.attaching) 135f else 0f).start()
|
||||
@@ -491,6 +534,21 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
return super.getColoredMenuItems() + R.id.call
|
||||
}
|
||||
|
||||
override fun onCreateContextMenu(
|
||||
menu: ContextMenu?,
|
||||
v: View?,
|
||||
menuInfo: ContextMenu.ContextMenuInfo?
|
||||
) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo)
|
||||
menuInflater.inflate(R.menu.mms_part_menu, menu)
|
||||
}
|
||||
|
||||
override fun onContextItemSelected(item: MenuItem): Boolean {
|
||||
super.onContextItemSelected(item)
|
||||
contextItemIntent.onNext(item)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (resultCode != Activity.RESULT_OK)
|
||||
return
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
package dev.octoshrimpy.quik.feature.compose
|
||||
|
||||
import android.net.Uri
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.view.inputmethod.InputContentInfoCompat
|
||||
import dev.octoshrimpy.quik.common.base.QkView
|
||||
@@ -43,12 +45,14 @@ interface ComposeView : QkView<ComposeState> {
|
||||
val chipDeletedIntent: Subject<Recipient>
|
||||
val menuReadyIntent: Observable<Unit>
|
||||
val optionsItemIntent: Observable<Int>
|
||||
val contextItemIntent: Observable<MenuItem>
|
||||
val sendAsGroupIntent: Observable<*>
|
||||
val messageClickIntent: Subject<Long>
|
||||
val messagePartClickIntent: Subject<Long>
|
||||
val messagePartContextMenuRegistrar: Subject<View>
|
||||
val messagesSelectedIntent: Observable<List<Long>>
|
||||
val cancelSendingIntent: Subject<Long>
|
||||
val sendNowIntent: Subject<Long>
|
||||
val resendIntent: Subject<Long>
|
||||
val attachmentDeletedIntent: Subject<Attachment>
|
||||
val textChangedIntent: Observable<CharSequence>
|
||||
val attachIntent: Observable<Unit>
|
||||
|
||||
@@ -60,7 +60,10 @@ import dev.octoshrimpy.quik.util.Preferences
|
||||
import dev.octoshrimpy.quik.util.tryOrNull
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import dev.octoshrimpy.quik.common.widget.QkContextMenuRecyclerView
|
||||
import dev.octoshrimpy.quik.extensions.isSmil
|
||||
import dev.octoshrimpy.quik.interactor.SaveImage
|
||||
import dev.octoshrimpy.quik.model.MmsPart
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
@@ -99,7 +102,8 @@ class ComposeViewModel @Inject constructor(
|
||||
private val prefs: Preferences,
|
||||
private val retrySending: RetrySending,
|
||||
private val sendMessage: SendMessage,
|
||||
private val subscriptionManager: SubscriptionManagerCompat
|
||||
private val subscriptionManager: SubscriptionManagerCompat,
|
||||
private val saveImage: SaveImage,
|
||||
) : QkViewModel<ComposeView, ComposeState>(ComposeState(
|
||||
editingMode = threadId == 0L && addresses.isEmpty(),
|
||||
threadId = threadId,
|
||||
@@ -432,6 +436,61 @@ class ComposeViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { copy(query = "", searchSelectionId = -1) } }
|
||||
|
||||
// message part context menu item selected - save
|
||||
view.contextItemIntent
|
||||
.filter { it.itemId == R.id.save }
|
||||
.filter { permissionManager.hasStorage().also { if (!it) view.requestStoragePermission() } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
val menuInfo = it.menuInfo as QkContextMenuRecyclerView.ContextMenuInfo<Long, MmsPart>
|
||||
if (menuInfo.viewHolderValue != null)
|
||||
saveImage.execute(menuInfo.viewHolderValue.id) {
|
||||
context.makeToast(R.string.gallery_toast_saved)
|
||||
}
|
||||
}
|
||||
|
||||
// message part context menu item selected - share
|
||||
view.contextItemIntent
|
||||
.filter { it.itemId == R.id.share }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
val menuInfo = it.menuInfo as QkContextMenuRecyclerView.ContextMenuInfo<Long, MmsPart>
|
||||
if (menuInfo.viewHolderValue != null)
|
||||
navigator.shareFile(
|
||||
MmsPartProvider.getUriForMmsPartId(
|
||||
menuInfo.viewHolderValue.id,
|
||||
menuInfo.viewHolderValue.getBestFilename()
|
||||
),
|
||||
menuInfo.viewHolderValue.type
|
||||
)
|
||||
}
|
||||
|
||||
// message part context menu item selected - forward
|
||||
view.contextItemIntent
|
||||
.filter { it.itemId == R.id.forward }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
val menuInfo = it.menuInfo as QkContextMenuRecyclerView.ContextMenuInfo<Long, MmsPart>
|
||||
if (menuInfo.viewHolderValue != null)
|
||||
navigator.showCompose("", listOf(menuInfo.viewHolderValue.getUri()))
|
||||
}
|
||||
|
||||
// message part context menu item selected - open externally
|
||||
view.contextItemIntent
|
||||
.filter { it.itemId == R.id.openExternally }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
val menuInfo = it.menuInfo as QkContextMenuRecyclerView.ContextMenuInfo<Long, MmsPart>
|
||||
if (menuInfo.viewHolderValue != null)
|
||||
navigator.viewFile(
|
||||
MmsPartProvider.getUriForMmsPartId(
|
||||
menuInfo.viewHolderValue.id,
|
||||
menuInfo.viewHolderValue.getBestFilename()
|
||||
),
|
||||
menuInfo.viewHolderValue.type
|
||||
)
|
||||
}
|
||||
|
||||
// Toggle the group sending mode
|
||||
view.sendAsGroupIntent
|
||||
.autoDisposable(view.scope())
|
||||
@@ -451,14 +510,6 @@ class ComposeViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Retry sending
|
||||
view.messageClickIntent
|
||||
.mapNotNull(messageRepo::getMessage)
|
||||
.filter { message -> message.isFailedMessage() }
|
||||
.doOnNext { message -> retrySending.execute(message.id) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Media attachment clicks
|
||||
view.messagePartClickIntent
|
||||
.mapNotNull(messageRepo::getPart)
|
||||
@@ -495,23 +546,31 @@ class ComposeViewModel @Inject constructor(
|
||||
|
||||
// send a delayed message now
|
||||
view.sendNowIntent
|
||||
.mapNotNull(messageRepo::getMessage)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { message ->
|
||||
cancelMessage.execute(CancelDelayedMessage.Params(message.id, message.threadId))
|
||||
val address = listOf(conversationRepo
|
||||
.getConversation(threadId)?.recipients?.firstOrNull()?.address ?: message.address)
|
||||
sendMessage.execute(
|
||||
SendMessage.Params(
|
||||
message.subId,
|
||||
message.threadId,
|
||||
address,
|
||||
message.body,
|
||||
listOf(), // sms with attachments (mms) can't be delayed so we can know attachments are empty for a 'send now' delayed sms
|
||||
0
|
||||
)
|
||||
.mapNotNull(messageRepo::getMessage)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { message ->
|
||||
cancelMessage.execute(CancelDelayedMessage.Params(message.id, message.threadId))
|
||||
val address = listOf(conversationRepo
|
||||
.getConversation(threadId)?.recipients?.firstOrNull()?.address ?: message.address)
|
||||
sendMessage.execute(
|
||||
SendMessage.Params(
|
||||
message.subId,
|
||||
message.threadId,
|
||||
address,
|
||||
message.body,
|
||||
listOf(), // sms with attachments (mms) can't be delayed so we can know attachments are empty for a 'send now' delayed sms
|
||||
0
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// resend a failed message
|
||||
view.resendIntent
|
||||
.mapNotNull(messageRepo::getMessage)
|
||||
.filter { message -> message.isFailedMessage() }
|
||||
.doOnNext { message -> retrySending.execute(message.id) }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Show the message details
|
||||
view.messageLinkAskIntent
|
||||
|
||||
@@ -45,7 +45,6 @@ import dev.octoshrimpy.quik.common.util.Colors
|
||||
import dev.octoshrimpy.quik.common.util.DateFormatter
|
||||
import dev.octoshrimpy.quik.common.util.TextViewStyler
|
||||
import dev.octoshrimpy.quik.common.util.extensions.dpToPx
|
||||
import dev.octoshrimpy.quik.common.util.extensions.forwardTouches
|
||||
import dev.octoshrimpy.quik.common.util.extensions.setBackgroundTint
|
||||
import dev.octoshrimpy.quik.common.util.extensions.setPadding
|
||||
import dev.octoshrimpy.quik.common.util.extensions.setTint
|
||||
@@ -66,7 +65,7 @@ import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import io.realm.RealmResults
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.*
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.attachments
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.parts
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.body
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.sim
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.simIndex
|
||||
@@ -109,11 +108,13 @@ class MessagesAdapter @Inject constructor(
|
||||
|
||||
}
|
||||
|
||||
val clicks: Subject<Long> = PublishSubject.create()
|
||||
// click events passed back to compose view model
|
||||
val partClicks: Subject<Long> = PublishSubject.create()
|
||||
val messageLinkClicks: Subject<Uri> = PublishSubject.create()
|
||||
val cancelSending: Subject<Long> = PublishSubject.create()
|
||||
val sendNow: Subject<Long> = PublishSubject.create()
|
||||
val cancelSendingClicks: Subject<Long> = PublishSubject.create()
|
||||
val sendNowClicks: Subject<Long> = PublishSubject.create()
|
||||
val resendClicks: Subject<Long> = PublishSubject.create()
|
||||
val partContextMenuRegistrar: Subject<View> = PublishSubject.create()
|
||||
|
||||
var data: Pair<Conversation, RealmResults<Message>>? = null
|
||||
set(value) {
|
||||
@@ -150,11 +151,6 @@ class MessagesAdapter @Inject constructor(
|
||||
|
||||
private val audioState = AudioState()
|
||||
|
||||
/**
|
||||
* If the viewType is negative, then the viewHolder has an attachment. We'll consider
|
||||
* this a unique viewType even though it uses the same view, so that regular messages
|
||||
* don't need clipToOutline set to true, and they don't need to worry about images
|
||||
*/
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
|
||||
// Use the parent's context to inflate the layout, otherwise link clicks will crash the app
|
||||
@@ -166,15 +162,15 @@ class MessagesAdapter @Inject constructor(
|
||||
view.findViewById<ImageView>(R.id.cancelIcon).setTint(theme.theme)
|
||||
view.findViewById<ProgressBar>(R.id.cancel).setTint(theme.theme)
|
||||
view.findViewById<ImageView>(R.id.sendNowIcon).setTint(theme.theme)
|
||||
view.findViewById<ImageView>(R.id.resendIcon).setTint(theme.theme)
|
||||
} else {
|
||||
view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false)
|
||||
}
|
||||
|
||||
view.body.hyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE
|
||||
|
||||
val partsAdapter = partsAdapterProvider.get()
|
||||
partsAdapter.clicks.subscribe(partClicks)
|
||||
view.attachments.adapter = partsAdapter
|
||||
// register recycler view with compose activity for context menus
|
||||
partContextMenuRegistrar.onNext(view.parts)
|
||||
|
||||
return QkViewHolder(view).apply {
|
||||
view.setOnClickListener {
|
||||
@@ -182,7 +178,6 @@ class MessagesAdapter @Inject constructor(
|
||||
when (toggleSelection(message.id, false)) {
|
||||
true -> view.isActivated = isSelected(message.id)
|
||||
false -> {
|
||||
clicks.onNext(message.id)
|
||||
expanded[message.id] = view.status.visibility != View.VISIBLE
|
||||
notifyItemChanged(adapterPosition)
|
||||
}
|
||||
@@ -207,45 +202,60 @@ class MessagesAdapter @Inject constructor(
|
||||
false -> colors.theme(contactCache[message.address])
|
||||
}
|
||||
|
||||
holder.parts.adapter = partsAdapterProvider.get().apply {
|
||||
contextMenuValue = message.id
|
||||
clicks.subscribe(partClicks) // part clicks gets passed back to compose view model
|
||||
}
|
||||
|
||||
// Update the selected state
|
||||
holder.containerView.isActivated = isSelected(message.id) || highlight == message.id
|
||||
|
||||
// Bind the cancelFrame (cancel button) view
|
||||
if (holder.cancelFrame != null) {
|
||||
holder.cancelFrame.let { cancelFrame ->
|
||||
val isCancellable = message.isSending() && message.date > System.currentTimeMillis()
|
||||
cancelFrame.visibility = if (isCancellable) View.VISIBLE else View.GONE
|
||||
cancelFrame.clicks().subscribe { cancelSending.onNext(message.id) }
|
||||
cancelFrame.cancel.progress = 2
|
||||
holder.cancelFrame.let { cancelFrame ->
|
||||
val isCancellable = message.isSending() && message.date > System.currentTimeMillis()
|
||||
cancelFrame.visibility = if (isCancellable) View.VISIBLE else View.GONE
|
||||
cancelFrame.clicks().subscribe { cancelSendingClicks.onNext(message.id) }
|
||||
cancelFrame.cancel.progress = 2
|
||||
|
||||
if (isCancellable) {
|
||||
val delay = when (prefs.sendDelay.get()) {
|
||||
Preferences.SEND_DELAY_SHORT -> 3000
|
||||
Preferences.SEND_DELAY_MEDIUM -> 5000
|
||||
Preferences.SEND_DELAY_LONG -> 10000
|
||||
else -> 0
|
||||
}
|
||||
val progress =
|
||||
(1 - (message.date - System.currentTimeMillis()) / delay.toFloat()) * 100
|
||||
if (isCancellable) {
|
||||
val delay = when (prefs.sendDelay.get()) {
|
||||
Preferences.SEND_DELAY_SHORT -> 3000
|
||||
Preferences.SEND_DELAY_MEDIUM -> 5000
|
||||
Preferences.SEND_DELAY_LONG -> 10000
|
||||
else -> 0
|
||||
}
|
||||
val progress =
|
||||
(1 - (message.date - System.currentTimeMillis()) / delay.toFloat()) * 100
|
||||
|
||||
ObjectAnimator.ofInt(cancelFrame.cancel, "progress", progress.toInt(), 100)
|
||||
.setDuration(message.date - System.currentTimeMillis())
|
||||
.start()
|
||||
ObjectAnimator.ofInt(cancelFrame.cancel, "progress", progress.toInt(), 100)
|
||||
.setDuration(message.date - System.currentTimeMillis())
|
||||
.start()
|
||||
}
|
||||
}
|
||||
|
||||
// bind the send now icon view
|
||||
holder.sendNowIcon.let { sendNowIcon ->
|
||||
if (message.isSending() && message.date > System.currentTimeMillis()) {
|
||||
sendNowIcon.visibility = View.VISIBLE
|
||||
sendNowIcon.clicks().subscribe { sendNowClicks.onNext(message.id) }
|
||||
}
|
||||
else
|
||||
sendNowIcon.visibility = View.GONE
|
||||
}
|
||||
|
||||
// bind the resend icon view
|
||||
holder.resendIcon.let { resendIcon ->
|
||||
if (message.isFailedMessage()) {
|
||||
resendIcon.visibility = View.VISIBLE
|
||||
resendIcon.clicks().subscribe {
|
||||
resendClicks.onNext(message.id)
|
||||
resendIcon.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
else
|
||||
resendIcon.visibility = View.GONE
|
||||
}
|
||||
|
||||
// Bind the send now icon view
|
||||
if (holder.sendNowIcon != null) {
|
||||
holder.sendNowIcon.let { sendNowIcon ->
|
||||
val isCancellable = message.isSending() && message.date > System.currentTimeMillis()
|
||||
sendNowIcon.visibility = if (isCancellable) View.VISIBLE else View.GONE
|
||||
sendNowIcon.clicks().subscribe { sendNow.onNext(message.id) }
|
||||
}
|
||||
}
|
||||
|
||||
val cancelableSimpleOnGestureListener = holder.body.forwardTouches(holder.containerView)
|
||||
|
||||
// Bind the message status
|
||||
bindStatus(holder, message, next)
|
||||
|
||||
@@ -325,9 +335,6 @@ class MessagesAdapter @Inject constructor(
|
||||
object : ClickableSpan() {
|
||||
override fun onClick(widget: View) {
|
||||
messageLinkClicks.onNext(Uri.parse(span.url))
|
||||
|
||||
// interrupt the upcoming click event on the body view
|
||||
cancelableSimpleOnGestureListener.cancelCurrentClick()
|
||||
}
|
||||
},
|
||||
spanString.getSpanStart(span),
|
||||
@@ -351,8 +358,8 @@ class MessagesAdapter @Inject constructor(
|
||||
canGroupWithNext = canGroup(message, next),
|
||||
isMe = message.isMe()))
|
||||
|
||||
// Bind the attachments
|
||||
val partsAdapter = holder.attachments.adapter as PartsAdapter
|
||||
// Bind the parts
|
||||
val partsAdapter = (holder.parts.adapter as PartsAdapter)
|
||||
partsAdapter.theme = theme
|
||||
partsAdapter.setData(message, previous, next, holder, audioState)
|
||||
}
|
||||
@@ -365,12 +372,9 @@ class MessagesAdapter @Inject constructor(
|
||||
message.isDelivered() -> context.getString(R.string.message_status_delivered,
|
||||
dateFormatter.getTimestamp(message.dateSent))
|
||||
message.isFailedMessage() -> context.getString(R.string.message_status_failed)
|
||||
|
||||
// Incoming group message
|
||||
!message.isMe() && conversation?.recipients?.size ?: 0 > 1 -> {
|
||||
!message.isMe() && (conversation?.recipients?.size ?: 0) > 1 -> { // incoming group message
|
||||
"${contactCache[message.address]?.getDisplayName()} • ${dateFormatter.getTimestamp(message.date)}"
|
||||
}
|
||||
|
||||
else -> dateFormatter.getTimestamp(message.date)
|
||||
}
|
||||
|
||||
@@ -379,7 +383,7 @@ class MessagesAdapter @Inject constructor(
|
||||
message.isSending() -> true
|
||||
message.isFailedMessage() -> true
|
||||
expanded[message.id] == false -> false
|
||||
conversation?.recipients?.size ?: 0 > 1 && !message.isMe() && next?.compareSender(message) != true -> true
|
||||
(conversation?.recipients?.size ?: 0) > 1 && !message.isMe() && next?.compareSender(message) != true -> true
|
||||
message.isDelivered() && next?.isDelivered() != true && age <= BubbleUtils.TIMESTAMP_THRESHOLD -> true
|
||||
else -> false
|
||||
})
|
||||
|
||||
@@ -35,7 +35,7 @@ import io.reactivex.subjects.PublishSubject
|
||||
import kotlinx.android.synthetic.main.contact_chip.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ChipsAdapter @Inject constructor() : QkAdapter<Recipient>() {
|
||||
class ChipsAdapter @Inject constructor() : QkAdapter<Recipient, QkViewHolder>() {
|
||||
|
||||
var view: RecyclerView? = null
|
||||
val chipDeleted: PublishSubject<Recipient> = PublishSubject.create<Recipient>()
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ import javax.inject.Inject
|
||||
class ComposeItemAdapter @Inject constructor(
|
||||
private val colors: Colors,
|
||||
private val conversationRepo: ConversationRepository
|
||||
) : QkAdapter<ComposeItem>() {
|
||||
) : QkAdapter<ComposeItem, QkViewHolder>() {
|
||||
|
||||
val clicks: Subject<ComposeItem> = PublishSubject.create()
|
||||
val longClicks: Subject<ComposeItem> = PublishSubject.create()
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import dev.octoshrimpy.quik.common.base.QkViewHolder
|
||||
import dev.octoshrimpy.quik.model.PhoneNumber
|
||||
import kotlinx.android.synthetic.main.contact_number_list_item.*
|
||||
|
||||
class PhoneNumberAdapter : QkAdapter<PhoneNumber>() {
|
||||
class PhoneNumberAdapter : QkAdapter<PhoneNumber, QkViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ import javax.inject.Inject
|
||||
|
||||
class PhoneNumberPickerAdapter @Inject constructor(
|
||||
private val context: Context
|
||||
) : QkAdapter<PhoneNumber>() {
|
||||
) : QkAdapter<PhoneNumber, QkViewHolder>() {
|
||||
|
||||
val selectedItemChanges: Subject<Optional<Long>> = BehaviorSubject.create()
|
||||
|
||||
|
||||
@@ -107,6 +107,9 @@ class AudioBinder @Inject constructor(colors: Colors, private val context: Conte
|
||||
canGroupWithPrevious: Boolean,
|
||||
canGroupWithNext: Boolean,
|
||||
) {
|
||||
// click on background - passes back to compose view model
|
||||
holder.containerView.setOnClickListener { clicks.onNext(part.id) }
|
||||
|
||||
// play/pause button click handling
|
||||
holder.playPause.setOnClickListener {
|
||||
when (holder.playPause.tag) {
|
||||
@@ -177,14 +180,6 @@ class AudioBinder @Inject constructor(colors: Colors, private val context: Conte
|
||||
}
|
||||
}
|
||||
|
||||
// share button click handling
|
||||
holder.share.setOnClickListener {
|
||||
navigator.shareFile(
|
||||
MmsPartProvider.getUriForMmsPartId(part.id, part.getBestFilename()),
|
||||
part.type
|
||||
)
|
||||
}
|
||||
|
||||
// if this item is the active active audio item update the active view holder
|
||||
if (audioState.partId == part.id)
|
||||
audioState.viewHolder = holder
|
||||
@@ -238,10 +233,6 @@ class AudioBinder @Inject constructor(colors: Colors, private val context: Conte
|
||||
setBackgroundTint(primaryColor)
|
||||
}
|
||||
|
||||
// share button
|
||||
holder.share.setTint(secondaryColor)
|
||||
holder.share.setBackgroundTint(primaryColor)
|
||||
|
||||
MediaMetadataRetriever().use {
|
||||
it.setDataSource(context, part.getUri())
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import dev.octoshrimpy.quik.model.MmsPart
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.android.synthetic.main.mms_audio_preview_list_item.share
|
||||
import kotlinx.android.synthetic.main.mms_file_list_item.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -76,33 +75,18 @@ class FileBinder @Inject constructor(colors: Colors, private val context: Contex
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { size -> holder.size.text = size }
|
||||
|
||||
// share button click handling
|
||||
holder.share.setOnClickListener {
|
||||
navigator.shareFile(
|
||||
MmsPartProvider.getUriForMmsPartId(part.id, part.getBestFilename()),
|
||||
part.type
|
||||
)
|
||||
}
|
||||
|
||||
holder.filename.text = part.name
|
||||
|
||||
val params = holder.fileBackground.layoutParams as FrameLayout.LayoutParams
|
||||
if (!message.isMe()) {
|
||||
holder.fileBackground.layoutParams = params.apply { gravity = Gravity.START }
|
||||
holder.fileBackground.setBackgroundTint(theme.theme)
|
||||
holder.icon.setTint(theme.textPrimary)
|
||||
holder.filename.setTextColor(theme.textPrimary)
|
||||
holder.size.setTextColor(theme.textTertiary)
|
||||
holder.share.setTint(theme.theme)
|
||||
holder.share.setBackgroundTint(theme.textPrimary)
|
||||
} else {
|
||||
holder.fileBackground.layoutParams = params.apply { gravity = Gravity.END }
|
||||
holder.fileBackground.setBackgroundTint(holder.containerView.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
holder.icon.setTint(holder.containerView.context.resolveThemeColor(android.R.attr.textColorSecondary))
|
||||
holder.filename.setTextColor(holder.containerView.context.resolveThemeColor(android.R.attr.textColorPrimary))
|
||||
holder.size.setTextColor(holder.containerView.context.resolveThemeColor(android.R.attr.textColorTertiary))
|
||||
holder.share.setTint(holder.containerView.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
holder.share.setBackgroundTint(holder.containerView.context.resolveThemeColor(android.R.attr.textColorTertiary))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
*/
|
||||
package dev.octoshrimpy.quik.feature.compose.part
|
||||
|
||||
import android.net.Uri
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import dev.octoshrimpy.quik.common.base.QkAdapter
|
||||
import dev.octoshrimpy.quik.common.base.QkViewHolder
|
||||
import dev.octoshrimpy.quik.common.util.Colors
|
||||
import dev.octoshrimpy.quik.common.util.extensions.forwardTouches
|
||||
import dev.octoshrimpy.quik.common.widget.QkContextMenuRecyclerView
|
||||
import dev.octoshrimpy.quik.extensions.isSmil
|
||||
import dev.octoshrimpy.quik.extensions.isText
|
||||
import dev.octoshrimpy.quik.feature.compose.BubbleUtils.canGroup
|
||||
@@ -35,13 +35,14 @@ import io.reactivex.Observable
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.*
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
class PartsAdapter @Inject constructor(
|
||||
colors: Colors,
|
||||
fileBinder: FileBinder,
|
||||
imageBinder: ImageBinder,
|
||||
audioBinder: AudioBinder,
|
||||
vCardBinder: VCardBinder,
|
||||
) : QkAdapter<MmsPart>() {
|
||||
) : QkContextMenuRecyclerView.Adapter<Long, MmsPart, QkContextMenuRecyclerView.ViewHolder<MmsPart>>() {
|
||||
|
||||
private val partBinders = listOf(audioBinder, imageBinder, vCardBinder, fileBinder)
|
||||
|
||||
@@ -56,7 +57,6 @@ class PartsAdapter @Inject constructor(
|
||||
private lateinit var message: Message
|
||||
private var previous: Message? = null
|
||||
private var next: Message? = null
|
||||
private var holder: QkViewHolder? = null
|
||||
private var bodyVisible: Boolean = true
|
||||
private var audioState: MessagesAdapter.AudioState? = null
|
||||
|
||||
@@ -70,37 +70,39 @@ class PartsAdapter @Inject constructor(
|
||||
this.message = message
|
||||
this.previous = previous
|
||||
this.next = next
|
||||
this.holder = holder
|
||||
this.bodyVisible = holder.body.visibility == View.VISIBLE
|
||||
this.data = message.parts.filter { !it.isSmil() && !it.isText() }
|
||||
this.audioState = audioState
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int)
|
||||
: QkContextMenuRecyclerView.ViewHolder<MmsPart> {
|
||||
val layout = partBinders.getOrNull(viewType)?.partLayout ?: 0
|
||||
val view = LayoutInflater.from(parent.context).inflate(layout, parent, false)
|
||||
holder?.containerView?.let(view::forwardTouches)
|
||||
return QkViewHolder(view)
|
||||
return QkContextMenuRecyclerView.ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
override fun onBindViewHolder(holder: QkContextMenuRecyclerView.ViewHolder<MmsPart>, position: Int) {
|
||||
val part = data[position]
|
||||
|
||||
holder.contextMenuValue = part
|
||||
|
||||
val canGroupWithPrevious = canGroup(message, previous) || position > 0
|
||||
val canGroupWithNext = canGroup(message, next) || position < itemCount - 1 || bodyVisible
|
||||
|
||||
val binder = partBinders.firstOrNull { it.canBindPart(part) }
|
||||
if (binder == null)
|
||||
return
|
||||
|
||||
// if audioState is set and binder is audio type, set audioState into it
|
||||
// if audioState is set and binder is audio type, set it's audioState ref
|
||||
if ((audioState != null) && (binder is AudioBinder))
|
||||
binder.audioState = audioState!!
|
||||
|
||||
binder?.bindPart(holder, part, message, canGroupWithPrevious, canGroupWithNext)
|
||||
binder.bindPart(holder, part, message, canGroupWithPrevious, canGroupWithNext)
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
val part = data[position]
|
||||
return partBinders.indexOfFirst { it.canBindPart(part) }
|
||||
return partBinders.indexOfFirst { it.canBindPart(data[position]) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -71,15 +71,12 @@ class VCardBinder @Inject constructor(colors: Colors, private val context: Conte
|
||||
holder.name.isVisible = displayName.isNotEmpty()
|
||||
}
|
||||
|
||||
val params = holder.vCardBackground.layoutParams as FrameLayout.LayoutParams
|
||||
if (!message.isMe()) {
|
||||
holder.vCardBackground.layoutParams = params.apply { gravity = Gravity.START }
|
||||
holder.vCardBackground.setBackgroundTint(theme.theme)
|
||||
holder.vCardAvatar.setTint(theme.textPrimary)
|
||||
holder.name.setTextColor(theme.textPrimary)
|
||||
holder.label.setTextColor(theme.textTertiary)
|
||||
} else {
|
||||
holder.vCardBackground.layoutParams = params.apply { gravity = Gravity.END }
|
||||
holder.vCardBackground.setBackgroundTint(holder.containerView.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
holder.vCardAvatar.setTint(holder.containerView.context.resolveThemeColor(android.R.attr.textColorSecondary))
|
||||
holder.name.setTextColor(holder.containerView.context.resolveThemeColor(android.R.attr.textColorPrimary))
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import javax.inject.Inject
|
||||
class ConversationInfoAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val colors: Colors
|
||||
) : QkAdapter<ConversationInfoItem>() {
|
||||
) : QkAdapter<ConversationInfoItem, QkViewHolder>() {
|
||||
|
||||
val recipientClicks: Subject<Long> = PublishSubject.create()
|
||||
val recipientLongClicks: Subject<Long> = PublishSubject.create()
|
||||
|
||||
@@ -107,7 +107,7 @@ class GalleryActivity : QkActivity(), GalleryView {
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.gallery, menu)
|
||||
menuInflater.inflate(R.menu.mms_part_menu, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ class GalleryPagerAdapter @Inject constructor(private val context: Context) : Qk
|
||||
holder.video.player = exoPlayer
|
||||
exoPlayers.add(exoPlayer)
|
||||
|
||||
val dataSourceFactory = DefaultDataSourceFactory(context, Util.getUserAgent(context, "QKSMS"))
|
||||
val dataSourceFactory = DefaultDataSourceFactory(context, Util.getUserAgent(context, "QUIK"))
|
||||
val videoSource = ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(part.getUri())
|
||||
exoPlayer?.prepare(videoSource)
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ import dev.octoshrimpy.quik.repository.ConversationRepository
|
||||
import dev.octoshrimpy.quik.repository.MessageRepository
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import dev.octoshrimpy.quik.common.widget.QkContextMenuRecyclerView
|
||||
import dev.octoshrimpy.quik.model.MmsPart
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
@@ -75,7 +77,7 @@ class GalleryViewModel @Inject constructor(
|
||||
|
||||
// Save image to device
|
||||
view.optionsItemSelected()
|
||||
.filter { itemId -> itemId == R.id.save }
|
||||
.filter { it == R.id.save }
|
||||
.filter { permissions.hasStorage().also { if (!it) view.requestStoragePermission() } }
|
||||
.withLatestFrom(view.pageChanged()) { _, part -> part.id }
|
||||
.autoDisposable(view.scope())
|
||||
@@ -83,7 +85,7 @@ class GalleryViewModel @Inject constructor(
|
||||
|
||||
// Share image externally
|
||||
view.optionsItemSelected()
|
||||
.filter { itemId -> itemId == R.id.share }
|
||||
.filter { it == R.id.share }
|
||||
.withLatestFrom(view.pageChanged()) { _, part -> part }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
@@ -92,6 +94,25 @@ class GalleryViewModel @Inject constructor(
|
||||
it.type
|
||||
)
|
||||
}
|
||||
|
||||
// message part context menu item selected - forward
|
||||
view.optionsItemSelected()
|
||||
.filter { it == R.id.forward }
|
||||
.withLatestFrom(view.pageChanged()) { _, part -> part }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.showCompose("", listOf(it.getUri())) }
|
||||
|
||||
// message part context menu item selected - open externally
|
||||
view.optionsItemSelected()
|
||||
.filter { it == R.id.openExternally }
|
||||
.withLatestFrom(view.pageChanged()) { _, part -> part }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
navigator.viewFile(
|
||||
MmsPartProvider.getUriForMmsPartId(it.id, it.getBestFilename()),
|
||||
it.type
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class SearchAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val dateFormatter: DateFormatter,
|
||||
private val navigator: Navigator
|
||||
) : QkAdapter<SearchResult>() {
|
||||
) : QkAdapter<SearchResult, QkViewHolder>() {
|
||||
|
||||
private val highlightColor: Int by lazy { colors.theme().highlight }
|
||||
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ import javax.inject.Inject
|
||||
|
||||
class ScheduledMessageAttachmentAdapter @Inject constructor(
|
||||
private val context: Context
|
||||
) : QkAdapter<Uri>() {
|
||||
) : QkAdapter<Uri, QkViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
return QkViewHolder(
|
||||
|
||||
@@ -43,7 +43,7 @@ import javax.inject.Inject
|
||||
class ThemeAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val colors: Colors
|
||||
) : QkAdapter<List<Int>>() {
|
||||
) : QkAdapter<List<Int>, QkViewHolder>() {
|
||||
|
||||
val colorSelected: Subject<Int> = PublishSubject.create()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user