Skip to content

Commit 4240d0a

Browse files
author
Harlber
committed
Code style in Fragment module
1 parent 7534a61 commit 4240d0a

6 files changed

Lines changed: 27 additions & 29 deletions

File tree

app/src/main/java/moose/com/ac/ui/ArticleFragment.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ protected void loadMore() {
6565

6666
@Override
6767
protected void doSwipeRefresh() {
68-
loadData(type, 1, false);
68+
lists.clear();
69+
adapter.notifyDataSetChanged();
70+
mPage = 1;
71+
loadData(type, mPage, false);
6972
}
7073

7174
@Override

app/src/main/java/moose/com/ac/ui/BaseListFragment.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package moose.com.ac.ui;
22

33

4+
import android.support.v7.widget.DefaultItemAnimator;
45
import android.support.v7.widget.LinearLayoutManager;
56
import android.support.v7.widget.RecyclerView;
67

7-
import jp.wasabeef.recyclerview.animators.FlipInTopXAnimator;
88
import moose.com.ac.R;
99
import moose.com.ac.ui.widget.DividerItemDecoration;
1010
import moose.com.ac.ui.widget.MultiSwipeRefreshLayout;
@@ -28,17 +28,14 @@
2828
* Created by Farble on 2015/8/13 23.
2929
*/
3030
public abstract class BaseListFragment extends BaseFragment {
31-
private static final String TAG = "BaseListFragment";
32-
private static final int ANIMATION_DURATION = 2000;
3331
protected RecyclerView mRecyclerView;
3432
protected LinearLayoutManager mLayoutManager;
3533
protected MultiSwipeRefreshLayout mSwipeRefreshLayout;
3634

3735
protected RecyclerView.Adapter adapter;
38-
protected FlipInTopXAnimator animator;
3936

4037
protected boolean isScroll = false;//is RecyclerView scrolling
41-
protected boolean isRequest = false;//request data status
38+
protected boolean isRequest = false;//request status
4239

4340
protected int mChannelId = 74;
4441
protected int type = 3;//default
@@ -64,10 +61,7 @@ public final void initRecyclerView() {
6461
throw new NullPointerException("Must call #initRecyclerViewAdapter()!");
6562
}
6663
mRecyclerView.setAdapter(adapter);
67-
animator = new FlipInTopXAnimator();
68-
animator.setAddDuration(ANIMATION_DURATION);
69-
animator.setRemoveDuration(ANIMATION_DURATION);
70-
mRecyclerView.setItemAnimator(animator);
64+
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
7165

7266
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
7367
@Override

app/src/main/java/moose/com/ac/ui/CloudCollectFragment.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ public class CloudCollectFragment extends BaseListFragment {
5353

5454
private TextView showStatus;
5555

56-
private int page = 1;//default
57-
5856
@Nullable
5957
@Override
6058
public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
61-
return inflater.inflate(
59+
return inflater.inflate(
6260
R.layout.abs_list_fragment, container, false);
6361
}
6462

@@ -87,6 +85,9 @@ protected void loadMore() {
8785

8886
@Override
8987
protected void doSwipeRefresh() {
88+
mPage = 1;
89+
list.clear();
90+
adapter.notifyDataSetChanged();
9091
load();
9192
}
9293

@@ -108,7 +109,7 @@ private void load() {
108109
mSwipeRefreshLayout.setEnabled(true);
109110
mSwipeRefreshLayout.setRefreshing(true);//show progressbar
110111
isRequest = true;
111-
subscription.add(api.getArticleCloudList(10, page, "63")
112+
subscription.add(api.getArticleCloudList(10, mPage, "63")
112113
.subscribeOn(Schedulers.io())
113114
.observeOn(AndroidSchedulers.mainThread())
114115
.compose(this.<ArticleCloud>bindUntilEvent(FragmentEvent.DESTROY_VIEW))
@@ -136,6 +137,7 @@ public void onNext(ArticleCloud articleCloud) {
136137
showStatus.setText(getString(R.string.no_local_data));
137138
}
138139
adapter.notifyDataSetChanged();
140+
mPage++;
139141
} else {
140142
snack(articleCloud.isSuccess() + "");
141143
}

app/src/main/java/moose/com/ac/ui/CommentListFragment.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public class CommentListFragment extends BaseListFragment {
5353
private Api api = RxUtils.createApi(Api.class, Config.BASE_URL);
5454
private int contentId;
5555

56-
private int page = 1;//default
5756
private SparseArrayCompatSerializable<CommentDetail> data = new SparseArrayCompatSerializable<>();
5857
private List<Integer> commentIdList = new ArrayList<>();
5958

@@ -73,7 +72,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
7372
if (savedInstanceState != null) {
7473
SaveInstance saveInstance = (SaveInstance) savedInstanceState.getSerializable(TAG);
7574
commentIdList.addAll(saveInstance != null ? saveInstance.getCommentIdList() : new ArrayList<Integer>());
76-
page = saveInstance != null ? saveInstance.getPage() : 1;
75+
mPage = saveInstance != null ? saveInstance.getPage() : 1;
7776
data = saveInstance != null ? saveInstance.getData() : new SparseArrayCompatSerializable<>();
7877
}
7978
}
@@ -96,16 +95,16 @@ public void onInitView() {
9695

9796
@Override
9897
protected void loadMore() {
99-
loadData(page);
98+
loadData(mPage);
10099
}
101100

102101
@Override
103102
protected void doSwipeRefresh() {
104-
page = 1;
103+
mPage = 1;
105104
data.clear();
106105
commentIdList.clear();
107106
adapter.notifyDataSetChanged();
108-
loadData(page);
107+
loadData(mPage);
109108
}
110109

111110
@Override
@@ -119,7 +118,7 @@ public void onInitData() {
119118
mSwipeRefreshLayout.post(new Runnable() {
120119
@Override
121120
public void run() {
122-
loadData(page);
121+
loadData(mPage);
123122
}
124123
});
125124
}
@@ -129,7 +128,7 @@ public void onSaveInstanceState(Bundle outState) {
129128
SaveInstance saveInstance = new SaveInstance();
130129
saveInstance.setCommentIdList(commentIdList);
131130
saveInstance.setData(data);
132-
saveInstance.setPage(page);
131+
saveInstance.setPage(mPage);
133132
outState.putSerializable(TAG, saveInstance);
134133
super.onSaveInstanceState(outState);
135134
}
@@ -168,7 +167,7 @@ public void onNext(JsonObject response) {
168167
mSwipeRefreshLayout.setRefreshing(false);
169168
isRequest = false;
170169
Log.i(TAG, "get comments response:" + response.toString());
171-
page++;
170+
mPage++;
172171
}
173172
}));
174173
}

app/src/main/java/moose/com/ac/ui/SearchFragment.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public class SearchFragment extends BaseListFragment {
5050
private List<SearchList> lists = new ArrayList<>();
5151
private String key;
5252
private CompositeSubscription subscription = new CompositeSubscription();
53-
private Api api;
54-
private int page = 1;
53+
private Api api = RxUtils.createApi(Api.class, Config.SEARCH_URL);
5554

5655
@Nullable
5756
@Override
@@ -84,6 +83,8 @@ protected void initRecyclerViewAdapter() {
8483

8584
@Override
8685
protected void doSwipeRefresh() {
86+
lists.clear();
87+
adapter.notifyDataSetChanged();
8788
loadData(0);
8889
}
8990

@@ -93,9 +94,8 @@ public void onInitData() {
9394
}
9495

9596
private void loadData(int flag) {
96-
api = RxUtils.createApi(Api.class, Config.SEARCH_URL);
9797
mSwipeRefreshLayout.setRefreshing(true);
98-
subscription.add(api.getSearch(key, page, Config.PAGESIZE)
98+
subscription.add(api.getSearch(key, mPage, Config.PAGESIZE)
9999
.subscribeOn(Schedulers.io())
100100
.observeOn(AndroidSchedulers.mainThread())
101101
.compose(this.<SearchBody>bindUntilEvent(FragmentEvent.DESTROY_VIEW))
@@ -124,7 +124,7 @@ public void onNext(SearchBody searchBody) {
124124
}
125125
lists.addAll(searchBody.getData().getPage().getList());
126126
adapter.notifyDataSetChanged();
127-
++page;
127+
mPage++;
128128
}
129129
}
130130
}));

app/src/main/res/layout/item_search.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
android:layout_height="match_parent"
3434
android:layout_alignBottom="@+id/meta_container"
3535
android:layout_alignTop="@id/stitle"
36-
android:background="#58bee4" />
36+
android:background="@color/colorPrimary" />
3737

3838
<ImageView
3939
android:id="@id/sbookmarked"
4040
android:layout_width="wrap_content"
4141
android:layout_height="wrap_content"
4242
android:gravity="top|left"
4343
android:src="@drawable/ic_bookmark_grey600_24dp"
44-
android:tint="@color/md_yellow_800"
44+
android:tint="@color/colorAccent"
4545
android:visibility="invisible" />
4646

4747
<TextView

0 commit comments

Comments
 (0)