Skip to content

Commit 528d6a5

Browse files
committed
Rework insets API + Support Android 15 on chats screen
1 parent ae3fefd commit 528d6a5

29 files changed

+419
-127
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import android.content.res.Configuration;
3131
import android.graphics.PorterDuff;
3232
import android.graphics.PorterDuffColorFilter;
33+
import android.graphics.Rect;
3334
import android.graphics.drawable.Drawable;
3435
import android.hardware.Sensor;
3536
import android.hardware.SensorEvent;
@@ -1956,7 +1957,7 @@ public RootFrameLayout getRootView () {
19561957
}
19571958

19581959
public int getVisibleContentHeight () {
1959-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
1960+
if (Config.ENABLE_EDGE_TO_EDGE) {
19601961
return rootView.getInnerContentHeight();
19611962
} else {
19621963
return contentView.getMeasuredHeight();
@@ -3129,9 +3130,14 @@ private void onCameraCompletelyOpen () { // camera is fully visible & user is no
31293130
hideSoftwareKeyboard();
31303131
}
31313132

3132-
public boolean dispatchCameraMargins (View view, int left, int top, int right, int bottom) {
3133+
public boolean dispatchCameraMargins (View view, Rect legacyInsets, Rect insets, Rect insetsWithoutIme) {
31333134
if (view != null && camera != null && camera.getWrapUnchecked() == view) {
3134-
camera.setControlMargins(left, top, right, bottom);
3135+
camera.setControlMargins(
3136+
insetsWithoutIme.left,
3137+
insetsWithoutIme.top,
3138+
insetsWithoutIme.right,
3139+
insetsWithoutIme.bottom
3140+
);
31353141
return true;
31363142
}
31373143
return false;

app/src/main/java/org/thunderdog/challegram/component/attach/MediaLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ public void show (boolean overlayStatusBar) {
494494
popupLayout.setDismissListener(this);
495495
popupLayout.setNeedRootInsets();
496496
popupLayout.setOverlayStatusBar(overlayStatusBar);
497-
popupLayout.init(Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM);
497+
popupLayout.init(!Config.ENABLE_EDGE_TO_EDGE);
498498
popupLayout.showAnimatedPopupView(this, this);
499499
}
500500

app/src/main/java/org/thunderdog/challegram/component/sticker/StickerSetWrap.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.annotation.SuppressLint;
1818
import android.content.Context;
1919
import android.graphics.Canvas;
20+
import android.graphics.Rect;
2021
import android.os.Build;
2122
import android.text.TextUtils;
2223
import android.util.TypedValue;
@@ -61,6 +62,7 @@
6162
import org.thunderdog.challegram.widget.NoScrollTextView;
6263
import org.thunderdog.challegram.widget.PopupLayout;
6364
import org.thunderdog.challegram.widget.ProgressComponentView;
65+
import org.thunderdog.challegram.widget.RootFrameLayout;
6466
import org.thunderdog.challegram.widget.ShadowView;
6567

6668
import java.util.ArrayList;
@@ -78,7 +80,7 @@
7880
import tgx.td.Td;
7981

8082
@SuppressLint("ViewConstructor")
81-
public class StickerSetWrap extends FrameLayoutFix implements StickersListController.StickerSetProvider, MediaStickersAdapter.OffsetProvider, View.OnClickListener, FactorAnimator.Target, PopupLayout.PopupHeightProvider, StickersListener {
83+
public class StickerSetWrap extends FrameLayoutFix implements StickersListController.StickerSetProvider, MediaStickersAdapter.OffsetProvider, View.OnClickListener, FactorAnimator.Target, PopupLayout.PopupHeightProvider, StickersListener, RootFrameLayout.InsetsChangeListener {
8284
private final HeaderView headerView;
8385
private final StickersListController stickersController;
8486
private final FrameLayoutFix bottomWrap;
@@ -122,6 +124,8 @@ protected void onDraw (Canvas c) {
122124

123125
private final Tdlib tdlib;
124126

127+
private final FrameLayoutFix buttonWrap;
128+
125129
public StickerSetWrap (Context context, Tdlib tdlib) {
126130
super(context);
127131

@@ -136,7 +140,7 @@ public StickerSetWrap (Context context, Tdlib tdlib) {
136140
bottomWrap.addView(shadowView);
137141
themeListener.addThemeInvalidateListener(shadowView);
138142

139-
FrameLayoutFix buttonWrap = new FrameLayoutFix(context);
143+
buttonWrap = new FrameLayoutFix(context);
140144
ViewSupport.setThemedBackground(buttonWrap, ColorId.filling);
141145
themeListener.addThemeInvalidateListener(buttonWrap);
142146
buttonWrap.setLayoutParams(FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(56f), Gravity.BOTTOM));
@@ -204,6 +208,13 @@ public void invalidate () {
204208
super.invalidate();
205209
}
206210

211+
@Override
212+
public void onInsetsChanged (RootFrameLayout viewGroup, Rect effectiveInsets, Rect effectiveInsetsWithoutIme, boolean isUpdate) {
213+
Views.setLayoutHeight(buttonWrap, Screen.dp(56f) + effectiveInsetsWithoutIme.bottom);
214+
buttonWrap.setPadding(0, 0, 0, effectiveInsetsWithoutIme.bottom);
215+
Views.setLayoutHeight(bottomWrap, Screen.dp(56f) + Screen.dp(7f) + effectiveInsetsWithoutIme.bottom);
216+
}
217+
207218
@Override
208219
public boolean onStickerClick (View view, TGStickerObj sticker, boolean isMenuClick, TdApi.MessageSendOptions sendOptions) {
209220
NavigationController navigation = UI.getContext(getContext()).navigation();
@@ -689,7 +700,8 @@ public void showStickerSet () {
689700
});
690701
popupLayout.setShowListener(popup -> stickersController.setItemAnimator());
691702
popupLayout.setPopupHeightProvider(this);
692-
popupLayout.init(Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM);
703+
popupLayout.init(true);
704+
popupLayout.addInsetsChangeListener(this);
693705
popupLayout.setHideKeyboard();
694706
popupLayout.setNeedRootInsets();
695707
popupLayout.showSimplePopupView(this, calculateTotalHeight());

app/src/main/java/org/thunderdog/challegram/config/Config.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ public static boolean useCloudPlayback (TdApi.Message playPauseFile) {
247247
public static final boolean USE_CUSTOM_NAVIGATION_COLOR = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
248248
public static final boolean USE_TRANSPARENT_STATUS_BAR = false; // Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM;
249249

250+
public static final boolean ENABLE_EDGE_TO_EDGE = Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM;
251+
250252
public static final boolean PREFER_RENDER_EXTENSIONS = true;
251253

252254
public static final boolean NEED_ONLINE = true; // !BuildConfig.DEBUG;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public class MediaViewController extends ViewController<MediaViewController.Args
202202
public static final int MODE_SECRET = 4; // just single photo, no animations and etc
203203
public static final int MODE_SIMPLE = 5;
204204

205-
private static final boolean APPLY_ALL_INSETS = Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM;
205+
private static final boolean APPLY_ALL_INSETS = Config.ENABLE_EDGE_TO_EDGE;
206206

207207
public MediaViewController (Context context, Tdlib tdlib) {
208208
super(context, tdlib);
@@ -5322,11 +5322,12 @@ private void setAppliedBottomPadding (int padding) {
53225322
}
53235323

53245324
@Override
5325-
public boolean dispatchSystemInsets (View parentView, ViewGroup.MarginLayoutParams originalParams, int left, int top, int right, int bottom) {
5326-
boolean changed = this.bottomInnerMargin != bottom;
5327-
this.bottomInnerMargin = bottom;
5325+
public void dispatchSystemInsets (View parentView, ViewGroup.MarginLayoutParams originalParams, Rect legacyInsets, Rect insets, Rect insetsWithoutIme, boolean fitsSystemWindows) {
5326+
super.dispatchSystemInsets(parentView, originalParams, legacyInsets, insets, insetsWithoutIme, fitsSystemWindows);
5327+
boolean changed = this.bottomInnerMargin != legacyInsets.bottom;
5328+
this.bottomInnerMargin = legacyInsets.bottom;
53285329
if (APPLY_ALL_INSETS || (mode == MODE_GALLERY && isFromCamera)) {
5329-
int controlsMargin = APPLY_ALL_INSETS || bottom <= Screen.getNavigationBarHeight() ? bottom : 0;
5330+
int controlsMargin = APPLY_ALL_INSETS || legacyInsets.bottom <= Screen.getNavigationBarHeight() ? legacyInsets.bottom : 0;
53305331
setControlsMargin(controlsMargin);
53315332
int bottomOffset = getSectionBottomOffset(SECTION_CROP);
53325333
Views.setBottomMargin(cropTargetView, bottomOffset);
@@ -5345,7 +5346,6 @@ public boolean dispatchSystemInsets (View parentView, ViewGroup.MarginLayoutPara
53455346
}
53465347
mediaView.layoutCells();
53475348
}
5348-
return super.dispatchSystemInsets(parentView, originalParams, left, top, right, bottom);
53495349
}
53505350

53515351
@Override

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,15 @@ public void onActivityResume () {
220220
}
221221

222222
@Override
223-
public boolean dispatchSystemInsets (View parentView, ViewGroup.MarginLayoutParams originalParams, int left, int top, int right, int bottom) {
224-
boolean updated = super.dispatchSystemInsets(parentView, originalParams, left, top, right, bottom);
223+
public boolean supportsBottomInset () {
224+
return true;
225+
}
226+
227+
@Override
228+
public void dispatchSystemInsets (View parentView, ViewGroup.MarginLayoutParams originalParams, Rect legacyInsets, Rect insets, Rect insetsWithoutIme, boolean fitsSystemWindows) {
229+
super.dispatchSystemInsets(parentView, originalParams, legacyInsets, insets, insetsWithoutIme, fitsSystemWindows);
230+
originalParams.bottomMargin = 0;
225231
recyclerView.setPadding(0, 0, 0, systemInsets.bottom);
226-
return updated;
227232
}
228233

229234
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected void onAttachedToWindow () {
9090
}
9191

9292
@Override
93-
public void onInsetsChanged (RootFrameLayout viewGroup, Rect effectiveInsets, Rect systemInsets, boolean isUpdate) {
93+
public void onInsetsChanged (RootFrameLayout viewGroup, Rect effectiveInsets, Rect effectiveInsetsWithoutIme, boolean isUpdate) {
9494
applyTopInset(effectiveInsets.top);
9595
}
9696

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ protected void onDetachedFromWindow () {
208208
}
209209

210210
@Override
211-
public void onInsetsChanged (RootFrameLayout viewGroup, Rect effectiveInsets, Rect systemInsets, boolean isUpdate) {
211+
public void onInsetsChanged (RootFrameLayout viewGroup, Rect effectiveInsets, Rect effectiveInsetsWithoutIme, boolean isUpdate) {
212212
setHeaderOffset(effectiveInsets.top);
213213
}
214214

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.animation.ValueAnimator;
2020
import android.content.Context;
2121
import android.content.res.Configuration;
22+
import android.graphics.Rect;
2223
import android.os.Build;
2324
import android.view.Gravity;
2425
import android.view.View;
@@ -1545,8 +1546,31 @@ public void onLanguagePackEvent (int event, int arg1) {
15451546
// TODO more
15461547
}
15471548

1548-
public boolean dispatchInnerMargins (View child, ViewGroup.MarginLayoutParams layoutParams, int left, int top, int right, int bottom) {
1549-
// TODO per-controller bottom margin handling
1550-
return Views.setMargins(layoutParams, left, top, right, bottom);
1549+
private int bottomInset, bottomInsetWithoutIme;
1550+
1551+
public void applyBottomInset (ViewController<?> controller) {
1552+
if (controller.supportsBottomInset()) {
1553+
controller.setBottomInset(bottomInset, bottomInsetWithoutIme);
1554+
} else {
1555+
View view = controller.getValue();
1556+
Views.setBottomMargin(view, bottomInset);
1557+
}
1558+
}
1559+
1560+
private void setBottomInset (int bottomInset, int bottomInsetWithoutIme) {
1561+
if (this.bottomInset != bottomInset || this.bottomInsetWithoutIme != bottomInsetWithoutIme) {
1562+
this.bottomInset = bottomInset;
1563+
this.bottomInsetWithoutIme = bottomInsetWithoutIme;
1564+
if (childWrappers != null) {
1565+
for (ViewController<?> controller : childWrappers) {
1566+
applyBottomInset(controller);
1567+
}
1568+
}
1569+
}
1570+
}
1571+
1572+
public void dispatchSystemInsets (View child, ViewGroup.MarginLayoutParams layoutParams, Rect legacyInsets, Rect systemInsets, Rect systemInsetWithoutIme) {
1573+
Views.setMargins(layoutParams, legacyInsets.left, legacyInsets.top, legacyInsets.right, 0);
1574+
setBottomInset(systemInsets.bottom, systemInsetWithoutIme.bottom);
15511575
}
15521576
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected void onDetachedFromWindow () {
5050
}
5151

5252
@Override
53-
public void onInsetsChanged (RootFrameLayout viewGroup, Rect effectiveInsets, Rect systemInsets, boolean isUpdate) {
53+
public void onInsetsChanged (RootFrameLayout viewGroup, Rect effectiveInsets, Rect effectiveInsetsWithoutIme, boolean isUpdate) {
5454
applyTopInset(effectiveInsets.top);
5555
}
5656

0 commit comments

Comments
 (0)