sud游戏搜索页面优化更改
This commit is contained in:
@@ -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) {
|
||||
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<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)
|
||||
|
||||
128
common/src/main/java/com/yunbao/common/views/FlowLayout.java
Normal file
128
common/src/main/java/com/yunbao/common/views/FlowLayout.java
Normal file
@@ -0,0 +1,128 @@
|
||||
package com.yunbao.common.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 流式佈局
|
||||
*/
|
||||
public class FlowLayout extends ViewGroup {
|
||||
|
||||
public FlowLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public FlowLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public FlowLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
// super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
//遍历去调用所有子元素的measure方法(child.getMeasuredHeight()才能获取到值,否则为0)
|
||||
measureChildren(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
int measuredWidth = 0, measuredHeight = 0;
|
||||
|
||||
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int widtMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||
//由于计算子view所占宽度,这里传值需要自身减去PaddingRight宽度,PaddingLeft会在接下来计算子元素位置时加上
|
||||
Map<String, Integer> compute = compute(widthSize - getPaddingRight());
|
||||
|
||||
//EXACTLY模式:对应于给定大小或者match_parent情况
|
||||
if (widtMode == MeasureSpec.EXACTLY) {
|
||||
measuredWidth = widthSize;
|
||||
//AT_MOS模式:对应wrap-content(需要手动计算大小,否则相当于match_parent)
|
||||
} else if (widtMode == MeasureSpec.AT_MOST) {
|
||||
measuredWidth = compute.get("allChildWidth");
|
||||
}
|
||||
|
||||
if (heightMode == MeasureSpec.EXACTLY) {
|
||||
measuredHeight = heightSize;
|
||||
} else {
|
||||
measuredHeight = compute.get("allChildHeight");
|
||||
}
|
||||
//设置flow的宽高
|
||||
setMeasuredDimension(measuredWidth, measuredHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View child = getChildAt(i);
|
||||
Rect rect = (Rect) getChildAt(i).getTag();
|
||||
child.layout(rect.left, rect.top, rect.right, rect.bottom);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 测量过程
|
||||
*
|
||||
* @param flowWidth 该view的宽度
|
||||
* @return 返回子元素总所占宽度和高度(用于计算Flowlayout的AT_MOST模式设置宽高)
|
||||
*/
|
||||
private Map<String, Integer> compute(int flowWidth) {
|
||||
//是否是单行
|
||||
boolean aRow = true;
|
||||
MarginLayoutParams marginParams;//子元素margin
|
||||
int rowsWidth = getPaddingLeft();//当前行已占宽度(注意需要加上paddingLeft)
|
||||
int columnHeight = getPaddingTop();//当前行顶部已占高度(注意需要加上paddingTop)
|
||||
int rowsMaxHeight = 0;//当前行所有子元素的最大高度(用于换行累加高度)
|
||||
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
|
||||
View child = getChildAt(i);
|
||||
//获取元素测量宽度和高度
|
||||
int measuredWidth = child.getMeasuredWidth();
|
||||
int measuredHeight = child.getMeasuredHeight();
|
||||
//获取元素的margin
|
||||
marginParams = (MarginLayoutParams) child.getLayoutParams();
|
||||
//子元素所占宽度 = MarginLeft+ child.getMeasuredWidth+MarginRight 注意此时不能child.getWidth,因为界面没有绘制完成,此时wdith为0
|
||||
int childWidth = marginParams.leftMargin + marginParams.rightMargin + measuredWidth;
|
||||
int childHeight = marginParams.topMargin + marginParams.bottomMargin + measuredHeight;
|
||||
//判断是否换行: 该行已占大小+该元素大小>父容器宽度 则换行
|
||||
|
||||
rowsMaxHeight = Math.max(rowsMaxHeight, childHeight);
|
||||
//换行
|
||||
if (rowsWidth + childWidth > flowWidth) {
|
||||
//重置行宽度
|
||||
rowsWidth = getPaddingLeft() + getPaddingRight();
|
||||
//累加上该行子元素最大高度
|
||||
columnHeight += rowsMaxHeight;
|
||||
//重置该行最大高度
|
||||
rowsMaxHeight = childHeight;
|
||||
aRow = false;
|
||||
}
|
||||
//累加上该行子元素宽度
|
||||
rowsWidth += childWidth;
|
||||
//判断时占的宽段时加上margin计算,设置顶点位置时不包括margin位置,不然margin会不起作用,这是给View设置tag,在onlayout给子元素设置位置再遍历取出
|
||||
child.setTag(new Rect(rowsWidth - childWidth + marginParams.leftMargin, columnHeight + marginParams.topMargin, rowsWidth - marginParams.rightMargin, columnHeight + childHeight - marginParams.bottomMargin));
|
||||
}
|
||||
|
||||
//返回子元素总所占宽度和高度(用于计算Flowlayout的AT_MOST模式设置宽高)
|
||||
Map<String, Integer> flowMap = new HashMap<>();
|
||||
//单行
|
||||
if (aRow) {
|
||||
flowMap.put("allChildWidth", rowsWidth);
|
||||
} else {
|
||||
//多行
|
||||
flowMap.put("allChildWidth", flowWidth);
|
||||
}
|
||||
//FlowLayout测量高度 = 当前行顶部已占高度 +当前行内子元素最大高度+FlowLayout的PaddingBottom
|
||||
flowMap.put("allChildHeight", columnHeight + rowsMaxHeight + getPaddingBottom());
|
||||
return flowMap;
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user