Skip to content

Commit

Permalink
Fix fragment refresh bug
Browse files Browse the repository at this point in the history
  • Loading branch information
djj0809 committed Aug 25, 2013
1 parent 5cc95fd commit fe2aa21
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (helper==null) {
helper = new LoadingModelHelper(view,this);
}
listView = (PullToRefreshListView) view.findViewById(R.id.loading_content);
helper = new LoadingModelHelper(view,this);
listView = (PullToRefreshListView) view.findViewById(R.id.loading_content);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Expand Down Expand Up @@ -111,7 +109,11 @@ public void onRequestComplete(List<E> result) {
setItems(result);
refreshListViewData();
listView.onRefreshComplete();
helper.content();
if (result.size()>0){
helper.content();
} else {
helper.empty();
}
}

protected void setItems(List<E> result) {
Expand All @@ -128,8 +130,8 @@ protected void refreshListViewData() {

@Override
public void onRequestError(String msg) {
listView.onRefreshComplete();
helper.empty();
listView.onRefreshComplete();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class SearchBoardFragment extends PullToRefeshListFragment<BoardStatus> {
private int position = 0;
private static final String TAG = "SearchBoardFragment";
private List<BoardStatus> totalBoards;
private List<BoardStatus> totalBoards = new ArrayList<BoardStatus>();

@InjectView(R.id.search_board_text)
private EditText searchContentEditText;
Expand Down
19 changes: 8 additions & 11 deletions app/src/main/java/tk/djcrazy/MyCC98/helper/LoadingModelHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import android.view.View;
import android.view.animation.AnimationUtils;

import com.handmark.pulltorefresh.library.PullToRefreshBase;

import tk.djcrazy.MyCC98.R;
import tk.djcrazy.MyCC98.util.ViewUtils;

Expand All @@ -13,7 +11,7 @@
*/
public class LoadingModelHelper {

private View contentView;
private View contentView;
private View loadingView;
private View emptyView;

Expand Down Expand Up @@ -44,7 +42,7 @@ public void onClick(View v) {
}

public void loading() {
hide(contentView).hide(emptyView).show(loadingView, false);
hide(contentView).hide(emptyView).show(loadingView, false);
}

public void content() {
Expand All @@ -54,6 +52,7 @@ public void content() {
hide(loadingView).hide(emptyView);
}
}

public void content(boolean animate) {
if (!contentView.isShown()) {
hide(loadingView).hide(emptyView).show(contentView, animate);
Expand All @@ -62,26 +61,24 @@ public void content(boolean animate) {
}
}

public void empty(){
if (!emptyView.isShown()) {
hide(contentView).hide(loadingView).show(emptyView);
} else {
hide(loadingView).hide(loadingView);
}
public void empty() {
hide(contentView).hide(loadingView).show(emptyView);
}

private LoadingModelHelper hide(View view) {
ViewUtils.setGone(view, true);
return this;
}

private LoadingModelHelper show(View view) {
ViewUtils.setGone(view, false);
fadeIn(view);
return this;
}

private LoadingModelHelper show(View view, boolean animate) {
ViewUtils.setGone(view, false);
if (animate){
if (animate) {
fadeIn(view);
}
return this;
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/tk/djcrazy/libCC98/NewCC98Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,12 @@ public void onResponse(String response) {
List<BoardStatus> list = mCC98Parser.parseTodayBoardList(response);
listener.onRequestComplete(list);
} catch (Exception e) {
e.printStackTrace();
listener.onRequestError("版面列表加载失败");
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
Log.e(this.getClass().getSimpleName(), error.getMessage());
listener.onRequestError("版面列表加载失败");
}
});
Expand Down

0 comments on commit fe2aa21

Please sign in to comment.