@@ -44,17 +44,19 @@ public class DemoFragment extends BaseLayoutFragment {
4444 private static final String CLICK_LOAD_MORE = "isClickLoadMore" ;
4545 private static final String AUTO_HIDDEN_MORE = "auto_hidden_more" ;
4646
47- public static DemoFragment newInstance (int layoutType , boolean isClickLoadMore , boolean autoHidden ) {
47+ public static DemoFragment newInstance (int layoutType , boolean isClickLoadMore , int visibilityWhenNoMore ) {
4848 Bundle args = new Bundle ();
4949 args .putInt (LAYOUT_TYPE , layoutType );
5050 args .putBoolean (CLICK_LOAD_MORE , isClickLoadMore );
51- args .putBoolean (AUTO_HIDDEN_MORE , autoHidden );
51+ args .putInt (AUTO_HIDDEN_MORE , visibilityWhenNoMore );
5252 DemoFragment fragment = new DemoFragment ();
5353 fragment .setArguments (args );
5454 return fragment ;
5555 }
5656
5757 private RecyclerView .LayoutManager createLayoutManager () {
58+ Bundle arguments = getArguments ();
59+ assert arguments != null ;
5860 int type = getArguments ().getInt (LAYOUT_TYPE );
5961 if (type == 1 ) {
6062 return new LinearLayoutManager (getContext ());
@@ -66,7 +68,7 @@ private RecyclerView.LayoutManager createLayoutManager() {
6668 }
6769
6870 public void onButtonClick (View v ) {
69- PopupMenu pop = new PopupMenu (getContext (), v );
71+ PopupMenu pop = new PopupMenu (requireContext (), v );
7072 Menu menu = pop .getMenu ();
7173 menu .add (Menu .NONE , 1 , 0 , "next time fail" );
7274 menu .add (Menu .NONE , 2 , 1 , "next time no more" );
@@ -105,7 +107,7 @@ protected int provideLayoutRes() {
105107 }
106108
107109 @ Override
108- public void onViewCreated (View view , @ Nullable Bundle savedInstanceState ) {
110+ public void onViewCreated (@ NonNull View view , @ Nullable Bundle savedInstanceState ) {
109111 super .onViewCreated (view , savedInstanceState );
110112 view .findViewById (R .id .frag_show_option ).setOnClickListener (new View .OnClickListener () {
111113 @ Override
@@ -127,7 +129,12 @@ public void onActivityCreated(Bundle savedInstanceState) {
127129 mRecyclerView .setLayoutManager (createLayoutManager ());
128130 mRecyclerView .addItemDecoration (new RecyclerView .ItemDecoration () {
129131 @ Override
130- public void getItemOffsets (Rect outRect , View view , RecyclerView parent , RecyclerView .State state ) {
132+ public void getItemOffsets (
133+ @ NonNull Rect outRect , @ NonNull
134+ View view ,
135+ @ NonNull RecyclerView parent ,
136+ @ NonNull RecyclerView .State state
137+ ) {
131138 outRect .bottom = DensityUtils .dip2px (getContext (), 10 );
132139 super .getItemOffsets (outRect , view , parent , state );
133140 }
@@ -136,12 +143,14 @@ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, Recycle
136143 mWrapperAdapter = WrapperAdapter .wrap (mRecyclerAdapter );
137144 mRecyclerView .setAdapter (mWrapperAdapter );
138145
139- if (getArguments ().getBoolean (CLICK_LOAD_MORE )) {
146+ Bundle arguments = getArguments ();
147+ assert arguments != null ;
148+
149+ if (arguments .getBoolean (CLICK_LOAD_MORE )) {
140150 mWrapperAdapter .setLoadMode (LoadMode .CLICK_LOAD );
141151 }
142- if (getArguments ().getBoolean (AUTO_HIDDEN_MORE )) {
143- mWrapperAdapter .setAutoHiddenWhenNoMore (true );
144- }
152+
153+ mWrapperAdapter .setVisibilityWhenNoMore (getArguments ().getInt (AUTO_HIDDEN_MORE , View .VISIBLE ));
145154
146155 setOnLoadMoreListener ();
147156
@@ -189,6 +198,7 @@ public void run() {
189198 mWrapperAdapter .loadFail ();
190199 return ;
191200 }
201+
192202 if (!mHasMore ) {
193203 mWrapperAdapter .loadCompleted (false );
194204 return ;
@@ -218,7 +228,7 @@ public void run() {
218228 "新来的Item" + count ++));
219229 mWrapperAdapter .loadCompleted (true );
220230 }
221- }, 1000 );
231+ }, 100 );
222232 }
223233 });
224234
0 commit comments