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;
}
}