Skip to content

Commit bcd63a8

Browse files
Give a video and a piece of music a download of their own
A video and a piece of music are the two worth having on the phone before they are wanted, and the two whose downloads run long enough to be worth stopping. Neither could be asked for on its own. Pressing the message is all there was, and pressing it does something else: it opens the viewer, and streams what has not arrived, or it starts playing. Keeping the file was only ever a side effect of watching or listening to it, and stopping the download was reachable only in the states where pressing the message happened to mean cancel. Both are now an action of their own, on a video and on a piece of music that is not already on the phone. While the file is on its way the action cancels it; where it was never started, or was stopped part of the way through, the action fetches it, and only fetches it: nothing is opened and nothing is played. A download taken up again carries on from where it was stopped, as it does for the button that is drawn. The action is not offered for what is already here, nor for a message still on its way out.
1 parent 62b56a0 commit bcd63a8

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17237,6 +17237,52 @@ private int getMiniIconForCurrentState() {
1723717237
}
1723817238
}
1723917239

17240+
// a video and a piece of music are the two that are worth having on the phone before they are
17241+
// wanted, and the two whose downloads are long enough to be worth stopping. Everything else
17242+
// arrives before there is anything to say about it.
17243+
private boolean hasMediaDownloadAction() {
17244+
if (currentMessageObject == null || documentAttach == null) {
17245+
return false;
17246+
}
17247+
if (documentAttachType != DOCUMENT_ATTACH_TYPE_VIDEO && documentAttachType != DOCUMENT_ATTACH_TYPE_MUSIC) {
17248+
return false;
17249+
}
17250+
if (currentMessageObject.isSending() || currentMessageObject.isEditing() || currentMessageObject.isSendError()) {
17251+
return false;
17252+
}
17253+
// what is already on the phone has nothing left to download
17254+
return !currentMessageObject.mediaExists && !currentMessageObject.attachPathExists;
17255+
}
17256+
17257+
private boolean isMediaDownloading() {
17258+
return FileLoader.getInstance(currentAccount).isLoadingFile(FileLoader.getAttachFileName(documentAttach));
17259+
}
17260+
17261+
// pressing the message plays what it holds, and streams it where it can, which is not the same
17262+
// as keeping it: this only fetches the file, and stops fetching it, and says which of the two
17263+
// it is about to do. A download taken up again carries on from where it was stopped, as it
17264+
// does for the button that is drawn.
17265+
private void performMediaDownloadAction() {
17266+
if (!hasMediaDownloadAction()) {
17267+
return;
17268+
}
17269+
if (isMediaDownloading()) {
17270+
currentMessageObject.loadingCancelled = true;
17271+
FileLoader.getInstance(currentAccount).cancelLoadFile(documentAttach);
17272+
} else {
17273+
currentMessageObject.loadingCancelled = false;
17274+
currentMessageObject.putInDownloadsStore = true;
17275+
if (documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
17276+
FileLoader.getInstance(currentAccount).loadFile(documentAttach, currentMessageObject, FileLoader.PRIORITY_NORMAL_UP, 0);
17277+
} else {
17278+
FileLoader.getInstance(currentAccount).loadFile(documentAttach, currentMessageObject, FileLoader.PRIORITY_NORMAL, currentMessageObject.shouldEncryptPhotoOrVideo() ? 2 : 0);
17279+
}
17280+
createLoadingProgressLayout(documentAttach);
17281+
}
17282+
updateButtonState(false, true, false);
17283+
invalidate();
17284+
}
17285+
1724017286
private int getIconForCurrentState() {
1724117287
if (currentMessageObject == null || currentMessageObject.hasExtendedMedia()) {
1724217288
return MediaActionDrawable.ICON_NONE;
@@ -26590,6 +26636,8 @@ public boolean performAccessibilityAction(int action, Bundle arguments) {
2659026636
return true;
2659126637
} else if (action == R.id.acc_action_small_button) {
2659226638
didPressMiniButton(true);
26639+
} else if (action == R.id.acc_action_download) {
26640+
performMediaDownloadAction();
2659326641
} else if (action == R.id.acc_action_msg_options) {
2659426642
if (delegate != null) {
2659526643
if (currentMessageObject.type == MessageObject.TYPE_PHONE_CALL) {
@@ -27363,6 +27411,9 @@ public void onClick(View view) {
2736327411
}
2736427412
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(AccessibilityNodeInfo.ACTION_CLICK, actionLabel));
2736527413
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(AccessibilityNodeInfo.ACTION_LONG_CLICK, getString("AccActionEnterSelectionMode", R.string.AccActionEnterSelectionMode)));
27414+
if (hasMediaDownloadAction()) {
27415+
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.acc_action_download, getString(isMediaDownloading() ? R.string.AccActionCancelDownload : R.string.AccActionDownload)));
27416+
}
2736627417
int smallIcon = getMiniIconForCurrentState();
2736727418
if (smallIcon == MediaActionDrawable.ICON_DOWNLOAD) {
2736827419
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.acc_action_small_button, getString("AccActionDownload", R.string.AccActionDownload)));

TMessagesProj/src/main/res/values/ids.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<item name="sheet_attached_to_fragment_tag" type="id"/>
2626
<item name="current_animation" type="id"/>
2727
<item name="acc_action_small_button" type="id"/>
28+
<item name="acc_action_download" type="id"/>
2829
<item name="acc_action_msg_options" type="id"/>
2930
<item name="acc_action_open_photo" type="id"/>
3031
<item name="acc_action_chat_preview" type="id"/>

0 commit comments

Comments
 (0)