Bläddra i källkod

集成我的收藏

316044749 7 år sedan
förälder
incheckning
563e2e5863

+ 67 - 3
app/src/main/java/com/ynstkz/shitu/android/activity/MineCollectActivity.java

@@ -1,20 +1,30 @@
 package com.ynstkz.shitu.android.activity;
 
+import android.content.Intent;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
 import android.view.View;
+import android.widget.AdapterView;
 import android.widget.ImageView;
+import android.widget.ListView;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
 
 import com.common.library.okhttp.callback.Callback;
+import com.common.library.pulltorefresh.PullToRefreshBase;
 import com.common.library.pulltorefresh.PullToRefreshListView;
 import com.google.gson.Gson;
 import com.ynstkz.shitu.android.R;
+import com.ynstkz.shitu.android.adapter.MineCollectItemAdapter;
+import com.ynstkz.shitu.android.adapter.MineCommentItemAdapter;
 import com.ynstkz.shitu.android.base.TitleBarActivity;
 import com.ynstkz.shitu.android.bean.MyCollectBean;
+import com.ynstkz.shitu.android.bean.OrgItemBean;
 import com.ynstkz.shitu.android.data.RequestGroup;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import butterknife.Bind;
 import okhttp3.Call;
 import okhttp3.Response;
@@ -24,7 +34,7 @@ import okhttp3.Response;
  * 作者:fuchangle on 2018/2/11 15:36
  */
 
