From 7ae7e13b26660e8d63bc046bb4fcca101e3805b9 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Fri, 8 Jan 2016 01:52:49 -0500 Subject: [PATCH] Show preview for image links Major credit to dethstar for starting this and getting the image loading set up. https://github.com/dethstar/qksms/commit/92ce8517580c0dd9c1c2454f0798b16 9677669c8 --- .../ui/messagelist/MessageListAdapter.java | 47 +++++++++++++---- .../ui/messagelist/MessageListViewHolder.java | 31 +++-------- .../com/moez/QKSMS/ui/view/MmsImageView.java | 40 -------------- .../main/res/drawable-xxhdpi/card_mask.9.png | Bin 0 -> 16050 bytes .../main/res/layout/list_item_message_in.xml | 39 ++++++++++---- .../main/res/layout/list_item_message_out.xml | 39 ++++++++++---- QKSMS/src/main/res/layout/view_mms_layout.xml | 49 ------------------ 7 files changed, 104 insertions(+), 141 deletions(-) delete mode 100644 QKSMS/src/main/java/com/moez/QKSMS/ui/view/MmsImageView.java create mode 100644 QKSMS/src/main/res/drawable-xxhdpi/card_mask.9.png delete mode 100644 QKSMS/src/main/res/layout/view_mms_layout.xml diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java index a59df7ad..1a0bf119 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListAdapter.java @@ -6,6 +6,7 @@ import android.content.res.Resources; import android.database.Cursor; import android.graphics.PorterDuff; import android.graphics.Typeface; +import android.net.Uri; import android.os.Handler; import android.provider.ContactsContract; import android.provider.Telephony; @@ -26,13 +27,16 @@ import com.android.mms.transaction.TransactionService; import com.android.mms.util.DownloadManager; import com.google.android.mms.ContentType; import com.google.android.mms.pdu_alt.PduHeaders; +import com.koushikdutta.ion.Ion; import com.moez.QKSMS.QKSMSApp; import com.moez.QKSMS.R; +import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.emoji.EmojiRegistry; import com.moez.QKSMS.common.utils.CursorUtils; import com.moez.QKSMS.common.utils.LinkifyUtils; import com.moez.QKSMS.common.utils.MessageUtils; import com.moez.QKSMS.data.Contact; +import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.transaction.SmsHelper; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.base.QKActivity; @@ -50,13 +54,15 @@ import java.util.regex.Pattern; public class MessageListAdapter extends RecyclerCursorAdapter { private final String TAG = "MessageListAdapter"; - public static final int INCOMING_ITEM_TYPE_SMS = 0; - public static final int OUTGOING_ITEM_TYPE_SMS = 1; - public static final int INCOMING_ITEM_TYPE_MMS = 2; - public static final int OUTGOING_ITEM_TYPE_MMS = 3; + public static final int INCOMING_ITEM = 0; + public static final int OUTGOING_ITEM = 1; private ArrayList mSelectedConversations = new ArrayList<>(); + private static final Pattern urlPattern = Pattern.compile( + "\\b(https?:\\/\\/\\S+(?:png|jpe?g|gif)\\S*)\\b", + Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); + private MessageItemCache mMessageItemCache; private MessageColumns.ColumnsMap mColumnsMap; @@ -114,7 +120,7 @@ public class MessageListAdapter extends RecyclerCursorAdapter { + holder.mMmsView.getForeground().setColorFilter(ThemeManager.getBackgroundColor(), PorterDuff.Mode.SRC_ATOP); + }); + return holder; } @@ -183,13 +193,13 @@ public class MessageListAdapter extends RecyclerCursorAdapter { + try { + holder.setImage("url_img" + holder.getItemId(), result); + holder.mImageView.setOnClickListener(v -> { + Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(imageUrl)); + mContext.startActivity(i); + }); + } catch (NullPointerException imageException) { + imageException.printStackTrace(); + } + }); + } LinkifyUtils.addLinks(holder.mBodyTextView); } holder.mBodyTextView.setVisibility(TextUtils.isEmpty(buf) ? View.GONE : View.VISIBLE); @@ -552,15 +579,15 @@ public class MessageListAdapter extends RecyclerCursorAdapter impleme protected AvatarView mAvatarView; protected LinearLayout mMessageBlock; protected View mSpace; - // MMS only views. These are nested within ViewStubs, so we don't need to obtain a reference - // to them right away. We'll inflate the stub only when needed - protected View mMmsView; + protected FrameLayout mMmsView; protected ImageView mImageView; protected ImageButton mSlideShowButton; protected Button mDownloadButton; @@ -59,30 +58,14 @@ public class MessageListViewHolder extends ClickyViewHolder impleme mAvatarView = (AvatarView) view.findViewById(R.id.avatar); mMessageBlock = (LinearLayout) view.findViewById(R.id.message_block); mSpace = view.findViewById(R.id.space); + mMmsView = (FrameLayout) view.findViewById(R.id.mms_view); + mImageView = (ImageView) view.findViewById(R.id.image_view); + mSlideShowButton = (ImageButton) view.findViewById(R.id.play_slideshow_button); } protected void showMmsView(boolean visible) { - if (mMmsView == null) { - mMmsView = mRoot.findViewById(R.id.mms_view); - // if mMmsView is still null here, that mean the mms section hasn't been inflated - - if (visible && mMmsView == null) { - // inflate the mms view_stub - View mmsStub = mRoot.findViewById(R.id.mms_layout_view_stub); - mmsStub.setVisibility(View.VISIBLE); - mMmsView = mRoot.findViewById(R.id.mms_view); - } - } - if (mMmsView != null) { - if (mImageView == null) { - mImageView = (ImageView) mRoot.findViewById(R.id.image_view); - } - if (mSlideShowButton == null) { - mSlideShowButton = (ImageButton) mRoot.findViewById(R.id.play_slideshow_button); - } - mMmsView.setVisibility(visible ? View.VISIBLE : View.GONE); - mImageView.setVisibility(visible ? View.VISIBLE : View.GONE); - } + mMmsView.setVisibility(visible ? View.VISIBLE : View.GONE); + mImageView.setVisibility(visible ? View.VISIBLE : View.GONE); } protected void inflateDownloadControls() { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/MmsImageView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/MmsImageView.java deleted file mode 100644 index 50176134..00000000 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/MmsImageView.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.moez.QKSMS.ui.view; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.util.AttributeSet; -import android.widget.ImageView; -import com.moez.QKSMS.common.utils.ImageUtils; - -public class MmsImageView extends ImageView { - private final String TAG = "MmsImageView"; - - public MmsImageView(Context context) { - super(context); - } - - public MmsImageView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - public void setImageDrawable(Drawable drawable) { - if (drawable != null) { - int width = getWidth(); - Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); - - if (bitmap != null) { - float ratio = (float) width / (float) bitmap.getWidth(); - int height = (int) (bitmap.getHeight() * ratio); - - if (width > 0 && height > 0) { - super.setImageDrawable(ImageUtils.getRoundedDrawable(getContext(), Bitmap.createScaledBitmap(bitmap, width, height, true), 4)); - } - } - } else { - super.setImageDrawable(drawable); - } - } -} diff --git a/QKSMS/src/main/res/drawable-xxhdpi/card_mask.9.png b/QKSMS/src/main/res/drawable-xxhdpi/card_mask.9.png new file mode 100644 index 0000000000000000000000000000000000000000..b3568be5295f6088b40a5f265ef0470f14992683 GIT binary patch literal 16050 zcmeI3eQ?v}9mj3=xMr}Xph%W1I~I<~i(_I|GcPfatk-~I$%zu%@+2j3 z!ohIq`T~Xa(w9It2BEAZYhi_kj!+ofZiNj7EnFxJSjgxgz(%1f8e4pR1kJ8x-Q{Ar^GVXf`Ew|mt739Oez`UTS>}X-l&6jnwN*?t8_3gL z|8T!f%hGweMT8S|28);)wxpS7%9`i9J$-vKuls4q|1q3pbr;GTK z(r>vK(P<-9#JW6Pf!v_B-09L5aXh0Xa*VJCHJY?0bB>-cnGB{`S`5__2#O;(3S&5F zKuH6pjeT_14C$AJr@dsU%^qt`it=vtf*_W!~>cu>rPHw3G6MHUy(CO@NDj>w@NgR<76-4wo zDB|}csWJtzlu2|lWv1Y63NlD3BXIS+hmopJOKnu#AoVWxv_mi|ZeRjpN-Js1l#Nog zPkZ`vg7v&F0-E+9jF0h4?FbSBeM$hq8cyVd8g7s#`{fA4R1J%)cMyQGGH4nTVh2f+ zm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