show a preview of the attached file

This commit is contained in:
tibbi 2020-04-12 13:33:30 +02:00
parent bed1d90434
commit 52a7376694
3 changed files with 62 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package com.simplemobiletools.smsmessenger.activities
import android.app.Activity
import android.app.PendingIntent
import android.content.Intent
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Bundle
import android.provider.Telephony
@ -16,6 +17,16 @@ import android.view.inputmethod.EditorInfo
import android.widget.LinearLayout
import android.widget.LinearLayout.LayoutParams
import android.widget.RelativeLayout
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
@ -185,6 +196,10 @@ class ThreadActivity : SimpleActivity() {
thread_add_attachment.setOnClickListener {
launchPickPhotoVideoIntent()
}
thread_remove_attachment.setOnClickListener {
}
}
private fun blockNumber() {
@ -293,7 +308,31 @@ class ThreadActivity : SimpleActivity() {
}
private fun addAttachment(uri: Uri) {
val roundedCornersRadius = resources.getDimension(R.dimen.medium_margin).toInt()
val options = RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.transform(CenterCrop(), RoundedCorners(roundedCornersRadius))
Glide.with(this)
.load(uri)
.transition(DrawableTransitionOptions.withCrossFade())
.apply(options)
.listener(object : RequestListener<Drawable> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
thread_attachment_preview.beGone()
thread_remove_attachment.beGone()
showErrorToast(e?.localizedMessage ?: "")
return false
}
override fun onResourceReady(dr: Drawable?, a: Any?, t: Target<Drawable>?, d: DataSource?, i: Boolean): Boolean {
thread_attachment_preview.beVisible()
thread_remove_attachment.beVisible()
return false
}
})
.into(thread_attachment_preview)
}
// show selected contacts, properly split to new lines when appropriate

View File

@ -94,7 +94,7 @@
android:id="@+id/message_divider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_above="@+id/thread_type_message"
android:layout_above="@+id/thread_attachment_preview"
android:background="@color/divider_grey"
android:importantForAccessibility="no" />
@ -111,6 +111,26 @@
android:padding="@dimen/normal_margin"
android:src="@drawable/ic_plus_vector" />
<ImageView
android:id="@+id/thread_attachment_preview"
android:layout_width="@dimen/attachment_preview_size"
android:layout_height="@dimen/attachment_preview_size"
android:layout_above="@+id/thread_type_message"
android:layout_alignStart="@+id/thread_type_message"
android:layout_marginTop="@dimen/normal_margin"
android:layout_marginBottom="@dimen/small_margin"
android:visibility="gone" />
<ImageView
android:id="@+id/thread_remove_attachment"
android:layout_width="@dimen/remove_attachment_size"
android:layout_height="@dimen/remove_attachment_size"
android:layout_alignTop="@+id/thread_attachment_preview"
android:layout_alignEnd="@+id/thread_attachment_preview"
android:padding="@dimen/tiny_margin"
android:src="@drawable/ic_cross_vector"
android:visibility="gone" />
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/thread_type_message"
android:layout_width="match_parent"

View File

@ -4,4 +4,6 @@
<dimen name="avatar_size">40dp</dimen>
<dimen name="bigger_avatar_size">64dp</dimen>
<dimen name="play_outline_size">36dp</dimen>
<dimen name="attachment_preview_size">60dp</dimen>
<dimen name="remove_attachment_size">24dp</dimen>
</resources>