forked from upstream-mirrors/quik
Test stt rebase (#11)
* Update build-on-pull.yml Update's versions. * Update build-on-pull.yml Update Versions and add code to add the signing keys to the build. * Update build-on-pull.yml * Fixes the size of the icon.png. * Update build-on-pull.yml Fixes the formatting of the keystore injections. * Update build-on-pull.yml Changes it to only set up a NoAnalyticsDebug. * Update build-on-pull.yml Remove --stacktrace. * 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 * Update build-and-release.yml * Update build-on-pull.yml * Update PR-deploy.yml * Update build-and-release.yml * Update PR-deploy.yml * fix npe when setting out icons in messagesadapter when in message * Update strings.xml Change to "Leave A Star". * new setting to show/hide new stt button - defaults to 'show' to enable discovery by user. move compose stt feature from double-tap compose entry box to new button on compose activity * change tools view to 'on' for messageList * changes to ingest all attachments in a standard manner. does not change user-facing functionality * changes to make the speed-to-text button drag-and-dropable * rebased to latest master * changes to fix non-reset media player re-use crash * manual update to fix my rebase merge * changes to record audio for audio message from bluetooth sco device (ie bluetooth headset or earbuds) if connected at time of record * changes to fix a bug that appeared to be a race condition between deleting mms parts (attachments) and removing the message data from the realm db when deleting a message. there could be attempts to access part data that no longer exists. protected where the access was being attempted. * Update compose.xml Fixed showing the copy text details, rather than message details. * changes to enable a delete/clear menu icon on compose screen when there is message contents to clear - ie a schedule set, text input or attachments added * changed to reset all necessary state, regardless of editingMode, in clearCurrentMessageIntent handler * changes to make scheduled messages activity ui compliant with the rest of the app message listing activities. now allows sending and deleting multiple scheduled messages at once * fixed title of send now confirm dialog --------- Co-authored-by: octoshrimpy <octoshrimpy@users.noreply.github.com> Co-authored-by: gavine99 <github@xymail.tk>
This commit is contained in:
@@ -25,19 +25,24 @@ import android.app.DatePickerDialog
|
||||
import android.app.TimePickerDialog
|
||||
import android.content.ContentValues
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.SystemClock
|
||||
import android.provider.ContactsContract
|
||||
import android.provider.MediaStore
|
||||
import android.speech.RecognizerIntent
|
||||
import android.text.format.DateFormat
|
||||
import android.view.GestureDetector
|
||||
import android.view.GestureDetector.SimpleOnGestureListener
|
||||
import android.view.ContextMenu
|
||||
import android.view.DragEvent.ACTION_DRAG_ENDED
|
||||
import android.view.DragEvent.ACTION_DRAG_EXITED
|
||||
import android.view.DragEvent.ACTION_DROP
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.View.OnTouchListener
|
||||
import android.widget.Toast
|
||||
import android.widget.SeekBar
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
@@ -52,6 +57,7 @@ import com.google.android.material.snackbar.Snackbar
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.jakewharton.rxbinding2.widget.textChanges
|
||||
import com.moez.QKSMS.common.QkMediaPlayer
|
||||
import com.uber.autodispose.ObservableSubscribeProxy
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import dagger.android.AndroidInjection
|
||||
@@ -61,31 +67,86 @@ import dev.octoshrimpy.quik.common.base.QkThemedActivity
|
||||
import dev.octoshrimpy.quik.common.util.DateFormatter
|
||||
import dev.octoshrimpy.quik.common.util.extensions.autoScrollToStart
|
||||
import dev.octoshrimpy.quik.common.util.extensions.hideKeyboard
|
||||
import dev.octoshrimpy.quik.common.util.extensions.makeToast
|
||||
import dev.octoshrimpy.quik.common.util.extensions.scrapViews
|
||||
import dev.octoshrimpy.quik.common.util.extensions.setBackgroundTint
|
||||
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.MicInputCloudView
|
||||
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.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
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.shadeBackground
|
||||
import kotlinx.android.synthetic.main.compose_activity.audioMsgAbort
|
||||
import kotlinx.android.synthetic.main.compose_activity.audioMsgAttach
|
||||
import kotlinx.android.synthetic.main.compose_activity.audioMsgBackground
|
||||
import kotlinx.android.synthetic.main.compose_activity.audioMsgPlayerBackground
|
||||
import kotlinx.android.synthetic.main.compose_activity.audioMsgPlayerPlayPause
|
||||
import kotlinx.android.synthetic.main.compose_activity.audioMsgPlayerSeekBar
|
||||
import kotlinx.android.synthetic.main.compose_activity.audioMsgRecord
|
||||
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.messageAttachments
|
||||
import kotlinx.android.synthetic.main.compose_activity.attachAnAudioMessageIcon
|
||||
import kotlinx.android.synthetic.main.compose_activity.attachAnAudioMessageLabel
|
||||
import kotlinx.android.synthetic.main.compose_activity.audioMsgBluetooth
|
||||
import kotlinx.android.synthetic.main.compose_activity.audioMsgDuration
|
||||
import kotlinx.android.synthetic.main.compose_activity.recordAudioMsg
|
||||
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.speechToTextFrame
|
||||
import kotlinx.android.synthetic.main.compose_activity.speechToTextIcon
|
||||
import kotlinx.android.synthetic.main.compose_activity.speechToTextIconBorder
|
||||
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 java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
|
||||
@Inject lateinit var attachmentAdapter: AttachmentAdapter
|
||||
@Inject lateinit var composeAttachmentAdapter: ComposeAttachmentAdapter
|
||||
@Inject lateinit var chipsAdapter: ChipsAdapter
|
||||
@Inject lateinit var dateFormatter: DateFormatter
|
||||
@Inject lateinit var messageAdapter: MessagesAdapter
|
||||
@@ -97,16 +158,18 @@ 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 attachmentDeletedIntent: Subject<Attachment> by lazy { attachmentAdapter.attachmentDeleted }
|
||||
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 { composeAttachmentAdapter.attachmentDeleted }
|
||||
override val textChangedIntent by lazy { message.textChanges() }
|
||||
override val attachIntent by lazy { Observable.merge(attach.clicks(), attachingBackground.clicks()) }
|
||||
override val attachIntent by lazy { Observable.merge(attach.clicks(), shadeBackground.clicks()) }
|
||||
override val cameraIntent by lazy { Observable.merge(camera.clicks(), cameraLabel.clicks()) }
|
||||
override val attachImageFileIntent by lazy { Observable.merge(gallery.clicks(), galleryLabel.clicks()) }
|
||||
override val attachAnyFileIntent by lazy { Observable.merge(attachAFileIcon.clicks(), attachAFileLabel.clicks()) }
|
||||
@@ -122,12 +185,39 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val confirmDeleteIntent: Subject<List<Long>> = PublishSubject.create()
|
||||
override val confirmClearCurrentMessageIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val clearCurrentMessageIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val messageLinkAskIntent: Subject<Uri> by lazy { messageAdapter.messageLinkClicks }
|
||||
override val speechRecogniserIntent by lazy { speechToTextIcon.clicks() }
|
||||
override val shadeIntent by lazy { shadeBackground.clicks() }
|
||||
override val recordAudioStartStopRecording: Subject<Boolean> = PublishSubject.create()
|
||||
override val recordAnAudioMessage by lazy {
|
||||
Observable.merge(recordAudioMsg.clicks(),
|
||||
attachAnAudioMessageIcon.clicks(),
|
||||
attachAnAudioMessageLabel.clicks())
|
||||
}
|
||||
override val recordAudioAbort by lazy { audioMsgAbort.clicks() }
|
||||
override val recordAudioAttach by lazy { audioMsgAttach.clicks() }
|
||||
override val recordAudioPlayerPlayPause: Subject<QkMediaPlayer.PlayingState> = PublishSubject.create()
|
||||
override val recordAudioPlayerConfigUI: Subject<QkMediaPlayer.PlayingState> = PublishSubject.create()
|
||||
override val recordAudioPlayerVisible: Subject<Boolean> = PublishSubject.create()
|
||||
override val recordAudioMsgRecordVisible: Subject<Boolean> = PublishSubject.create()
|
||||
override val recordAudioChronometer: Subject<Boolean> = PublishSubject.create()
|
||||
override val recordAudioRecord: Subject<MicInputCloudView.ViewState> = PublishSubject.create()
|
||||
|
||||
private var seekBarUpdater: Disposable? = null
|
||||
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ComposeViewModel::class.java] }
|
||||
|
||||
private var cameraDestination: Uri? = null
|
||||
|
||||
private fun getSeekBarUpdater(): ObservableSubscribeProxy<Long> {
|
||||
return Observable.interval(500, TimeUnit.MILLISECONDS)
|
||||
.subscribeOn(Schedulers.single())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDisposable(scope())
|
||||
}
|
||||
|
||||
private val speechResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode != Activity.RESULT_OK)
|
||||
return@registerForActivityResult
|
||||
@@ -181,11 +271,55 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
messageList.setHasFixedSize(true)
|
||||
messageList.adapter = messageAdapter
|
||||
|
||||
attachments.adapter = attachmentAdapter
|
||||
messageAttachments.adapter = composeAttachmentAdapter
|
||||
|
||||
message.supportsInputContent = true
|
||||
|
||||
theme
|
||||
.doOnNext { loading.setTint(it.theme) }
|
||||
.doOnNext { attach.setBackgroundTint(it.theme) }
|
||||
.doOnNext { attach.setTint(it.textPrimary) }
|
||||
.doOnNext { speechToTextIconBorder.setBackgroundTint(it.theme) }
|
||||
.doOnNext { speechToTextIcon.setBackgroundTint(it.textPrimary) }
|
||||
.doOnNext { speechToTextIcon.setTint(it.theme) }
|
||||
.doOnNext { audioMsgRecord.setColor(it.theme) }
|
||||
.doOnNext { audioMsgPlayerPlayPause.setTint(it.theme) }
|
||||
.doOnNext {
|
||||
audioMsgPlayerSeekBar.apply {
|
||||
thumbTintList = ColorStateList.valueOf(it.theme)
|
||||
progressBackgroundTintList = ColorStateList.valueOf(it.theme)
|
||||
progressTintList = ColorStateList.valueOf(it.theme)
|
||||
}
|
||||
}
|
||||
.doOnNext { messageAdapter.theme = it }
|
||||
.autoDisposable(scope())
|
||||
.subscribe()
|
||||
|
||||
// context menu registration for message parts
|
||||
messagePartContextMenuRegistrar
|
||||
.mapNotNull { it }
|
||||
.autoDisposable(scope())
|
||||
.subscribe { registerForContextMenu(it) }
|
||||
|
||||
// drag drop handlers for speech-to-text icon
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
speechToTextIcon.setOnLongClickListener {
|
||||
it.startDragAndDrop(null, View.DragShadowBuilder(speechToTextFrame), null, 0)
|
||||
speechToTextFrame.isVisible = false
|
||||
|
||||
contentView.setOnDragListener { _, event ->
|
||||
when (event.action) {
|
||||
ACTION_DROP -> {
|
||||
speechToTextFrame.x = (event.x - (speechToTextFrame.width / 2))
|
||||
speechToTextFrame.y =(event.y - (speechToTextFrame.height / 2))
|
||||
|
||||
// get offset from root view as a percentage of root view for saving
|
||||
prefs.showSttOffsetX.set((speechToTextFrame.x - contentView.x) / contentView.width)
|
||||
prefs.showSttOffsetY.set((speechToTextFrame.y - contentView.y) / contentView.height)
|
||||
}
|
||||
ACTION_DRAG_ENDED, ACTION_DRAG_EXITED -> {
|
||||
speechToTextFrame.isVisible = true
|
||||
}
|
||||
.doOnNext { loading.setTint(it.theme) }
|
||||
.doOnNext { attach.setBackgroundTint(it.theme) }
|
||||
.doOnNext { attach.setTint(it.textPrimary) }
|
||||
@@ -217,26 +351,101 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
||||
if (lastUpEvent !== null) {
|
||||
message.onTouchEvent(lastUpEvent)
|
||||
lastUpEvent?.recycle()
|
||||
lastUpEvent = null
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onSingleTapUp(e: MotionEvent): Boolean {
|
||||
lastUpEvent = MotionEvent.obtain(e)
|
||||
return true // don't show soft keyboard on this event
|
||||
}
|
||||
})
|
||||
|
||||
override fun onTouch(v: View, e: MotionEvent): Boolean {
|
||||
return gestureDetector.onTouchEvent(e)
|
||||
true
|
||||
}
|
||||
true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// start/stop audio message recording
|
||||
audioMsgRecord.setOnClickListener {
|
||||
recordAudioRecord.onNext(audioMsgRecord.getState())
|
||||
}
|
||||
|
||||
recordAudioChronometer
|
||||
.subscribeOn(AndroidSchedulers.mainThread())
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(scope())
|
||||
.subscribe {
|
||||
if (it) {
|
||||
audioMsgDuration.base = SystemClock.elapsedRealtime()
|
||||
audioMsgDuration.start()
|
||||
} else {
|
||||
audioMsgDuration.stop()
|
||||
}
|
||||
}
|
||||
|
||||
// audio record playback play/pause button
|
||||
audioMsgPlayerPlayPause.setOnClickListener {
|
||||
recordAudioPlayerPlayPause.onNext(
|
||||
audioMsgPlayerPlayPause.tag as QkMediaPlayer.PlayingState
|
||||
)
|
||||
}
|
||||
|
||||
recordAudioMsgRecordVisible
|
||||
.subscribeOn(AndroidSchedulers.mainThread())
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(scope())
|
||||
.subscribe {
|
||||
audioMsgRecord.isVisible = it
|
||||
audioMsgDuration.isVisible = it // chronometer follows record button visibility
|
||||
audioMsgBluetooth.isVisible = !it
|
||||
}
|
||||
|
||||
recordAudioPlayerVisible
|
||||
.subscribeOn(AndroidSchedulers.mainThread())
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(scope())
|
||||
.subscribe {
|
||||
audioMsgPlayerBackground.isVisible = it
|
||||
recordAudioPlayerConfigUI.onNext(QkMediaPlayer.PlayingState.Stopped)
|
||||
}
|
||||
|
||||
recordAudioPlayerConfigUI
|
||||
.subscribeOn(AndroidSchedulers.mainThread())
|
||||
.distinctUntilChanged()
|
||||
.autoDisposable(scope())
|
||||
.subscribe {
|
||||
when (it) {
|
||||
QkMediaPlayer.PlayingState.Playing -> {
|
||||
audioMsgPlayerPlayPause.tag = QkMediaPlayer.PlayingState.Playing
|
||||
QkMediaPlayer.start()
|
||||
audioMsgPlayerPlayPause.setImageResource(R.drawable.exo_icon_pause)
|
||||
seekBarUpdater = getSeekBarUpdater().subscribe {
|
||||
audioMsgPlayerSeekBar.progress = QkMediaPlayer.currentPosition
|
||||
audioMsgPlayerSeekBar.max = QkMediaPlayer.duration
|
||||
}
|
||||
audioMsgPlayerSeekBar.isEnabled = true
|
||||
}
|
||||
QkMediaPlayer.PlayingState.Paused -> {
|
||||
audioMsgPlayerPlayPause.tag = QkMediaPlayer.PlayingState.Paused
|
||||
QkMediaPlayer.pause()
|
||||
audioMsgPlayerPlayPause.setImageResource(R.drawable.exo_icon_play)
|
||||
seekBarUpdater?.dispose()
|
||||
}
|
||||
else -> {
|
||||
audioMsgPlayerPlayPause.tag = QkMediaPlayer.PlayingState.Stopped
|
||||
QkMediaPlayer.reset()
|
||||
audioMsgPlayerPlayPause.setImageResource(R.drawable.exo_icon_play)
|
||||
seekBarUpdater?.dispose()
|
||||
audioMsgPlayerSeekBar.progress = 0
|
||||
audioMsgPlayerSeekBar.isEnabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// audio msg player seek bar handler
|
||||
audioMsgPlayerSeekBar.setOnSeekBarChangeListener(
|
||||
object : SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(p0: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||
// if seek was initiated by the user and this part is currently playing
|
||||
if (fromUser)
|
||||
QkMediaPlayer.seekTo(progress)
|
||||
}
|
||||
override fun onStartTrackingTouch(p0: SeekBar?) {}
|
||||
override fun onStopTrackingTouch(p0: SeekBar?) {}
|
||||
}
|
||||
)
|
||||
|
||||
window.callback = ComposeWindowCallback(window.callback, this)
|
||||
}
|
||||
@@ -244,6 +453,16 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
activityVisibleIntent.onNext(true)
|
||||
|
||||
// if first time stt icon is shown (since setting reset), pop up an instruction toast
|
||||
if (prefs.showStt.get() &&
|
||||
(prefs.showSttOffsetX.get() == Float.MIN_VALUE) &&
|
||||
(prefs.showSttOffsetX.get() == Float.MIN_VALUE)) {
|
||||
makeToast(R.string.compose_toast_drag_stt, Toast.LENGTH_LONG)
|
||||
// reset to new flag value that indicates 'not first time through, but not customised'
|
||||
prefs.showSttOffsetX.set(Float.MAX_VALUE)
|
||||
prefs.showSttOffsetY.set(Float.MAX_VALUE)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
@@ -256,6 +475,8 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
|
||||
// stop any playing audio
|
||||
QkMediaPlayer.reset()
|
||||
|
||||
seekBarUpdater?.dispose()
|
||||
}
|
||||
|
||||
|
||||
@@ -292,7 +513,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
&& state.query.isEmpty()
|
||||
toolbar.menu.findItem(R.id.copy)?.isVisible = !state.editingMode && state.selectedMessages > 0
|
||||
toolbar.menu.findItem(R.id.details)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||
toolbar.menu.findItem(R.id.delete)?.isVisible = !state.editingMode && state.selectedMessages > 0
|
||||
toolbar.menu.findItem(R.id.delete)?.isVisible = !state.editingMode && ((state.selectedMessages > 0) || state.canSend)
|
||||
toolbar.menu.findItem(R.id.forward)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||
toolbar.menu.findItem(R.id.show_status)?.isVisible = !state.editingMode && state.selectedMessages > 0
|
||||
toolbar.menu.findItem(R.id.previous)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty()
|
||||
@@ -313,12 +534,19 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
scheduledGroup.isVisible = state.scheduled != 0L
|
||||
scheduledTime.text = dateFormatter.getScheduledTimestamp(state.scheduled)
|
||||
|
||||
attachments.setVisible(state.attachments.isNotEmpty())
|
||||
attachmentAdapter.data = state.attachments
|
||||
messageAttachments.setVisible(state.attachments.isNotEmpty())
|
||||
composeAttachmentAdapter.data = state.attachments
|
||||
|
||||
attach.animate().rotation(if (state.attaching) 135f else 0f).start()
|
||||
attaching.isVisible = state.attaching
|
||||
|
||||
shadeBackground.visibility =
|
||||
if (state.attaching || state.audioMsgRecording) View.VISIBLE
|
||||
else View.GONE
|
||||
|
||||
// show or hide audio message recording panel and shade background
|
||||
audioMsgBackground.isVisible = state.audioMsgRecording
|
||||
|
||||
counter.text = state.remaining
|
||||
counter.setVisible(counter.text.isNotBlank())
|
||||
|
||||
@@ -326,8 +554,9 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
sim.contentDescription = getString(R.string.compose_sim_cd, state.subscription?.displayName)
|
||||
simIndex.text = state.subscription?.simSlotIndex?.plus(1)?.toString()
|
||||
|
||||
send.isEnabled = state.canSend
|
||||
send.imageAlpha = if (state.canSend) 255 else 128
|
||||
// show either send or audio msg record button
|
||||
send.visibility = if (state.canSend && !state.loading) View.VISIBLE else View.INVISIBLE
|
||||
recordAudioMsg.visibility = if (state.canSend && !state.loading) View.INVISIBLE else View.VISIBLE
|
||||
|
||||
// if not in editing mode, and there are no non-me participants that can be sent to,
|
||||
// hide controls that allow constructing a reply and inform user no valid recipients
|
||||
@@ -352,6 +581,19 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
// if scheduling mode is set, show schedule dialog
|
||||
if (state.scheduling)
|
||||
scheduleAction.onNext(true)
|
||||
|
||||
if (prefs.showStt.get()) {
|
||||
speechToTextFrame.isVisible = true
|
||||
|
||||
var xPercent = prefs.showSttOffsetX.get()
|
||||
var yPercent = prefs.showSttOffsetY.get()
|
||||
|
||||
// if the stt icon has a custom position, move it
|
||||
if ((xPercent != Float.MAX_VALUE) && (yPercent != Float.MAX_VALUE)) {
|
||||
speechToTextFrame.x = (contentView.x + (xPercent * contentView.width))
|
||||
speechToTextFrame.y = (contentView.y + (yPercent * contentView.height))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun clearSelection() = messageAdapter.clearSelection()
|
||||
@@ -397,6 +639,10 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 0)
|
||||
}
|
||||
|
||||
override fun requestRecordAudioPermission() {
|
||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO), 0)
|
||||
}
|
||||
|
||||
override fun requestSmsPermission() {
|
||||
ActivityCompat.requestPermissions(this, arrayOf(
|
||||
Manifest.permission.READ_SMS,
|
||||
@@ -423,7 +669,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
|
||||
override fun requestContact() {
|
||||
val intent = Intent(Intent.ACTION_PICK)
|
||||
.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE)
|
||||
.setType(ContactsContract.Contacts.CONTENT_TYPE)
|
||||
|
||||
startActivityForResult(Intent.createChooser(intent, null), ComposeView.AttachContactRequestCode)
|
||||
}
|
||||
@@ -437,6 +683,18 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
startActivityForResult(intent, ComposeView.SelectContactRequestCode)
|
||||
}
|
||||
|
||||
override fun startSpeechRecognition() {
|
||||
startActivityForResult(
|
||||
Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).putExtra(
|
||||
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
|
||||
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
|
||||
),
|
||||
// include below if want a custom message that the STT can (optionally) display
|
||||
// .putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak your message")
|
||||
ComposeView.SpeechRecognitionRequestCode
|
||||
)
|
||||
}
|
||||
|
||||
override fun themeChanged() {
|
||||
messageList.scrapViews()
|
||||
}
|
||||
@@ -497,6 +755,17 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun showClearCurrentMessageDialog() {
|
||||
android.app.AlertDialog.Builder(this)
|
||||
.setTitle(R.string.dialog_clear_compose_title)
|
||||
.setMessage(R.string.dialog_clear_compose)
|
||||
.setPositiveButton(R.string.button_clear) { _, _ ->
|
||||
clearCurrentMessageIntent.onNext(Unit)
|
||||
}
|
||||
.setNegativeButton(R.string.button_cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.compose, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
@@ -511,6 +780,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
|
||||
@@ -538,6 +822,21 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
data?.data?.let(contactSelectedIntent::onNext)
|
||||
}
|
||||
|
||||
ComposeView.SpeechRecognitionRequestCode -> {
|
||||
// check returned results are good
|
||||
val match = data?.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
|
||||
if ((match !== null) && (match.size > 0) && (!match[0].isNullOrEmpty())) {
|
||||
// get the edit text view
|
||||
val messageEditBox = findViewById<QkEditText>(R.id.message)
|
||||
if (messageEditBox !== null) {
|
||||
// populate message box with data returned by STT, set cursor to end, and focus
|
||||
messageEditBox.append(match[0])
|
||||
messageEditBox.setSelection(messageEditBox.text.length)
|
||||
messageEditBox.requestFocus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else -> super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,12 @@ package dev.octoshrimpy.quik.feature.compose
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.google.android.mms.ContentType
|
||||
import dev.octoshrimpy.quik.injection.ViewModelKey
|
||||
import dev.octoshrimpy.quik.model.Attachment
|
||||
import dev.octoshrimpy.quik.model.Attachments
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.multibindings.IntoMap
|
||||
import java.net.URLDecoder
|
||||
import java.nio.charset.Charset
|
||||
import javax.inject.Named
|
||||
|
||||
@Module
|
||||
@@ -74,12 +71,12 @@ class ComposeActivityModule {
|
||||
|
||||
@Provides
|
||||
@Named("attachments")
|
||||
fun provideSharedAttachments(activity: ComposeActivity): Attachments {
|
||||
fun provideSharedAttachments(activity: ComposeActivity): List<Attachment> {
|
||||
val uris = mutableListOf<Uri>()
|
||||
activity.intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)?.run(uris::add)
|
||||
activity.intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)?.run(uris::addAll)
|
||||
|
||||
return Attachments(uris.mapNotNull { Attachment(it) })
|
||||
return uris.mapNotNull { Attachment(activity, it) }
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
+5
-5
@@ -41,9 +41,9 @@ import kotlinx.android.synthetic.main.attachment_contact_list_item.*
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
class AttachmentAdapter @Inject constructor(
|
||||
class ComposeAttachmentAdapter @Inject constructor(
|
||||
private val context: Context
|
||||
) : QkAdapter<Attachment>() {
|
||||
) : QkAdapter<Attachment, QkViewHolder>() {
|
||||
|
||||
companion object {
|
||||
private const val VIEW_TYPE_FILE = 0
|
||||
@@ -93,14 +93,14 @@ class AttachmentAdapter @Inject constructor(
|
||||
holder.fileName.visibility = View.GONE
|
||||
|
||||
// if attachment uri is missing
|
||||
if (!attachment.getUri().resourceExists(context)) {
|
||||
if (!attachment.uri.resourceExists(context)) {
|
||||
holder.thumbnail.setImageResource(android.R.drawable.ic_delete)
|
||||
holder.fileName.text = context.getString(R.string.attachment_missing)
|
||||
holder.fileName.visibility = View.VISIBLE
|
||||
return
|
||||
}
|
||||
|
||||
val uri = attachment.getUri()
|
||||
val uri = attachment.uri
|
||||
val mimeType = attachment.getType(context)
|
||||
|
||||
// if attachment mime type is image/* or video/*, use image/frame
|
||||
@@ -160,4 +160,4 @@ class AttachmentAdapter @Inject constructor(
|
||||
else -> VIEW_TYPE_FILE
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -40,11 +40,12 @@ data class ComposeState(
|
||||
val messages: Pair<Conversation, RealmResults<Message>>? = null,
|
||||
val selectedMessages: Int = 0,
|
||||
val scheduled: Long = 0,
|
||||
val attachments: List<Attachment> = ArrayList(),
|
||||
val attachments: List<Attachment> = listOf(),
|
||||
val attaching: Boolean = false,
|
||||
val scheduling: Boolean = false,
|
||||
val remaining: String = "",
|
||||
val subscription: SubscriptionInfoCompat? = null,
|
||||
val canSend: Boolean = false,
|
||||
val validRecipientNumbers: Int = 1,
|
||||
val audioMsgRecording: Boolean = false,
|
||||
)
|
||||
@@ -19,9 +19,13 @@
|
||||
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 com.moez.QKSMS.common.QkMediaPlayer
|
||||
import dev.octoshrimpy.quik.common.base.QkView
|
||||
import dev.octoshrimpy.quik.common.widget.MicInputCloudView
|
||||
import dev.octoshrimpy.quik.model.Attachment
|
||||
import dev.octoshrimpy.quik.model.Recipient
|
||||
import io.reactivex.Observable
|
||||
@@ -32,8 +36,9 @@ interface ComposeView : QkView<ComposeState> {
|
||||
companion object {
|
||||
const val SelectContactRequestCode = 0
|
||||
const val TakePhotoRequestCode = 1
|
||||
const val AttachAFileRequestCode = 4
|
||||
const val AttachContactRequestCode = 3
|
||||
const val AttachAFileRequestCode = 4
|
||||
const val SpeechRecognitionRequestCode = 5
|
||||
|
||||
const val CameraDestinationKey = "camera_destination"
|
||||
}
|
||||
@@ -43,12 +48,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>
|
||||
@@ -68,7 +75,21 @@ interface ComposeView : QkView<ComposeState> {
|
||||
val viewQksmsPlusIntent: Subject<Unit>
|
||||
val backPressedIntent: Observable<Unit>
|
||||
val confirmDeleteIntent: Observable<List<Long>>
|
||||
val confirmClearCurrentMessageIntent: Observable<Unit>
|
||||
val clearCurrentMessageIntent: Subject<Unit>
|
||||
val messageLinkAskIntent: Observable<Uri>
|
||||
val speechRecogniserIntent: Observable<*>
|
||||
val shadeIntent: Observable<Unit>
|
||||
val recordAudioStartStopRecording: Subject<Boolean>
|
||||
val recordAnAudioMessage: Observable<Unit>
|
||||
val recordAudioAbort: Observable<Unit>
|
||||
val recordAudioAttach: Observable<Unit>
|
||||
val recordAudioPlayerPlayPause: Observable<QkMediaPlayer.PlayingState>
|
||||
val recordAudioPlayerConfigUI: Subject<QkMediaPlayer.PlayingState>
|
||||
val recordAudioPlayerVisible: Subject<Boolean>
|
||||
val recordAudioMsgRecordVisible: Subject<Boolean>
|
||||
val recordAudioRecord: Subject<MicInputCloudView.ViewState>
|
||||
val recordAudioChronometer: Subject<Boolean>
|
||||
|
||||
fun clearSelection()
|
||||
fun toggleSelectAll()
|
||||
@@ -77,6 +98,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
fun showMessageLinkAskDialog(uri: Uri)
|
||||
fun requestDefaultSms()
|
||||
fun requestStoragePermission()
|
||||
fun requestRecordAudioPermission()
|
||||
fun requestSmsPermission()
|
||||
fun showContacts(sharing: Boolean, chips: List<Recipient>)
|
||||
fun themeChanged()
|
||||
@@ -89,5 +111,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
fun scrollToMessage(id: Long)
|
||||
fun showQksmsPlusSnackbar(@StringRes message: Int)
|
||||
fun showDeleteDialog( messages: List<Long>)
|
||||
fun showClearCurrentMessageDialog()
|
||||
fun startSpeechRecognition()
|
||||
|
||||
}
|
||||
@@ -18,13 +18,20 @@
|
||||
*/
|
||||
package dev.octoshrimpy.quik.feature.compose
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.media.AudioAttributes
|
||||
import android.media.AudioDeviceInfo
|
||||
import android.net.Uri
|
||||
import android.os.Vibrator
|
||||
import android.provider.ContactsContract
|
||||
import android.telephony.SmsMessage
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.net.toFile
|
||||
import androidx.core.net.toUri
|
||||
import com.moez.QKSMS.common.QkMediaPlayer
|
||||
import com.moez.QKSMS.contentproviders.MmsPartProvider
|
||||
import com.moez.QKSMS.manager.MediaRecorderManager
|
||||
import com.moez.QKSMS.manager.BluetoothMicManager
|
||||
import dev.octoshrimpy.quik.R
|
||||
import dev.octoshrimpy.quik.common.Navigator
|
||||
import dev.octoshrimpy.quik.common.base.QkViewModel
|
||||
@@ -47,7 +54,6 @@ import dev.octoshrimpy.quik.manager.ActiveConversationManager
|
||||
import dev.octoshrimpy.quik.manager.BillingManager
|
||||
import dev.octoshrimpy.quik.manager.PermissionManager
|
||||
import dev.octoshrimpy.quik.model.Attachment
|
||||
import dev.octoshrimpy.quik.model.Attachments
|
||||
import dev.octoshrimpy.quik.model.Conversation
|
||||
import dev.octoshrimpy.quik.model.Message
|
||||
import dev.octoshrimpy.quik.model.Recipient
|
||||
@@ -60,7 +66,11 @@ 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.MicInputCloudView
|
||||
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
|
||||
@@ -71,6 +81,7 @@ import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
@@ -80,7 +91,7 @@ class ComposeViewModel @Inject constructor(
|
||||
@Named("threadId") private val threadId: Long,
|
||||
@Named("addresses") private val addresses: List<String>,
|
||||
@Named("text") private val sharedText: String,
|
||||
@Named("attachments") private val sharedAttachments: Attachments,
|
||||
@Named("attachments") private val sharedAttachments: List<Attachment>,
|
||||
@Named("mode") private val mode: String,
|
||||
private val contactRepo: ContactRepository,
|
||||
private val context: Context,
|
||||
@@ -99,14 +110,18 @@ 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,
|
||||
query = query)
|
||||
) {
|
||||
|
||||
private val attachments: Subject<List<Attachment>> = BehaviorSubject.createDefault(sharedAttachments)
|
||||
companion object {
|
||||
private const val AUDIO_FILE_PREFIX = "recorded-"
|
||||
}
|
||||
|
||||
private val chipsReducer: Subject<(List<Recipient>) -> List<Recipient>> = PublishSubject.create()
|
||||
private val conversation: Subject<Conversation> = BehaviorSubject.create()
|
||||
private val messages: Subject<List<Message>> = BehaviorSubject.create()
|
||||
@@ -116,7 +131,12 @@ class ComposeViewModel @Inject constructor(
|
||||
|
||||
private var shouldShowContacts = threadId == 0L && addresses.isEmpty()
|
||||
|
||||
private var bluetoothMicManager: BluetoothMicManager? = null
|
||||
|
||||
init {
|
||||
// set shared attachments into state, if any
|
||||
newState { copy(attachments = sharedAttachments) }
|
||||
|
||||
val initialConversation = threadId.takeIf { it != 0L }
|
||||
?.let(conversationRepo::getConversationAsync)
|
||||
?.asObservable()
|
||||
@@ -197,9 +217,6 @@ class ComposeViewModel @Inject constructor(
|
||||
.distinctUntilChanged()
|
||||
.subscribe { enabled -> newState { copy(sendAsGroup = enabled) } }
|
||||
|
||||
disposables += attachments
|
||||
.subscribe { attachments -> newState { copy(attachments = attachments) } }
|
||||
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.id }
|
||||
.distinctUntilChanged()
|
||||
@@ -251,10 +268,11 @@ class ComposeViewModel @Inject constructor(
|
||||
newState { copy(scheduling = true) }
|
||||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
override fun bindView(view: ComposeView) {
|
||||
super.bindView(view)
|
||||
|
||||
val sharing = sharedText.isNotEmpty() || sharedAttachments.isNotEmpty()
|
||||
val sharing = (sharedText.isNotEmpty() || sharedAttachments.isNotEmpty())
|
||||
if (shouldShowContacts) {
|
||||
shouldShowContacts = false
|
||||
view.showContacts(sharing, selectedChips.blockingFirst())
|
||||
@@ -370,23 +388,31 @@ class ComposeViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.showDetails(it) }
|
||||
|
||||
// Show the delete message dialog
|
||||
// Show the delete message dialog if one or more messages selected
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.delete }
|
||||
.filter { permissionManager.isDefaultSms().also { if (!it) view.requestDefaultSms() } }
|
||||
.withLatestFrom(view.messagesSelectedIntent, conversation) { _, messages, conversation ->
|
||||
view.showDeleteDialog(messages)
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
.filter { it == R.id.delete }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, selectedMessages -> selectedMessages }
|
||||
.filter { permissionManager.isDefaultSms().also { if (!it) view.requestDefaultSms() } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.showDeleteDialog(it) }
|
||||
|
||||
// show the clear current message dialog if no messages selected
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.delete }
|
||||
.withLatestFrom(state) { _, state -> state }
|
||||
.filter { it.selectedMessages == 0 }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.showClearCurrentMessageDialog() }
|
||||
|
||||
// Forward the message
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.forward }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, messages ->
|
||||
messages?.firstOrNull()?.let { messageRepo.getMessage(it) }?.let { message ->
|
||||
val attachments = message.parts.filter { !it.isSmil() }.mapNotNull { it.getUri() }
|
||||
navigator.showCompose(message.getText(), attachments)
|
||||
navigator.showCompose(
|
||||
message.getText(),
|
||||
message.parts.filter { !it.isSmil() }.mapNotNull { it.getUri() }
|
||||
)
|
||||
}
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
@@ -432,6 +458,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 +532,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 +568,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
|
||||
@@ -591,15 +672,16 @@ class ComposeViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.requestDatePicker() }
|
||||
|
||||
// a file, photo or otherwise, was picked by the user
|
||||
// an attachment was picked by the user
|
||||
Observable.merge(
|
||||
view.attachAnyFileSelectedIntent.map { uri -> Attachment(uri) },
|
||||
view.inputContentIntent.map { inputContent -> Attachment(inputContent = inputContent) }
|
||||
view.attachAnyFileSelectedIntent.map { uri -> Attachment(context, uri) },
|
||||
view.inputContentIntent.map { inputContent -> Attachment(context, inputContent = inputContent) }
|
||||
)
|
||||
.withLatestFrom(attachments) { attachment, attachments -> attachments + attachment }
|
||||
.doOnNext(attachments::onNext)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { copy(attaching = false) } }
|
||||
.subscribe {
|
||||
newState { copy(attachments = attachments + it, attaching = false) }
|
||||
}
|
||||
|
||||
// Set the scheduled time
|
||||
view.scheduleSelectedIntent
|
||||
.filter { scheduled ->
|
||||
@@ -618,20 +700,28 @@ class ComposeViewModel @Inject constructor(
|
||||
|
||||
// Contact was selected for attachment
|
||||
view.contactSelectedIntent
|
||||
.map { uri -> Attachment(getFullVCardUri(uri)) }
|
||||
.withLatestFrom(attachments) { attachment, attachments -> attachments + attachment }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe(attachments::onNext) { error ->
|
||||
.subscribe(
|
||||
{
|
||||
newState {
|
||||
copy(attachments = attachments + Attachment(context, uri = it))
|
||||
}
|
||||
}
|
||||
) { error ->
|
||||
context.makeToast(R.string.compose_contact_error)
|
||||
Timber.w(error)
|
||||
}
|
||||
|
||||
// Detach a photo
|
||||
// Detach an attachment
|
||||
view.attachmentDeletedIntent
|
||||
.withLatestFrom(attachments) { bitmap, attachments -> attachments.filter { it !== bitmap } }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { attachments.onNext(it) }
|
||||
.subscribe {
|
||||
newState { copy(attachments = attachments - it) }
|
||||
|
||||
// if the attachment is backed by a local file, delete the file
|
||||
it.removeCacheFile()
|
||||
}
|
||||
|
||||
conversation
|
||||
.map { conversation -> conversation.draft }
|
||||
@@ -650,14 +740,23 @@ class ComposeViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
// Enable the send button when there is text input into the new message body or there's
|
||||
// an attachment, disable otherwise
|
||||
Observables
|
||||
.combineLatest(view.textChangedIntent, attachments) { text, attachments ->
|
||||
text.isNotBlank() || attachments.isNotEmpty()
|
||||
// set canSend state depending on if there is text input, an attachment or a schedule set
|
||||
Observables.combineLatest(
|
||||
view.textChangedIntent, // input message text changed
|
||||
state
|
||||
.distinctUntilChanged { state -> state.attachments } // attachments changed
|
||||
.map { it.attachments.size }, // number of attachments
|
||||
state.distinctUntilChanged { state -> state.scheduled } // schedule set or not
|
||||
.map { it.scheduled }
|
||||
)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
newState {
|
||||
copy(
|
||||
canSend = (it.first.isNotBlank() || (it.second > 0)) || (it.third > 0)
|
||||
)
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { canSend -> newState { copy(canSend = canSend) } }
|
||||
}
|
||||
|
||||
// Show the remaining character counter when necessary
|
||||
view.textChangedIntent
|
||||
@@ -704,11 +803,188 @@ class ComposeViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// speech recognition button clicked
|
||||
view.speechRecogniserIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.startSpeechRecognition() }
|
||||
|
||||
// shade clicked
|
||||
view.shadeIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { copy(attaching = false) } }
|
||||
|
||||
// starting or stopping (change state) of audio message ui
|
||||
state
|
||||
.distinctUntilChanged { state -> state.audioMsgRecording }
|
||||
.skip(1) // skip initial value
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
// stop any audio playback (ie from mms attachment or audio recorder)
|
||||
QkMediaPlayer.reset()
|
||||
|
||||
// if leaving audio recording mode
|
||||
if (!it.audioMsgRecording) {
|
||||
// ensure recording stopped and delete any recording file
|
||||
safeDeleteLocalFile(MediaRecorderManager.stopRecording())
|
||||
view.recordAudioStartStopRecording.onNext(false)
|
||||
}
|
||||
}
|
||||
|
||||
// starting or stopping the recording of audio
|
||||
view.recordAudioStartStopRecording
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
// if start recording
|
||||
if (it == true) {
|
||||
view.recordAudioPlayerVisible.onNext(false) // hide audio player
|
||||
|
||||
// check have permissions to record audio
|
||||
if (permissionManager.hasRecordAudio().also {
|
||||
if (!it) view.requestRecordAudioPermission()
|
||||
}) {
|
||||
// create bluetooth mic device manager
|
||||
bluetoothMicManager?.close()
|
||||
bluetoothMicManager = BluetoothMicManager(
|
||||
context,
|
||||
object : BluetoothMicManager.Callbacks {
|
||||
override fun onNoDeviceFound() {
|
||||
// no bluetooth sco device found, use built-in mic
|
||||
this.onConnected(null)
|
||||
}
|
||||
override fun onDeviceFound(device: AudioDeviceInfo?) {
|
||||
// show bluetooth placeholder until bluetooth connected
|
||||
view.recordAudioMsgRecordVisible.onNext(false)
|
||||
}
|
||||
override fun onConnecting(device: AudioDeviceInfo?) { /* nothing */ }
|
||||
override fun onConnected(device: AudioDeviceInfo?) {
|
||||
// show record button and chronometer, hide bluetooth placeholder
|
||||
view.recordAudioMsgRecordVisible.onNext(true)
|
||||
view.recordAudioChronometer.onNext(true) // start chronometer
|
||||
MediaRecorderManager.startRecording(context, device)
|
||||
}
|
||||
override fun onDisconnected(device: AudioDeviceInfo?) {
|
||||
// if bluetooth disconnects, stop recording
|
||||
if (device != null) {
|
||||
view.recordAudioRecord.onNext(
|
||||
MicInputCloudView.ViewState.PAUSED_STATE
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
bluetoothMicManager?.startBluetoothDevice()
|
||||
}
|
||||
} else {
|
||||
// stop recording
|
||||
bluetoothMicManager?.close()
|
||||
view.recordAudioChronometer.onNext(false) // stop chronometer
|
||||
MediaRecorderManager.stopRecording()
|
||||
}
|
||||
}
|
||||
|
||||
// record an audio message menu item or main mic icon
|
||||
view.recordAnAudioMessage
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
view.recordAudioStartStopRecording.onNext(true) // start recording
|
||||
newState { copy( attaching = false, audioMsgRecording = true) }
|
||||
}
|
||||
|
||||
// abort recording audio message button
|
||||
view.recordAudioAbort
|
||||
.observeOn(Schedulers.io())
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { copy( audioMsgRecording = false) } }
|
||||
|
||||
// main record/stop recording audio message button
|
||||
view.recordAudioRecord
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
if (it == MicInputCloudView.ViewState.PAUSED_STATE) {
|
||||
view.recordAudioStartStopRecording.onNext(false) // stop recording
|
||||
view.recordAudioPlayerVisible.onNext(true) // show audio player
|
||||
} else { // state = start recording
|
||||
safeDeleteLocalFile(MediaRecorderManager.uri) // delete old recording file
|
||||
view.recordAudioStartStopRecording.onNext(true) // start new recording
|
||||
}
|
||||
}
|
||||
|
||||
// attach recorded audio message button
|
||||
view.recordAudioAttach
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
MediaRecorderManager.stopRecording()
|
||||
|
||||
try {
|
||||
// create new filename for recorded file (so cache clean doesn't accidentally
|
||||
// delete the attachment file)
|
||||
val newFile = File(
|
||||
context.cacheDir,
|
||||
"${AUDIO_FILE_PREFIX}${UUID.randomUUID()}${MediaRecorderManager.AUDIO_FILE_SUFFIX}"
|
||||
)
|
||||
|
||||
// rename recorded file to new name
|
||||
MediaRecorderManager.uri.toFile().renameTo(newFile)
|
||||
|
||||
// attach newly named file to message
|
||||
newState {
|
||||
copy(
|
||||
audioMsgRecording = false,
|
||||
attachments = attachments + Attachment(context, newFile.toUri())
|
||||
)
|
||||
}
|
||||
}
|
||||
catch (e: Exception) { /* nothing */ }
|
||||
}
|
||||
|
||||
// audio recording player play/pause button
|
||||
view.recordAudioPlayerPlayPause
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
when (it) {
|
||||
QkMediaPlayer.PlayingState.Paused ->
|
||||
view.recordAudioPlayerConfigUI.onNext(
|
||||
QkMediaPlayer.PlayingState.Playing
|
||||
)
|
||||
QkMediaPlayer.PlayingState.Playing ->
|
||||
view.recordAudioPlayerConfigUI.onNext(
|
||||
QkMediaPlayer.PlayingState.Paused
|
||||
)
|
||||
else -> {
|
||||
if (MediaRecorderManager.uri != Uri.EMPTY) {
|
||||
QkMediaPlayer.setOnPreparedListener {
|
||||
view.recordAudioPlayerConfigUI.onNext(
|
||||
QkMediaPlayer.PlayingState.Playing
|
||||
)
|
||||
}
|
||||
QkMediaPlayer.setOnCompletionListener {
|
||||
view.recordAudioPlayerConfigUI.onNext(
|
||||
QkMediaPlayer.PlayingState.Stopped
|
||||
)
|
||||
}
|
||||
|
||||
// start the media player play sequence
|
||||
QkMediaPlayer.setAudioAttributes(
|
||||
AudioAttributes.Builder()
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
|
||||
.setUsage(AudioAttributes.USAGE_MEDIA)
|
||||
.build()
|
||||
)
|
||||
|
||||
QkMediaPlayer.reset()
|
||||
|
||||
QkMediaPlayer.setDataSource(context, MediaRecorderManager.uri)
|
||||
|
||||
QkMediaPlayer.prepareAsync()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send a message when the send button is clicked, and disable editing mode if it's enabled
|
||||
view.sendIntent
|
||||
.withLatestFrom(view.textChangedIntent) { _, body -> body.toString() }
|
||||
.withLatestFrom(state, attachments, conversation, selectedChips) { body, state, attachments,
|
||||
conversation, chips ->
|
||||
.withLatestFrom(state, conversation, selectedChips) { body, state, conversation, chips ->
|
||||
if (!permissionManager.isDefaultSms()) {
|
||||
view.requestDefaultSms()
|
||||
return@withLatestFrom
|
||||
@@ -742,9 +1018,7 @@ class ComposeViewModel @Inject constructor(
|
||||
// Scheduling a message
|
||||
state.scheduled != 0L -> {
|
||||
newState { copy(scheduled = 0) }
|
||||
val uris = attachments
|
||||
.map { it.getUri() }
|
||||
.map { it.toString() }
|
||||
val uris = state.attachments.map { it.uri.toString() }
|
||||
val params = AddScheduledMessage
|
||||
.Params(state.scheduled, subId, addresses, sendAsGroup, body, uris)
|
||||
addScheduledMessage.execute(params)
|
||||
@@ -754,19 +1028,19 @@ class ComposeViewModel @Inject constructor(
|
||||
// Sending a group message
|
||||
sendAsGroup -> {
|
||||
sendMessage.execute(SendMessage
|
||||
.Params(subId, conversation.id, addresses, body, attachments, delay))
|
||||
.Params(subId, conversation.id, addresses, body, state.attachments, delay))
|
||||
}
|
||||
|
||||
// Sending a message to an existing conversation with one recipient
|
||||
conversation.recipients.size == 1 -> {
|
||||
val address = conversation.recipients.map { it.address }
|
||||
sendMessage.execute(SendMessage.Params(subId, threadId, address, body, attachments, delay))
|
||||
sendMessage.execute(SendMessage.Params(subId, threadId, address, body, state.attachments, delay))
|
||||
}
|
||||
|
||||
// Create a new conversation with one address
|
||||
addresses.size == 1 -> {
|
||||
sendMessage.execute(SendMessage
|
||||
.Params(subId, threadId, addresses, body, attachments, delay))
|
||||
.Params(subId, threadId, addresses, body, state.attachments, delay))
|
||||
}
|
||||
|
||||
// Send a message to multiple addresses
|
||||
@@ -778,17 +1052,13 @@ class ComposeViewModel @Inject constructor(
|
||||
val address = listOf(conversationRepo
|
||||
.getConversation(threadId)?.recipients?.firstOrNull()?.address ?: addr)
|
||||
sendMessage.execute(SendMessage
|
||||
.Params(subId, threadId, address, body, attachments, delay))
|
||||
.Params(subId, threadId, address, body, state.attachments, delay))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
view.setDraft("")
|
||||
this.attachments.onNext(ArrayList())
|
||||
|
||||
if (state.editingMode) {
|
||||
newState { copy(editingMode = false, hasError = !sendAsGroup) }
|
||||
}
|
||||
// clear the current message ready for new message composition
|
||||
view.clearCurrentMessageIntent.onNext(Unit)
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
@@ -820,19 +1090,50 @@ class ComposeViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.clearSelection() }
|
||||
|
||||
view.confirmClearCurrentMessageIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.clearCurrentMessageIntent.onNext(Unit) }
|
||||
|
||||
// clear the current message schedule, text and attachments
|
||||
view.clearCurrentMessageIntent
|
||||
.withLatestFrom(state) { _, state -> state }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
view.setDraft("")
|
||||
// if choosing contacts, don't remove attachments. they may have come from an
|
||||
// external share
|
||||
newState {
|
||||
copy(
|
||||
editingMode = false,
|
||||
hasError = !sendAsGroup,
|
||||
attachments = listOf(),
|
||||
scheduled = 0,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// when activity changes visibility, delete old recording cache files in background thread
|
||||
// generally there won't be any, but under some circumstances some can be left behind
|
||||
view.activityVisibleIntent
|
||||
.subscribeOn(Schedulers.io())
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
context.cacheDir.listFiles()?.forEach {
|
||||
if (it.isFile &&
|
||||
it.name.startsWith(AUDIO_FILE_PREFIX) &&
|
||||
it.name.endsWith(MediaRecorderManager.AUDIO_FILE_SUFFIX))
|
||||
safeDeleteLocalFile(it.toUri())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFullVCardUri(contactData: Uri): Uri {
|
||||
val lookupKey = context.contentResolver.query(contactData, null, null, null, null)?.use {
|
||||
it.moveToFirst()
|
||||
val index = it.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)
|
||||
if (index >= 0)
|
||||
it.getString(index)
|
||||
else
|
||||
""
|
||||
private fun safeDeleteLocalFile(uri: Uri): Boolean {
|
||||
return try {
|
||||
if (uri == Uri.EMPTY)
|
||||
false
|
||||
uri.toFile().delete()
|
||||
}
|
||||
|
||||
return Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey)
|
||||
catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
@@ -131,17 +132,6 @@ class MessagesAdapter @Inject constructor(
|
||||
private val conversation: Conversation?
|
||||
get() = data?.first?.takeIf { it.isValid }
|
||||
|
||||
/**
|
||||
* Mark this message as highlighted
|
||||
*/
|
||||
var highlight: Long = -1L
|
||||
set(value) {
|
||||
if (field == value) return
|
||||
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private val contactCache = ContactCache()
|
||||
private val expanded = HashMap<Long, Boolean>()
|
||||
private val subs = subscriptionManager.activeSubscriptionInfoList
|
||||
@@ -150,11 +140,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 +151,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 +167,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,6 +191,11 @@ 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
|
||||
|
||||
@@ -215,7 +204,7 @@ class MessagesAdapter @Inject constructor(
|
||||
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.clicks().subscribe { cancelSendingClicks.onNext(message.id) }
|
||||
cancelFrame.cancel.progress = 2
|
||||
|
||||
if (isCancellable) {
|
||||
@@ -235,16 +224,30 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
// Bind the send now icon view
|
||||
// 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) }
|
||||
if (message.isSending() && message.date > System.currentTimeMillis()) {
|
||||
sendNowIcon.visibility = View.VISIBLE
|
||||
sendNowIcon.clicks().subscribe { sendNowClicks.onNext(message.id) }
|
||||
} else
|
||||
sendNowIcon.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
val cancelableSimpleOnGestureListener = holder.body.forwardTouches(holder.containerView)
|
||||
// bind the resend icon view
|
||||
if (holder.resendIcon != null) {
|
||||
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 message status
|
||||
bindStatus(holder, message, next)
|
||||
@@ -325,9 +328,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 +351,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 +365,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 +376,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
|
||||
})
|
||||
@@ -397,30 +394,6 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleSelectAll() {
|
||||
var needToSelectAll = false
|
||||
|
||||
// if a non-selected item is found, then we need to select all, otherwise deselect all
|
||||
for (position in 0 until itemCount)
|
||||
if (!isSelected(getItemId(position))) {
|
||||
needToSelectAll = true
|
||||
break
|
||||
}
|
||||
|
||||
// select or deselect item based on if toggling all selected of deselected
|
||||
for (position in 0 until itemCount) {
|
||||
val messageId = getItemId(position)
|
||||
// if deselecting all then toggle selection (we know all items are selected)
|
||||
if (!needToSelectAll)
|
||||
toggleSelection(messageId)
|
||||
// else, selecting all, toggle if not already selected
|
||||
else if (!isSelected(messageId))
|
||||
toggleSelection(messageId)
|
||||
}
|
||||
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun expandMessages(messageIds: List<Long>, expand: Boolean) {
|
||||
messageIds.forEach { messageId -> expanded[messageId] = expand }
|
||||
notifyDataSetChanged()
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import dev.octoshrimpy.quik.common.util.extensions.setBackgroundTint
|
||||
import dev.octoshrimpy.quik.common.util.extensions.setTint
|
||||
import dev.octoshrimpy.quik.common.widget.BubbleImageView
|
||||
import dev.octoshrimpy.quik.extensions.isAudio
|
||||
import dev.octoshrimpy.quik.extensions.resourceExists
|
||||
import dev.octoshrimpy.quik.feature.compose.MessagesAdapter
|
||||
import dev.octoshrimpy.quik.model.Message
|
||||
import dev.octoshrimpy.quik.model.MmsPart
|
||||
@@ -107,6 +108,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) {
|
||||
@@ -131,60 +135,54 @@ class AudioBinder @Inject constructor(colors: Colors, private val context: Conte
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
QkMediaPlayer.reset() // make sure reset before trying to (re-)use
|
||||
if (part.getUri().resourceExists(context)) {
|
||||
QkMediaPlayer.reset() // make sure reset before trying to (re-)use
|
||||
|
||||
QkMediaPlayer.setOnPreparedListener {
|
||||
// start media playing
|
||||
QkMediaPlayer.start()
|
||||
QkMediaPlayer.setOnPreparedListener {
|
||||
// start media playing
|
||||
QkMediaPlayer.start()
|
||||
|
||||
uiToPlaying(holder)
|
||||
uiToPlaying(holder)
|
||||
|
||||
// set current view holder and part as active
|
||||
audioState.apply {
|
||||
audioState.state = QkMediaPlayer.PlayingState.Playing
|
||||
partId = part.id
|
||||
viewHolder = holder
|
||||
// set current view holder and part as active
|
||||
audioState.apply {
|
||||
audioState.state = QkMediaPlayer.PlayingState.Playing
|
||||
partId = part.id
|
||||
viewHolder = holder
|
||||
}
|
||||
|
||||
// start progress bar update timer
|
||||
startSeekBarUpdateTimer()
|
||||
}
|
||||
|
||||
// start progress bar update timer
|
||||
startSeekBarUpdateTimer()
|
||||
}
|
||||
QkMediaPlayer.setOnCompletionListener { // also called on error because we don't have an onerrorlistener
|
||||
audioState.apply {
|
||||
// if this part is currently active, set it to stopped and inactive
|
||||
if ((partId == part.id) && (viewHolder != null))
|
||||
uiToStopped(viewHolder!!)
|
||||
|
||||
QkMediaPlayer.setOnCompletionListener { // also called on error because we don't have an onerrorlistener
|
||||
audioState.apply {
|
||||
// if this part is currently active, set it to stopped and inactive
|
||||
if ((partId == part.id) && (viewHolder != null))
|
||||
uiToStopped(viewHolder!!)
|
||||
|
||||
state = QkMediaPlayer.PlayingState.Stopped
|
||||
partId = -1
|
||||
viewHolder = null
|
||||
state = QkMediaPlayer.PlayingState.Stopped
|
||||
partId = -1
|
||||
viewHolder = null
|
||||
}
|
||||
}
|
||||
|
||||
// start the media player play sequence
|
||||
QkMediaPlayer.setAudioAttributes(
|
||||
AudioAttributes.Builder()
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) // music, maybe?? could be voice. don't want to use CONTENT_TYPE_UNKNOWN though
|
||||
.setUsage(AudioAttributes.USAGE_MEDIA)
|
||||
.build()
|
||||
)
|
||||
|
||||
QkMediaPlayer.setDataSource(context, part.getUri())
|
||||
|
||||
QkMediaPlayer.prepareAsync()
|
||||
}
|
||||
|
||||
// start the media player play sequence
|
||||
QkMediaPlayer.setAudioAttributes(
|
||||
AudioAttributes.Builder()
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) // music, maybe?? could be voice. don't want to use CONTENT_TYPE_UNKNOWN though
|
||||
.setUsage(AudioAttributes.USAGE_MEDIA)
|
||||
.build()
|
||||
)
|
||||
|
||||
QkMediaPlayer.setDataSource(context, part.getUri())
|
||||
|
||||
QkMediaPlayer.prepareAsync()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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,12 +236,9 @@ 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())
|
||||
if (part.getUri().resourceExists(context))
|
||||
it.setDataSource(context, part.getUri())
|
||||
|
||||
// metadata title
|
||||
holder.metadataTitle.apply {
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user