2222import info .papdt .express .helper .ui .adapter .HomePackageListAdapter ;
2323import info .papdt .express .helper .ui .callback .OnDataRemovedCallback ;
2424import info .papdt .express .helper .ui .common .AbsFragment ;
25+ import info .papdt .express .helper .view .AnimatedRecyclerView ;
2526import info .papdt .express .helper .widget .SwipeRefreshLayout ;
2627
2728public abstract class BaseFragment extends AbsFragment implements SwipeRefreshLayout .OnRefreshListener {
2829
2930 private SwipeRefreshLayout mRefreshLayout ;
30- private RecyclerView mRecyclerView ;
31+ private AnimatedRecyclerView mRecyclerView ;
3132 private LinearLayout mEmptyView ;
3233
3334 private RecyclerView .Adapter mAdapter ;
@@ -36,6 +37,7 @@ public abstract class BaseFragment extends AbsFragment implements SwipeRefreshLa
3637 private PackageDatabase mDatabase ;
3738 private static Context sInstance = null ;
3839 private final static int FLAG_REFRESH_LIST = 0 , FLAG_UPDATE_ADAPTER_ONLY = 1 ;
40+ private boolean hasPlayedAnimation = false ;
3941
4042 int eggCount = 0 , bigEggCount = 0 ;
4143
@@ -124,6 +126,13 @@ protected PackageDatabase getDatabase() {
124126 return mDatabase ;
125127 }
126128
129+ protected void playListAnimation () {
130+ if (!hasPlayedAnimation ) {
131+ hasPlayedAnimation = true ;
132+ mRecyclerView .scheduleLayoutAnimation ();
133+ }
134+ }
135+
127136 protected void setAdapter (RecyclerView .Adapter adapter ) {
128137 this .mAdapter = adapter ;
129138 mRecyclerView .setAdapter (mSwipeManager .createWrappedAdapter (mAdapter ));
@@ -176,6 +185,7 @@ public void handleMessage(Message msg) {
176185 case FLAG_UPDATE_ADAPTER_ONLY :
177186 if (mAdapter != null ) {
178187 mAdapter .notifyDataSetChanged ();
188+ playListAnimation ();
179189 mEmptyView .setVisibility (mAdapter != null && mAdapter .getItemCount () > 0 ? View .GONE : View .VISIBLE );
180190 }
181191 break ;
@@ -193,6 +203,7 @@ protected Void doInBackground(Void... voids) {
193203
194204 @ Override
195205 protected void onPostExecute (Void msg ) {
206+ hasPlayedAnimation = false ;
196207 mRefreshLayout .setRefreshing (false );
197208 mHandler .sendEmptyMessage (FLAG_UPDATE_ADAPTER_ONLY );
198209 }
0 commit comments