猜你喜欢功能完成
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<AnchorRecommendItemModel> 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<AnchorRecommendItemModel> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public AnchorRecommendModel setList(List<AnchorRecommendItemModel> list) {
|
||||
this.list = list;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<String, String> historyRecordMap = new HashMap<>();
|
||||
//猜你喜欢数据
|
||||
@SerializedName("list")
|
||||
private List<AnchorRecommendItemModel> list = new ArrayList<>();
|
||||
|
||||
public Map<String, String> getHistoryRecordMap() {
|
||||
return historyRecordMap;
|
||||
@@ -21,4 +26,13 @@ public class SearchRecommendModel extends BaseModel {
|
||||
this.historyRecordMap = historyRecordMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<AnchorRecommendItemModel> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public SearchRecommendModel setList(List<AnchorRecommendItemModel> list) {
|
||||
this.list = list;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.yunbao.common.event;
|
||||
|
||||
import com.yunbao.common.bean.BaseModel;
|
||||
|
||||
/**
|
||||
* 刷新猜你喜欢
|
||||
*/
|
||||
public class SearchRecommendEvent extends BaseModel {
|
||||
}
|
||||
@@ -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<ResponseModel<AnchorRecommendModel>> anchorRecommend(
|
||||
@Query("num") String num
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<List<List<SearchModel>>> 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<List<SearchModel>> 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<AnchorRecommendModel> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String, String> historyRecordMap;
|
||||
private List<SearchHistoryModel> historyRecordList;
|
||||
|
||||
public SearchHistoryRecordManager(Context context) {
|
||||
super(context);
|
||||
@@ -36,40 +38,70 @@ public class SearchHistoryRecordManager extends BaseCacheManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指导员备注信息
|
||||
* 获取搜索历史记录
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, String> getHistoryRecord() {
|
||||
if (null == historyRecordMap) {
|
||||
historyRecordMap = JSON.parseObject(getString(KEY_HISTORY_RECORD), new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
public List<SearchHistoryModel> getHistoryRecord() {
|
||||
if (null == historyRecordList) {
|
||||
historyRecordList = new Gson().fromJson(getString(KEY_HISTORY_RECORD), new TypeToken<List<SearchHistoryModel>>() {
|
||||
}.getType());
|
||||
}
|
||||
if (historyRecordMap == null) {
|
||||
historyRecordMap = new HashMap<>();
|
||||
if (historyRecordList == null) {
|
||||
historyRecordList = new ArrayList<>();
|
||||
}
|
||||
return historyRecordMap;
|
||||
return historyRecordList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取搜索记录繁体简体map集合
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, String> getHistoryRecordMap() {
|
||||
Map<String, String> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user