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 cd3a3e3db..f7cff9fae 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -123,6 +123,6 @@ public interface PDLiveApi { */ @GET("/api/public/?service=User.setAttents") Observable>> setAttents( - @Query("liveuid") String liveuid + @Query("touid") 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 e2d273a64..12e727bbd 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 @@ -5,6 +5,7 @@ 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.bean.SetAttentsModel; import com.yunbao.common.http.API; import com.yunbao.common.http.ResponseModel; import com.yunbao.common.http.base.HttpCallback; @@ -91,23 +92,48 @@ public class LiveNetManager { 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("直播已结束"); - } - + .subscribe(listResponseModel -> { + 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()); - }); + }).isDisposed(); + } + + /** + * 关注主播 + * + * @param liveuid + * @return + */ + public void setAttents(String liveuid, HttpCallback callback) { + API.get().pdLiveApi(mContext).setAttents(liveuid) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(listResponseModel -> { + List setAttentsModels = listResponseModel.getData().getInfo(); + if (setAttentsModels.size() > 0) { + if (callback != null) + callback.onSuccess(setAttentsModels.get(0)); + } else { + if (callback != null) + callback.onError("操作失效"); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) + callback.onError(throwable.getMessage()); + } + }).isDisposed(); } } diff --git a/main/src/main/java/com/yunbao/main/adapter/SearchResultsAdapter.java b/main/src/main/java/com/yunbao/main/adapter/SearchResultsAdapter.java index 87bbe7a87..1ecf3b6c6 100644 --- a/main/src/main/java/com/yunbao/main/adapter/SearchResultsAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/SearchResultsAdapter.java @@ -1,5 +1,6 @@ package com.yunbao.main.adapter; +import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -8,6 +9,9 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.yunbao.common.bean.SearchModel; +import com.yunbao.common.bean.SetAttentsModel; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.main.R; import com.yunbao.main.views.SearchResultsViewHolder; @@ -17,6 +21,11 @@ import java.util.List; public class SearchResultsAdapter extends RecyclerView.Adapter { private List searchModels = new ArrayList<>(); private int type = -1; + private Context context; + + public SearchResultsAdapter(Context context) { + this.context = context; + } @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -29,6 +38,23 @@ public class SearchResultsAdapter extends RecyclerView.Adapter { if (holder instanceof SearchResultsViewHolder) { SearchResultsViewHolder resultsViewHolder = (SearchResultsViewHolder) holder; resultsViewHolder.showData(searchModels.get(position), type); + resultsViewHolder.setCallback(new SearchResultsViewHolder.SearchResultsCallback() { + @Override + public void focusOn(SearchModel model) { + LiveNetManager.get(context) + .setAttents(String.valueOf(model.getId()), new HttpCallback() { + @Override + public void onSuccess(SetAttentsModel data) { + + } + + @Override + public void onError(String error) { + + } + }); + } + }); } } 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 5a210d56d..78580216e 100644 --- a/main/src/main/java/com/yunbao/main/views/AnchorSearchResultsItemViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/AnchorSearchResultsItemViewHolder.java @@ -24,6 +24,7 @@ public class AnchorSearchResultsItemViewHolder extends RecyclerView.ViewHolder { private TextView anchorMore; private SearchResultsAdapter resultsAdapter; private FrameLayout typeTitle; + private List searchModels; public AnchorSearchResultsItemViewHolder(@NonNull View itemView) { super(itemView); @@ -39,13 +40,14 @@ public class AnchorSearchResultsItemViewHolder extends RecyclerView.ViewHolder { } public void showAnchors(List searchModels, int type) { - resultsAdapter = new SearchResultsAdapter(); + this.searchModels = searchModels; + resultsAdapter = new SearchResultsAdapter(itemView.getContext()); anchorList.setLayoutManager(new LinearLayoutManager(itemView.getContext(), LinearLayoutManager.VERTICAL, false)); anchorList.setAdapter(resultsAdapter); resultsAdapter.putData(searchModels, type); } - public void hideTypeTitle(){ + public void hideTypeTitle() { typeTitle.setVisibility(View.GONE); } } 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 8cd66fbac..077e902e5 100644 --- a/main/src/main/java/com/yunbao/main/views/SearchResultsViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/SearchResultsViewHolder.java @@ -24,6 +24,12 @@ public class SearchResultsViewHolder extends RecyclerView.ViewHolder { private LinearLayout nickLayout; private RelativeLayout avatarLayout; private SearchModel model; + private SearchResultsCallback callback; + + public SearchResultsViewHolder setCallback(SearchResultsCallback callback) { + this.callback = callback; + return this; + } public SearchResultsViewHolder(@NonNull View itemView) { super(itemView); @@ -37,6 +43,12 @@ public class SearchResultsViewHolder extends RecyclerView.ViewHolder { avatarLayout = itemView.findViewById(R.id.avatar_layout); nickLayout.setOnClickListener(jumpUserHome); avatarLayout.setOnClickListener(jumpUserHome); + //关注主播或者用户 + itemView.findViewById(R.id.focus_on).setOnClickListener(v -> { + if (callback != null) { + callback.focusOn(model); + } + }); } public void showData(SearchModel model, int type) { @@ -75,4 +87,8 @@ public class SearchResultsViewHolder extends RecyclerView.ViewHolder { Bus.get().post(new JumpUserHomeEvent(model)); } }; + + public interface SearchResultsCallback { + void focusOn(SearchModel 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 6d9cd108b..31508e64b 100644 --- a/main/src/main/java/com/yunbao/main/views/UserSearchResultsItemViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/UserSearchResultsItemViewHolder.java @@ -39,7 +39,7 @@ public class UserSearchResultsItemViewHolder extends RecyclerView.ViewHolder { } public void showAnchors(List searchModels, int type) { - resultsAdapter = new SearchResultsAdapter(); + resultsAdapter = new SearchResultsAdapter(itemView.getContext()); anchorList.setLayoutManager(new LinearLayoutManager(itemView.getContext(), LinearLayoutManager.VERTICAL, false)); anchorList.setAdapter(resultsAdapter); resultsAdapter.putData(searchModels, type);