mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 11:23:38 +00:00
let ThumbnailView handle remove button placement
Closes #3849 // FREEBIE
This commit is contained in:
parent
835f1efc76
commit
1641fd91cf
@ -9,7 +9,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<shape android:shape="oval">
|
<shape android:shape="oval">
|
||||||
<size android:height="21dp" android:width="21dp"/>
|
<size android:height="21dp" android:width="21dp"/>
|
||||||
<solid android:color="@color/textsecure_primary_dark"/>
|
<solid android:color="@color/red_600"/>
|
||||||
<stroke android:color="@android:color/transparent"
|
<stroke android:color="@android:color/transparent"
|
||||||
android:width="3dp"/>
|
android:width="3dp"/>
|
||||||
</shape>
|
</shape>
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:paddingTop="10dp"
|
|
||||||
android:background="?android:windowBackground"
|
android:background="?android:windowBackground"
|
||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
@ -41,13 +40,6 @@
|
|||||||
android:contentDescription="@string/conversation_activity__attachment_thumbnail"
|
android:contentDescription="@string/conversation_activity__attachment_thumbnail"
|
||||||
app:backgroundColorHint="?conversation_background" />
|
app:backgroundColorHint="?conversation_background" />
|
||||||
|
|
||||||
<ImageView android:id="@+id/remove_image_button"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:src="@drawable/conversation_attachment_close_circle"
|
|
||||||
android:layout_marginRight="115dp"
|
|
||||||
android:layout_gravity="top|center_horizontal"/>
|
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<LinearLayout android:id="@+id/bottom_panel"
|
<LinearLayout android:id="@+id/bottom_panel"
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
||||||
|
|
||||||
<ImageView android:id="@+id/thumbnail_image"
|
<ImageView android:id="@+id/thumbnail_image"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -10,15 +9,15 @@
|
|||||||
android:contentDescription="@string/conversation_item__mms_image_description"
|
android:contentDescription="@string/conversation_item__mms_image_description"
|
||||||
android:layout_margin="@dimen/media_bubble_border_width" />
|
android:layout_margin="@dimen/media_bubble_border_width" />
|
||||||
|
|
||||||
<com.pnikosis.materialishprogress.ProgressWheel
|
<ViewStub android:id="@+id/progress_wheel_stub"
|
||||||
android:id="@+id/progress_wheel"
|
android:layout_width="70dp"
|
||||||
android:layout_width="70dp"
|
android:layout_height="70dp"
|
||||||
android:layout_height="70dp"
|
android:layout_gravity="center"
|
||||||
android:layout_gravity="center"
|
android:layout="@layout/thumbnail_view_progress_wheel" />
|
||||||
android:background="@drawable/progress_background"
|
|
||||||
android:visibility="gone"
|
|
||||||
app:matProg_barColor="@color/white"
|
|
||||||
app:matProg_linearProgress="true"
|
|
||||||
app:matProg_spinSpeed="0.333" />
|
|
||||||
|
|
||||||
|
<ViewStub android:id="@+id/remove_button_stub"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="top|right"
|
||||||
|
android:layout="@layout/thumbnail_view_remove_button" />
|
||||||
</merge>
|
</merge>
|
||||||
|
12
res/layout/thumbnail_view_progress_wheel.xml
Normal file
12
res/layout/thumbnail_view_progress_wheel.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.pnikosis.materialishprogress.ProgressWheel
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/progress_wheel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@drawable/progress_background"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:matProg_barColor="@color/white"
|
||||||
|
app:matProg_linearProgress="true"
|
||||||
|
app:matProg_spinSpeed="0.333" />
|
6
res/layout/thumbnail_view_remove_button.xml
Normal file
6
res/layout/thumbnail_view_remove_button.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/remove_image_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/conversation_attachment_close_circle" />
|
@ -5,6 +5,7 @@ import android.app.Activity;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Build.VERSION;
|
import android.os.Build.VERSION;
|
||||||
import android.os.Build.VERSION_CODES;
|
import android.os.Build.VERSION_CODES;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
@ -16,6 +17,7 @@ import android.view.animation.AlphaAnimation;
|
|||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.Animation.AnimationListener;
|
import android.view.animation.Animation.AnimationListener;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
import com.bumptech.glide.DrawableTypeRequest;
|
import com.bumptech.glide.DrawableTypeRequest;
|
||||||
@ -37,6 +39,7 @@ import org.thoughtcrime.securesms.mms.SlideDeck;
|
|||||||
import org.thoughtcrime.securesms.util.FutureTaskListener;
|
import org.thoughtcrime.securesms.util.FutureTaskListener;
|
||||||
import org.thoughtcrime.securesms.util.ListenableFutureTask;
|
import org.thoughtcrime.securesms.util.ListenableFutureTask;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
|
|
||||||
import de.greenrobot.event.EventBus;
|
import de.greenrobot.event.EventBus;
|
||||||
import ws.com.google.android.mms.pdu.PduPart;
|
import ws.com.google.android.mms.pdu.PduPart;
|
||||||
@ -47,6 +50,7 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
private boolean showProgress = true;
|
private boolean showProgress = true;
|
||||||
private ImageView image;
|
private ImageView image;
|
||||||
private ProgressWheel progress;
|
private ProgressWheel progress;
|
||||||
|
private ImageView removeButton;
|
||||||
private int backgroundColorHint;
|
private int backgroundColorHint;
|
||||||
private int radius;
|
private int radius;
|
||||||
|
|
||||||
@ -68,8 +72,7 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
inflate(context, R.layout.thumbnail_view, this);
|
inflate(context, R.layout.thumbnail_view, this);
|
||||||
radius = getResources().getDimensionPixelSize(R.dimen.message_bubble_corner_radius);
|
radius = getResources().getDimensionPixelSize(R.dimen.message_bubble_corner_radius);
|
||||||
image = (ImageView) findViewById(R.id.thumbnail_image);
|
image = (ImageView) findViewById(R.id.thumbnail_image);
|
||||||
progress = (ProgressWheel) findViewById(R.id.progress_wheel);
|
|
||||||
|
|
||||||
if (attrs != null) {
|
if (attrs != null) {
|
||||||
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ThumbnailView, 0, 0);
|
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ThumbnailView, 0, 0);
|
||||||
@ -78,6 +81,15 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
super.onLayout(changed, left, top, right, bottom);
|
||||||
|
if (removeButton != null) {
|
||||||
|
final int paddingHorizontal = removeButton.getWidth() / 2;
|
||||||
|
final int paddingVertical = removeButton.getHeight() / 2;
|
||||||
|
image.setPadding(paddingHorizontal, paddingVertical, paddingHorizontal, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override protected void onAttachedToWindow() {
|
@Override protected void onAttachedToWindow() {
|
||||||
super.onAttachedToWindow();
|
super.onAttachedToWindow();
|
||||||
if (!EventBus.getDefault().isRegistered(this)) EventBus.getDefault().registerSticky(this);
|
if (!EventBus.getDefault().isRegistered(this)) EventBus.getDefault().registerSticky(this);
|
||||||
@ -88,12 +100,26 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
EventBus.getDefault().unregister(this);
|
EventBus.getDefault().unregister(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ProgressWheel getProgressWheel() {
|
||||||
|
if (progress == null) progress = ViewUtil.inflateStub(this, R.id.progress_wheel_stub);
|
||||||
|
return progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hideProgressWheel() {
|
||||||
|
if (progress != null) progress.setVisibility(GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImageView getRemoveButton() {
|
||||||
|
if (removeButton == null) removeButton = ViewUtil.inflateStub(this, R.id.remove_button_stub);
|
||||||
|
return removeButton;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void onEventAsync(final PartProgressEvent event) {
|
public void onEventAsync(final PartProgressEvent event) {
|
||||||
if (this.slide != null && event.partId.equals(this.slide.getPart().getPartId())) {
|
if (this.slide != null && event.partId.equals(this.slide.getPart().getPartId())) {
|
||||||
Util.runOnMain(new Runnable() {
|
Util.runOnMain(new Runnable() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
progress.setInstantProgress(((float)event.progress) / event.total);
|
getProgressWheel().setInstantProgress(((float)event.progress) / event.total);
|
||||||
if (event.progress >= event.total) animateOutProgress();
|
if (event.progress >= event.total) animateOutProgress();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -115,7 +141,7 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
String slideId = id + "::" + timestamp;
|
String slideId = id + "::" + timestamp;
|
||||||
|
|
||||||
if (!slideId.equals(this.slideId)) {
|
if (!slideId.equals(this.slideId)) {
|
||||||
progress.setVisibility(GONE);
|
hideProgressWheel();
|
||||||
image.setImageDrawable(null);
|
image.setImageDrawable(null);
|
||||||
this.slide = null;
|
this.slide = null;
|
||||||
this.slideId = slideId;
|
this.slideId = slideId;
|
||||||
@ -138,10 +164,10 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
|
|
||||||
this.slide = slide;
|
this.slide = slide;
|
||||||
if (slide.isInProgress() && showProgress) {
|
if (slide.isInProgress() && showProgress) {
|
||||||
progress.spin();
|
getProgressWheel().spin();
|
||||||
progress.setVisibility(VISIBLE);
|
getProgressWheel().setVisibility(VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
progress.setVisibility(GONE);
|
hideProgressWheel();
|
||||||
}
|
}
|
||||||
buildGlideRequest(slide, masterSecret).into(image);
|
buildGlideRequest(slide, masterSecret).into(image);
|
||||||
setOnClickListener(new ThumbnailClickDispatcher(thumbnailClickListener, slide));
|
setOnClickListener(new ThumbnailClickDispatcher(thumbnailClickListener, slide));
|
||||||
@ -151,13 +177,17 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
this.thumbnailClickListener = listener;
|
this.thumbnailClickListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRemoveClickListener(OnClickListener listener) {
|
||||||
|
getRemoveButton().setOnClickListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
if (isContextValid()) Glide.clear(this);
|
if (isContextValid()) Glide.clear(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShowProgress(boolean showProgress) {
|
public void setShowProgress(boolean showProgress) {
|
||||||
this.showProgress = showProgress;
|
this.showProgress = showProgress;
|
||||||
if (progress.getVisibility() == View.VISIBLE && !showProgress) {
|
if (progress != null && progress.getVisibility() == View.VISIBLE && !showProgress) {
|
||||||
animateOutProgress();
|
animateOutProgress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,16 +251,17 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void animateOutProgress() {
|
private void animateOutProgress() {
|
||||||
|
if (progress == null) return;
|
||||||
AlphaAnimation animation = new AlphaAnimation(1f, 0f);
|
AlphaAnimation animation = new AlphaAnimation(1f, 0f);
|
||||||
animation.setDuration(200);
|
animation.setDuration(200);
|
||||||
animation.setAnimationListener(new AnimationListener() {
|
animation.setAnimationListener(new AnimationListener() {
|
||||||
@Override public void onAnimationStart(Animation animation) { }
|
@Override public void onAnimationStart(Animation animation) { }
|
||||||
@Override public void onAnimationRepeat(Animation animation) { }
|
@Override public void onAnimationRepeat(Animation animation) { }
|
||||||
@Override public void onAnimationEnd(Animation animation) {
|
@Override public void onAnimationEnd(Animation animation) {
|
||||||
progress.setVisibility(View.GONE);
|
getProgressWheel().setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
progress.startAnimation(animation);
|
getProgressWheel().startAnimation(animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SlideDeckListener implements FutureTaskListener<SlideDeck> {
|
private class SlideDeckListener implements FutureTaskListener<SlideDeck> {
|
||||||
@ -300,7 +331,7 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PduThumbnailSetListener implements RequestListener<Object, GlideDrawable> {
|
private class PduThumbnailSetListener implements RequestListener<Object, GlideDrawable> {
|
||||||
private PduPart part;
|
private PduPart part;
|
||||||
|
|
||||||
public PduThumbnailSetListener(@NonNull PduPart part) {
|
public PduThumbnailSetListener(@NonNull PduPart part) {
|
||||||
@ -318,6 +349,11 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
Log.w(TAG, "onResourceReady() for a Bitmap. Saving.");
|
Log.w(TAG, "onResourceReady() for a Bitmap. Saving.");
|
||||||
part.setThumbnail(((GlideBitmapDrawable)resource).getBitmap());
|
part.setThumbnail(((GlideBitmapDrawable)resource).getBitmap());
|
||||||
}
|
}
|
||||||
|
if (resource.getIntrinsicWidth() < resource.getIntrinsicHeight()) {
|
||||||
|
getRemoveButton().setPadding(0, 0, (getWidth() - resource.getIntrinsicWidth()) / 2, 0);
|
||||||
|
} else {
|
||||||
|
getRemoveButton().setPadding(0, (getHeight() - resource.getIntrinsicHeight()) / 2, 0, 0);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ import android.util.Log;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.animation.AlphaAnimation;
|
import android.view.animation.AlphaAnimation;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
@ -48,7 +47,6 @@ public class AttachmentManager {
|
|||||||
private final Context context;
|
private final Context context;
|
||||||
private final View attachmentView;
|
private final View attachmentView;
|
||||||
private final ThumbnailView thumbnail;
|
private final ThumbnailView thumbnail;
|
||||||
private final ImageView removeButton;
|
|
||||||
private final SlideDeck slideDeck;
|
private final SlideDeck slideDeck;
|
||||||
private final AttachmentListener attachmentListener;
|
private final AttachmentListener attachmentListener;
|
||||||
|
|
||||||
@ -57,12 +55,11 @@ public class AttachmentManager {
|
|||||||
public AttachmentManager(Activity view, AttachmentListener listener) {
|
public AttachmentManager(Activity view, AttachmentListener listener) {
|
||||||
this.attachmentView = view.findViewById(R.id.attachment_editor);
|
this.attachmentView = view.findViewById(R.id.attachment_editor);
|
||||||
this.thumbnail = (ThumbnailView)view.findViewById(R.id.attachment_thumbnail);
|
this.thumbnail = (ThumbnailView)view.findViewById(R.id.attachment_thumbnail);
|
||||||
this.removeButton = (ImageView)view.findViewById(R.id.remove_image_button);
|
|
||||||
this.slideDeck = new SlideDeck();
|
this.slideDeck = new SlideDeck();
|
||||||
this.context = view;
|
this.context = view;
|
||||||
this.attachmentListener = listener;
|
this.attachmentListener = listener;
|
||||||
|
|
||||||
this.removeButton.setOnClickListener(new RemoveButtonListener());
|
thumbnail.setRemoveClickListener(new RemoveButtonListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
@ -76,7 +73,6 @@ public class AttachmentManager {
|
|||||||
attachmentView.setVisibility(View.GONE);
|
attachmentView.setVisibility(View.GONE);
|
||||||
attachmentListener.onAttachmentChanged();
|
attachmentListener.onAttachmentChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
attachmentView.startAnimation(animation);
|
attachmentView.startAnimation(animation);
|
||||||
|
@ -18,12 +18,14 @@ package org.thoughtcrime.securesms.util;
|
|||||||
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.support.annotation.DrawableRes;
|
import android.support.annotation.DrawableRes;
|
||||||
|
import android.support.annotation.IdRes;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.TextUtils.TruncateAt;
|
import android.text.TextUtils.TruncateAt;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewStub;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class ViewUtil {
|
public class ViewUtil {
|
||||||
@ -61,4 +63,9 @@ public class ViewUtil {
|
|||||||
TruncateAt.END);
|
TruncateAt.END);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T extends View> T inflateStub(@NonNull View parent, @IdRes int stubId) {
|
||||||
|
return (T)((ViewStub)parent.findViewById(stubId)).inflate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user