Преглед на файлове

邀请赚钱中的好友提成完成,只需要美化界面

zengjiebin преди 8 години
родител
ревизия
db51c1eecb

+ 44 - 14
app/src/main/java/com/kfzs/duanduan/fragment/FgtFriendExtractPage.java

@@ -1,19 +1,19 @@
 package com.kfzs.duanduan.fragment;
 
 import android.app.Activity;
-import android.app.Fragment;
 import android.text.TextUtils;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
 import android.widget.ListView;
+import android.widget.TextView;
 
 import com.alibaba.fastjson.JSON;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.Friend;
-import com.sheep.gamegroup.model.entity.TaskReleaseEty;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.view.activity.AskGetMoneyAct;
-import com.sheep.gamegroup.view.adapter.CreditCardTaskAdp;
 import com.sheep.gamegroup.view.adapter.FriendExtractAdp;
-import com.sheep.gamegroup.view.customview.RefreshLayout;
 import com.sheep.jiuyan.samllsheep.BuildConfig;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
@@ -33,42 +33,67 @@ import rx.schedulers.Schedulers;
  * realicing@sina.com
  */
 public class FgtFriendExtractPage extends BaseFragment {
-    @BindView(R.id.list_view)
-    ListView list_view;
+    @BindView(R.id.friend_list_ll)
+    LinearLayout friend_list_ll;
     @Override
     public int getLayoutId() {
-        return R.layout.list_view;
+        return R.layout.friend_list;
     }
 
     private List<Friend> list = new ArrayList<>();
-    private FriendExtractAdp adapter;
     @Override
     public void onViewCreated() {
         ButterKnife.bind(this, mView);
-        adapter = new FriendExtractAdp(getActivity(), list);
-        list_view.setAdapter(adapter);
         initData();
     }
 
 
-    private int per_page = 5;
+    public static int per_page = 5;
     private int page = 1;
+    private void notifyDataSetChanged(){
+        int size = list.size();
+        for (int i = 0; i < friend_list_ll.getChildCount(); i++) {
+            ViewGroup view = (ViewGroup) friend_list_ll.getChildAt(i);
+            if(i < size){
+                view.setVisibility(View.VISIBLE);
+                int j = 0;
+                Friend friend = list.get(i);
+                TextView friend_item_id = (TextView) view.getChildAt(j++);
+                friend_item_id.setText(friend.getInvitation_code());
+                TextView friend_item_name = (TextView) view.getChildAt(j++);
+                friend_item_name.setText(friend.getNickname());
+                TextView friend_item_extract = (TextView) view.getChildAt(j++);
+                friend_item_extract.setText(""+friend.getAward_amount());
+                TextView friend_item_time = (TextView) view.getChildAt(j);
+                friend_item_time.setText(FgtSmallSheep.TimeStamp2Date(friend.getCreate_time(), "yyyy/MM/dd HH:mm"));
+            } else {
+                view.setVisibility(View.INVISIBLE);
+            }
+        }
+    }
+    private boolean isLoadding = false;
     private void initData(){
+        if(list.size() >= per_page || isLoadding){
+            return;
+        }
+        isLoadding = true;
+        list.clear();
         SheepApp.getInstance().getNetComponent().getApiService().getUserFriendList(page, per_page)
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new SheepSubscriber<BaseMessage>(getContext()) {
                     @Override
                     public void onNext(BaseMessage baseMessage) {
+                        List<Friend> friendList = baseMessage.getDatas(Friend.class);
                         Activity activity = getActivity();
                         if(activity instanceof AskGetMoneyAct){
-                            ((AskGetMoneyAct) activity).setFriendExtractCount(baseMessage.getTotal());
+                            ((AskGetMoneyAct) activity).setFriendExtractCount(baseMessage.getTotal(), page, friendList.size());
                         }
-                        List<Friend> friendList = baseMessage.getDatas(Friend.class);
                         list.addAll(friendList);
-                        adapter.notifyDataSetChanged();
+                        notifyDataSetChanged();
                         if(BuildConfig.DEBUG)
                             System.out.println("baseMessage onNext "+JSON.toJSONString(baseMessage));
+                        isLoadding = false;
                     }
 
                     @Override
@@ -76,6 +101,7 @@ public class FgtFriendExtractPage extends BaseFragment {
                         if(BuildConfig.DEBUG)
                             System.out.println("baseMessage onError "+JSON.toJSONString(baseMessage));
                         G.showToast(TextUtils.isEmpty(baseMessage.getMsg()) ? "服务器错误,请稍候再试" : baseMessage.getMsg());
+                        isLoadding = false;
                     }
                 });
     }
