Retrofit

public interface Objget {
    @GET("/api/news/news.php?")
    Call<Json> SelectJson(@QueryMap HashMap<String,Integer> map);
}

Utils

package com.example.zsd.myapplication0316.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

import com.example.zsd.myapplication0316.api.API;
import com.example.zsd.myapplication0316.bean.Json;
import com.example.zsd.myapplication0316.mvp.MVP;
import com.example.zsd.myapplication0316.obj.Objget;

import java.util.HashMap;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitUtils {
    private static RetrofitUtils retrofitUtils = null;

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

    public void doGet(HashMap<String, Integer> stringIntegerHashMap, final MVP.SelectModelable selectModelable) {
        if (stringIntegerHashMap != null) {
            Retrofit builder = new Retrofit.Builder()
                    .baseUrl(API.Select)
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .build();
            Objget o = builder.create(Objget.class);
            o.SelectJson(stringIntegerHashMap).enqueue(new Callback<Json>() {
                @Override
                public void onResponse(Call<Json> call, Response<Json> response) {
                    Json body = response.body();
                    Log.e("tag","----------");
                        selectModelable.SelectSucces(body);
                }
                @Override
                public void onFailure(Call<Json> call, Throwable t) {
                    Log.e("tag","sdsdsdsdsd");
                        selectModelable.SelectErrors(t.getMessage());
                }
            });
        }

    }

    public static boolean IsNetWorkConnected(Context context) {
        if (context != null) {
            Log.e("tag","-------------------------------");
            ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo info = connectivityManager.getActiveNetworkInfo();
            if (info != null) {
            Log.e("tag","-------------------------------");
                return true;
            }
        }
        return false;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值