Skip to content

Commit

Permalink
Reactions: full implementation. PR: TGX-Android#154 (TGX-Android#185)
Browse files Browse the repository at this point in the history
* Telegram X Android Competition: Round 1 - main commit

* Smallest Fix)

* add vkryl changes

* Update submodule

* Adding modified vkryl files to the repository

* Rejecting changes in vkryl android submodule

* fix color in reaction badge

* Revert gitmodules file

* Quick reactions update + Premium features

* Reactions preloading on starting app

* Haptic feedbacks

* Disable Reactions to a Sponsored Post

* Fixes - Animate reaction button bubble

* Support TextSize settings + flat mode reactions mockup

* Fix GifThread crashes?

* Fix design + fix crashes

* Quick reaction fixes

* Reactions bottom sheet Improvements

* Reactions bottom sheet Improvements

* Disable message list animator

* Quick gesture improvements

* Fix bottom sheet jumping

* Reaction Bubble Improvements

* Reaction button improvements

* Improving mockup compliance

* Change toast to tooltip

* some fixes

* Improving the fidelity of animations

* Bottom sheet improvements + bugfixes

* Round video reaction fix?

* -

* fix quick buttons

* -

* Round video fix

* Unread reactions fixes

* Update app/src/main/java/org/thunderdog/challegram/unsorted/Settings.java

Co-authored-by: Vyacheslav <6242627+vkryl@users.noreply.github.com>

* 1

* Fix phantom buttons

* Fixes

* Bottom sheet fix? + overlay translation fix

* fix for fix

* Remove log output

* Color fixes

* improving the accuracy of full-screen animation

* canGetAddedReactions fix

* Update app/src/main/java/org/thunderdog/challegram/navigation/ViewPagerTopView.java

Co-authored-by: Vyacheslav <6242627+vkryl@users.noreply.github.com>

* Update app/src/main/java/org/thunderdog/challegram/unsorted/Settings.java

Co-authored-by: Vyacheslav <6242627+vkryl@users.noreply.github.com>

* Update app/src/main/java/org/thunderdog/challegram/unsorted/Settings.java

Co-authored-by: Vyacheslav <6242627+vkryl@users.noreply.github.com>

* Thread safety fix

* Update Paints.java

* archive fix

* Theme fix

* Update TGReactions.java

* Update MessageOptionsPagerController.java

* Update MessageOptionsPagerController.java

* bugfixes

* Bottom shit fix

* Bottom sheet fixes 2

* Bottom sheet fixes 3

* Bottomsheet  fixes 3

* Update PopupLayout.java

* scroll fix?

* Add visibleIfZero option to Counter class

* Layout accuracy improvement

* Fix width if bubble is stretched

* Update TGMessage.java

* Update ReactionsSelectorRecyclerView.java

* Update TGMessage.java

* Scroll fix 2

* Start animation position fix

* Fixes

* Scroll fixes

* -

* Update MessageView.java

* Update MessagesManager.java

* Update MessageView.java

* Scroll fix?

* Update ComplexReceiver.java

* Update MessagesManager.java

* Update MessagesManager.java

* Fixes

* Fixes

* Update MessagesManager.java

* Update TGMessage.java

* fixes

* Optimizations

* Add timeExpandAnimation

* Update TGMessage.java

* Update TGMessage.java

Co-authored-by: Vyacheslav <6242627+vkryl@users.noreply.github.com>
  • Loading branch information
Arseny271 and vkryl committed Aug 9, 2022
1 parent 8ebb7f7 commit dc330bd
Show file tree
Hide file tree
Showing 71 changed files with 8,298 additions and 372 deletions.
62 changes: 62 additions & 0 deletions app/src/main/java/org/thunderdog/challegram/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.thunderdog.challegram.config.Device;
import org.thunderdog.challegram.core.Lang;
import org.thunderdog.challegram.data.InlineResult;
import org.thunderdog.challegram.data.TGReaction;
import org.thunderdog.challegram.mediaview.MediaViewController;
import org.thunderdog.challegram.navigation.ActivityResultHandler;
import org.thunderdog.challegram.navigation.DrawerController;
Expand All @@ -88,6 +89,7 @@
import org.thunderdog.challegram.navigation.NavigationGestureController;
import org.thunderdog.challegram.navigation.OptionsLayout;
import org.thunderdog.challegram.navigation.OverlayView;
import org.thunderdog.challegram.navigation.ReactionsOverlayView;
import org.thunderdog.challegram.navigation.RootDrawable;
import org.thunderdog.challegram.navigation.TooltipOverlayView;
import org.thunderdog.challegram.navigation.ViewController;
Expand Down Expand Up @@ -1538,6 +1540,27 @@ public TooltipOverlayView tooltipManager () {
return tooltipOverlayView;
}

private ReactionsOverlayView reactionsOverlayView;

