diff --git a/common/src/main/java/com/yunbao/common/bean/AnchorRecommendItemModel.java b/common/src/main/java/com/yunbao/common/bean/AnchorRecommendItemModel.java new file mode 100644 index 000000000..d53818f8a --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/AnchorRecommendItemModel.java @@ -0,0 +1,324 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +/** + * 猜你喜欢数据类(具体主播数据) + */ +public class AnchorRecommendItemModel extends BaseModel { + /** + * islive : 1 + * uid : 97616 + * title : 12 + * stream : 97616_1649830285 + * pull : http://pullry.yaoulive.com/uwd1c0sxu1p71/97616_1649830285.flv + * thumb : https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600 + * isvideo : 0 + * type : 0 + * type_val : + * anyway : 1 + * landscape : 1 + * liveclassid : 1 + * is_rong : 1 + * hot_num : 30579 + * content_pic_size_one : + * content_pic_size_two : + * content_pic_size_three : + * nums : 1 + * avatar : https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600 + * avatar_thumb : https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600 + * avatar2 : + * user_nicename : RongCloudcs20 + * level : 32 + * level_anchor : 58 + */ + + @SerializedName("islive") + private long islive = 0; + @SerializedName("uid") + private long uid = 0; + @SerializedName("title") + private String title = ""; + @SerializedName("stream") + private String stream = ""; + @SerializedName("pull") + private String pull = ""; + @SerializedName("thumb") + private String thumb = ""; + @SerializedName("isvideo") + private long isvideo = 0; + @SerializedName("type") + private int type = 0; + @SerializedName("type_val") + private String typeVal = ""; + @SerializedName("anyway") + private long anyway = 0; + @SerializedName("landscape") + private long landscape = 0; + @SerializedName("liveclassid") + private long liveclassid = 0; + @SerializedName("is_rong") + private long isRong = 0; + @SerializedName("hot_num") + private long hotNum = 0; + @SerializedName("content_pic_size_one") + private String contentPicSizeOne = ""; + @SerializedName("content_pic_size_two") + private String contentPicSizeTwo = ""; + @SerializedName("content_pic_size_three") + private String contentPicSizeThree; + @SerializedName("nums") + private String nums = ""; + @SerializedName("avatar") + private String avatar = ""; + @SerializedName("avatar_thumb") + private String avatarThumb = ""; + @SerializedName("avatar2") + private String avatar2 = ""; + @SerializedName("user_nicename") + private String userNicename = ""; + @SerializedName("level") + private String level = ""; + @SerializedName("level_anchor") + private String levelAnchor = ""; + //是否是pk状态 + @SerializedName("drpk_status") + private String drpkStatus; + //pk对方的头像 + @SerializedName("pk_avatar_thumb") + private String pkAvatarThumb; + + public String getPkAvatarThumb() { + return pkAvatarThumb; + } + + public AnchorRecommendItemModel setPkAvatarThumb(String pkAvatarThumb) { + this.pkAvatarThumb = pkAvatarThumb; + return this; + } + + public String getDrpkStatus() { + return drpkStatus; + } + + public AnchorRecommendItemModel setDrpkStatus(String drpkStatus) { + this.drpkStatus = drpkStatus; + return this; + } + + public long getIslive() { + return islive; + } + + public AnchorRecommendItemModel setIslive(long islive) { + this.islive = islive; + return this; + } + + public long getUid() { + return uid; + } + + public AnchorRecommendItemModel setUid(long uid) { + this.uid = uid; + return this; + } + + public String getTitle() { + return title; + } + + public AnchorRecommendItemModel setTitle(String title) { + this.title = title; + return this; + } + + public String getStream() { + return stream; + } + + public AnchorRecommendItemModel setStream(String stream) { + this.stream = stream; + return this; + } + + public String getPull() { + return pull; + } + + public AnchorRecommendItemModel setPull(String pull) { + this.pull = pull; + return this; + } + + public String getThumb() { + return thumb; + } + + public AnchorRecommendItemModel setThumb(String thumb) { + this.thumb = thumb; + return this; + } + + public long getIsvideo() { + return isvideo; + } + + public AnchorRecommendItemModel setIsvideo(long isvideo) { + this.isvideo = isvideo; + return this; + } + + public int getType() { + return type; + } + + public AnchorRecommendItemModel setType(int type) { + this.type = type; + return this; + } + + public String getTypeVal() { + return typeVal; + } + + public AnchorRecommendItemModel setTypeVal(String typeVal) { + this.typeVal = typeVal; + return this; + } + + public long getAnyway() { + return anyway; + } + + public AnchorRecommendItemModel setAnyway(long anyway) { + this.anyway = anyway; + return this; + } + + public long getLandscape() { + return landscape; + } + + public AnchorRecommendItemModel setLandscape(long landscape) { + this.landscape = landscape; + return this; + } + + public long getLiveclassid() { + return liveclassid; + } + + public AnchorRecommendItemModel setLiveclassid(long liveclassid) { + this.liveclassid = liveclassid; + return this; + } + + public long getIsRong() { + return isRong; + } + + public AnchorRecommendItemModel setIsRong(long isRong) { + this.isRong = isRong; + return this; + } + + public long getHotNum() { + return hotNum; + } + + public AnchorRecommendItemModel setHotNum(long hotNum) { + this.hotNum = hotNum; + return this; + } + + public String getContentPicSizeOne() { + return contentPicSizeOne; + } + + public AnchorRecommendItemModel setContentPicSizeOne(String contentPicSizeOne) { + this.contentPicSizeOne = contentPicSizeOne; + return this; + } + + public String getContentPicSizeTwo() { + return contentPicSizeTwo; + } + + public AnchorRecommendItemModel setContentPicSizeTwo(String contentPicSizeTwo) { + this.contentPicSizeTwo = contentPicSizeTwo; + return this; + } + + public String getContentPicSizeThree() { + return contentPicSizeThree; + } + + public AnchorRecommendItemModel setContentPicSizeThree(String contentPicSizeThree) { + this.contentPicSizeThree = contentPicSizeThree; + return this; + } + + public String getNums() { + return nums; + } + + public AnchorRecommendItemModel setNums(String nums) { + this.nums = nums; + return this; + } + + public String getAvatar() { + return avatar; + } + + public AnchorRecommendItemModel setAvatar(String avatar) { + this.avatar = avatar; + return this; + } + + public String getAvatarThumb() { + return avatarThumb; + } + + public AnchorRecommendItemModel setAvatarThumb(String avatarThumb) { + this.avatarThumb = avatarThumb; + return this; + } + + public String getAvatar2() { + return avatar2; + } + + public AnchorRecommendItemModel setAvatar2(String avatar2) { + this.avatar2 = avatar2; + return this; + } + + public String getUserNicename() { + return userNicename; + } + + public AnchorRecommendItemModel setUserNicename(String userNicename) { + this.userNicename = userNicename; + return this; + } + + public String getLevel() { + return level; + } + + public AnchorRecommendItemModel setLevel(String level) { + this.level = level; + return this; + } + + public String getLevelAnchor() { + return levelAnchor; + } + + public AnchorRecommendItemModel setLevelAnchor(String levelAnchor) { + this.levelAnchor = levelAnchor; + return this; + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/AnchorRecommendModel.java b/common/src/main/java/com/yunbao/common/bean/AnchorRecommendModel.java new file mode 100644 index 000000000..37aab8302 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/AnchorRecommendModel.java @@ -0,0 +1,52 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +import java.util.ArrayList; +import java.util.List; + +/** + * 猜你喜欢 + */ +public class AnchorRecommendModel extends BaseModel { + /** + * list_show : 1 + * up_show : 1 + * list : [{"islive":1,"uid":97616,"title":"12","stream":"97616_1649830285","pull":"http://pullry.yaoulive.com/uwd1c0sxu1p71/97616_1649830285.flv","thumb":"https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600","isvideo":0,"type":0,"type_val":"","anyway":1,"landscape":1,"liveclassid":1,"is_rong":1,"hot_num":30579,"content_pic_size_one":"","content_pic_size_two":"","content_pic_size_three":"","nums":"1","avatar":"https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600","avatar_thumb":"https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600","avatar2":"","user_nicename":"RongCloudcs20","level":"32","level_anchor":"58"},{"islive":1,"uid":97617,"title":"23","stream":"97617_1649830293","pull":"http://pullry.yaoulive.com/uwd1c0sxu1p71/97617_1649830293.flv","thumb":"https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600","isvideo":0,"type":0,"type_val":"","anyway":1,"landscape":1,"liveclassid":1,"is_rong":1,"hot_num":5356,"content_pic_size_one":"","content_pic_size_two":"","content_pic_size_three":"","nums":"1","avatar":"https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600","avatar_thumb":"https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600","avatar2":"","user_nicename":"RongCloudcs21","level":"32","level_anchor":"12"},{"islive":1,"uid":97619,"title":"45","stream":"97619_1649830309","pull":"http://pullry.yaoulive.com/uwd1c0sxu1p71/97619_1649830309.flv","thumb":"https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600","isvideo":0,"type":0,"type_val":"","anyway":1,"landscape":1,"liveclassid":1,"is_rong":1,"hot_num":41061,"content_pic_size_one":"","content_pic_size_two":"","content_pic_size_three":"","nums":"4","avatar":"https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600","avatar_thumb":"https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600","avatar2":"","user_nicename":"RongCloudcs23","level":"32","level_anchor":"21"},{"islive":1,"uid":97620,"title":"56","stream":"97620_1649830320","pull":"http://pullry.yaoulive.com/uwd1c0sxu1p71/97620_1649830320.flv","thumb":"https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600","isvideo":0,"type":0,"type_val":"","anyway":1,"landscape":1,"liveclassid":1,"is_rong":1,"hot_num":29610,"content_pic_size_one":"","content_pic_size_two":"","content_pic_size_three":"","nums":"4","avatar":"https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600","avatar_thumb":"https://qny.shayucm.com/20210805013115_aaf2203dd76321d068943bb6868c3461?imageView2/2/w/600/h/600","avatar2":"","user_nicename":"RongCloudcs24","level":"32","level_anchor":"34"},{"islive":1,"uid":97712,"title":"宽哥太牛辣","stream":"97712_1658912067","pull":"http://pullry.yaoulive.com/uwd1c0sxu1p71/97712_2022.flv","thumb":"https://qny.shayucm.com/20220329113227_c661f791c5fc878c2ef357ee022f9fbc?imageView2/2/w/600/h/600","isvideo":0,"type":0,"type_val":"","anyway":1,"landscape":1,"liveclassid":1,"is_rong":1,"hot_num":41498,"content_pic_size_one":"","content_pic_size_two":"","content_pic_size_three":"","nums":"3","avatar":"https://qny.shayucm.com/20220329113227_c661f791c5fc878c2ef357ee022f9fbc?imageView2/2/w/600/h/600","avatar_thumb":"https://qny.shayucm.com/20220329113227_c661f791c5fc878c2ef357ee022f9fbc?imageView2/2/w/200/h/200","avatar2":"","user_nicename":"rongyun002","level":"71","level_anchor":"14"}] + */ + //是否展示0=不展示1=展示 + @SerializedName("list_show") + private int listShow = 0; + //是否支持换一批0=不支持 1=支持 + @SerializedName("up_show") + private int upShow = 0; + @SerializedName("list") + private List list = new ArrayList<>(); + + public int getListShow() { + return listShow; + } + + public AnchorRecommendModel setListShow(int listShow) { + this.listShow = listShow; + return this; + } + + public int getUpShow() { + return upShow; + } + + public AnchorRecommendModel setUpShow(int upShow) { + this.upShow = upShow; + return this; + } + + public List getList() { + return list; + } + + public AnchorRecommendModel setList(List list) { + this.list = list; + return this; + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/SearchHistoryModel.java b/common/src/main/java/com/yunbao/common/bean/SearchHistoryModel.java new file mode 100644 index 000000000..62559e7df --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/SearchHistoryModel.java @@ -0,0 +1,38 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +/** + * 搜索记录 + */ +public class SearchHistoryModel extends BaseModel { + //简体 + @SerializedName("simplified") + private String simplified = ""; + //繁体 + @SerializedName("traditionalChinese") + private String traditionalChinese = ""; + + public String getSimplified() { + return simplified; + } + + public SearchHistoryModel setSimplified(String simplified) { + this.simplified = simplified; + return this; + } + + public String getTraditionalChinese() { + return traditionalChinese; + } + + public SearchHistoryModel setTraditionalChinese(String traditionalChinese) { + this.traditionalChinese = traditionalChinese; + return this; + } + + public SearchHistoryModel(String simplified, String traditionalChinese) { + this.simplified = simplified; + this.traditionalChinese = traditionalChinese; + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/SearchRecommendModel.java b/common/src/main/java/com/yunbao/common/bean/SearchRecommendModel.java index 641f9bd05..8f3665b66 100644 --- a/common/src/main/java/com/yunbao/common/bean/SearchRecommendModel.java +++ b/common/src/main/java/com/yunbao/common/bean/SearchRecommendModel.java @@ -2,7 +2,9 @@ package com.yunbao.common.bean; import com.google.gson.annotations.SerializedName; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -12,6 +14,9 @@ public class SearchRecommendModel extends BaseModel { //存在第一条数据 @SerializedName("historyRecordMap") private Map historyRecordMap = new HashMap<>(); + //猜你喜欢数据 + @SerializedName("list") + private List list = new ArrayList<>(); public Map getHistoryRecordMap() { return historyRecordMap; @@ -21,4 +26,13 @@ public class SearchRecommendModel extends BaseModel { this.historyRecordMap = historyRecordMap; return this; } + + public List getList() { + return list; + } + + public SearchRecommendModel setList(List list) { + this.list = list; + return this; + } } diff --git a/common/src/main/java/com/yunbao/common/event/SearchRecommendEvent.java b/common/src/main/java/com/yunbao/common/event/SearchRecommendEvent.java new file mode 100644 index 000000000..93a0bf0e2 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/event/SearchRecommendEvent.java @@ -0,0 +1,9 @@ +package com.yunbao.common.event; + +import com.yunbao.common.bean.BaseModel; + +/** + * 刷新猜你喜欢 + */ +public class SearchRecommendEvent extends BaseModel { +} 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 7f22792c6..edd482765 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -1,5 +1,6 @@ package com.yunbao.common.http; +import com.yunbao.common.bean.AnchorRecommendModel; import com.yunbao.common.bean.BaseModel; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.NobleTrumpetModel; @@ -75,7 +76,7 @@ public interface PDLiveApi { @Query("p") int p); /** - * 搜索 + * 搜索(返回数据格式不一样所以写了两个方法其实就是同一个接口) * * @param jianKey 簡體關鍵字 * @param fanKey 繁體關鍵字 @@ -89,4 +90,15 @@ public interface PDLiveApi { @Query("fan_key") String fanKey, @Query("type") int type, @Query("p") int p); + + /** + * 猜你喜欢 + * + * @param num 请求数量 + * @return + */ + @GET("/api/public/?service=Home.anchorRecommend ") + Observable> anchorRecommend( + @Query("num") String num + ); } diff --git a/common/src/main/java/com/yunbao/common/http/main/MainNetManager.java b/common/src/main/java/com/yunbao/common/http/main/MainNetManager.java index df70a6c0f..3a19ceadc 100644 --- a/common/src/main/java/com/yunbao/common/http/main/MainNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/main/MainNetManager.java @@ -2,6 +2,7 @@ package com.yunbao.common.http.main; import android.app.Activity; +import com.yunbao.common.bean.AnchorRecommendModel; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.SearchModel; import com.yunbao.common.http.API; @@ -73,7 +74,7 @@ public class MainNetManager { * @param p 頁碼 */ public void search(String jianKey, String fanKey, int type, int p, HttpCallback>> callback) { - API.get().pdLiveApi(mContext).search(jianKey,fanKey,type,p) + API.get().pdLiveApi(mContext).search(jianKey, fanKey, type, p) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(listResponseModel -> { @@ -87,6 +88,7 @@ public class MainNetManager { } }).isDisposed(); } + /** * 搜索 * @@ -96,7 +98,7 @@ public class MainNetManager { * @param p 頁碼 */ public void searchNew(String jianKey, String fanKey, int type, int p, HttpCallback> callback) { - API.get().pdLiveApi(mContext).searchNew(jianKey,fanKey,type,p) + API.get().pdLiveApi(mContext).searchNew(jianKey, fanKey, type, p) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(listResponseModel -> { @@ -110,4 +112,26 @@ public class MainNetManager { } }).isDisposed(); } + + /** + * 猜你喜欢 + * + * @param num 请求数量 + * @return + */ + public void anchorRecommend(String num, HttpCallback httpCallback) { + API.get().pdLiveApi(mContext).anchorRecommend(num) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(anchorRecommendModelResponseModel -> { + if (httpCallback != null) { + AnchorRecommendModel model = anchorRecommendModelResponseModel.getData().getInfo(); + httpCallback.onSuccess(model); + } + }, throwable -> { + if (httpCallback != null) { + httpCallback.onError(throwable.getMessage()); + } + }).isDisposed(); + } } diff --git a/common/src/main/java/com/yunbao/common/manager/SearchHistoryRecordManager.java b/common/src/main/java/com/yunbao/common/manager/SearchHistoryRecordManager.java index acf8d51b6..5f63d25a9 100644 --- a/common/src/main/java/com/yunbao/common/manager/SearchHistoryRecordManager.java +++ b/common/src/main/java/com/yunbao/common/manager/SearchHistoryRecordManager.java @@ -2,12 +2,14 @@ package com.yunbao.common.manager; import android.content.Context; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.TypeReference; import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.yunbao.common.bean.SearchHistoryModel; import com.yunbao.common.manager.base.BaseCacheManager; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -17,7 +19,7 @@ public class SearchHistoryRecordManager extends BaseCacheManager { private final static String KEY_HISTORY_RECORD = "HistoryRecord"; private static SearchHistoryRecordManager manager; - private Map historyRecordMap; + private List historyRecordList; public SearchHistoryRecordManager(Context context) { super(context); @@ -36,40 +38,70 @@ public class SearchHistoryRecordManager extends BaseCacheManager { } /** - * 获取指导员备注信息 + * 获取搜索历史记录 * * @return */ - public Map getHistoryRecord() { - if (null == historyRecordMap) { - historyRecordMap = JSON.parseObject(getString(KEY_HISTORY_RECORD), new TypeReference>() { - }); + public List getHistoryRecord() { + if (null == historyRecordList) { + historyRecordList = new Gson().fromJson(getString(KEY_HISTORY_RECORD), new TypeToken>() { + }.getType()); } - if (historyRecordMap == null) { - historyRecordMap = new HashMap<>(); + if (historyRecordList == null) { + historyRecordList = new ArrayList<>(); } - return historyRecordMap; + return historyRecordList; } + /** + * 获取搜索记录繁体简体map集合 + * + * @return + */ + public Map getHistoryRecordMap() { + Map historyMap1 = new HashMap<>(); + getHistoryRecord(); + for (SearchHistoryModel historyModel : historyRecordList) { + historyMap1.put(historyModel.getSimplified(), historyModel.getTraditionalChinese()); + } + return historyMap1; + } /** - * 新增备注 + * 新增搜索历史记录最多存储10条 * * @param key 用户id * @param value 备注信息 */ public void addHistoryRecord(String key, String value) { - this.historyRecordMap.put(key, value); - String json = new Gson().toJson(historyRecordMap).toString(); + + if (historyRecordList.size() == 10) { + historyRecordList.remove(0); + } + historyRecordList.add(new SearchHistoryModel(key, value)); + String json = new Gson().toJson(historyRecordList); put(KEY_HISTORY_RECORD, json); } /** - * 删除备注 + * 删除历史记录 */ public void removeHistoryRecord(String key) { - historyRecordMap.remove(key); - String json = new Gson().toJson(historyRecordMap).toString(); + for (SearchHistoryModel historyModel : historyRecordList) { + if (historyModel.getSimplified().equals(key)) { + historyRecordList.remove(historyModel); + return; + } + } + String json = new Gson().toJson(historyRecordList); put(KEY_HISTORY_RECORD, json); } + + /** + * 清空历史记录 + */ + public void removeAllHistoryRecord() { + deleteByKey(KEY_HISTORY_RECORD); + historyRecordList.clear(); + } } diff --git a/common/src/main/java/com/yunbao/common/utils/DeviceUtils.java b/common/src/main/java/com/yunbao/common/utils/DeviceUtils.java new file mode 100644 index 000000000..b2f2f82d8 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/utils/DeviceUtils.java @@ -0,0 +1,58 @@ +package com.yunbao.common.utils; + +import android.app.Activity; +import android.content.Context; +import android.util.DisplayMetrics; + +/** + * 设备通用类 + */ +public class DeviceUtils { + /** + * 获取屏幕宽度 + * + * @param activity activity + * @return 屏幕宽度 + */ + public static int getScreenWidth(Activity activity) { + DisplayMetrics displayMetrics = new DisplayMetrics(); + activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); + return displayMetrics.widthPixels; + } + + /** + * 获取屏幕高度 + * + * @param activity activity + * @return 屏幕高度 + */ + public static int getScreenHeight(Activity activity) { + DisplayMetrics displayMetrics = new DisplayMetrics(); + activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); + return displayMetrics.heightPixels; + } + + /** + * 根据手机的分辨率从 dp 的单位 转成为 px(像素) + * + * @param context context + * @param dpValue dp + * @return 返回px + */ + public static int dip2px(Context context, float dpValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (dpValue * scale + 0.5f); + } + + /** + * 根据手机的分辨率从 px(像素) 的单位 转成为 dp + * + * @param context context + * @param pxValue px + * @return 返回dp + */ + public static int px2dip(Context context, float pxValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (pxValue / scale + 0.5f); + } +} \ No newline at end of file diff --git a/main/src/main/java/com/yunbao/main/adapter/SearchRecommendAdapter.java b/main/src/main/java/com/yunbao/main/adapter/SearchRecommendAdapter.java index d07f870a9..fb09867ff 100644 --- a/main/src/main/java/com/yunbao/main/adapter/SearchRecommendAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/SearchRecommendAdapter.java @@ -1,5 +1,6 @@ package com.yunbao.main.adapter; +import android.app.Activity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -22,6 +23,11 @@ public class SearchRecommendAdapter extends RecyclerView.Adapter { private static final int HEAD = 0; private static final int BODY = 1; private List recommendModels = new ArrayList<>(); + private Activity activity; + + public SearchRecommendAdapter(Activity activity) { + this.activity = activity; + } @NonNull @Override @@ -32,7 +38,7 @@ public class SearchRecommendAdapter extends RecyclerView.Adapter { return new SearchRecommendHeardViewHolder(herdView); default: View bodyView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_search_recommend_body, parent, false); - return new SearchRecommendBodyViewHolder(bodyView); + return new SearchRecommendBodyViewHolder(bodyView, activity); } } @@ -42,7 +48,8 @@ public class SearchRecommendAdapter extends RecyclerView.Adapter { SearchRecommendHeardViewHolder heardViewHolder = (SearchRecommendHeardViewHolder) holder; heardViewHolder.setHistory(recommendModels.get(position).getHistoryRecordMap()); } else { - + SearchRecommendBodyViewHolder bodyViewHolder = (SearchRecommendBodyViewHolder) holder; + bodyViewHolder.showData(recommendModels.get(position).getList()); } } @@ -53,11 +60,16 @@ public class SearchRecommendAdapter extends RecyclerView.Adapter { @Override public int getItemViewType(int position) { - if (position == (recommendModels.size() - 1)) { - return HEAD; - } else { + if (recommendModels.size() == 1 && recommendModels.get(position).getHistoryRecordMap().size() == 0){ return BODY; + }else { + if (position == (recommendModels.size() - 1) ) { + return HEAD; + } else { + return BODY; + } } + } /** diff --git a/main/src/main/java/com/yunbao/main/adapter/SearchRecommendBodyAdapter.java b/main/src/main/java/com/yunbao/main/adapter/SearchRecommendBodyAdapter.java new file mode 100644 index 000000000..112fba9cd --- /dev/null +++ b/main/src/main/java/com/yunbao/main/adapter/SearchRecommendBodyAdapter.java @@ -0,0 +1,59 @@ +package com.yunbao.main.adapter; + +import android.app.Activity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.yunbao.common.bean.AnchorRecommendItemModel; +import com.yunbao.common.utils.DeviceUtils; +import com.yunbao.main.R; +import com.yunbao.main.views.SearchRecommendBodyItemViewHolder; + +import java.util.ArrayList; +import java.util.List; + +/** + * 猜你喜欢适配器 + */ +public class SearchRecommendBodyAdapter extends RecyclerView.Adapter { + List itemModelList = new ArrayList<>(); + private Activity activity; + + public SearchRecommendBodyAdapter(Activity activity) { + this.activity = activity; + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View herdView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main_home_lives, parent, false); + return new SearchRecommendBodyItemViewHolder(herdView); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + int height = DeviceUtils.getScreenHeight(activity); + if (holder instanceof SearchRecommendBodyItemViewHolder) { + SearchRecommendBodyItemViewHolder bodyItemViewHolder = (SearchRecommendBodyItemViewHolder) holder; + bodyItemViewHolder.showData(itemModelList.get(position), height); + } + } + + @Override + public int getItemCount() { + return itemModelList.size(); + } + + /** + * 设置数据源 + */ + public void showData(List list) { + itemModelList.clear(); + itemModelList.addAll(list); + notifyDataSetChanged(); + } +} diff --git a/main/src/main/java/com/yunbao/main/fragment/SearchRecommendFragment.java b/main/src/main/java/com/yunbao/main/fragment/SearchRecommendFragment.java index 163f3776b..73863de0d 100644 --- a/main/src/main/java/com/yunbao/main/fragment/SearchRecommendFragment.java +++ b/main/src/main/java/com/yunbao/main/fragment/SearchRecommendFragment.java @@ -8,13 +8,21 @@ import android.view.ViewGroup; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.yunbao.common.bean.AnchorRecommendModel; import com.yunbao.common.bean.SearchRecommendModel; +import com.yunbao.common.dialog.LoadingDialog; +import com.yunbao.common.event.SearchRecommendEvent; import com.yunbao.common.fragment.BaseFragment; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.main.MainNetManager; +import com.yunbao.common.manager.SearchHistoryRecordManager; import com.yunbao.main.R; import com.yunbao.main.adapter.SearchRecommendAdapter; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,27 +48,64 @@ public class SearchRecommendFragment extends BaseFragment { protected void initViews(Bundle savedInstanceState, View contentView) { searchRecommend = contentView.findViewById(R.id.search_recommend_list); - adapter = new SearchRecommendAdapter(); + adapter = new SearchRecommendAdapter(getActivity()); searchRecommend.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, true)); searchRecommend.setAdapter(adapter); + } @Override protected void loadData() { - List searchRecommendModels = new ArrayList<>(); - SearchRecommendModel model = new SearchRecommendModel(); - Map historyRecordMap = new HashMap<>(); - historyRecordMap.put("大米", ""); - historyRecordMap.put("開門", ""); - historyRecordMap.put("芝麻", ""); - historyRecordMap.put("瓦達上來看沒看", ""); - historyRecordMap.put("錒", ""); - historyRecordMap.put("加兩顆蛋", ""); - historyRecordMap.put("打算", ""); - searchRecommendModels.add(model.setHistoryRecordMap(historyRecordMap)); - adapter.addData(searchRecommendModels); + //展示网络请求弹窗 + LoadingDialog fragment = new LoadingDialog(); + fragment.show(getChildFragmentManager(), "LoadingDialog"); + MainNetManager.get(getActivity()) + .anchorRecommend("6", new HttpCallback() { + @Override + public void onSuccess(AnchorRecommendModel data) { + fragment.dismiss(); + //组装搜索历史数据 + List searchRecommendModels = new ArrayList<>(); + Map historyRecordMap = SearchHistoryRecordManager.get(getActivity()).getHistoryRecordMap(); + if (historyRecordMap.size() > 0) { + SearchRecommendModel model = new SearchRecommendModel(); + searchRecommendModels.add(model.setHistoryRecordMap(historyRecordMap)); + } + searchRecommendModels.add(0, new SearchRecommendModel().setList(data.getList())); + adapter.addData(searchRecommendModels); + + } + + @Override + public void onError(String error) { + fragment.dismiss(); + } + }); } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onSearchRecommendEvent(SearchRecommendEvent event) { + //展示网络请求弹窗 + LoadingDialog fragment = new LoadingDialog(); + fragment.show(getChildFragmentManager(), "LoadingDialog"); + MainNetManager.get(getActivity()) + .anchorRecommend("6", new HttpCallback() { + @Override + public void onSuccess(AnchorRecommendModel data) { + fragment.dismiss(); + //组装搜索历史数据 + List searchRecommendModels = new ArrayList<>(); + searchRecommendModels.add(0, new SearchRecommendModel().setList(data.getList())); + adapter.addData(searchRecommendModels); + + } + + @Override + public void onError(String error) { + fragment.dismiss(); + } + }); + } } diff --git a/main/src/main/java/com/yunbao/main/views/SearchRecommendBodyItemViewHolder.java b/main/src/main/java/com/yunbao/main/views/SearchRecommendBodyItemViewHolder.java new file mode 100644 index 000000000..bbc4b60ce --- /dev/null +++ b/main/src/main/java/com/yunbao/main/views/SearchRecommendBodyItemViewHolder.java @@ -0,0 +1,106 @@ +package com.yunbao.main.views; + +import android.content.Context; +import android.text.TextUtils; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.squareup.picasso.Picasso; +import com.yunbao.common.Constants; +import com.yunbao.common.bean.AnchorRecommendItemModel; +import com.yunbao.common.custom.RatioRoundImageView; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.utils.formatBigNum; +import com.yunbao.main.R; +import com.yunbao.main.utils.MainIconUtil; + +public class SearchRecommendBodyItemViewHolder extends RecyclerView.ViewHolder { + private ImageView mCover, liveType, mLiveIco, mType, pkico, drPkIco, pkAvatar; + private RatioRoundImageView bgs; + private View views; + private TextView mLiveState, mTitle, mName, mNum; + + public SearchRecommendBodyItemViewHolder(@NonNull View itemView) { + super(itemView); + //展示普通布局,隐藏周星榜布局 + itemView.findViewById(R.id.live_info_view).setVisibility(View.VISIBLE); + itemView.findViewById(R.id.lt_week_list).setVisibility(View.GONE); + mCover = itemView.findViewById(R.id.cover); + bgs = itemView.findViewById(R.id.bgs); + liveType = itemView.findViewById(R.id.live_type); + views = itemView.findViewById(R.id.views); + mLiveIco = (ImageView) itemView.findViewById(R.id.tv_live_ico); + mLiveState = (TextView) itemView.findViewById(R.id.tv_live_state); + mType = (ImageView) itemView.findViewById(R.id.type); + mTitle = (TextView) itemView.findViewById(R.id.title); + mName = (TextView) itemView.findViewById(R.id.name); + mNum = (TextView) itemView.findViewById(R.id.num); + pkico = (ImageView) itemView.findViewById(R.id.pk_ico); + drPkIco = (ImageView) itemView.findViewById(R.id.dr_pk_ico); + pkAvatar = (ImageView) itemView.findViewById(R.id.pk_avatar); + + } + + public void showData(AnchorRecommendItemModel model, int height) { + Context mContext = itemView.getContext(); + liveType.setImageDrawable(null); + if (model.getContentPicSizeTwo() != null && !model.getContentPicSizeTwo().equals("") && height <= 1920) { + Picasso.with(mContext) + .load(model.getContentPicSizeTwo()) + .into(liveType); + } else if (model.getContentPicSizeThree() != null && !model.getContentPicSizeThree().equals("") && height > 1920) { + Picasso.with(mContext) + .load(model.getContentPicSizeThree()) + .into(liveType); + } + ImgLoader.display(itemView.getContext(), model.getThumb(), mCover); + bgs.setVisibility(View.VISIBLE); + pkico.setVisibility(View.GONE); + pkAvatar.setVisibility(View.GONE); + drPkIco.setVisibility(View.GONE); + if (model.getDrpkStatus() != null && model.getDrpkStatus().equals("1")) { + drPkIco.setVisibility(View.VISIBLE); + } + if (model.getPkAvatarThumb() != null && !model.getPkAvatarThumb().equals("")) { + ImgLoader.display(mContext, model.getPkAvatarThumb(), pkAvatar); + pkico.setVisibility(View.VISIBLE); + pkAvatar.setVisibility(View.VISIBLE); + } + mName.setText(model.getUserNicename()); + if (TextUtils.isEmpty(model.getTitle())) { + if (mTitle.getVisibility() == View.VISIBLE) { + mTitle.setVisibility(View.GONE); + } + } else { + if (mTitle.getVisibility() != View.VISIBLE) { + mTitle.setVisibility(View.VISIBLE); + } + mTitle.setText(model.getTitle()); + } + mNum.setText(formatBigNum.formatBigNum(String.valueOf(model.getHotNum()))); + views.setVisibility(View.GONE); + if (model.getIslive() == 1) { + views.setVisibility(View.VISIBLE); + //直播中 + mType.setImageResource(MainIconUtil.getLiveTypeIcon(model.getType())); + mType.setVisibility(View.VISIBLE); + mLiveIco.setImageResource(R.mipmap.icon_main_rest_work); + mNum.setVisibility(View.VISIBLE); + liveType.setVisibility(View.VISIBLE); + mLiveState.setText(R.string.lives_state); + } else { + views.setVisibility(View.VISIBLE); + //休息中 + mType.setImageResource(MainIconUtil.getLiveTypeIcon(Constants.LIVE_TYPE_RESTING)); + mType.setVisibility(View.GONE); + mLiveIco.setImageResource(R.mipmap.icon_main_rest_spot); + mLiveState.setText(R.string.rest_state); + liveType.setVisibility(View.GONE); + mNum.setVisibility(View.GONE); + } + } +} diff --git a/main/src/main/java/com/yunbao/main/views/SearchRecommendBodyViewHolder.java b/main/src/main/java/com/yunbao/main/views/SearchRecommendBodyViewHolder.java index feda8632f..03f660b38 100644 --- a/main/src/main/java/com/yunbao/main/views/SearchRecommendBodyViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/SearchRecommendBodyViewHolder.java @@ -1,15 +1,53 @@ package com.yunbao.main.views; +import android.app.Activity; import android.view.View; +import android.widget.ImageView; import androidx.annotation.NonNull; +import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.yunbao.common.bean.AnchorRecommendItemModel; +import com.yunbao.common.event.SearchRecommendEvent; +import com.yunbao.common.utils.Bus; +import com.yunbao.main.R; +import com.yunbao.main.adapter.SearchRecommendBodyAdapter; + +import java.util.List; + /** * 搜索推荐页头部搜索历史信息 */ public class SearchRecommendBodyViewHolder extends RecyclerView.ViewHolder { - public SearchRecommendBodyViewHolder(@NonNull View itemView) { + private RecyclerView liveList; + private SearchRecommendBodyAdapter adapter; + private ImageView changeBatch; + + public SearchRecommendBodyViewHolder(@NonNull View itemView, Activity activity) { super(itemView); + liveList = itemView.findViewById(R.id.live_list); + changeBatch = itemView.findViewById(R.id.change_batch); + liveList.setLayoutManager(new GridLayoutManager(itemView.getContext(), 2, GridLayoutManager.VERTICAL, false)); + adapter = new SearchRecommendBodyAdapter(activity); + liveList.setAdapter(adapter); + changeBatch.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Bus.get().post(new SearchRecommendEvent()); + } + }); } + + /** + * 猜你喜欢数据 + * + * @param list + */ + public void showData(List list) { + adapter.showData(list); + } + + } + diff --git a/main/src/main/res/layout/view_search_recommend.xml b/main/src/main/res/layout/view_search_recommend.xml index 45aa886e1..e31e02fff 100644 --- a/main/src/main/res/layout/view_search_recommend.xml +++ b/main/src/main/res/layout/view_search_recommend.xml @@ -7,5 +7,6 @@ \ No newline at end of file diff --git a/main/src/main/res/layout/view_search_recommend_body.xml b/main/src/main/res/layout/view_search_recommend_body.xml index 9a59881f1..f40333409 100644 --- a/main/src/main/res/layout/view_search_recommend_body.xml +++ b/main/src/main/res/layout/view_search_recommend_body.xml @@ -2,10 +2,35 @@ + + + + + + +