From 76a0d9ec8c1c78da38ea9a8832fb03d8d4ff37f9 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Mon, 8 Aug 2022 10:26:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=86=E5=8F=B2=E6=A3=80=E7=B4=A2=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/SearchHistoryRecordManager.java | 3 +++ .../yunbao/main/activity/SearchActivity.java | 12 ++++++++++ .../main/adapter/SearchRecommendAdapter.java | 15 +++++++++---- .../main/adapter/SearchResultsAdapter.java | 18 +++++++++++++-- .../views/SearchRecommendHeardViewHolder.java | 22 ++++++++++++++++++- 5 files changed, 63 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/manager/SearchHistoryRecordManager.java b/common/src/main/java/com/yunbao/common/manager/SearchHistoryRecordManager.java index 5f63d25a9..de343138c 100644 --- a/common/src/main/java/com/yunbao/common/manager/SearchHistoryRecordManager.java +++ b/common/src/main/java/com/yunbao/common/manager/SearchHistoryRecordManager.java @@ -78,6 +78,9 @@ public class SearchHistoryRecordManager extends BaseCacheManager { if (historyRecordList.size() == 10) { historyRecordList.remove(0); } + for (SearchHistoryModel historyModel : historyRecordList) { + if (historyModel.getSimplified().equals(key)) return; + } historyRecordList.add(new SearchHistoryModel(key, value)); String json = new Gson().toJson(historyRecordList); put(KEY_HISTORY_RECORD, json); 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 8daa06456..233b56f17 100644 --- a/main/src/main/java/com/yunbao/main/activity/SearchActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/SearchActivity.java @@ -85,6 +85,13 @@ public class SearchActivity extends AbsActivity { protected void onDestroy() { super.onDestroy(); Bus.getOff(this); + //检索关键字 + String searchKey = mEditText.getText().toString().trim(); + if (!TextUtils.isEmpty(searchKey)) { + + //保存检索历史记录 + SearchHistoryRecordManager.get(mContext).addHistoryRecord(WordsTypeUtil.changeSimplified(searchKey), WordsTypeUtil.changeTraditional(searchKey)); + } } @Override @@ -174,4 +181,9 @@ public class SearchActivity extends AbsActivity { } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onChip(String chip) { + mEditText.setText(chip); + } + } diff --git a/main/src/main/java/com/yunbao/main/adapter/SearchRecommendAdapter.java b/main/src/main/java/com/yunbao/main/adapter/SearchRecommendAdapter.java index 022b3ad61..d6b162c4c 100644 --- a/main/src/main/java/com/yunbao/main/adapter/SearchRecommendAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/SearchRecommendAdapter.java @@ -9,6 +9,7 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.yunbao.common.bean.SearchRecommendModel; +import com.yunbao.common.utils.Bus; import com.yunbao.main.R; import com.yunbao.main.views.SearchRecommendBodyViewHolder; import com.yunbao.main.views.SearchRecommendHeardViewHolder; @@ -47,6 +48,12 @@ public class SearchRecommendAdapter extends RecyclerView.Adapter { if (holder instanceof SearchRecommendHeardViewHolder) { SearchRecommendHeardViewHolder heardViewHolder = (SearchRecommendHeardViewHolder) holder; heardViewHolder.setHistory(recommendModels.get(position).getHistoryRecordMap()); + heardViewHolder.setCallBack(new SearchRecommendHeardViewHolder.SearchRecommendHeardCallBack() { + @Override + public void onChipClick(String chip) { + Bus.get().post(chip); + } + }); } else { SearchRecommendBodyViewHolder bodyViewHolder = (SearchRecommendBodyViewHolder) holder; bodyViewHolder.showData(recommendModels.get(position).getList()); @@ -60,11 +67,11 @@ public class SearchRecommendAdapter extends RecyclerView.Adapter { @Override public int getItemViewType(int position) { - if (recommendModels.size() == 1 && recommendModels.get(position).getHistoryRecordMap().size() == 0){ + if (recommendModels.size() == 1 && recommendModels.get(position).getHistoryRecordMap().size() == 0) { return BODY; - }else { - if (position == 0 ) { - return HEAD; + } else { + if (position == 0) { + return HEAD; } else { return BODY; } 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 1ecf3b6c6..fa80f250a 100644 --- a/main/src/main/java/com/yunbao/main/adapter/SearchResultsAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/SearchResultsAdapter.java @@ -6,12 +6,15 @@ import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; +import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import com.yunbao.common.bean.SearchModel; import com.yunbao.common.bean.SetAttentsModel; +import com.yunbao.common.dialog.LoadingDialog; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.main.R; import com.yunbao.main.views.SearchResultsViewHolder; @@ -36,21 +39,32 @@ public class SearchResultsAdapter extends RecyclerView.Adapter { @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { 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) { + LoadingDialog fragment = new LoadingDialog(); + fragment.show(((FragmentActivity) context).getSupportFragmentManager(), "LoadingDialog"); LiveNetManager.get(context) .setAttents(String.valueOf(model.getId()), new HttpCallback() { @Override public void onSuccess(SetAttentsModel data) { - + for (SearchModel searchModel : searchModels) { + if (searchModel.getId() == model.getId()) { + searchModel.setIsattention(data.getIsattent()); + } + } + notifyDataSetChanged(); + fragment.dismiss(); } @Override public void onError(String error) { - + ToastUtil.show(error); + fragment.dismiss(); } }); } diff --git a/main/src/main/java/com/yunbao/main/views/SearchRecommendHeardViewHolder.java b/main/src/main/java/com/yunbao/main/views/SearchRecommendHeardViewHolder.java index 2d966669e..0fa606dfa 100644 --- a/main/src/main/java/com/yunbao/main/views/SearchRecommendHeardViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/SearchRecommendHeardViewHolder.java @@ -6,7 +6,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -50,7 +49,28 @@ public class SearchRecommendHeardViewHolder extends RecyclerView.ViewHolder { chip.setBackgroundResource(R.drawable.background_search_chip); chip.setLayoutParams(layoutParams); searchHistory.addView(chip, layoutParams); + chip.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (callBack != null) { + callBack.onChipClick(chip.getText().toString()); + } + } + }); } } + /** + * 检索历史记录 + */ + public interface SearchRecommendHeardCallBack { + void onChipClick(String chip); + } + + private SearchRecommendHeardCallBack callBack; + + public SearchRecommendHeardViewHolder setCallBack(SearchRecommendHeardCallBack callBack) { + this.callBack = callBack; + return this; + } }