购物车的简单集成

package view.bw.com.myapp2;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.hjm.bottomtabbar.BottomTabBar;

import view.bw.com.fragment.Fragment01;
import view.bw.com.fragment.Fragment02;
import view.bw.com.fragment.Fragment03;
import view.bw.com.fragment.Fragment04;
import view.bw.com.fragment.Fragment05;

public class MainActivity extends AppCompatActivity {
    private BottomTabBar mBottomTabBar;

//    private Fragment01 fragment01;
//    private Fragment02 fragment02;
//    private Fragment03 fragment03;
//    private Fragment04 fragment04;
//    private Fragment05 fragment05;
//    private FrameLayout mFragment;
//    /**
//     * 首页
//     */
//    private RadioButton mBt01;
//    /**
//     * 分类
//     */
//    private RadioButton mBt02;
//    /**
//     * 发现
//     */
//    private RadioButton mBt03;
//    /**
//     * 购物车
//     */
//    private RadioButton mBt04;
//    /**
//     * 我的
//     */
//    private RadioButton mBt05;
//    private RadioGroup mGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

        getSupportActionBar().hide();


//
//        fragment01 = new Fragment01();
//        fragment02 = new Fragment02();
//        fragment03 = new Fragment03();
//        fragment04 = new Fragment04();
//        fragment05 = new Fragment05();
//
//        getSupportFragmentManager().beginTransaction().add(R.id.fragment, fragment01).commit();
//        getSupportFragmentManager().beginTransaction().add(R.id.fragment, fragment02).commit();
//        getSupportFragmentManager().beginTransaction().add(R.id.fragment, fragment03).commit();
//        getSupportFragmentManager().beginTransaction().add(R.id.fragment, fragment04).commit();
//        getSupportFragmentManager().beginTransaction().add(R.id.fragment, fragment05).commit();
//
//        getSupportFragmentManager().beginTransaction().show(fragment01).hide(fragment02).hide(fragment03).hide(fragment04).hide(fragment05).commit();


    }

    private void initView() {
        mBottomTabBar = (BottomTabBar) findViewById(R.id.bottom_tab_bar);

        mBottomTabBar.init(getSupportFragmentManager())
                .setImgSize(50,30)
                .setFontSize(12)
                .setTabPadding(5,0,0)
                .setChangeColor(Color.RED, Color.DKGRAY)
                .addTabItem("首页",R.drawable.gs, Fragment01.class)
                .addTabItem("分类",R.drawable.gf, Fragment02.class)
                .addTabItem("发现",R.drawable.gff, Fragment03.class)
                .addTabItem("购物车",R.drawable.gc, Fragment04.class)
                .addTabItem("我的",R.drawable.gw, Fragment05.class)
                .isShowDivider(false)
                .setOnTabChangeListener(new BottomTabBar.OnTabChangeListener() {
                    @Override
                    public void onTabChange(int position, String name) {

                    }
                });





    }

//    private void initView() {
//        mFragment = (FrameLayout) findViewById(R.id.fragment);
//        mBt01 = (RadioButton) findViewById(R.id.bt_01);
//        mBt01.setOnClickListener(this);
//        mBt02 = (RadioButton) findViewById(R.id.bt_02);
//        mBt02.setOnClickListener(this);
//        mBt03 = (RadioButton) findViewById(R.id.bt_03);
//        mBt03.setOnClickListener(this);
//        mBt04 = (RadioButton) findViewById(R.id.bt_04);
//        mBt04.setOnClickListener(this);
//        mBt05 = (RadioButton) findViewById(R.id.bt_05);
//        mBt05.setOnClickListener(this);
//        mGroup = (RadioGroup) findViewById(R.id.group);
//    }
//
//    @Override
//    public void onClick(View v) {
//        switch (v.getId()) {
//            default:
//                break;
//            case R.id.bt_01:
//                getSupportFragmentManager().beginTransaction().show(fragment01).hide(fragment02).hide(fragment03).hide(fragment04).hide(fragment05).commit();
//                break;
//            case R.id.bt_02:
//                getSupportFragmentManager().beginTransaction().show(fragment02).hide(fragment01).hide(fragment03).hide(fragment04).hide(fragment05).commit();
//                break;
//            case R.id.bt_03:
//                getSupportFragmentManager().beginTransaction().show(fragment03).hide(fragment02).hide(fragment01).hide(fragment04).hide(fragment05).commit();
//                break;
//            case R.id.bt_04:
//                getSupportFragmentManager().beginTransaction().show(fragment04).hide(fragment02).hide(fragment03).hide(fragment01).hide(fragment05).commit();
//                break;
//            case R.id.bt_05:
//                getSupportFragmentManager().beginTransaction().show(fragment05).hide(fragment02).hide(fragment03).hide(fragment04).hide(fragment01).commit();
//                break;
//        }


}


