From 43133e503dd7bdd25adccff7f3cb20de59a19e10 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Sat, 6 Aug 2022 18:18:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E6=B3=A8=E4=B8=BB=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/bean/LiveInfoModel.java | 300 ++++++++++++++++++ .../yunbao/common/bean/SetAttentsModel.java | 26 ++ .../com/yunbao/common/http/PDLiveApi.java | 24 ++ .../common/http/live/LiveNetManager.java | 33 ++ .../presenter/LiveRoomCheckLivePresenter.java | 10 +- .../yunbao/main/activity/SearchActivity.java | 58 ++++ .../yunbao/main/event/JumpUserHomeEvent.java | 22 ++ .../AnchorSearchResultsItemViewHolder.java | 2 +- .../main/views/SearchResultsViewHolder.java | 22 ++ .../UserSearchResultsItemViewHolder.java | 5 +- .../view_search_results_item_holder.xml | 2 + 11 files changed, 497 insertions(+), 7 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/bean/LiveInfoModel.java create mode 100644 common/src/main/java/com/yunbao/common/bean/SetAttentsModel.java create mode 100644 main/src/main/java/com/yunbao/main/event/JumpUserHomeEvent.java diff --git a/common/src/main/java/com/yunbao/common/bean/LiveInfoModel.java b/common/src/main/java/com/yunbao/common/bean/LiveInfoModel.java new file mode 100644 index 000000000..a619aa83d --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/LiveInfoModel.java @@ -0,0 +1,300 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +/** + * 直播间信息数据类 + */ +public class LiveInfoModel extends BaseModel { + /** + * uid : 97721 + * title : + * city : 好像在火星 + * stream : 97721_1653119771 + * pull : http://pullry.yaoulive.com/uwd1c0sxu1p71/97721_1653119771.flv + * thumb : https://ceshi.yaoulive.com/default.jpg + * isvideo : 0 + * type : 0 + * type_val : 0 + * game_action : 0 + * goodnum : 0 + * anyway : 1 + * push : rtmp://pushry.yaoulive.com/uwd1c0sxu1p71/97721_1653119771 + * islive : 1 + * landscape : 2 + * is_rong : 1 + * nums : 4 + * avatar : https://ceshi.yaoulive.com/default.jpg + * avatar_thumb : https://ceshi.yaoulive.com/default_thumb.jpg + * user_nicename : 卢本伟 + * sex : 1 + * level : 8 + * level_anchor : 20 + * game : + */ + + @SerializedName("uid") + private long uid = 0; + @SerializedName("title") + private String title = ""; + @SerializedName("city") + private String city = ""; + @SerializedName("stream") + private String stream = ""; + @SerializedName("pull") + private String pull = ""; + @SerializedName("thumb") + private String thumb = ""; + @SerializedName("isvideo") + private long isvideo = 0; + @SerializedName("type") + private long type = 0; + @SerializedName("type_val") + private String typeVal = ""; + @SerializedName("game_action") + private long gameAction = 0; + @SerializedName("goodnum") + private String goodnum = ""; + @SerializedName("anyway") + private long anyway = 0; + @SerializedName("push") + private String push = ""; + @SerializedName("islive") + private long islive; + @SerializedName("landscape") + private long landscape = 0; + @SerializedName("is_rong") + private long isRong = 0; + @SerializedName("nums") + private String nums = ""; + @SerializedName("avatar") + private String avatar = ""; + @SerializedName("avatar_thumb") + private String avatarThumb = ""; + @SerializedName("user_nicename") + private String userNicename = ""; + @SerializedName("sex") + private long sex = 0; + @SerializedName("level") + private String level = ""; + @SerializedName("level_anchor") + private String levelAnchor = ""; + @SerializedName("game") + private String game = ""; + + public long getUid() { + return uid; + } + + public LiveInfoModel setUid(long uid) { + this.uid = uid; + return this; + } + + public String getTitle() { + return title; + } + + public LiveInfoModel setTitle(String title) { + this.title = title; + return this; + } + + public String getCity() { + return city; + } + + public LiveInfoModel setCity(String city) { + this.city = city; + return this; + } + + public String getStream() { + return stream; + } + + public LiveInfoModel setStream(String stream) { + this.stream = stream; + return this; + } + + public String getPull() { + return pull; + } + + public LiveInfoModel setPull(String pull) { + this.pull = pull; + return this; + } + + public String getThumb() { + return thumb; + } + + public LiveInfoModel setThumb(String thumb) { + this.thumb = thumb; + return this; + } + + public long getIsvideo() { + return isvideo; + } + + public LiveInfoModel setIsvideo(long isvideo) { + this.isvideo = isvideo; + return this; + } + + public long getType() { + return type; + } + + public LiveInfoModel setType(long type) { + this.type = type; + return this; + } + + public String getTypeVal() { + return typeVal; + } + + public LiveInfoModel setTypeVal(String typeVal) { + this.typeVal = typeVal; + return this; + } + + public long getGameAction() { + return gameAction; + } + + public LiveInfoModel setGameAction(long gameAction) { + this.gameAction = gameAction; + return this; + } + + public String getGoodnum() { + return goodnum; + } + + public LiveInfoModel setGoodnum(String goodnum) { + this.goodnum = goodnum; + return this; + } + + public long getAnyway() { + return anyway; + } + + public LiveInfoModel setAnyway(long anyway) { + this.anyway = anyway; + return this; + } + + public String getPush() { + return push; + } + + public LiveInfoModel setPush(String push) { + this.push = push; + return this; + } + + public long getIslive() { + return islive; + } + + public LiveInfoModel setIslive(long islive) { + this.islive = islive; + return this; + } + + public long getLandscape() { + return landscape; + } + + public LiveInfoModel setLandscape(long landscape) { + this.landscape = landscape; + return this; + } + + public long getIsRong() { + return isRong; + } + + public LiveInfoModel setIsRong(long isRong) { + this.isRong = isRong; + return this; + } + + public String getNums() { + return nums; + } + + public LiveInfoModel setNums(String nums) { + this.nums = nums; + return this; + } + + public String getAvatar() { + return avatar; + } + + public LiveInfoModel setAvatar(String avatar) { + this.avatar = avatar; + return this; + } + + public String getAvatarThumb() { + return avatarThumb; + } + + public LiveInfoModel setAvatarThumb(String avatarThumb) { + this.avatarThumb = avatarThumb; + return this; + } + + public String getUserNicename() { + return userNicename; + } + + public LiveInfoModel setUserNicename(String userNicename) { + this.userNicename = userNicename; + return this; + } + + public long getSex() { + return sex; + } + + public LiveInfoModel setSex(long sex) { + this.sex = sex; + return this; + } + + public String getLevel() { + return level; + } + + public LiveInfoModel setLevel(String level) { + this.level = level; + return this; + } + + public String getLevelAnchor() { + return levelAnchor; + } + + public LiveInfoModel setLevelAnchor(String levelAnchor) { + this.levelAnchor = levelAnchor; + return this; + } + + public String getGame() { + return game; + } + + public LiveInfoModel setGame(String game) { + this.game = game; + return this; + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/SetAttentsModel.java b/common/src/main/java/com/yunbao/common/bean/SetAttentsModel.java new file mode 100644 index 000000000..dec0192b1 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/SetAttentsModel.java @@ -0,0 +1,26 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +/** + * 关注直播 + */ +public class SetAttentsModel extends BaseModel { + + + /** + * isattent : 1 + */ + + @SerializedName("isattent") + private String isattent = ""; + + public String getIsattent() { + return isattent; + } + + public SetAttentsModel setIsattent(String isattent) { + this.isattent = isattent; + return this; + } +} 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 edd482765..cd3a3e3db 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -3,8 +3,10 @@ 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.LiveInfoModel; import com.yunbao.common.bean.NobleTrumpetModel; import com.yunbao.common.bean.SearchModel; +import com.yunbao.common.bean.SetAttentsModel; import java.util.List; @@ -101,4 +103,26 @@ public interface PDLiveApi { Observable> anchorRecommend( @Query("num") String num ); + + /** + * 获取直播间信息 + * + * @param liveuid 主播id + * @return + */ + @GET("/api/public/?service=Live.getLiveInfo") + Observable>> getLiveInfo( + @Query("liveuid") String liveuid + ); + + /** + * 关注主播 + * + * @param liveuid + * @return + */ + @GET("/api/public/?service=User.setAttents") + Observable>> setAttents( + @Query("liveuid") String liveuid + ); } diff --git a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java index e5e5eebd1..e2d273a64 100644 --- a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java @@ -3,13 +3,16 @@ package com.yunbao.common.http.live; import android.content.Context; import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.bean.LiveInfoModel; import com.yunbao.common.bean.NobleTrumpetModel; 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; /** @@ -77,4 +80,34 @@ public class LiveNetManager { //java.lang.IllegalStateException: Fragment LiveInputDialogFragment{229db51} (f38ce923-7a48-4c64-925a-bed0edfb7fa7)} not attached to a context. }).isDisposed(); } + + /** + * 获取直播间信息 + * + * @param liveuid 主播id + * @return + */ + public void getLiveInfo(String liveuid, HttpCallback callback) { + API.get().pdLiveApi(mContext).getLiveInfo(liveuid) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer>>() { + @Override + public void accept(ResponseModel> listResponseModel) throws Exception { + List liveInfoModels = listResponseModel.getData().getInfo(); + if (liveInfoModels.size() > 0) { + LiveInfoModel liveInfoModel = liveInfoModels.get(0); + if (callback != null) + callback.onSuccess(liveInfoModel); + } else { + if (callback != null) + callback.onError("直播已结束"); + } + + } + }, throwable -> { + if (callback != null) + callback.onError(throwable.getMessage()); + }); + } } diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRoomCheckLivePresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRoomCheckLivePresenter.java index a16d52857..0bfe5ac2c 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRoomCheckLivePresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRoomCheckLivePresenter.java @@ -8,15 +8,15 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; -import com.yunbao.live.R; -import com.yunbao.live.bean.LiveBean; import com.yunbao.common.http.HttpCallback; -import com.yunbao.live.http.LiveHttpConsts; -import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.MD5Util; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; +import com.yunbao.live.R; +import com.yunbao.live.bean.LiveBean; +import com.yunbao.live.http.LiveHttpConsts; +import com.yunbao.live.http.LiveHttpUtil; /** * Created by cxf on 2017/9/29. @@ -45,6 +45,8 @@ public class LiveRoomCheckLivePresenter { LiveHttpUtil.checkLive(bean.getUid(), bean.getStream(), mCheckLiveCallback); } + + private HttpCallback mCheckLiveCallback = new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { diff --git a/main/src/main/java/com/yunbao/main/activity/SearchActivity.java b/main/src/main/java/com/yunbao/main/activity/SearchActivity.java index 05caba447..8daa06456 100644 --- a/main/src/main/java/com/yunbao/main/activity/SearchActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/SearchActivity.java @@ -7,18 +7,33 @@ import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.view.View; +import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; +import com.blankj.utilcode.util.GsonUtils; import com.yunbao.common.activity.AbsActivity; +import com.yunbao.common.bean.LiveInfoModel; +import com.yunbao.common.dialog.LoadingDialog; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.SearchHistoryRecordManager; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.RouteUtil; +import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.bean.LiveBean; +import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; import com.yunbao.main.R; +import com.yunbao.main.event.JumpUserHomeEvent; import com.yunbao.main.fragment.SearchRecommendFragment; import com.yunbao.main.fragment.SearchResultsFragment; import com.yunbao.main.utils.WordsTypeUtil; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + /** * Created by cxf on 2018/10/25. @@ -26,6 +41,7 @@ import com.yunbao.main.utils.WordsTypeUtil; public class SearchActivity extends AbsActivity { private EditText mEditText; + private InputMethodManager imm; public static void forward(Context context) { context.startActivity(new Intent(context, SearchActivity.class)); @@ -40,6 +56,8 @@ public class SearchActivity extends AbsActivity { //历史记录 @Override protected void main() { + Bus.getOn(this); + imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); //進入頁面首先展示推薦頁面 SearchRecommendFragment searchRecommendFragment = new SearchRecommendFragment(); FragmentManager manager = getSupportFragmentManager(); @@ -66,6 +84,7 @@ public class SearchActivity extends AbsActivity { @Override protected void onDestroy() { super.onDestroy(); + Bus.getOff(this); } @Override @@ -115,5 +134,44 @@ public class SearchActivity extends AbsActivity { } }; + /** + * 跳转用户首页 + */ + @Subscribe(threadMode = ThreadMode.MAIN) + public void onJumpUserHome(JumpUserHomeEvent event) { + //展示网络请求弹窗 + LoadingDialog fragment = new LoadingDialog(); + fragment.show(getSupportFragmentManager(), "LoadingDialog"); + LiveNetManager.get(mContext) + .getLiveInfo(String.valueOf(event.getModel().getId()), new HttpCallback() { + @Override + public void onSuccess(LiveInfoModel data) { + fragment.dismiss(); + LiveRoomCheckLivePresenter mCheckLivePresenter = new LiveRoomCheckLivePresenter(mContext, (liveBean, liveType, liveTypeVal, liveSdk) -> { + if (liveBean == null) { + return; + } + LiveAudienceActivity.forward(mContext, liveBean, liveType, liveTypeVal, "", 0, liveSdk); + finish(); + }); + //讲数据转成json + String json = GsonUtils.toJson(data); + LiveBean liveBean = GsonUtils.fromJson(json, LiveBean.class); + mCheckLivePresenter.checkLive(liveBean); + } + + @Override + public void onError(String error) { + fragment.dismiss(); + //跳转到个人资料 + if (imm != null && mEditText != null) { + imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0); + RouteUtil.forwardUserHome(mContext, String.valueOf(event.getModel().getId()), 0); + finish(); + } + } + }); + + } } diff --git a/main/src/main/java/com/yunbao/main/event/JumpUserHomeEvent.java b/main/src/main/java/com/yunbao/main/event/JumpUserHomeEvent.java new file mode 100644 index 000000000..ab5a64bf8 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/event/JumpUserHomeEvent.java @@ -0,0 +1,22 @@ +package com.yunbao.main.event; + +import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.bean.SearchModel; + +public class JumpUserHomeEvent extends BaseModel { + //携带用户信息 + private SearchModel model = new SearchModel(); + + public JumpUserHomeEvent(SearchModel model) { + this.model = model; + } + + public SearchModel getModel() { + return model; + } + + public JumpUserHomeEvent setModel(SearchModel model) { + this.model = model; + return this; + } +} diff --git a/main/src/main/java/com/yunbao/main/views/AnchorSearchResultsItemViewHolder.java b/main/src/main/java/com/yunbao/main/views/AnchorSearchResultsItemViewHolder.java index 3691d8f89..5a210d56d 100644 --- a/main/src/main/java/com/yunbao/main/views/AnchorSearchResultsItemViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/AnchorSearchResultsItemViewHolder.java @@ -40,7 +40,7 @@ public class AnchorSearchResultsItemViewHolder extends RecyclerView.ViewHolder { public void showAnchors(List searchModels, int type) { resultsAdapter = new SearchResultsAdapter(); - anchorList.setLayoutManager(new LinearLayoutManager(itemView.getContext(), LinearLayoutManager.VERTICAL, true)); + anchorList.setLayoutManager(new LinearLayoutManager(itemView.getContext(), LinearLayoutManager.VERTICAL, false)); anchorList.setAdapter(resultsAdapter); resultsAdapter.putData(searchModels, type); } diff --git a/main/src/main/java/com/yunbao/main/views/SearchResultsViewHolder.java b/main/src/main/java/com/yunbao/main/views/SearchResultsViewHolder.java index 37e19ea12..8cd66fbac 100644 --- a/main/src/main/java/com/yunbao/main/views/SearchResultsViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/SearchResultsViewHolder.java @@ -3,6 +3,8 @@ package com.yunbao.main.views; import android.text.TextUtils; import android.view.View; import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -12,11 +14,16 @@ import com.yunbao.common.CommonAppConfig; import com.yunbao.common.bean.LevelBean; import com.yunbao.common.bean.SearchModel; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.utils.Bus; import com.yunbao.main.R; +import com.yunbao.main.event.JumpUserHomeEvent; public class SearchResultsViewHolder extends RecyclerView.ViewHolder { private ImageView avatar, isLive, sex, focusOn, contribute; private TextView nickName; + private LinearLayout nickLayout; + private RelativeLayout avatarLayout; + private SearchModel model; public SearchResultsViewHolder(@NonNull View itemView) { super(itemView); @@ -26,9 +33,14 @@ public class SearchResultsViewHolder extends RecyclerView.ViewHolder { focusOn = itemView.findViewById(R.id.focus_on); nickName = itemView.findViewById(R.id.nick_name); contribute = itemView.findViewById(R.id.contribute); + nickLayout = itemView.findViewById(R.id.nick_layout); + avatarLayout = itemView.findViewById(R.id.avatar_layout); + nickLayout.setOnClickListener(jumpUserHome); + avatarLayout.setOnClickListener(jumpUserHome); } public void showData(SearchModel model, int type) { + this.model = model; ImgLoader.displayAvatar(itemView.getContext(), model.getAvatar(), avatar); //用戶直接隱藏 if (type == 3) { @@ -53,4 +65,14 @@ public class SearchResultsViewHolder extends RecyclerView.ViewHolder { nickName.setText(model.getUserNicename()); focusOn.setVisibility(TextUtils.equals(model.getIsattention(), "1") ? View.GONE : View.VISIBLE); } + + /** + * 跳转点击用户主页 + */ + View.OnClickListener jumpUserHome = new View.OnClickListener() { + @Override + public void onClick(View v) { + Bus.get().post(new JumpUserHomeEvent(model)); + } + }; } diff --git a/main/src/main/java/com/yunbao/main/views/UserSearchResultsItemViewHolder.java b/main/src/main/java/com/yunbao/main/views/UserSearchResultsItemViewHolder.java index 77acee558..6d9cd108b 100644 --- a/main/src/main/java/com/yunbao/main/views/UserSearchResultsItemViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/UserSearchResultsItemViewHolder.java @@ -40,13 +40,14 @@ public class UserSearchResultsItemViewHolder extends RecyclerView.ViewHolder { public void showAnchors(List searchModels, int type) { resultsAdapter = new SearchResultsAdapter(); - anchorList.setLayoutManager(new LinearLayoutManager(itemView.getContext(), LinearLayoutManager.VERTICAL, true)); + anchorList.setLayoutManager(new LinearLayoutManager(itemView.getContext(), LinearLayoutManager.VERTICAL, false)); anchorList.setAdapter(resultsAdapter); resultsAdapter.putData(searchModels, type); //滾動到頂部 anchorList.smoothScrollToPosition(0); } - public void hideTypeTitle(){ + + public void hideTypeTitle() { typeTitle.setVisibility(View.GONE); } } diff --git a/main/src/main/res/layout/view_search_results_item_holder.xml b/main/src/main/res/layout/view_search_results_item_holder.xml index 871b3ebdc..2cc5c43de 100644 --- a/main/src/main/res/layout/view_search_results_item_holder.xml +++ b/main/src/main/res/layout/view_search_results_item_holder.xml @@ -6,6 +6,7 @@ android:paddingTop="10dp"> @@ -23,6 +24,7 @@