mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-28 04:34:21 +01:00
Support stop download and upload for documents.
This commit is contained in:
@@ -27,25 +27,30 @@ 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.util.Util;
|
||||
import org.thoughtcrime.securesms.mms.SlidesClickedListener;
|
||||
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 ProgressWheel downloadProgress;
|
||||
private final @NonNull View container;
|
||||
private final @NonNull ViewGroup iconContainer;
|
||||
private final @NonNull ViewGroup stopUploadButton;
|
||||
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);
|
||||
@@ -59,10 +64,11 @@ public class DocumentView extends FrameLayout {
|
||||
super(context, attrs, defStyleAttr);
|
||||
inflate(context, R.layout.document_view, this);
|
||||
|
||||
this.container = findViewById(R.id.document_container);
|
||||
this.iconContainer = findViewById(R.id.icon_container);
|
||||
this.stopUploadButton = findViewById(R.id.stop_upload_progress_container);
|
||||
this.controlToggle = findViewById(R.id.control_toggle);
|
||||
this.downloadButton = findViewById(R.id.download);
|
||||
this.uploadButton = findViewById(R.id.upload);
|
||||
this.downloadProgress = findViewById(R.id.download_progress);
|
||||
this.fileName = findViewById(R.id.file_name);
|
||||
this.fileSize = findViewById(R.id.file_size);
|
||||
@@ -90,17 +96,30 @@ 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)
|
||||
{
|
||||
if (showControls && documentSlide.isPendingDownload()) {
|
||||
if (showControls && documentSlide.getTransferState() == AttachmentTable.TRANSFER_PROGRESS_STARTED) {
|
||||
controlToggle.displayQuick(stopUploadButton);
|
||||
downloadProgress.spin();
|
||||
stopUploadButton.setOnClickListener(new CancelTransferListener(documentSlide));
|
||||
} else if (showControls && documentSlide.getUri() != null && documentSlide.isPendingDownload()) {
|
||||
controlToggle.displayQuick(uploadButton);
|
||||
uploadButton.setOnClickListener(new ResendTransferClickListener(documentSlide));
|
||||
if (downloadProgress.isSpinning()) downloadProgress.stopSpinning();
|
||||
} else if (showControls && documentSlide.getUri() == null && documentSlide.isPendingDownload()) {
|
||||
controlToggle.displayQuick(downloadButton);
|
||||
downloadButton.setOnClickListener(new DownloadClickedListener(documentSlide));
|
||||
if (downloadProgress.isSpinning()) downloadProgress.stopSpinning();
|
||||
} else if (showControls && documentSlide.getTransferState() == AttachmentTable.TRANSFER_PROGRESS_STARTED) {
|
||||
controlToggle.displayQuick(downloadProgress);
|
||||
downloadProgress.spin();
|
||||
} else {
|
||||
controlToggle.displayQuick(iconContainer);
|
||||
if (downloadProgress.isSpinning()) downloadProgress.stopSpinning();
|
||||
@@ -121,12 +140,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);
|
||||
@@ -180,4 +193,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1267,6 +1267,8 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
|
||||
displayMode != ConversationItemDisplayMode.Detailed.INSTANCE
|
||||
);
|
||||
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,151 @@
|
||||
<?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/stop_upload_progress_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="@drawable/circle_touch_highlight_background"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
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="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_gravity="center"
|
||||
android:clickable="false"
|
||||
android:contentDescription="@string/document_view__cancel_accessibility_description"
|
||||
android:focusable="false"
|
||||
android:src="@drawable/transfer_controls_stop_icon"
|
||||
tools: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:contentDescription="@string/DocumentView_document_file"
|
||||
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:focusable="true"
|
||||
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:focusable="true"
|
||||
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>
|
||||
@@ -1156,6 +1156,7 @@
|
||||
|
||||
<!-- DocumentView -->
|
||||
<string name="DocumentView_unnamed_file">Unnamed file</string>
|
||||
<string name="DocumentView_document_file">Document file</string>
|
||||
|
||||
<!-- DozeReminder -->
|
||||
<string name="DozeReminder_optimize_for_missing_play_services">Optimize for missing Play Services</string>
|
||||
@@ -3394,6 +3395,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>
|
||||
|
||||
Reference in New Issue
Block a user