关注主播

This commit is contained in:
18401019693 2022-08-06 18:18:48 +08:00
parent ae9f15d963
commit 43133e503d
11 changed files with 497 additions and 7 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<ResponseModel<AnchorRecommendModel>> anchorRecommend(
@Query("num") String num
);
/**
* 获取直播间信息
*
* @param liveuid 主播id
* @return
*/
@GET("/api/public/?service=Live.getLiveInfo")
Observable<ResponseModel<List<LiveInfoModel>>> getLiveInfo(
@Query("liveuid") String liveuid
);
/**
* 关注主播
*
* @param liveuid
* @return
*/
@GET("/api/public/?service=User.setAttents")
Observable<ResponseModel<List<SetAttentsModel>>> setAttents(
@Query("liveuid") String liveuid
);
}

View File

@ -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<LiveInfoModel> callback) {
API.get().pdLiveApi(mContext).getLiveInfo(liveuid)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ResponseModel<List<LiveInfoModel>>>() {
@Override
public void accept(ResponseModel<List<LiveInfoModel>> listResponseModel) throws Exception {
List<LiveInfoModel> 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());
});
}
}

View File

@ -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) {

View File

@ -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<LiveInfoModel>() {
@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();
}
}
});
}
}

View File

@ -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;
}
}

View File

@ -40,7 +40,7 @@ public class AnchorSearchResultsItemViewHolder extends RecyclerView.ViewHolder {
public void showAnchors(List<SearchModel> 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);
}

View File

@ -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));
}
};
}

View File

@ -40,13 +40,14 @@ public class UserSearchResultsItemViewHolder extends RecyclerView.ViewHolder {
public void showAnchors(List<SearchModel> 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);
}
}

View File

@ -6,6 +6,7 @@
android:paddingTop="10dp">
<RelativeLayout
android:id="@+id/avatar_layout"
android:layout_width="60dp"
android:layout_height="60dp">
@ -23,6 +24,7 @@
</RelativeLayout>
<LinearLayout
android:id="@+id/nick_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"