From a029466c2f9ee07889923105939081bb8c8d77ad Mon Sep 17 00:00:00 2001
From: xuxiuxi <xuxiuxi@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期一, 17 四月 2017 14:01:28 +0800
Subject: [PATCH] 

---
 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/AttendanceFragment.java              |   13 ++++++
 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/adapter/AttendanceFragment.java               |   29 ++++++++++++++
 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/AttendanceMng.java                    |   20 +++++++++-
 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/widget/attendance/AttendanceLeftListView.java |   20 +++++++++-
 4 files changed, 76 insertions(+), 6 deletions(-)

diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/adapter/AttendanceFragment.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/adapter/AttendanceFragment.java
index 406349e..3903fe7 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/adapter/AttendanceFragment.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/adapter/AttendanceFragment.java
@@ -10,6 +10,7 @@
 import com.camnter.easyrecyclerview.holder.EasyRecyclerViewHolder;
 import com.facebook.drawee.view.SimpleDraweeView;
 
+import cn.com.basic.face.discern.common.CommonVariables;
 import cn.com.basic.face.discern.query.item.AttendanceDetailQueryItem;
 import cn.com.basic.face.discern.query.item.AttendanceQueryItem;
 import cn.com.basic.face.util.AppApi;
@@ -50,11 +51,28 @@
 
         @Override
         public int[] getItemLayouts() {
-            return new int[]{R.layout.fragment_attendance_left_date_row, R.layout.fragment_attendance_left_person_row};
+            return new int[]{R.layout.fragment_attendance_left_date_row, R.layout.fragment_attendance_left_person_row,R.layout.load_more, R.layout.no_more, R.layout.reach_bottom};
         }
 
         @Override
         public void onBindRecycleViewHolder(EasyRecyclerViewHolder viewHolder, final int position) {
+            if (getItem(position) instanceof Integer && ((int)getItem(position))== CommonVariables.Page.reachBottom) {
+                return;
+            }
+            if (getItem(position) instanceof Integer && ((int)getItem(position))== CommonVariables.Page.noMorePage) {
+                return;
+            }
+            if (getItem(position) instanceof Integer && ((int)getItem(position))== CommonVariables.Page.hasMorePages) {
+                TextView load_more_text_view = viewHolder.findViewById(R.id.load_more_text_view);
+                load_more_text_view.setOnClickListener(new View.OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        cn.com.basic.face.fragment.AttendanceFragment.getInstance().addPageNum();
+                        cn.com.basic.face.fragment.AttendanceFragment.getInstance().append();
+                    }
+                });
+                return;
+            }
             if(!(getItem(position) instanceof String)) {
                 final RadioButton fragment_visit_left_person_row_check_box = viewHolder.findViewById(R.id.fragment_attendance_left_person_row_check_box);
                 TextView fragment_visit_left_person_row_name = viewHolder.findViewById(R.id.fragment_attendance_left_person_row_name);
@@ -106,6 +124,15 @@
 
         @Override
         public int getRecycleViewItemType(int position) {
+            if (getItem(position) instanceof Integer && ((int)getItem(position))== CommonVariables.Page.reachBottom) {
+                return 4;
+            }
+            if (getItem(position) instanceof Integer && ((int)getItem(position))== CommonVariables.Page.noMorePage) {
+                return 3;
+            }
+            if (getItem(position) instanceof Integer && ((int)getItem(position))== CommonVariables.Page.hasMorePages) {
+                return 2;
+            }
             if(!(getItem(position) instanceof String)) {
                 return 1;
             }
diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/AttendanceFragment.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/AttendanceFragment.java
index bac5886..22556c9 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/AttendanceFragment.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/AttendanceFragment.java
@@ -49,6 +49,8 @@
     @ViewInject(R.id.fragment_attendance_right_photo_placeholder_text_view)
     private TextView fragment_attendance_right_photo_placeholder_text_view;
 
+    private int pageNum = 1;
+
     public int[] getLeftRightLayoutIds() {
         return new int[]{R.layout.fragment_attendance_left, R.layout.fragment_attendance_right};
     }
@@ -74,8 +76,17 @@
     private void reloadRightList() {
     }
 
+    public void append() {
+        AttendanceMng.getInstance().reloadLeftList(fragment_attendance_left_search.getText().toString(), pageNum, true);
+    }
+
+    public void addPageNum() {
+        pageNum++;
+    }
+
     private void reloadLeftList() {
-        AttendanceMng.getInstance().reloadLeftList(fragment_attendance_left_search.getText().toString());
+        pageNum = 1;
+        AttendanceMng.getInstance().reloadLeftList(fragment_attendance_left_search.getText().toString(), pageNum, false);
     }
 
     @OnClick(R.id.fragment_attendance_left_back)
diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/AttendanceMng.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/AttendanceMng.java
index 70944ea..b4a6e44 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/AttendanceMng.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/AttendanceMng.java
@@ -8,6 +8,7 @@
 import java.util.List;
 
 import cn.com.basic.face.discern.common.BaseCommonCallBack;
+import cn.com.basic.face.discern.common.CommonVariables;
 import cn.com.basic.face.discern.query.condition.AttendanceDetailQueryCondition;
 import cn.com.basic.face.discern.query.condition.AttendanceQueryCondition;
 import cn.com.basic.face.discern.query.item.AttendanceDetailQueryItem;
@@ -22,9 +23,11 @@
         return instance;
     }
 
-    public void reloadLeftList(String searchText) {
+    public void reloadLeftList(String searchText, final int pageNum, final boolean append) {
         RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.ATTENDANCE_QUERY);
         params.addBodyParameter(AttendanceQueryCondition.FieldNames.username, searchText);
+        params.addBodyParameter(CommonVariables.Page.PAGE_NUM, pageNum+"");
+        params.addBodyParameter(CommonVariables.Page.PAGE_SIZE, "7");
         x.http().post(params, new BaseCommonCallBack() {
             public void success() {
                 List<AttendanceQueryItem> list = getList(AttendanceQueryItem.class);
@@ -44,7 +47,20 @@
                     itemList.add(item);
                     i++;
                 }
-                AttendanceFragment.getInstance().get_fragment_attendance_left_list_view().show(itemList);
+                if (hasMorePages()) {
+                    itemList.add(CommonVariables.Page.hasMorePages);
+                } else {
+                    if (getPageNum() > 1) {
+                        itemList.add(CommonVariables.Page.reachBottom);
+                    } else {
+                        if (itemList.size() > 0) {
+                            itemList.add(CommonVariables.Page.reachBottom);
+                        } else {
+                            itemList.add(CommonVariables.Page.noMorePage);
+                        }
+                    }
+                }
+                AttendanceFragment.getInstance().get_fragment_attendance_left_list_view().show(itemList, append);
             }
         });
 
diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/widget/attendance/AttendanceLeftListView.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/widget/attendance/AttendanceLeftListView.java
index 4c57b35..42cfadf 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/widget/attendance/AttendanceLeftListView.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/widget/attendance/AttendanceLeftListView.java
@@ -5,10 +5,12 @@
 
 import com.camnter.easyrecyclerview.widget.EasyRecyclerView;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import cn.com.basic.face.adapter.AttendanceFragment;
 import cn.com.basic.face.adapter.VisitFragment;
+import cn.com.basic.face.discern.common.CommonVariables;
 
 public class AttendanceLeftListView extends EasyRecyclerView {
 
@@ -34,8 +36,22 @@
         initView();
     }
 
-    public void show(List list) {
-        adapter.setList(list);
+    public void show(List list, boolean append) {
+        if (append) {
+            List newList = new ArrayList();
+            if (adapter.getList().size() > 0 &&  adapter.getList().get(adapter.getList().size()-1) instanceof Integer && ((int)adapter.getList().get(adapter.getList().size()-1))== CommonVariables.Page.hasMorePages) {
+                adapter.getList().remove(adapter.getList().size() - 1);
+            }
+            if (adapter.getList().size() > 0 &&  adapter.getList().get(adapter.getList().size()-1) instanceof
+                    Integer && ((int)adapter.getList().get(adapter.getList().size()-1))== CommonVariables.Page.noMorePage) {
+                adapter.getList().remove(adapter.getList().size() - 1);
+            }
+            newList.addAll(adapter.getList());
+            newList.addAll(list);
+            adapter.setList(newList);
+        } else {
+            adapter.setList(list);
+        }
         setAdapter(adapter);
     }
 

--
Gitblit v1.8.0