Commit 47279953 by 王文龙

[add]增加搜索功能

parent 367a8b99
......@@ -15,8 +15,8 @@
<activity
android:name=".ui.SplashActivity"
android:configChanges="keyboardHidden|screenSize|orientation"
android:theme="@style/App.Theme.Launch"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
android:theme="@style/App.Theme.Launch">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
......@@ -46,6 +46,12 @@
android:configChanges="keyboardHidden|screenSize|orientation"
android:screenOrientation="portrait"></activity>
<!-- 搜索页-->
<activity
android:name=".ui.SearchActivity"
android:configChanges="keyboardHidden|screenSize|orientation"
android:screenOrientation="portrait"></activity>
<!-- 会话聊天页-->
<activity
android:name=".ui.ChatActivity"
......@@ -65,7 +71,6 @@
</activity>
<!-- 中公IM平台appkey-->
<meta-data
android:name="com.offcn.live.im.appkey"
......@@ -108,9 +113,9 @@
<!--begin 点击推送通知栏处理配置-->
<activity
android:name=".ui.PushTranslateActivity"
android:configChanges="keyboardHidden|screenSize|orientation"
android:excludeFromRecents="true"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|screenSize|orientation"
android:taskAffinity="com.offcn.im.demo.push.activity.PushTranslateActivity"
android:theme="@style/Activity.Translucent">
<intent-filter>
......
......@@ -72,11 +72,12 @@ public class ContactListExpandableAdapter extends AnimatedExpandableListView.Ani
holder = (ChildHolder) convertView.getTag();
}
holder.title.setText(item.getName());
if (childPosition == 0) {
holder.title.setText("群发消息");
holder.avatar.setImageResource(R.mipmap.ic_chat_group_mixed);
} else {
holder.title.setText(item.getName());
Glide.with(mContext).load(item.getAvatar()).placeholder(R.mipmap.ic_teacher).into(holder.avatar);
}
......
package com.offcn.imclient.adapter;
import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.jyall.base.adapter.BaseRecyclerViewAdapter;
import com.jyall.base.adapter.RecyclerViewHolderUtil;
import com.offcn.imclient.R;
import com.offcn.imclient.bean.UserBean;
import java.util.List;
public class ContactSearchAdapter extends BaseRecyclerViewAdapter<UserBean> {
public ContactSearchAdapter(Context paramContext) {
super(paramContext);
}
public ContactSearchAdapter(Context context, List<UserBean> list) {
super(context, list);
}
@Override
public int onCreateViewLayoutID(int i) {
return R.layout.item_contact_child;
}
@Override
public void bindItemViewHolder(RecyclerViewHolderUtil recyclerViewHolderUtil, int i) {
UserBean item = getItem(i);
TextView title = recyclerViewHolderUtil.get(R.id.tv_name);
ImageView avatar = recyclerViewHolderUtil.get(R.id.iv_avatar);
title.setText(item.getName());
Glide.with(mContext).load(item.getAvatar()).placeholder(R.mipmap.ic_teacher).into(avatar);
}
}
......@@ -140,4 +140,21 @@ public class UserBean implements Serializable {
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return "UserBean{" +
"id=" + id +
", user_id='" + user_id + '\'' +
", name='" + name + '\'' +
", username='" + username + '\'' +
", avatar='" + avatar + '\'' +
", avatar_color='" + avatar_color + '\'' +
", type='" + type + '\'' +
", token='" + token + '\'' +
", remark='" + remark + '\'' +
", group_id='" + group_id + '\'' +
", group_name='" + group_name + '\'' +
'}';
}
}
......@@ -45,6 +45,7 @@ public class ContactListFragment extends BaseFragment {
private RelativeLayout mContainerContact;
private AnimatedExpandableListView mRecyclerView;
private RelativeLayout mSearch;
private List<ServerContactBean> friends = new ArrayList<>();
private ContactListExpandableAdapter mAdapter;
......@@ -58,6 +59,7 @@ public class ContactListFragment extends BaseFragment {
protected void init(View view) {
mContainerContact = view.findViewById(R.id.container_list);
mRecyclerView = view.findViewById(R.id.recycler_view);
mSearch = view.findViewById(R.id.search);
mAdapter = new ContactListExpandableAdapter(getContext(), friends);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
......@@ -137,6 +139,15 @@ public class ContactListFragment extends BaseFragment {
}
}
});
mSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!CommonUtils.isFastDoubleClick()) {
startActivity(new Intent(getActivity(), SearchActivity.class));
getActivity().overridePendingTransition(R.anim.push_bottom_in, R.anim.push_bottom_still);
}
}
});
getContactList();
......@@ -184,6 +195,7 @@ public class ContactListFragment extends BaseFragment {
public void onResponse(JSONObject response) {
ZGLLogUtils.e(TAG, "contact success " + response.toString());
dismissLoading();
UserBeanDaoManager.getInstance().deleteAll();
try {
int rtnCode = response.getInt("code");
if (rtnCode == 0) {
......@@ -193,8 +205,8 @@ public class ContactListFragment extends BaseFragment {
exeContactList();
} else {
// 数据为空
friends.clear();
showEmptyView();
friends.clear();
}
} else if (rtnCode == 1 || rtnCode == 2) {
// {"code":1,"msg":"登陆过期,请重新登陆","params":{"im_token":"0XR5YOS6dg7x2lirfeX3CbjRLqPWmesaFbdsr\/M4IRZS4mYYyZILI82FT8dgqybCA4W+MxfjJDY=@ip6c.cn.rongnav.com;ip6c.cn.rongcfg.com"}}
......@@ -230,7 +242,7 @@ public class ContactListFragment extends BaseFragment {
if (!ValidateUtils.isEmpty(friends)) {
showNormalContent();
for (ServerContactBean serverContactBean : friends) {
serverContactBean.getList().add(0, new UserBean("", "群发消息", ""));
serverContactBean.getList().add(0, new UserBean());
}
mAdapter.setData(friends);
List<UserBean> userBeanList = new ArrayList<>();
......
......@@ -92,11 +92,17 @@ public class LoginActivity extends BaseActivity {
private void login(String name, String pwd) {
if (!CommonUtils.isNetConnected(this)) {
CommonUtils.showToast(this, R.string.net_off);
return;
}
if (ValidateUtils.isEmpty(name) || ValidateUtils.isEmpty(pwd)) {
CommonUtils.showToast(this, "请输入用户名或密码");
return;
}
showLoading();
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("username", name);
......@@ -108,6 +114,7 @@ public class LoginActivity extends BaseActivity {
@Override
public void onResponse(JSONObject response) {
Log.e(TAG, "login success " + response.toString());
dismissLoading();
try {
if (response.getInt("code") == 0) {
if (response.getJSONObject("data") == null || response.getJSONObject("data").getJSONObject("user_info") == null) {
......@@ -134,6 +141,7 @@ public class LoginActivity extends BaseActivity {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "login error " + error.toString());
dismissLoading();
CommonUtils.showToast(LoginActivity.this, error.toString());
}
}
......
package com.offcn.imclient.ui;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.jyall.base.base.BaseActivity;
import com.jyall.base.util.CommonUtils;
import com.jyall.base.util.KeyboardUtils;
import com.jyall.base.util.ValidateUtils;
import com.jyall.base.view.ClearEditText;
import com.offcn.imclient.R;
import com.offcn.imclient.adapter.ContactSearchAdapter;
import com.offcn.imclient.bean.UserBean;
import com.offcn.imclient.util.LoginManager;
import com.offcn.imclient.util.UserBeanDaoManager;
import com.offcn.live.im.OIMSDK;
import com.offcn.live.im.bean.OIMSendTypeEnum;
import com.offcn.live.im.util.ZGLLogUtils;
import java.util.List;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
/**
* 搜索页
*
* @author wangwenlong
* @date 2020/12/21
*/
public class SearchActivity extends BaseActivity {
private static final String TAG = SearchActivity.class.getSimpleName();
ClearEditText mEditText;
TextView mTvCancel;
RecyclerView mRecyclerView;
LinearLayout mContainerContent, mContainerNone;
private ContactSearchAdapter mSearchAdapter;
@Override
protected int getContentViewLayoutId() {
return R.layout.activity_search;
}
@Override
protected void initViewsAndEvents() {
mEditText = findViewById(R.id.et_search);
mTvCancel = findViewById(R.id.tv_cancel);
mRecyclerView = findViewById(R.id.recycler_view);
mContainerContent = findViewById(R.id.container_content);
mContainerNone = findViewById(R.id.container_none);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(RecyclerView.VERTICAL);
mRecyclerView.setLayoutManager(linearLayoutManager);
mRecyclerView.setAdapter(mSearchAdapter = new ContactSearchAdapter(this));
mSearchAdapter.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
UserBean userBean = mSearchAdapter.getItem(position);
if (userBean != null) {
OIMSDK.getInstance().startChat(SearchActivity.this, OIMSendTypeEnum.PRIVATE, userBean.getUser_id(), userBean.getName(), 0);
} else {
CommonUtils.showToast(SearchActivity.this, "获取学生信息失败");
}
}
});
mTvCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
overridePendingTransition(R.anim.push_bottom_still, R.anim.push_bottom_out);
}
});
mEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (s == null || s.length() == 0 || TextUtils.isEmpty(s.toString().trim())) {
mContainerContent.setVisibility(View.GONE);
mContainerNone.setVisibility(View.GONE);
mSearchAdapter.clear();
return;
}
String content = s.toString().trim();
searchStudentByContent(content);
}
});
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
KeyboardUtils.showSoftInput(SearchActivity.this, mEditText);
}
}, 300);
}
@Override
protected void loadData() {
}
@Override
public void onBackPressed() {
finish();
overridePendingTransition(R.anim.push_bottom_still, R.anim.push_bottom_out);
}
/**
* 查询学生
*
* @param content
*/
private void searchStudentByContent(String content) {
ZGLLogUtils.e(TAG, "searchStudentByContent " + content);
List<UserBean> list = UserBeanDaoManager.getInstance().queryByNameOrMobile(content);
if (ValidateUtils.isEmpty(list)) {
mContainerContent.setVisibility(View.GONE);
mContainerNone.setVisibility(View.VISIBLE);
mSearchAdapter.clear();
} else {
mContainerNone.setVisibility(View.GONE);
mContainerContent.setVisibility(View.VISIBLE);
mSearchAdapter.clear();
mSearchAdapter.addAll(list);
}
}
}
......@@ -2,12 +2,9 @@ package com.offcn.imclient.util;
import android.content.Context;
import com.jyall.base.util.SharedPrefUtils;
import com.jyall.base.util.ValidateUtils;
import com.offcn.imclient.bean.UserBean;
import com.offcn.imclient.greendao.gen.DaoSession;
import com.offcn.imclient.greendao.gen.UserBeanDao;
import com.offcn.live.im.util.ZGLParseUtils;
import org.greenrobot.greendao.query.QueryBuilder;
......@@ -94,7 +91,7 @@ public class UserBeanDaoManager {
public List<UserBean> queryStudent() {
//查询构建器
QueryBuilder<UserBean> builder = manager.getDaoSession().queryBuilder(UserBean.class);
List<UserBean> list = builder.where(UserBeanDao.Properties.User_id.ge(1)).where(UserBeanDao.Properties.Name.like("王小二")).list();
List<UserBean> list = builder.where(UserBeanDao.Properties.User_id.ge(1)).list();
return list;
}
......@@ -108,7 +105,23 @@ public class UserBeanDaoManager {
QueryBuilder<UserBean> builder = manager.getDaoSession().queryBuilder(UserBean.class);
UserBean userBean = builder.where(UserBeanDao.Properties.User_id.eq(userId)).limit(1).unique();
return userBean;
}catch (Exception e){
} catch (Exception e) {
return null;
}
}
public List<UserBean> queryByNameOrMobile(String content) {
try {
QueryBuilder<UserBean> builder = manager.getDaoSession().queryBuilder(UserBean.class);
List<UserBean> list = builder.where(
builder.or(
UserBeanDao.Properties.Name.like("%" + content + "%"),
UserBeanDao.Properties.Username.like("%" + content + "%")
)
)
.list();
return list;
} catch (Exception e) {
return null;
}
}
......
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="100%p"
android:toYDelta="0"
android:duration="300" />
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="25"
android:toYDelta="100%p"
android:duration="300" />
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0"
android:toYDelta="0"
android:duration="500" />
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/color_f5f5f5" />
<corners android:radius="20dp" />
</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:fitsSystemWindows="true"
android:background="@android:color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_margin="15dp"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="0dp"
android:layout_height="38dp"
android:layout_weight="1"
android:background="@drawable/bg_search"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_search" />
<com.jyall.base.view.ClearEditText
android:id="@+id/et_search"
android:layout_width="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:background="@null"
android:textSize="13sp"
android:hint="@string/search"
android:textColor="@color/color_333333"
android:textColorHint="#CECECE" />
</LinearLayout>
<TextView
android:id="@+id/tv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="取消"
android:textColor="@color/color_333333"
android:textSize="16sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/container_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/color_cecece" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/container_none"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@android:color/white"
android:gravity="center"
android:text="找不到对应用户" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_f5f5f5" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
\ No newline at end of file
......@@ -5,7 +5,7 @@
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="@dimen/toolbar_padding_top">
android:paddingTop="@dimen/main_padding_top">
<fragment
android:name="com.offcn.live.imkit.ui.ChatListFragment"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:gravity="center"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingTop="@dimen/toolbar_padding_top"
android:orientation="vertical">
android:orientation="vertical"
android:paddingTop="@dimen/main_padding_top">
<RelativeLayout
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/bg_search">
<TextView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:layout_centerInParent="true"
android:drawableLeft="@mipmap/ic_search"
android:drawablePadding="5dp"
android:gravity="center"
android:text="@string/search"
android:textColor="@color/color_cecece"
android:textSize="15sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/container_list"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_marginTop="15dp">
<com.offcn.imclient.view.AnimatedExpandableListView
android:id="@+id/recycler_view"
android:groupIndicator="@null"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:groupIndicator="@null" />
</RelativeLayout>
......
......@@ -5,7 +5,7 @@
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:background="@mipmap/ic_me_bg"
android:paddingTop="@dimen/toolbar_padding_top"
android:paddingTop="@dimen/main_padding_top"
android:orientation="vertical">
<com.offcn.live.imkit.view.CircleImageView
......
......@@ -2,18 +2,21 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:paddingLeft="50dp"
android:gravity="center_vertical">
android:gravity="center_vertical"
android:paddingLeft="50dp">
<ImageView
android:id="@+id/iv_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="45dp"
android:layout_height="45dp"
android:scaleType="centerCrop"
android:src="@mipmap/ic_teacher" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:singleLine="true"
android:ellipsize="end"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp" />
......
<resources>
<!--Toolbar 距上方距离, v19为25dp-->
<dimen name="main_padding_top">35dp</dimen>
</resources>
......@@ -6,4 +6,6 @@
<color name="color_333333">#333333</color>
<color name="color_cecece">#CECECE</color>
<color name="color_f5f5f5">#F5F5F5</color>
</resources>
\ No newline at end of file
<resources>
<!--Toolbar 距上方距离, v19为25dp-->
<dimen name="main_padding_top">0dp</dimen>
</resources>
......@@ -8,4 +8,5 @@
<string name="push_vivo_appkey">5920cbae23f22a915ecabf26554b644e</string>
<string name="push_oppo_appkey">aa5d4f8306b04b7c820019b906e2ce92</string>
<string name="push_oppo_appsecret">365b1426c0a14519b3f96092f0a729a9</string>
<string name="search">搜索姓名或者手机号</string>
</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