1515package org .thunderdog .challegram .component .preview ;
1616
1717import android .content .Context ;
18+ import android .graphics .Canvas ;
19+ import android .graphics .Rect ;
1820import android .net .Uri ;
1921import android .view .Gravity ;
2022import android .view .View ;
2123import android .view .ViewGroup ;
2224import android .widget .TextView ;
2325
2426import androidx .annotation .CallSuper ;
27+ import androidx .annotation .NonNull ;
2528import androidx .annotation .StringRes ;
2629import androidx .collection .SparseArrayCompat ;
2730
3437import org .thunderdog .challegram .navigation .OptionsLayout ;
3538import org .thunderdog .challegram .navigation .ViewController ;
3639import org .thunderdog .challegram .support .RippleSupport ;
40+ import org .thunderdog .challegram .theme .Theme ;
3741import org .thunderdog .challegram .theme .ThemeListenerList ;
42+ import org .thunderdog .challegram .tool .Paints ;
3843import org .thunderdog .challegram .tool .Screen ;
3944import org .thunderdog .challegram .tool .Strings ;
4045import org .thunderdog .challegram .tool .UI ;
46+ import org .thunderdog .challegram .tool .Views ;
47+ import org .thunderdog .challegram .unsorted .Settings ;
4148import org .thunderdog .challegram .widget .PopupLayout ;
49+ import org .thunderdog .challegram .widget .RootFrameLayout ;
4250
4351import 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 );
0 commit comments