public ReactionsOverlayView reactionsOverlayManager () {
if (reactionsOverlayView == null) {
reactionsOverlayView = new ReactionsOverlayView(this);
reactionsOverlayView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
/*reactionsOverlayView.setAvailabilityListener((overlayView, hasChildren) -> {
if (hasChildren) {
if (tooltipOverlayView.getParent() != null)
return;
addToRoot(tooltipOverlayView, true);
} else {
removeFromRoot(tooltipOverlayView);
}
});*/
addToRoot(reactionsOverlayView, true);
}
return reactionsOverlayView;
}


// Progress view

private boolean isProgressShowing, isProgressAnimating;
Expand Down Expand Up @@ -1806,6 +1829,39 @@ public void closeStickerPreview () {
}
}

// ReactionPreview

public void openReactionPreview (Tdlib tdlib, StickerSmallView stickerView, TGReaction reaction, int cx, int cy, int maxWidth, int viewportHeight, boolean disableEmojis) {
if (stickerPreview != null) {
return;
}

stickerPreviewControllerView = stickerView;

stickerPreview = new StickerPreviewView(this);
stickerPreview.setControllerView(stickerPreviewControllerView);
stickerPreview.setReaction(tdlib, reaction, cx, cy, maxWidth, viewportHeight, disableEmojis);

stickerPreviewWindow = new PopupLayout(this);
stickerPreviewWindow.setBackListener(stickerPreview);
stickerPreviewWindow.setOverlayStatusBar(true);
stickerPreviewWindow.init(true);
stickerPreviewWindow.setNeedRootInsets();
stickerPreviewWindow.showAnimatedPopupView(stickerPreview, stickerPreview);
}

public void replaceReactionPreview (TGReaction reaction, int cx, int cy) {
if (stickerPreview != null) {
stickerPreview.replaceReaction(reaction, cx, cy);
}
}

public void replaceReactionPreviewCords (int cx, int cy) {
if (stickerPreview != null) {
stickerPreview.replaceStartCords(cx, cy);
}
}

// Force touch

private PopupLayout forceTouchWindow;
Expand Down Expand Up @@ -1866,6 +1922,9 @@ public void updateHackyOverlaysPositions () {
if (tooltipOverlayView != null) {
tooltipOverlayView.reposition();
}
if (reactionsOverlayView != null) {
reactionsOverlayView.reposition();
}
}

