sud游戏搜索页面优化更改

This commit is contained in:
18401019693 2023-09-27 17:08:14 +08:00
parent c94f549531
commit 32ebfa719d
8 changed files with 96 additions and 36 deletions

View File

@ -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<String>() {
@Override
public void onItemClick(String bean, int position) {
editSearch.setText(bean);
}
});
// historyListAdapter.setOnItemClickListener(new OnItemClickListener<String>() {
// @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<String> historyList;
private void initHistoryData() {
String value = SpUtil.getStringValue(SP_HISTORY);
List<String> 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<List<SudRoomListModel>>() {
@Override
public void onSuccess(List<SudRoomListModel> 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<String> list = historyListAdapter.getList();
if (list.size() >= 5) {
list.remove(0);
}
list.add(value);
SpUtil.setStringValue(SP_HISTORY, JSONArray.toJSONString(list));
}
}
@Subscribe(threadMode = ThreadMode.MAIN)

View File

@ -1,4 +1,4 @@
package com.yunbao.main.views;
package com.yunbao.common.views;
import android.content.Context;
import android.graphics.Rect;

View File

@ -4,6 +4,7 @@
<shape android:shape="rectangle">
<solid android:color="#343434" />
<corners android:topLeftRadius="14dp" android:topRightRadius="14dp" android:bottomLeftRadius="14dp" android:bottomRightRadius="14dp" />
<padding android:bottom="7dp" android:left="11dp" android:right="11dp" android:top="7dp" />
</shape>
</item>
</selector>

View File

@ -4,6 +4,7 @@
<shape android:shape="rectangle">
<solid android:color="#ffe7e0df" />
<corners android:topLeftRadius="14dp" android:topRightRadius="14dp" android:bottomLeftRadius="14dp" android:bottomRightRadius="14dp" />
<padding android:bottom="7dp" android:left="11dp" android:right="11dp" android:top="7dp" />
</shape>
</item>
</selector>

View File

@ -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" />
<com.yunbao.common.views.FlowLayout
android:id="@+id/search_history"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
<LinearLayout
android:id="@+id/layout_history_empty"
android:layout_width="match_parent"

View File

@ -87,6 +87,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list_history"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
@ -95,6 +96,11 @@
tools:itemCount="5"
tools:layoutManager="GridLayoutManager"
tools:listitem="@layout/item_search_history" />
<com.yunbao.common.views.FlowLayout
android:id="@+id/search_history"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
<LinearLayout
android:id="@+id/layout_history_empty"

View File

@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.yunbao.common.manager.SearchHistoryRecordManager;
import com.yunbao.common.views.FlowLayout;
import com.yunbao.main.R;
import java.util.Map;

View File

@ -33,7 +33,7 @@
android:src="@mipmap/search_del" />
</FrameLayout>
<com.yunbao.main.views.FlowLayout
<com.yunbao.common.views.FlowLayout
android:id="@+id/search_history"
android:layout_marginTop="10dp"
android:layout_width="match_parent"