Added functionality to stop upload/download Documents
This commit is contained in:
parent
28c280947f
commit
69c2327a3d
4 changed files with 204 additions and 103 deletions
|
@ -26,25 +26,33 @@ import org.thoughtcrime.securesms.database.AttachmentTable;
|
|||
import org.thoughtcrime.securesms.events.PartProgressEvent;
|
||||
import org.thoughtcrime.securesms.mms.Slide;
|
||||
import org.thoughtcrime.securesms.mms.SlideClickListener;
|
||||
import org.thoughtcrime.securesms.mms.SlidesClickedListener;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.signalservice.api.util.OptionalUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class DocumentView extends FrameLayout {
|
||||
|
||||
private static final String TAG = Log.tag(DocumentView.class);
|
||||
|
||||
private final @NonNull AnimatingToggle controlToggle;
|
||||
private final @NonNull ImageView downloadButton;
|
||||
private final @NonNull ImageView uploadButton;
|
||||
private final @NonNull ImageView stopUploadButton;
|
||||
private final @NonNull ProgressWheel downloadProgress;
|
||||
private final @NonNull View container;
|
||||
private final @NonNull ViewGroup iconContainer;
|
||||
private final @NonNull ViewGroup progressContainer;
|
||||
private final @NonNull TextView fileName;
|
||||
private final @NonNull TextView fileSize;
|
||||
private final @NonNull TextView document;
|
||||
|
||||
private @Nullable SlideClickListener downloadListener;
|
||||
private @Nullable SlideClickListener viewListener;
|
||||
private @Nullable Slide documentSlide;
|
||||
private @Nullable SlideClickListener downloadListener;
|
||||
private @Nullable SlideClickListener viewListener;
|
||||
private @Nullable SlidesClickedListener cancelTransferClickListener;
|
||||
private @Nullable SlidesClickedListener resendTransferClickListener;
|
||||
private @Nullable Slide documentSlide;
|
||||
|
||||
public DocumentView(@NonNull Context context) {
|
||||
this(context, null);
|
||||
|
@ -60,8 +68,11 @@ public class DocumentView extends FrameLayout {
|
|||
|
||||
this.container = findViewById(R.id.document_container);
|
||||
this.iconContainer = findViewById(R.id.icon_container);
|
||||
this.progressContainer = findViewById(R.id.progress_container);
|
||||
this.controlToggle = findViewById(R.id.control_toggle);
|
||||
this.downloadButton = findViewById(R.id.download);
|
||||
this.uploadButton = findViewById(R.id.upload);
|
||||
this.stopUploadButton = findViewById(R.id.stop_upload);
|
||||
this.downloadProgress = findViewById(R.id.download_progress);
|
||||
this.fileName = findViewById(R.id.file_name);
|
||||
this.fileSize = findViewById(R.id.file_size);
|
||||
|
@ -89,17 +100,31 @@ public class DocumentView extends FrameLayout {
|
|||
this.viewListener = listener;
|
||||
}
|
||||
|
||||
public void setCancelTransferClickListener(@Nullable SlidesClickedListener listener) {
|
||||
this.cancelTransferClickListener = listener;
|
||||
}
|
||||
|
||||
public void setResendTransferClickListener(@Nullable SlidesClickedListener listener) {
|
||||
this.resendTransferClickListener = listener;
|
||||
}
|
||||
|
||||
public void setDocument(final @NonNull Slide documentSlide,
|
||||
final boolean showControls,
|
||||
final boolean showSingleLineFilename)
|
||||
final boolean showSingleLineFilename,
|
||||
final boolean isSender)
|
||||
{
|
||||
if (showControls && documentSlide.isPendingDownload()) {
|
||||
if (showControls && documentSlide.isPendingDownload() && !isSender) {
|
||||
controlToggle.displayQuick(downloadButton);
|
||||
downloadButton.setOnClickListener(new DownloadClickedListener(documentSlide));
|
||||
if (downloadProgress.isSpinning()) downloadProgress.stopSpinning();
|
||||
} else if (showControls && documentSlide.isPendingDownload() && isSender) {
|
||||
controlToggle.displayQuick(uploadButton);
|
||||
uploadButton.setOnClickListener(new ResendTransferClickListener(documentSlide));
|
||||
if (downloadProgress.isSpinning()) downloadProgress.stopSpinning();
|
||||
} else if (showControls && documentSlide.getTransferState() == AttachmentTable.TRANSFER_PROGRESS_STARTED) {
|
||||
controlToggle.displayQuick(downloadProgress);
|
||||
controlToggle.displayQuick(progressContainer);
|
||||
downloadProgress.spin();
|
||||
stopUploadButton.setOnClickListener(new CancelTransferListener(documentSlide));
|
||||
} else {
|
||||
controlToggle.displayQuick(iconContainer);
|
||||
if (downloadProgress.isSpinning()) downloadProgress.stopSpinning();
|
||||
|
@ -120,12 +145,6 @@ public class DocumentView extends FrameLayout {
|
|||
this.setOnClickListener(new OpenClickedListener(documentSlide));
|
||||
}
|
||||
|
||||
public void setDocument(final @NonNull Slide documentSlide,
|
||||
final boolean showControls)
|
||||
{
|
||||
setDocument(documentSlide, showControls, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocusable(boolean focusable) {
|
||||
super.setFocusable(focusable);
|
||||
|
@ -179,4 +198,38 @@ public class DocumentView extends FrameLayout {
|
|||
}
|
||||
}
|
||||
|
||||
private class CancelTransferListener implements View.OnClickListener {
|
||||
private final @NonNull Slide slide;
|
||||
|
||||
private CancelTransferListener(@NonNull Slide slide) {
|
||||
this.slide = slide;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (cancelTransferClickListener != null) {
|
||||
cancelTransferClickListener.onClick(v, Collections.singletonList(slide));
|
||||
} else {
|
||||
Log.w(TAG, "Received a cancel button click, but unable to execute it. slide: " + slide);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ResendTransferClickListener implements View.OnClickListener {
|
||||
private final @NonNull Slide slide;
|
||||
|
||||
private ResendTransferClickListener(@NonNull Slide slide) {
|
||||
this.slide = slide;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (resendTransferClickListener != null) {
|
||||
resendTransferClickListener.onClick(v, Collections.singletonList(slide));
|
||||
} else {
|
||||
Log.w(TAG, "Received a cancel button click, but unable to execute it. slide: " + slide);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1263,11 +1263,14 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
|
|||
|
||||
//noinspection ConstantConditions
|
||||
documentViewStub.get().setDocument(
|
||||
((MmsMessageRecord) messageRecord).getSlideDeck().getDocumentSlide(),
|
||||
((MmsMessageRecord) messageRecord).getSlideDeck() .getDocumentSlide(),
|
||||
showControls,
|
||||
displayMode != ConversationItemDisplayMode.Detailed.INSTANCE
|
||||
displayMode != ConversationItemDisplayMode.Detailed.INSTANCE,
|
||||
messageRecord.isOutgoing()
|
||||
);
|
||||
documentViewStub.get().setDocumentClickListener(new ThumbnailClickListener());
|
||||
documentViewStub.get().setCancelTransferClickListener(attachmentCancelClickListener);
|
||||
documentViewStub.get().setResendTransferClickListener(new ResendClickListener(messageRecord));
|
||||
documentViewStub.get().setDownloadClickListener(singleDownloadClickListener);
|
||||
documentViewStub.get().setOnLongClickListener(passthroughClickListener);
|
||||
|
||||
|
|
|
@ -1,106 +1,146 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:viewBindingIgnore="true"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context="org.thoughtcrime.securesms.components.DocumentView">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="org.thoughtcrime.securesms.components.DocumentView"
|
||||
tools:viewBindingIgnore="true">
|
||||
|
||||
<LinearLayout android:id="@+id/document_container"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
<LinearLayout
|
||||
android:id="@+id/document_container"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<org.thoughtcrime.securesms.components.AnimatingToggle
|
||||
android:id="@+id/control_toggle"
|
||||
<org.thoughtcrime.securesms.components.AnimatingToggle
|
||||
android:id="@+id/control_toggle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:gravity="center">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/progress_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:gravity="center"
|
||||
android:visibility="gone">
|
||||
|
||||
<com.pnikosis.materialishprogress.ProgressWheel
|
||||
android:id="@+id/download_progress"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="center"
|
||||
android:clickable="false"
|
||||
android:visibility="visible"
|
||||
app:matProg_barColor="@color/white"
|
||||
app:matProg_linearProgress="true"
|
||||
app:matProg_spinSpeed="0.333"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/stop_upload"
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:layout_gravity="center"
|
||||
android:clickable="true"
|
||||
android:contentDescription="@string/document_view__cancel_accessibility_description"
|
||||
android:src="@drawable/transfer_controls_stop_icon"
|
||||
android:visibility="visible" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/icon_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="-4dp"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:gravity="center"
|
||||
android:visibility="visible">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="38dp"
|
||||
android:layout_height="50dp"
|
||||
android:src="@drawable/ic_document_large" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/document"
|
||||
style="@style/Signal.Text.Caption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:gravity="center">
|
||||
android:gravity="center"
|
||||
android:scaleType="centerInside"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/core_black"
|
||||
android:textSize="10sp"
|
||||
android:visibility="visible"
|
||||
tools:text="PDF"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<com.pnikosis.materialishprogress.ProgressWheel
|
||||
android:id="@+id/download_progress"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:visibility="gone"
|
||||
android:clickable="false"
|
||||
android:layout_gravity="center"
|
||||
app:matProg_barColor="@color/white"
|
||||
app:matProg_linearProgress="true"
|
||||
app:matProg_spinSpeed="0.333"
|
||||
tools:visibility="gone"/>
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/icon_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="-4dp"
|
||||
android:gravity="center"
|
||||
android:visibility="visible"
|
||||
android:clickable="false"
|
||||
android:focusable="false">
|
||||
<ImageView
|
||||
android:id="@+id/download"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="@drawable/circle_touch_highlight_background"
|
||||
android:clickable="true"
|
||||
android:contentDescription="@string/document_view__download_accessibility_description"
|
||||
android:src="@drawable/download_attachment"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="38dp"
|
||||
android:layout_height="50dp"
|
||||
android:src="@drawable/ic_document_large"/>
|
||||
<ImageView
|
||||
android:id="@+id/upload"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="@drawable/circle_touch_highlight_background"
|
||||
android:clickable="true"
|
||||
android:contentDescription="@string/document_view__upload_accessibility_description"
|
||||
android:rotation="180"
|
||||
android:src="@drawable/download_attachment"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView android:id="@+id/document"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:clickable="false"
|
||||
android:visibility="visible"
|
||||
android:textAlignment="center"
|
||||
android:scaleType="centerInside"
|
||||
style="@style/Signal.Text.Caption"
|
||||
android:textSize="10sp"
|
||||
android:textColor="@color/core_black"
|
||||
tools:visibility="visible"
|
||||
tools:text="PDF" />
|
||||
</org.thoughtcrime.securesms.components.AnimatingToggle>
|
||||
|
||||
</FrameLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="2dp"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView android:id="@+id/download"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:visibility="gone"
|
||||
android:background="@drawable/circle_touch_highlight_background"
|
||||
android:src="@drawable/download_attachment"
|
||||
android:contentDescription="@string/audio_view__download_accessibility_description"/>
|
||||
<TextView
|
||||
android:id="@+id/file_name"
|
||||
style="@style/Signal.Text.Body"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:ellipsize="end"
|
||||
tools:text="The-Anarchist-Tension-by-Alfredo-Bonanno.pdf" />
|
||||
|
||||
</org.thoughtcrime.securesms.components.AnimatingToggle>
|
||||
|
||||
<LinearLayout android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="2dp"
|
||||
android:orientation="vertical"
|
||||
android:focusable="false"
|
||||
android:clickable="false">
|
||||
|
||||
<TextView android:id="@+id/file_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/Signal.Text.Body"
|
||||
android:clickable="false"
|
||||
android:ellipsize="end"
|
||||
tools:text="The-Anarchist-Tension-by-Alfredo-Bonanno.pdf"/>
|
||||
|
||||
<TextView android:id="@+id/file_size"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/Signal.Text.Caption"
|
||||
android:clickable="false"
|
||||
tools:text="24kb"/>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/file_size"
|
||||
style="@style/Signal.Text.Caption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
tools:text="24kb" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</merge>
|
|
@ -3238,6 +3238,11 @@
|
|||
<string name="audio_view__play_pause_accessibility_description">Play … Pause</string>
|
||||
<string name="audio_view__download_accessibility_description">Download</string>
|
||||
|
||||
<!-- document_view -->
|
||||
<string name="document_view__download_accessibility_description">Download</string>
|
||||
<string name="document_view__upload_accessibility_description">Upload</string>
|
||||
<string name="document_view__cancel_accessibility_description">Cancel</string>
|
||||
|
||||
<!-- QuoteView -->
|
||||
<string name="QuoteView_audio">Audio</string>
|
||||
<string name="QuoteView_video">Video</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue