Commit 215bcfd8 authored by chenyuling's avatar chenyuling

"增加搜索模块"

parent 8b53b469
Pipeline #1652 canceled with stages
......@@ -14,21 +14,33 @@ import com.srthinker.statinfo.databinding.ItemSelectGroupBinding;
import java.util.ArrayList;
import java.util.List;
public class PersonGroupSAdapter extends RecyclerView.Adapter {
public class PersonGroupSAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final String TAG = "pgAdapter";
private final Context context;
private List<PersonEntity> personEntities = new ArrayList<>();
private List<PersonEntity> oriPersons = new ArrayList<>();
private SparseBooleanArray mSelectedPositions = new SparseBooleanArray();
private boolean mIsSelectable =false;
public PersonGroupSAdapter(Context context, List<PersonEntity> personEntities){
this.context = context;
this.personEntities = personEntities;
this.oriPersons = personEntities;
}
public void setDataList(List<PersonEntity> personEntities){
/*this.personEntities.clear();
this.personEntities.addAll(personEntities);*/
this.personEntities = personEntities;
mSelectedPositions = new SparseBooleanArray();
this.oriPersons = personEntities;
//mSelectedPositions = new SparseBooleanArray();
mSelectedPositions.clear();
notifyDataSetChanged();
}
public void setSearchList(List<PersonEntity> personEntities){
this.personEntities = personEntities;
//mSelectedPositions.clear();
notifyDataSetChanged();
}
@NonNull
......@@ -42,16 +54,19 @@ public class PersonGroupSAdapter extends RecyclerView.Adapter {
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
ItemHolder itemHolder = (ItemHolder) holder;
PersonEntity person = personEntities.get(position);
int oriPosition = oriPersons.indexOf(person);
if (person!=null){
itemHolder.mBinding.tvPersonName.setText(person.getPerson_name());
itemHolder.mBinding.tvPersonName.setSelected(isItemChecked(position));
itemHolder.mBinding.tvPersonName.setSelected(isItemChecked(oriPosition));
itemHolder.mBinding.llItem.setOnClickListener(v->{
if (isItemChecked(position)){
if (isItemChecked(oriPosition)){
itemHolder.mBinding.tvPersonName.setSelected(false);
setItemChecked(position,false);
//setItemChecked(position,false);
setItemChecked(oriPosition,false);
}else{
itemHolder.mBinding.tvPersonName.setSelected(true);
setItemChecked(position,true);
//setItemChecked(position,true);
setItemChecked(oriPosition,true);
}
});
}
......@@ -59,7 +74,7 @@ public class PersonGroupSAdapter extends RecyclerView.Adapter {
@Override
public int getItemCount() {
return personEntities!=null&&personEntities.size()>=0?personEntities.size():0;
return personEntities!=null&&personEntities.size()>0?personEntities.size():0;
}
//设置给定位置条目的选择状态
......@@ -84,10 +99,11 @@ public class PersonGroupSAdapter extends RecyclerView.Adapter {
//获取选中的结果
public List<PersonEntity> getSelectedItem(){
List<PersonEntity> selectList = new ArrayList<>();
if (personEntities!=null){
for (int i = 0; i < personEntities.size(); i++) {
//Log.i(TAG, "getSelectedItem: oriPersons.size()="+oriPersons.size());
if (oriPersons!=null){
for (int i = 0; i < oriPersons.size(); i++) {
if (isItemChecked(i)){
selectList.add(personEntities.get(i));
selectList.add(oriPersons.get(i));
}
}
}
......
......@@ -157,4 +157,12 @@ public class PersonHelper {
locker.unlock();
return personEntities;
}
public List<PersonEntity> queryByGN(int group,String name){
List<PersonEntity> personEntities = null;
locker.lock(0);
personEntities = SQLite.select().from(PersonEntity.class).where(PersonEntity_Table.group.eq(group)).and(PersonEntity_Table.person_name.like("%"+name+"%")).queryList();
locker.unlock();
return personEntities;
}
}
......@@ -24,6 +24,7 @@ import com.srthinker.statinfo.database.entity.ConfigEntity;
import com.srthinker.statinfo.database.helper.ConfigHelper;
import com.srthinker.statinfo.databinding.DialogConfigBinding;
import com.srthinker.statinfo.listener.ConfigCallback;
import com.srthinker.statinfo.util.common.KeyBoardUtil;
import com.srthinker.statinfo.util.common.SharedUtil;
import com.srthinker.statinfo.util.common.Utils;
import com.srthinker.statinfo.wedget.EditView;
......@@ -66,6 +67,8 @@ public class ConfigDlgFragment extends DialogFragment {
mBinding = DialogConfigBinding.inflate(inflater, container, false);
initData();
initView();
return mBinding.getRoot();
}
......@@ -287,8 +290,10 @@ public class ConfigDlgFragment extends DialogFragment {
private void initWindow() {
Window window = getDialog().getWindow();
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
window.setLayout(Utils.dip2px(context,280),ViewGroup.LayoutParams.WRAP_CONTENT);
//window.setLayout(Utils.dip2px(context,280),ViewGroup.LayoutParams.WRAP_CONTENT);
window.setLayout(Utils.dip2px(context,280), (int) (Utils.getScreenHeight(context)*0.6));
window.setGravity(Gravity.CENTER);
KeyBoardUtil.initSoftInputListener(getDialog());
}
@Override
......@@ -301,4 +306,7 @@ public class ConfigDlgFragment extends DialogFragment {
this.callback = callback;
}
}
......@@ -31,6 +31,7 @@ public class GroupFragment extends BaseFragment{
private FragmentActivity mActivity;
private NoGroupFragment noGroupFragment;
private GroupedFragment groupedFragment;
private int mPage;
@Nullable
@Override
......@@ -56,6 +57,33 @@ public class GroupFragment extends BaseFragment{
mBinding.ivBack.setOnClickListener(v-> mActivity.onBackPressed());
mBinding.btnGrouping.setOnClickListener(v-> clickGrouping());
mBinding.btnRemove.setOnClickListener(v-> clickRemove());
mBinding.btnSearch.setOnClickListener(v->clickSearch());
mBinding.btnReset.setOnClickListener(v->clickReset());
}
private void clickReset() {
clearSearch();
clickSearch();
}
private void clickSearch() {
String search_name = mBinding.etName.getText().toString();
switch (mPage){
case NO_GROUP:
if (noGroupFragment != null) {
noGroupFragment.searchNoList(search_name);
}
break;
case GROUPED:
if (groupedFragment != null) {
groupedFragment.searchListCurrent(search_name);
}
break;
}
}
private void clearSearch(){
mBinding.etName.setText("");
}
private void clickRemove() {
......@@ -104,6 +132,9 @@ public class GroupFragment extends BaseFragment{
}
private void selectPage(int page) {
//标志选择的是哪一页,切换的时候清空搜索框
clearSearch();
mPage = page;
switch (page){
case NO_GROUP:
mBinding.tvTabNo.setSelected(true);
......
......@@ -99,6 +99,14 @@ public class GroupedFragment extends BaseFragment {
}
}
public void searchListCurrent(String name){
int currentItem = mBinding.vpPager.getCurrentItem();
if (groupPagerAdapter != null) {
TabGroupFragment tabGroupFragment = (TabGroupFragment) groupPagerAdapter.getItem(currentItem);
tabGroupFragment.searchLists(name);
}
}
public void updateListTotal(){
if (groupPagerAdapter != null) {
int totalPage = groupPagerAdapter.getCount();
......
......@@ -24,6 +24,7 @@ import java.util.List;
public class NoGroupFragment extends BaseFragment {
private static final String TAG = "NoGroupFragment";
private com.srthinker.statinfo.databinding.FragmentNoGroupBinding mBinding;
private List<PersonEntity> noGroupList;
private Context mContext;
......@@ -86,9 +87,29 @@ public class NoGroupFragment extends BaseFragment {
//查询数据库
if (activity != null) {
activity.runOnUiThread(()->{
noGroupList = PersonHelper.getInstance().queryByGroup(0);
List<PersonEntity> updatePersons = new ArrayList<>();
updatePersons = PersonHelper.getInstance().queryByGroup(0);
noGroupList = updatePersons;
/*for (PersonEntity updatePerson : updatePersons) {
Log.i(TAG, "updateNoList: updatePerson.name="+updatePerson.getPerson_name());
}*/
if (mNoGroupAdapter != null) {
mNoGroupAdapter.setDataList(updatePersons);
}
});
}
}
public void searchNoList(String name){
//查询数据库
if (activity != null) {
activity.runOnUiThread(()->{
List<PersonEntity> updatePersons = new ArrayList<>();
updatePersons = PersonHelper.getInstance().queryByGN(0,name);
if (mNoGroupAdapter != null) {
mNoGroupAdapter.setDataList(noGroupList);
mNoGroupAdapter.setSearchList(updatePersons);
}
});
}
......
......@@ -96,13 +96,27 @@ public class TabGroupFragment extends BaseFragment {
entity.setPerson_name("王大锤"+i+"-"+type);
personItems.add(entity);
}*/
personItems = PersonHelper.getInstance().queryByGroup(type);
List<PersonEntity> updatePersons = new ArrayList<>();
updatePersons = PersonHelper.getInstance().queryByGroup(type);
personItems = updatePersons;
if (groupSAdapter != null) {
groupSAdapter.setDataList(personItems);
groupSAdapter.setDataList(updatePersons);
}
});
}
}
public void searchLists(String name){
if (activity != null) {
activity.runOnUiThread(()->{
//访问数据库,然后刷新
List<PersonEntity> searchPersons = new ArrayList<>();
searchPersons = PersonHelper.getInstance().queryByGN(type,name);
if (groupSAdapter != null) {
groupSAdapter.setSearchList(searchPersons);
}
});
}
}
}
package com.srthinker.statinfo.util.common;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
......@@ -14,6 +16,29 @@ public class KeyBoardUtil {
}
/**
* 使用自定义dialogFragment时,在resume中调用以下方法,传getDialog,点击非输入框区域时,自动收起键盘
*/
public static void initSoftInputListener(Dialog dialog) {
dialog.getWindow().getDecorView()
.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
InputMethodManager manager = (InputMethodManager) dialog.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (dialog.getCurrentFocus() != null
&& dialog.getCurrentFocus().getWindowToken() != null) {
manager.hideSoftInputFromWindow(
dialog.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
return false;
}
});
}
/**
* 软键盘监听器
......
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-2dp"
android:right="-2dp"
android:left="-2dp">
<shape>
<padding android:left="4dp"
android:top="2dp"
android:bottom="4dp"/>
<stroke
android:width="2dp"
android:color="@color/color_2D52E3"/>
</shape>
</item>
</layer-list>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="2dp"/>
<solid android:color="@color/color_2D52E3"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_070A2E"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
......@@ -39,16 +42,61 @@
android:drawablePadding="5.5dp"
android:drawableBottom="@drawable/indicator"
android:layout_marginTop="4dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_toRightOf="@+id/iv_back"
android:visibility="visible"
android:layout_centerVertical="true"
android:layout_marginLeft="200dp">
<EditText
android:id="@+id/et_name"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:hint="请输入名字"
android:inputType="text"
android:textColorHint="@color/white"
android:textSize="@dimen/text_11"
android:textColor="@color/white"
android:singleLine="true"
android:imeOptions="actionDone"
android:background="@drawable/edit_bottom_line"
android:textCursorDrawable="@drawable/edit_cursor"
/>
<Button
android:id="@+id/btn_search"
android:layout_width="60dp"
android:layout_height="22dp"
android:layout_marginLeft="10dp"
android:background="@color/color_2D52E3"
android:text="查询"
android:textColor="@color/white"
android:textSize="@dimen/text_10"
tools:ignore="TouchTargetSizeCheck" />
<Button
android:id="@+id/btn_reset"
android:layout_width="60dp"
android:layout_height="22dp"
android:layout_marginLeft="10dp"
android:background="@color/color_2D52E3"
android:textColor="@color/white"
android:textSize="@dimen/text_10"
android:text="重置"/>
</LinearLayout>
<Button
android:id="@+id/btn_grouping"
android:layout_width="60dp"
android:layout_height="22dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@color/color_2D52E3"
android:text="人员分组"
android:textColor="@color/white"
android:textSize="@dimen/text_10"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
tools:ignore="TouchTargetSizeCheck" />
<Button
android:id="@+id/btn_remove"
android:layout_width="60dp"
......@@ -65,7 +113,7 @@
android:id="@+id/fcv_group_people"
android:layout_width="924dp"
android:layout_height="422dp"
android:layout_marginTop="16dp"
android:layout_marginTop="12dp"
android:background="@drawable/bg_shape"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
\ No newline at end of file
......@@ -12,5 +12,6 @@
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="colorAccent">@color/color_2D52E3</item>
</style>
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment