Retrofit相关

 RetrofitUtils

package zjj.bwie.com.jx.utils;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitUtils {
    private static RetrofitUtils retrofitUtils;
    private OkHttpClient okHttpClient;

    private RetrofitUtils(){
        okHttpClient = new OkHttpClient.Builder().build();
    }

    public static RetrofitUtils getInstence(){
        if(retrofitUtils==null){
            synchronized (RetrofitUtils.class){
                if(retrofitUtils==null){
                    retrofitUtils=new RetrofitUtils();
                }
            }
        }
        return retrofitUtils;
    }

    public BaseApiInterface getApi(){

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BaseApi.BASE_URL)
                .client(okHttpClient)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        BaseApiInterface baseApiInterface = retrofit.create(BaseApiInterface.class);

        return baseApiInterface;
    }
}

 Retrofit interface

package zjj.bwie.com.jx.utils;


import java.util.Map;

import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
import zjj.bwie.com.jx.homepage.bean.HomePageBean;
import zjj.bwie.com.jx.me.bean.MeLoginBean;
import zjj.bwie.com.jx.shopcart.bean.ShopCartBean;
import zjj.bwie.com.jx.sort.bean.ChildSortBean;
import zjj.bwie.com.jx.sort.bean.SortBean;

public interface BaseApiInterface {
    //获取首页bean类
    @GET("ad/getAd")
    Observable<HomePageBean> getHomePageBean();

    //商品分类接口
    @GET("product/getCatagory")
    Observable<SortBean> getSortBean();
    //商品子分类接口
    @GET("product/getProductCatagory")
    Observable<ChildSortBean> getChildShrtBean(@Query("cid") int cid);

    //查询购物车
    @GET("product/getCarts?uid=17403")
    Observable<ShopCartBean> getShopCartBean();
    //添加购物车
    @GET("product/addCart?uid=17403")
    Observable<ShopCartBean> addCart(@Query("pid") int pid);
    //更新购物车
    @GET("product/updateCarts?uid=17403")
    Observable<ShopCartBean> updateCart(@QueryMap Map<String,Integer> map);
    //删除购物车
    @GET("product/deleteCart?uid=17403")
    Observable<ShopCartBean> deleteCart(@Query("pid") int pid);

    //维度登录
    @FormUrlEncoded
    @POST("login")
    Observable<MeLoginBean> login(@Field("phone")String phone,@Field("pwd")String pwd);
    //维度注册
    @FormUrlEncoded
    @POST("registerUser")
    Observable<MeLoginBean> reg(@FieldMap Map<String,String> map);


}

v层

package zjj.bwie.com.jx.homepage.mvp.view;


import zjj.bwie.com.jx.homepage.bean.HomePageBean;
import zjj.bwie.com.jx.sort.bean.SortBean;

public interface HomePageContract {
    public interface HomePageView{
        void getData(HomePageBean homePageBean);
        void getSortData(SortBean sortBean);
    }
    public interface HomePageModel{
        interface OnRequestListenter{
            void onSuccess(HomePageBean homePageBean);

            void onSortSuccess(SortBean sortBean);
        }

        void requestData(OnRequestListenter listenter);
    }

    public interface HomePagePresenter{
        void homePageData();
    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值