diff --git a/common/src/main/java/com/yunbao/common/bean/ContributeModel.java b/common/src/main/java/com/yunbao/common/bean/ContributeModel.java new file mode 100644 index 000000000..687fa17df --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/ContributeModel.java @@ -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 + '\'' + + '}'; + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/IMLoginModel.java b/common/src/main/java/com/yunbao/common/bean/IMLoginModel.java index 307c5023c..11eebb93c 100644 --- a/common/src/main/java/com/yunbao/common/bean/IMLoginModel.java +++ b/common/src/main/java/com/yunbao/common/bean/IMLoginModel.java @@ -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 + + '}'; + } } diff --git a/live/src/main/java/com/yunbao/live/bean/LiveUserRankBean.java b/common/src/main/java/com/yunbao/common/bean/LiveUserRankBean.java similarity index 83% rename from live/src/main/java/com/yunbao/live/bean/LiveUserRankBean.java rename to common/src/main/java/com/yunbao/common/bean/LiveUserRankBean.java index 50bec21f6..f3c7a1824 100644 --- a/live/src/main/java/com/yunbao/live/bean/LiveUserRankBean.java +++ b/common/src/main/java/com/yunbao/common/bean/LiveUserRankBean.java @@ -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{" + diff --git a/common/src/main/java/com/yunbao/common/bean/UserRankModel.java b/common/src/main/java/com/yunbao/common/bean/UserRankModel.java new file mode 100644 index 000000000..4fb5e998b --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/UserRankModel.java @@ -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 listDay; + @SerializedName("list_week") + private List listWeek; + + public List getListDay() { + return listDay; + } + + public void setListDay(List listDay) { + this.listDay = listDay; + } + + public List getListWeek() { + return listWeek; + } + + public void setListWeek(List listWeek) { + this.listWeek = listWeek; + } + + @Override + public String toString() { + return "UserRankModel{" + + "listDay=" + listDay + + ", listWeek=" + listWeek + + '}'; + } +} diff --git a/common/src/main/java/com/yunbao/common/http/API.java b/common/src/main/java/com/yunbao/common/http/API.java index 2c2944636..06c72a665 100644 --- a/common/src/main/java/com/yunbao/common/http/API.java +++ b/common/src/main/java/com/yunbao/common/http/API.java @@ -44,30 +44,40 @@ public class API extends BaseApi { public PDLiveApi pdLiveApi(Context context) { if (null == pdLiveApi) { //实例化gson - Gson gson = new GsonBuilder() - .registerTypeAdapter(Date.class, new DateTypeAdapter()) - .create(); - HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("http"); - loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY); - OkHttpClient.Builder builder = new OkHttpClient() - .newBuilder() - .addInterceptor(initQuery(CommonAppContext.sInstance.getApplicationContext())) - .addInterceptor(loggingInterceptor); - - pdLiveApi = create(builder.build(), - GsonConverterFactory.create(gson), RxJava2CallAdapterFactory.create(), CommonAppConfig.HOST, PDLiveApi.class); + 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(); + HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("http"); + loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY); + OkHttpClient.Builder builder = new OkHttpClient() + .newBuilder() + .addInterceptor(initQuery(isNeedUid,CommonAppContext.sInstance.getApplicationContext())) + .addInterceptor(loggingInterceptor); + + return create(builder.build(), + GsonConverterFactory.create(gson), RxJava2CallAdapterFactory.create(), CommonAppConfig.HOST, PDLiveApi.class); + } + //公共参数 - 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); } }; diff --git a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java index a465f85a2..cf3c624e5 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -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>> getDrLm(); + + /** + * 获取日榜、周榜数据 + * @param uid 直播间id,并非用户uid + * @return 榜单结构 + */ + @GET("/api/public/?service=Contribute.index") + Observable>> getRanksList(@Query("uid")String uid); } diff --git a/common/src/main/java/com/yunbao/common/http/ResponseData.java b/common/src/main/java/com/yunbao/common/http/ResponseData.java index eed765701..51937bf92 100644 --- a/common/src/main/java/com/yunbao/common/http/ResponseData.java +++ b/common/src/main/java/com/yunbao/common/http/ResponseData.java @@ -1,6 +1,7 @@ package com.yunbao.common.http; import com.google.gson.annotations.SerializedName; +import com.yunbao.common.bean.UserRankModel; public class ResponseData { @SerializedName("code") @@ -9,6 +10,8 @@ public class ResponseData { 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 { this.info = info; return this; } + + public UserRankModel getData() { + return data; + } + + public void setData(UserRankModel data) { + this.data = data; + } } diff --git a/common/src/main/java/com/yunbao/common/http/base/GetRequestParams.java b/common/src/main/java/com/yunbao/common/http/base/GetRequestParams.java index 174392b95..1d8860202 100644 --- a/common/src/main/java/com/yunbao/common/http/base/GetRequestParams.java +++ b/common/src/main/java/com/yunbao/common/http/base/GetRequestParams.java @@ -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(); } diff --git a/common/src/main/java/com/yunbao/common/http/base/IRequestParam.java b/common/src/main/java/com/yunbao/common/http/base/IRequestParam.java index 505f4cae2..bf3a7b311 100644 --- a/common/src/main/java/com/yunbao/common/http/base/IRequestParam.java +++ b/common/src/main/java/com/yunbao/common/http/base/IRequestParam.java @@ -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); } diff --git a/common/src/main/java/com/yunbao/common/http/base/ParamsContext.java b/common/src/main/java/com/yunbao/common/http/base/ParamsContext.java index 4bfe01e39..8eedbed38 100644 --- a/common/src/main/java/com/yunbao/common/http/base/ParamsContext.java +++ b/common/src/main/java/com/yunbao/common/http/base/ParamsContext.java @@ -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); } } diff --git a/common/src/main/java/com/yunbao/common/http/base/PostRequestParams.java b/common/src/main/java/com/yunbao/common/http/base/PostRequestParams.java index 9e90f6762..6d7730b45 100644 --- a/common/src/main/java/com/yunbao/common/http/base/PostRequestParams.java +++ b/common/src/main/java/com/yunbao/common/http/base/PostRequestParams.java @@ -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(); diff --git a/live/src/main/java/com/yunbao/live/adapter/UserMoreInfoAdapter.java b/live/src/main/java/com/yunbao/live/adapter/UserMoreInfoAdapter.java index 500e55b14..fae9d438f 100644 --- a/live/src/main/java/com/yunbao/live/adapter/UserMoreInfoAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/UserMoreInfoAdapter.java @@ -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; diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java index 36c1340b1..1a6b253c2 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java @@ -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 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 data =new ArrayList<>(); + /** + * 由于在线观众和粉丝列表实体结构与榜单结构不一致,做个兼容操作 + */ for (Object o : rank) { JSONObject item= (JSONObject) o; LiveUserRankBean bean=JSON.parseObject(item.getString("userinfo"),LiveUserRankBean.class);