From c889fc2d18232d63d2719593e5cff2bd9febe48c Mon Sep 17 00:00:00 2001 From: Ezerous Date: Fri, 29 May 2020 19:31:22 +0300 Subject: [PATCH] Display zoomed/zoomable Profile pictures on click --- .../activities/profile/ProfileActivity.java | 9 +++-- .../thmmy/mthmmy/utils/ui/PhotoViewUtils.java | 35 +++++++++++++++++++ .../thmmy/mthmmy/views/ReactiveWebView.java | 31 ++-------------- 3 files changed, 43 insertions(+), 32 deletions(-) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/utils/ui/PhotoViewUtils.java diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java index 0cb1edeb..380a827b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java @@ -57,6 +57,7 @@ import timber.log.Timber; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.emojiTagToHtml; +import static gr.thmmy.mthmmy.utils.ui.PhotoViewUtils.displayPhotoViewImage; /** * Activity for user profile. When creating an Intent of this activity you need to bundle a String @@ -127,8 +128,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment avatarView = findViewById(R.id.user_thumbnail); if (!Objects.equals(avatarUrl, "")) - //noinspection ConstantConditions loadAvatar(false); + else loadAvatar(true); usernameView = findViewById(R.id.profile_activity_username); @@ -215,8 +216,11 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment String avatarUri; if(loadDefault) avatarUri = "R.drawable.ic_default_user_avatar"; - else + else { avatarUri = avatarUrl; + if(avatarUrl!=null) + avatarView.setOnClickListener(v -> displayPhotoViewImage(ProfileActivity.this, avatarUrl)); + } Glide.with(this) .load(avatarUri) @@ -305,7 +309,6 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment usernameView.setText(usernameSpan); } else if (usernameView.getText() != username) usernameView.setText(username); if (avatarUrl != null && !Objects.equals(avatarUrl, "")) - //noinspection ConstantConditions loadAvatar(false); else loadAvatar(true); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ui/PhotoViewUtils.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ui/PhotoViewUtils.java new file mode 100644 index 00000000..cb357324 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ui/PhotoViewUtils.java @@ -0,0 +1,35 @@ +package gr.thmmy.mthmmy.utils.ui; + +import android.app.Dialog; +import android.content.Context; +import android.graphics.drawable.ColorDrawable; +import android.view.ViewGroup; +import android.view.Window; + +import com.bumptech.glide.Glide; +import com.github.chrisbanes.photoview.PhotoView; + +import gr.thmmy.mthmmy.base.BaseApplication; + +public class PhotoViewUtils { + private final static int screenWidth = BaseApplication.getInstance().getWidthInPixels(); + private final static int screenHeight = BaseApplication.getInstance().getHeightInPixels(); + + public static void displayPhotoViewImage(Context context, String url) { + Dialog builder = new Dialog(context); + builder.requestWindowFeature(Window.FEATURE_NO_TITLE); + builder.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + builder.getWindow().setBackgroundDrawable( + new ColorDrawable(android.graphics.Color.TRANSPARENT)); + + PhotoView photoView = new PhotoView(context); + photoView.setLayoutParams(new ViewGroup.LayoutParams(screenWidth, screenHeight)); + + Glide.with(context).load(url).fitCenter().into(photoView); + + builder.addContentView(photoView, new ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT)); + builder.show(); + } +} diff --git a/app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java b/app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java index 35fe87b7..294c6451 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java @@ -1,28 +1,19 @@ package gr.thmmy.mthmmy.views; -import android.app.Dialog; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; -import android.graphics.drawable.ColorDrawable; import android.util.AttributeSet; import android.view.MotionEvent; -import android.view.ViewGroup; -import android.view.Window; import android.webkit.WebView; import android.widget.Toast; -import com.bumptech.glide.Glide; -import com.github.chrisbanes.photoview.PhotoView; - import gr.thmmy.mthmmy.base.BaseApplication; import static android.content.Context.CLIPBOARD_SERVICE; +import static gr.thmmy.mthmmy.utils.ui.PhotoViewUtils.displayPhotoViewImage; public class ReactiveWebView extends WebView { - private final static int screenWidth = BaseApplication.getInstance().getWidthInPixels(); - private final static int screenHeight = BaseApplication.getInstance().getHeightInPixels(); - private final static long MAX_TOUCH_DURATION = 100; private final Context context; private long downTime; @@ -72,29 +63,11 @@ public class ReactiveWebView extends WebView { WebView.HitTestResult result = this.getHitTestResult(); if(result.getType() == WebView.HitTestResult.IMAGE_TYPE){ String imageURL = result.getExtra(); - showImage(imageURL); + displayPhotoViewImage(context, imageURL); } return super.performClick(); } - private void showImage(String url) { - Dialog builder = new Dialog(context); - builder.requestWindowFeature(Window.FEATURE_NO_TITLE); - builder.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - builder.getWindow().setBackgroundDrawable( - new ColorDrawable(android.graphics.Color.TRANSPARENT)); - - PhotoView photoView = new PhotoView(context); - photoView.setLayoutParams(new ViewGroup.LayoutParams(screenWidth, screenHeight)); - - Glide.with(context).load(url).fitCenter().into(photoView); - - builder.addContentView(photoView, new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT)); - builder.show(); - } - private void setOnLongClickListener(){ this.setOnLongClickListener(v -> { HitTestResult result = ReactiveWebView.this.getHitTestResult();