changed to not save message attachments

to media store when sharing.
fixed using wrong attachment class for vcards (use lowercase on both sides of attachment mime type comparison)
added share button to audio attachment preview
removed old fileprovider that was never used
added content provider to provide mms attachments to external activities using a filename - not mms part id - so they can be saved externally with a proper name
fix bug when re-using attachment viewholder that has previously had text
fixed bug of image attachments always being named 'image' rather than their filename
 added share button to generic file attachment type in compose message list and removed onclick handler for viewing
This commit is contained in:
gavine99
2025-02-03 19:58:40 +11:00
parent 51ba356526
commit 042bbe80a1
14 changed files with 285 additions and 93 deletions
-11
View File
@@ -252,17 +252,6 @@
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
</application>
<queries>
@@ -73,6 +73,8 @@ class AttachmentAdapter @Inject constructor(
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
val attachment = getItem(position)
holder.fileName.visibility = View.GONE
if (attachment.isVCard(context)) {
val displayName = Ezvcard.parse(
String(attachment.getResourceBytes(context))
@@ -24,6 +24,7 @@ import android.os.Vibrator
import android.provider.ContactsContract
import android.telephony.SmsMessage
import androidx.core.content.getSystemService
import com.moez.QKSMS.contentproviders.MmsPartProvider
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.Navigator
import dev.octoshrimpy.quik.common.base.QkViewModel
@@ -470,12 +471,11 @@ class ComposeViewModel @Inject constructor(
.mapNotNull(messageRepo::getPart)
.filter { part -> !part.isImage() && !part.isVideo() }
.autoDisposable(view.scope())
.subscribe { part ->
if (permissionManager.hasStorage()) {
messageRepo.savePart(part.id)?.let { navigator.viewFile(it, part.type) }
} else {
view.requestStoragePermission()
}
.subscribe {
navigator.viewFile(
MmsPartProvider.getUriForMmsPartId(it.id, it.getBestFilename()),
it.type
)
}
// Update the State when the message selected count changes
@@ -25,7 +25,9 @@ import android.media.MediaMetadataRetriever
import android.view.View
import android.widget.SeekBar
import com.moez.QKSMS.common.QkMediaPlayer
import com.moez.QKSMS.contentproviders.MmsPartProvider
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.Navigator
import dev.octoshrimpy.quik.common.base.QkViewHolder
import dev.octoshrimpy.quik.common.util.Colors
import dev.octoshrimpy.quik.common.util.extensions.resolveThemeColor
@@ -49,6 +51,12 @@ import javax.inject.Inject
class AudioBinder @Inject constructor(colors: Colors, private val context: Context) :
PartBinder() {
companion object {
const val DEFAULT_SHARE_FILENAME = "quik-audio-attachment.mp3"
}
@Inject lateinit var navigator: Navigator
override val partLayout = R.layout.mms_audio_preview_list_item
override var theme = colors.theme()
@@ -169,7 +177,13 @@ class AudioBinder @Inject constructor(colors: Colors, private val context: Conte
}
}
holder.containerView.setOnClickListener { clicks.onNext(part.id) }
// 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)
@@ -224,6 +238,10 @@ 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())
@@ -22,7 +22,9 @@ import android.annotation.SuppressLint
import android.content.Context
import android.view.Gravity
import android.widget.FrameLayout
import com.moez.QKSMS.contentproviders.MmsPartProvider
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.Navigator
import dev.octoshrimpy.quik.common.base.QkViewHolder
import dev.octoshrimpy.quik.common.util.Colors
import dev.octoshrimpy.quik.common.util.extensions.resolveThemeColor
@@ -34,11 +36,14 @@ 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
class FileBinder @Inject constructor(colors: Colors, private val context: Context) : PartBinder() {
@Inject lateinit var navigator: Navigator
override val partLayout = R.layout.mms_file_list_item
override var theme = colors.theme()
@@ -56,8 +61,6 @@ class FileBinder @Inject constructor(colors: Colors, private val context: Contex
BubbleUtils.getBubble(false, canGroupWithPrevious, canGroupWithNext, message.isMe())
.let(holder.fileBackground::setBackgroundResource)
holder.containerView.setOnClickListener { clicks.onNext(part.id) }
Observable.just(part.getUri())
.map(context.contentResolver::openInputStream)
.map { inputStream -> inputStream.use { it.available() } }
@@ -73,6 +76,14 @@ 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
@@ -82,12 +93,16 @@ class FileBinder @Inject constructor(colors: Colors, private val context: Contex
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))
}
}
@@ -19,6 +19,7 @@
package dev.octoshrimpy.quik.feature.gallery
import android.content.Context
import com.moez.QKSMS.contentproviders.MmsPartProvider
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.Navigator
import dev.octoshrimpy.quik.common.base.QkViewModel
@@ -45,6 +46,9 @@ class GalleryViewModel @Inject constructor(
private val saveImage: SaveImage,
private val permissions: PermissionManager
) : QkViewModel<GalleryView, GalleryState>(GalleryState()) {
companion object {
const val DEFAULT_SHARE_FILENAME = "quik-media-attachment.jpg"
}
init {
disposables += Flowable.just(partId)
@@ -80,11 +84,13 @@ class GalleryViewModel @Inject constructor(
// Share image externally
view.optionsItemSelected()
.filter { itemId -> itemId == R.id.share }
.filter { permissions.hasStorage().also { if (!it) view.requestStoragePermission() } }
.withLatestFrom(view.pageChanged()) { _, part -> part }
.autoDisposable(view.scope())
.subscribe { part ->
messageRepo.savePart(part.id)?.let { navigator.shareFile(it, part.type) }
.subscribe {
navigator.shareFile(
MmsPartProvider.getUriForMmsPartId(it.id, it.getBestFilename()),
it.type
)
}
}
@@ -53,30 +53,29 @@
android:progressTint="@color/tools_theme"
android:thumbTint="@color/tools_theme" />
<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="12dp"
android:clipChildren="false"
android:orientation="horizontal">
android:layout_marginBottom="12dp">
<ImageView
android:id="@+id/playPause"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="bottom"
android:layout_marginStart="12dp"
android:background="@drawable/circle"
android:elevation="4dp"
android:padding="6dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/exo_icon_play"
app:tint="@color/tools_theme" />
<dev.octoshrimpy.quik.common.widget.QkTextView
android:id="@+id/metadataTitle"
style="@style/TextPrimary"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="12dp"
@@ -91,8 +90,24 @@
android:scrollHorizontally="true"
android:singleLine="true"
android:text="@tools:sample/lorem/random[0]"
android:textColor="@color/black" />
android:textColor="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/share"
app:layout_constraintStart_toEndOf="@id/playPause" />
</LinearLayout>
<ImageView
android:id="@+id/share"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="bottom"
android:layout_marginEnd="12dp"
android:background="@drawable/circle"
android:elevation="4dp"
android:padding="6dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="?attr/actionModeShareDrawable"
app:tint="@color/tools_theme" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
@@ -35,36 +35,53 @@
android:layout_height="24dp"
android:layout_marginStart="12dp"
android:src="@drawable/ic_attachment_black_24dp"
android:tint="?android:attr/textColorSecondary"
app:layout_constraintBottom_toBottomOf="@id/fileBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/fileBackground" />
<dev.octoshrimpy.quik.common.widget.QkTextView
android:id="@+id/filename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="12dp"
android:paddingTop="8dp"
android:paddingEnd="12dp"
app:layout_constraintTop_toTopOf="parent"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintStart_toEndOf="@id/icon"
app:textSize="primary"
tools:text="Resume.pdf" />
app:tint="?android:attr/textColorSecondary" />
<dev.octoshrimpy.quik.common.widget.QkTextView
android:id="@+id/size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="12dp"
android:paddingEnd="12dp"
tools:text="35 KB"
android:paddingBottom="8dp"
android:textColor="?android:attr/textColorTertiary"
app:layout_constraintStart_toStartOf="@id/filename"
app:layout_constraintTop_toBottomOf="@id/filename"
app:textSize="secondary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="@id/share"
app:layout_constraintStart_toEndOf="@id/icon">
<dev.octoshrimpy.quik.common.widget.QkTextView
android:id="@+id/filename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="12dp"
android:paddingTop="8dp"
android:paddingEnd="12dp"
android:textColor="?android:attr/textColorPrimary"
app:textSize="primary"
tools:text="Resume.pdf" />
<dev.octoshrimpy.quik.common.widget.QkTextView
android:id="@+id/size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:paddingBottom="8dp"
android:textColor="?android:attr/textColorTertiary"
app:textSize="secondary"
tools:text="35 KB" />
</LinearLayout>
<ImageView
android:id="@+id/share"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginEnd="12dp"
android:background="@drawable/circle"
android:padding="6dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="?attr/actionModeShareDrawable"
app:tint="@color/tools_theme" />
</androidx.constraintlayout.widget.ConstraintLayout>
@@ -1,24 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2019 Moez Bhatti <moez.bhatti@gmail.com>
~
~ This file is part of QKSMS.
~
~ QKSMS is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ QKSMS is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
-->
<paths>
<external-path
name="external_files"
path="." />
</paths>