@@ -84,4 +110,8 @@ public class FgtFriendExtractPage extends BaseFragment {
         friendExtractPage.page = page;
         return friendExtractPage;
     }
+
+    public List<Friend> getList() {
+        return list;
+    }
 }

+ 49 - 0
app/src/main/java/com/kfzs/duanduan/view/VerticalScrollView.java

@@ -0,0 +1,49 @@
+package com.kfzs.duanduan.view;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.widget.ScrollView;
+
+/**
+ * Created by realicing on 2018/4/26.
+ * realicing@sina.com
+ */
+public class VerticalScrollView extends ScrollView {
+    public VerticalScrollView(Context context) {
+        super(context);
+    }
+
+    public VerticalScrollView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public VerticalScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+    }
+    float mDownPosX;
+    float mDownPosY;
+    @Override
+    public boolean onInterceptTouchEvent(MotionEvent ev) {
+        final float x = ev.getX();
+        final float y = ev.getY();
+
+        final int action = ev.getAction();
+        switch (action) {
+            case MotionEvent.ACTION_DOWN:
+                mDownPosX = x;
+                mDownPosY = y;
+
+                break;
+            case MotionEvent.ACTION_MOVE:
+                final float deltaX = Math.abs(x - mDownPosX);
+                final float deltaY = Math.abs(y - mDownPosY);
+                // 这里是够拦截的判断依据是左右滑动,读者可根据自己的逻辑进行是否拦截
+                if (deltaX > deltaY) {
+                    return false;
+                }
+        }
+
+        return super.onInterceptTouchEvent(ev);
+    }
+}

+ 59 - 0
app/src/main/java/com/kfzs/duanduan/view/ViewPagerPlus.java

@@ -0,0 +1,59 @@
+package com.kfzs.duanduan.view;
+
+import android.content.Context;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v4.view.ViewPager;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+
+/**
+ * Created by realicing on 2018/4/26.
+ * realicing@sina.com
+ */
+public class ViewPagerPlus extends ViewPager {
+
+    public ViewPagerPlus(@NonNull Context context) {
+        super(context);
+    }
+
+    public ViewPagerPlus(@NonNull Context context, @Nullable AttributeSet attrs) {
+        super(context, attrs);
+    }
+    int lastX = -1;
+    int lastY = -1;
+    @Override
+    public boolean dispatchTouchEvent(MotionEvent ev) {
+        int x = (int) ev.getRawX();
+        int y = (int) ev.getRawY();
+        int dealtX = 0;
+        int dealtY = 0;
+
+        switch (ev.getAction()) {
+            case MotionEvent.ACTION_DOWN:
+                dealtX = 0;
+                dealtY = 0;
+                // 保证子View能够接收到Action_move事件
+                getParent().requestDisallowInterceptTouchEvent(true);
+                break;
+            case MotionEvent.ACTION_MOVE:
+                dealtX += Math.abs(x - lastX);
+                dealtY += Math.abs(y - lastY);
+                // 这里是够拦截的判断依据是左右滑动,读者可根据自己的逻辑进行是否拦截
+                if (dealtX >= dealtY) {
+                    getParent().requestDisallowInterceptTouchEvent(true);
+                } else {
+                    getParent().requestDisallowInterceptTouchEvent(false);
+                }
+                lastX = x;
+                lastY = y;
+                break;
+            case MotionEvent.ACTION_CANCEL:
+                break;
+            case MotionEvent.ACTION_UP:
+                break;
+
+        }
+        return super.dispatchTouchEvent(ev);
+    }
+}

