历史检索记录完善
This commit is contained in:
parent
90bc939a61
commit
76a0d9ec8c
@ -78,6 +78,9 @@ public class SearchHistoryRecordManager extends BaseCacheManager {
|
|||||||
if (historyRecordList.size() == 10) {
|
if (historyRecordList.size() == 10) {
|
||||||
historyRecordList.remove(0);
|
historyRecordList.remove(0);
|
||||||
}
|
}
|
||||||
|
for (SearchHistoryModel historyModel : historyRecordList) {
|
||||||
|
if (historyModel.getSimplified().equals(key)) return;
|
||||||
|
}
|
||||||
historyRecordList.add(new SearchHistoryModel(key, value));
|
historyRecordList.add(new SearchHistoryModel(key, value));
|
||||||
String json = new Gson().toJson(historyRecordList);
|
String json = new Gson().toJson(historyRecordList);
|
||||||
put(KEY_HISTORY_RECORD, json);
|
put(KEY_HISTORY_RECORD, json);
|
||||||
|
@ -85,6 +85,13 @@ public class SearchActivity extends AbsActivity {
|
|||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
Bus.getOff(this);
|
Bus.getOff(this);
|
||||||
|
//检索关键字
|
||||||
|
String searchKey = mEditText.getText().toString().trim();
|
||||||
|
if (!TextUtils.isEmpty(searchKey)) {
|
||||||
|
|
||||||
|
//保存检索历史记录
|
||||||
|
SearchHistoryRecordManager.get(mContext).addHistoryRecord(WordsTypeUtil.changeSimplified(searchKey), WordsTypeUtil.changeTraditional(searchKey));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -174,4 +181,9 @@ public class SearchActivity extends AbsActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
public void onChip(String chip) {
|
||||||
|
mEditText.setText(chip);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.yunbao.common.bean.SearchRecommendModel;
|
import com.yunbao.common.bean.SearchRecommendModel;
|
||||||
|
import com.yunbao.common.utils.Bus;
|
||||||
import com.yunbao.main.R;
|
import com.yunbao.main.R;
|
||||||
import com.yunbao.main.views.SearchRecommendBodyViewHolder;
|
import com.yunbao.main.views.SearchRecommendBodyViewHolder;
|
||||||
import com.yunbao.main.views.SearchRecommendHeardViewHolder;
|
import com.yunbao.main.views.SearchRecommendHeardViewHolder;
|
||||||
@ -47,6 +48,12 @@ public class SearchRecommendAdapter extends RecyclerView.Adapter {
|
|||||||
if (holder instanceof SearchRecommendHeardViewHolder) {
|
if (holder instanceof SearchRecommendHeardViewHolder) {
|
||||||
SearchRecommendHeardViewHolder heardViewHolder = (SearchRecommendHeardViewHolder) holder;
|
SearchRecommendHeardViewHolder heardViewHolder = (SearchRecommendHeardViewHolder) holder;
|
||||||
heardViewHolder.setHistory(recommendModels.get(position).getHistoryRecordMap());
|
heardViewHolder.setHistory(recommendModels.get(position).getHistoryRecordMap());
|
||||||
|
heardViewHolder.setCallBack(new SearchRecommendHeardViewHolder.SearchRecommendHeardCallBack() {
|
||||||
|
@Override
|
||||||
|
public void onChipClick(String chip) {
|
||||||
|
Bus.get().post(chip);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
SearchRecommendBodyViewHolder bodyViewHolder = (SearchRecommendBodyViewHolder) holder;
|
SearchRecommendBodyViewHolder bodyViewHolder = (SearchRecommendBodyViewHolder) holder;
|
||||||
bodyViewHolder.showData(recommendModels.get(position).getList());
|
bodyViewHolder.showData(recommendModels.get(position).getList());
|
||||||
@ -60,10 +67,10 @@ public class SearchRecommendAdapter extends RecyclerView.Adapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
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;
|
return BODY;
|
||||||
}else {
|
} else {
|
||||||
if (position == 0 ) {
|
if (position == 0) {
|
||||||
return HEAD;
|
return HEAD;
|
||||||
} else {
|
} else {
|
||||||
return BODY;
|
return BODY;
|
||||||
|
@ -6,12 +6,15 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.yunbao.common.bean.SearchModel;
|
import com.yunbao.common.bean.SearchModel;
|
||||||
import com.yunbao.common.bean.SetAttentsModel;
|
import com.yunbao.common.bean.SetAttentsModel;
|
||||||
|
import com.yunbao.common.dialog.LoadingDialog;
|
||||||
import com.yunbao.common.http.base.HttpCallback;
|
import com.yunbao.common.http.base.HttpCallback;
|
||||||
import com.yunbao.common.http.live.LiveNetManager;
|
import com.yunbao.common.http.live.LiveNetManager;
|
||||||
|
import com.yunbao.common.utils.ToastUtil;
|
||||||
import com.yunbao.main.R;
|
import com.yunbao.main.R;
|
||||||
import com.yunbao.main.views.SearchResultsViewHolder;
|
import com.yunbao.main.views.SearchResultsViewHolder;
|
||||||
|
|
||||||
@ -36,21 +39,32 @@ public class SearchResultsAdapter extends RecyclerView.Adapter {
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||||
if (holder instanceof SearchResultsViewHolder) {
|
if (holder instanceof SearchResultsViewHolder) {
|
||||||
|
//展示网络请求弹窗
|
||||||
|
|
||||||
SearchResultsViewHolder resultsViewHolder = (SearchResultsViewHolder) holder;
|
SearchResultsViewHolder resultsViewHolder = (SearchResultsViewHolder) holder;
|
||||||
resultsViewHolder.showData(searchModels.get(position), type);
|
resultsViewHolder.showData(searchModels.get(position), type);
|
||||||
resultsViewHolder.setCallback(new SearchResultsViewHolder.SearchResultsCallback() {
|
resultsViewHolder.setCallback(new SearchResultsViewHolder.SearchResultsCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void focusOn(SearchModel model) {
|
public void focusOn(SearchModel model) {
|
||||||
|
LoadingDialog fragment = new LoadingDialog();
|
||||||
|
fragment.show(((FragmentActivity) context).getSupportFragmentManager(), "LoadingDialog");
|
||||||
LiveNetManager.get(context)
|
LiveNetManager.get(context)
|
||||||
.setAttents(String.valueOf(model.getId()), new HttpCallback<SetAttentsModel>() {
|
.setAttents(String.valueOf(model.getId()), new HttpCallback<SetAttentsModel>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(SetAttentsModel data) {
|
public void onSuccess(SetAttentsModel data) {
|
||||||
|
for (SearchModel searchModel : searchModels) {
|
||||||
|
if (searchModel.getId() == model.getId()) {
|
||||||
|
searchModel.setIsattention(data.getIsattent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notifyDataSetChanged();
|
||||||
|
fragment.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(String error) {
|
public void onError(String error) {
|
||||||
|
ToastUtil.show(error);
|
||||||
|
fragment.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -50,7 +49,28 @@ public class SearchRecommendHeardViewHolder extends RecyclerView.ViewHolder {
|
|||||||
chip.setBackgroundResource(R.drawable.background_search_chip);
|
chip.setBackgroundResource(R.drawable.background_search_chip);
|
||||||
chip.setLayoutParams(layoutParams);
|
chip.setLayoutParams(layoutParams);
|
||||||
searchHistory.addView(chip, 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user