Skip to content

Commit 20f4d38

Browse files
committed
Support Android 15 in mentions wrap
1 parent 0e666ad commit 20f4d38

File tree

10 files changed

+161
-65
lines changed

10 files changed

+161
-65
lines changed

app/src/main/java/org/thunderdog/challegram/BaseActivity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,6 +2194,12 @@ public InlineResultsWrap getInlineResultsView () {
21942194
return inlineResultsView;
21952195
}
21962196

2197+
public void destroyStickersSuggestions (StickersSuggestionsLayout layout) {
2198+
if (emojiSuggestionsWrap == layout) {
2199+
emojiSuggestionsWrap = null;
2200+
}
2201+
}
2202+
21972203
public void setEmojiSuggestions (MessagesController context, @Nullable ArrayList<TGStickerObj> stickers, @Nullable RecyclerView.OnScrollListener scrollCallback, StickersSuggestionsLayout.Delegate choosingDelegate) {
21982204
if (emojiSuggestionsWrap == null) {
21992205
emojiSuggestionsWrap = new StickersSuggestionsLayout(context.context());

app/src/main/java/org/thunderdog/challegram/component/chat/InlineResultsAdapter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import android.content.Context;
1818
import android.graphics.Canvas;
19+
import android.graphics.Color;
1920
import android.util.TypedValue;
2021
import android.view.Gravity;
2122
import android.view.View;
@@ -26,6 +27,7 @@
2627
import androidx.annotation.Nullable;
2728
import androidx.recyclerview.widget.RecyclerView;
2829

30+
import org.thunderdog.challegram.BuildConfig;
2931
import org.thunderdog.challegram.R;
3032
import org.thunderdog.challegram.U;
3133
import org.thunderdog.challegram.component.emoji.GifView;

app/src/main/java/org/thunderdog/challegram/component/chat/InlineResultsWrap.java

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import androidx.recyclerview.widget.RecyclerView;
3131

3232
import org.drinkless.tdlib.TdApi;
33-
import org.thunderdog.challegram.BaseActivity;
3433
import org.thunderdog.challegram.R;
3534
import org.thunderdog.challegram.component.sticker.StickerSmallView;
3635
import org.thunderdog.challegram.component.sticker.TGStickerObj;
@@ -66,6 +65,7 @@
6665
import org.thunderdog.challegram.util.CancellableResultHandler;
6766
import org.thunderdog.challegram.v.NewFlowLayoutManager;
6867
import org.thunderdog.challegram.widget.BaseView;
68+
import org.thunderdog.challegram.widget.RootFrameLayout;
6969
import org.thunderdog.challegram.widget.ShadowView;
7070

7171
import java.util.ArrayList;
@@ -79,7 +79,7 @@
7979
import me.vkryl.core.StringUtils;
8080
import tgx.td.ChatId;
8181

82-
public class InlineResultsWrap extends FrameLayoutFix implements View.OnClickListener, StickerSmallView.StickerMovementCallback, InlineResultsAdapter.HeightProvider, FactorAnimator.Target, View.OnLongClickListener, TGLegacyManager.EmojiLoadListener, BaseView.CustomControllerProvider {
82+
public class InlineResultsWrap extends FrameLayoutFix implements View.OnClickListener, StickerSmallView.StickerMovementCallback, InlineResultsAdapter.HeightProvider, FactorAnimator.Target, View.OnLongClickListener, TGLegacyManager.EmojiLoadListener, BaseView.CustomControllerProvider, RootFrameLayout.InsetsChangeListener, RootFrameLayout.MarginModifier {
8383
private RecyclerView recyclerView;
8484
private ShadowView shadowView;
8585
private GridLayoutManager gridManager;
@@ -94,7 +94,6 @@ public class InlineResultsWrap extends FrameLayoutFix implements View.OnClickLis
9494

9595
public interface OffsetProvider {
9696
int provideOffset (InlineResultsWrap v);
97-
int provideParentHeight (InlineResultsWrap v);
9897
}
9998

10099
private OffsetProvider offsetProvider;
@@ -122,6 +121,10 @@ public void setOffsetProvider (OffsetProvider offsetProvider) {
122121
public InlineResultsWrap (Context context) {
123122
super(context);
124123

124+
setClipChildren(true);
125+
setClipToPadding(true);
126+
setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
127+
125128
gridManager = new GridLayoutManager(context, spanCount = calculateSpanCount(Screen.currentWidth(), Screen.currentHeight()));
126129
gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
127130
@Override
@@ -229,6 +232,15 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
229232

230233
@Override
231234
public void onScrolled (RecyclerView recyclerView, int dx, int dy) {
235+
/*View topView = recyclerView.getLayoutManager().findViewByPosition(0);
236+
if (topView != null) {
237+
Log.v("scroll: %d inset: %d %d " +
238+
"margin: %d, shadow: %d %d " +
239+
"items: %d root: %d top: %d expected: %d",
240+
recyclerView.getLayoutManager().getDecoratedTop(topView), topOffset, bottomInset,
241+
lastBottomMargin, shadowView.getLayoutParams().height, ShadowView.simpleBottomShadowHeight(),
242+
measureItemsHeight(), rootView != null ? rootView.getMeasuredHeight() : 0, topView.getMeasuredHeight(), provideHeight());
243+
}*/
232244
if (scrollCallback != null) {
233245
scrollCallback.onScrolled(recyclerView, dx, dy);
234246
}
@@ -817,10 +829,8 @@ protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
817829
private void setBottomMargin (int bottomMargin) {
818830
if (this.lastBottomMargin != bottomMargin) {
819831
this.lastBottomMargin = bottomMargin;
820-
/*FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) recyclerView.getLayoutParams();
821-
params.topMargin = bottomMargin;
822-
recyclerView.setLayoutParams(params);*/
823-
setTranslationY(-bottomMargin);
832+
Views.setBottomMargin(this, bottomInset + bottomMargin);
833+
updateOffset();
824834
}
825835
if (lickView != null) {
826836
lickView.invalidate();
@@ -852,10 +862,59 @@ public void updatePosition (boolean needTranslate) {
852862

853863
@Override
854864
public int provideHeight () {
855-
int height = offsetProvider != null ? offsetProvider.provideParentHeight(this) : ((BaseActivity) getContext()).getVisibleContentHeight(); // - measureItemsHeight();
856-
height -= getMinItemsHeight();
857-
int minHeight = Math.max(Screen.getStatusBarHeight(), ((BaseActivity) getContext()).getRootView().getTopInset()) + lastBottomMargin;
858-
return Math.max(minHeight, height);
865+
// height of the offset
866+
final int totalHeight = rootView != null ? rootView.getMeasuredHeight() - bottomInset - lastBottomMargin : 0;
867+
int itemsHeight = measureItemsHeight();
868+
return Math.max(topOffset, totalHeight - Math.min(totalHeight / 2, itemsHeight));
869+
}
870+
871+
private int topOffset, bottomInset;
872+
873+
private void setInsets (int topOffset, int bottomInset) {
874+
if (this.topOffset != topOffset || this.bottomInset != bottomInset) {
875+
this.topOffset = topOffset;
876+
this.bottomInset = bottomInset;
877+
Views.setBottomMargin(this, bottomInset + lastBottomMargin);
878+
updateOffset();
879+
}
880+
}
881+
882+
@Override
883+
public void onApplyMarginInsets (View child, LayoutParams params, Rect legacyInsets, Rect insets, Rect insetsWithoutIme) {
884+
Views.setMargins(params,
885+
legacyInsets.left,
886+
legacyInsets.top,
887+
legacyInsets.right,
888+
insets.bottom + lastBottomMargin
889+
);
890+
setInsets(insets.top, insets.bottom);
891+
}
892+
893+
@Override
894+
public void onInsetsChanged (RootFrameLayout viewGroup, Rect effectiveInsets, Rect effectiveInsetsWithoutIme, Rect systemInsets, Rect systemInsetsWithoutIme, boolean isUpdate) {
895+
setInsets(systemInsets.top, systemInsets.bottom);
896+
}
897+
898+
private RootFrameLayout rootView;
899+
900+
@Override
901+
protected void onAttachedToWindow () {
902+
super.onAttachedToWindow();
903+
rootView = Views.findAncestor(this, RootFrameLayout.class, true);
904+
if (rootView != null) {
905+
rootView.addInsetsChangeListener(this);
906+
Rect systemInsets = rootView.getSystemInsets();
907+
setInsets(systemInsets.top, systemInsets.bottom);
908+
}
909+
}
910+
911+
@Override
912+
protected void onDetachedFromWindow () {
913+
super.onDetachedFromWindow();
914+
if (rootView != null) {
915+
rootView.removeInsetsChangeListener(this);
916+
rootView = null;
917+
}
859918
}
860919

861920
public int getMinItemsHeight () {

app/src/main/java/org/thunderdog/challegram/component/chat/InputView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ public void showLinkPreview (@Nullable FoundUrls foundUrls) {
10091009

10101010
@Override
10111011
public boolean needsInlineBots () {
1012-
return !isCaptionEditing() && tdlib.canSendMessage(controller.getChat(), RightId.SEND_OTHER_MESSAGES);
1012+
return !isCaptionEditing() && tdlib.canSendMessage(controller.getChat(), RightId.SEND_OTHER_MESSAGES) && !controller.hasAttachedFiles();
10131013
}
10141014

10151015
@Override

app/src/main/java/org/thunderdog/challegram/mediaview/MediaViewController.java

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.drinkless.tdlib.Client;
5858
import org.drinkless.tdlib.TdApi;
5959
import org.thunderdog.challegram.BaseActivity;
60+
import org.thunderdog.challegram.BuildConfig;
6061
import org.thunderdog.challegram.R;
6162
import org.thunderdog.challegram.U;
6263
import org.thunderdog.challegram.component.MediaCollectorDelegate;
@@ -541,13 +542,8 @@ public long provideInlineSearchChatUserId (InputView v) {
541542

542543
@Override
543544
public int provideOffset (InlineResultsWrap v) {
544-
final int offset = keyboardFrameLayout != null && keyboardFrameLayout.getVisibility() == View.VISIBLE && keyboardFrameLayout.getParent() != null ? keyboardFrameLayout.getMeasuredHeight() : 0;
545-
return (captionView.getMeasuredHeight() /*- Screen.dp(50f)*/) + offset;
546-
}
547-
548-
@Override
549-
public int provideParentHeight (InlineResultsWrap v) {
550-
return popupView.getMeasuredHeight();
545+
final int offset = keyboardFrameLayout != null && emojiShown ? Math.max(0, keyboardFrameLayout.getMeasuredHeight() - bottomInnerMargin) : 0;
546+
return (captionWrapView.getMeasuredHeight()) + offset;
551547
}
552548

553549
@Override
@@ -557,19 +553,11 @@ public void showInlineResults (InputView v, ArrayList<InlineResult<?>> results,
557553
return;
558554
}
559555

560-
FrameLayoutFix.LayoutParams params = FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
561-
// params.bottomMargin = Screen.dp(50f);
562-
inlineResultsView = new InlineResultsWrap(context()) {
563-
@Override
564-
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
565-
super.onMeasure(widthMeasureSpec, popupView.getMeasuredHeight());
566-
}
567-
};
556+
inlineResultsView = new InlineResultsWrap(context());
568557
inlineResultsView.setListener((InlineResultsWrap.PickListener) captionView);
569558
inlineResultsView.setAlpha(inCaptionFactor);
570559
inlineResultsView.setOffsetProvider(this);
571560
inlineResultsView.setUseDarkMode(true);
572-
inlineResultsView.setLayoutParams(params);
573561
}
574562

575563
if (results != null && !results.isEmpty()) {
@@ -708,11 +696,20 @@ private void onKeyboardLayoutTranslation (float translationY) {
708696
private void openEmojiKeyboard () {
709697
if (!emojiShown) {
710698
if (keyboardFrameLayout == null) {
711-
keyboardFrameLayout = new KeyboardFrameLayout(context());
699+
keyboardFrameLayout = new KeyboardFrameLayout(context()) {
700+
@Override
701+
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
702+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
703+
if (inlineResultsView != null) {
704+
inlineResultsView.updatePosition(true);
705+
}
706+
}
707+
};
712708
keyboardFrameLayout.setLayoutParams(FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));
713709
keyboardFrameLayout.setParentView(bottomWrap, contentView, popupView);
714710
keyboardFrameLayout.setUpdateTranslationListener(this::onKeyboardLayoutTranslation);
715711
keyboardFrameLayout.useHideByDetachView();
712+
keyboardFrameLayout.setExtraBottomInset(systemInsets.bottom, systemInsets.bottom);
716713

717714
textFormattingLayout = keyboardFrameLayout.contentView.textFormattingLayout;
718715
textFormattingLayout.init(this, inputView, new TextFormattingLayout.Delegate() {
@@ -812,7 +809,7 @@ private void setInCaption () {
812809
}
813810

814811
private int getBottomWrapMargin () {
815-
return (inCaption || mode != MODE_GALLERY ? 0 : Screen.dp(56f)) + controlsMargin;
812+
return (inCaption || mode != MODE_GALLERY ? 0 : Screen.dp(56f)) + (emojiShown ? 0 : controlsMargin);
816813
}
817814

818815
private void setInCaption (boolean inCaption) {
@@ -3504,6 +3501,7 @@ private void checkBottomWrapY () {
35043501
int thumbsDistance = (Screen.dp(THUMBS_PADDING) * 2 + Screen.dp(THUMBS_HEIGHT)) * (inForceEditMode() ? 0 : 1);
35053502
float offsetDistance = (float) measureBottomWrapHeight() * dismissFactor - getKeyboardOffset();
35063503
float maxY = 0;
3504+
int appliedBottomPadding = emojiShown ? 0 : this.appliedBottomPadding;
35073505
if (bottomWrap != null) {
35083506
float y = offsetDistance - (thumbsFactor * (float) thumbsDistance) * (1f - dismissFactor) - appliedBottomPadding;
35093507
bottomWrap.setTranslationY(y);
@@ -5292,7 +5290,8 @@ public boolean onTouchEvent (MotionEvent event) {
52925290
bottomSpace.setThemedBackground(ColorId.transparentEditor, this);
52935291
bottomSpace.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, Gravity.BOTTOM));
52945292
bottomSpace.setAlpha(0f);
5295-
bottomSpace.setLayoutHeight(bottomInnerMargin, true);
5293+
bottomSpace.setLayoutHeight(bottomInnerMargin, false);
5294+
bottomSpace.setVisibility(bottomInnerMargin > 0 ? View.VISIBLE : View.GONE);
52965295
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !Config.DISABLE_VIEWER_ELEVATION) {
52975296
bottomSpace.setElevation(Screen.dp(3f));
52985297
}
@@ -5348,7 +5347,8 @@ private void setControlsMargin (int margin) {
53485347
Views.setBottomMargin(thumbsRecyclerView, margin);
53495348
Views.setBottomMargin(editWrap, margin);
53505349
Views.setBottomMargin(bottomWrap, getBottomWrapMargin());
5351-
bottomSpace.setLayoutHeight(margin, true);
5350+
bottomSpace.setLayoutHeight(margin, false);
5351+
bottomSpace.setVisibility(margin > 0 && !emojiShown ? View.VISIBLE : View.GONE);
53525352
}
53535353
}
53545354

@@ -5425,6 +5425,9 @@ public void dispatchSystemInsets (View parentView, ViewGroup.MarginLayoutParams
54255425
cropAreaView.setOffsetBottom(bottomOffset);
54265426
}
54275427
checkBottomWrapY();
5428+
if (keyboardFrameLayout != null) {
5429+
keyboardFrameLayout.setExtraBottomInset(insets.bottom, insetsWithoutIme.bottom);
5430+
}
54285431
}
54295432
if (mediaView != null) {
54305433
if (changed) {
@@ -8539,6 +8542,13 @@ private void setEmojiShown (boolean emojiShown) {
85398542
if (inputView != null) {
85408543
inputView.setActionModeVisibility(!textInputHasSelection || !emojiShown);
85418544
}
8545+
if (inlineResultsView != null) {
8546+
inlineResultsView.updatePosition(false);
8547+
}
8548+
Views.setBottomMargin(bottomWrap, getBottomWrapMargin());
8549+
if (bottomSpace != null) {
8550+
bottomSpace.setVisibility(bottomInnerMargin > 0 && !emojiShown ? View.VISIBLE : View.GONE);
8551+
}
85428552
}
85438553
}
85448554

app/src/main/java/org/thunderdog/challegram/tool/Views.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,14 +861,16 @@ public static boolean setMargins (ViewGroup.MarginLayoutParams params, int left,
861861
return false;
862862
}
863863

864-
public static void setLayoutHeight (View view, int height) {
864+
public static boolean setLayoutHeight (View view, int height) {
865865
if (view != null) {
866866
ViewGroup.LayoutParams params = view.getLayoutParams();
867867
if (params != null && params.height != height) {
868868
params.height = height;
869869
view.setLayoutParams(params);
870+
return true;
870871
}
871872
}
873+
return false;
872874
}
873875

874876
public static void setTopMargin (View view, int margin) {

0 commit comments

Comments
 (0)