public void showInlineResults (ViewController<?> context, Tdlib tdlib, @Nullable ArrayList<InlineResult<?>> results, boolean needBackground, @Nullable InlineResultsWrap.LoadMoreCallback callback) {
Expand Down Expand Up @@ -2992,6 +3051,9 @@ public void onThemeColorsChanged (boolean areTemp, ColorState state) {
if (tooltipOverlayView != null) {
tooltipOverlayView.invalidate();
}
if (reactionsOverlayView != null) {
reactionsOverlayView.invalidate();
}
for (ThemeListenerList list : globalThemeListeners) {
list.onThemeColorsChanged(areTemp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import org.thunderdog.challegram.component.chat.MessageView;

import java.util.ArrayList;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.thunderdog.challegram.U;
import org.thunderdog.challegram.component.user.RemoveHelper;
import org.thunderdog.challegram.core.Lang;
import org.thunderdog.challegram.loader.ComplexReceiver;
import org.thunderdog.challegram.loader.ImageReceiver;
import org.thunderdog.challegram.navigation.TooltipOverlayView;
import org.thunderdog.challegram.navigation.ViewController;
Expand Down Expand Up @@ -119,10 +120,12 @@ public interface IconOverlay {

private TextWrapper text;
private IconOverlay overlay;
private final ComplexReceiver complexReceiver;

public SettingView (Context context, Tdlib tdlib) {
super(context);
this.tdlib = tdlib;
this.complexReceiver = new ComplexReceiver(this);
setWillNotDraw(false);
}

Expand Down Expand Up @@ -190,6 +193,7 @@ public void attach () {
flags |= FLAG_ATTACHED;
if (receiver != null)
receiver.attach();
complexReceiver.attach();
}

@Override
Expand All @@ -198,13 +202,15 @@ public void detach () {
flags &= ~FLAG_ATTACHED;
if (receiver != null)
receiver.detach();
complexReceiver.detach();
}

@Override
public void performDestroy () {
Views.destroy(this);
if (receiver != null)
receiver.destroy();
complexReceiver.performDestroy();
if (subscribedToEmojiUpdates) {
TGLegacyManager.instance().removeEmojiListener(this);
subscribedToEmojiUpdates = false;
Expand All @@ -220,6 +226,10 @@ public ImageReceiver getReceiver () {
return receiver;
}

public ComplexReceiver getComplexReceiver () {
return complexReceiver;
}

public void setTextColorId (@ThemeColorId int textColorId) {
if (textColorId == ThemeColorId.NONE)
textColorId = R.id.theme_color_text;
Expand Down Expand Up @@ -504,6 +514,14 @@ private void buildLayout (int totalWidth, int totalHeight) {
availWidth = totalWidth - paddingLeft - paddingRight;
}

if (drawModifiers != null) {
int maxWidth = 0;
for (DrawModifier modifier : drawModifiers) {
maxWidth = Math.max(maxWidth, modifier.getWidth());
}
availWidth -= maxWidth;
}

if (counter != null) {
availWidth -= counter.getScaledWidth(Screen.dp(24f) + Screen.dp(8f));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ private boolean hasRunningRecoverAnim() {
* If user drags the view to the edge, trigger a scroll if necessary.
*/
private boolean scrollIfNecessary() {
if (mSelected == null) {
if (mSelected == null || !mCallback.canScroll()) {
mDragScrollStartTimeInMs = Long.MIN_VALUE;
return false;
}
Expand Down Expand Up @@ -1500,6 +1500,10 @@ public static int makeFlag(int actionState, int directions) {
public abstract int getMovementFlags(RecyclerView recyclerView,
ViewHolder viewHolder);

public boolean canScroll() {
return true;
}

/**
* Converts a given set of flags to absolution direction which means {@link #START} and
* {@link #END} are replaced with {@link #LEFT} and {@link #RIGHT} depending on the layout
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.thunderdog.challegram.component.chat;

import android.util.Log;

import org.thunderdog.challegram.data.TGMessage;
import org.thunderdog.challegram.tool.Screen;

import me.vkryl.core.MathUtils;

public class MessageQuickActionSwipeHelper {
public static final float SWIPE_BUBBLE_MOVE_MAX = 64f;
public static final float SWIPE_THRESHOLD_WIDTH = 124f;
public static final float SWIPE_VERTICAL_HEIGHT = 80f;
public static final float SWIPE_VERTICAL_LOCK_WIDTH = Screen.px(Screen.smallestSide() * 0.75f);

private final TGMessage message;
private final boolean useBubbles;

private float currentDx;
private float currentDy;
private float actualDx;
private float actualDy;

private boolean lockedBecauseSmallDy;
private boolean lockedBecauseNotReadyInBubbleMode;
private boolean lockedBecauseSwipeStarted;

private float moveFactor;
private int quickActionNumber;

public MessageQuickActionSwipeHelper (TGMessage message) {
this.message = message;
this.useBubbles = message.useBubbles();
}

public void translate (float dx, float dy, boolean bySwipe) {
final boolean lockedVerticalSwipe = isLockedVerticalSwipe();
final boolean isLeft = dx > 0;
final float ddx = dx - currentDx;
final float ddy = lockedVerticalSwipe ? 0f: dy - currentDy;
currentDx = dx; actualDx += ddx;
currentDy = dy; actualDy += ddy;
actualDy = clampActualDy(isLeft, actualDy);

if (dx != 0f) {
lockedBecauseNotReadyInBubbleMode &= useBubbles && Math.abs(actualDx) < Screen.dp(SWIPE_BUBBLE_MOVE_MAX);
lockedBecauseSmallDy &= Math.abs(currentDy) < Screen.dp(SWIPE_VERTICAL_HEIGHT) / 2f;
moveFactor = Math.min(1f, Math.abs(dx) / Screen.dp(SWIPE_THRESHOLD_WIDTH));
} else {
reset();
}



final float verticalPosition = actualDy / Screen.dp(SWIPE_VERTICAL_HEIGHT);
updateVerticalPosition(verticalPosition);

message.translate(dx, verticalPosition, true);
message.invalidate(true);
}

public void onBeforeSwipe () {
lockedBecauseSwipeStarted = true;
}

public void reset () {
currentDx = 0f;
currentDy = 0f;
actualDx = 0f;
actualDy = 0f;
lockedBecauseSmallDy = true;
lockedBecauseNotReadyInBubbleMode = useBubbles;
lockedBecauseSwipeStarted = false;
moveFactor = 0f;
quickActionNumber = 0;
}

public float getMoveFactor () {
return moveFactor;
}

public TGMessage.SwipeQuickAction getChosenQuickAction () {
final boolean isLeft = actualDx > 0;
final int realActionQuickNumber = quickActionNumber + message.getQuickDefaultPosition(isLeft);

return message.getQuickAction(isLeft, realActionQuickNumber);
}

private void updateVerticalPosition (float verticalPosition) {
final int newQuickActionNumber = Math.round(verticalPosition);
if (quickActionNumber != newQuickActionNumber) {
quickActionNumber = newQuickActionNumber;

}
}

private float clampActualDy (boolean isLeft, float dy) {
final int minPosition = -message.getQuickDefaultPosition(isLeft);
final int maxPosition = minPosition + Math.max(message.getQuickActionsCount(isLeft) - 1, 0);
return MathUtils.clamp(dy, minPosition * Screen.dp(SWIPE_VERTICAL_HEIGHT), maxPosition * Screen.dp(SWIPE_VERTICAL_HEIGHT));
}

private boolean isLockedVerticalSwipe () {
boolean lockedBecauseReadyInFlatMode = !useBubbles && Math.abs(actualDx) > Screen.dp(SWIPE_VERTICAL_LOCK_WIDTH);
return lockedBecauseNotReadyInBubbleMode || lockedBecauseReadyInFlatMode || lockedBecauseSmallDy || lockedBecauseSwipeStarted;
}
}
Loading

0 comments on commit dc330bd

Please sign in to comment.