-public class MineCollectActivity extends TitleBarActivity {
+public class MineCollectActivity extends TitleBarActivity implements PullToRefreshBase.OnRefreshListener2<ListView>{
 
     @Bind(R.id.tv_all)
     TextView tvAll;
@@ -39,6 +49,10 @@ public class MineCollectActivity extends TitleBarActivity {
     @Bind(R.id.tv_title)
     TextView tvTitle;
 
+    private int pageNumber;
+    private List<OrgItemBean> listCollentOrg;
+    private MineCollectItemAdapter mineCollectItemAdapter;
+
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -55,15 +69,39 @@ public class MineCollectActivity extends TitleBarActivity {
 
     private void initView() {
         tvTitle.setText("我的收藏");
+        pullToRefresh.setOnRefreshListener(this);
     }
 
     private void initData() {
+        pageNumber = 1;
+        getMyCollectList();
+    }
 
+    @Override
+    public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
+        pageNumber = 1;
+        getMyCollectList();
+    }
+
+    @Override
+    public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
+        pageNumber ++;
         getMyCollectList();
     }
 
     private void setListener() {
 
+        pullToRefresh.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
+                OrgItemBean orgItemBean = (OrgItemBean)adapterView.getAdapter().getItem(i);
+                if(orgItemBean != null){
+                    Intent intent = new Intent(MineCollectActivity.this, OrgDetailActivity.class);
+                    intent.putExtra("memberId", orgItemBean.getMemberId());
+                    startActivity(intent);
+                }
+            }
+        });
     }
 
     /**
@@ -71,7 +109,7 @@ public class MineCollectActivity extends TitleBarActivity {
      */
     private void getMyCollectList() {
 
-        RequestGroup.getMyCollectList(new Callback() {
+        RequestGroup.getMyCollectList(pageNumber+"", new Callback() {
             @Override
             public Object parseNetworkResponse(Response response, int id) throws Exception {
                 return new Gson().fromJson(response.body().string(), MyCollectBean.class);
@@ -85,7 +123,33 @@ public class MineCollectActivity extends TitleBarActivity {
 
             @Override
             public void onResponse(Object response, int id) {
-
+                MyCollectBean myCollectBean = (MyCollectBean)response;
+                if(myCollectBean != null){
+                    if("200".equals(myCollectBean.getCode())){
+                        if(myCollectBean.getData() != null){
+                            if(myCollectBean.getData().getRecords() != null && myCollectBean.getData().getRecords().size() > 0){
+                                if(pageNumber == 1){
+                                    if(listCollentOrg == null){
+                                        listCollentOrg = new ArrayList<>();
+                                    }
+                                    listCollentOrg.clear();
+                                    listCollentOrg.addAll(myCollectBean.getData().getRecords());
+                                    mineCollectItemAdapter = new MineCollectItemAdapter(MineCollectActivity.this, listCollentOrg);
+                                    pullToRefresh.setAdapter(mineCollectItemAdapter);
+                                    mineCollectItemAdapter.notifyDataSetChanged();
+                                } else {
+                                    listCollentOrg.addAll(myCollectBean.getData().getRecords());
+                                    mineCollectItemAdapter.notifyDataSetChanged();
+                                }
+                            } else {
+                                showNoData();
+                            }
+                        }
+                    } else {
+                        showToast(myCollectBean.getMsg());
+                    }
+                }
+                pullToRefresh.onRefreshComplete();
             }
         });
     }

+ 70 - 0
app/src/main/java/com/ynstkz/shitu/android/adapter/MineCollectItemAdapter.java

@@ -0,0 +1,70 @@
+package com.ynstkz.shitu.android.adapter;
+
+import android.content.Context;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.bumptech.glide.Glide;
+import com.common.library.adapter.CCAdapterHolder;
+import com.common.library.adapter.CCListAdapter;
+import com.ynstkz.shitu.android.R;
+import com.ynstkz.shitu.android.bean.OrgItemBean;
+
+import java.util.List;
+
+import me.zhanghai.android.materialratingbar.MaterialRatingBar;
+
+/**
+ * 作者:fuchangle on 2018/3/17 16:08
+ */
+
+public class MineCollectItemAdapter extends CCListAdapter<OrgItemBean>{
+
+    private Context context;
+    private List<OrgItemBean> adapterContent;
+    /**
+     * Construct list adapter.
+     *
+     * @param context        Context.
+     * @param adapterContent Content to display.
+     */
+    public MineCollectItemAdapter(Context context, List<OrgItemBean> adapterContent) {
+        super(context, adapterContent);
+        this.context = context;
+        this.adapterContent = adapterContent;
+    }
+
+    @Override
+    public CCAdapterHolder<OrgItemBean> createHolder(int type) {
+
+        return new CCAdapterHolder<OrgItemBean>() {
+
+            ImageView ivHeadPic;
+            TextView tvMemberName;
+            TextView tvRegaddress;
+            MaterialRatingBar materialRatingBar;
+
+            @Override
+            public int getResource() {
+                return R.layout.item_mine_collect;
+            }
+
+            @Override
+            public void initializeView(View convertView) {
+                ivHeadPic = convertView.findViewById(R.id.iv_headPic);
+                tvMemberName = convertView.findViewById(R.id.tv_memberName);
+                tvRegaddress = convertView.findViewById(R.id.tv_regaddress);
+                materialRatingBar = convertView.findViewById(R.id.rb_score);
+            }
+
+            @Override
+            public void updateView(OrgItemBean content, int position) {
+                Glide.with(context).load(content.getHeadPic()).into(ivHeadPic);
+                tvMemberName.setText(content.getMemberName());
+                tvRegaddress.setText(content.getAddress());
+                materialRatingBar.setProgress(content.getScore());
+            }
+        };
+    }
+}

+ 2 - 1
app/src/main/java/com/ynstkz/shitu/android/data/RequestGroup.java

@@ -218,8 +218,9 @@ public class RequestGroup {
     /**
      * 我的收藏
      */
-    public static void getMyCollectList(Callback callback){
+    public static void getMyCollectList(String pageNumber, Callback callback){
         Map<String, String> params = getSystemParams();
+        params.put("pageNumber",pageNumber);
         OkHttpUtils.get().url(UrlCat.URL_MY_COLLECT).addHeader(KEY_TOKEN,
                 SharedPreferencesUtils.getToken()).params(params).build().execute(callback);
     }

+ 100 - 0
app/src/main/res/layout/item_mine_collect.xml

@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:background="@color/white">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:padding="10dp">
+
+        <ImageView
+            android:id="@+id/iv_headPic"
+            android:layout_width="@dimen/company_80dp"
+            android:layout_height="@dimen/company_80dp"
+            android:background="@mipmap/ic_launcher"/>
+
+        <RelativeLayout
+            android:layout_width="match_parent"
+            android:layout_height="@dimen/company_80dp"
+            android:layout_marginLeft="@dimen/company_10dp"
+            android:orientation="vertical">
+
+            <TextView
+                android:id="@+id/tv_memberName"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textSize="@dimen/company_16sp"
+                android:textColor="@color/color_333"
+                android:textStyle="bold"
+                android:text="新东方培训学校-西湖文化广场分校"/>
+
+            <RelativeLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_below="@+id/tv_memberName">
+
+                <me.zhanghai.android.materialratingbar.MaterialRatingBar
+                    android:id="@+id/rb_score"
+                    android:layout_width="@dimen/company_90dp"
+                    android:layout_height="@dimen/company_20dp"
+                    android:layout_marginTop="@dimen/company_5dp"
+                    android:isIndicator="true"
+                    app:mrb_progressTint="@color/rb_color"
+                    app:mrb_secondaryProgressTint="@color/color_999"
+                    android:stepSize="0.5"
+                    style="@style/Widget.MaterialRatingBar.RatingBar" />
+
+                <TextView
+                    android:id="@+id/tv_comment_count"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_toRightOf="@+id/rb_score"/>
+
+                <TextView
+                    android:id="@+id/tv_view_count"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_alignParentRight="true"/>
+
+            </RelativeLayout>
+
+            <RelativeLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_alignParentBottom="true">
+
+                <TextView
+                    android:id="@+id/tv_regaddress"
+                    android:layout_width="@dimen/company_200dp"
+                    android:layout_height="wrap_content"
+                    android:layout_alignParentRight="true"
+                    android:maxLines="1"
+                    android:ellipsize="end"
+                    android:gravity="right"
+                    android:text="未名湖"/>
+
+            </RelativeLayout>
+
+        </RelativeLayout>
+
+    </LinearLayout>
+
+    <LinearLayout
+        android:id="@+id/ll_course_main"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical">
+
+    </LinearLayout>
+
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/company_5dp"
+        android:background="@color/default_bg"/>
+
+</LinearLayout>