mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-21 20:51:31 +00:00
parent
f95435b0f1
commit
415a61a09b
@ -9,23 +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" />
|
||||||
|
|
||||||
<ViewStub android:id="@+id/progress_wheel_stub"
|
<ViewStub android:id="@+id/transfer_controls_stub"
|
||||||
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:layout="@layout/transfer_controls_stub" />
|
||||||
|
|
||||||
<ViewStub android:id="@+id/remove_button_stub"
|
<ViewStub android:id="@+id/remove_button_stub"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="top|right"
|
android:layout_gravity="top|right"
|
||||||
android:layout="@layout/thumbnail_view_remove_button" />
|
android:layout="@layout/thumbnail_view_remove_button" />
|
||||||
|
|
||||||
<ImageButton android:id="@+id/download_button"
|
|
||||||
android:layout_width="70dp"
|
|
||||||
android:layout_height="70dp"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:background="@drawable/progress_background"
|
|
||||||
android:src="@drawable/ic_file_download_white_36dp"
|
|
||||||
android:visibility="gone" />
|
|
||||||
</merge>
|
</merge>
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
<?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" />
|
|
8
res/layout/transfer_controls_stub.xml
Normal file
8
res/layout/transfer_controls_stub.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<org.thoughtcrime.securesms.components.TransferControlView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/transfer_controls"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
22
res/layout/transfer_controls_view.xml
Normal file
22
res/layout/transfer_controls_view.xml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<com.pnikosis.materialishprogress.ProgressWheel
|
||||||
|
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" />
|
||||||
|
|
||||||
|
<ImageButton android:id="@+id/download_button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:background="@drawable/progress_background"
|
||||||
|
android:src="@drawable/ic_file_download_white_36dp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
</merge>
|
@ -2,22 +2,19 @@ package org.thoughtcrime.securesms.components;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.AnimationSet;
|
|
||||||
import android.view.animation.AnimationUtils;
|
import android.view.animation.AnimationUtils;
|
||||||
import android.view.animation.TranslateAnimation;
|
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
|
||||||
public class AnimatingToggle extends FrameLayout {
|
public class AnimatingToggle extends FrameLayout {
|
||||||
|
|
||||||
private static final int SPEED_MILLIS = 200;
|
|
||||||
|
|
||||||
private View current;
|
private View current;
|
||||||
|
|
||||||
public AnimatingToggle(Context context) {
|
public AnimatingToggle(Context context) {
|
||||||
@ -45,11 +42,20 @@ public class AnimatingToggle extends FrameLayout {
|
|||||||
child.setClickable(false);
|
child.setClickable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void display(View view) {
|
public void display(@Nullable View view) {
|
||||||
|
display(view, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void display(@Nullable View view, boolean animated) {
|
||||||
if (view == current) return;
|
if (view == current) return;
|
||||||
|
|
||||||
animateOut(current, AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_out));
|
if (animated) {
|
||||||
animateIn(view, AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_in));
|
if (current != null) animateOut(current, AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_out));
|
||||||
|
if (view != null) animateIn(view, AnimationUtils.loadAnimation(getContext(), R.anim.animation_toggle_in));
|
||||||
|
} else {
|
||||||
|
if (current != null) current.setVisibility(GONE);
|
||||||
|
if (view != null) view.setVisibility(VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
current = view;
|
current = view;
|
||||||
}
|
}
|
||||||
@ -78,12 +84,4 @@ public class AnimatingToggle extends FrameLayout {
|
|||||||
view.setVisibility(View.VISIBLE);
|
view.setVisibility(View.VISIBLE);
|
||||||
view.startAnimation(animation);
|
view.startAnimation(animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getViewIndex(View view) {
|
|
||||||
for (int i=0;i<getChildCount();i++) {
|
|
||||||
if (getChildAt(i) == view) return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalArgumentException("Not a parent of this view.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,7 @@ import android.support.annotation.Nullable;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.animation.AlphaAnimation;
|
|
||||||
import android.view.animation.Animation;
|
|
||||||
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;
|
||||||
@ -26,12 +22,10 @@ import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable;
|
|||||||
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
|
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
|
||||||
import com.bumptech.glide.request.RequestListener;
|
import com.bumptech.glide.request.RequestListener;
|
||||||
import com.bumptech.glide.request.target.Target;
|
import com.bumptech.glide.request.target.Target;
|
||||||
import com.pnikosis.materialishprogress.ProgressWheel;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||||
import org.thoughtcrime.securesms.database.PartDatabase;
|
import org.thoughtcrime.securesms.database.PartDatabase;
|
||||||
import org.thoughtcrime.securesms.jobs.PartProgressEvent;
|
|
||||||
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri;
|
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri;
|
||||||
import org.thoughtcrime.securesms.mms.RoundedCorners;
|
import org.thoughtcrime.securesms.mms.RoundedCorners;
|
||||||
import org.thoughtcrime.securesms.mms.Slide;
|
import org.thoughtcrime.securesms.mms.Slide;
|
||||||
@ -41,7 +35,6 @@ 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 org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
|
|
||||||
import de.greenrobot.event.EventBus;
|
|
||||||
import ws.com.google.android.mms.pdu.PduPart;
|
import ws.com.google.android.mms.pdu.PduPart;
|
||||||
|
|
||||||
public class ThumbnailView extends FrameLayout {
|
public class ThumbnailView extends FrameLayout {
|
||||||
@ -49,9 +42,8 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
|
|
||||||
private boolean hideControls;
|
private boolean hideControls;
|
||||||
private ImageView image;
|
private ImageView image;
|
||||||
private ProgressWheel progress;
|
|
||||||
private ImageView removeButton;
|
private ImageView removeButton;
|
||||||
private ImageButton downloadButton;
|
private TransferControlView transferControls;
|
||||||
private int backgroundColorHint;
|
private int backgroundColorHint;
|
||||||
private int radius;
|
private int radius;
|
||||||
|
|
||||||
@ -75,11 +67,6 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
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);
|
|
||||||
downloadButton = (ImageButton) findViewById(R.id.download_button);
|
|
||||||
|
|
||||||
setOnClickListener(new ThumbnailClickDispatcher());
|
|
||||||
downloadButton.setOnClickListener(new DownloadClickDispatcher());
|
|
||||||
|
|
||||||
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);
|
||||||
@ -97,40 +84,15 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onAttachedToWindow() {
|
|
||||||
super.onAttachedToWindow();
|
|
||||||
if (!EventBus.getDefault().isRegistered(this)) EventBus.getDefault().registerSticky(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override protected void onDetachedFromWindow() {
|
|
||||||
super.onDetachedFromWindow();
|
|
||||||
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() {
|
private ImageView getRemoveButton() {
|
||||||
if (removeButton == null) removeButton = ViewUtil.inflateStub(this, R.id.remove_button_stub);
|
if (removeButton == null) removeButton = ViewUtil.inflateStub(this, R.id.remove_button_stub);
|
||||||
return removeButton;
|
return removeButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
private TransferControlView getTransferControls() {
|
||||||
public void onEventAsync(final PartProgressEvent event) {
|
if (transferControls == null) transferControls = ViewUtil.inflateStub(this, R.id.transfer_controls_stub);
|
||||||
if (this.slide != null && event.partId.equals(this.slide.getPart().getPartId())) {
|
|
||||||
Util.runOnMain(new Runnable() {
|
return transferControls;
|
||||||
@Override public void run() {
|
|
||||||
getProgressWheel().setInstantProgress(((float)event.progress) / event.total);
|
|
||||||
if (event.progress >= event.total) animateOutProgress();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBackgroundColorHint(int color) {
|
public void setBackgroundColorHint(int color) {
|
||||||
@ -148,7 +110,7 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
String slideId = id + "::" + timestamp;
|
String slideId = id + "::" + timestamp;
|
||||||
|
|
||||||
if (!slideId.equals(this.slideId)) {
|
if (!slideId.equals(this.slideId)) {
|
||||||
hideProgressWheel();
|
if (transferControls != null) transferControls.clear();
|
||||||
image.setImageDrawable(null);
|
image.setImageDrawable(null);
|
||||||
this.slide = null;
|
this.slide = null;
|
||||||
this.slideId = slideId;
|
this.slideId = slideId;
|
||||||
@ -170,22 +132,21 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log.w(TAG, "loading part with id " + slide.getPart().getPartId() + ", progress " + slide.getTransferProgress());
|
Log.w(TAG, "loading part with id " + slide.getPart().getPartId() + ", progress " + slide.getTransferProgress());
|
||||||
if (!hideControls && slide.getTransferProgress() == PartDatabase.TRANSFER_PROGRESS_STARTED) {
|
|
||||||
getProgressWheel().spin();
|
|
||||||
getProgressWheel().setVisibility(VISIBLE);
|
|
||||||
downloadButton.setVisibility(GONE);
|
|
||||||
} else if (!hideControls && slide.getTransferProgress() == PartDatabase.TRANSFER_PROGRESS_AUTO_PENDING ||
|
|
||||||
slide.getTransferProgress() == PartDatabase.TRANSFER_PROGRESS_FAILED)
|
|
||||||
{
|
|
||||||
hideProgressWheel();
|
|
||||||
downloadButton.setVisibility(VISIBLE);
|
|
||||||
} else {
|
|
||||||
hideProgressWheel();
|
|
||||||
downloadButton.setVisibility(GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.slide = slide;
|
this.slide = slide;
|
||||||
buildGlideRequest(slide, masterSecret).into(image);
|
buildGlideRequest(slide, masterSecret).into(image);
|
||||||
|
|
||||||
|
if (this.slide.getTransferProgress() == PartDatabase.TRANSFER_PROGRESS_DONE) {
|
||||||
|
setOnClickListener(new ThumbnailClickDispatcher());
|
||||||
|
} else {
|
||||||
|
setOnClickListener(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hideControls) {
|
||||||
|
getTransferControls().setSlide(slide);
|
||||||
|
getTransferControls().setDownloadClickListener(new DownloadClickDispatcher());
|
||||||
|
getTransferControls().setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThumbnailClickListener(ThumbnailClickListener listener) {
|
public void setThumbnailClickListener(ThumbnailClickListener listener) {
|
||||||
@ -203,6 +164,7 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
public void clear() {
|
public void clear() {
|
||||||
if (isContextValid()) Glide.clear(image);
|
if (isContextValid()) Glide.clear(image);
|
||||||
if (slideDeckFuture != null) slideDeckFuture.removeListener(slideDeckListener);
|
if (slideDeckFuture != null) slideDeckFuture.removeListener(slideDeckListener);
|
||||||
|
if (transferControls != null) transferControls.clear();
|
||||||
slide = null;
|
slide = null;
|
||||||
slideId = null;
|
slideId = null;
|
||||||
slideDeckFuture = null;
|
slideDeckFuture = null;
|
||||||
@ -211,12 +173,11 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
|
|
||||||
public void hideControls(boolean hideControls) {
|
public void hideControls(boolean hideControls) {
|
||||||
this.hideControls = hideControls;
|
this.hideControls = hideControls;
|
||||||
if (hideControls) hideProgressWheel();
|
if (hideControls && transferControls != null) transferControls.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showProgressSpinner() {
|
public void showProgressSpinner() {
|
||||||
getProgressWheel().spin();
|
getTransferControls().showProgressSpinner();
|
||||||
getProgressWheel().setVisibility(VISIBLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(VERSION_CODES.JELLY_BEAN_MR1)
|
@TargetApi(VERSION_CODES.JELLY_BEAN_MR1)
|
||||||
@ -276,20 +237,6 @@ public class ThumbnailView extends FrameLayout {
|
|||||||
.fitCenter();
|
.fitCenter();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void animateOutProgress() {
|
|
||||||
if (progress == null) return;
|
|
||||||
AlphaAnimation animation = new AlphaAnimation(1f, 0f);
|
|
||||||
animation.setDuration(200);
|
|
||||||
animation.setAnimationListener(new AnimationListener() {
|
|
||||||
@Override public void onAnimationStart(Animation animation) { }
|
|
||||||
@Override public void onAnimationRepeat(Animation animation) { }
|
|
||||||
@Override public void onAnimationEnd(Animation animation) {
|
|
||||||
getProgressWheel().setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
getProgressWheel().startAnimation(animation);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SlideDeckListener implements FutureTaskListener<SlideDeck> {
|
private class SlideDeckListener implements FutureTaskListener<SlideDeck> {
|
||||||
private final MasterSecret masterSecret;
|
private final MasterSecret masterSecret;
|
||||||
|
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
package org.thoughtcrime.securesms.components;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.widget.ImageButton;
|
||||||
|
|
||||||
|
import com.pnikosis.materialishprogress.ProgressWheel;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.R;
|
||||||
|
import org.thoughtcrime.securesms.database.PartDatabase;
|
||||||
|
import org.thoughtcrime.securesms.jobs.PartProgressEvent;
|
||||||
|
import org.thoughtcrime.securesms.mms.Slide;
|
||||||
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
|
|
||||||
|
import de.greenrobot.event.EventBus;
|
||||||
|
|
||||||
|
public class TransferControlView extends AnimatingToggle {
|
||||||
|
private Slide slide;
|
||||||
|
private ProgressWheel progressWheel;
|
||||||
|
private ImageButton downloadButton;
|
||||||
|
|
||||||
|
public TransferControlView(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TransferControlView(Context context, AttributeSet attrs) {
|
||||||
|
this(context, attrs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TransferControlView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
inflate(context, R.layout.transfer_controls_view, this);
|
||||||
|
this.progressWheel = ViewUtil.findById(this, R.id.progress_wheel);
|
||||||
|
this.downloadButton = ViewUtil.findById(this, R.id.download_button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected void onAttachedToWindow() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
if (!EventBus.getDefault().isRegistered(this)) EventBus.getDefault().registerSticky(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
EventBus.getDefault().unregister(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSlide(final @NonNull Slide slide) {
|
||||||
|
this.slide = slide;
|
||||||
|
|
||||||
|
if (slide.getTransferProgress() == PartDatabase.TRANSFER_PROGRESS_STARTED) {
|
||||||
|
showProgressSpinner();
|
||||||
|
} else if (slide.isPendingDownload()) {
|
||||||
|
display(downloadButton);
|
||||||
|
} else {
|
||||||
|
display(null, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showProgressSpinner() {
|
||||||
|
progressWheel.spin();
|
||||||
|
display(progressWheel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownloadClickListener(final @Nullable OnClickListener listener) {
|
||||||
|
downloadButton.setOnClickListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
display(null, false);
|
||||||
|
slide = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public void onEventAsync(final PartProgressEvent event) {
|
||||||
|
if (this.slide != null && event.partId.equals(this.slide.getPart().getPartId())) {
|
||||||
|
Util.runOnMain(new Runnable() {
|
||||||
|
@Override public void run() {
|
||||||
|
progressWheel.setInstantProgress(((float)event.progress) / event.total);
|
||||||
|
if (event.progress >= event.total) display(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,7 @@ import android.support.annotation.Nullable;
|
|||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||||
|
import org.thoughtcrime.securesms.database.PartDatabase;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -74,6 +75,11 @@ public abstract class Slide {
|
|||||||
return part.isInProgress();
|
return part.isInProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPendingDownload() {
|
||||||
|
return getTransferProgress() == PartDatabase.TRANSFER_PROGRESS_FAILED ||
|
||||||
|
getTransferProgress() == PartDatabase.TRANSFER_PROGRESS_AUTO_PENDING;
|
||||||
|
}
|
||||||
|
|
||||||
public long getTransferProgress() {
|
public long getTransferProgress() {
|
||||||
return part.getTransferProgress();
|
return part.getTransferProgress();
|
||||||
}
|
}
|
||||||
|
@ -68,4 +68,9 @@ public class ViewUtil {
|
|||||||
public static <T extends View> T inflateStub(@NonNull View parent, @IdRes int stubId) {
|
public static <T extends View> T inflateStub(@NonNull View parent, @IdRes int stubId) {
|
||||||
return (T)((ViewStub)parent.findViewById(stubId)).inflate();
|
return (T)((ViewStub)parent.findViewById(stubId)).inflate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T extends View> T findById(@NonNull View parent, @IdRes int resId) {
|
||||||
|
return (T) parent.findViewById(resId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user