diff --git a/app/jni/thirdparty/libyuv b/app/jni/thirdparty/libyuv index eb6e7bb637..b4ddbaf549 160000 --- a/app/jni/thirdparty/libyuv +++ b/app/jni/thirdparty/libyuv @@ -1 +1 @@ -Subproject commit eb6e7bb63738e29efd82ea3cf2a115238a89fa51 +Subproject commit b4ddbaf549a1bf5572bf703fd2862d1eb7380c6a diff --git a/app/src/main/java/org/thunderdog/challegram/component/sharedmedia/MediaSmallView.java b/app/src/main/java/org/thunderdog/challegram/component/sharedmedia/MediaSmallView.java index ca7c755097..27c5b9171c 100644 --- a/app/src/main/java/org/thunderdog/challegram/component/sharedmedia/MediaSmallView.java +++ b/app/src/main/java/org/thunderdog/challegram/component/sharedmedia/MediaSmallView.java @@ -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; @@ -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) { diff --git a/app/src/main/java/org/thunderdog/challegram/data/MediaWrapper.java b/app/src/main/java/org/thunderdog/challegram/data/MediaWrapper.java index 92824fa98f..a1f379f2cd 100644 --- a/app/src/main/java/org/thunderdog/challegram/data/MediaWrapper.java +++ b/app/src/main/java/org/thunderdog/challegram/data/MediaWrapper.java @@ -906,7 +906,7 @@ public 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); @@ -940,6 +940,10 @@ public void draw (T view, Canvas c, int star paint.setAlpha(255); } + if (showDuration && isDoubleLine) { + + } + if (!hideLoader) { fileProgress.draw(view, c); } diff --git a/app/src/main/java/org/thunderdog/challegram/mediaview/data/MediaItem.java b/app/src/main/java/org/thunderdog/challegram/mediaview/data/MediaItem.java index 0f75491b3d..2eb7c3a743 100644 --- a/app/src/main/java/org/thunderdog/challegram/mediaview/data/MediaItem.java +++ b/app/src/main/java/org/thunderdog/challegram/mediaview/data/MediaItem.java @@ -1011,6 +1011,10 @@ 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()) { @@ -1018,10 +1022,10 @@ public boolean onClick (View view, float x, float y) { 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; diff --git a/app/src/main/java/org/thunderdog/challegram/ui/SharedMediaController.java b/app/src/main/java/org/thunderdog/challegram/ui/SharedMediaController.java index c86bfaa029..589ab66511 100644 --- a/app/src/main/java/org/thunderdog/challegram/ui/SharedMediaController.java +++ b/app/src/main/java/org/thunderdog/challegram/ui/SharedMediaController.java @@ -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); @@ -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); diff --git a/app/src/main/java/org/thunderdog/challegram/widget/FileProgressComponent.java b/app/src/main/java/org/thunderdog/challegram/widget/FileProgressComponent.java index 52654fc716..0d79fe8b0a 100644 --- a/app/src/main/java/org/thunderdog/challegram/widget/FileProgressComponent.java +++ b/app/src/main/java/org/thunderdog/challegram/widget/FileProgressComponent.java @@ -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; @@ -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; @@ -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(); } @@ -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; } @@ -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); @@ -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); @@ -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; @@ -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 void draw (T view, final Canvas c) { final boolean cloudPlayback = Config.useCloudPlayback(playPauseFile) && !noCloud; final float alpha = this.alpha * requestedAlpha; @@ -1377,8 +1376,8 @@ public 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) );