use of com.rongseal.bean.Friend in project SeaStar by 13120241790.
the class FriendsFragment method filledData.
/**
* 为ListView填充数据
*
* @param
* @return
*/
private List<Friend> filledData(List<Friend> lsit) {
List<Friend> mFriendList = new ArrayList<Friend>();
for (int i = 0; i < lsit.size(); i++) {
Friend friendModel = new Friend();
friendModel.setName(lsit.get(i).getName());
//汉字转换成拼音
String pinyin = characterParser.getSelling(lsit.get(i).getName());
String sortString = pinyin.substring(0, 1).toUpperCase();
// 正则表达式,判断首字母是否是英文字母
if (sortString.matches("[A-Z]")) {
friendModel.setLetters(sortString.toUpperCase());
} else {
friendModel.setLetters("#");
}
mFriendList.add(friendModel);
}
return mFriendList;
}
use of com.rongseal.bean.Friend in project SeaStar by 13120241790.
the class FriendsFragment method initView.
private void initView() {
//实例化汉字转拼音类
characterParser = CharacterParser.getInstance();
pinyinComparator = PinyinComparator.getInstance();
mAboutSerrch = (ClearWriteEditText) mView.findViewById(R.id.filter_edit);
mListView = (ListView) mView.findViewById(R.id.friendlistview);
mSidBar = (SideBar) mView.findViewById(R.id.sidrbar);
dialog = (TextView) mView.findViewById(R.id.dialog);
show_no_friends = (TextView) mView.findViewById(R.id.show_no_friends);
mSidBar.setTextView(dialog);
//设置右侧触摸监听
mSidBar.setOnTouchingLetterChangedListener(new SideBar.OnTouchingLetterChangedListener() {
@Override
public void onTouchingLetterChanged(String s) {
//该字母首次出现的位置
int position = adapter.getPositionForSection(s.charAt(0));
if (position != -1) {
mListView.setSelection(position);
}
}
});
//-------------- 获取好友列表数据 ---------------
friendDao = DBManager.getInstance(getActivity()).getDaoSession().getFriendDao();
QueryBuilder<com.rongseal.db.com.rongseal.database.Friend> qb = friendDao.queryBuilder();
if (qb.list().size() > 0 && qb.list() != null) {
for (int i = 0; i < qb.list().size(); i++) {
com.rongseal.db.com.rongseal.database.Friend bean = qb.list().get(i);
mSourceDateList.add(new Friend(bean.getUserId(), bean.getName(), bean.getPortraitUri()));
}
} else {
//TODO 是否需要网络再次拉取? login 已经拉取存数据库
NLog.e("database", "friend database is null");
}
//过滤数据对象为友字母字段
SourceDateList = filledData(mSourceDateList);
if (SourceDateList.size() > 0) {
show_no_friends.setVisibility(View.GONE);
}
for (int i = 0; i < mSourceDateList.size(); i++) {
SourceDateList.get(i).setUserId(mSourceDateList.get(i).getUserId());
SourceDateList.get(i).setName(mSourceDateList.get(i).getName());
SourceDateList.get(i).setUri(mSourceDateList.get(i).getUri());
}
mSourceDateList = null;
// 根据a-z进行排序源数据
Collections.sort(SourceDateList, pinyinComparator);
adapter = new FriendAdapter(getActivity(), SourceDateList);
mListView.setAdapter(adapter);
mListView.setOnItemLongClickListener(this);
mListView.setOnItemClickListener(this);
//根据输入框输入值的改变来过滤搜索 顶部实时搜索
mAboutSerrch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//当输入框里面的值为空,更新为原来的列表,否则为过滤数据列表
filterData(s.toString());
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
use of com.rongseal.bean.Friend in project SeaStar by 13120241790.
the class FriendsFragment method filterData.
/**
* 根据输入框中的值来过滤数据并更新ListView
*
* @param filterStr
*/
private void filterData(String filterStr) {
List<Friend> filterDateList = new ArrayList<Friend>();
if (TextUtils.isEmpty(filterStr)) {
filterDateList = SourceDateList;
} else {
filterDateList.clear();
for (Friend friendModel : SourceDateList) {
String name = friendModel.getName();
if (name.indexOf(filterStr.toString()) != -1 || characterParser.getSelling(name).startsWith(filterStr.toString())) {
filterDateList.add(friendModel);
}
}
}
// 根据a-z进行排序
Collections.sort(filterDateList, pinyinComparator);
adapter.updateListView(filterDateList);
}
use of com.rongseal.bean.Friend in project SeaStar by 13120241790.
the class StartDiscussionActivity method filledData.
/**
* 为ListView填充数据
*
* @param
* @return
*/
private List<Friend> filledData(List<Friend> lsit) {
List<Friend> mFriendList = new ArrayList<Friend>();
for (int i = 0; i < lsit.size(); i++) {
Friend friendModel = new Friend();
friendModel.setName(lsit.get(i).getName());
//汉字转换成拼音
String pinyin = characterParser.getSelling(lsit.get(i).getName());
String sortString = pinyin.substring(0, 1).toUpperCase();
// 正则表达式,判断首字母是否是英文字母
if (sortString.matches("[A-Z]")) {
friendModel.setLetters(sortString.toUpperCase());
} else {
friendModel.setLetters("#");
}
mFriendList.add(friendModel);
}
return mFriendList;
}
use of com.rongseal.bean.Friend in project SeaStar by 13120241790.
the class FriendAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
final Friend mContent = list.get(position);
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.friend_item, null);
viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.friendname);
viewHolder.tvLetter = (TextView) convertView.findViewById(R.id.catalog);
viewHolder.mImageView = (CircleImageView) convertView.findViewById(R.id.frienduri);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
//根据position获取分类的首字母的Char ascii值
int section = getSectionForPosition(position);
//如果当前位置等于该分类首字母的Char的位置 ,则认为是第一次出现
if (position == getPositionForSection(section)) {
viewHolder.tvLetter.setVisibility(View.VISIBLE);
viewHolder.tvLetter.setText(mContent.getLetters());
} else {
viewHolder.tvLetter.setVisibility(View.GONE);
}
viewHolder.tvTitle.setText(this.list.get(position).getName());
String url = this.list.get(position).getUri();
if (!TextUtils.isEmpty(url)) {
ImageLoader.getInstance().displayImage(url, viewHolder.mImageView, App.getOptions());
}
return convertView;
}
Aggregations