From 52a73766945a47f919bc134e78f3490b8a0a167b Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 12 Apr 2020 13:33:30 +0200 Subject: [PATCH] show a preview of the attached file --- .../smsmessenger/activities/ThreadActivity.kt | 39 +++++++++++++++++++ app/src/main/res/layout/activity_thread.xml | 22 ++++++++++- app/src/main/res/values/dimens.xml | 2 + 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt index acf9a546..d674359d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -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 { + override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, 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?, 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 diff --git a/app/src/main/res/layout/activity_thread.xml b/app/src/main/res/layout/activity_thread.xml index cb7a294f..38be3a0e 100644 --- a/app/src/main/res/layout/activity_thread.xml +++ b/app/src/main/res/layout/activity_thread.xml @@ -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" /> + + + + 40dp 64dp 36dp + 60dp + 24dp