Skip to content

Commit dac16e3

Browse files
committed
Support edge-to-edge in web preview pop-ups
1 parent 1e562da commit dac16e3

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

app/src/main/java/org/thunderdog/challegram/component/preview/PreviewLayout.java

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
package org.thunderdog.challegram.component.preview;
1616

1717
import android.content.Context;
18+
import android.graphics.Canvas;
19+
import android.graphics.Rect;
1820
import android.net.Uri;
1921
import android.view.Gravity;
2022
import android.view.View;
2123
import android.view.ViewGroup;
2224
import android.widget.TextView;
2325

2426
import androidx.annotation.CallSuper;
27+
import androidx.annotation.NonNull;
2528
import androidx.annotation.StringRes;
2629
import androidx.collection.SparseArrayCompat;
2730

@@ -34,15 +37,20 @@
3437
import org.thunderdog.challegram.navigation.OptionsLayout;
3538
import org.thunderdog.challegram.navigation.ViewController;
3639
import org.thunderdog.challegram.support.RippleSupport;
40+
import org.thunderdog.challegram.theme.Theme;
3741
import org.thunderdog.challegram.theme.ThemeListenerList;
42+
import org.thunderdog.challegram.tool.Paints;
3843
import org.thunderdog.challegram.tool.Screen;
3944
import org.thunderdog.challegram.tool.Strings;
4045
import org.thunderdog.challegram.tool.UI;
46+
import org.thunderdog.challegram.tool.Views;
47+
import org.thunderdog.challegram.unsorted.Settings;
4148
import org.thunderdog.challegram.widget.PopupLayout;
49+
import org.thunderdog.challegram.widget.RootFrameLayout;
4250

4351
import me.vkryl.android.widget.FrameLayoutFix;
4452

45-
public abstract class PreviewLayout extends FrameLayoutFix implements View.OnClickListener, PopupLayout.ShowListener, PopupLayout.DismissListener {
53+
public abstract class PreviewLayout extends FrameLayoutFix implements View.OnClickListener, PopupLayout.ShowListener, PopupLayout.DismissListener, RootFrameLayout.InsetsChangeListener {
4654
protected EmbeddedService nativeEmbed;
4755
protected int footerHeight;
4856
protected final ViewController<?> parent;
@@ -57,6 +65,7 @@ public PreviewLayout (Context context, final ViewController<?> parent) {
5765
addFooterItem(R.id.btn_openLink, R.string.OpenInExternalApp, R.drawable.baseline_open_in_browser_24);
5866

5967
setLayoutParams(FrameLayoutFix.newParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));
68+
themeListeners.addThemeInvalidateListener(this);
6069

6170
UI.getContext(context).addGlobalThemeListeners(themeListeners);
6271
}
@@ -112,12 +121,62 @@ private void show () {
112121
popupLayout.setOverlayStatusBar(true);
113122
popupLayout.setShowListener(this);
114123
popupLayout.setDismissListener(this);
124+
popupLayout.init(true);
115125
popupLayout.showSimplePopupView(this, getPreviewHeight());
116126
}
117127

128+
private RootFrameLayout rootFrameLayout;
129+
130+
@Override
131+
protected void onAttachedToWindow () {
132+
super.onAttachedToWindow();
133+
if (Settings.instance().useEdgeToEdge()) {
134+
rootFrameLayout = Views.findAncestor(this, RootFrameLayout.class, false);
135+
if (rootFrameLayout != null) {
136+
rootFrameLayout.addInsetsChangeListener(this);
137+
Rect rect = rootFrameLayout.getSystemInsetsWithoutIme();
138+
setVerticalInsets(rect.top, rect.bottom);
139+
}
140+
}
141+
}
142+
143+
@Override
144+
protected void onDetachedFromWindow () {
145+
super.onDetachedFromWindow();
146+
if (rootFrameLayout != null) {
147+
rootFrameLayout.removeInsetsChangeListener(this);
148+
rootFrameLayout = null;
149+
}
150+
}
151+
152+
@Override
153+
public void onInsetsChanged (RootFrameLayout viewGroup, Rect effectiveInsets, Rect effectiveInsetsWithoutIme, Rect systemInsets, Rect systemInsetsWithoutIme, boolean isUpdate) {
154+
setVerticalInsets(systemInsetsWithoutIme.top, systemInsetsWithoutIme.bottom);
155+
}
156+
157+
private int topInset, bottomInset;
158+
159+
private void setVerticalInsets (int top, int bottomInset) {
160+
if (this.topInset != top || this.bottomInset != bottomInset) {
161+
this.topInset = top;
162+
this.bottomInset = bottomInset;
163+
Views.setPaddingBottom(this, bottomInset);
164+
setWillNotDraw(bottomInset == 0);
165+
UI.post(this::requestLayout);
166+
}
167+
}
168+
169+
@Override
170+
protected void onDraw (@NonNull Canvas c) {
171+
super.onDraw(c);
172+
if (getPaddingBottom() != 0) {
173+
c.drawRect(0, getMeasuredHeight() - getPaddingBottom(), getMeasuredWidth(), getMeasuredHeight(), Paints.fillingPaint(Theme.fillingColor()));
174+
}
175+
}
176+
118177
@Override
119178
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
120-
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(computeHeight(MeasureSpec.getSize(widthMeasureSpec)), MeasureSpec.EXACTLY));
179+
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(computeHeight(MeasureSpec.getSize(widthMeasureSpec)) + bottomInset + topInset, MeasureSpec.EXACTLY));
121180
}
122181

123182
protected abstract int computeHeight (int currentWidth);

app/src/main/java/org/thunderdog/challegram/component/preview/WebViewPreviewLayout.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import android.widget.FrameLayout;
2929

3030
import org.thunderdog.challegram.BaseActivity;
31-
import org.thunderdog.challegram.config.Config;
3231
import org.thunderdog.challegram.data.EmbeddedService;
3332
import org.thunderdog.challegram.navigation.ViewController;
3433
import org.thunderdog.challegram.player.TGPlayerController;

0 commit comments

Comments
 (0)