From 32ebfa719dd8a7c4d9370294564888e798093225 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Wed, 27 Sep 2023 17:08:14 +0800 Subject: [PATCH] =?UTF-8?q?sud=E6=B8=B8=E6=88=8F=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=BC=98=E5=8C=96=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dialog/SudGameSearchDialogPopup.java | 110 ++++++++++++------ .../com/yunbao/common}/views/FlowLayout.java | 2 +- .../drawable/bg_item_home_search_history.xml | 1 + .../res/drawable/bg_item_search_history.xml | 1 + .../layout/dialog_home_search_sud_game.xml | 9 +- .../res/layout/dialog_search_sud_game.xml | 6 + .../views/SearchRecommendHeardViewHolder.java | 1 + .../layout/view_search_recommend_heard.xml | 2 +- 8 files changed, 96 insertions(+), 36 deletions(-) rename {main/src/main/java/com/yunbao/main => common/src/main/java/com/yunbao/common}/views/FlowLayout.java (99%) diff --git a/common/src/main/java/com/yunbao/common/dialog/SudGameSearchDialogPopup.java b/common/src/main/java/com/yunbao/common/dialog/SudGameSearchDialogPopup.java index cad8083f9..41909b57b 100644 --- a/common/src/main/java/com/yunbao/common/dialog/SudGameSearchDialogPopup.java +++ b/common/src/main/java/com/yunbao/common/dialog/SudGameSearchDialogPopup.java @@ -1,29 +1,33 @@ package com.yunbao.common.dialog; import android.content.Context; +import android.graphics.Color; import android.text.Editable; +import android.text.TextUtils; import android.text.TextWatcher; +import android.util.TypedValue; import android.view.View; +import android.view.ViewGroup; import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.alibaba.fastjson.JSONArray; import com.lxj.xpopup.XPopup; import com.yunbao.common.R; -import com.yunbao.common.adapter.SudGameSearchHistoryListAdapter; import com.yunbao.common.adapter.SudHomeGameListAdapter; import com.yunbao.common.bean.CreateSudRoomModel; import com.yunbao.common.bean.SudRoomListModel; import com.yunbao.common.event.SudRoomListModelEvent; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; -import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.utils.SpUtil; import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.views.FlowLayout; import com.yunbao.common.views.LiveSudGamePopup; import com.yunbao.common.views.weight.ViewClicksAntiShake; @@ -36,10 +40,10 @@ import java.util.List; public class SudGameSearchDialogPopup extends AbsDialogPopupWindow { private static final String SP_HISTORY = "sud_game_search_history"; private EditText editSearch; - private RecyclerView listHistory, listRoom; + private RecyclerView listRoom;//listHistory, ; private View history; - - private SudGameSearchHistoryListAdapter historyListAdapter; + private FlowLayout searchHistory; + // private SudGameSearchHistoryListAdapter historyListAdapter; private SudHomeGameListAdapter sudGameListAdapter; private boolean isHome = false; @@ -67,27 +71,28 @@ public class SudGameSearchDialogPopup extends AbsDialogPopupWindow { protected void onCreate() { super.onCreate(); editSearch = findViewById(R.id.edit_search); - listHistory = findViewById(R.id.list_history); +// listHistory = findViewById(R.id.list_history); listRoom = findViewById(R.id.list_room); history = findViewById(R.id.layout_history); findViewById(R.id.layout_history_empty).setVisibility(GONE); + searchHistory = findViewById(R.id.search_history); + searchHistory.removeAllViews(); +// GridLayoutManager manager = (GridLayoutManager) listHistory.getLayoutManager(); +// if (manager != null) { +// manager.setReverseLayout(true); +// } - GridLayoutManager manager = (GridLayoutManager) listHistory.getLayoutManager(); - if (manager != null) { - manager.setReverseLayout(true); - } - - historyListAdapter = new SudGameSearchHistoryListAdapter(mContext, isHome); +// historyListAdapter = new SudGameSearchHistoryListAdapter(mContext, isHome); sudGameListAdapter = new SudHomeGameListAdapter(mContext, isHome); - historyListAdapter.setOnItemClickListener(new OnItemClickListener() { - @Override - public void onItemClick(String bean, int position) { - editSearch.setText(bean); - } - }); +// historyListAdapter.setOnItemClickListener(new OnItemClickListener() { +// @Override +// public void onItemClick(String bean, int position) { +// editSearch.setText(bean); +// } +// }); listRoom.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)); listRoom.setAdapter(sudGameListAdapter); - listHistory.setAdapter(historyListAdapter); +// listHistory.setAdapter(historyListAdapter); initHistoryData(); switchList(true); @@ -120,13 +125,45 @@ public class SudGameSearchDialogPopup extends AbsDialogPopupWindow { }); } + private List historyList; + private void initHistoryData() { String value = SpUtil.getStringValue(SP_HISTORY); - List historyList = new ArrayList<>(); + historyList = new ArrayList<>(); if (!StringUtil.isEmpty(value)) { historyList = JSONArray.parseArray(value, String.class); } - historyListAdapter.setList(historyList); +// historyListAdapter.setList(historyList); + + LinearLayout.LayoutParams layoutParams = + new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + layoutParams.setMargins(15, 10, 15, 7); + for (String str : historyList) { + TextView chip = new TextView(mContext); + chip.setText(str); + chip.setMaxEms(10); + chip.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12); + chip.setSingleLine(); + if (isHome) { + + chip.setBackgroundResource(R.drawable.bg_item_search_history); + chip.setTextColor(Color.parseColor("#FF999999")); + } else { + + chip.setBackgroundResource(R.drawable.bg_item_home_search_history); + chip.setTextColor(Color.parseColor("#FFFFFF")); + } + + chip.setLayoutParams(layoutParams); + searchHistory.addView(chip, layoutParams); + + chip.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + editSearch.setText(str); + } + }); + } } private void search(String value) { @@ -134,8 +171,23 @@ public class SudGameSearchDialogPopup extends AbsDialogPopupWindow { .searchRoomList("0", "0,0", "0", value, 0, new HttpCallback>() { @Override public void onSuccess(List data) { - switchList(false); - sudGameListAdapter.setList(data); + if (data.size() > 0) { + switchList(false); + sudGameListAdapter.setList(data); + boolean isValue = false; + for (String str : historyList) { + if (!isValue) { + isValue = TextUtils.equals(value, str); + } + + } + if (!isValue) { + historyList.add(value); + SpUtil.setStringValue(SP_HISTORY, JSONArray.toJSONString(historyList)); + } + + } + } @Override @@ -158,15 +210,7 @@ public class SudGameSearchDialogPopup extends AbsDialogPopupWindow { @Override protected void onDismiss() { super.onDismiss(); - String value = editSearch.getText().toString(); - if (!StringUtil.isEmpty(value)) { - List list = historyListAdapter.getList(); - if (list.size() >= 5) { - list.remove(0); - } - list.add(value); - SpUtil.setStringValue(SP_HISTORY, JSONArray.toJSONString(list)); - } + } @Subscribe(threadMode = ThreadMode.MAIN) diff --git a/main/src/main/java/com/yunbao/main/views/FlowLayout.java b/common/src/main/java/com/yunbao/common/views/FlowLayout.java similarity index 99% rename from main/src/main/java/com/yunbao/main/views/FlowLayout.java rename to common/src/main/java/com/yunbao/common/views/FlowLayout.java index c6e348b20..faa58fa62 100644 --- a/main/src/main/java/com/yunbao/main/views/FlowLayout.java +++ b/common/src/main/java/com/yunbao/common/views/FlowLayout.java @@ -1,4 +1,4 @@ -package com.yunbao.main.views; +package com.yunbao.common.views; import android.content.Context; import android.graphics.Rect; diff --git a/common/src/main/res/drawable/bg_item_home_search_history.xml b/common/src/main/res/drawable/bg_item_home_search_history.xml index acb8f9067..491c6fce0 100644 --- a/common/src/main/res/drawable/bg_item_home_search_history.xml +++ b/common/src/main/res/drawable/bg_item_home_search_history.xml @@ -4,6 +4,7 @@ + \ No newline at end of file diff --git a/common/src/main/res/drawable/bg_item_search_history.xml b/common/src/main/res/drawable/bg_item_search_history.xml index db8fdd66e..a38fb93ab 100644 --- a/common/src/main/res/drawable/bg_item_search_history.xml +++ b/common/src/main/res/drawable/bg_item_search_history.xml @@ -4,6 +4,7 @@ + \ No newline at end of file diff --git a/common/src/main/res/layout/dialog_home_search_sud_game.xml b/common/src/main/res/layout/dialog_home_search_sud_game.xml index 248c65025..c160673b0 100644 --- a/common/src/main/res/layout/dialog_home_search_sud_game.xml +++ b/common/src/main/res/layout/dialog_home_search_sud_game.xml @@ -48,7 +48,7 @@ android:id="@+id/edit_search" android:layout_width="266dp" android:layout_height="wrap_content" - android:background="@drawable/bg_live_sud_list_input_home" + android:background="@null" android:hint="@string/interactive_game_search_room_name_input" android:paddingStart="5dp" android:paddingTop="9dp" @@ -81,12 +81,19 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="10dp" + android:visibility="gone" app:layoutManager="androidx.recyclerview.widget.GridLayoutManager" app:spanCount="3" tools:itemCount="5" tools:layoutManager="GridLayoutManager" tools:listitem="@layout/item_search_history" /> + + + -