44
44
import android .view .WindowManager ;
45
45
import android .view .animation .Interpolator ;
46
46
import android .widget .Button ;
47
+ import android .widget .FrameLayout ;
47
48
import android .widget .LinearLayout ;
48
49
import android .widget .TextView ;
49
50
112
113
import org .thunderdog .challegram .util .text .TextEntity ;
113
114
import org .thunderdog .challegram .v .HeaderEditText ;
114
115
import org .thunderdog .challegram .widget .CustomTextView ;
116
+ import org .thunderdog .challegram .widget .FillingDecoration ;
115
117
import org .thunderdog .challegram .widget .ForceTouchView ;
116
118
import org .thunderdog .challegram .widget .InfiniteRecyclerView ;
117
119
import org .thunderdog .challegram .widget .MaterialEditText ;
118
120
import org .thunderdog .challegram .widget .MaterialEditTextGroup ;
119
121
import org .thunderdog .challegram .widget .NoScrollTextView ;
120
122
import org .thunderdog .challegram .widget .PopupLayout ;
123
+ import org .thunderdog .challegram .widget .RootFrameLayout ;
121
124
import org .thunderdog .challegram .widget .SeparatorView ;
122
125
import org .thunderdog .challegram .widget .ShadowView ;
123
126
import org .thunderdog .challegram .widget .TimerView ;
@@ -1905,6 +1908,43 @@ public final void showSettings (final @IdRes int id, ListItem[] rawItems, final
1905
1908
showSettings (new SettingsWrapBuilder (id ).setRawItems (rawItems ).setIntDelegate (delegate ).setAllowResize (allowResize ));
1906
1909
}
1907
1910
1911
+ private static class SettingsWrapLayout extends FrameLayoutFix implements RootFrameLayout .MarginModifier {
1912
+ public SettingsWrapLayout (@ NonNull Context context ) {
1913
+ super (context );
1914
+ }
1915
+
1916
+ @ Override
1917
+ public void onApplyMarginInsets (View child , LayoutParams params , Rect legacyInsets , Rect insets , Rect insetsWithoutIme ) {
1918
+ Views .setMargins (params , insets .left , insets .top , insets .right , 0 );
1919
+ setBottomInset (insetsWithoutIme .bottom );
1920
+ }
1921
+
1922
+ private int bottomInset ;
1923
+
1924
+ private void setBottomInset (int extraBottomInsetWithoutIme ) {
1925
+ if (this .bottomInset != extraBottomInsetWithoutIme ) {
1926
+ this .bottomInset = extraBottomInsetWithoutIme ;
1927
+ if (footerView != null ) {
1928
+ footerView .setLayoutParams (FrameLayoutFix .newParams (ViewGroup .LayoutParams .MATCH_PARENT , Screen .dp (56f ) + extraBottomInsetWithoutIme , Gravity .BOTTOM ));
1929
+ Views .setPaddingBottom (footerView , extraBottomInsetWithoutIme );
1930
+ }
1931
+ Views .applyBottomInset (recyclerView , footerView == null ? extraBottomInsetWithoutIme : 0 );
1932
+ Views .setBottomMargin (shadowView , Screen .dp (56f ) + extraBottomInsetWithoutIme );
1933
+ }
1934
+ }
1935
+
1936
+ private RecyclerView recyclerView ;
1937
+ private FrameLayout footerView ;
1938
+ private SeparatorView shadowView ;
1939
+
1940
+ private void setBottomInsetTargets (RecyclerView recyclerView , FrameLayout footerView , SeparatorView shadowView , int inset ) {
1941
+ this .recyclerView = recyclerView ;
1942
+ this .footerView = footerView ;
1943
+ this .shadowView = shadowView ;
1944
+ this .bottomInset = inset ;
1945
+ }
1946
+ }
1947
+
1908
1948
@ SuppressWarnings ("deprecation" )
1909
1949
public final @ Nullable SettingsWrap showSettings (final SettingsWrapBuilder b ) {
1910
1950
if (isStackLocked ()) {
@@ -1938,8 +1978,8 @@ public final void showSettings (final @IdRes int id, ListItem[] rawItems, final
1938
1978
Collections .addAll (items , b .rawItems );
1939
1979
}
1940
1980
1941
- final FrameLayoutFix popupView = new FrameLayoutFix (context );
1942
- popupView .setLayoutParams (FrameLayoutFix .newParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT ));
1981
+ final SettingsWrapLayout settingsLayout = new SettingsWrapLayout (context );
1982
+ settingsLayout .setLayoutParams (FrameLayoutFix .newParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT ));
1943
1983
1944
1984
final SettingsWrap settings = new SettingsWrap ();
1945
1985
@@ -1973,6 +2013,36 @@ protected void onMeasure (int widthSpec, int heightSpec) {
1973
2013
}
1974
2014
}
1975
2015
};
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
+ });
1976
2046
settings .recyclerView = recyclerView ;
1977
2047
if (b .allowResize ) {
1978
2048
recyclerView .addItemDecoration (new RecyclerView .ItemDecoration () {
@@ -1994,7 +2064,7 @@ public void getItemOffsets (@NonNull Rect outRect, @NonNull View view, @NonNull
1994
2064
if (firstPosition == 0 ) {
1995
2065
View view = manager .findViewByPosition (0 );
1996
2066
if (view != null ) {
1997
- return Math .min (Screen .currentHeight (), Math .min (popupView .getMeasuredHeight () - view .getTop (), settings .adapter .measureHeight (-1 )) + Screen .dp (56f ) + ( Screen . needsKeyboardPadding ( context ) ? Screen . getNavigationBarFrameHeight () : 0 ) );
2067
+ return Math .min (Screen .currentHeight (), Math .min (settingsLayout .getMeasuredHeight () - view .getTop (), settings .adapter .measureHeight (-1 )) + Screen .dp (56f ) + extraBottomInsetWithoutIme );
1998
2068
}
1999
2069
}
2000
2070
return Screen .currentHeight ();
@@ -2005,6 +2075,7 @@ public void getItemOffsets (@NonNull Rect outRect, @NonNull View view, @NonNull
2005
2075
}
2006
2076
popupLayout .addStatusBar ();
2007
2077
popupLayout .setDismissListener (b .dismissListener );
2078
+ popupLayout .setNeedFullScreen (true );
2008
2079
2009
2080
final View .OnClickListener onClickListener = v -> {
2010
2081
final int viewId = v .getId ();
@@ -2085,7 +2156,8 @@ public boolean onTouchEvent (MotionEvent event) {
2085
2156
}
2086
2157
};
2087
2158
ViewSupport .setThemedBackground (footerView , ColorId .filling , this );
2088
- footerView .setLayoutParams (FrameLayoutFix .newParams (ViewGroup .LayoutParams .MATCH_PARENT , Screen .dp (56f ), Gravity .BOTTOM ));
2159
+ footerView .setLayoutParams (FrameLayoutFix .newParams (ViewGroup .LayoutParams .MATCH_PARENT , Screen .dp (56f ) + extraBottomInsetWithoutIme , Gravity .BOTTOM ));
2160
+ Views .setPaddingBottom (footerView , extraBottomInsetWithoutIme );
2089
2161
2090
2162
for (int i = 0 ; i < 2 ; i ++) {
2091
2163
TextView button = new NoScrollTextView (context );
@@ -2119,77 +2191,41 @@ public boolean onTouchEvent (MotionEvent event) {
2119
2191
}
2120
2192
2121
2193
FrameLayoutFix .LayoutParams params = FrameLayoutFix .newParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .WRAP_CONTENT , Gravity .BOTTOM );
2122
- params .bottomMargin = footerView != null ? Screen .dp (56f ) : 0 ;
2194
+ params .bottomMargin = footerView != null ? Screen .dp (56f ) + extraBottomInsetWithoutIme : 0 ;
2123
2195
2196
+ Views .applyBottomInset (recyclerView , footerView == null ? extraBottomInsetWithoutIme : 0 );
2124
2197
recyclerView .setAdapter (settings .adapter );
2125
2198
recyclerView .setLayoutParams (params );
2199
+ addThemeInvalidateListener (recyclerView );
2126
2200
2127
- popupView .addView (recyclerView );
2201
+ SeparatorView shadowView = null ;
2202
+
2203
+ settingsLayout .addView (recyclerView );
2128
2204
if (footerView != null ) {
2129
- popupView .addView (footerView );
2205
+ settingsLayout .addView (footerView );
2130
2206
}
2131
2207
2132
- SeparatorView shadowView = null ;
2133
-
2134
2208
if (footerView != null ) {
2135
2209
params = FrameLayoutFix .newParams (ViewGroup .LayoutParams .MATCH_PARENT , Screen .dp (1f ), Gravity .BOTTOM );
2136
- params .bottomMargin = Screen .dp (56f );
2210
+ params .bottomMargin = Screen .dp (56f ) + extraBottomInsetWithoutIme ;
2137
2211
shadowView = SeparatorView .simpleSeparator (context , params , true );
2138
2212
shadowView .setAlignBottom ();
2139
2213
addThemeInvalidateListener (shadowView );
2140
- popupView .addView (shadowView );
2214
+ settingsLayout .addView (shadowView );
2141
2215
}
2142
2216
2143
- int popupAdditionalHeight = 0 ;
2144
-
2145
- if (Screen .needsKeyboardPadding (context )) {
2146
- popupAdditionalHeight = Screen .getNavigationBarFrameHeight ();
2147
-
2148
- View dummyView = new View (context );
2149
- dummyView .setBackgroundColor (Theme .getColor (ColorId .filling ));
2150
- addThemeBackgroundColorListener (dummyView , ColorId .filling );
2151
-
2152
- FrameLayoutFix .LayoutParams modifiedParams = (FrameLayoutFix .LayoutParams ) recyclerView .getLayoutParams ();
2153
- modifiedParams .bottomMargin += popupAdditionalHeight ;
2154
- recyclerView .setLayoutParams (modifiedParams );
2155
-
2156
- if (footerView != null ) {
2157
- modifiedParams = (FrameLayoutFix .LayoutParams ) footerView .getLayoutParams ();
2158
- modifiedParams .bottomMargin += popupAdditionalHeight ;
2159
- footerView .setLayoutParams (modifiedParams );
2160
- }
2161
-
2162
- if (shadowView != null ) {
2163
- modifiedParams = (FrameLayoutFix .LayoutParams ) shadowView .getLayoutParams ();
2164
- modifiedParams .bottomMargin += popupAdditionalHeight ;
2165
- shadowView .setLayoutParams (modifiedParams );
2166
- }
2167
-
2168
- modifiedParams = FrameLayoutFix .newParams (ViewGroup .LayoutParams .MATCH_PARENT , popupAdditionalHeight , Gravity .BOTTOM );
2169
- dummyView .setLayoutParams (modifiedParams );
2170
-
2171
- modifiedParams = FrameLayoutFix .newParams (ViewGroup .LayoutParams .MATCH_PARENT , Screen .dp (1f ), Gravity .BOTTOM );
2172
- modifiedParams .bottomMargin = popupAdditionalHeight ;
2173
-
2174
- SeparatorView bottomShadowView = SeparatorView .simpleSeparator (context , modifiedParams , true );
2175
- bottomShadowView .setAlignBottom ();
2176
- addThemeInvalidateListener (bottomShadowView );
2177
- popupView .addView (bottomShadowView );
2178
-
2179
- popupView .addView (dummyView );
2180
- popupLayout .setNeedFullScreen (true );
2181
- }
2217
+ settingsLayout .setBottomInsetTargets (recyclerView , footerView , shadowView , extraBottomInset );
2182
2218
2183
2219
final int height = settings .adapter .measureHeight (-1 );
2184
- final int desiredHeight = height + (footerView != null ? Screen .dp (56f ) : 0 ) + popupAdditionalHeight ;
2220
+ final int desiredHeight = height + (footerView != null ? Screen .dp (56f ) : 0 ) + extraBottomInsetWithoutIme ;
2185
2221
final int popupHeight = Math .min (Screen .currentHeight (), desiredHeight );
2186
2222
2187
2223
if (desiredHeight > Screen .currentActualHeight () && checkedIndex != -1 ) {
2188
2224
int viewHeight = SettingHolder .measureHeightForType (items .get (checkedIndex ).getViewType ());
2189
2225
((LinearLayoutManager ) recyclerView .getLayoutManager ()).scrollToPositionWithOffset (checkedIndex , (Screen .currentActualHeight () - Screen .dp (56f )) / 2 - viewHeight / 2 );
2190
2226
}
2191
2227
popupLayout .addThemeListeners (this );
2192
- popupLayout .showSimplePopupView (popupView , Math .min (Screen .currentHeight () / 2 + Screen .dp (56f ), popupHeight ));
2228
+ popupLayout .showSimplePopupView (settingsLayout , Math .min (Screen .currentHeight () / 2 + Screen .dp (56f ), popupHeight ));
2193
2229
2194
2230
onCreatePopupLayout (popupLayout );
2195
2231
return settings ;
@@ -2509,11 +2545,11 @@ public final PopupLayout showOptions (Options options, final OptionDelegate dele
2509
2545
}
2510
2546
2511
2547
final PopupLayout popupLayout = new PopupLayout (context );
2512
- int popupAdditionalHeight ;
2513
2548
2514
2549
popupLayout .setTag (this );
2515
2550
popupLayout .init (true );
2516
2551
popupLayout .setDismissOtherPopUps (!options .ignoreOtherPopUps );
2552
+ popupLayout .setNeedFullScreen (true );
2517
2553
2518
2554
if (delegate != null ) {
2519
2555
popupLayout .setDisableCancelOnTouchDown (delegate .disableCancelOnTouchdown ());
@@ -2528,14 +2564,6 @@ public final PopupLayout showOptions (Options options, final OptionDelegate dele
2528
2564
optionsWrap .setInfo (this , tdlib (), options .info , false );
2529
2565
optionsWrap .setLayoutParams (FrameLayoutFix .newParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .WRAP_CONTENT , Gravity .BOTTOM ));
2530
2566
2531
- if (Screen .needsKeyboardPadding (context )) {
2532
- popupAdditionalHeight = Screen .getNavigationBarFrameHeight ();
2533
- optionsWrap .setPadding (0 , 0 , 0 , popupAdditionalHeight );
2534
- popupLayout .setNeedFullScreen (true );
2535
- } else {
2536
- popupAdditionalHeight = 0 ;
2537
- }
2538
-
2539
2567
ShadowView shadowView = new ShadowView (context );
2540
2568
shadowView .setSimpleTopShadow (true );
2541
2569
optionsWrap .addView (shadowView , 0 );
@@ -2557,7 +2585,7 @@ public final PopupLayout showOptions (Options options, final OptionDelegate dele
2557
2585
}
2558
2586
};
2559
2587
}
2560
- int totalHeight = shadowView .getLayoutParams ().height + optionsWrap .getTextHeight () + popupAdditionalHeight ;
2588
+ int totalHeight = shadowView .getLayoutParams ().height + optionsWrap .getTextHeight () + extraBottomInsetWithoutIme ;
2561
2589
int index = 0 ;
2562
2590
for (OptionItem item : options .items ) {
2563
2591
if (item == OptionItem .SEPARATOR ) {
@@ -2604,6 +2632,7 @@ public final PopupLayout showPopup (CharSequence title, boolean isTitle, @NonNul
2604
2632
final PopupLayout popupLayout = new PopupLayout (context );
2605
2633
popupLayout .setTag (this );
2606
2634
popupLayout .init (true );
2635
+ popupLayout .setNeedFullScreen (true );
2607
2636
2608
2637
int totalHeight = 0 ;
2609
2638
@@ -2619,13 +2648,7 @@ public final PopupLayout showPopup (CharSequence title, boolean isTitle, @NonNul
2619
2648
totalHeight += shadowView .getLayoutParams ().height ;
2620
2649
2621
2650
totalHeight += popUpBuilder .onBuildPopUp (popupLayout , optionsWrap );
2622
-
2623
- if (Screen .needsKeyboardPadding (context )) {
2624
- int additionalHeight = Screen .getNavigationBarFrameHeight ();
2625
- totalHeight += additionalHeight ;
2626
- optionsWrap .setPadding (0 , 0 , 0 , additionalHeight );
2627
- popupLayout .setNeedFullScreen (true );
2628
- }
2651
+ totalHeight += extraBottomInsetWithoutIme ;
2629
2652
2630
2653
popupLayout .showSimplePopupView (optionsWrap , totalHeight );
2631
2654
onCreatePopupLayout (popupLayout );
0 commit comments