Commit d2948155 authored by jianglx's avatar jianglx

添加好友的初次提交

parent f210bad7
......@@ -8,7 +8,8 @@ public enum CacheEnum {
USER(1, "user"), // 用户
CONSUMER_RECORD(2, "consumer_record"), // 消费记录
VISTOR_LIST(3, "vistor_list"), //出游人列表
IM_CONFIG(4,"im_config") ;
IM_CONFIG(4, "im_config"),
CONTACTS(5, "contacts"); // 通讯录
private int type;
private String fileName;
......
......@@ -926,7 +926,7 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
showToast("Im初始化中...");
return;
}
ComponentName name = new ComponentName(getActivity(), "com.rv.im.CustomerListActivity");
ComponentName name = new ComponentName(getActivity(), "com.rv.im.ConversationListActivity");
Intent intent = new Intent();
intent.putExtra("login_user_id", Cookie.getStringValue(getContext(), SPConstance.USER_JSON_IMUSERID));
intent.setComponent(name);
......
......@@ -83,6 +83,8 @@ dependencies {
implementation 'cjt.library.wheel:camera:1.1.9'
api 'com.lzy.net:okgo:3.0.4'
api project(':RvWrapper')
implementation files('libs/pinyin4j-2.5.0.jar')
implementation files('libs/pinyin4j-2.5.0.jar')
}
configurations {
all*.exclude group: 'xpp3', module: 'xpp3'
......
......@@ -10,43 +10,53 @@
<uses-permission android:name="android.permission.CALL_PHONE" />
<application>
<activity android:name="com.rv.im.ChatActivity"
<activity
android:name=".ChatActivity"
android:screenOrientation="portrait" />
<activity
android:name="com.rv.im.photopicker.PhotoPickerActivity"
android:screenOrientation="portrait"
android:name=".photopicker.PhotoPickerActivity"
android:configChanges="orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/PhotoPickerTheme" />
<activity
android:name="com.rv.im.photopicker.PhotoPreviewActivity"
android:theme="@style/PhotoPickerTheme"
android:name=".photopicker.PhotoPreviewActivity"
android:screenOrientation="portrait"
android:theme="@style/PhotoPickerTheme" />
<activity
android:name=".call.Jitsi_pre"
android:screenOrientation="portrait" />
<activity android:name="com.rv.im.call.Jitsi_pre"
<activity
android:name=".call.Jitsi_connecting_second"
android:screenOrientation="portrait" />
<activity android:name="com.rv.im.call.Jitsi_connecting_second"
<activity
android:name=".call.JitsiIncomingcall"
android:screenOrientation="portrait" />
<activity android:name="com.rv.im.call.JitsiIncomingcall"
<activity
android:name=".MucFileDetails"
android:screenOrientation="portrait" />
<activity android:name="com.rv.im.MucFileDetails"
<activity
android:name=".ConversationListActivity"
android:screenOrientation="portrait" />
<activity android:name="com.rv.im.ConversationListActivity"
<activity
android:name=".video.ChatVideoPreviewActivity"
android:screenOrientation="portrait" />
<activity android:name="com.rv.im.video.ChatVideoPreviewActivity"
<activity
android:name=".SingleImagePreviewActivity"
android:screenOrientation="portrait" />
<activity android:name="com.rv.im.SingleImagePreviewActivity"
android:screenOrientation="portrait"/>
<service
android:name="com.rv.im.ImService"
android:name=".ImService"
android:enabled="true"
android:exported="true" />
<!--android:process=":im_romote" /> -->
<!-- android:process=":im_romote" /> -->
<service android:name="com.rv.im.call.RecordService" />
<service android:name=".call.RecordService" />
<activity android:name="com.rv.im.CustomerListActivity"
<activity
android:name=".CustomerListActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<activity android:name=".AddressListActivity"></activity>
</application>
</manifest>
\ No newline at end of file
package com.rv.im;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.LinearLayout;
import com.ruiwenliu.wrapper.base.BaseBean;
import com.ruiwenliu.wrapper.base.BaseStatusActivity;
import com.ruiwenliu.wrapper.weight.TitleView;
import com.rv.component.utils.CacheEnum;
import com.rv.component.utils.RvCache;
import com.rv.im.adapter.AddressListAdapter;
import com.rv.im.bean.ContactsBean;
import com.rv.im.presenter.AddressPresenter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/************
*
* 通讯录
*
*/
public class AddressListActivity extends BaseStatusActivity<AddressPresenter> {
private RecyclerView recyclerView;
private AddressListAdapter adapter = null;
private List<ContactsBean.ContactItemBean> lists = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected int setLayout() {
return R.layout.activity_address_list;
}
@Override
protected void initView(Bundle savedInstanceState, TitleView titleView, Intent intent) {
titleView.setTitle(getString(R.string.title_address_list));
recyclerView = findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayout.VERTICAL, false));
}
@Override
protected void loadData(Bundle savedInstanceState, Intent intent) {
super.loadData(savedInstanceState, intent);
mPresenter.initAddress(lists);
adapter = new AddressListAdapter(lists);
recyclerView.setAdapter(adapter);
}
@Override
public void onShowResult(int requestType, BaseBean result) {
switch (requestType) {
case 0:
if (result != null && result instanceof ContactsBean) {
ContactsBean bean = (ContactsBean) result;
if (bean.resultCode == 1) {
RvCache.getInstance().save(bean, CacheEnum.CONTACTS);
if (bean.getData() != null && bean.getData().size() > 0) {
// 保存数据,更新ui;
lists.clear();
lists.addAll(bean.getData());
Collections.sort(lists);
adapter.setNewData(lists);
adapter.notifyDataSetChanged();
}
}
}
break;
default:
break;
}
}
}
......@@ -68,10 +68,10 @@ public class ConversationListActivity extends BaseStatusActivity<CommonPresenter
// titleView.setImageResource(R.id.iv_title_right, R.drawable.ic_app_add);
titleView.setChildClickListener(R.id.tv_title_right, v -> {
Intent in = new Intent(this, CustomerListActivity.class);
Intent in = new Intent(this, AddressListActivity.class);
startActivityForResult(in, 1);
});
titleView.setText(R.id.tv_title_right, "客服列表");
titleView.setText(R.id.tv_title_right, "通讯录");
refreshLayout = findViewById(R.id.refresh);
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayout.VERTICAL, false));
......
package com.rv.im.adapter;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ruiwenliu.wrapper.util.glide.GlideManager;
import com.rv.im.R;
import com.rv.im.bean.ContactsBean;
import java.util.List;
public class AddressListAdapter extends BaseQuickAdapter<ContactsBean.ContactItemBean, BaseViewHolder> {
private boolean needShowNavigation = true;
private char lastNavigation;
public AddressListAdapter(@Nullable List<ContactsBean.ContactItemBean> data) {
super(R.layout.item_address_list, data);
}
@Override
protected void convert(BaseViewHolder helper, ContactsBean.ContactItemBean item) {
helper.setText(R.id.tv_name, item.getToNickname());
if (item.getType() == 0) {
helper.itemView.findViewById(R.id.ll_navigation).setVisibility(View.GONE);
if (item.getLocalHead() != 0) {
helper.setImageResource(R.id.img_header, item.getLocalHead());
}
} else {
if (needShowNavigation) {
helper.itemView.findViewById(R.id.ll_navigation).setVisibility(View.VISIBLE);
} else {
helper.itemView.findViewById(R.id.ll_navigation).setVisibility(View.GONE);
}
// if (!TextUtils.isEmpty(item.getHeadUrl())) {
// ImageView imageView = helper.itemView.findViewById(R.id.img_header);
// GlideManager.getInstance(mContext).loadImage(item.getHeadUrl(), imageView);
// }
}
}
}
package com.rv.im.bean;
import android.text.TextUtils;
import com.rv.im.util.sortlist.PingYinUtil;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ContactsBean extends ImBaseBean implements Serializable {
private long currentTime;
private List<ContactItemBean> data;
public long getCurrentTime() {
return currentTime;
}
public void setCurrentTime(long currentTime) {
this.currentTime = currentTime;
}
public List<ContactItemBean> getData() {
return data;
}
public void setData(List<ContactItemBean> data) {
this.data = data;
}
public static class ContactItemBean implements Serializable, Comparable<ContactItemBean> {
private int blacklist; // 0 表示不是黑名单,1表示是在黑名单
private double chatRecordTimeOut; //0 || -1 消息永久保存 单位:day
private long createTime;
private int encryptType;
private int fromAddType;
private int isBeenBlack; // 1表示对方将我拉入黑名单
private int isOpenSnapchat;
private int lastTalkTime;
private int modifyTime; // 修改时间
private int msgNum;
private int offlineNoPushMsg; // 消息免打扰
private int openTopChatTime;
private int status;
private String toNickname;
private String toUserId;// 被关注的人
private int toUserType;// 2 公众号
private int userId;// 发起关注的人
private int type = 1;
private int localHead;
public int getBlacklist() {
return blacklist;
}
public void setBlacklist(int blacklist) {
this.blacklist = blacklist;
}
public double getChatRecordTimeOut() {
return chatRecordTimeOut;
}
public void setChatRecordTimeOut(double chatRecordTimeOut) {
this.chatRecordTimeOut = chatRecordTimeOut;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public int getEncryptType() {
return encryptType;
}
public void setEncryptType(int encryptType) {
this.encryptType = encryptType;
}
public int getFromAddType() {
return fromAddType;
}
public void setFromAddType(int fromAddType) {
this.fromAddType = fromAddType;
}
public int getIsBeenBlack() {
return isBeenBlack;
}
public void setIsBeenBlack(int isBeenBlack) {
this.isBeenBlack = isBeenBlack;
}
public int getIsOpenSnapchat() {
return isOpenSnapchat;
}
public void setIsOpenSnapchat(int isOpenSnapchat) {
this.isOpenSnapchat = isOpenSnapchat;
}
public int getLastTalkTime() {
return lastTalkTime;
}
public void setLastTalkTime(int lastTalkTime) {
this.lastTalkTime = lastTalkTime;
}
public int getModifyTime() {
return modifyTime;
}
public void setModifyTime(int modifyTime) {
this.modifyTime = modifyTime;
}
public int getMsgNum() {
return msgNum;
}
public void setMsgNum(int msgNum) {
this.msgNum = msgNum;
}
public int getOfflineNoPushMsg() {
return offlineNoPushMsg;
}
public void setOfflineNoPushMsg(int offlineNoPushMsg) {
this.offlineNoPushMsg = offlineNoPushMsg;
}
public int getOpenTopChatTime() {
return openTopChatTime;
}
public void setOpenTopChatTime(int openTopChatTime) {
this.openTopChatTime = openTopChatTime;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getToNickname() {
return toNickname;
}
public void setToNickname(String toNickname) {
this.toNickname = toNickname;
}
public String getToUserId() {
return toUserId;
}
public void setToUserId(String toUserId) {
this.toUserId = toUserId;
}
public int getToUserType() {
return toUserType;
}
public void setToUserType(int toUserType) {
this.toUserType = toUserType;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getLocalHead() {
return localHead;
}
public void setLocalHead(int localHead) {
this.localHead = localHead;
}
// @Override
// public boolean equals(Object obj) {
// ContactItemBean bean = (ContactItemBean) obj;
// return !TextUtils.isEmpty(getToUserId()) && !TextUtils.isEmpty(bean.getToUserId()) ? getToUserId().equals(bean.getToUserId()) : false;
// }
//
// @Override
// public int hashCode() {
// return !TextUtils.isEmpty(getToUserId()) ? getToUserId().hashCode() : super.hashCode();
// }
@Override
public int compareTo(ContactItemBean o) {
String pingyin = PingYinUtil.getPingYin(o.getToNickname());
String pingy = PingYinUtil.getPingYin(this.getToNickname());
if (!TextUtils.isEmpty(pingy) && !TextUtils.isEmpty(pingyin)) {
return pingy.compareTo(pingyin);
}
return 0;
}
}
}
package com.rv.im.bean;
import com.google.gson.annotations.SerializedName;
import java.util.List;
/**
* 用户表
*/
......
package com.rv.im.presenter;
import com.ruiwenliu.wrapper.base.presenter.CommonPresenter;
import com.rv.component.utils.CacheEnum;
import com.rv.component.utils.RvCache;
import com.rv.im.AppConfig;
import com.rv.im.ImSetting;
import com.rv.im.R;
import com.rv.im.bean.ContactsBean;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AddressPresenter extends CommonPresenter {
/******
*
* 初始化好友列表
* @param lists
*/
public void initAddress(List<ContactsBean.ContactItemBean> lists) {
boolean isShowLoading = lists == null || lists.size() == 0;
addCustomerItem(lists);
addGroupItem(lists);
addNewFriendItem(lists);
ContactsBean bean = (ContactsBean) RvCache.getInstance().get(CacheEnum.CONTACTS);
if (bean != null && bean.getData() != null && bean.getData().size() > 0) {
lists.addAll(bean.getData());
}
pullFriends(isShowLoading);
}
private void addNewFriendItem(List<ContactsBean.ContactItemBean> lists) {
ContactsBean.ContactItemBean bean = new ContactsBean.ContactItemBean();
bean.setType(0);
bean.setToNickname(getPresenterContext().getString(R.string.text_new_friend));
bean.setLocalHead(R.drawable.icon_lion);
lists.add(bean);
}
private void addGroupItem(List<ContactsBean.ContactItemBean> lists) {
ContactsBean.ContactItemBean bean = new ContactsBean.ContactItemBean();
bean.setType(0);
bean.setToNickname(getPresenterContext().getString(R.string.text_group));
bean.setLocalHead(R.drawable.icon_lion);
lists.add(bean);
}
private void addCustomerItem(List<ContactsBean.ContactItemBean> lists) {
ContactsBean.ContactItemBean bean = new ContactsBean.ContactItemBean();
bean.setType(0);
bean.setToNickname(getPresenterContext().getString(R.string.text_customer_list));
bean.setLocalHead(R.drawable.icon_lion);
lists.add(bean);
}
/**
* 从服务端获取好友列表,更新数据库
*/
private void pullFriends(boolean isShowLoading) {
AppConfig appConfig = (AppConfig) RvCache.getInstance().get(CacheEnum.IM_CONFIG);
if (appConfig == null) return;
Map<String, String> params = new HashMap<>();
params.put("access_token", ImSetting.getImToken());
getData(0, appConfig.FRIENDS_ATTENTION_LIST, ContactsBean.class, params, isShowLoading);
}
}
package com.rv.im.util.sortlist;
import java.util.Comparator;
/**
* 根据首字母排序 #排序到最后面
*/
public class BaseComparator<T> implements Comparator<BaseSortModel<T>> {
public int compare(BaseSortModel<T> o1, BaseSortModel<T> o2) {
if (o1.getFirstLetter().equals("#")) {
if (o2.getFirstLetter().equals("#")) {
return o1.getWholeSpell().compareTo(o2.getWholeSpell());
} else {
return 1;
}
} else {
if (o2.getFirstLetter().equals("#")) {
return -1;
} else {
return o1.getWholeSpell().compareTo(o2.getWholeSpell());
}
}
}
}
package com.rv.im.util.sortlist;
public class BaseSortModel<T> {
public T bean;
public String firstLetter;// 首字母
public String wholeSpell;// 全拼
public String getFirstLetter() {
return firstLetter;
}
public void setFirstLetter(String firstLetter) {
this.firstLetter = firstLetter;
}
public String getWholeSpell() {
return wholeSpell;
}
public void setWholeSpell(String wholeSpell) {
this.wholeSpell = wholeSpell;
}
public T getBean() {
return bean;
}
public void setBean(T bean) {
this.bean = bean;
}
}
package com.rv.im.util.sortlist;
import android.text.TextUtils;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
public class PingYinUtil {
private static final HanyuPinyinOutputFormat format;
static {
format = new HanyuPinyinOutputFormat();
format.setCaseType(HanyuPinyinCaseType.UPPERCASE);
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
format.setVCharType(HanyuPinyinVCharType.WITH_V);
}
private static boolean isChineseCharacter(char ch) {
return '\u4E00' < ch && ch < '\u9FA5';
}
/**
* 将字符串中的中文转换为全拼<br/>
* 1、如果字符串为空,返回#<br/>
* 2、如为中文,张三输出ZHANGSAN<br/>
* 3、如果为字符 abc输出ABC<br/>
* 4、如果为其他字符,输入#<br/>
*/
public static String getPingYin(String inputString) {
if (TextUtils.isEmpty(inputString)) {
return "#";
}
char[] input = inputString.toCharArray();
StringBuilder output = new StringBuilder();
try {
for (char ch : input) {
if (isChineseCharacter(ch)) {
String[] temp = PinyinHelper.toHanyuPinyinStringArray(ch, format);
if (temp == null || temp.length == 0) {
// unicode_to_hanyu_pinyin.txt里写死了部分汉字没有拼音,比如\u8985, 覅,
// 也就是正常情况这个temp可能为空,
output.append("#");
} else {
output.append(temp[0]);
}
} else if (Character.isAlphabetic(ch)) {
output.append(Character.toUpperCase(ch));
} else {
output.append("#");
}
}
} catch (Exception e) {
}
return output.toString();
}
}
package com.rv.im.util.sortlist;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import com.sk.weichat.R;
import java.util.HashMap;
import java.util.Map;
public class SideBar extends View {
// 触摸事件
private OnTouchingLetterChangedListener onTouchingLetterChangedListener;
// 26个字母和#,首字母不是英文字母的放到#分类
public static String[] b = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W",
"X", "Y", "Z", "#"};
private int choose = -1;// 选中
private Paint paint = new Paint();
private TextView mTextDialog;
private Map<String, Integer> isExistMap;
public void setExistMap(Map<String, Integer> existMap) {
isExistMap = existMap;
invalidate();
}
public void addExist(String alphaet) {// 存在的Count+1
int count = 0;
if (isExistMap.containsKey(alphaet)) {
count = isExistMap.get(alphaet);
}
count++;
isExistMap.put(alphaet, count);
}
public void removeExist(String alphaet) {// 存在的Count-1,存在才减1,不存在则移除
int count = 0;
if (isExistMap.containsKey(alphaet)) {
count = isExistMap.get(alphaet);
}
if (count > 0) {
count--;
}
if (count > 0) {
isExistMap.put(alphaet, count);
} else {
isExistMap.remove(alphaet);
}
}
public void clearExist() {
isExistMap.clear();
}
public void setTextView(TextView mTextDialog) {
this.mTextDialog = mTextDialog;
}
public SideBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
isExistMap = new HashMap<String, Integer>();
}
public SideBar(Context context, AttributeSet attrs) {
super(context, attrs);
isExistMap = new HashMap<String, Integer>();
}
public SideBar(Context context) {
super(context);
isExistMap = new HashMap<String, Integer>();
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// 获取焦点改变背景颜色.
int height = getHeight();// 获取对应高度
int width = getWidth(); // 获取对应宽度
int singleHeight = height / b.length;// 获取每一个字母的高度
for (int i = 0; i < b.length; i++) {
paint.setColor(Color.parseColor("#555555"));
paint.setTypeface(Typeface.DEFAULT);
paint.setAntiAlias(true);
paint.setTextSize(28);
// 选中的状态
if (i == choose) {
paint.setColor(Color.parseColor("#4FC557"));
paint.setFakeBoldText(true);
}
// x坐标等于中间-字符串宽度的一半.
float xPos = width / 2 - paint.measureText(b[i]) / 2;
float yPos = singleHeight * i + singleHeight;
canvas.drawText(b[i], xPos, yPos, paint);
paint.reset();// 重置画笔
}
}
@SuppressWarnings("deprecation")
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
final int action = event.getAction();
final float y = event.getY();// 点击y坐标
final int oldChoose = choose;
final int c = (int) (y / getHeight() * b.length);// 点击y坐标所占总高度的比例*b数组的长度就等于点击b中的个数.
switch (action) {
case MotionEvent.ACTION_UP:
// setBackgroundDrawable(new ColorDrawable(0x00000000));
setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.app_white)));
choose = -1;//
invalidate();
if (mTextDialog != null) {
mTextDialog.setVisibility(View.INVISIBLE);
}
break;
default:
setBackgroundResource(R.drawable.sidebar_background);
if (oldChoose != c) {
if (c >= 0 && c < b.length) {
if (onTouchingLetterChangedListener != null) {
int count = 0;
if (isExistMap.containsKey(b[c])) {
count = isExistMap.get(b[c]);
}
if (count > 0) {
onTouchingLetterChangedListener.onTouchingLetterChanged(b[c]);
if (mTextDialog != null) {
mTextDialog.setText(b[c]);
mTextDialog.setVisibility(View.VISIBLE);
}
}
}
choose = c;
invalidate();
}
}
break;
}
return true;
}
/**
* 向外公开的方法
*
* @param onTouchingLetterChangedListener
*/
public void setOnTouchingLetterChangedListener(OnTouchingLetterChangedListener onTouchingLetterChangedListener) {
this.onTouchingLetterChangedListener = onTouchingLetterChangedListener;
}
/**
* 接口
*
* @author coder
*/
public interface OnTouchingLetterChangedListener {
public void onTouchingLetterChanged(String s);
}
}
\ No newline at end of file
package com.rv.im.util.sortlist;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import com.ruiwenliu.wrapper.util.LogUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class SortHelper {
public static void setSortCondition(BaseSortModel<?> mode, String name) {
String wholeSpell = PingYinUtil.getPingYin(name);
if (!TextUtils.isEmpty(wholeSpell)) {
String firstLetter = Character.toString(wholeSpell.charAt(0));
mode.setWholeSpell(wholeSpell);
mode.setFirstLetter(firstLetter);
} else {// 如果全拼为空,理论上是一种错误情况,因为这代表着昵称为空
mode.setWholeSpell("#");
mode.setFirstLetter("#");
}
}
public static <T> List<BaseSortModel<T>> toSortedModelList(List<T> beanList, Map<String, Integer> existMap, NameMapping<T> mapping) {
List<BaseSortModel<T>> ret = new ArrayList<>(beanList.size());
for (int i = 0; i < beanList.size(); i++) {
BaseSortModel<T> mode = new BaseSortModel<>();
mode.setBean(beanList.get(i));
String name = mapping.getName(mode.getBean());
if (name == null) {
continue;
}
setSortCondition(mode, name);
Integer exists = existMap.get(mode.firstLetter);
if (exists == null) {
exists = 0;
}
++exists;
existMap.put(mode.firstLetter, exists);
ret.add(mode);
}
Collections.sort(ret, (o1, o2) -> {
if (o1.getFirstLetter().equals("#")) {
if (o2.getFirstLetter().equals("#")) {
return o1.getWholeSpell().compareTo(o2.getWholeSpell());
} else {
return 1;
}
} else {
if (o2.getFirstLetter().equals("#")) {
return -1;
} else {
return o1.getWholeSpell().compareTo(o2.getWholeSpell());
}
}
});
return ret;
}
public interface NameMapping<T> {
/**
* 返回null表示过滤掉这个元素,
*/
@Nullable
String getName(T bean);
}
}
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AddressListActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_navigation"
android:layout_width="match_parent"
android:layout_height="@dimen/size_38"
android:background="@color/colorGray"
android:orientation="vertical">
<include layout="@layout/common_line" />
<TextView
android:id="@+id/tv_character"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="@dimen/dp_10"
android:layout_weight="1"
android:textSize="@dimen/sp_12" />
<include layout="@layout/common_line" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="58dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<com.base.utils.ui.image.round.RoundImageView
android:id="@+id/img_header"
android:layout_width="@dimen/dp40"
android:layout_height="@dimen/dp40"
android:layout_marginLeft="@dimen/dp_10"
android:contentDescription="@string/app_name"
android:src="@drawable/common_icon_avatar_default" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/dp_10"
android:gravity="center_vertical|left"
android:text="牧之"
android:textSize="@dimen/sp_14" />
</LinearLayout>
</LinearLayout>
......@@ -172,4 +172,10 @@
<string name="sava_video">保存视频</string>
<string name="tip_meet_server_empty">服务器地址为空</string>
<string name="title_address_list">通讯录</string>
<string name="text_customer_list">客服列表</string>
<string name="text_group">群聊</string>
<string name="text_new_friend">新的朋友</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