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:
@@ -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) {
|
||||
|
||||
@@ -52,13 +52,28 @@ abstract class QkRealmAdapter<T : RealmModel> : RealmRecyclerViewAdapter<T, QkVi
|
||||
|
||||
private var selection = listOf<Long>()
|
||||
|
||||
/**
|
||||
* Mark this message as highlighted
|
||||
*/
|
||||
var highlight: Long = -1L
|
||||
set(value) {
|
||||
if (field == value) return
|
||||
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the selected state for a particular view
|
||||
*
|
||||
* If we are currently in selection mode (we have an active selection), then the state will
|
||||
* toggle. If we are not in selection mode, then we will only toggle if [force]
|
||||
*/
|
||||
protected fun toggleSelection(id: Long, force: Boolean = true): Boolean {
|
||||
protected fun toggleSelection(
|
||||
id: Long,
|
||||
force: Boolean = true,
|
||||
useChangeEvent: Boolean = true
|
||||
): Boolean {
|
||||
if (!force && selection.isEmpty()) return false
|
||||
|
||||
selection = when (selection.contains(id)) {
|
||||
@@ -66,7 +81,8 @@ abstract class QkRealmAdapter<T : RealmModel> : RealmRecyclerViewAdapter<T, QkVi
|
||||
false -> selection + id
|
||||
}
|
||||
|
||||
selectionChanges.onNext(selection)
|
||||
if (useChangeEvent)
|
||||
selectionChanges.onNext(selection)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -80,6 +96,33 @@ abstract class QkRealmAdapter<T : RealmModel> : RealmRecyclerViewAdapter<T, QkVi
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
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, useChangeEvent = false)
|
||||
// else, selecting all, toggle if not already selected
|
||||
else if (!isSelected(messageId))
|
||||
toggleSelection(messageId, useChangeEvent = false)
|
||||
}
|
||||
|
||||
// fire a single change event now
|
||||
selectionChanges.onNext(selection)
|
||||
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getItem(index: Int): T? {
|
||||
if (index < 0) {
|
||||
Timber.w("Only indexes >= 0 are allowed. Input was: $index")
|
||||
|
||||
@@ -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,404 @@
|
||||
/*
|
||||
* Copyright (C) - see below
|
||||
*
|
||||
* This file is part of QUIK.
|
||||
*
|
||||
* QUIK is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QUIK is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QUIK. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*
|
||||
* Original from: Nextcloud Talk - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2023 Julius Linus <julius.linus@nextcloud.com>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package dev.octoshrimpy.quik.common.widget
|
||||
|
||||
import android.animation.ValueAnimator
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Paint.ANTI_ALIAS_FLAG
|
||||
import android.graphics.Path
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.animation.LinearInterpolator
|
||||
import androidx.annotation.ColorInt
|
||||
import dev.octoshrimpy.quik.R
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class MicInputCloudView(context: Context, attrs: AttributeSet) : View(context, attrs) {
|
||||
/**
|
||||
* State Descriptions:
|
||||
* - PAUSED_STATE: Animation speed is set to zero.
|
||||
* - PLAY_STATE: Animation speed is set to default, but can be overridden.
|
||||
*/
|
||||
enum class ViewState {
|
||||
/**
|
||||
* Animation speed is set to zero.
|
||||
*/
|
||||
PAUSED_STATE,
|
||||
|
||||
/**
|
||||
* Animation speed is set to default, but can be overridden.
|
||||
*/
|
||||
PLAY_STATE
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
private var primaryColor: Int = Color.WHITE
|
||||
|
||||
private var pauseIcon: Drawable? = null
|
||||
|
||||
private var playIcon: Drawable? = null
|
||||
|
||||
init {
|
||||
context.theme.obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.MicInputCloudView,
|
||||
0,
|
||||
0
|
||||
).apply {
|
||||
|
||||
try {
|
||||
pauseIcon = getDrawable(R.styleable.MicInputCloudView_pauseIcon)
|
||||
playIcon = getDrawable(R.styleable.MicInputCloudView_playIcon)
|
||||
} finally {
|
||||
recycle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var state: ViewState = ViewState.PLAY_STATE
|
||||
private var ovalOneAnimator: ValueAnimator? = null
|
||||
private var ovalTwoAnimator: ValueAnimator? = null
|
||||
private var ovalThreeAnimator: ValueAnimator? = null
|
||||
private var r1 = OVAL_ONE_DEFAULT_ROTATION
|
||||
private var r2 = OVAL_TWO_DEFAULT_ROTATION
|
||||
private var r3 = OVAL_THREE_DEFAULT_ROTATION
|
||||
private var o1h = OVAL_ONE_DEFAULT_HEIGHT
|
||||
private var o1w = OVAL_ONE_DEFAULT_WIDTH
|
||||
private var o2h = OVAL_TWO_DEFAULT_HEIGHT
|
||||
private var o2w = OVAL_TWO_DEFAULT_WIDTH
|
||||
private var o3h = OVAL_THREE_DEFAULT_HEIGHT
|
||||
private var o3w = OVAL_THREE_DEFAULT_WIDTH
|
||||
private var rotationSpeedMultiplier: Float = DEFAULT_ROTATION_SPEED_MULTIPLIER
|
||||
private var radius: Float = DEFAULT_RADIUS
|
||||
private var centerX: Float = 0f
|
||||
private var centerY: Float = 0f
|
||||
|
||||
private val bottomCirclePaint = Paint(ANTI_ALIAS_FLAG).apply {
|
||||
color = primaryColor
|
||||
style = Paint.Style.FILL
|
||||
alpha = DEFAULT_OPACITY
|
||||
}
|
||||
|
||||
private val topCircleBounds = Rect(0, 0, 0, 0)
|
||||
private val iconBounds = topCircleBounds
|
||||
|
||||
override fun onVisibilityChanged(changedView: View, visibility: Int) {
|
||||
super.onVisibilityChanged(changedView, visibility)
|
||||
if (visibility == VISIBLE) {
|
||||
createAnimators()
|
||||
} else {
|
||||
state = ViewState.PLAY_STATE
|
||||
destroyAnimators()
|
||||
}
|
||||
}
|
||||
|
||||
private fun createAnimators() {
|
||||
ovalOneAnimator = ValueAnimator.ofInt(
|
||||
o1h,
|
||||
OVAL_ONE_DEFAULT_HEIGHT + ANIMATION_CAP,
|
||||
o1h
|
||||
).apply {
|
||||
duration = OVAL_ONE_ANIMATION_LENGTH
|
||||
interpolator = LinearInterpolator()
|
||||
repeatCount = ValueAnimator.INFINITE
|
||||
addUpdateListener { valueAnimator ->
|
||||
o1h = valueAnimator.animatedValue as Int
|
||||
}
|
||||
}
|
||||
|
||||
ovalTwoAnimator = ValueAnimator.ofInt(
|
||||
o2h,
|
||||
OVAL_TWO_DEFAULT_HEIGHT + ANIMATION_CAP,
|
||||
o2h
|
||||
).apply {
|
||||
duration = OVAL_TWO_ANIMATION_LENGTH
|
||||
interpolator = LinearInterpolator()
|
||||
repeatCount = ValueAnimator.INFINITE
|
||||
addUpdateListener { valueAnimator ->
|
||||
o2h = valueAnimator.animatedValue as Int
|
||||
}
|
||||
}
|
||||
|
||||
ovalThreeAnimator = ValueAnimator.ofInt(
|
||||
o3h,
|
||||
OVAL_THREE_DEFAULT_HEIGHT + ANIMATION_CAP,
|
||||
o3h
|
||||
).apply {
|
||||
duration = OVAL_THREE_ANIMATION_LENGTH
|
||||
interpolator = LinearInterpolator()
|
||||
repeatCount = ValueAnimator.INFINITE
|
||||
addUpdateListener { valueAnimator ->
|
||||
o3h = valueAnimator.animatedValue as Int
|
||||
invalidate() // needed to animate the other listeners as well
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun destroyAnimators() {
|
||||
ovalOneAnimator?.cancel()
|
||||
ovalOneAnimator?.removeAllUpdateListeners()
|
||||
ovalTwoAnimator?.cancel()
|
||||
ovalTwoAnimator?.removeAllUpdateListeners()
|
||||
ovalThreeAnimator?.cancel()
|
||||
ovalThreeAnimator?.removeAllUpdateListeners()
|
||||
}
|
||||
|
||||
private val circlePath: Path = Path()
|
||||
private val ovalOnePath: Path = Path()
|
||||
private val ovalTwoPath: Path = Path()
|
||||
private val ovalThreePath: Path = Path()
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
super.onDraw(canvas)
|
||||
circlePath.apply {
|
||||
addCircle(centerX, centerY, DEFAULT_RADIUS, Path.Direction.CCW)
|
||||
}
|
||||
ovalOnePath.apply {
|
||||
addOval(
|
||||
centerX - (radius + o1w),
|
||||
centerY - o1h,
|
||||
centerX + (radius + o1w),
|
||||
centerY + o1h,
|
||||
Path.Direction.CCW
|
||||
)
|
||||
op(this, circlePath, Path.Op.DIFFERENCE)
|
||||
}
|
||||
ovalTwoPath.apply {
|
||||
addOval(
|
||||
centerX - (radius + o2w),
|
||||
centerY - o2h,
|
||||
centerX + (radius + o2w),
|
||||
centerY + o2h,
|
||||
Path.Direction.CCW
|
||||
)
|
||||
op(this, circlePath, Path.Op.DIFFERENCE)
|
||||
}
|
||||
ovalThreePath.apply {
|
||||
addOval(
|
||||
centerX - (radius + o3w),
|
||||
centerY - o3h,
|
||||
centerX + (radius + o3w),
|
||||
centerY + o3h,
|
||||
Path.Direction.CCW
|
||||
)
|
||||
op(this, circlePath, Path.Op.DIFFERENCE)
|
||||
}
|
||||
drawMicInputCloud(canvas)
|
||||
if (state == ViewState.PLAY_STATE) {
|
||||
r1 += OVAL_ONE_ANIMATION_SPEED * rotationSpeedMultiplier
|
||||
r2 -= OVAL_TWO_ANIMATION_SPEED * rotationSpeedMultiplier
|
||||
r3 += OVAL_THREE_ANIMATION_SPEED * rotationSpeedMultiplier
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawMicInputCloud(canvas: Canvas?) {
|
||||
canvas?.apply {
|
||||
save()
|
||||
rotate(r1, centerX, centerY)
|
||||
drawPath(ovalOnePath, bottomCirclePaint)
|
||||
restore()
|
||||
save()
|
||||
rotate(r2, centerX, centerY)
|
||||
drawPath(ovalTwoPath, bottomCirclePaint)
|
||||
restore()
|
||||
save()
|
||||
rotate(r3, centerX, centerY)
|
||||
drawPath(ovalThreePath, bottomCirclePaint)
|
||||
restore()
|
||||
circlePath.reset()
|
||||
ovalOnePath.reset()
|
||||
ovalTwoPath.reset()
|
||||
ovalThreePath.reset()
|
||||
if (state == ViewState.PLAY_STATE) {
|
||||
pauseIcon?.apply {
|
||||
bounds = topCircleBounds
|
||||
setTint(primaryColor)
|
||||
draw(canvas)
|
||||
}
|
||||
} else {
|
||||
playIcon?.apply {
|
||||
bounds = topCircleBounds
|
||||
setTint(primaryColor)
|
||||
draw(canvas)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
val desiredWidth = DEFAULT_SIZE.dp
|
||||
val desiredHeight = DEFAULT_SIZE.dp
|
||||
|
||||
val widthMode = MeasureSpec.getMode(widthMeasureSpec)
|
||||
val widthSize = MeasureSpec.getSize(widthMeasureSpec)
|
||||
val heightMode = MeasureSpec.getMode(heightMeasureSpec)
|
||||
val heightSize = MeasureSpec.getSize(heightMeasureSpec)
|
||||
|
||||
val width: Int = when (widthMode) {
|
||||
MeasureSpec.EXACTLY -> {
|
||||
widthSize
|
||||
}
|
||||
|
||||
MeasureSpec.AT_MOST -> {
|
||||
desiredWidth.coerceAtMost(widthSize)
|
||||
}
|
||||
|
||||
else -> {
|
||||
desiredWidth
|
||||
}
|
||||
}
|
||||
|
||||
val height: Int = when (heightMode) {
|
||||
MeasureSpec.EXACTLY -> {
|
||||
heightSize
|
||||
}
|
||||
|
||||
MeasureSpec.AT_MOST -> {
|
||||
desiredHeight.coerceAtMost(heightSize)
|
||||
}
|
||||
|
||||
else -> {
|
||||
desiredHeight
|
||||
}
|
||||
}
|
||||
|
||||
centerX = (width / 2).toFloat()
|
||||
centerY = (height / 2).toFloat()
|
||||
topCircleBounds.apply {
|
||||
left = (centerX - DEFAULT_RADIUS).toInt()
|
||||
top = (centerY - DEFAULT_RADIUS).toInt()
|
||||
right = (centerX + DEFAULT_RADIUS).toInt()
|
||||
bottom = (centerY + DEFAULT_RADIUS).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Drawables are drawn the same way as the canvas is drawn, as both originate from the top-left corner.
|
||||
* Because of this, the icon's width = (right - left) and height = (bottom - top).
|
||||
*/
|
||||
iconBounds.apply {
|
||||
left = (centerX - DEFAULT_RADIUS + ICON_SIZE.dp).toInt()
|
||||
top = (centerY - DEFAULT_RADIUS + ICON_SIZE.dp).toInt()
|
||||
right = (centerX + DEFAULT_RADIUS - ICON_SIZE.dp).toInt()
|
||||
bottom = (centerY + DEFAULT_RADIUS - ICON_SIZE.dp).toInt()
|
||||
}
|
||||
|
||||
setMeasuredDimension(width, height)
|
||||
}
|
||||
|
||||
override fun performClick(): Boolean {
|
||||
state = if (state == ViewState.PAUSED_STATE) {
|
||||
ovalOneAnimator?.resume()
|
||||
ovalTwoAnimator?.resume()
|
||||
ovalThreeAnimator?.resume()
|
||||
ViewState.PLAY_STATE
|
||||
} else {
|
||||
ovalOneAnimator?.pause()
|
||||
ovalTwoAnimator?.pause()
|
||||
ovalThreeAnimator?.pause()
|
||||
ViewState.PAUSED_STATE
|
||||
}
|
||||
invalidate()
|
||||
return super.performClick()
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the cloud to the parameter, opacity is still set to 50%.
|
||||
*/
|
||||
fun setColor(primary: Int) {
|
||||
primaryColor = primary
|
||||
bottomCirclePaint.apply {
|
||||
color = primary
|
||||
style = Paint.Style.FILL
|
||||
alpha = DEFAULT_OPACITY
|
||||
}
|
||||
invalidate()
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets state of the component to the parameter, must be of type MicInputCloud.ViewState.
|
||||
*/
|
||||
fun setState(s: ViewState) {
|
||||
state = s
|
||||
invalidate()
|
||||
}
|
||||
|
||||
fun getState() : ViewState {
|
||||
return state
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rotation speed and radius to the parameters, defaults are left unchanged.
|
||||
*/
|
||||
fun setRotationSpeed(speed: Float, r: Float) {
|
||||
rotationSpeedMultiplier = speed
|
||||
radius = r
|
||||
invalidate()
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the growing and shrinking animation
|
||||
*/
|
||||
fun startAnimators() {
|
||||
ovalOneAnimator?.start()
|
||||
ovalTwoAnimator?.start()
|
||||
ovalThreeAnimator?.start()
|
||||
}
|
||||
|
||||
companion object {
|
||||
val TAG: String? = MicInputCloudView::class.simpleName
|
||||
const val DEFAULT_RADIUS: Float = 70f
|
||||
const val EXTENDED_RADIUS: Float = 75f
|
||||
const val MAXIMUM_RADIUS: Float = 80f
|
||||
const val ICON_SIZE: Int = 9 // Converted to dp this equals about 24dp
|
||||
private const val DEFAULT_SIZE: Int = 110
|
||||
private const val DEFAULT_OPACITY: Int = 108
|
||||
private const val DEFAULT_ROTATION_SPEED_MULTIPLIER: Float = 0.5f
|
||||
private const val OVAL_ONE_DEFAULT_ROTATION: Float = 105f
|
||||
private const val OVAL_ONE_DEFAULT_HEIGHT: Int = 85
|
||||
private const val OVAL_ONE_DEFAULT_WIDTH: Int = 30
|
||||
private const val OVAL_ONE_ANIMATION_LENGTH: Long = 2000
|
||||
private const val OVAL_ONE_ANIMATION_SPEED: Float = 2.3f
|
||||
private const val OVAL_TWO_DEFAULT_ROTATION: Float = 138f
|
||||
private const val OVAL_TWO_DEFAULT_HEIGHT: Int = 70
|
||||
private const val OVAL_TWO_DEFAULT_WIDTH: Int = 25
|
||||
private const val OVAL_TWO_ANIMATION_LENGTH: Long = 1000
|
||||
private const val OVAL_TWO_ANIMATION_SPEED: Float = 1.75f
|
||||
private const val OVAL_THREE_DEFAULT_ROTATION: Float = 63f
|
||||
private const val OVAL_THREE_DEFAULT_HEIGHT: Int = 80
|
||||
private const val OVAL_THREE_DEFAULT_WIDTH: Int = 40
|
||||
private const val OVAL_THREE_ANIMATION_LENGTH: Long = 1500
|
||||
private const val OVAL_THREE_ANIMATION_SPEED: Float = 1f
|
||||
private const val ANIMATION_CAP: Int = 15
|
||||
private val Int.dp: Int
|
||||
get() = (this * Resources.getSystem().displayMetrics.density).roundToInt()
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
+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()
|
||||
|
||||
-23
@@ -131,27 +131,4 @@ class ConversationsAdapter @Inject constructor(
|
||||
return if (getItem(position)?.unread == false) 0 else 1
|
||||
}
|
||||
|
||||
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 threadId = getItemId(position)
|
||||
// if deselecting all then toggle selection (we know all items are selected)
|
||||
if (!needToSelectAll)
|
||||
toggleSelection(threadId)
|
||||
// else, selecting all, toggle if not already selected
|
||||
else if (!isSelected(threadId))
|
||||
toggleSelection(threadId)
|
||||
}
|
||||
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 }
|
||||
|
||||
|
||||
@@ -20,33 +20,36 @@ package dev.octoshrimpy.quik.feature.scheduled
|
||||
|
||||
import android.graphics.Typeface
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import dev.octoshrimpy.quik.R
|
||||
import dev.octoshrimpy.quik.common.QkDialog
|
||||
import dev.octoshrimpy.quik.common.base.QkThemedActivity
|
||||
import dev.octoshrimpy.quik.common.util.FontProvider
|
||||
import dev.octoshrimpy.quik.common.util.extensions.setBackgroundTint
|
||||
import dev.octoshrimpy.quik.common.util.extensions.setTint
|
||||
import dagger.android.AndroidInjection
|
||||
import kotlinx.android.synthetic.main.collapsing_toolbar.*
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.main_activity.toolbar
|
||||
import kotlinx.android.synthetic.main.scheduled_activity.*
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
class ScheduledActivity : QkThemedActivity(), ScheduledView {
|
||||
|
||||
@Inject lateinit var dialog: QkDialog
|
||||
@Inject lateinit var fontProvider: FontProvider
|
||||
@Inject lateinit var messageAdapter: ScheduledMessageAdapter
|
||||
@Inject lateinit var scheduledMessageAdapter: ScheduledMessageAdapter
|
||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
||||
override val messageClickIntent by lazy { messageAdapter.clicks }
|
||||
override val messageMenuIntent by lazy { dialog.adapter.menuItemClicks }
|
||||
override val composeIntent by lazy { compose.clicks() }
|
||||
override val upgradeIntent by lazy { upgrade.clicks() }
|
||||
override val messagesSelectedIntent by lazy { scheduledMessageAdapter.selectionChanges }
|
||||
override val optionsItemIntent: Subject<Int> = PublishSubject.create()
|
||||
override val deleteScheduledMessages: Subject<List<Long>> = PublishSubject.create()
|
||||
override val sendScheduledMessages: Subject<List<Long>> = PublishSubject.create()
|
||||
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ScheduledViewModel::class.java] }
|
||||
|
||||
@@ -58,19 +61,8 @@ class ScheduledActivity : QkThemedActivity(), ScheduledView {
|
||||
showBackButton(true)
|
||||
viewModel.bindView(this)
|
||||
|
||||
if (!prefs.systemFont.get()) {
|
||||
fontProvider.getLato { lato ->
|
||||
val typeface = Typeface.create(lato, Typeface.BOLD)
|
||||
collapsingToolbar.setCollapsedTitleTypeface(typeface)
|
||||
collapsingToolbar.setExpandedTitleTypeface(typeface)
|
||||
}
|
||||
}
|
||||
|
||||
dialog.title = getString(R.string.scheduled_options_title)
|
||||
dialog.adapter.setData(R.array.scheduled_options)
|
||||
|
||||
messageAdapter.emptyView = empty
|
||||
messages.adapter = messageAdapter
|
||||
scheduledMessageAdapter.emptyView = empty
|
||||
messages.adapter = scheduledMessageAdapter
|
||||
|
||||
colors.theme().let { theme ->
|
||||
sampleMessage.setBackgroundTint(theme.theme)
|
||||
@@ -84,14 +76,65 @@ class ScheduledActivity : QkThemedActivity(), ScheduledView {
|
||||
}
|
||||
|
||||
override fun render(state: ScheduledState) {
|
||||
messageAdapter.updateData(state.scheduledMessages)
|
||||
scheduledMessageAdapter.updateData(state.scheduledMessages)
|
||||
|
||||
setTitle(when {
|
||||
(state.selectedMessages > 0) ->
|
||||
getString(R.string.compose_title_selected, state.selectedMessages)
|
||||
else -> getString(R.string.scheduled_title)
|
||||
})
|
||||
|
||||
// show/hide menu items
|
||||
toolbar.menu.findItem(R.id.delete)?.isVisible =
|
||||
((scheduledMessageAdapter.itemCount != 0) && (state.selectedMessages != 0))
|
||||
toolbar.menu.findItem(R.id.select_all)?.isVisible =
|
||||
((scheduledMessageAdapter.itemCount > 1) && (state.selectedMessages != 0))
|
||||
toolbar.menu.findItem(R.id.copy)?.isVisible = (state.selectedMessages != 0)
|
||||
toolbar.menu.findItem(R.id.send_now)?.isVisible = (state.selectedMessages != 0)
|
||||
|
||||
// show compose button
|
||||
compose.isVisible = state.upgraded
|
||||
upgrade.isVisible = !state.upgraded
|
||||
}
|
||||
|
||||
override fun showMessageOptions() {
|
||||
dialog.show(this)
|
||||
override fun onBackPressed() = backPressedIntent.onNext(Unit)
|
||||
|
||||
override fun clearSelection() = scheduledMessageAdapter.clearSelection()
|
||||
|
||||
override fun toggleSelectAll() = scheduledMessageAdapter.toggleSelectAll()
|
||||
|
||||
override fun showDeleteDialog(messages: List<Long>) {
|
||||
val count = messages.size
|
||||
android.app.AlertDialog.Builder(this)
|
||||
.setTitle(R.string.dialog_delete_title)
|
||||
.setMessage(resources.getQuantityString(R.plurals.dialog_delete_chat, count, count))
|
||||
.setPositiveButton(R.string.button_delete) { _, _ -> deleteScheduledMessages.onNext(messages) }
|
||||
.setNegativeButton(R.string.button_cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun showSendNowDialog(messages: List<Long>) {
|
||||
val count = messages.size
|
||||
android.app.AlertDialog.Builder(this)
|
||||
.setTitle(R.string.main_menu_send_now)
|
||||
.setMessage(resources.getQuantityString(R.plurals.dialog_send_now, count, count))
|
||||
.setPositiveButton(R.string.main_menu_send_now) { _, _ -> sendScheduledMessages.onNext(messages) }
|
||||
.setNegativeButton(R.string.button_cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.scheduled_messages, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
optionsItemIntent.onNext(item.itemId)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun finishActivity() {
|
||||
finish()
|
||||
}
|
||||
|
||||
}
|
||||
+14
-1
@@ -61,7 +61,13 @@ class ScheduledMessageAdapter @Inject constructor(
|
||||
return QkViewHolder(view).apply {
|
||||
view.setOnClickListener {
|
||||
val message = getItem(adapterPosition) ?: return@setOnClickListener
|
||||
clicks.onNext(message.id)
|
||||
if (toggleSelection(message.id, false))
|
||||
view.isActivated = isSelected(message.id)
|
||||
}
|
||||
view.setOnClickListener {
|
||||
val message = getItem(adapterPosition) ?: return@setOnClickListener
|
||||
toggleSelection(message.id)
|
||||
view.isActivated = isSelected(message.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,11 +85,18 @@ class ScheduledMessageAdapter @Inject constructor(
|
||||
holder.date.text = dateFormatter.getScheduledTimestamp(message.date)
|
||||
holder.body.text = message.body
|
||||
|
||||
// update the selected/highlighted state
|
||||
holder.containerView.isActivated = isSelected(message.id) || highlight == message.id
|
||||
|
||||
val adapter = holder.attachments.adapter as ScheduledMessageAttachmentAdapter
|
||||
adapter.data = message.attachments.map(Uri::parse)
|
||||
holder.attachments.isVisible = message.attachments.isNotEmpty()
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return getItem(position)?.id ?: -1
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache the contacts in a map by the address, because the messages we're binding don't have
|
||||
* a reference to the contact.
|
||||
|
||||
+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(
|
||||
|
||||
@@ -23,5 +23,6 @@ import io.realm.RealmResults
|
||||
|
||||
data class ScheduledState(
|
||||
val scheduledMessages: RealmResults<ScheduledMessage>? = null,
|
||||
val upgraded: Boolean = true
|
||||
val upgraded: Boolean = true,
|
||||
val selectedMessages: Int = 0,
|
||||
)
|
||||
|
||||
@@ -23,11 +23,18 @@ import io.reactivex.Observable
|
||||
|
||||
interface ScheduledView : QkView<ScheduledState> {
|
||||
|
||||
val messageClickIntent: Observable<Long>
|
||||
val messageMenuIntent: Observable<Int>
|
||||
val composeIntent: Observable<*>
|
||||
val upgradeIntent: Observable<*>
|
||||
val messagesSelectedIntent: Observable<List<Long>>
|
||||
val optionsItemIntent: Observable<Int>
|
||||
val deleteScheduledMessages: Observable<List<Long>>
|
||||
val sendScheduledMessages: Observable<List<Long>>
|
||||
val backPressedIntent: Observable<Unit>
|
||||
|
||||
fun showMessageOptions()
|
||||
fun clearSelection()
|
||||
fun toggleSelectAll()
|
||||
fun showDeleteDialog(messages: List<Long>)
|
||||
fun showSendNowDialog(messages: List<Long>)
|
||||
fun finishActivity()
|
||||
|
||||
}
|
||||
|
||||
@@ -4,14 +4,12 @@ import android.content.Context
|
||||
import dev.octoshrimpy.quik.R
|
||||
import dev.octoshrimpy.quik.common.Navigator
|
||||
import dev.octoshrimpy.quik.common.base.QkViewModel
|
||||
import dev.octoshrimpy.quik.common.util.ClipboardUtils
|
||||
import dev.octoshrimpy.quik.common.util.extensions.makeToast
|
||||
import dev.octoshrimpy.quik.interactor.SendScheduledMessage
|
||||
import dev.octoshrimpy.quik.manager.BillingManager
|
||||
import dev.octoshrimpy.quik.repository.ScheduledMessageRepository
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import io.reactivex.Observable
|
||||
import dev.octoshrimpy.quik.common.util.ClipboardUtils
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
@@ -23,7 +21,7 @@ class ScheduledViewModel @Inject constructor(
|
||||
private val context: Context,
|
||||
private val navigator: Navigator,
|
||||
private val scheduledMessageRepo: ScheduledMessageRepository,
|
||||
private val sendScheduledMessage: SendScheduledMessage
|
||||
private val sendScheduledMessageInteractor: SendScheduledMessage,
|
||||
) : QkViewModel<ScheduledView, ScheduledState>(ScheduledState(
|
||||
scheduledMessages = scheduledMessageRepo.getScheduledMessages()
|
||||
)) {
|
||||
@@ -36,41 +34,93 @@ class ScheduledViewModel @Inject constructor(
|
||||
override fun bindView(view: ScheduledView) {
|
||||
super.bindView(view)
|
||||
|
||||
view.messageClickIntent
|
||||
// update the state when the message selected count changes
|
||||
view.messagesSelectedIntent
|
||||
.map { selection -> selection.size }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.showMessageOptions() }
|
||||
.subscribe { newState { copy(selectedMessages = it) } }
|
||||
|
||||
view.messageMenuIntent
|
||||
.withLatestFrom(view.messageClickIntent) { itemId, messageId ->
|
||||
when (itemId) {
|
||||
0 -> sendScheduledMessage.execute(messageId)
|
||||
1 -> scheduledMessageRepo.getScheduledMessage(messageId)?.let { message ->
|
||||
ClipboardUtils.copy(context, message.body)
|
||||
context.makeToast(R.string.toast_copied)
|
||||
}
|
||||
2 -> {
|
||||
val deleteSubscription = Observable.fromCallable {
|
||||
scheduledMessageRepo.deleteScheduledMessage(messageId)
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
// Handle completion, e.g., log success or update UI
|
||||
}, {
|
||||
// Handle error, e.g., log or show error message
|
||||
})
|
||||
// toggle select all / select none
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.select_all }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.toggleSelectAll() }
|
||||
|
||||
disposables += deleteSubscription
|
||||
// show the delete message dialog if one or more messages selected
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.delete }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, selectedMessages -> selectedMessages }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { view.showDeleteDialog(it) }
|
||||
|
||||
// copy the selected message text to the clipboard
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.copy }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, selectedMessages -> selectedMessages }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
val messages = it
|
||||
.mapNotNull(scheduledMessageRepo::getScheduledMessage)
|
||||
.sortedBy { it.date } // same order as messages on screen
|
||||
val text = when (messages.size) {
|
||||
1 -> messages.first().body
|
||||
else -> messages.fold(StringBuilder()) { acc, message ->
|
||||
if (acc.isNotEmpty() && message.body.isNotEmpty())
|
||||
acc.append("\n\n")
|
||||
acc.append(message.body)
|
||||
}
|
||||
}
|
||||
Unit
|
||||
|
||||
ClipboardUtils.copy(context, text.toString())
|
||||
}
|
||||
|
||||
// send the messages now menu item selected
|
||||
view.optionsItemIntent
|
||||
.filter { it == R.id.send_now }
|
||||
.withLatestFrom(view.messagesSelectedIntent) { _, selectedMessages -> selectedMessages }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
.subscribe { view.showSendNowDialog(it) }
|
||||
|
||||
// delete message(s) (fired after the confirmation dialog has been shown)
|
||||
view.deleteScheduledMessages
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
scheduledMessageRepo.deleteScheduledMessages(it)
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
// send message(s) now (fired after the confirmation dialog has been shown)
|
||||
view.sendScheduledMessages
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
it.forEach { sendScheduledMessageInteractor.execute(it) }
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
// navigate back or unselect
|
||||
view.optionsItemIntent
|
||||
.filter { it == android.R.id.home }
|
||||
.map { Unit }
|
||||
.mergeWith(view.backPressedIntent)
|
||||
.withLatestFrom(state) { _, state -> state }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
when {
|
||||
(it.selectedMessages > 0) -> view.clearSelection()
|
||||
else -> view.finishActivity()
|
||||
}
|
||||
}
|
||||
|
||||
view.composeIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.showCompose(mode = "scheduling") }
|
||||
.subscribe {
|
||||
navigator.showCompose(mode = "scheduling")
|
||||
view.clearSelection()
|
||||
}
|
||||
|
||||
view.upgradeIntent
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
@@ -184,6 +184,8 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
||||
|
||||
systemFont.checkbox.isChecked = state.systemFontEnabled
|
||||
|
||||
showStt.checkbox.isChecked = state.showStt
|
||||
|
||||
unicode.checkbox.isChecked = state.stripUnicodeEnabled
|
||||
mobileOnly.checkbox.isChecked = state.mobileOnly
|
||||
|
||||
|
||||
@@ -116,7 +116,10 @@ class SettingsPresenter @Inject constructor(
|
||||
.subscribe { autoColor -> newState { copy(autoColor = autoColor) } }
|
||||
|
||||
disposables += prefs.systemFont.asObservable()
|
||||
.subscribe { enabled -> newState { copy(systemFontEnabled = enabled) } }
|
||||
.subscribe { enabled -> newState { copy(systemFontEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.showStt.asObservable()
|
||||
.subscribe { enabled -> newState { copy(showStt = enabled) } }
|
||||
|
||||
disposables += prefs.unicode.asObservable()
|
||||
.subscribe { enabled -> newState { copy(stripUnicodeEnabled = enabled) } }
|
||||
@@ -207,6 +210,12 @@ class SettingsPresenter @Inject constructor(
|
||||
|
||||
R.id.systemFont -> prefs.systemFont.set(!prefs.systemFont.get())
|
||||
|
||||
R.id.showStt -> {
|
||||
prefs.showStt.set(!prefs.showStt.get())
|
||||
prefs.showSttOffsetX.set(Float.MIN_VALUE)
|
||||
prefs.showSttOffsetY.set(Float.MIN_VALUE)
|
||||
}
|
||||
|
||||
R.id.unicode -> prefs.unicode.set(!prefs.unicode.get())
|
||||
|
||||
R.id.mobileOnly -> prefs.mobileOnly.set(!prefs.mobileOnly.get())
|
||||
|
||||
@@ -39,6 +39,9 @@ data class SettingsState(
|
||||
val textSizeSummary: String = "",
|
||||
val textSizeId: Int = Preferences.TEXT_SIZE_NORMAL,
|
||||
val systemFontEnabled: Boolean = false,
|
||||
val showStt: Boolean = true,
|
||||
val showSttOffsetX: Float = Float.MIN_VALUE,
|
||||
val showSttOffsetY: Float = Float.MAX_VALUE,
|
||||
val splitSmsEnabled: Boolean = false,
|
||||
val stripUnicodeEnabled: Boolean = false,
|
||||
val mobileOnly: Boolean = false,
|
||||
|
||||
@@ -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