Browse Source

Display zoomed/zoomable Profile pictures on click

pull/70/head
Ezerous 5 years ago
parent
commit
c889fc2d18
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  2. 35
      app/src/main/java/gr/thmmy/mthmmy/utils/ui/PhotoViewUtils.java
  3. 31
      app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java

9
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_TITLE;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; 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.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 <b>String</b> * Activity for user profile. When creating an Intent of this activity you need to bundle a <b>String</b>
@ -127,8 +128,8 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
avatarView = findViewById(R.id.user_thumbnail); avatarView = findViewById(R.id.user_thumbnail);
if (!Objects.equals(avatarUrl, "")) if (!Objects.equals(avatarUrl, ""))
//noinspection ConstantConditions
loadAvatar(false); loadAvatar(false);
else else
loadAvatar(true); loadAvatar(true);
usernameView = findViewById(R.id.profile_activity_username); usernameView = findViewById(R.id.profile_activity_username);
@ -215,8 +216,11 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
String avatarUri; String avatarUri;
if(loadDefault) if(loadDefault)
avatarUri = "R.drawable.ic_default_user_avatar"; avatarUri = "R.drawable.ic_default_user_avatar";
else else {
avatarUri = avatarUrl; avatarUri = avatarUrl;
if(avatarUrl!=null)
avatarView.setOnClickListener(v -> displayPhotoViewImage(ProfileActivity.this, avatarUrl));
}
Glide.with(this) Glide.with(this)
.load(avatarUri) .load(avatarUri)
@ -305,7 +309,6 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
usernameView.setText(usernameSpan); usernameView.setText(usernameSpan);
} else if (usernameView.getText() != username) usernameView.setText(username); } else if (usernameView.getText() != username) usernameView.setText(username);
if (avatarUrl != null && !Objects.equals(avatarUrl, "")) if (avatarUrl != null && !Objects.equals(avatarUrl, ""))
//noinspection ConstantConditions
loadAvatar(false); loadAvatar(false);
else else
loadAvatar(true); loadAvatar(true);

35
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();
}
}

31
app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java

@ -1,28 +1,19 @@
package gr.thmmy.mthmmy.views; package gr.thmmy.mthmmy.views;
import android.app.Dialog;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.Window;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.Toast; import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.github.chrisbanes.photoview.PhotoView;
import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseApplication;
import static android.content.Context.CLIPBOARD_SERVICE; import static android.content.Context.CLIPBOARD_SERVICE;
import static gr.thmmy.mthmmy.utils.ui.PhotoViewUtils.displayPhotoViewImage;
public class ReactiveWebView extends WebView { 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 static long MAX_TOUCH_DURATION = 100;
private final Context context; private final Context context;
private long downTime; private long downTime;
@ -72,29 +63,11 @@ public class ReactiveWebView extends WebView {
WebView.HitTestResult result = this.getHitTestResult(); WebView.HitTestResult result = this.getHitTestResult();
if(result.getType() == WebView.HitTestResult.IMAGE_TYPE){ if(result.getType() == WebView.HitTestResult.IMAGE_TYPE){
String imageURL = result.getExtra(); String imageURL = result.getExtra();
showImage(imageURL); displayPhotoViewImage(context, imageURL);
} }
return super.performClick(); 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(){ private void setOnLongClickListener(){
this.setOnLongClickListener(v -> { this.setOnLongClickListener(v -> {
HitTestResult result = ReactiveWebView.this.getHitTestResult(); HitTestResult result = ReactiveWebView.this.getHitTestResult();

Loading…
Cancel
Save