222222222222222222222222

布局

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <com.stx.xhb.xbanner.XBanner
            android:id="@+id/home_xbanner"
            android:layout_width="match_parent"
            android:layout_height="250dp">
        </com.stx.xhb.xbanner.XBanner>

        <TextView
            android:id="@+id/home_rxsp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_rxxp_syf"
            android:text="热销新品"
            android:textColor="#ff00"
            android:gravity="center"
            />
        <android.support.v7.widget.RecyclerView
            android:id="@+id/home_rxsp_recycler"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            ></android.support.v7.widget.RecyclerView>

        <TextView
            android:id="@+id/home_mlss"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_mlss_syf"
            android:text="魔丽时尚"
            android:textColor="#ff00"
            android:gravity="center"
            />
        <android.support.v7.widget.RecyclerView
            android:id="@+id/home_mlss_recycler"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </android.support.v7.widget.RecyclerView>


        <TextView
            android:id="@+id/home_pzsh"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_pzsh_syf"
            android:gravity="center"
            android:textColor="#ff00"
            android:text="品质时尚" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/home_pzsh_recycler"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            ></android.support.v7.widget.RecyclerView>
    </LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>


<android.support.v7.widget.CardView
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
app:cardCornerRadius=“8dp”
android:layout_marginBottom=“8dp”
>





</android.support.v7.widget.CardView>

<?xml version="1.0" encoding="utf-8"?>


<android.support.v7.widget.CardView
android:layout_width=“200dp”
android:layout_height=“210dp”

    app:cardCornerRadius="8dp"
    android:layout_marginBottom="8dp"
    >
    <ImageView
        android:id="@+id/home_pzsh_img"
        android:layout_width="140dp"
        android:layout_height="120dp"
        android:layout_marginLeft="25dp"
        />
    <TextView
        android:id="@+id/home_pzsh_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="生活馆和"
        android:layout_marginTop="140dp"
        android:singleLine="true"
        android:layout_marginLeft="@dimen/dp_10"
        android:maxLines="1"
        />
    <TextView
        android:id="@+id/home_pzsh_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="100$"
        android:layout_marginTop="170dp"
        android:textColor="#ff0000"
        android:layout_marginLeft="30dp"
        />
</android.support.v7.widget.CardView>
<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.CardView
    android:layout_width="180dp"
    android:layout_height="150dp"
    app:cardCornerRadius="8dp"
    android:layout_marginBottom="8dp"
    >
    <ImageView
        android:id="@+id/home_rxxp_img"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_marginTop="10dp"
        />
    <TextView
        android:id="@+id/home_rxxp_text"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:hint="苹果"
        android:layout_marginTop="100dp"
        android:singleLine="true"
        android:gravity="center"
        />
    <TextView
        android:id="@+id/home_rxxp_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="100R"
        android:layout_marginTop="125dp"
        android:layout_marginLeft="70dp"
        android:textColor="#ff0000"
        />
</android.support.v7.widget.CardView>

适配器

package weektest.baway.com.moni_week2.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import weektest.baway.com.moni_week2.R;
import weektest.baway.com.moni_week2.bean.CommodityBean;

/**

  • 郑可心

  • Data:2019/4/2011:33

  • 描述
    */
    public class MlssAdapter extends BaseQuickAdapter<CommodityBean.ResultBean.MlssBean.CommodityListBeanXX,BaseViewHolder> {

    public MlssAdapter(int layoutResId, @Nullable List<CommodityBean.ResultBean.MlssBean.CommodityListBeanXX> data) {
    super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CommodityBean.ResultBean.MlssBean.CommodityListBeanXX item) {

     helper.setText(R.id.home_mlss_text,item.getCommodityName());
     helper.setText(R.id.home_mlss_price,item.getPrice()+"$");
     ImageView img = helper.getView(R.id.home_mlss_img);
     Glide.with(mContext).load(item.getMasterPic().toString()).into(img);
    

    }
    }

package weektest.baway.com.moni_week2.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import weektest.baway.com.moni_week2.R;
import weektest.baway.com.moni_week2.bean.CommodityBean;

/**

  • 郑可心

  • Data:2019/4/2011:34

  • 描述
    */
    public class RxxpAdapter extends BaseQuickAdapter<CommodityBean.ResultBean.RxxpBean.CommodityListBean,BaseViewHolder> {

    public RxxpAdapter(int layoutResId, @Nullable List<CommodityBean.ResultBean.RxxpBean.CommodityListBean> data) {
    super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CommodityBean.ResultBean.RxxpBean.CommodityListBean item) {
    //设置文字
    helper.setText(R.id.home_rxxp_text,item.getCommodityName());
    helper.setText(R.id.home_rxxp_price,item.getMasterPic()+"$");
    //图片设置
    ImageView img = helper.getView(R.id.home_rxxp_img);
    Glide.with(mContext).load(item.getMasterPic().toString()).into(img);
    }
    }

package weektest.baway.com.moni_week2.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import weektest.baway.com.moni_week2.R;
import weektest.baway.com.moni_week2.bean.CommodityBean;

/**

  • 郑可心

  • Data:2019/4/2011:34

  • 描述
    */
    public class RxxpAdapter extends BaseQuickAdapter<CommodityBean.ResultBean.RxxpBean.CommodityListBean,BaseViewHolder> {

    public RxxpAdapter(int layoutResId, @Nullable List<CommodityBean.ResultBean.RxxpBean.CommodityListBean> data) {
    super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CommodityBean.ResultBean.RxxpBean.CommodityListBean item) {
    //设置文字
    helper.setText(R.id.home_rxxp_text,item.getCommodityName());
    helper.setText(R.id.home_rxxp_price,item.getMasterPic()+"$");
    //图片设置
    ImageView img = helper.getView(R.id.home_rxxp_img);
    Glide.with(mContext).load(item.getMasterPic().toString()).into(img);
    }
    }