P


package view.bw.com.persenter;

import java.util.List;

import view.bw.com.bean.SupperClass;
import view.bw.com.fragment.IFragment04;
import view.bw.com.model.ShoppModel;

/**
 * Created by lenovo on 2018/1/11.
 */

public class ShoppPersenter implements IShoppPersenter{
    IFragment04 iFragment04;
    ShoppModel shoppModel;
    public ShoppPersenter(IFragment04 iFragment04) {
        this.iFragment04 = iFragment04;
        shoppModel = new ShoppModel();
    }

    @Override
    public void getCar(String uid) {
        shoppModel.getCar(uid,this);
    }

    @Override
    public void onFailed(String str) {
        if (iFragment04!=null){
            System.out.print(str + "======");
            iFragment04.onFailed(str);
        }
    }

    @Override
    public void onSuccess(List<SupperClass.DataBean> list) {
        if (iFragment04!=null){
            System.out.print(list.size() + "---");
            iFragment04.onSuccess(list);
        }

    }

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

IP


package view.bw.com.persenter;

import java.util.List;

import view.bw.com.bean.SupperClass;

/**
 * Created by lenovo on 2018/1/11.
 */

public interface IShoppPersenter {
    void getCar(String uid);
    void onFailed(String str);
    void onSuccess(List<SupperClass.DataBean> list);
    void onDestory();
}

M

package view.bw.com.model;

import android.os.Handler;

import com.google.gson.Gson;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import view.bw.com.bean.SupperClass2;
import view.bw.com.persenter.IShowPersenter;

/**
 * Created by lenovo on 2018/1/12.
 */

public class ShowModel implements IShowModel {
    private Handler handler = new Handler();
    private List<String> list = new ArrayList<>();
    @Override
    public void getShow(final IShowPersenter iShowPersenter) {
        final String url = "https://www.zhaoapi.cn/ad/getAd";
        OkHttpClient client = new OkHttpClient();

        Request request = new Request.Builder()
                .get()
                .url(url)
                .build();
       Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, final IOException e) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        iShowPersenter.onFailed(e.getMessage());
                    }
                });
            }

            @Override
            public void onResponse(Call call, final Response response) throws IOException {
               String result = response.body().string();
                Gson g = new Gson();
               final SupperClass2 supperClass2 = g.fromJson(result, SupperClass2.class);
//               final List<SupperClass2> bean = new ArrayList<>();
//               bean.add(supperClass2);
                //final List<SupperClass2.DataBean> data = supperClass2.getData();

//                for (int i = 0;i<data.size();i++){
//                    String icon = data.get(i).getIcon();
//                    list.add(icon);
//                }



                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        iShowPersenter.onSuccess(supperClass2);
                    }
                });
            }
        });
    }
}

IM'

'

package view.bw.com.model;

import view.bw.com.persenter.IShowPersenter;

/**
 * Created by lenovo on 2018/1/12.
 */

public interface IShowModel {
    void getShow(IShowPersenter iShowPersenter);
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值