fix:调整榜单的请求接口改为retrofit2模块

fix:调整榜单实体类为IMLoginModel而非UserBean
add:网络请求接口允许配置是否默认添加uid参数*榜单接口需求
This commit is contained in:
zlzw 2022-08-22 13:53:38 +08:00
parent 5ef2015715
commit e65f0fe0ce
13 changed files with 272 additions and 37 deletions

View File

@ -0,0 +1,63 @@
package com.yunbao.common.bean;
import com.google.gson.annotations.SerializedName;
/**
* 直播间榜单实体类
*/
public class ContributeModel extends BaseModel{
@SerializedName("uid")
private long uid;
@SerializedName("total")
private String total;
@SerializedName("userinfo")
private IMLoginModel userinfo;
@SerializedName("dress_head")
private String dressHead;
public long getUid() {
return uid;
}
public ContributeModel setUid(long uid) {
this.uid = uid;
return this;
}
public String getTotal() {
return total;
}
public ContributeModel setTotal(String total) {
this.total = total;
return this;
}
public IMLoginModel getUserinfo() {
return userinfo;
}
public ContributeModel setUserinfo(IMLoginModel userinfo) {
this.userinfo = userinfo;
return this;
}
public String getDressHead() {
return dressHead;
}
public ContributeModel setDressHead(String dressHead) {
this.dressHead = dressHead;
return this;
}
@Override
public String toString() {
return "ContributeModel{" +
"uid=" + uid +
", total='" + total + '\'' +
", userinfo=" + userinfo +
", dressHead='" + dressHead + '\'' +
'}';
}
}

View File

@ -673,4 +673,62 @@ public class IMLoginModel extends BaseModel {
this.slide = slide;
return this;
}
@Override
public String toString() {
return "IMLoginModel{" +
"avatar='" + avatar + '\'' +
", avatarThumb='" + avatarThumb + '\'' +
", birthday='" + birthday + '\'' +
", city='" + city + '\'' +
", coin=" + coin +
", consumption=" + consumption +
", frontTask=" + frontTask +
", gold=" + gold +
", goldsumption=" + goldsumption +
", goodnum='" + goodnum + '\'' +
", id=" + id +
", issuper=" + issuper +
", langue='" + langue + '\'' +
", level='" + level + '\'' +
", levelAnchor='" + levelAnchor + '\'' +
", liang=" + liang +
", location='" + location + '\'' +
", medalLevel='" + medalLevel + '\'' +
", medalName='" + medalName + '\'' +
", nobleId=" + nobleId +
", nobleEndTime='" + nobleEndTime + '\'' +
", province='" + province + '\'' +
", sex=" + sex +
", signature='" + signature + '\'' +
", token='" + token + '\'' +
", tokenRong='" + tokenRong + '\'' +
", userNicename='" + userNicename + '\'' +
", userStatus=" + userStatus +
", vip=" + vip +
", votestotal=" + votestotal +
", firstLogin=" + firstLogin +
", isagent=" + isagent +
", num='" + num + '\'' +
", isAdmin='" + isAdmin + '\'' +
", agentSwitch='" + agentSwitch + '\'' +
", avatar2='" + avatar2 + '\'' +
", dress=" + dress +
", familySwitch=" + familySwitch +
", fans=" + fans +
", follows=" + follows +
", isBind=" + isBind +
", lives=" + lives +
", medalNoDisplaySrc='" + medalNoDisplaySrc + '\'' +
", mobile='" + mobile + '\'' +
", nobleName='" + nobleName + '\'' +
", usersType='" + usersType + '\'' +
", votes='" + votes + '\'' +
", yuanbao=" + yuanbao +
", list=" + list +
", slide=" + slide +
", giftEffect=" + giftEffect +
", mountEffect=" + mountEffect +
'}';
}
}

View File

