|
|
@@ -1,462 +0,0 @@
|
|
|
-package com.uas.appcontact.ui.fragment;
|
|
|
-
|
|
|
-import android.content.BroadcastReceiver;
|
|
|
-import android.content.Context;
|
|
|
-import android.content.Intent;
|
|
|
-import android.content.IntentFilter;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.support.v4.content.LocalBroadcastManager;
|
|
|
-import android.text.Editable;
|
|
|
-import android.text.TextUtils;
|
|
|
-import android.view.Gravity;
|
|
|
-import android.view.LayoutInflater;
|
|
|
-import android.view.Menu;
|
|
|
-import android.view.MenuInflater;
|
|
|
-import android.view.MenuItem;
|
|
|
-import android.view.View;
|
|
|
-import android.widget.AdapterView;
|
|
|
-import android.widget.LinearLayout;
|
|
|
-import android.widget.PopupWindow;
|
|
|
-import android.widget.TextView;
|
|
|
-
|
|
|
-import com.common.data.ListUtils;
|
|
|
-import com.common.data.StringUtil;
|
|
|
-import com.common.system.DisplayUtil;
|
|
|
-import com.common.thread.ThreadUtil;
|
|
|
-import com.core.api.wxapi.ApiPlatform;
|
|
|
-import com.core.api.wxapi.ApiUtils;
|
|
|
-import com.core.app.Constants;
|
|
|
-import com.core.app.MyApplication;
|
|
|
-import com.core.base.EasyFragment;
|
|
|
-import com.core.broadcast.MsgBroadcast;
|
|
|
-import com.core.model.EmployeesEntity;
|
|
|
-import com.core.model.Friend;
|
|
|
-import com.core.net.http.http.OAHttpHelper;
|
|
|
-import com.core.utils.CommonUtil;
|
|
|
-import com.core.utils.sortlist.BaseComparator;
|
|
|
-import com.core.utils.sortlist.BaseSortModel;
|
|
|
-import com.core.utils.sortlist.PingYinUtil;
|
|
|
-import com.core.utils.sortlist.SideBar;
|
|
|
-import com.core.widget.CustomProgressDialog;
|
|
|
-import com.core.widget.VoiceSearchView;
|
|
|
-import com.core.widget.listener.EditChangeListener;
|
|
|
-import com.core.app.AppConstant;
|
|
|
-import com.uas.appcontact.R;
|
|
|
-import com.uas.appcontact.adapter.FriendSortAdapter;
|
|
|
-import com.uas.appcontact.listener.ImStatusListener;
|
|
|
-import com.uas.appcontact.manager.ContactsManager;
|
|
|
-import com.uas.appcontact.ui.activity.CommonFragmentActivity;
|
|
|
-import com.uas.appcontact.ui.activity.CompanyContactsActivity;
|
|
|
-import com.uas.appcontact.ui.activity.ContactsActivity;
|
|
|
-import com.uas.appcontact.ui.activity.MyFriendActivity;
|
|
|
-import com.uas.appcontact.ui.activity.NewFriendActivity;
|
|
|
-import com.uas.appcontact.ui.activity.PlatContactAddPeopleActivity;
|
|
|
-import com.uas.appcontact.ui.activity.UserSearchActivity;
|
|
|
-import com.uas.appcontact.ui.widget.stickylistheaders.StickyListHeadersListView;
|
|
|
-import com.yalantis.phoenix.PullToRefreshView;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by pengminggong on 2016/10/12.
|
|
|
- */
|
|
|
-public class ContactFragment extends EasyFragment implements View.OnClickListener, ContactsManager.OnEmployListener {
|
|
|
- private SideBar sidebar;
|
|
|
- private TextView text_dialog;
|
|
|
- private StickyListHeadersListView refreshListView;
|
|
|
- private PullToRefreshView mPullToRefreshView;
|
|
|
- private TextView tv_uu_new;
|
|
|
- private FriendSortAdapter adapter;
|
|
|
- private String loginUserId;
|
|
|
- private List<BaseSortModel<Friend>> showDatas;//显示的数据
|
|
|
- private List<BaseSortModel<Friend>> allDatas;//获取到的全部数据
|
|
|
- private BaseComparator comparator;
|
|
|
- private VoiceSearchView voiceSearchView;
|
|
|
-
|
|
|
- private CustomProgressDialog mcProgressDialog;
|
|
|
-
|
|
|
- private boolean isB2b;
|
|
|
-
|
|
|
- private IntentFilter inputFilter;
|
|
|
- private BroadcastReceiver receiver = new BroadcastReceiver() {
|
|
|
- @Override
|
|
|
- public void onReceive(Context context, Intent intent) {
|
|
|
- if (intent.getAction().equals("com.app.home.update") || intent.getAction().equals(MsgBroadcast.ACTION_MSG_COMPANY_UPDATE)) {//账套变更,重新刷新数据,初始化任务
|
|
|
- loadData();
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- private ImStatusListener mListener;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onAttach(Context context) {
|
|
|
- super.onAttach(context);
|
|
|
- if (context instanceof ImStatusListener) {
|
|
|
- mListener = (ImStatusListener) context;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCreate(Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- inputFilter = new IntentFilter();
|
|
|
- inputFilter.addAction(MsgBroadcast.ACTION_MSG_COMPANY_UPDATE);
|
|
|
- inputFilter.addAction("com.app.home.update");
|
|
|
- LocalBroadcastManager.getInstance(ct).registerReceiver(receiver, inputFilter);
|
|
|
- setHasOptionsMenu(true);
|
|
|
- isB2b = ApiUtils.getApiModel() instanceof ApiPlatform;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected int inflateLayoutId() {
|
|
|
- return R.layout.fragment_contact;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onDestroy() {
|
|
|
- super.onDestroy();
|
|
|
- LocalBroadcastManager.getInstance(ct).unregisterReceiver(receiver);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
- super.onCreateOptionsMenu(menu, inflater);
|
|
|
- inflater.inflate(R.menu.menu_nearby, menu);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
- if (item.getItemId() == R.id.search) {
|
|
|
- if (!isB2b) {
|
|
|
- startActivity(new Intent(getActivity(), UserSearchActivity.class));
|
|
|
- } else {
|
|
|
- showPopupWindow();
|
|
|
- }
|
|
|
- }
|
|
|
- return super.onOptionsItemSelected(item);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void showPopupWindow() {
|
|
|
- View viewContext = LayoutInflater.from(getActivity()).inflate(R.layout.contact_add_menu, null);
|
|
|
- final PopupWindow setWindow = new PopupWindow(viewContext,
|
|
|
- LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
- LinearLayout.LayoutParams.WRAP_CONTENT, true);
|
|
|
- viewContext.findViewById(R.id.add_friend_tv).setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- startActivity(new Intent(getActivity(), UserSearchActivity.class));
|
|
|
- if (setWindow != null) {
|
|
|
- setWindow.dismiss();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- viewContext.findViewById(R.id.add_people_tv).setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- startActivity(new Intent(getActivity(), PlatContactAddPeopleActivity.class));
|
|
|
- if (setWindow != null) {
|
|
|
- setWindow.dismiss();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- setWindow.setAnimationStyle(R.style.MenuAnimationFade);
|
|
|
- setWindow.setBackgroundDrawable(ct.getResources().getDrawable(R.drawable.bg_popuwin));
|
|
|
- setWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
- @Override
|
|
|
- public void onDismiss() {
|
|
|
- DisplayUtil.backgroundAlpha(getActivity(), 1f);
|
|
|
- }
|
|
|
- });
|
|
|
- setWindow.showAtLocation(getActivity().getWindow().getDecorView().
|
|
|
- findViewById(android.R.id.content), Gravity.CENTER, 0, 0);
|
|
|
- DisplayUtil.backgroundAlpha(getActivity(), 0.4f);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreateView(Bundle savedInstanceState, boolean createView) {
|
|
|
- if (createView) {
|
|
|
- initView();
|
|
|
- initEvent();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void initEvent() {
|
|
|
- //侧边栏检索
|
|
|
- sidebar.setOnTouchingLetterChangedListener(new SideBar.OnTouchingLetterChangedListener() {
|
|
|
- @Override
|
|
|
- public void onTouchingLetterChanged(String s) {
|
|
|
- // 该字母首次出现的位置
|
|
|
- int position = adapter.getPositionForSection(s.charAt(0));
|
|
|
- if (position != -1) {
|
|
|
- int count = refreshListView.getHeaderViewsCount();
|
|
|
- refreshListView.setSelection(position + count);
|
|
|
- }
|
|
|
- if ("↑".equals(s)) {
|
|
|
- refreshListView.setSelection(0);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onTouchingUp() {
|
|
|
- }
|
|
|
- });
|
|
|
- mPullToRefreshView.setOnRefreshListener(new PullToRefreshView.OnRefreshListener() {
|
|
|
- @Override
|
|
|
- public void onRefresh() {
|
|
|
- if ("1".equals(CommonUtil.getUserRole())) {
|
|
|
- mPullToRefreshView.setRefreshing(false, false);
|
|
|
- mcProgressDialog.dismiss();
|
|
|
- } else {
|
|
|
- ContactsManager.getInstance().loadContactByNet(ContactFragment.this);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- //item点击事件处理
|
|
|
- refreshListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
- @Override
|
|
|
- public void onItemClick(AdapterView<?> adapterView, View view, int i, long id) {
|
|
|
- List<BaseSortModel<Friend>> list = adapter.getmSortFriends();
|
|
|
- if (!ListUtils.isEmpty(list)) {
|
|
|
- Friend friend = list.get((int) id).getBean();
|
|
|
- clickFriend(friend);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- //搜索框处理
|
|
|
- if (voiceSearchView == null) return;
|
|
|
- voiceSearchView.addTextChangedListener(new EditChangeListener() {
|
|
|
- @Override
|
|
|
- public void afterTextChanged(Editable editable) {
|
|
|
- String str = editable == null ? "" : editable.toString();
|
|
|
- upDataBySearch(str);
|
|
|
- adapter.setData(showDatas);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void initView() {
|
|
|
- sidebar = (SideBar) findViewById(R.id.sidebar);
|
|
|
- text_dialog = (TextView) findViewById(R.id.text_dialog);
|
|
|
- mPullToRefreshView = (PullToRefreshView) findViewById(R.id.contact_ptrv);
|
|
|
- refreshListView = (StickyListHeadersListView) findViewById(R.id.pull_refresh_list);
|
|
|
- showDatas = new ArrayList<>();
|
|
|
- allDatas = new ArrayList<>();
|
|
|
- mcProgressDialog = CustomProgressDialog.createDialog(ct);
|
|
|
- comparator = new BaseComparator();
|
|
|
- loginUserId = MyApplication.getInstance().mLoginUser.getUserId();
|
|
|
- sidebar.setTextView(text_dialog);
|
|
|
- setHeaderView();
|
|
|
- adapter = new FriendSortAdapter(ct, showDatas);
|
|
|
- refreshListView.setAdapter(adapter);
|
|
|
- loadData();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onResume() {
|
|
|
- super.onResume();
|
|
|
- mPullToRefreshView.setRefreshing(false, false);
|
|
|
- }
|
|
|
-
|
|
|
- /*设置头文件*/
|
|
|
- private void setHeaderView() {
|
|
|
- View headview = LayoutInflater.from(ct).inflate(R.layout.header_fragment_contact, null);
|
|
|
- refreshListView.addHeaderView(headview);
|
|
|
- voiceSearchView = (VoiceSearchView) headview.findViewById(R.id.voiceSearchView);
|
|
|
-
|
|
|
- headview.findViewById(R.id.company).setOnClickListener(this);//企业结构
|
|
|
- headview.findViewById(R.id.group).setOnClickListener(this);//商务群
|
|
|
- headview.findViewById(R.id.uu_friend).setOnClickListener(this);//我的好友
|
|
|
- headview.findViewById(R.id.peculiar_tv).setOnClickListener(this);//我的好友
|
|
|
- tv_uu_new = (TextView) headview.findViewById(R.id.tv_uu_new);
|
|
|
- tv_uu_new.setVisibility(CommonUtil.getSharedPreferencesBoolean(ct, Constants.SET_UU_NEW, false) ? View.GONE : View.VISIBLE);
|
|
|
- }
|
|
|
-
|
|
|
- private void clickFriend(Friend friend) {
|
|
|
- Intent intent = null;
|
|
|
- if (friend.getUserId().equals(Friend.ID_NEW_FRIEND_MESSAGE)) {// 新朋友消息
|
|
|
- intent = new Intent(getActivity(), NewFriendActivity.class);
|
|
|
- } else if (friend.getUserId().equals(Friend.ID_SYSTEM_MESSAGE)) {// 新朋友消息
|
|
|
- intent = new Intent("com.modular.message.ChatActivity");
|
|
|
- intent.putExtra("friend", friend);
|
|
|
- } else {
|
|
|
- intent = new Intent("com.modular.basic.BasicInfoActivity");
|
|
|
- intent.putExtra(AppConstant.EXTRA_NICK_CODE, friend.getPhone());
|
|
|
- intent.putExtra(AppConstant.EXTRA_USER_ID, friend.getUserId());
|
|
|
- intent.putExtra(AppConstant.EXTRA_NICK_NAME, friend.getNickName());
|
|
|
- intent.putExtra(AppConstant.EXTRA_EM_CODE, friend.getEmCode());
|
|
|
- intent.putExtra("friend", friend);
|
|
|
- }
|
|
|
- startActivity(intent);
|
|
|
- }
|
|
|
-
|
|
|
- void showLoading() {
|
|
|
-
|
|
|
- }//显示刷新
|
|
|
-
|
|
|
- void dimssLoading() {
|
|
|
-
|
|
|
- }//关闭刷新
|
|
|
-
|
|
|
- private void loadData() {
|
|
|
- showLoading();
|
|
|
- ContactsManager.getInstance().loadContact(this);
|
|
|
- }
|
|
|
-
|
|
|
- private void handlerData(List<BaseSortModel<Friend>> friends) {
|
|
|
- allDatas = friends;
|
|
|
- if (voiceSearchView == null || TextUtils.isEmpty(voiceSearchView.getText())) {//没有搜索数据
|
|
|
- showDatas = friends;
|
|
|
- } else {//
|
|
|
- String str = voiceSearchView.getText().toString();
|
|
|
- upDataBySearch(str);
|
|
|
- }
|
|
|
- OAHttpHelper.getInstance().post(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- if (adapter == null) return;
|
|
|
- adapter.setData(showDatas);
|
|
|
- mPullToRefreshView.setRefreshing(false);
|
|
|
- if (mcProgressDialog.isShowing())
|
|
|
- mcProgressDialog.dismiss();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 当搜索框有字时候获取
|
|
|
- *
|
|
|
- * @param str 搜索框文字
|
|
|
- */
|
|
|
- private void upDataBySearch(String str) {
|
|
|
- if (ListUtils.isEmpty(allDatas)) return;
|
|
|
- showDatas = new ArrayList<>();
|
|
|
- for (BaseSortModel<Friend> e : allDatas) {
|
|
|
- String text = e.getBean().getShowName() + e.getBean().getDepart() + e.getBean().getPosition() + e.getBean().getPhone();
|
|
|
- if (StringUtil.isInclude(text, str)) {
|
|
|
- showDatas.add(e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 想获取到的人员列表数据整合为Friend数据列表
|
|
|
- *
|
|
|
- * @return 查询到数据列表
|
|
|
- */
|
|
|
- private List<BaseSortModel<Friend>> getFriendsByErpDB(List<EmployeesEntity> emList) throws Exception {
|
|
|
- if (ListUtils.isEmpty(emList)) return null;
|
|
|
- List<BaseSortModel<Friend>> list = new ArrayList<>();
|
|
|
- for (EmployeesEntity e : emList) {
|
|
|
- list.add(getFriendByErp(e));
|
|
|
- }
|
|
|
- if (ListUtils.isEmpty(list)) {
|
|
|
- list = new ArrayList<>();
|
|
|
- } else {
|
|
|
- Collections.sort(list, comparator);
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 将Rep转化为Friend对象
|
|
|
- *
|
|
|
- * @param e 员工对象
|
|
|
- * @return
|
|
|
- */
|
|
|
- private BaseSortModel<Friend> getFriendByErp(EmployeesEntity e) {
|
|
|
- Friend friend = new Friend();
|
|
|
- friend.setTimeCreate((int) (System.currentTimeMillis() / 1000));
|
|
|
- friend.setOwnerId(loginUserId);
|
|
|
- friend.setUserId(String.valueOf(e.getEm_IMID()));
|
|
|
- friend.setNickName(e.getEM_NAME());
|
|
|
- friend.setPhone(e.getEM_MOBILE());
|
|
|
- friend.setDepart(e.getEM_DEPART());
|
|
|
- friend.setPosition(e.getEM_POSITION());
|
|
|
- friend.setEmCode(e.getEM_CODE());
|
|
|
- friend.setPrivacy(e.getEM_EMAIL());
|
|
|
- friend.setCompanyId(0);
|
|
|
- friend.setRoomFlag(0);// 0朋友 1群组
|
|
|
- friend.setStatus(Friend.STATUS_UNKNOW);
|
|
|
- BaseSortModel<Friend> mode = new BaseSortModel<>();
|
|
|
- mode.setBean(friend);
|
|
|
- setSortCondition(mode);
|
|
|
- return mode;
|
|
|
- }
|
|
|
-
|
|
|
- /*设置当前mode所在的索引值*/
|
|
|
- private void setSortCondition(BaseSortModel<Friend> mode) {
|
|
|
- Friend friend = mode.getBean();
|
|
|
- if (friend == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- String name = friend.getShowName();
|
|
|
- String wholeSpell = PingYinUtil.getPingYin(name);
|
|
|
- if (!StringUtil.isEmpty(wholeSpell)) {
|
|
|
- try {
|
|
|
- String firstLetter = Character.toString(wholeSpell.charAt(0));
|
|
|
- sidebar.addExist(firstLetter);
|
|
|
- mode.setWholeSpell(wholeSpell);
|
|
|
- mode.setFirstLetter(firstLetter);
|
|
|
- mode.setSimpleSpell(PingYinUtil.converterToFirstSpell(name));
|
|
|
- } catch (NullPointerException e) {
|
|
|
-
|
|
|
- }
|
|
|
- } else {// 如果全拼为空,理论上是一种错误情况,因为这代表着昵称为空
|
|
|
- mode.setWholeSpell("#");
|
|
|
- mode.setFirstLetter("#");
|
|
|
- mode.setSimpleSpell("#");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onClick(View view) {
|
|
|
- Intent intent = null;
|
|
|
- int id = view.getId();
|
|
|
- if (id == R.id.company) {
|
|
|
- intent = new Intent(ct, CompanyContactsActivity.class);
|
|
|
- ct.startActivity(intent);
|
|
|
- } else if (id == R.id.group) {
|
|
|
- intent = new Intent(ct, CommonFragmentActivity.class);
|
|
|
- intent.putExtra("imStatus", mListener == null ? 0 : mListener.getmImStatus());
|
|
|
- intent.putExtra("type", Constants.TYPE_CHAT_All);
|
|
|
- ct.startActivity(intent);
|
|
|
- } else if (id == R.id.uu_friend) {
|
|
|
- startActivity(new Intent(ct, ContactsActivity.class));
|
|
|
- tv_uu_new.setVisibility(View.GONE);
|
|
|
- CommonUtil.setSharedPreferences(MyApplication.getInstance(), Constants.SET_UU_NEW, true);
|
|
|
- } else if (id == R.id.peculiar_tv) {
|
|
|
- intent = new Intent(ct, MyFriendActivity.class);
|
|
|
- intent.putExtra("isPeculiar", true);
|
|
|
- ct.startActivity(intent);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void callback(List<EmployeesEntity> employees) {
|
|
|
- try {
|
|
|
- final List<BaseSortModel<Friend>> friends = getFriendsByErpDB(employees);
|
|
|
- ThreadUtil.getInstance().addTask(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- handlerData(friends);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- dimssLoading();
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|