diff --git a/common/build.gradle b/common/build.gradle index f993ab723..b547dd1e0 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -175,4 +175,9 @@ dependencies { //rxjava2库 api 'io.reactivex.rxjava2:rxjava:2.0.1' api 'io.reactivex.rxjava2:rxandroid:2.0.1' + //loading样式库 + api 'com.wang.avi:library:2.1.3' + //黄油刀,注解绑定视图 + api "com.jakewharton:butterknife:10.0.0" + annotationProcessor "com.jakewharton:butterknife-compiler:10.0.0" } diff --git a/common/src/main/java/com/yunbao/common/bean/SearchModel.java b/common/src/main/java/com/yunbao/common/bean/SearchModel.java new file mode 100644 index 000000000..d6ffd7e52 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/SearchModel.java @@ -0,0 +1,154 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +/** + * 首頁搜索返回 + */ +public class SearchModel extends BaseModel { + /** + * id : 79365 + * user_nicename : 鱼鱼子 + * avatar : https://ceshi.yaoulive.com/default.jpg + * sex : 2 + * signature : + * consumption : 2600 + * votestotal : 62850 + * islive : 0 + * level : 4 + * level_anchor : 4 + * isattention : 0 + */ + //用戶ID + @SerializedName("id") + private long id = 0; + //暱稱 + @SerializedName("user_nicename") + private String userNicename = ""; + //頭像 + @SerializedName("avatar") + private String avatar = ""; + //性別 + @SerializedName("sex") + private long sex = 0; + //個性簽名 + @SerializedName("signature") + private String signature = ""; + //消費額度 + @SerializedName("consumption") + private long consumption = 0; + //票數 + @SerializedName("votestotal") + private long votestotal = 0; + //是否在直播 + @SerializedName("islive") + private long islive = 0; + //用戶等級 + @SerializedName("level") + private String level = ""; + + @SerializedName("level_anchor") + private String levelAnchor = ""; + //是否關注 1,關注 2,未關注 + @SerializedName("isattention") + private String isattention = ""; + + public long getId() { + return id; + } + + public SearchModel setId(long id) { + this.id = id; + return this; + } + + public String getUserNicename() { + return userNicename; + } + + public SearchModel setUserNicename(String userNicename) { + this.userNicename = userNicename; + return this; + } + + public String getAvatar() { + return avatar; + } + + public SearchModel setAvatar(String avatar) { + this.avatar = avatar; + return this; + } + + public long getSex() { + return sex; + } + + public SearchModel setSex(long sex) { + this.sex = sex; + return this; + } + + public String getSignature() { + return signature; + } + + public SearchModel setSignature(String signature) { + this.signature = signature; + return this; + } + + public long getConsumption() { + return consumption; + } + + public SearchModel setConsumption(long consumption) { + this.consumption = consumption; + return this; + } + + public long getVotestotal() { + return votestotal; + } + + public SearchModel setVotestotal(long votestotal) { + this.votestotal = votestotal; + return this; + } + + public long getIslive() { + return islive; + } + + public SearchModel setIslive(long islive) { + this.islive = islive; + return this; + } + + public String getLevel() { + return level; + } + + public SearchModel setLevel(String level) { + this.level = level; + return this; + } + + public String getLevelAnchor() { + return levelAnchor; + } + + public SearchModel setLevelAnchor(String levelAnchor) { + this.levelAnchor = levelAnchor; + return this; + } + + public String getIsattention() { + return isattention; + } + + public SearchModel setIsattention(String isattention) { + this.isattention = isattention; + return this; + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/SearchRecommendModel.java b/common/src/main/java/com/yunbao/common/bean/SearchRecommendModel.java new file mode 100644 index 000000000..641f9bd05 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/SearchRecommendModel.java @@ -0,0 +1,24 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +import java.util.HashMap; +import java.util.Map; + +/** + * 搜索页面数据类 + */ +public class SearchRecommendModel extends BaseModel { + //存在第一条数据 + @SerializedName("historyRecordMap") + private Map historyRecordMap = new HashMap<>(); + + public Map getHistoryRecordMap() { + return historyRecordMap; + } + + public SearchRecommendModel setHistoryRecordMap(Map historyRecordMap) { + this.historyRecordMap = historyRecordMap; + return this; + } +} diff --git a/common/src/main/java/com/yunbao/common/dialog/LoadingDialog.java b/common/src/main/java/com/yunbao/common/dialog/LoadingDialog.java new file mode 100644 index 000000000..8c1c3e126 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/dialog/LoadingDialog.java @@ -0,0 +1,41 @@ +package com.yunbao.common.dialog; + +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.view.Gravity; +import android.view.Window; +import android.view.WindowManager; + +import com.yunbao.common.R; + +/** + * 耗时操作通用Loading弹窗 + */ +public class LoadingDialog extends AbsDialogFragment { + @Override + protected int getLayoutId() { + return R.layout.view_loading; + } + + @Override + protected int getDialogStyle() { + return R.style.dialog4; + } + + @Override + protected boolean canCancel() { + return false; + } + + + @Override + protected void setWindowAttributes(Window window) { + window.setWindowAnimations(R.style.bottomToTopAnim); + WindowManager.LayoutParams params = window.getAttributes(); + params.width = WindowManager.LayoutParams.WRAP_CONTENT; + params.height = WindowManager.LayoutParams.WRAP_CONTENT; + params.gravity = Gravity.CENTER; + window.setAttributes(params); + window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + } +} diff --git a/common/src/main/java/com/yunbao/common/fragment/BaseFragment.java b/common/src/main/java/com/yunbao/common/fragment/BaseFragment.java new file mode 100644 index 000000000..f2fefa3eb --- /dev/null +++ b/common/src/main/java/com/yunbao/common/fragment/BaseFragment.java @@ -0,0 +1,80 @@ +package com.yunbao.common.fragment; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import com.yunbao.common.utils.Bus; + +/** + * Fragment基类 + */ +public abstract class BaseFragment extends Fragment { + public static String TAG = BaseFragment.class.getSimpleName(); + private View contentView; + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + if (null == contentView) { + //赋值TAG + TAG = this.getClass().getSimpleName(); + //创建视图 + contentView = createView(inflater, container); + + //初始化变量(用户传递进来的参数) + initVariables(getArguments()); + //初始化视图 + initViews(savedInstanceState,contentView); + //加载数据 + loadData(); + } + //返回视图 + return contentView; + } + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + //基类中注册消息总线 + Bus.getOnWithBase(this); + } + + /** + * 创建视图 + * + * @param inflater inflater + * @param container container + * @return 视图 + */ + public abstract View createView(LayoutInflater inflater, ViewGroup container); + + /** + * 初始化变量 + * + * @param bundle bundle + */ + protected abstract void initVariables(Bundle bundle); + + /** + * 初始化视图 + * + * @param savedInstanceState savedInstanceState + */ + protected abstract void initViews(Bundle savedInstanceState,View contentView); + + /** + * 请求数据 + */ + protected abstract void loadData(); + + @Override + public void onDestroy() { + super.onDestroy(); + //基类中反注册 + Bus.getOffWithBase(this); + } +} diff --git a/common/src/main/java/com/yunbao/common/glide/ImgLoader.java b/common/src/main/java/com/yunbao/common/glide/ImgLoader.java index 1db2e70fe..399194296 100644 --- a/common/src/main/java/com/yunbao/common/glide/ImgLoader.java +++ b/common/src/main/java/com/yunbao/common/glide/ImgLoader.java @@ -61,7 +61,15 @@ public class ImgLoader { } Glide.with(context).asDrawable().load(url).error(errorRes).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView); } - + public static void displayWithError(Context context, int url, ImageView imageView, int errorRes) { + if (!contextIsExist(context)){ + return; + } + if (imageView == null){ + return; + } + Glide.with(context).asDrawable().load(url).error(errorRes).skipMemoryCache(SKIP_MEMORY_CACHE).into(imageView); + } public static void displayAvatar(Context context, String url, ImageView imageView) { if (!contextIsExist(context)){ return; @@ -69,7 +77,13 @@ public class ImgLoader { displayWithError(context, url, imageView, R.mipmap.icon_avatar_placeholder); } + public static void displayAvatar(Context context, int url, ImageView imageView) { + if (!contextIsExist(context)){ + return; + } + displayWithError(context, url, imageView, R.mipmap.icon_avatar_placeholder); + } public static void display(Context context, File file, ImageView imageView) { if (!contextIsExist(context)){ return; 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 f07bbbeb5..7f22792c6 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.BaseModel; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.NobleTrumpetModel; +import com.yunbao.common.bean.SearchModel; import java.util.List; @@ -56,4 +57,36 @@ public interface PDLiveApi { Observable>> nobleUseTrumpet( @Query("trumpet_msg") String trumpetMsg, @Query("anchor_id") String anchorid); + + /** + * 搜索 + * + * @param jianKey 簡體關鍵字 + * @param fanKey 繁體關鍵字 + * @param type 搜索類型 1,全部 + * @param p 頁碼 + * @return + */ + @GET("/api/public/?service=Home.newSearch") + Observable>>> search( + @Query("jian_key") String jianKey, + @Query("fan_key") String fanKey, + @Query("type") int type, + @Query("p") int p); + + /** + * 搜索 + * + * @param jianKey 簡體關鍵字 + * @param fanKey 繁體關鍵字 + * @param type 搜索類型 2,主播 3,用戶 + * @param p 頁碼 + * @return + */ + @GET("/api/public/?service=Home.newSearch") + Observable>> searchNew( + @Query("jian_key") String jianKey, + @Query("fan_key") String fanKey, + @Query("type") int type, + @Query("p") int p); } 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 b147a12cb..df70a6c0f 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 @@ -3,10 +3,13 @@ package com.yunbao.common.http.main; import android.app.Activity; import com.yunbao.common.bean.IMLoginModel; +import com.yunbao.common.bean.SearchModel; import com.yunbao.common.http.API; import com.yunbao.common.http.ResponseModel; import com.yunbao.common.http.base.HttpCallback; +import java.util.List; + import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; @@ -61,5 +64,50 @@ public class MainNetManager { }).isDisposed(); } - + /** + * 搜索 + * + * @param jianKey 簡體關鍵字 + * @param fanKey 繁體關鍵字 + * @param type 搜索類型 1,全部 2,主播 3,用戶 + * @param p 頁碼 + */ + public void search(String jianKey, String fanKey, int type, int p, HttpCallback>> callback) { + API.get().pdLiveApi(mContext).search(jianKey,fanKey,type,p) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(listResponseModel -> { + if (callback != null) { + List> model = listResponseModel.getData().getInfo(); + callback.onSuccess(model); + } + }, throwable -> { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + }).isDisposed(); + } + /** + * 搜索 + * + * @param jianKey 簡體關鍵字 + * @param fanKey 繁體關鍵字 + * @param type 搜索類型 1,全部 2,主播 3,用戶 + * @param p 頁碼 + */ + public void searchNew(String jianKey, String fanKey, int type, int p, HttpCallback> callback) { + API.get().pdLiveApi(mContext).searchNew(jianKey,fanKey,type,p) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(listResponseModel -> { + if (callback != null) { + List model = listResponseModel.getData().getInfo(); + callback.onSuccess(model); + } + }, throwable -> { + if (callback != null) { + callback.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 new file mode 100644 index 000000000..acf8d51b6 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/manager/SearchHistoryRecordManager.java @@ -0,0 +1,75 @@ +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.yunbao.common.manager.base.BaseCacheManager; + +import java.util.HashMap; +import java.util.Map; + +/** + * 搜索历史记录管理 + */ +public class SearchHistoryRecordManager extends BaseCacheManager { + + private final static String KEY_HISTORY_RECORD = "HistoryRecord"; + private static SearchHistoryRecordManager manager; + private Map historyRecordMap; + + public SearchHistoryRecordManager(Context context) { + super(context); + } + + /** + * 获取单利 + * + * @return + */ + public static SearchHistoryRecordManager get(Context context) { + if (null == manager) { + manager = new SearchHistoryRecordManager(context); + } + return manager; + } + + /** + * 获取指导员备注信息 + * + * @return + */ + public Map getHistoryRecord() { + if (null == historyRecordMap) { + historyRecordMap = JSON.parseObject(getString(KEY_HISTORY_RECORD), new TypeReference>() { + }); + } + if (historyRecordMap == null) { + historyRecordMap = new HashMap<>(); + } + return historyRecordMap; + } + + + /** + * 新增备注 + * + * @param key 用户id + * @param value 备注信息 + */ + public void addHistoryRecord(String key, String value) { + this.historyRecordMap.put(key, value); + String json = new Gson().toJson(historyRecordMap).toString(); + put(KEY_HISTORY_RECORD, json); + } + + /** + * 删除备注 + */ + public void removeHistoryRecord(String key) { + historyRecordMap.remove(key); + String json = new Gson().toJson(historyRecordMap).toString(); + put(KEY_HISTORY_RECORD, json); + } +} diff --git a/common/src/main/java/com/yunbao/common/utils/Bus.java b/common/src/main/java/com/yunbao/common/utils/Bus.java new file mode 100644 index 000000000..0454d1957 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/utils/Bus.java @@ -0,0 +1,82 @@ +package com.yunbao.common.utils; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; + +import java.lang.reflect.Method; + +/** + * 老司机-消息总线 + */ + +public class Bus extends EventBus { + private static Bus INSTANCE; + + /** + * 获取车次 + * + * @return eventbus对象 + */ + public static Bus get() { + synchronized (Bus.class) { + if (null == INSTANCE) { + INSTANCE = new Bus(); + } + } + return INSTANCE; + } + + /** + * 上车-老司机带带我 + * + * @param subscriber 监听者 + */ + public static void getOn(Object subscriber) { + get().register(subscriber); + } + + /** + * 在基类中注册eventbus + * + * @param subscriber + */ + public static void getOnWithBase(Object subscriber) { + for (Method method : subscriber + .getClass().getDeclaredMethods()) { + if (method.isAnnotationPresent(Subscribe.class)) { + getOn(subscriber); + break; + } + } + } + + /** + * 下车 + * + * @param subscriber 监听者 + */ + public static void getOff(Object subscriber) { + get().unregister(subscriber); + } + + /** + * 基类中销毁的方法 + * + * @param subscriber + */ + public static void getOffWithBase(Object subscriber) { + if (inBus(subscriber)) { + getOff(subscriber); + } + } + + /** + * 是否上车了 + * + * @param subscriber 监听者 + * @return 是否已监听 + */ + public static boolean inBus(Object subscriber) { + return get().isRegistered(subscriber); + } +} \ No newline at end of file diff --git a/common/src/main/res/layout/view_loading.xml b/common/src/main/res/layout/view_loading.xml new file mode 100644 index 000000000..986fa925f --- /dev/null +++ b/common/src/main/res/layout/view_loading.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/common/src/main/res/values-en/strings.xml b/common/src/main/res/values-en/strings.xml index 65f4dd3f0..1d216e368 100644 --- a/common/src/main/res/values-en/strings.xml +++ b/common/src/main/res/values-en/strings.xml @@ -527,7 +527,7 @@ Scavenging Cache cleared search - Please enter the nickname or ID to search + Search by nickname or ID No content found QQ QQ Zone diff --git a/common/src/main/res/values/colors.xml b/common/src/main/res/values/colors.xml index 8b7d63267..6e444f1f3 100644 --- a/common/src/main/res/values/colors.xml +++ b/common/src/main/res/values/colors.xml @@ -81,4 +81,5 @@ #81C16D #F6F7FB + #FFF6F6F6 diff --git a/common/src/main/res/values/dimens.xml b/common/src/main/res/values/dimens.xml new file mode 100644 index 000000000..8481b66f5 --- /dev/null +++ b/common/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + + 5dp + \ No newline at end of file diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index fc75a5a36..4ef99d87d 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -464,7 +464,7 @@ 清除中 緩存已清除 蒐索 - 請輸入要搜索的昵稱或ID + 搜索昵稱或ID 沒有搜索到相關內容 QQ電話 QQ空間 @@ -866,4 +866,8 @@ 前往贵族 使用成功 前往直播間 + 搜索歷史 + 猜你喜歡 + 主播 + 更多 diff --git a/common/src/main/res/values/style.xml b/common/src/main/res/values/style.xml index b31bb9383..dbe6fbaf8 100644 --- a/common/src/main/res/values/style.xml +++ b/common/src/main/res/values/style.xml @@ -32,6 +32,15 @@ true + + \ No newline at end of file