+ 36 - 2
app/src/main/java/com/sheep/gamegroup/view/activity/AskGetMoneyAct.java

@@ -222,9 +222,27 @@ public class AskGetMoneyAct extends BaseUMActivity implements UMShareListener, A
         }
     }
     private SparseArray<FgtFriendExtractPage> mTestFragments;
-    public void setFriendExtractCount(int count){
+    public void setFriendExtractCount(int count, int page, int size){
         friend_extract_count_tv.setText(getString(R.string.friend_extract_count, count));
+        checkAddPage(page, size);
     }
+    private void checkAddPage(int page, int size) {
+        if(curPage+2 > page && size == FgtFriendExtractPage.per_page){//已经到最后一页面,且数据是满的,可以添加一页面
+            int nextPage = page + 1;
+            if(mTestFragments.get(nextPage) == null) {
+//                if(BuildConfig.DEBUG) G.showToast("添加新的一页:" + nextPage);
+                mTestFragments.put(nextPage, FgtFriendExtractPage.newInstance(nextPage));
+                mPagerAdapter.notifyDataSetChanged();
+            } else {
+//                if(BuildConfig.DEBUG) G.showToast("不用添加新的一页:" + nextPage);
+            }
+        }
+        if(size > FgtFriendExtractPage.per_page){
+            if(BuildConfig.DEBUG) G.showToast("页面" + page+"的数据为:"+size);
+        }
+    }
+
+    private int curPage = 1;
     private PagerAdapter mPagerAdapter;
     private void initFriendExtractList(){
         mTestFragments = new SparseArray<>();
@@ -239,7 +257,9 @@ public class AskGetMoneyAct extends BaseUMActivity implements UMShareListener, A
 
             @Override
             public void onPageSelected(int i) {
-
+                curPage = i+1;
+                friend_extract_page_tv.setText(""+curPage);
+                checkAddPage(curPage,mTestFragments.get(curPage).getList().size());
             }
 
             @Override
@@ -247,6 +267,20 @@ public class AskGetMoneyAct extends BaseUMActivity implements UMShareListener, A
 
             }
         });
+        if(BuildConfig.DEBUG) {
+            friend_extract_count_tv.setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View view) {
+                    friend_extract_vp.setCurrentItem(curPage - 2);
+                }
+            });
+            friend_extract_page_tv.setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View view) {
+                    friend_extract_vp.setCurrentItem(curPage);
+                }
+            });
+        }
 //
 //                mTestFragments.put(key++,TestFragment.newInstance("第"+key));
 //                mPagerAdapter.notifyDataSetChanged();

+ 19 - 0
app/src/main/res/layout/friend_list.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/friend_list_ll"
+    android:layout_width="match_parent"
+    android:layout_height="130dp"
+    android:layout_centerInParent="true"
+    android:orientation="vertical">
+
+    <include layout="@layout/x_ask_getmoney_act_layout_item"
+        android:visibility="invisible"/>
+    <include layout="@layout/x_ask_getmoney_act_layout_item"
+        android:visibility="invisible"/>
+    <include layout="@layout/x_ask_getmoney_act_layout_item"
+        android:visibility="invisible"/>
+    <include layout="@layout/x_ask_getmoney_act_layout_item"
+        android:visibility="invisible"/>
+    <include layout="@layout/x_ask_getmoney_act_layout_item"
+        android:visibility="invisible"/>
+</LinearLayout>

+ 0 - 9
app/src/main/res/layout/list_view.xml

@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<com.kfzs.duanduan.view.diag.MyListview xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/list_view"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:listSelector="@color/transparent"
-    android:divider="@null"
-    android:layout_margin="@dimen/content_padding_13"
-    android:scrollbars="none"/>

