历史检索记录完善

This commit is contained in:
18401019693 2022-08-08 10:26:45 +08:00
parent 90bc939a61
commit 76a0d9ec8c
5 changed files with 63 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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

View File

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