30
30
import androidx .recyclerview .widget .RecyclerView ;
31
31
32
32
import org .drinkless .tdlib .TdApi ;
33
- import org .thunderdog .challegram .BaseActivity ;
34
33
import org .thunderdog .challegram .R ;
35
34
import org .thunderdog .challegram .component .sticker .StickerSmallView ;
36
35
import org .thunderdog .challegram .component .sticker .TGStickerObj ;
66
65
import org .thunderdog .challegram .util .CancellableResultHandler ;
67
66
import org .thunderdog .challegram .v .NewFlowLayoutManager ;
68
67
import org .thunderdog .challegram .widget .BaseView ;
68
+ import org .thunderdog .challegram .widget .RootFrameLayout ;
69
69
import org .thunderdog .challegram .widget .ShadowView ;
70
70
71
71
import java .util .ArrayList ;
79
79
import me .vkryl .core .StringUtils ;
80
80
import tgx .td .ChatId ;
81
81
82
- public class InlineResultsWrap extends FrameLayoutFix implements View .OnClickListener , StickerSmallView .StickerMovementCallback , InlineResultsAdapter .HeightProvider , FactorAnimator .Target , View .OnLongClickListener , TGLegacyManager .EmojiLoadListener , BaseView .CustomControllerProvider {
82
+ public class InlineResultsWrap extends FrameLayoutFix implements View .OnClickListener , StickerSmallView .StickerMovementCallback , InlineResultsAdapter .HeightProvider , FactorAnimator .Target , View .OnLongClickListener , TGLegacyManager .EmojiLoadListener , BaseView .CustomControllerProvider , RootFrameLayout . InsetsChangeListener , RootFrameLayout . MarginModifier {
83
83
private RecyclerView recyclerView ;
84
84
private ShadowView shadowView ;
85
85
private GridLayoutManager gridManager ;
@@ -94,7 +94,6 @@ public class InlineResultsWrap extends FrameLayoutFix implements View.OnClickLis
94
94
95
95
public interface OffsetProvider {
96
96
int provideOffset (InlineResultsWrap v );
97
- int provideParentHeight (InlineResultsWrap v );
98
97
}
99
98
100
99
private OffsetProvider offsetProvider ;
@@ -122,6 +121,10 @@ public void setOffsetProvider (OffsetProvider offsetProvider) {
122
121
public InlineResultsWrap (Context context ) {
123
122
super (context );
124
123
124
+ setClipChildren (true );
125
+ setClipToPadding (true );
126
+ setLayoutParams (new LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT ));
127
+
125
128
gridManager = new GridLayoutManager (context , spanCount = calculateSpanCount (Screen .currentWidth (), Screen .currentHeight ()));
126
129
gridManager .setSpanSizeLookup (new GridLayoutManager .SpanSizeLookup () {
127
130
@ Override
@@ -229,6 +232,15 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
229
232
230
233
@ Override
231
234
public void onScrolled (RecyclerView recyclerView , int dx , int dy ) {
235
+ /*View topView = recyclerView.getLayoutManager().findViewByPosition(0);
236
+ if (topView != null) {
237
+ Log.v("scroll: %d inset: %d %d " +
238
+ "margin: %d, shadow: %d %d " +
239
+ "items: %d root: %d top: %d expected: %d",
240
+ recyclerView.getLayoutManager().getDecoratedTop(topView), topOffset, bottomInset,
241
+ lastBottomMargin, shadowView.getLayoutParams().height, ShadowView.simpleBottomShadowHeight(),
242
+ measureItemsHeight(), rootView != null ? rootView.getMeasuredHeight() : 0, topView.getMeasuredHeight(), provideHeight());
243
+ }*/
232
244
if (scrollCallback != null ) {
233
245
scrollCallback .onScrolled (recyclerView , dx , dy );
234
246
}
@@ -817,10 +829,8 @@ protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
817
829
private void setBottomMargin (int bottomMargin ) {
818
830
if (this .lastBottomMargin != bottomMargin ) {
819
831
this .lastBottomMargin = bottomMargin ;
820
- /*FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) recyclerView.getLayoutParams();
821
- params.topMargin = bottomMargin;
822
- recyclerView.setLayoutParams(params);*/
823
- setTranslationY (-bottomMargin );
832
+ Views .setBottomMargin (this , bottomInset + bottomMargin );
833
+ updateOffset ();
824
834
}
825
835
if (lickView != null ) {
826
836
lickView .invalidate ();
@@ -852,10 +862,59 @@ public void updatePosition (boolean needTranslate) {
852
862
853
863
@ Override
854
864
public int provideHeight () {
855
- int height = offsetProvider != null ? offsetProvider .provideParentHeight (this ) : ((BaseActivity ) getContext ()).getVisibleContentHeight (); // - measureItemsHeight();
856
- height -= getMinItemsHeight ();
857
- int minHeight = Math .max (Screen .getStatusBarHeight (), ((BaseActivity ) getContext ()).getRootView ().getTopInset ()) + lastBottomMargin ;
858
- return Math .max (minHeight , height );
865
+ // height of the offset
866
+ final int totalHeight = rootView != null ? rootView .getMeasuredHeight () - bottomInset - lastBottomMargin : 0 ;
867
+ int itemsHeight = measureItemsHeight ();
868
+ return Math .max (topOffset , totalHeight - Math .min (totalHeight / 2 , itemsHeight ));
869
+ }
870
+
871
+ private int topOffset , bottomInset ;
872
+
873
+ private void setInsets (int topOffset , int bottomInset ) {
874
+ if (this .topOffset != topOffset || this .bottomInset != bottomInset ) {
875
+ this .topOffset = topOffset ;
876
+ this .bottomInset = bottomInset ;
877
+ Views .setBottomMargin (this , bottomInset + lastBottomMargin );
878
+ updateOffset ();
879
+ }
880
+ }
881
+
882
+ @ Override
883
+ public void onApplyMarginInsets (View child , LayoutParams params , Rect legacyInsets , Rect insets , Rect insetsWithoutIme ) {
884
+ Views .setMargins (params ,
885
+ legacyInsets .left ,
886
+ legacyInsets .top ,
887
+ legacyInsets .right ,
888
+ insets .bottom + lastBottomMargin
889
+ );
890
+ setInsets (insets .top , insets .bottom );
891
+ }
892
+
893
+ @ Override
894
+ public void onInsetsChanged (RootFrameLayout viewGroup , Rect effectiveInsets , Rect effectiveInsetsWithoutIme , Rect systemInsets , Rect systemInsetsWithoutIme , boolean isUpdate ) {
895
+ setInsets (systemInsets .top , systemInsets .bottom );
896
+ }
897
+
898
+ private RootFrameLayout rootView ;
899
+
900
+ @ Override
901
+ protected void onAttachedToWindow () {
902
+ super .onAttachedToWindow ();
903
+ rootView = Views .findAncestor (this , RootFrameLayout .class , true );
904
+ if (rootView != null ) {
905
+ rootView .addInsetsChangeListener (this );
906
+ Rect systemInsets = rootView .getSystemInsets ();
907
+ setInsets (systemInsets .top , systemInsets .bottom );
908
+ }
909
+ }
910
+
911
+ @ Override
912
+ protected void onDetachedFromWindow () {
913
+ super .onDetachedFromWindow ();
914
+ if (rootView != null ) {
915
+ rootView .removeInsetsChangeListener (this );
916
+ rootView = null ;
917
+ }
859
918
}
860
919
861
920
public int getMinItemsHeight () {
0 commit comments