Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arseny271 committed Aug 21, 2022
1 parent bfef30e commit 0678fab
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader;
import android.os.Build;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
Expand All @@ -29,11 +28,9 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import org.drinkless.td.libcore.telegram.TdApi;
import org.thunderdog.challegram.Log;
import org.thunderdog.challegram.R;
import org.thunderdog.challegram.config.Config;
import org.thunderdog.challegram.core.Lang;
import org.thunderdog.challegram.data.TGMessage;
import org.thunderdog.challegram.support.RippleSupport;
import org.thunderdog.challegram.telegram.Tdlib;
Expand All @@ -57,32 +54,6 @@ public VH (View itemView) {

@Override
public void checkRtl () {
LinearLayoutManager manager = (LinearLayoutManager) getRecyclerView().getLayoutManager();
if (manager.getReverseLayout() != Lang.rtl()) {
View view = manager.findViewByPosition(0);
boolean needScroll = false;
int scrollOffset = 0;
if (view != null) {
int parentWidth = getRecyclerView().getMeasuredWidth();
int viewWidth = view.getMeasuredWidth();
int viewOffset = view.getLeft();
if (viewWidth > parentWidth) {
int availScrollX = viewWidth - parentWidth;
int scrolledX;
if (Lang.rtl()) { // LTR -> RTL
scrolledX = -viewOffset;
} else { // RTL -> LTR
scrolledX = availScrollX + viewOffset;
}
scrollOffset = -scrolledX;
needScroll = true;
}
}
manager.setReverseLayout(Lang.rtl());
if (needScroll) {
manager.scrollToPositionWithOffset(0, scrollOffset);
}
}
getTopView().checkRtl();
}

Expand Down Expand Up @@ -138,7 +109,7 @@ public ViewPagerHeaderViewReactionsCompact (Context context, Tdlib tdlib, TGMess
adapter = new A(topView);

if (needReactionSelector) {
reactionsSelectorRecyclerView = new ReactionsSelectorRecyclerView(context, message) {
reactionsSelectorRecyclerView = new ReactionsSelectorRecyclerView(context) {
@Override
protected void dispatchDraw (Canvas c) {
super.dispatchDraw(c);
Expand All @@ -163,14 +134,11 @@ public void onScrolled (int dx, int dy) {
}
}
};
reactionsSelectorRecyclerView.setOverScrollMode(Config.HAS_NICE_OVER_SCROLL_EFFECT ? OVER_SCROLL_IF_CONTENT_SCROLLS : OVER_SCROLL_NEVER);
reactionsSelectorRecyclerView.setMessage(message);
reactionsSelectorRecyclerView.setLayoutParams(FrameLayoutFix.newParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
Gravity.CENTER_VERTICAL, 0, 0, this.rightOffset, 0));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
reactionsSelectorRecyclerView.setLayoutDirection(LAYOUT_DIRECTION_LTR);
}
addView(reactionsSelectorRecyclerView);
} else {
reactionsSelectorRecyclerView = null;
Expand Down Expand Up @@ -210,14 +178,16 @@ public void onScrolled (int dx, int dy) {
Gravity.TOP, Screen.dp(56), 0, 0, 0));
recyclerView.setOverScrollMode(Config.HAS_NICE_OVER_SCROLL_EFFECT ? OVER_SCROLL_IF_CONTENT_SCROLLS : OVER_SCROLL_NEVER);
recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) {
@Override
protected boolean isLayoutRTL () {
return false;
}

@Override
public boolean canScrollHorizontally () {
return isScrollEnabled && super.canScrollHorizontally();
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
recyclerView.setLayoutDirection(LAYOUT_DIRECTION_LTR);
}
recyclerView.setAdapter(adapter);
addView(recyclerView);

Expand Down Expand Up @@ -255,7 +225,6 @@ public void updatePaints (int color) {
shadowPaint1.setShader(shader1);
shadowPaint2.setShader(shader2);
if (reactionsSelectorRecyclerView != null) {
reactionsSelectorRecyclerView.invalidateAll();
reactionsSelectorRecyclerView.invalidate();
}
recyclerView.invalidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.os.Build;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
Expand All @@ -17,35 +18,40 @@
import org.thunderdog.challegram.component.sticker.StickerSmallView;
import org.thunderdog.challegram.component.sticker.TGStickerObj;
import org.thunderdog.challegram.config.Config;
import org.thunderdog.challegram.core.Lang;
import org.thunderdog.challegram.data.TGMessage;
import org.thunderdog.challegram.data.TGReaction;
import org.thunderdog.challegram.telegram.Tdlib;
import org.thunderdog.challegram.theme.Theme;
import org.thunderdog.challegram.tool.Paints;
import org.thunderdog.challegram.tool.Screen;
import org.thunderdog.challegram.util.text.Counter;
import org.thunderdog.challegram.v.CustomRecyclerView;

import java.util.Arrays;

import me.vkryl.android.widget.FrameLayoutFix;

public class ReactionsSelectorRecyclerView extends CustomRecyclerView {
public ReactionsSelectorRecyclerView (@NonNull Context context, TGMessage message) {
public class ReactionsSelectorRecyclerView extends RecyclerView {

public ReactionsSelectorRecyclerView (@NonNull Context context) {
super(context);
}

public void setMessage (TGMessage message) {
String chosen = message.getMessageReactions().getChosen();
TdApi.AvailableReaction[] reactions = message.getMessageAvailableReactions();

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false) {
@Override
protected boolean isLayoutRTL () {
return false;
}
};

setOverScrollMode(Config.HAS_NICE_OVER_SCROLL_EFFECT ? OVER_SCROLL_IF_CONTENT_SCROLLS : OVER_SCROLL_NEVER);
setLayoutManager(linearLayoutManager);
setAdapter(adapter = new ReactionsAdapter(context, message));
setLayoutParams(FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER_VERTICAL));
setPadding(Screen.dp(9), Screen.dp(8), Screen.dp(9), Screen.dp(8));
setClipToPadding(false);
setHasFixedSize(true);

setLayoutManager(linearLayoutManager);
setAdapter(adapter = new ReactionsAdapter(getContext(), message));

int index = -1;
for (int a = 0; a < reactions.length; a++) {
Expand All @@ -69,6 +75,7 @@ private static class ReactionView extends FrameLayoutFix {
private Counter counter;
private boolean chosen;
private boolean useCounter;
private TGStickerObj centerAnimationSicker;
private RectF rectF;

public ReactionView (Context context) {
Expand All @@ -95,18 +102,22 @@ public boolean dispatchTouchEvent (MotionEvent event) {
public void setReaction (TGReaction reaction, TdApi.MessageReaction messageReaction, boolean useCounter) {
this.useCounter = useCounter;
this.chosen = messageReaction.isChosen;
TGStickerObj centerAnimationSicker = reaction.newCenterAnimationSicker();
if (centerAnimationSicker.getPreviewAnimation() != null) {
centerAnimationSicker.getPreviewAnimation().setPlayOnce(true);
centerAnimationSicker.getPreviewAnimation().setLooped(false);
}
this.centerAnimationSicker = reaction.newCenterAnimationSicker();
this.playAnimation();
stickerView.setSticker(centerAnimationSicker);
if (useCounter) {
counter.setCount(messageReaction.totalCount, !messageReaction.isChosen, false);
}
requestLayout();
}

public void playAnimation () {
if (centerAnimationSicker != null && centerAnimationSicker.getPreviewAnimation() != null) {
centerAnimationSicker.getPreviewAnimation().setPlayOnce(true);
centerAnimationSicker.getPreviewAnimation().setLooped(false);
}
}

@Override
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
int width = Screen.dp(38f);
Expand Down Expand Up @@ -203,6 +214,7 @@ public int getItemCount () {
@Override
public void onViewAttachedToWindow (ReactionHolder holder) {
((ReactionView) holder.itemView).stickerView.attach();
((ReactionView) holder.itemView).playAnimation();
}

@Override
Expand All @@ -218,7 +230,6 @@ public void onViewRecycled (ReactionHolder holder) {

public interface ReactionSelectDelegate {
void onClick (View v, TGReaction reaction);

void onLongClick (View v, TGReaction reaction);
}
}

0 comments on commit 0678fab

Please sign in to comment.