Skip to content

Commit 7af86c5

Browse files
committed
Support Android 15 in message menu
1 parent ba29c7f commit 7af86c5

10 files changed

+113
-53
lines changed

app/src/main/java/org/thunderdog/challegram/navigation/ViewController.java

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
import org.thunderdog.challegram.util.text.TextEntity;
114114
import org.thunderdog.challegram.v.HeaderEditText;
115115
import org.thunderdog.challegram.widget.CustomTextView;
116-
import org.thunderdog.challegram.widget.FillingDecoration;
117116
import org.thunderdog.challegram.widget.ForceTouchView;
118117
import org.thunderdog.challegram.widget.InfiniteRecyclerView;
119118
import org.thunderdog.challegram.widget.MaterialEditText;
@@ -124,6 +123,7 @@
124123
import org.thunderdog.challegram.widget.SeparatorView;
125124
import org.thunderdog.challegram.widget.ShadowView;
126125
import org.thunderdog.challegram.widget.TimerView;
126+
import org.thunderdog.challegram.widget.decoration.BottomInsetFillingDecoration;
127127

128128
import java.lang.annotation.Retention;
129129
import java.lang.annotation.RetentionPolicy;
@@ -2013,36 +2013,7 @@ protected void onMeasure (int widthSpec, int heightSpec) {
20132013
}
20142014
}
20152015
};
2016-
recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
2017-
@Override
2018-
public void onDraw (@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
2019-
super.onDraw(c, parent, state);
2020-
2021-
LinearLayoutManager manager = (LinearLayoutManager) parent.getLayoutManager();
2022-
2023-
int maxBottom = -1;
2024-
boolean hasBottom = false;
2025-
for (int i = 0; i < manager.getChildCount(); i++) {
2026-
View view = manager.getChildAt(i);
2027-
if (view != null) {
2028-
int bottom = manager.getDecoratedBottom(view);
2029-
if (hasBottom) {
2030-
maxBottom = Math.max(bottom, maxBottom);
2031-
} else {
2032-
maxBottom = bottom;
2033-
}
2034-
hasBottom = true;
2035-
}
2036-
}
2037-
2038-
if (hasBottom) {
2039-
int height = parent.getMeasuredHeight();
2040-
if (height > maxBottom) {
2041-
c.drawRect(0, maxBottom, parent.getMeasuredWidth(), height, Paints.fillingPaint(Theme.fillingColor()));
2042-
}
2043-
}
2044-
}
2045-
});
2016+
recyclerView.addItemDecoration(new BottomInsetFillingDecoration(ColorId.filling));
20462017
settings.recyclerView = recyclerView;
20472018
if (b.allowResize) {
20482019
recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {

app/src/main/java/org/thunderdog/challegram/navigation/ViewPagerController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.widget.LinearLayout;
2424
import android.widget.TextView;
2525

26+
import androidx.annotation.CallSuper;
2627
import androidx.annotation.IdRes;
2728
import androidx.annotation.IntDef;
2829
import androidx.annotation.NonNull;
@@ -160,6 +161,12 @@ protected int getDrawerReplacementColorId () {
160161
}
161162

162163
@Override
164+
public final boolean supportsBottomInset () {
165+
return true;
166+
}
167+
168+
@Override
169+
@CallSuper
163170
protected void onBottomInsetChanged (int extraBottomInset, int extraBottomInsetWithoutIme, boolean isImeInset) {
164171
super.onBottomInsetChanged(extraBottomInset, extraBottomInsetWithoutIme, isImeInset);
165172
if (adapter != null) {

app/src/main/java/org/thunderdog/challegram/ui/BottomSheetViewController.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import android.content.Context;
55
import android.graphics.Canvas;
66
import android.graphics.Rect;
7-
import android.os.Build;
87
import android.view.MotionEvent;
98
import android.view.View;
109
import android.view.ViewGroup;
@@ -17,7 +16,6 @@
1716
import androidx.recyclerview.widget.LinearLayoutManager;
1817
import androidx.recyclerview.widget.RecyclerView;
1918

20-
import org.thunderdog.challegram.config.Device;
2119
import org.thunderdog.challegram.navigation.HeaderView;
2220
import org.thunderdog.challegram.navigation.TooltipOverlayView;
2321
import org.thunderdog.challegram.navigation.ViewController;
@@ -26,7 +24,6 @@
2624
import org.thunderdog.challegram.telegram.Tdlib;
2725
import org.thunderdog.challegram.theme.ColorId;
2826
import org.thunderdog.challegram.theme.Theme;
29-
import org.thunderdog.challegram.tool.Keyboard;
3027
import org.thunderdog.challegram.tool.Paints;
3128
import org.thunderdog.challegram.tool.Screen;
3229
import org.thunderdog.challegram.tool.UI;
@@ -245,14 +242,13 @@ protected void checkHeaderPosition (RecyclerView recyclerView) {
245242
}
246243

247244
protected int getTargetHeight () {
248-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
249-
return Screen.currentHeight()
250-
+ (context.isKeyboardVisible() ? Keyboard.getSize() : 0)
251-
- (Screen.needsKeyboardPadding(context) ? Screen.getNavigationBarFrameDifference() : 0)
252-
+ (context.isKeyboardVisible() && Device.NEED_ADD_KEYBOARD_SIZE ? Screen.getNavigationBarHeight() : 0);
253-
} else {
254-
return Screen.currentHeight();
255-
}
245+
return context().getRootView().getMeasuredHeight();
246+
}
247+
248+
@Override
249+
protected void onBottomInsetChanged (int extraBottomInset, int extraBottomInsetWithoutIme, boolean isImeInset) {
250+
super.onBottomInsetChanged(extraBottomInset, extraBottomInsetWithoutIme, isImeInset);
251+
invalidateAllItemDecorations();
256252
}
257253

258254
protected void invalidateAllItemDecorations () {
@@ -416,6 +412,7 @@ protected void setupPopupLayout (PopupLayout popupLayout) {
416412
popupLayout.setBoundController(this);
417413
popupLayout.setPopupHeightProvider(this);
418414
popupLayout.init(true);
415+
popupLayout.setNeedFullScreen(true);
419416
popupLayout.setTouchProvider(this);
420417
}
421418

@@ -527,12 +524,12 @@ public void getItemOffsets (@NonNull Rect outRect, @NonNull View view, RecyclerV
527524

528525
if (position == 0 || isUnknown) {
529526
top = controller.canHideByScroll() ?
530-
(controller.getTargetHeight() - HeaderView.getTopOffset()):
527+
(controller.getTargetHeight() - HeaderView.getTopOffset() - controller.context().getRootView().getSystemInsetsWithoutIme().bottom):
531528
(controller.getContentOffset());
532529
}
533530
if (position == itemCount - 1 || isUnknown) {
534531
final int itemsHeight = isUnknown ? view.getMeasuredHeight() : page.getItemsHeight(parent);
535-
final int parentHeight = parent.getMeasuredHeight();
532+
final int parentHeight = parent.getMeasuredHeight() - parent.getPaddingBottom();
536533
bottom = parentHeight - itemsHeight;
537534
}
538535

app/src/main/java/org/thunderdog/challegram/ui/MainController.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,6 @@ protected View onCreateView (Context context) {
187187
return super.onCreateView(context);
188188
}
189189

190-
@Override
191-
public boolean supportsBottomInset () {
192-
return true;
193-
}
194-
195190
@Override
196191
protected void onBottomInsetChanged (int extraBottomInset, int extraBottomInsetWithoutIme, boolean isImeInset) {
197192
super.onBottomInsetChanged(extraBottomInset, extraBottomInsetWithoutIme, isImeInset);

app/src/main/java/org/thunderdog/challegram/ui/MessageOptionsPagerController.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ public float getTranslationY () {
213213
return headerView;
214214
}
215215

216+
@Override
217+
protected void onBottomInsetChanged (int extraBottomInset, int extraBottomInsetWithoutIme, boolean isImeInset) {
218+
super.onBottomInsetChanged(extraBottomInset, extraBottomInsetWithoutIme, isImeInset);
219+
if (reactionsPickerController != null) {
220+
reactionsPickerController.setBottomInset(extraBottomInset, extraBottomInsetWithoutIme);
221+
}
222+
}
223+
216224
@Override
217225
protected void onBeforeCreateView () {
218226
headerCell = new ViewPagerHeaderViewReactionsCompact(context, state) {
@@ -445,7 +453,9 @@ protected int getContentOffset () {
445453
return (getTargetHeight()
446454
- (Screen.dp(54) + HeaderView.getTopOffset())
447455
- getOptionItemsHeight()
448-
- Screen.dp(1));
456+
- Screen.dp(1)
457+
- context().getRootView().getSystemInsetsWithoutIme().bottom
458+
);
449459
} else {
450460
return Screen.currentHeight() / 2;
451461
}
@@ -684,6 +694,7 @@ protected void onBottomHeaderLeaveSearchMode () {
684694
}
685695
};
686696
reactionsPickerController.setArguments(state);
697+
reactionsPickerController.setBottomInset(extraBottomInset, extraBottomInsetWithoutIme);
687698
reactionsPickerController.getValue();
688699

689700
reactionsPickerRecyclerView = reactionsPickerController.getRecyclerView();
@@ -705,7 +716,7 @@ public void getItemOffsets (@NonNull Rect outRect, @NonNull View view, @NonNull
705716

706717
if (position == itemCount - 1) {
707718
int keyboardHeight = getKeyboardState() ? Keyboard.getSize(Keyboard.getSize()) : 0;
708-
bottom = Math.max(parent.getMeasuredHeight() - reactionsPickerController.measureItemsHeight(), keyboardHeight + Screen.dp(64));
719+
bottom = Math.max(parent.getMeasuredHeight() - parent.getPaddingBottom() - reactionsPickerController.measureItemsHeight(), keyboardHeight + Screen.dp(64));
709720
}
710721

711722
outRect.set(leftRight, 0, leftRight, bottom);

app/src/main/java/org/thunderdog/challegram/ui/MessageOptionsReactedController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ private void processNewAddedReactions (TdApi.AddedReactions addedReactions) {
147147
items.add(new ListItem(ListItem.TYPE_LIST_INFO_VIEW));
148148
}
149149

150-
adapter.notifyItemRangeChanged(itemsCount, items.size() - itemsCount);
150+
if (itemsCount > 0) {
151+
adapter.notifyItemRangeChanged(itemsCount - 1, items.size() - itemsCount + 1);
152+
} else {
153+
adapter.notifyItemRangeChanged(itemsCount, items.size() - itemsCount);
154+
}
151155
}
152156

153157
@Override

app/src/main/java/org/thunderdog/challegram/ui/ReactionsPickerController.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.thunderdog.challegram.tool.Paints;
5454
import org.thunderdog.challegram.tool.Screen;
5555
import org.thunderdog.challegram.tool.UI;
56+
import org.thunderdog.challegram.tool.Views;
5657
import org.thunderdog.challegram.util.StickerSetsDataProvider;
5758
import org.thunderdog.challegram.v.CustomRecyclerView;
5859
import org.thunderdog.challegram.widget.EmojiLayout;
@@ -87,6 +88,21 @@ public ReactionsPickerController (Context context, Tdlib tdlib) {
8788
super(context, tdlib);
8889
}
8990

91+
@Override
92+
public boolean supportsBottomInset () {
93+
return true;
94+
}
95+
96+
@Override
97+
protected void onBottomInsetChanged (int extraBottomInset, int extraBottomInsetWithoutIme, boolean isImeInset) {
98+
super.onBottomInsetChanged(extraBottomInset, extraBottomInsetWithoutIme, isImeInset);
99+
Views.applyBottomInset(recyclerView, extraBottomInsetWithoutIme);
100+
Views.setLayoutHeight(bottomHeaderViewGroup, HeaderView.getSize(false) + extraBottomInsetWithoutIme);
101+
if (bottomHeaderView != null) {
102+
bottomHeaderView.setBackgroundHeight(HeaderView.getSize(false) + extraBottomInsetWithoutIme);
103+
}
104+
}
105+
90106
@Override
91107
protected View onCreateView (Context context) {
92108
ArrayList<EmojiSection> emojiSections = new ArrayList<>(3);
@@ -104,6 +120,7 @@ protected View onCreateView (Context context) {
104120
bottomHeaderCell.setSectionsOnClickListener(this::onStickerSectionClick);
105121

106122
recyclerView = onCreateRecyclerView();
123+
Views.applyBottomInset(recyclerView, extraBottomInsetWithoutIme);
107124
recyclerView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> reactionsController.invalidateStickerObjModifiers());
108125
recyclerView.setItemAnimator(null);
109126
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@@ -775,6 +792,7 @@ public boolean onTouchEvent (MotionEvent e) {
775792
};
776793
bottomHeaderView.initWithSingleController(fakeControllerForBottomHeader, false);
777794
bottomHeaderView.setLayoutParams(FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.BOTTOM));
795+
bottomHeaderView.setBackgroundHeight(HeaderView.getSize(false) + extraBottomInsetWithoutIme);
778796
fakeControllerForBottomHeader.attachHeaderViewWithoutNavigation(bottomHeaderView);
779797

780798
emojiTypesRecyclerView = new EmojiCategoriesRecyclerView(context);
@@ -785,7 +803,7 @@ public boolean onTouchEvent (MotionEvent e) {
785803
emojiTypesRecyclerView.setMinimalLeftPadding(((int) U.measureText(Lang.getString(R.string.Search), Paints.getRegularTextPaint(16))) + Screen.dp(68 - 56));
786804

787805
bottomHeaderViewGroup = new FrameLayout(context);
788-
bottomHeaderViewGroup.setLayoutParams(FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, HeaderView.getSize(false), Gravity.BOTTOM));
806+
bottomHeaderViewGroup.setLayoutParams(FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, HeaderView.getSize(false) + extraBottomInsetWithoutIme, Gravity.BOTTOM));
789807
bottomHeaderViewGroup.addView(bottomHeaderView);
790808
bottomHeaderViewGroup.addView(emojiTypesRecyclerView);
791809
}

app/src/main/java/org/thunderdog/challegram/widget/ListInfoView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,8 @@ private void setText (CharSequence text) {
125125
requestLayout();
126126
}
127127
}
128+
129+
public CharSequence getText () {
130+
return textView.getText();
131+
}
128132
}

app/src/main/java/org/thunderdog/challegram/widget/RootFrameLayout.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,10 @@ public Rect getSystemInsets () {
493493
return systemInsets;
494494
}
495495

496+
public Rect getSystemInsetsWithoutIme () {
497+
return systemInsetsWithoutIme;
498+
}
499+
496500
private int previousHeight;
497501
private int previousWidth;
498502

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.thunderdog.challegram.widget.decoration;
2+
3+
import android.graphics.Canvas;
4+
import android.view.View;
5+
6+
import androidx.annotation.NonNull;
7+
import androidx.recyclerview.widget.LinearLayoutManager;
8+
import androidx.recyclerview.widget.RecyclerView;
9+
10+
import org.thunderdog.challegram.theme.ColorId;
11+
import org.thunderdog.challegram.theme.Theme;
12+
import org.thunderdog.challegram.tool.Paints;
13+
14+
public class BottomInsetFillingDecoration extends RecyclerView.ItemDecoration {
15+
private final @ColorId int colorId;
16+
17+
public BottomInsetFillingDecoration (int colorId) {
18+
this.colorId = colorId;
19+
}
20+
21+
@Override
22+
public void onDraw (@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
23+
super.onDraw(c, parent, state);
24+
25+
LinearLayoutManager manager = (LinearLayoutManager) parent.getLayoutManager();
26+
27+
int maxBottom = -1;
28+
boolean hasBottom = false;
29+
for (int i = 0; i < manager.getChildCount(); i++) {
30+
View view = manager.getChildAt(i);
31+
if (view != null) {
32+
int bottom = manager.getDecoratedBottom(view);
33+
if (hasBottom) {
34+
maxBottom = Math.max(bottom, maxBottom);
35+
} else {
36+
maxBottom = bottom;
37+
}
38+
hasBottom = true;
39+
}
40+
}
41+
42+
if (hasBottom) {
43+
int height = parent.getMeasuredHeight();
44+
if (height > maxBottom) {
45+
c.drawRect(0, maxBottom, parent.getMeasuredWidth(), height, Paints.fillingPaint(Theme.getColor(colorId)));
46+
}
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)