MVP

package weektest.baway.com.moni_week2.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import weektest.baway.com.moni_week2.R;
import weektest.baway.com.moni_week2.bean.CommodityBean;

/**

  • 郑可心

  • Data:2019/4/2011:34

  • 描述
    */
    public class RxxpAdapter extends BaseQuickAdapter<CommodityBean.ResultBean.RxxpBean.CommodityListBean,BaseViewHolder> {

    public RxxpAdapter(int layoutResId, @Nullable List<CommodityBean.ResultBean.RxxpBean.CommodityListBean> data) {
    super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CommodityBean.ResultBean.RxxpBean.CommodityListBean item) {
    //设置文字
    helper.setText(R.id.home_rxxp_text,item.getCommodityName());
    helper.setText(R.id.home_rxxp_price,item.getMasterPic()+"$");
    //图片设置
    ImageView img = helper.getView(R.id.home_rxxp_img);
    Glide.with(mContext).load(item.getMasterPic().toString()).into(img);
    }
    }

package weektest.baway.com.moni_week2.util;

import android.content.Context;

import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;

/**

  • 郑可心

  • Data:2019/4/2010:31

  • 描述
    */
    public class OkHttpUtil {

    private final OkHttpClient client;
    private static OkHttpUtil okHttpUtil;

    public OkHttpUtil(){
    client = new OkHttpClient.Builder()
    .build();
    }

    public static OkHttpUtil getInstance(){
    if (okHttpUtil == null){
    synchronized (OkHttpUtil.class){
    if (okHttpUtil == null){
    okHttpUtil = new OkHttpUtil();
    }
    }
    }
    return okHttpUtil;
    }

    public void get(String urlstring, Callback callback){
    final Request request = new Request.Builder()
    .url(urlstring)
    .build();

     client.newCall(request).enqueue(callback);
    

    }

    public void post(FormBody formBody,String urlstring, Callback callback){
    final Request request = new Request.Builder()
    .method(“POST”, formBody)
    .url(urlstring)
    .build();
    client.newCall(request).enqueue(callback);
    }

}

package weektest.baway.com.moni_week2.mvp;

import android.content.Context;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
import weektest.baway.com.moni_week2.api.Api;
import weektest.baway.com.moni_week2.util.OkHttpUtil;

/**

  • 郑可心

  • Data:2019/4/2010:09

  • 描述
    */
    public class Model implements IContrat.IModel{

    @Override
    public void XbannerCallBack(final onCallBack onCallBack) {
    OkHttpUtil.getInstance().get(Api.XBANNER, new Callback() {
    @Override
    public void onFailure(Call call, IOException e) {

         }
    
         @Override
         public void onResponse(Call call, Response response) throws IOException {
             final String s = response.body().string();
             onCallBack.onCallBack(s);
         }
     });
    

    }

    @Override
    public void RecyclerCallBack(final onCallBack onCallBack) {
    OkGo.get(Api.COMMODITY).execute(new StringCallback() {
    @Override
    public void onSuccess(com.lzy.okgo.model.Response response) {
    final String s = response.body().toString();
    onCallBack.onCallBack(s);
    }
    });
    }
    }

package weektest.baway.com.moni_week2.mvp;

import java.lang.ref.SoftReference;

/**

  • 郑可心

  • Data:2019/4/2010:09

  • 描述
    */
    public class Presenter implements IContrat.IPresenter{
    IContrat.IView iView;
    private Model imodel;
    private SoftReference<IContrat.IView> reference;

    @Override
    public void attch(IContrat.IView iView) {
    this.iView = iView;
    imodel = new Model();
    reference = new SoftReference<>(iView);
    }

    @Override
    public void death(IContrat.IView iView) {
    reference.clear();
    }

    @Override
    public void XbannerRequest() {
    imodel.XbannerCallBack(new IContrat.IModel.onCallBack() {
    @Override
    public void onCallBack(String s) {
    iView.XbannerData(s);
    }
    });
    }

    @Override
    public void RecyclerRequest() {
    imodel.RecyclerCallBack(new IContrat.IModel.onCallBack() {
    @Override
    public void onCallBack(String s) {
    iView.RecyclerData(s);
    }
    });
    }
    }

APP

package weektest.baway.com.moni_week2;

import android.app.Application;
import android.content.Context;

/**

  • 郑可心

  • Data:2019/4/2010:29

  • 描述
    */
    public class App extends Application {

    public static Context context;
    @Override
    public void onCreate() {
    super.onCreate();
    this.context = context;
    }
    }

//butterknife快速查找资源的依赖
implementation ‘com.jakewharton:butterknife:8.8.1’
annotationProcessor ‘com.jakewharton:butterknife-compiler:8.8.1’
//cardview
implementation ‘com.android.support:cardview-v7:28.0.0’
// glide加载图片依赖
implementation ‘com.github.bumptech.glide:glide:4.8.0’
//okgo
implementation ‘com.lzy.net:okgo:3.0.4’
//Gson
implementation ‘org.kie.modules:com-google-code-gson:6.5.0.Final’
//导入xbanner
implementation ‘com.github.xiaohaibin:XBanner:1.6.1’
//recyclerview依赖
implementation ‘com.android.support:recyclerview-v7:28.0.0’
//Brvah:RecyclerView快速开发框架
implementation ‘com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30’
//okhttp依赖
implementation ‘com.squareup.okhttp3:okhttp:3.11.0’
implementation ‘com.squareup.okhttp3:logging-interceptor:3.11.0’

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值