@ -1,16 +1,18 @@
package com.yunbao.live.bean;
package com.yunbao.common.bean;
import com.yunbao.common.bean.UserBean;
import android.os.Parcelable;
/**
* Created by zlzw on 2022/8/20.
* 直播间榜单实体类
*/
public class LiveUserRankBean extends UserBean {
public class LiveUserRankBean extends UserBean implements Parcelable {
private long total;
private UserBean userinfo;
public long getTotal() {
return total;
}
@ -19,6 +21,14 @@ public class LiveUserRankBean extends UserBean {
this.total = total;
}
public UserBean getUserinfo() {
return userinfo;
}
public void setUserinfo(UserBean userinfo) {
this.userinfo = userinfo;
}
@Override
public String toString() {
return "LiveUserRankBean{" +

View File

@ -0,0 +1,39 @@
package com.yunbao.common.bean;
import com.google.gson.annotations.SerializedName;
import java.util.List;
/**
* 直播间榜单数据类
*/
public class UserRankModel extends BaseModel{
@SerializedName("list_day")
private List<ContributeModel> listDay;
@SerializedName("list_week")
private List<ContributeModel> listWeek;
public List<ContributeModel> getListDay() {
return listDay;
}
public void setListDay(List<ContributeModel> listDay) {
this.listDay = listDay;
}
public List<ContributeModel> getListWeek() {
return listWeek;
}
public void setListWeek(List<ContributeModel> listWeek) {
this.listWeek = listWeek;
}
@Override
public String toString() {
return "UserRankModel{" +
"listDay=" + listDay +
", listWeek=" + listWeek +
'}';
}
}

View File

@ -44,6 +44,18 @@ public class API extends BaseApi {
public PDLiveApi pdLiveApi(Context context) {
if (null == pdLiveApi) {
//实例化gson
pdLiveApi=createPDLiveApi(true);
}
return pdLiveApi;
}
/**
* 创建新的PDLiveApi兼容部分接口需要控制是否添加UID参数
* 仅有需要不添加uid的接口使用默认请用pdLiveApi()
* @param isNeedUid 是否需要用户uid参数
* @return PDLiveApi
*/
public PDLiveApi createPDLiveApi(boolean isNeedUid){
Gson gson = new GsonBuilder()
.registerTypeAdapter(Date.class, new DateTypeAdapter())
.create();
@ -51,23 +63,21 @@ public class API extends BaseApi {
loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder builder = new OkHttpClient()
.newBuilder()
.addInterceptor(initQuery(CommonAppContext.sInstance.getApplicationContext()))
.addInterceptor(initQuery(isNeedUid,CommonAppContext.sInstance.getApplicationContext()))
.addInterceptor(loggingInterceptor);
pdLiveApi = create(builder.build(),
return create(builder.build(),
GsonConverterFactory.create(gson), RxJava2CallAdapterFactory.create(), CommonAppConfig.HOST, PDLiveApi.class);
}
return pdLiveApi;
}
//公共参数
public Interceptor initQuery(final Context context) {
public Interceptor initQuery(boolean isNeedUid,final Context context) {
Interceptor addQueryParameterInterceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
//配置公共参数
request = new ParamsContext(request, context).getInRequest();
request = new ParamsContext(request, context).getInRequest(isNeedUid);
return chain.proceed(request);
}
};

View File

@ -3,6 +3,7 @@ package com.yunbao.common.http;
import com.yunbao.common.bean.ActiveModel;
import com.yunbao.common.bean.AnchorRecommendModel;
import com.yunbao.common.bean.BaseModel;
import com.yunbao.common.bean.ContributeModel;
import com.yunbao.common.bean.FaceBookUpModel;
import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.bean.LiveInfoModel;
@ -153,4 +154,12 @@ public interface PDLiveApi {
*/
@GET("/api/public/?service=live.getDrLm")
Observable<ResponseModel<List<ActiveModel>>> getDrLm();
/**
* 获取日榜周榜数据
* @param uid 直播间id并非用户uid
* @return 榜单结构
*/
@GET("/api/public/?service=Contribute.index")
Observable<ResponseModel<List<ContributeModel>>> getRanksList(@Query("uid")String uid);
}

View File

@ -1,6 +1,7 @@
package com.yunbao.common.http;
import com.google.gson.annotations.SerializedName;
import com.yunbao.common.bean.UserRankModel;
public class ResponseData<T> {
@SerializedName("code")
@ -9,6 +10,8 @@ public class ResponseData<T> {
private String msg;
@SerializedName("info")
private T info;
@SerializedName("data")
private UserRankModel data;
public int getCode() {
return code;
@ -36,4 +39,12 @@ public class ResponseData<T> {
this.info = info;
return this;
}
public UserRankModel getData() {
return data;
}
public void setData(UserRankModel data) {
this.data = data;
}
}

View File

@ -9,16 +9,28 @@ import okhttp3.HttpUrl;
import okhttp3.Request;
public class GetRequestParams implements IRequestParam {
/**
* 构建Request
* @param isNeedUid 是否需要添加用户uid参数
* @param request
* @param context
* @return
*/
@Override
public Request getRequest(Request request, Context context) {
public Request getRequest(boolean isNeedUid,Request request, Context context) {
//添加公共参数
if (IMLoginManager.isLogin(context)) {
IMLoginModel model = IMLoginManager.get(context).getUserInfo();
HttpUrl modifiedUrl = request.url().newBuilder()
/* HttpUrl modifiedUrl = request.url().newBuilder()
.addQueryParameter("uid", String.valueOf(model.getId()))
.addQueryParameter("token", model.getToken())
.build();
return request.newBuilder().url(modifiedUrl).build();
.build();*/
HttpUrl.Builder builder = request.url().newBuilder();
if(isNeedUid) {
builder.addQueryParameter("uid", String.valueOf(model.getId()));
}
builder.addQueryParameter("token", model.getToken());
return request.newBuilder().url(builder.build()).build();
}

View File

@ -5,5 +5,5 @@ import android.content.Context;
import okhttp3.Request;
public interface IRequestParam {
Request getRequest(Request request, Context context);
Request getRequest(boolean isNeedUid,Request request, Context context);
}

View File

@ -14,7 +14,7 @@ public class ParamsContext {
this.request = request;
}
public Request getInRequest() {
public Request getInRequest(boolean isNeedUid) {
switch (request.method()) {
case "GET":
iRequestParam = new GetRequestParams();
@ -23,6 +23,6 @@ public class ParamsContext {
iRequestParam = new PostRequestParams();
break;
}
return iRequestParam.getRequest(request, context);
return iRequestParam.getRequest(isNeedUid,request, context);
}
}

View File

@ -10,7 +10,7 @@ import okhttp3.Request;
public class PostRequestParams implements IRequestParam {
@Override
public Request getRequest(Request request, Context context) {
public Request getRequest(boolean isNeedUid,Request request, Context context) {
if (request.body() instanceof FormBody) {
FormBody.Builder bodyBuilder = new FormBody.Builder();
@ -21,9 +21,14 @@ public class PostRequestParams implements IRequestParam {
}
if (IMLoginManager.isLogin(context)) {
IMLoginModel model = IMLoginManager.get(context).getUserInfo();
formBody = bodyBuilder.addEncoded("uid", String.valueOf(model.getId()))
/* formBody = bodyBuilder.addEncoded("uid", String.valueOf(model.getId()))
.addEncoded("token", model.getToken())
.build();
.build();*/
if (isNeedUid){
bodyBuilder.addEncoded("uid", String.valueOf(model.getId()));
}
bodyBuilder.addEncoded("token", model.getToken());
formBody=bodyBuilder.build();
}
request = request.newBuilder().post(formBody).build();

View File

@ -28,12 +28,10 @@ import com.yunbao.common.bean.UserBean;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.utils.CommonIconUtil;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.RandomUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.live.R;
import com.yunbao.live.activity.LiveActivity;
import com.yunbao.live.bean.LiveUserGiftBean;
import com.yunbao.live.bean.LiveUserRankBean;
import com.yunbao.common.bean.LiveUserRankBean;
import com.yunbao.live.dialog.LiveUserMoreDialogFragment;
import java.net.MalformedURLException;

View File

@ -3,8 +3,6 @@ package com.yunbao.live.dialog;
import android.app.ActionBar;
import android.graphics.Color;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
@ -14,14 +12,20 @@ import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yunbao.common.Constants;
import com.yunbao.common.adapter.RefreshAdapter;
import com.yunbao.common.bean.LiveUserRankBean;
import com.yunbao.common.bean.UserBean;
import com.yunbao.common.bean.UserRankModel;
import com.yunbao.common.custom.CommonRefreshView;
import com.yunbao.common.dialog.AbsDialogFragment;
import com.yunbao.common.http.API;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.live.R;
@ -29,12 +33,14 @@ import com.yunbao.live.activity.LiveActivity;
import com.yunbao.live.adapter.UserMoreInfoAdapter;
import com.yunbao.live.bean.LiveGuardInfo;
import com.yunbao.live.bean.LiveUserGiftBean;
import com.yunbao.live.bean.LiveUserRankBean;
import com.yunbao.live.http.LiveHttpUtil;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
/**
* 观看直播的人 列表
*/
@ -203,9 +209,20 @@ public class LiveUserMoreDialogFragment extends AbsDialogFragment implements Vie
public void loadData(int p, HttpCallback callback) {
Log.i("tag111", p + "ssss");
if(isRank()){
LiveHttpUtil.getUserRankList(mLiveUid,callback);
//榜单没有分页需求
mRefreshView.setPageCount(1);
/**
* 榜单接口的uid为直播间ID并不是也不需要用户uid
*/
API.get().createPDLiveApi(false).getRanksList(mLiveUid)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(listResponseModel -> {
UserRankModel data = listResponseModel.getData().getData();
//获取到参数后手动调用成功方法
callback.onSuccess(0,"",new String[]{JSONObject.toJSONString(data)});
}, throwable -> {
throwable.printStackTrace();
callback.onError();
}).isDisposed();
}else {
LiveHttpUtil.getUserList(mLiveUid, stream, type, p, callback);
pg = p;
@ -269,8 +286,11 @@ public class LiveUserMoreDialogFragment extends AbsDialogFragment implements Vie
return data;
}
private List<LiveUserRankBean> processRankData(JSONObject json){
JSONArray rank=Integer.parseInt(Tips)==4?json.getJSONArray("list_day"):json.getJSONArray("list_week");
JSONArray rank=Integer.parseInt(Tips)==4?json.getJSONArray("listDay"):json.getJSONArray("listWeek");
List<LiveUserRankBean> data =new ArrayList<>();
/**
* 由于在线观众和粉丝列表实体结构与榜单结构不一致做个兼容操作
*/
for (Object o : rank) {
JSONObject item= (JSONObject) o;
LiveUserRankBean bean=JSON.parseObject(item.getString("userinfo"),LiveUserRankBean.class);