From e96d0e7bf41f0592cd55520fd3a45e624c5ae398 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Wed, 10 Aug 2022 13:40:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95=E9=97=AE?= =?UTF-8?q?=E9=A2=98,shouye=20ytuijian?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/main/activity/MainActivity.java | 4 ++-- .../main/adapter/SearchResultsAdapter.java | 6 ++++-- .../main/adapter/SearchResultsItemAdapter.java | 11 +++++++---- .../fragment/SearchResultsItemFragment.java | 8 ++++---- .../AnchorSearchResultsItemViewHolder.java | 4 ++-- .../com/yunbao/main/views/FloatBannerView.java | 2 +- .../main/views/SearchResultsViewHolder.java | 17 ++++++++++++++--- .../views/UserSearchResultsItemViewHolder.java | 4 ++-- 8 files changed, 36 insertions(+), 20 deletions(-) diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index 8fa871a42..9035e078b 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -368,7 +368,6 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene mViewPager.setCurrentItem(0); mTabButtonGroup.setCurPosition(0); isInstructor(); - initAnchorRecommendBanner(); findViewById(R.id.banner_click).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -406,6 +405,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene if (index==0){ floatBanner.setVisibility(View.VISIBLE); findViewById(R.id.banner_click).setVisibility(View.VISIBLE); + initAnchorRecommendBanner(); }else { floatBanner.setVisibility(View.GONE); findViewById(R.id.banner_click).setVisibility(View.GONE); @@ -675,7 +675,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene //获取指导员引导逻辑 NoviceInstructorManager.get(mContext).getNoviceInstructor(); NoviceInstructorManager.get(mContext).checktHomeZdyPop(); - + initAnchorRecommendBanner(); } 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 fa80f250a..11bd9614c 100644 --- a/main/src/main/java/com/yunbao/main/adapter/SearchResultsAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/SearchResultsAdapter.java @@ -25,6 +25,7 @@ public class SearchResultsAdapter extends RecyclerView.Adapter { private List searchModels = new ArrayList<>(); private int type = -1; private Context context; + private String searchKey; public SearchResultsAdapter(Context context) { this.context = context; @@ -42,7 +43,7 @@ public class SearchResultsAdapter extends RecyclerView.Adapter { //展示网络请求弹窗 SearchResultsViewHolder resultsViewHolder = (SearchResultsViewHolder) holder; - resultsViewHolder.showData(searchModels.get(position), type); + resultsViewHolder.showData(searchModels.get(position), type,searchKey); resultsViewHolder.setCallback(new SearchResultsViewHolder.SearchResultsCallback() { @Override public void focusOn(SearchModel model) { @@ -82,7 +83,8 @@ public class SearchResultsAdapter extends RecyclerView.Adapter { * * @param models */ - public void putData(List models, int type) { + public void putData(List models, int type, String searchKey) { + this.searchKey = searchKey; this.type = type; searchModels.clear(); searchModels.addAll(models); diff --git a/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java b/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java index 39f1910f9..a9af179c2 100644 --- a/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java @@ -24,6 +24,7 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { private int type = -1; //确定是不是全部展示列表 private boolean isAll = true; + private String searchKey = ""; @NonNull @Override @@ -42,13 +43,13 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof AnchorSearchResultsItemViewHolder) { AnchorSearchResultsItemViewHolder itemViewHolder = (AnchorSearchResultsItemViewHolder) holder; - itemViewHolder.showAnchors(lists.get(position), ANCHOR); + itemViewHolder.showAnchors(lists.get(position), ANCHOR,searchKey); if (type != 1 && !isAll) { itemViewHolder.hideTypeTitle(); } } else { UserSearchResultsItemViewHolder viewHolder = (UserSearchResultsItemViewHolder) holder; - viewHolder.showAnchors(lists.get(position), USER); + viewHolder.showAnchors(lists.get(position), USER,searchKey); if (type != 1 && !isAll) { viewHolder.hideTypeTitle(); } @@ -78,7 +79,8 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { * @param mLists 數據源 * @param type */ - public void showData(List> mLists, int type) { + public void showData(List> mLists, int type,String searchKey) { + this.searchKey = searchKey; this.type = type; //展示全部列表在只展示用户或者主播的一个判断,服务器在查全部的时候会返回两个集合没数据也会展示一个空集合 if (mLists.size() > 1) { @@ -104,7 +106,8 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { /** * 加载更多资源 */ - public void onLoadMoreData(List> mLists) { + public void onLoadMoreData(List> mLists,String searchKey) { + this.searchKey = searchKey; lists.addAll(mLists); notifyDataSetChanged(); } diff --git a/main/src/main/java/com/yunbao/main/fragment/SearchResultsItemFragment.java b/main/src/main/java/com/yunbao/main/fragment/SearchResultsItemFragment.java index 24c0b8390..f08359fbe 100644 --- a/main/src/main/java/com/yunbao/main/fragment/SearchResultsItemFragment.java +++ b/main/src/main/java/com/yunbao/main/fragment/SearchResultsItemFragment.java @@ -83,9 +83,9 @@ public class SearchResultsItemFragment extends BaseFragment { public void onSuccess(List> data) { fragment.dismiss(); if (page > 1) { - itemAdapter.onLoadMoreData(data); + itemAdapter.onLoadMoreData(data,searchKey); } else { - itemAdapter.showData(data, type); + itemAdapter.showData(data, type,searchKey); } } @@ -109,9 +109,9 @@ public class SearchResultsItemFragment extends BaseFragment { List> listList = new ArrayList<>(); listList.add(data); if (page > 1) { - itemAdapter.onLoadMoreData(listList); + itemAdapter.onLoadMoreData(listList,searchKey); } else { - itemAdapter.showData(listList, type); + itemAdapter.showData(listList, type,searchKey); } } 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 78580216e..7e83e2cbd 100644 --- a/main/src/main/java/com/yunbao/main/views/AnchorSearchResultsItemViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/AnchorSearchResultsItemViewHolder.java @@ -39,12 +39,12 @@ public class AnchorSearchResultsItemViewHolder extends RecyclerView.ViewHolder { }); } - public void showAnchors(List searchModels, int type) { + public void showAnchors(List searchModels, int type, String searchKey) { this.searchModels = searchModels; resultsAdapter = new SearchResultsAdapter(itemView.getContext()); anchorList.setLayoutManager(new LinearLayoutManager(itemView.getContext(), LinearLayoutManager.VERTICAL, false)); anchorList.setAdapter(resultsAdapter); - resultsAdapter.putData(searchModels, type); + resultsAdapter.putData(searchModels, type,searchKey ); } public void hideTypeTitle() { diff --git a/main/src/main/java/com/yunbao/main/views/FloatBannerView.java b/main/src/main/java/com/yunbao/main/views/FloatBannerView.java index b7c15abb8..cc7478b03 100644 --- a/main/src/main/java/com/yunbao/main/views/FloatBannerView.java +++ b/main/src/main/java/com/yunbao/main/views/FloatBannerView.java @@ -71,7 +71,7 @@ public class FloatBannerView extends FrameLayout { */ public void showBanner(List mList) { list.clear(); - list.addAll(mList); + list.addAll(mList);release(); bannerHandler.post(mFlipRunnable); } 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 077e902e5..3481e5f9b 100644 --- a/main/src/main/java/com/yunbao/main/views/SearchResultsViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/SearchResultsViewHolder.java @@ -1,5 +1,7 @@ package com.yunbao.main.views; +import android.text.Html; +import android.text.Spanned; import android.text.TextUtils; import android.view.View; import android.widget.ImageView; @@ -25,6 +27,7 @@ public class SearchResultsViewHolder extends RecyclerView.ViewHolder { private RelativeLayout avatarLayout; private SearchModel model; private SearchResultsCallback callback; + private String searchKey = ""; public SearchResultsViewHolder setCallback(SearchResultsCallback callback) { this.callback = callback; @@ -51,7 +54,7 @@ public class SearchResultsViewHolder extends RecyclerView.ViewHolder { }); } - public void showData(SearchModel model, int type) { + public void showData(SearchModel model, int type, String searchKey) { this.model = model; ImgLoader.displayAvatar(itemView.getContext(), model.getAvatar(), avatar); //用戶直接隱藏 @@ -66,7 +69,7 @@ public class SearchResultsViewHolder extends RecyclerView.ViewHolder { if (anchorLevelBean != null) { ImgLoader.display(isLive.getContext(), CommonAppConfig.getInstance().HOST + anchorLevelBean.getThumb(), contribute); } - isLive.setVisibility(model.getIslive() == 0 ? View.VISIBLE : View.GONE); + isLive.setVisibility(model.getIslive() == 0 ? View.GONE : View.VISIBLE); } if (model.getSex() == 2) { @@ -74,7 +77,7 @@ public class SearchResultsViewHolder extends RecyclerView.ViewHolder { } else { ImgLoader.displayAvatar(itemView.getContext(), R.mipmap.icon_sex_male_1, sex); } - nickName.setText(model.getUserNicename()); + nickName.setText(userNicenamehighlight(model.getUserNicename(),searchKey)); focusOn.setVisibility(TextUtils.equals(model.getIsattention(), "1") ? View.GONE : View.VISIBLE); } @@ -91,4 +94,12 @@ public class SearchResultsViewHolder extends RecyclerView.ViewHolder { public interface SearchResultsCallback { void focusOn(SearchModel model); } + + private Spanned userNicenamehighlight(String context, String keyword) { + String keywordHtml = "" + keyword + ""; + String contextHtml = "" + context + ""; + contextHtml = contextHtml.replace(keyword, keywordHtml); + return Html.fromHtml(contextHtml); + } + } 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 31508e64b..34715656f 100644 --- a/main/src/main/java/com/yunbao/main/views/UserSearchResultsItemViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/UserSearchResultsItemViewHolder.java @@ -38,11 +38,11 @@ public class UserSearchResultsItemViewHolder extends RecyclerView.ViewHolder { }); } - public void showAnchors(List searchModels, int type) { + public void showAnchors(List searchModels, int type, String searchKey) { resultsAdapter = new SearchResultsAdapter(itemView.getContext()); anchorList.setLayoutManager(new LinearLayoutManager(itemView.getContext(), LinearLayoutManager.VERTICAL, false)); anchorList.setAdapter(resultsAdapter); - resultsAdapter.putData(searchModels, type); + resultsAdapter.putData(searchModels, type,searchKey); //滾動到頂部 anchorList.smoothScrollToPosition(0); }