82 lines
3.1 KiB
Java
82 lines
3.1 KiB
Java
package com.gh.common.util;
|
|
|
|
import android.content.Context;
|
|
|
|
import com.gh.gamecenter.eventbus.EBReuse;
|
|
import com.gh.gamecenter.retrofit.Response;
|
|
import com.gh.gamecenter.retrofit.RetrofitManager;
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.json.JSONArray;
|
|
|
|
import okhttp3.MediaType;
|
|
import okhttp3.RequestBody;
|
|
import okhttp3.ResponseBody;
|
|
import retrofit2.HttpException;
|
|
import rx.Observable;
|
|
import rx.functions.Func1;
|
|
import rx.schedulers.Schedulers;
|
|
|
|
/**
|
|
* Created by khy on 2016/8/24.
|
|
* croncern 工具类
|
|
*/
|
|
public class ConcernUtils {
|
|
|
|
public static void postConcernGameId(final Context context, final String gameId) {
|
|
TokenUtils.getToken(context, true)
|
|
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
|
@Override
|
|
public Observable<ResponseBody> call(String token) {
|
|
JSONArray params = new JSONArray();
|
|
params.put(gameId);
|
|
RequestBody body = RequestBody.create(MediaType.parse("application/json"), params.toString());
|
|
return RetrofitManager.getUser().postConcern(token, body);
|
|
}
|
|
}).subscribeOn(Schedulers.io())
|
|
.observeOn(Schedulers.io())
|
|
.subscribe(new Response<ResponseBody>());
|
|
}
|
|
|
|
public static void deleteConcernData(final Context context, final String gameId) {
|
|
TokenUtils.getToken(context, true)
|
|
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
|
@Override
|
|
public Observable<ResponseBody> call(String token) {
|
|
return RetrofitManager.getUser().deleteConcern(token, gameId);
|
|
}
|
|
}).subscribeOn(Schedulers.io())
|
|
.observeOn(Schedulers.io())
|
|
.subscribe(new Response<ResponseBody>());
|
|
}
|
|
|
|
public static void updateConcernData(final Context context, final JSONArray data) {
|
|
TokenUtils.getToken(context, true)
|
|
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
|
@Override
|
|
public Observable<ResponseBody> call(String token) {
|
|
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
|
data.toString());
|
|
return RetrofitManager.getUser().putConcern(token, body);
|
|
}
|
|
})
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(Schedulers.io())
|
|
.subscribe(new Response<ResponseBody>() {
|
|
@Override
|
|
public void onResponse(ResponseBody response) {
|
|
super.onResponse(response);
|
|
EventBus.getDefault().post(new EBReuse("UpdateConcernSuccess"));
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(HttpException e) {
|
|
super.onFailure(e);
|
|
EventBus.getDefault().post(new EBReuse("UpdateConcernFailure"));
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
|