Android - 准备工作【仿】淘宝App

首先是所有要用到的依赖

依赖包

compile 'com.facebook.fresco:fresco:0.12.0'
    compile 'org.greenrobot:eventbus:3.1.1'
    compile 'com.jakewharton:butterknife:8.8.1'
    compile 'io.reactivex.rxjava2:rxjava:2.1.1'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.squareup.retrofit2:retrofit:2.0.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.2'
    compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

清单文件


    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

ApiService.java网络接口

public interface ApiService {
    //http://120.27.23.105/user/login?mobile=15011420106&password=123456
    @GET("user/login")
    Flowable<LoginBean> loginget(@QueryMap Map<String, String> map);

    @GET("user/reg")
    Flowable<RegisBean> regisget(@QueryMap Map<String, String> map);

    //https://www.zhaoapi.cn/product/getProducts?pscid=39&page=1
    @GET("product/getProducts")
    Flowable<DetailsBean> detailsget(@QueryMap Map<String, String> map);

    //https://www.zhaoapi.cn/product/getProductDetail?source=android&pid=1
    @GET("product/getProductDetail")
    Flowable<DetaiBean> detaiget(@QueryMap Map<String, String> map);

    //product/addCart
    @GET("product/addCart")
    Flowable<AddBean> addget(@QueryMap Map<String, String> map);

    //http://120.27.23.105/product/getCarts?source=android&uid=1653
    @GET("product/getCarts")
    Flowable<SeBean> seget(@QueryMap Map<String, String> map);

    //http://120.27.23.105/product/deleteCart?source=android&uid=1653&pid=2
    @GET("product/deleteCart")
    Flowable<DeBean> deget(@QueryMap Map<String, String> map);
}

RetrofitUtils.java

public class RetrofitUtils {
    private static volatile RetrofitUtils instance;
    private final Retrofit retrofit;

    private RetrofitUtils(String baseurl) {
        retrofit = new Retrofit.Builder()
                .baseUrl(baseurl)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public static RetrofitUtils getInstance(String baseurl) {
        if (instance == null) {
            synchronized (RetrofitUtils.class) {
                if (instance == null) {
                    instance = new RetrofitUtils(baseurl);
                }
            }
        }
        return instance;
    }

    public Retrofit getretrofit() {
        return retrofit;
    }

你可能感兴趣的:(Android,Studio,javascript,jquery,html5+css3,angularjs)