Skip to content

Commit

Permalink
Video Streaming: implement download indicator for Shared Media (TGX-A…
Browse files Browse the repository at this point in the history
…ndroid#126)

* Update libyuv

Signed-off-by: iTaysonLab <[email protected]>

* Implement download indicator for Shared Media

Signed-off-by: iTaysonLab <[email protected]>
  • Loading branch information
iTaysonLab authored Feb 9, 2022
1 parent bb17994 commit 08229c6
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/jni/thirdparty/libyuv
Submodule libyuv updated from eb6e7b to b4ddba
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import androidx.annotation.Nullable;

import org.thunderdog.challegram.R;
import org.thunderdog.challegram.U;
import org.thunderdog.challegram.loader.ImageReceiver;
import org.thunderdog.challegram.loader.Receiver;
Expand Down Expand Up @@ -254,17 +255,29 @@ protected void onDraw (Canvas c) {
if (scaled) {
c.restore();
}
if (item.isVideo() || item.isGif() || item.getType() == MediaItem.TYPE_VIDEO_MESSAGE) {
item.drawComponents(this, c, 0, 0, getMeasuredWidth(), getMeasuredHeight());
}

boolean isStreamingUI = item.isVideo() && !item.isLoaded();

int textLeft = receiver.getLeft() + Screen.dp(7f);
int textTop = receiver.getTop() + Screen.dp(5f);

if (text != null) {
int textLeft = receiver.getLeft() + Screen.dp(7f);
int textTop = receiver.getTop() + Screen.dp(5f);
RectF rectF = Paints.getRectF();
rectF.set(textLeft - Screen.dp(3f), textTop - Screen.dp(2f), textLeft + textWidth + Screen.dp(3f), textTop + Screen.dp(15f));
rectF.set(textLeft - Screen.dp(3f), textTop - Screen.dp(2f), textLeft + textWidth + Screen.dp(3f) + (isStreamingUI ? Screen.dp(22f) : 0), textTop + Screen.dp(isStreamingUI ? 21f : 15f));

c.drawRoundRect(rectF, Screen.dp(4f), Screen.dp(4f), Paints.fillingPaint(0x4c000000));
c.drawText(text, textLeft, textTop + Screen.dp(11f), Paints.whiteMediumPaint(12f, false, false));
c.drawText(text, textLeft + (isStreamingUI ? Screen.dp(22f) : 0), textTop + Screen.dp(11f) + (isStreamingUI ? Screen.dp(3.5f) : 0), Paints.whiteMediumPaint(12f, false, false)); // TODO

item.getFileProgress().setDownloadedIconRes(FileProgressComponent.PLAY_ICON);
item.getFileProgress().setPausedIconRes(R.drawable.baseline_cloud_download_16);

if (isStreamingUI) {
item.getFileProgress().setVideoStreamingClickRect(false, FileProgressComponent.STREAMING_UI_MODE_EXTRA_SMALL, rectF);
}
}

if (item.isVideo() || item.isGif() || item.getType() == MediaItem.TYPE_VIDEO_MESSAGE) {
item.drawComponents(this, c, 0, 0, getMeasuredWidth(), getMeasuredHeight());
}

if (saved) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ public <T extends View & DrawableProvider> void draw (T view, Canvas c, int star
RectF rectF = Paints.getRectF();
rectF.set(pDurationLeft - Screen.dp(4f), pDurationTop, pDurationRight, pDurationBottom);

getFileProgress().setVideoStreamingClickRect(needTopOffset, isSmallStreamingUI, rectF);
getFileProgress().setVideoStreamingClickRect(needTopOffset, isSmallStreamingUI ? FileProgressComponent.STREAMING_UI_MODE_SMALL : FileProgressComponent.STREAMING_UI_MODE_LARGE, rectF);

if (isSmallStreamingUI) {
getFileProgress().setVideoStreamingProgressIgnore(true);
Expand Down Expand Up @@ -940,6 +940,10 @@ public <T extends View & DrawableProvider> void draw (T view, Canvas c, int star
paint.setAlpha(255);
}

if (showDuration && isDoubleLine) {

}

if (!hideLoader) {
fileProgress.draw(view, c);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,17 +1011,21 @@ public boolean performClick (View view) {
return fileProgress != null && fileProgress.performClick(view);
}

public boolean performClick (View view, float x, float y) {
return fileProgress != null && fileProgress.performClick(view, x, y);
}

public boolean onClick (View view, float x, float y) {
if (fileProgress != null) {
if (isLoaded()) {
int centerX = fileProgress.centerX();
int centerY = fileProgress.centerY();
int bound = Screen.dp(FileProgressComponent.DEFAULT_RADIUS);
if (x >= centerX - bound && x <= centerX + bound && y >= centerY - bound && y <= centerY + bound) {
return fileProgress.performClick(view);
return fileProgress.performClick(view, x, y);
}
} else {
return fileProgress.performClick(view);
return fileProgress.performClick(view, x, y);
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ protected MediaItem parseObject (TdApi.Object object) {
}
MediaItem item = MediaItem.valueOf(context(), tdlib, message);
if (item != null) {
if (item.isVideo() && Config.VIDEO_CLOUD_PLAYBACK_AVAILABLE) {
item.getFileProgress().setVideoStreaming(true);
}

item.setScaleType(ImageFile.CENTER_CROP);
item.setSize(Screen.dp(124f, 3f));
item.setNeedSquare(true);
Expand Down Expand Up @@ -460,8 +464,14 @@ public void onClickAt (View v, float x, float y) {
}

MediaItem mediaItem = (MediaItem) item.getData();
if (mediaItem.isVideo() && (!mediaItem.isLoaded() && !Config.VIDEO_CLOUD_PLAYBACK_AVAILABLE)) {
mediaItem.performClick(v);
if (mediaItem.isVideo()) {
if (mediaItem.isLoaded()) {
MediaViewController.openFromMedia(this, mediaItem);
} else {
if (!mediaItem.performClick(v, x, y)) {
MediaViewController.openFromMedia(this, mediaItem);
}
}
} else if (mediaItem.getType() == MediaItem.TYPE_VIDEO_MESSAGE) {
if (mediaItem.isLoaded()) {
tdlib.context().player().playPauseMessage(tdlib, mediaItem.getMessage(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public class FileProgressComponent implements TdlibFilesManager.FileListener, Fa
public static final float DEFAULT_SMALL_STREAMING_RADIUS = 12f;
public static final float DEFAULT_FILE_RADIUS = 25f;

public static final int STREAMING_UI_MODE_LARGE = 0;
public static final int STREAMING_UI_MODE_SMALL = 1;
public static final int STREAMING_UI_MODE_EXTRA_SMALL = 2;

private static final int INVALIDATE_CONTENT_RECEIVER = 0;
private static final int CHANGE_CURRENT_STATE = 1;
private static final int SET_PROGRESS = 2;
Expand Down Expand Up @@ -124,7 +128,7 @@ public interface SimpleListener {
private boolean isVideoStreaming;
private boolean isVideoStreamingOffsetNeeded;
private boolean isVideoStreamingProgressIgnore;
private boolean isVideoStreamingSmallUi;
private int videoStreamingUiMode;

private float requestedAlpha;

Expand Down Expand Up @@ -169,9 +173,9 @@ public void setVideoStreaming (boolean isVideoStreaming) {
DrawAlgorithms.buildPlayPause(playPausePath, Screen.dp(18f), -1f, playPauseDrawFactor = this.playPauseFactor);
}

public void setVideoStreamingClickRect (boolean topOffsetNeeded, boolean smallUi, RectF videoStreamingRect) {
public void setVideoStreamingClickRect (boolean topOffsetNeeded, int uiMode, RectF videoStreamingRect) {
isVideoStreamingOffsetNeeded = topOffsetNeeded;
isVideoStreamingSmallUi = smallUi;
videoStreamingUiMode = uiMode;
videoStreamingRect.round(this.vsDownloadClickRect);
updateVsRect();
}
Expand All @@ -184,6 +188,10 @@ private boolean isVideoStreaming () {
return isVideoStreaming && !isLoaded();
}

private boolean isVideoStreamingSmallUi () {
return videoStreamingUiMode != STREAMING_UI_MODE_LARGE;
}

public TdApi.File getFile () {
return file;
}
Expand Down Expand Up @@ -555,7 +563,7 @@ public int centerY () {

public int getRadius () {
if (isVideoStreaming()) {
return Math.min(Screen.dp(isVideoStreamingSmallUi ? DEFAULT_SMALL_STREAMING_RADIUS : DEFAULT_STREAMING_RADIUS), Math.min(right - left, bottom - top) / 2);
return Math.min(Screen.dp(videoStreamingUiMode == STREAMING_UI_MODE_LARGE ? DEFAULT_STREAMING_RADIUS : DEFAULT_SMALL_STREAMING_RADIUS), Math.min(right - left, bottom - top) / 2);
}

return Math.min(Screen.dp(fileType == TdlibFilesManager.DOWNLOAD_FLAG_FILE || fileType == TdlibFilesManager.DOWNLOAD_FLAG_MUSIC || fileType == TdlibFilesManager.DOWNLOAD_FLAG_VOICE ? DEFAULT_FILE_RADIUS : DEFAULT_RADIUS), Math.min(right - left, bottom - top) / 2);
Expand Down Expand Up @@ -637,6 +645,12 @@ public boolean performClick (View view) {
return performClick(view, false);
}

public boolean performClick (View view, float x, float y) {
this.startX = (int) x;
this.startY = (int) y;
return performClick(view, false);
}

public boolean performClick (View view, boolean ignoreListener) {
if (ignoreLoaderClicks && !(isVideoStreaming() && vsDownloadClickRect.contains(startX, startY))) {
return !ignoreListener && listener != null && listener.onClick(this, view, file, messageId);
Expand Down Expand Up @@ -945,7 +959,7 @@ public void setCurrentState (@TdlibFilesManager.FileDownloadState int state, boo
}
case TdlibFilesManager.STATE_IN_PROGRESS: {
completeCloud(false);
setIcon((isVideoStreamingProgressIgnore && !isVideoStreamingSmallUi) ? pausedIconRes : isVideoStreaming() ? isVideoStreamingSmallUi ? R.drawable.deproko_baseline_close_16 : R.drawable.deproko_baseline_close_18 : R.drawable.deproko_baseline_close_24, animated);
setIcon((isVideoStreamingProgressIgnore && !isVideoStreamingSmallUi()) ? pausedIconRes : isVideoStreaming() ? isVideoStreamingSmallUi() ? R.drawable.deproko_baseline_close_16 : R.drawable.deproko_baseline_close_18 : R.drawable.deproko_baseline_close_24, animated);
setInProgress(true, animated);
setAlpha(1f, animated);
break;
Expand Down Expand Up @@ -1285,21 +1299,6 @@ public void drawPlayPause (Canvas c, int cx, int cy, float alpha, boolean applyN
DrawAlgorithms.drawPlayPause(c, cx, cy, Screen.dp(13f), playPausePath, drawFactor, factor, progressFactor, ColorUtils.alphaColor(alpha, 0xffffffff));
}

public void drawStreamingPlay (final Canvas c) {
if (file != null && alpha != 0f && !isTrack) {
final float alpha = this.alpha * requestedAlpha;
final int fillingColor;
if (alpha == 1f) {
fillingColor = backgroundColorIsId ? Theme.getColor(backgroundColor) : backgroundColor;
} else {
fillingColor = ColorUtils.alphaColor(alpha, backgroundColorIsId ? Theme.getColor(backgroundColor) : backgroundColor);
}

c.drawCircle(centerX(), centerY(), Screen.dp(DEFAULT_RADIUS), Paints.fillingPaint(fillingColor));
drawPlayPause(c, centerX(), centerY(), alpha, true);
}
}

public <T extends View & DrawableProvider> void draw (T view, final Canvas c) {
final boolean cloudPlayback = Config.useCloudPlayback(playPauseFile) && !noCloud;
final float alpha = this.alpha * requestedAlpha;
Expand Down Expand Up @@ -1377,8 +1376,8 @@ public <T extends View & DrawableProvider> void draw (T view, final Canvas c) {
// Video streaming UI stuff

private void updateVsRect () {
int startX = left + Screen.dp(isVideoStreamingSmallUi ? 8f : 14f);
int startY = top + Screen.dp(isVideoStreamingSmallUi ? 6f : 12f) + (isVideoStreamingOffsetNeeded ? Screen.dp(16f) : 0);
int startX = left + Screen.dp(videoStreamingUiMode == STREAMING_UI_MODE_EXTRA_SMALL ? 4f : videoStreamingUiMode == STREAMING_UI_MODE_SMALL ? 8f : 14f);
int startY = top + Screen.dp(videoStreamingUiMode == STREAMING_UI_MODE_EXTRA_SMALL ? 3f : videoStreamingUiMode == STREAMING_UI_MODE_SMALL ? 6f : 12f) + (isVideoStreamingOffsetNeeded ? Screen.dp(16f) : 0);
vsDownloadRect.set(
startX, startY, startX + (getRadius() * 2), startY + (getRadius() * 2)
);
Expand Down

0 comments on commit 08229c6

Please sign in to comment.