Skip to content

Commit 72281a5

Browse files
committed
Update insets handling on Android 11-14
1 parent 77570e8 commit 72281a5

File tree

17 files changed

+61
-28
lines changed

17 files changed

+61
-28
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ android {
7171

7272
buildConfigField("boolean", "EXPERIMENTAL", isExperimentalBuild.toString())
7373

74+
buildConfigInt("TARGET_SDK_INT", versions.getIntOrThrow("version.sdk_target"))
75+
7476
buildConfigInt("TELEGRAM_API_ID", properties.getIntOrThrow("telegram.api_id"))
7577
buildConfigString("TELEGRAM_API_HASH", properties.getOrThrow("telegram.api_hash"))
7678

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,7 @@ public RootFrameLayout getRootView () {
19611961
}
19621962

19631963
public int getVisibleContentHeight () {
1964-
if (Config.ENABLE_EDGE_TO_EDGE) {
1964+
if (Settings.instance().useEdgeToEdge()) {
19651965
return rootView.getInnerContentHeight();
19661966
} else {
19671967
return contentView.getMeasuredHeight();
@@ -2103,7 +2103,7 @@ public boolean openForceTouch (ForceTouchView.ForceTouchContext context) {
21032103
// forceTouchWindow.setNeedRootInsets();
21042104
}
21052105
forceTouchWindow.init(true);
2106-
forceTouchWindow.setNeedFullScreen(Config.ENABLE_EDGE_TO_EDGE);
2106+
forceTouchWindow.setNeedFullScreen(Settings.instance().useEdgeToEdge());
21072107
if (!context.allowFullscreen()) {
21082108
forceTouchWindow.setNeedRootInsets();
21092109
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.thunderdog.challegram.theme.ColorId;
4141
import org.thunderdog.challegram.tool.Screen;
4242
import org.thunderdog.challegram.tool.Views;
43+
import org.thunderdog.challegram.unsorted.Settings;
4344
import org.thunderdog.challegram.util.HapticMenuHelper;
4445
import org.thunderdog.challegram.widget.EmptyTextView;
4546

@@ -148,7 +149,7 @@ protected final void initMetrics () { // FIXME make private again and move calli
148149
}
149150

150151
private int getBarHeightIfAvailable () {
151-
return mediaLayout.inSpecificMode() && mediaLayout.getMode() != MediaLayout.MODE_CUSTOM_ADAPTER ? 0 : MediaBottomBar.getBarHeight() + (Config.ENABLE_EDGE_TO_EDGE ? context.getRootView().getSystemInsetsWithoutIme().bottom : 0);
152+
return mediaLayout.inSpecificMode() && mediaLayout.getMode() != MediaLayout.MODE_CUSTOM_ADAPTER ? 0 : MediaBottomBar.getBarHeight() + (Settings.instance().useEdgeToEdge() ? context.getRootView().getSystemInsetsWithoutIme().bottom : 0);
152153
}
153154

154155
private void resetStartHeights (boolean initial) {

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
@@ -521,7 +521,7 @@ public void show (boolean overlayStatusBar) {
521521
popupLayout.setDismissListener(this);
522522
popupLayout.setNeedRootInsets();
523523
popupLayout.setOverlayStatusBar(overlayStatusBar);
524-
popupLayout.init(!Config.ENABLE_EDGE_TO_EDGE);
524+
popupLayout.init(true);
525525
popupLayout.showAnimatedPopupView(this, this);
526526
}
527527

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +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;
250+
public static final boolean EDGE_TO_EDGE_AVAILABLE = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R;
251+
public static final boolean EDGE_TO_EDGE_CUSTOMIZABLE = EDGE_TO_EDGE_AVAILABLE && (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM || BuildConfig.TARGET_SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM);
251252

252253
public static final boolean PREFER_RENDER_EXTENSIONS = true;
253254

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ public class MediaViewController extends ViewController<MediaViewController.Args
205205
public static final int MODE_SECRET = 4; // just single photo, no animations and etc
206206
public static final int MODE_SIMPLE = 5;
207207

208-
private static final boolean APPLY_ALL_INSETS = Config.ENABLE_EDGE_TO_EDGE;
208+
private boolean useEdgeToEdge () {
209+
return Settings.instance().useEdgeToEdge();
210+
}
209211

210212
public MediaViewController (Context context, Tdlib tdlib) {
211213
super(context, tdlib);
@@ -3432,7 +3434,7 @@ private void animateVideoFactor (float toFactor) {
34323434
private boolean ignoreCaptionUpdate;
34333435

34343436
private boolean canRunFullscreen () {
3435-
if (APPLY_ALL_INSETS) {
3437+
if (useEdgeToEdge()) {
34363438
return true;
34373439
}
34383440
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Config.CUTOUT_ENABLED && mode == MODE_MESSAGES) {
@@ -3485,7 +3487,7 @@ private int measureBottomWrapHeight () {
34853487
if (captionFactor == 1f && captionWrapView != null) {
34863488
height += captionWrapView.getMeasuredHeight();
34873489
}
3488-
if (APPLY_ALL_INSETS) {
3490+
if (useEdgeToEdge()) {
34893491
height += bottomInnerMargin;
34903492
}
34913493
return height;
@@ -5128,7 +5130,7 @@ protected void onDraw (Canvas c) {
51285130
headerView.setElevation(Screen.dp(3f));
51295131
}
51305132
attachHeaderViewWithoutNavigation(headerView);
5131-
headerView.initWithSingleController(this, APPLY_ALL_INSETS || ((SET_FULLSCREEN_ON_OPEN || canRunFullscreen()) && !Config.CUTOUT_ENABLED));
5133+
headerView.initWithSingleController(this, useEdgeToEdge() || ((SET_FULLSCREEN_ON_OPEN || canRunFullscreen()) && !Config.CUTOUT_ENABLED));
51325134
headerView.getFilling().setShadowAlpha(0f);
51335135
int leftMargin = Screen.dp(68f);
51345136
int rightMargin = measureButtonsPadding();
@@ -5430,8 +5432,8 @@ public void dispatchSystemInsets (View parentView, ViewGroup.MarginLayoutParams
54305432
int bottomInset = insets.bottom;
54315433
boolean changed = this.bottomInnerMargin != bottomInset;
54325434
this.bottomInnerMargin = bottomInset;
5433-
if (APPLY_ALL_INSETS || (mode == MODE_GALLERY && isFromCamera)) {
5434-
int controlsMargin = APPLY_ALL_INSETS || bottomInset <= Screen.getNavigationBarHeight() ? bottomInset : 0;
5435+
if (useEdgeToEdge() || (mode == MODE_GALLERY && isFromCamera)) {
5436+
int controlsMargin = useEdgeToEdge() || bottomInset <= Screen.getNavigationBarHeight() ? bottomInset : 0;
54355437
setControlsMargin(controlsMargin);
54365438
int bottomOffset = getSectionBottomOffset(SECTION_CROP);
54375439
Views.setBottomMargin(cropTargetView, bottomOffset);
@@ -5706,7 +5708,7 @@ private int getSectionBottomOffset (int section) {
57065708
if (mode != MODE_GALLERY) {
57075709
return 0;
57085710
}
5709-
int add = APPLY_ALL_INSETS || isFromCamera ? this.bottomInnerMargin : 0;
5711+
int add = useEdgeToEdge() || isFromCamera ? this.bottomInnerMargin : 0;
57105712
switch (section) {
57115713
case SECTION_CAPTION: {
57125714
return 0; // Screen.dp(56f);
@@ -8640,7 +8642,7 @@ private void openForceEditMode () {
86408642
}
86418643

86428644
private void stopFullScreenTemporarily (boolean stop) {
8643-
if (APPLY_ALL_INSETS) {
8645+
if (useEdgeToEdge()) {
86448646
return;
86458647
}
86468648
if (stop) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.thunderdog.challegram.tool.Paints;
3434
import org.thunderdog.challegram.tool.Screen;
3535
import org.thunderdog.challegram.tool.UI;
36+
import org.thunderdog.challegram.unsorted.Settings;
3637

3738
public class RootDrawable extends Drawable {
3839
private final RootState state;
@@ -57,7 +58,7 @@ public void draw (@NonNull final Canvas c) {
5758
if (!state.isDisabled) {
5859
c.drawColor(Theme.getColor(state.getColorId()));
5960
}
60-
if (Config.ENABLE_EDGE_TO_EDGE) {
61+
if (Settings.instance().useEdgeToEdge()) {
6162
int width = state.context.getRootView().getMeasuredWidth();
6263
int height = state.context.getRootView().getMeasuredHeight();
6364
Rect rect = state.context.getRootView().getSystemInsetsWithoutIme();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public static ViewController<?> getCurrentStackItem (Context context) {
588588
public static void clearActivity (BaseActivity a) {
589589
a.requestWindowFeature(Window.FEATURE_NO_TITLE);
590590
Window w = a.getWindow();
591-
if (Config.ENABLE_EDGE_TO_EDGE) {
591+
if (Settings.instance().useEdgeToEdge()) {
592592
w.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
593593
} else {
594594
w.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.thunderdog.challegram.tool.Screen;
3030
import org.thunderdog.challegram.tool.UI;
3131
import org.thunderdog.challegram.tool.Views;
32+
import org.thunderdog.challegram.unsorted.Settings;
3233
import org.thunderdog.challegram.v.CustomRecyclerView;
3334
import org.thunderdog.challegram.widget.LickView;
3435
import org.thunderdog.challegram.widget.PopupLayout;
@@ -528,7 +529,7 @@ public void getItemOffsets (@NonNull Rect outRect, @NonNull View view, RecyclerV
528529

529530
if (position == 0 || isUnknown) {
530531
top = controller.canHideByScroll() ?
531-
(controller.getTargetHeight() - HeaderView.getTopOffset() - (Config.ENABLE_EDGE_TO_EDGE ? controller.context().getRootView().getSystemInsetsWithoutIme().bottom : 0)):
532+
(controller.getTargetHeight() - HeaderView.getTopOffset() - (Settings.instance().useEdgeToEdge() ? controller.context().getRootView().getSystemInsetsWithoutIme().bottom : 0)):
532533
(controller.getContentOffset());
533534
}
534535
if (position == itemCount - 1 || isUnknown) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.thunderdog.challegram.tool.Screen;
5858
import org.thunderdog.challegram.tool.UI;
5959
import org.thunderdog.challegram.tool.Views;
60+
import org.thunderdog.challegram.unsorted.Settings;
6061
import org.thunderdog.challegram.util.DrawableProvider;
6162
import org.thunderdog.challegram.util.OptionDelegate;
6263
import org.thunderdog.challegram.util.text.Counter;
@@ -459,7 +460,7 @@ protected int getContentOffset () {
459460
- (Screen.dp(54) + HeaderView.getTopOffset())
460461
- getOptionItemsHeight()
461462
- Screen.dp(1)
462-
- (Config.ENABLE_EDGE_TO_EDGE ? context().getRootView().getSystemInsetsWithoutIme().bottom : 0)
463+
- (Settings.instance().useEdgeToEdge() ? context().getRootView().getSystemInsetsWithoutIme().bottom : 0)
463464
);
464465
} else {
465466
return Screen.currentHeight() / 2;

0 commit comments

Comments
 (0)