+ 11 - 8
app/src/main/res/layout/x_ask_getmoney_act_layout.xml

@@ -9,11 +9,14 @@
     >
 
    <LinearLayout
-              android:layout_width="match_parent"
-              android:layout_height="match_parent"
-              android:orientation="vertical"
-              android:background="@color/bg_gray"
-    android:baselineAligned="false">
+       android:layout_width="match_parent"
+       android:layout_height="match_parent"
+       android:background="@color/bg_gray"
+       android:baselineAligned="false"
+       android:descendantFocusability="beforeDescendants"
+       android:focusable="true"
+       android:focusableInTouchMode="true"
+       android:orientation="vertical">
 
 
     <include layout="@layout/title"></include>
@@ -298,11 +301,11 @@
             android:layout_marginStart="@dimen/content_padding"
             android:layout_marginBottom="@dimen/content_padding_10"
             android:text="已邀请好友列表"/>
-        <include layout="@layout/x_ask_getmoney_act_layout_item"/>
-        <com.kfzs.duanduan.view.ViewPagerAutoHeigh
+        <include layout="@layout/x_ask_getmoney_act_layout_include"/>
+        <com.kfzs.duanduan.view.ViewPagerPlus
             android:id="@+id/friend_extract_vp"
             android:layout_width="match_parent"
-            android:layout_height="wrap_content"/>
+            android:layout_height="130dp"/>
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"

+ 44 - 0
app/src/main/res/layout/x_ask_getmoney_act_layout_include.xml

@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:gravity="center_vertical"
+    android:orientation="horizontal">
+    <TextView
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        android:gravity="center"
+        android:singleLine="true"
+        android:textSize="12sp"
+        android:textColor="#282828"
+        android:text="绵羊ID"/>
+    <TextView
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="2"
+        android:gravity="center"
+        android:singleLine="true"
+        android:textSize="12sp"
+        android:textColor="#282828"
+        android:text="好友昵称"/>
+    <TextView
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        android:gravity="center"
+        android:singleLine="true"
+        android:textSize="12sp"
+        android:textColor="#282828"
+        android:text="获得奖励金"/>
+    <TextView
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="2"
+        android:singleLine="true"
+        android:gravity="center"
+        android:textSize="12sp"
+        android:textColor="#282828"
+        android:text="注册时间"/>
+
+</LinearLayout>

+ 20 - 7
app/src/main/res/layout/x_ask_getmoney_act_layout_item.xml

@@ -1,31 +1,44 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
+    android:layout_height="26dp"
+    android:gravity="center_vertical"
     android:orientation="horizontal">
     <TextView
         android:layout_width="0dp"
-        android:layout_height="wrap_content"
+        android:layout_height="26dp"
         android:layout_weight="1"
         android:gravity="center"
+        android:singleLine="true"
+        android:textSize="@dimen/text_size_12"
+        android:textColor="#868686"
         android:text="绵羊ID"/>
     <TextView
         android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:layout_weight="1"
+        android:layout_height="26dp"
+        android:layout_weight="2"
         android:gravity="center"
+        android:singleLine="true"
+        android:textSize="@dimen/text_size_12"
+        android:textColor="#868686"
         android:text="好友昵称"/>
     <TextView
         android:layout_width="0dp"
-        android:layout_height="wrap_content"
+        android:layout_height="26dp"
         android:layout_weight="1"
         android:gravity="center"
+        android:singleLine="true"
+        android:textSize="@dimen/text_size_12"
+        android:textColor="#868686"
         android:text="获得奖励金"/>
     <TextView
         android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:layout_weight="1"
+        android:layout_height="26dp"
+        android:layout_weight="2"
+        android:singleLine="true"
         android:gravity="center"
+        android:textSize="@dimen/text_size_12"
+        android:textColor="#868686"
         android:text="注册时间"/>
 
 </LinearLayout>