仿京东购物车分类

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.squareup.okhttp3:okhttp:3.9.0'
implementation files('libs/gson-2.8.0.jar')
implementation files('libs/universal-image-loader-1.9.5.jar')

implementation 'com.android.support:recyclerview-v7:26.1.0'

activity_main.xml

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.lenovo.myapplication_classify.view.activity.MainActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/left_recycle"
        android:layout_width="match_parent"
        android:layout_weight="8"
        android:layout_height="match_parent"/>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/right_recycle"
        android:layout_width="match_parent"
        android:layout_weight="2"
        android:background="#eeeeee"
        android:layout_height="match_parent"/>

</LinearLayout>
group_item.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp">
    <TextView
        android:id="@+id/item_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"/>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/item_list"
        android:background="#fff"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>
item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:padding="10dp">

    <ImageView
        android:id="@+id/myimg"
        android:layout_width="match_parent"
        android:layout_height="60dp" />

    <TextView
        android:id="@+id/mytitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center" />
</LinearLayout>

text_item.xml

<?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:orientation="vertical">

    <TextView
        android:id="@+id/left_title"
        android:padding="15dp"
        android:textSize="16sp"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

modle

ITotalModle


package com.example.lenovo.myapplication_classify.modle;

import com.example.lenovo.myapplication_classify.presenter.ITotalPresenter;

import java.util.Map;

/**
 * Created by lenovo on 2018/3/2.
 */

public interface ITotalModle {
    void left(String path, Map<String,String> map , ITotalPresenter iTotalPresenter);

    void right(String path, Map<String,String> map , ITotalPresenter iTotalPresenter);
}
TotalModle


package com.example.lenovo.myapplication_classify.modle;

import com.example.lenovo.myapplication_classify.presenter.ITotalPresenter;
import com.example.lenovo.myapplication_classify.view.bean.LeftSuperClass;
import com.example.lenovo.myapplication_classify.view.bean.RightSuperClass;
import com.example.lenovo.myapplication_classify.view.utils.OkHttpUtils;
import com.example.lenovo.myapplication_classify.view.utils.OnFinishListener;
import com.google.gson.Gson;

import java.util.List;
import java.util.Map;

/**
 * Created by lenovo on 2018/3/2.
 */

public class TotalModle implements ITotalModle {

    private OkHttpUtils okHttpUtils;

    @Override
    public void left(String path, Map<String, String> map, final ITotalPresenter iTotalPresenter) {
        okHttpUtils = OkHttpUtils.getIndata();
        okHttpUtils.doGet(path, map, new OnFinishListener() {
            @Override
            public void onFailed(String str) {
                iTotalPresenter.onFailed(str);
            }

            @Override
            public void onSuccess(Object obj) {
                Gson gson = new Gson();
                LeftSuperClass leftSuperClass = gson.fromJson(obj.toString(), LeftSuperClass.class);
                iTotalPresenter.onLeftSuccess(leftSuperClass.getData());
            }
        });
    }

    @Override
    public void right(String path, Map<String, String> map, final ITotalPresenter iTotalPresenter) {
        okHttpUtils = OkHttpUtils.getIndata();
        okHttpUtils.doGet(path, map, new OnFinishListener() {
            @Override
            public void onFailed(String str) {
                iTotalPresenter.onFailed(str);
            }

            @Override
            public void onSuccess(Object obj) {
                Gson gson = new Gson();
                RightSuperClass rightSuperClass = gson.fromJson(obj.toString(), RightSuperClass.class);
                iTotalPresenter.onRightSuccess(rightSuperClass.getData());
            }
        });
    }
}

presenter

ITotalPresenter

package com.example.lenovo.myapplication_classify.presenter;

import com.example.lenovo.myapplication_classify.view.bean.LeftSuperClass;
import com.example.lenovo.myapplication_classify.view.bean.RightSuperClass;

import java.util.List;
import java.util.Map;

/**
 * Created by lenovo on 2018/3/2.
 */

public interface ITotalPresenter {
    void left(String path, Map<String,String> map);

    void right(String path, Map<String,String> map);

    void onFailed(String str);

    void onLeftSuccess(List<LeftSuperClass.DataBean> list);

    void onRightSuccess(List<RightSuperClass.DataBean> list);

    void onDestory();
}
TotalPresenter

package com.example.lenovo.myapplication_classify.presenter;

import com.example.lenovo.myapplication_classify.modle.ITotalModle;
import com.example.lenovo.myapplication_classify.modle.TotalModle;
import com.example.lenovo.myapplication_classify.view.activity.IMainActivity;
import com.example.lenovo.myapplication_classify.view.bean.LeftSuperClass;
import com.example.lenovo.myapplication_classify.view.bean.RightSuperClass;

import java.util.List;
import java.util.Map;

/**
 * Created by lenovo on 2018/3/2.
 */

public class TotalPresenter implements ITotalPresenter {
    private IMainActivity iMainActivity;
    private ITotalModle iTotalModle;

    public TotalPresenter(IMainActivity iMainActivity) {
        this.iMainActivity = iMainActivity;
        iTotalModle = new TotalModle();
    }

    @Override
    public void left(String path, Map<String, String> map) {
        iTotalModle.left(path,map,this);
    }

    @Override
    public void right(String path, Map<String, String> map) {
        iTotalModle.right(path,map,this);
    }

    @Override
    public void onFailed(String str) {
        if (iMainActivity != null){
            iMainActivity.onFailed(str);
        }
    }

    @Override
    public void onLeftSuccess(List<LeftSuperClass.DataBean> list) {
        if (iMainActivity != null){
            iMainActivity.onLeftSuccess(list);
        }
    }

    @Override
    public void onRightSuccess(List<RightSuperClass.DataBean> list) {
        if (iMainActivity != null){
            iMainActivity.onRightSuccess(list);
        }
    }

    @Override
    public void onDestory() {
        if (iMainActivity != null){
            iMainActivity = null;
        }
    }
}
view

Constans


package com.example.lenovo.myapplication_classify;

/**
 * Created by lenovo on 2018/3/2.
 */

public class Constans {
    public static final String HOST_NAME = "https://www.zhaoapi.cn";

    public static final String LEFT_URL = HOST_NAME + "/product/getCatagory";

    public static final String RIGHT_URL = HOST_NAME + "/product/getProductCatagory";
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值