|
|
@@ -1,1025 +0,0 @@
|
|
|
-package com.xzjmyk.pm.activity.ui.erp.fragment;
|
|
|
-
|
|
|
-import android.app.Activity;
|
|
|
-import android.app.AlertDialog;
|
|
|
-import android.app.ProgressDialog;
|
|
|
-import android.content.BroadcastReceiver;
|
|
|
-import android.content.ComponentName;
|
|
|
-import android.content.Context;
|
|
|
-import android.content.DialogInterface;
|
|
|
-import android.content.Intent;
|
|
|
-import android.content.IntentFilter;
|
|
|
-import android.content.ServiceConnection;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.os.Handler;
|
|
|
-import android.os.IBinder;
|
|
|
-import android.os.Message;
|
|
|
-import android.text.Editable;
|
|
|
-import android.text.InputFilter;
|
|
|
-import android.text.TextUtils;
|
|
|
-import android.text.TextWatcher;
|
|
|
-import android.util.Log;
|
|
|
-import android.view.LayoutInflater;
|
|
|
-import android.view.Menu;
|
|
|
-import android.view.MenuInflater;
|
|
|
-import android.view.MenuItem;
|
|
|
-import android.view.View;
|
|
|
-import android.view.ViewGroup;
|
|
|
-import android.widget.AdapterView;
|
|
|
-import android.widget.EditText;
|
|
|
-import android.widget.ListView;
|
|
|
-import android.widget.TextView;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.android.volley.Response;
|
|
|
-import com.android.volley.VolleyError;
|
|
|
-import com.handmark.pulltorefresh.library.PullToRefreshBase;
|
|
|
-import com.handmark.pulltorefresh.library.PullToRefreshListView;
|
|
|
-import com.xzjmyk.pm.activity.AppConstant;
|
|
|
-import com.xzjmyk.pm.activity.MyApplication;
|
|
|
-import com.xzjmyk.pm.activity.R;
|
|
|
-import com.xzjmyk.pm.activity.adapter.FriendSortAdapter;
|
|
|
-import com.xzjmyk.pm.activity.bean.AttentionUser;
|
|
|
-import com.xzjmyk.pm.activity.bean.Friend;
|
|
|
-import com.xzjmyk.pm.activity.bean.message.NewFriendMessage;
|
|
|
-import com.xzjmyk.pm.activity.bean.message.XmppMessage;
|
|
|
-import com.xzjmyk.pm.activity.broadcast.MsgBroadcast;
|
|
|
-import com.xzjmyk.pm.activity.db.dao.FriendDao;
|
|
|
-import com.xzjmyk.pm.activity.db.dao.OnCompleteListener;
|
|
|
-import com.xzjmyk.pm.activity.helper.FriendHelper;
|
|
|
-import com.xzjmyk.pm.activity.sortlist.BaseComparator;
|
|
|
-import com.xzjmyk.pm.activity.sortlist.BaseSortModel;
|
|
|
-import com.xzjmyk.pm.activity.sortlist.PingYinUtil;
|
|
|
-import com.xzjmyk.pm.activity.sortlist.SideBar;
|
|
|
-import com.xzjmyk.pm.activity.ui.MainActivity;
|
|
|
-import com.xzjmyk.pm.activity.ui.base.XutilsFragment;
|
|
|
-import com.xzjmyk.pm.activity.ui.circle.BasicInfoActivity;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.activity.CommonFragmentActivity;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.activity.CompanyContactsActivity;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.activity.MyFriendActivity;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.adapter.ContactExpanAdapter;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.db.DBManager;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.entity.EmployeesEntity;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.entity.HrorgsEntity;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.util.Constants;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.util.ListUtils;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.util.ViewUtil;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.view.CustomProgressDialog;
|
|
|
-import com.xzjmyk.pm.activity.ui.message.ChatActivity;
|
|
|
-import com.xzjmyk.pm.activity.ui.message.NewFriendActivity;
|
|
|
-import com.xzjmyk.pm.activity.ui.nearby.UserSearchActivity;
|
|
|
-import com.xzjmyk.pm.activity.util.ProgressDialogUtil;
|
|
|
-import com.xzjmyk.pm.activity.util.StringUtils;
|
|
|
-import com.xzjmyk.pm.activity.util.ToastUtil;
|
|
|
-import com.xzjmyk.pm.activity.view.ClearEditText;
|
|
|
-import com.xzjmyk.pm.activity.volley.ArrayResult;
|
|
|
-import com.xzjmyk.pm.activity.volley.ObjectResult;
|
|
|
-import com.xzjmyk.pm.activity.volley.Result;
|
|
|
-import com.xzjmyk.pm.activity.volley.StringJsonArrayRequest;
|
|
|
-import com.xzjmyk.pm.activity.volley.StringJsonObjectRequest;
|
|
|
-import com.xzjmyk.pm.activity.xmpp.CoreService;
|
|
|
-
|
|
|
-import java.text.ParseException;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-import static com.xzjmyk.pm.activity.R.id.company;
|
|
|
-
|
|
|
-
|
|
|
-/**
|
|
|
- * @desc:联系人
|
|
|
- * @author:Administrator on 2016/1/30 16:15
|
|
|
- */
|
|
|
-@Deprecated
|
|
|
-public class LinksManFragment extends XutilsFragment implements View.OnClickListener {
|
|
|
- private Context ct;
|
|
|
- private PullToRefreshListView mPullToRefreshListView;
|
|
|
- private TextView mTextDialog;
|
|
|
- private SideBar mSideBar;
|
|
|
- private ProgressDialog mProgressDialog;
|
|
|
- private CustomProgressDialog mcProgressDialog;
|
|
|
- private List<BaseSortModel<Friend>> mSortFriends;
|
|
|
- private List<BaseSortModel<Friend>> sortFrientSeach;
|
|
|
- private BaseComparator<Friend> mBaseComparator;
|
|
|
- private FriendSortAdapter mAdapter;
|
|
|
- private String mLoginUserId;
|
|
|
- private Handler mHandler = new Handler() {
|
|
|
- @Override
|
|
|
- public void handleMessage(Message msg) {
|
|
|
- switch (msg.what) {
|
|
|
- case LOAD_COMPANYDATA_SUCESS://企业架构数据
|
|
|
- String result = msg.getData().getString("result");
|
|
|
- JSONObject jsonobject = JSON.parseObject(result);
|
|
|
- String server_time = jsonobject.getString("sysdate");
|
|
|
- List<HrorgsEntity> hrorgsEntities = JSON.parseArray(jsonobject.getString("hrorgs"), HrorgsEntity.class);
|
|
|
- List<EmployeesEntity> employeesEntities = JSON.parseArray(jsonobject.getString("employees"), EmployeesEntity.class);
|
|
|
- String master = CommonUtil.getSharedPreferences(ct, "erp_master");
|
|
|
- HrorgsEntity hrEntity = manager.select_getRootData(new String[]{master}, "whichsys=?");
|
|
|
- boolean isFristLoad = true;//是否第一次加载
|
|
|
- if (hrEntity != null) {
|
|
|
- isFristLoad = false;
|
|
|
- }
|
|
|
- if (!hrorgsEntities.isEmpty() || !employeesEntities.isEmpty()) {
|
|
|
- insertDataSqlite(isFristLoad, hrorgsEntities, employeesEntities,
|
|
|
- server_time); //写入缓存
|
|
|
- loadData();//同步数据库之后更新界面
|
|
|
- } else {
|
|
|
- //取缓存
|
|
|
- loadData();
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
- private boolean mNeedUpdate = true;
|
|
|
- private Activity mActivity;
|
|
|
- private DBManager manager;
|
|
|
- private int groupHeight = 0;
|
|
|
- //接收修改F司广播
|
|
|
- private IntentFilter inputFilter;
|
|
|
- private BroadcastReceiver receiver = new BroadcastReceiver() {
|
|
|
- @Override
|
|
|
- public void onReceive(Context context, Intent intent) {
|
|
|
- if ("home".equals(intent.getStringExtra("falg"))) {
|
|
|
- upDataFriend();
|
|
|
- loadCompanyData();//切换账套之后会触发加载企业通讯录数据的方法---该方法内部实现了缓存处理
|
|
|
- } else if (intent.getBooleanExtra("isGood", false)) {
|
|
|
- updateGoodFriend();
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
-
|
|
|
- private ClearEditText search_edit;
|
|
|
- private View headview;
|
|
|
- private ContactExpanAdapter adapter;
|
|
|
-
|
|
|
- public void onResult() {
|
|
|
- upDataFriend();
|
|
|
- loadData();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- Intent intent = null;
|
|
|
- switch (v.getId()) {
|
|
|
- case R.id.company://企业架构
|
|
|
- intent = new Intent(ct, CompanyContactsActivity.class);
|
|
|
- ((MainActivity) ct).startActivityForResult(intent, MainActivity.UPDATA_LIST);
|
|
|
- break;
|
|
|
- case R.id.uu_friend://UU好友
|
|
|
- intent = new Intent(ct, MyFriendActivity.class);
|
|
|
- ct.startActivity(intent);
|
|
|
- break;
|
|
|
- case R.id.group://商务群
|
|
|
- intent = new Intent(ct, CommonFragmentActivity.class);
|
|
|
- intent.putExtra("type", Constants.TYPE_CHAT_All);
|
|
|
- ct.startActivity(intent);
|
|
|
- break;
|
|
|
-
|
|
|
- case R.id.peculiar_tv://我的关注
|
|
|
- intent = new Intent(ct, MyFriendActivity.class);
|
|
|
- intent.putExtra("isPeculiar", true);
|
|
|
- ct.startActivity(intent);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public LinksManFragment() {
|
|
|
- mSortFriends = new ArrayList<>();
|
|
|
- sortFrientSeach = new ArrayList<>();
|
|
|
- mBaseComparator = new BaseComparator<Friend>();
|
|
|
- mLoginUserId = MyApplication.getInstance().mLoginUser.getUserId();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected int inflateLayoutId() {
|
|
|
- return R.layout.fragment_friend;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCreate(Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- inputFilter = new IntentFilter("com.app.home.update");
|
|
|
- getActivity().registerReceiver(receiver, inputFilter);
|
|
|
- setHasOptionsMenu(true);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreateView(Bundle savedInstanceState, boolean createView) {
|
|
|
- if (createView) {
|
|
|
- ct = getActivity();
|
|
|
- initView();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void upDataFriend() {
|
|
|
- HashMap<String, String> params = new HashMap<String, String>();
|
|
|
- params.put("access_token", MyApplication.getInstance().mAccessToken);
|
|
|
- Log.i("url", "相互关注:" + MyApplication.getInstance().getConfig().FRIENDS_ATTENTION_LIST);
|
|
|
- StringJsonArrayRequest<AttentionUser> request = new StringJsonArrayRequest<AttentionUser>(
|
|
|
- MyApplication.getInstance().getConfig().FRIENDS_ATTENTION_LIST, new Response.ErrorListener() {
|
|
|
- @Override
|
|
|
- public void onErrorResponse(VolleyError arg0) {
|
|
|
- ToastUtil.showErrorNet(mActivity);
|
|
|
- }
|
|
|
- }, new StringJsonArrayRequest.Listener<AttentionUser>() {
|
|
|
- @Override
|
|
|
- public void onResponse(ArrayResult<AttentionUser> result) {
|
|
|
- boolean success = Result.defaultParser(mActivity, result, false);
|
|
|
- if (success) {
|
|
|
- FriendDao.getInstance().addAttentionUsers(mHandler, MyApplication.getInstance().mLoginUser.getUserId(), result.getData(),
|
|
|
- new OnCompleteListener() {
|
|
|
- @Override
|
|
|
- public void onCompleted() {
|
|
|
- mPullToRefreshListView.getRefreshableView();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }, AttentionUser.class, params);
|
|
|
- MyApplication.getInstance().getFastVolley().addDefaultRequest(HASHCODE, request);
|
|
|
- }
|
|
|
-
|
|
|
- private ServiceConnection mServiceConnection = new ServiceConnection() {
|
|
|
- @Override
|
|
|
- public void onServiceDisconnected(ComponentName name) {
|
|
|
- mXmppService = null;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onServiceConnected(ComponentName name, IBinder service) {
|
|
|
- mXmppService = ((CoreService.CoreServiceBinder) service).getService();
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- private void initView() {
|
|
|
- mcProgressDialog = CustomProgressDialog.createDialog(ct);
|
|
|
- mcProgressDialog.show();
|
|
|
- mBind = getActivity().bindService(CoreService.getIntent(), mServiceConnection, Activity.BIND_AUTO_CREATE);
|
|
|
- mTextDialog = (TextView) findViewById(R.id.text_dialog);
|
|
|
- mSideBar = (SideBar) findViewById(R.id.sidebar);
|
|
|
- mSideBar.setTextView(mTextDialog);
|
|
|
- setHeaderView();
|
|
|
- //查好友
|
|
|
- search_edit.addTextChangedListener(new TextWatcher() {
|
|
|
- @Override
|
|
|
- public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void afterTextChanged(Editable editable) {
|
|
|
- sortFrientSeach.clear();
|
|
|
- String filter = editable.toString().trim();
|
|
|
- if (filter.length() > 0) {
|
|
|
- for (BaseSortModel<Friend> e : mSortFriends) {
|
|
|
- if (!StringUtils.isEmpty(e.getBean().getShowName()) && com.xzjmyk.pm.activity.ui.erp.util.StringUtils.isInclude(e.getBean().getShowName(), filter)) {
|
|
|
- sortFrientSeach.add(e);
|
|
|
- }
|
|
|
- }
|
|
|
- mAdapter.setData(sortFrientSeach);
|
|
|
- } else {
|
|
|
-
|
|
|
- mAdapter.setData(mSortFriends);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- mSideBar.setOnTouchingLetterChangedListener(new SideBar.OnTouchingLetterChangedListener() {
|
|
|
- @Override
|
|
|
- public void onTouchingLetterChanged(String s) {
|
|
|
- // 该字母首次出现的位置
|
|
|
- int position = mAdapter.getPositionForSection(s.charAt(0));
|
|
|
- if (position != -1) {
|
|
|
- int count = mPullToRefreshListView.getRefreshableView().getHeaderViewsCount();
|
|
|
- mPullToRefreshListView.getRefreshableView().setSelection(position + count);
|
|
|
- }
|
|
|
- if ("↑".equals(s)) {
|
|
|
- mPullToRefreshListView.getRefreshableView().setSelection(1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onTouchingUp() {
|
|
|
- }
|
|
|
- });
|
|
|
- mAdapter = new FriendSortAdapter(getActivity(), mSortFriends);
|
|
|
- mPullToRefreshListView.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
|
|
|
- mPullToRefreshListView.getRefreshableView().setAdapter(mAdapter);
|
|
|
- mPullToRefreshListView.setAdapter(mAdapter);
|
|
|
- mPullToRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() {
|
|
|
- @Override
|
|
|
- public void onRefresh(PullToRefreshBase<ListView> refreshView) {
|
|
|
- mAdapter.setisRefeshed(true);
|
|
|
- upDataFriend();
|
|
|
- loadData();
|
|
|
- updateGoodFriend();
|
|
|
- }
|
|
|
- });
|
|
|
- mPullToRefreshListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
- @Override
|
|
|
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
- List<BaseSortModel<Friend>> list = mAdapter.getmSortFriends();
|
|
|
- if (!ListUtils.isEmpty(list)) {
|
|
|
- Friend friend = list.get((int) id).getBean();
|
|
|
- clickFriend(friend);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- mPullToRefreshListView.getRefreshableView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
|
|
- @Override
|
|
|
- public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
- List<BaseSortModel<Friend>> list = mAdapter.getmSortFriends();
|
|
|
- if (!ListUtils.isEmpty(list)) {
|
|
|
- BaseSortModel<Friend> sortFriend = list.get((int) id);
|
|
|
- if (sortFriend == null) return false;
|
|
|
- Friend friend = sortFriend.getBean();
|
|
|
- if (friend == null) return false;
|
|
|
- String userId = friend.getUserId();
|
|
|
- if (friend.getStatus() == Friend.STATUS_FRIEND) {
|
|
|
-
|
|
|
- }
|
|
|
- if (userId.equals(Friend.ID_SYSTEM_MESSAGE) || userId.equals(Friend.ID_NEW_FRIEND_MESSAGE)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- showLongClickOperationDialog(sortFriend);
|
|
|
- } else
|
|
|
- return false;
|
|
|
- return true;
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- mProgressDialog = ProgressDialogUtil.init(getActivity(), null, getString(R.string.please_wait));
|
|
|
- }
|
|
|
-
|
|
|
- public void update() {
|
|
|
- if (isResumed()) {
|
|
|
- loadData();
|
|
|
- } else {
|
|
|
- mNeedUpdate = true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onResume() {
|
|
|
- super.onResume();
|
|
|
- if (mNeedUpdate) {
|
|
|
- loadData();
|
|
|
- mNeedUpdate = false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /*处理头文件*/
|
|
|
- private void setHeaderView() {
|
|
|
- headview = LayoutInflater.from(ct).inflate(R.layout.header_fragment_contact, null);
|
|
|
- mPullToRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);
|
|
|
- mPullToRefreshListView.getRefreshableView().addHeaderView(headview);
|
|
|
- search_edit = (ClearEditText) headview.findViewById(R.id.search_edit);
|
|
|
- headview.findViewById(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);//我的好友
|
|
|
- updateGoodFriend();
|
|
|
- }
|
|
|
-
|
|
|
- private void updateGoodFriend() {
|
|
|
- List<Friend> friends = FriendDao.getInstance().getFriends(mLoginUserId, "clickNum", 10);
|
|
|
- List<List<Friend>> data = new ArrayList<>();
|
|
|
- data.add(friends);
|
|
|
- if (adapter == null)
|
|
|
- adapter = new ContactExpanAdapter(ct, data);
|
|
|
- else {
|
|
|
- adapter.setFriends(data);
|
|
|
- adapter.notifyDataSetInvalidated();
|
|
|
-
|
|
|
-// if (expandableListView == null || expandableListView.getExpandableListAdapter() == null)
|
|
|
-// return;
|
|
|
-// int children = expandableListView.getExpandableListAdapter().getChildrenCount(0);
|
|
|
-// int childHeight = expandableListView.getChildAt(0).getHeight() + DisplayUtil.dip2px(ct, 8);
|
|
|
-// ViewGroup.LayoutParams params = expandableListView.getLayoutParams();
|
|
|
-// params.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
-// if (!parent.isGroupExpanded(i)) {//判断点击前是否是打开状态,点击前打开,点击后为关闭
|
|
|
-// params.height = groupHeight + children * childHeight;
|
|
|
-// } else {
|
|
|
-// params.height = groupHeight;
|
|
|
-// }
|
|
|
-// expandableListView.setLayoutParams(params);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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(getActivity(), ChatActivity.class);
|
|
|
- intent.putExtra(ChatActivity.FRIEND, friend);
|
|
|
- } else {
|
|
|
- intent = new Intent(getActivity(), BasicInfoActivity.class);
|
|
|
- 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("friend", friend);
|
|
|
- }
|
|
|
- startActivity(intent);
|
|
|
- }
|
|
|
-
|
|
|
- private List<Friend> friends;//临时变量
|
|
|
-
|
|
|
- private void loadData() {
|
|
|
- new Thread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- long startTime = System.currentTimeMillis();
|
|
|
- if (mLoginUserId == null)
|
|
|
- mLoginUserId = MyApplication.getInstance().mLoginUser.getUserId();
|
|
|
- friends = FriendDao.getInstance().getFriendsAndEm(mLoginUserId);
|
|
|
- getFriendByErp(friends);
|
|
|
- long delayTime = 200 - (startTime - System.currentTimeMillis());// 保证至少200ms的刷新过程
|
|
|
- if (delayTime < 0) {
|
|
|
- delayTime = 0;
|
|
|
- }
|
|
|
- mHandler.postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- isHideManageChatMenu();
|
|
|
- mSortFriends.clear();
|
|
|
- mSideBar.clearExist();
|
|
|
- mSideBar.addExist("↑");
|
|
|
- mSideBar.addExist("↑");
|
|
|
- mSideBar.addExist("↑");
|
|
|
- if (friends != null && friends.size() > 0) {
|
|
|
- for (int i = 0; i < friends.size(); i++) {
|
|
|
- BaseSortModel<Friend> mode = new BaseSortModel<>();
|
|
|
- mode.setBean(friends.get(i));
|
|
|
- setSortCondition(mode);
|
|
|
- mSortFriends.add(mode);
|
|
|
- }
|
|
|
- Collections.sort(mSortFriends, mBaseComparator);
|
|
|
- }
|
|
|
- mAdapter.notifyDataSetInvalidated();
|
|
|
- mPullToRefreshListView.onRefreshComplete();
|
|
|
- mcProgressDialog.dismiss();
|
|
|
- }
|
|
|
- }, delayTime);
|
|
|
- }
|
|
|
- }).start();
|
|
|
- }
|
|
|
-
|
|
|
- private void getFriendByErp(List<Friend> friends) {
|
|
|
- if (manager == null)
|
|
|
- manager = new DBManager(MyApplication.getInstance());
|
|
|
- String master = CommonUtil.getSharedPreferences(ct, "erp_master");
|
|
|
- List<EmployeesEntity> emList = null;
|
|
|
- if (!StringUtils.isEmpty(master)) {
|
|
|
- emList = manager.select_getEmployee(new String[]{master}, "whichsys=?");
|
|
|
- }
|
|
|
- if (ListUtils.isEmpty(emList)) return;
|
|
|
- ArrayList<Friend> list = new ArrayList<>();
|
|
|
- for (EmployeesEntity e : emList) {
|
|
|
- boolean isHave = false;
|
|
|
- if (!ListUtils.isEmpty(friends)) {
|
|
|
- for (int i = 0; i < friends.size(); i++) {
|
|
|
- if ((friends.get(i).getUserId().equals(String.valueOf(e.getEm_IMID()))) || friends.get(i).getUserId().equals(mLoginUserId)) {
|
|
|
- isHave = true;
|
|
|
- if (friends.get(i).getUserId().equals(mLoginUserId)) {
|
|
|
- friends.remove(i);
|
|
|
- } else {
|
|
|
- friends.get(i).setPhone(e.getEM_MOBILE());
|
|
|
- friends.get(i).setDepart(e.getEM_DEPART());
|
|
|
- friends.get(i).setPosition(e.getEM_POSITION());
|
|
|
- friends.get(i).setEmCode(e.getEM_CODE());
|
|
|
- friends.get(i).setPrivacy(e.getEM_EMAIL());
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!isHave)
|
|
|
- list.add(getFriendByErp(e));
|
|
|
- }
|
|
|
- }
|
|
|
- if (!ListUtils.isEmpty(friends) && !ListUtils.isEmpty(list)) {
|
|
|
- friends.addAll(list);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private Friend getFriendByErp(EmployeesEntity e) {
|
|
|
- Friend friend = new Friend();
|
|
|
- friend.setTimeCreate((int) (System.currentTimeMillis() / 1000));
|
|
|
- friend.setOwnerId(mLoginUserId);
|
|
|
- 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);
|
|
|
- return friend;
|
|
|
- }
|
|
|
-
|
|
|
- private void isHideManageChatMenu() {
|
|
|
- //判断隐藏或者显示管理群
|
|
|
- DBManager db = new DBManager(ct);
|
|
|
- String master = CommonUtil.getSharedPreferences(ct, "erp_master");
|
|
|
- String emCode = CommonUtil.getSharedPreferences(ct, "erp_username");
|
|
|
- if (StringUtils.isEmpty(master)) return;
|
|
|
- //查找本地数据库,管理群存在,则不创建
|
|
|
- List<HrorgsEntity> hlist = db.queryHrorgList(new String[]{master, emCode}, "whichsys=? and or_headmancode=?");
|
|
|
-// if (hlist.isEmpty()) {
|
|
|
-// chat_manage_rl.setVisibility(View.GONE);
|
|
|
-// } else {
|
|
|
-// chat_manage_rl.setVisibility(View.VISIBLE);
|
|
|
-// }
|
|
|
- }
|
|
|
-
|
|
|
- private final void setSortCondition(BaseSortModel<Friend> mode) {
|
|
|
- Friend friend = mode.getBean();
|
|
|
- if (friend == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- String name = friend.getShowName();
|
|
|
- String wholeSpell = PingYinUtil.getPingYin(name);
|
|
|
- if (!TextUtils.isEmpty(wholeSpell)) {
|
|
|
- String firstLetter = Character.toString(wholeSpell.charAt(0));
|
|
|
- mSideBar.addExist(firstLetter);
|
|
|
- mode.setWholeSpell(wholeSpell);
|
|
|
- mode.setFirstLetter(firstLetter);
|
|
|
- mode.setSimpleSpell(PingYinUtil.converterToFirstSpell(name));
|
|
|
- } else {// 如果全拼为空,理论上是一种错误情况,因为这代表着昵称为空
|
|
|
- mode.setWholeSpell("#");
|
|
|
- mode.setFirstLetter("#");
|
|
|
- mode.setSimpleSpell("#");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // ///////////其他操作///////////////////
|
|
|
- private void showLongClickOperationDialog(final BaseSortModel<Friend> sortFriend) {
|
|
|
- Friend friend = sortFriend.getBean();
|
|
|
- if (friend.getStatus() != Friend.STATUS_BLACKLIST && friend.getStatus() == Friend.STATUS_ATTENTION
|
|
|
- && friend.getStatus() == Friend.STATUS_FRIEND) {
|
|
|
- return;
|
|
|
- }
|
|
|
- CharSequence[] items = new CharSequence[4];
|
|
|
- items[0] = getString(R.string.set_remark_name);// 设置备注名
|
|
|
- if (friend.getStatus() == Friend.STATUS_BLACKLIST) {// 在黑名单中,显示“设置备注名”、“移除黑名单”,"取消关注",“彻底删除”
|
|
|
- items[1] = getString(R.string.remove_blacklist);
|
|
|
- } else {
|
|
|
- items[1] = getString(R.string.add_blacklist);
|
|
|
- }
|
|
|
- items[2] = getString(R.string.cancel_attention);
|
|
|
- items[3] = getString(R.string.delete_all);
|
|
|
-
|
|
|
- new AlertDialog.Builder(getActivity()).setItems(items, new DialogInterface.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
- switch (which) {
|
|
|
- case 0:// 设置备注名
|
|
|
- showRemarkDialog(sortFriend);
|
|
|
- break;
|
|
|
- case 1:// 加入黑名单,或者移除黑名单
|
|
|
- showBlacklistDialog(sortFriend);
|
|
|
- break;
|
|
|
- case 2:// 取消关注
|
|
|
- showCancelAttentionDialog(sortFriend);
|
|
|
- break;
|
|
|
- case 3:// 解除关注关系或者解除好友关系
|
|
|
- showDeleteAllDialog(sortFriend);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }).setCancelable(true).create().show();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private void showRemarkDialog(final BaseSortModel<Friend> sortFriend) {
|
|
|
- final EditText editText = new EditText(getActivity());
|
|
|
- editText.setMaxLines(2);
|
|
|
- editText.setLines(2);
|
|
|
- editText.setText(sortFriend.getBean().getShowName());
|
|
|
- editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});
|
|
|
- editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
|
|
-
|
|
|
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
- builder.setTitle(R.string.set_remark_name).setView(editText)
|
|
|
- .setPositiveButton(getString(R.string.sure), new DialogInterface.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
- String input = editText.getText().toString();
|
|
|
- if (input.equals(sortFriend.getBean().getShowName())) {// 备注名没变
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!StringUtils.isNickName(input)) {// 不符合昵称
|
|
|
- if (input.length() != 0) {
|
|
|
- ToastUtil.showToast(getActivity(), R.string.remark_name_format_error);
|
|
|
- return;
|
|
|
- } else {// 不符合昵称,因为长度为0,但是可以做备注名操作,操作就是清除备注名
|
|
|
- // 判断之前有没有备注名
|
|
|
- if (TextUtils.isEmpty(sortFriend.getBean().getRemarkName())) {// 如果没有备注名,就不需要清除
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- remarkFriend(sortFriend, input);
|
|
|
- }
|
|
|
- }).setNegativeButton(getString(R.string.cancel), null);
|
|
|
- builder.create().show();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onActivityCreated(Bundle savedInstanceState) {
|
|
|
- super.onActivityCreated(savedInstanceState);
|
|
|
- mActivity = getActivity();
|
|
|
- }
|
|
|
-
|
|
|
- private void remarkFriend(final BaseSortModel<Friend> sortFriend, final String remarkName) {
|
|
|
- HashMap<String, String> params = new HashMap<String, String>();
|
|
|
- params.put("access_token", MyApplication.getInstance().mAccessToken);
|
|
|
- params.put("toUserId", sortFriend.getBean().getUserId());
|
|
|
- params.put("remarkName", remarkName);
|
|
|
- ProgressDialogUtil.show(mProgressDialog);
|
|
|
- StringJsonObjectRequest<Result> request = new StringJsonObjectRequest<Result>(MyApplication.getInstance().getConfig().FRIENDS_REMARK, new Response.ErrorListener() {
|
|
|
- @Override
|
|
|
- public void onErrorResponse(VolleyError arg0) {
|
|
|
- ProgressDialogUtil.dismiss(mProgressDialog);
|
|
|
- ToastUtil.showErrorNet(getActivity());
|
|
|
- }
|
|
|
- }, new StringJsonObjectRequest.Listener<Result>() {
|
|
|
- @Override
|
|
|
- public void onResponse(ObjectResult<Result> result) {
|
|
|
- boolean success = Result.defaultParser(getActivity(), result, true);
|
|
|
- ProgressDialogUtil.dismiss(mProgressDialog);
|
|
|
- if (success) {
|
|
|
- String firstLetter = sortFriend.getFirstLetter();
|
|
|
- mSideBar.removeExist(firstLetter);// 移除之前设置的首字母
|
|
|
- sortFriend.getBean().setRemarkName(remarkName);// 修改备注名称
|
|
|
- setSortCondition(sortFriend);
|
|
|
- Collections.sort(mSortFriends, mBaseComparator);
|
|
|
- mAdapter.notifyDataSetChanged();
|
|
|
- // 更新到数据库
|
|
|
- FriendDao.getInstance().setRemarkName(mLoginUserId, sortFriend.getBean().getUserId(), remarkName);
|
|
|
- // 更新消息界面(因为昵称变了,所有要更新)
|
|
|
- MsgBroadcast.broadcastMsgUiUpdate(getActivity());
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }, Result.class, params);
|
|
|
- //mActivity.addDefaultRequest(request);
|
|
|
- //Integer.toHexString(this.hashCode()) + "@"
|
|
|
- MyApplication.getInstance().getFastVolley().addDefaultRequest(HASHCODE, request);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- String HASHCODE = Integer.toHexString(this.hashCode()) + "@";
|
|
|
-
|
|
|
- /* 显示加入黑名单的对话框 */
|
|
|
- private void showBlacklistDialog(final BaseSortModel<Friend> sortFriend) {
|
|
|
- final Friend friend = sortFriend.getBean();
|
|
|
- int messageId = 0;
|
|
|
- if (friend.getStatus() == Friend.STATUS_BLACKLIST) {// 已经在黑名单,那就是移出黑名单(在名片盒界面,不可能出现此情况,从别的地方copy过来的,懒得去掉)
|
|
|
- messageId = R.string.remove_blacklist_prompt;
|
|
|
- } else if (friend.getStatus() == Friend.STATUS_ATTENTION || friend.getStatus() == Friend.STATUS_FRIEND) {
|
|
|
- messageId = R.string.add_blacklist_prompt;
|
|
|
- } else {// 其他关系(错误的状态)
|
|
|
- return;
|
|
|
- }
|
|
|
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle(R.string.prompt_title).setMessage(messageId)
|
|
|
- .setPositiveButton(getString(R.string.sure), new DialogInterface.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
- if (friend.getStatus() == Friend.STATUS_BLACKLIST) {// 已经在黑名单,那就是移出黑名单(在名片盒界面,不可能出现此情况)
|
|
|
- // removeBlacklist(friend);
|
|
|
- } else if (friend.getStatus() == Friend.STATUS_ATTENTION || friend.getStatus() == Friend.STATUS_FRIEND) {
|
|
|
- addBlacklist(sortFriend);
|
|
|
- }
|
|
|
- }
|
|
|
- }).setNegativeButton(getString(R.string.cancel), null);
|
|
|
- builder.create().show();
|
|
|
- }
|
|
|
-
|
|
|
- private void addBlacklist(final BaseSortModel<Friend> sortFriend) {
|
|
|
- HashMap<String, String> params = new HashMap<String, String>();
|
|
|
- params.put("access_token", MyApplication.getInstance().mAccessToken);
|
|
|
- params.put("toUserId", sortFriend.getBean().getUserId());
|
|
|
-
|
|
|
- ProgressDialogUtil.show(mProgressDialog);
|
|
|
- StringJsonObjectRequest<Void> request = new StringJsonObjectRequest<Void>(MyApplication.getInstance().getConfig().FRIENDS_BLACKLIST_ADD, new Response.ErrorListener() {
|
|
|
- @Override
|
|
|
- public void onErrorResponse(VolleyError arg0) {
|
|
|
- ProgressDialogUtil.dismiss(mProgressDialog);
|
|
|
- ToastUtil.showErrorNet(getActivity());
|
|
|
- }
|
|
|
- }, new StringJsonObjectRequest.Listener<Void>() {
|
|
|
- @Override
|
|
|
- public void onResponse(ObjectResult<Void> result) {
|
|
|
-
|
|
|
- boolean success = Result.defaultParser(getActivity(), result, true);
|
|
|
- if (success) {
|
|
|
- FriendDao.getInstance().updateFriendStatus(sortFriend.getBean().getOwnerId(), sortFriend.getBean().getUserId(),
|
|
|
- Friend.STATUS_BLACKLIST);
|
|
|
- FriendHelper.addBlacklistExtraOperation(mLoginUserId, sortFriend.getBean().getUserId());
|
|
|
-
|
|
|
- /* 发送加入黑名单的通知 */
|
|
|
- if (sortFriend.getBean().getStatus() == Friend.STATUS_FRIEND) {// 之前是好友,需要发消息让那个人不能看我的商务圈
|
|
|
- NewFriendMessage message = NewFriendMessage.createWillSendMessage(MyApplication.getInstance().mLoginUser,
|
|
|
- XmppMessage.TYPE_BLACK, null, sortFriend.getBean());
|
|
|
- sendNewFriendMessage(sortFriend.getBean().getUserId(), message);// 加入黑名单
|
|
|
- }
|
|
|
-
|
|
|
- ToastUtil.showToast(getActivity(), R.string.add_blacklist_succ);
|
|
|
-
|
|
|
- mSortFriends.remove(sortFriend);
|
|
|
- String firstLetter = sortFriend.getFirstLetter();
|
|
|
- mSideBar.removeExist(firstLetter);// 移除之前设置的首字母
|
|
|
- mAdapter.notifyDataSetInvalidated();
|
|
|
-
|
|
|
- // 更新消息界面
|
|
|
- MsgBroadcast.broadcastMsgUiUpdate(getActivity());
|
|
|
- }
|
|
|
- ProgressDialogUtil.dismiss(mProgressDialog);
|
|
|
- }
|
|
|
- }, Void.class, params);
|
|
|
-// mActivity.addDefaultRequest(request);
|
|
|
- MyApplication.getInstance().getFastVolley().addDefaultRequest(HASHCODE, request);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private boolean mBind;
|
|
|
- private CoreService mXmppService;
|
|
|
-
|
|
|
- void sendNewFriendMessage(String toUserId, NewFriendMessage message) {
|
|
|
- if (mBind && mXmppService != null) {
|
|
|
- mXmppService.sendNewFriendMessage(toUserId, message);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 取消关注
|
|
|
- *
|
|
|
- * @param
|
|
|
- */
|
|
|
- private void showCancelAttentionDialog(final BaseSortModel<Friend> sortFriend) {
|
|
|
- if (sortFriend.getBean().getStatus() == Friend.STATUS_UNKNOW) {
|
|
|
- return;
|
|
|
- }
|
|
|
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle(R.string.prompt_title)
|
|
|
- .setMessage(R.string.cancel_attention_prompt).setPositiveButton(getString(R.string.sure), new DialogInterface.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
- deleteFriend(sortFriend, 0);
|
|
|
- }
|
|
|
- }).setNegativeButton(getString(R.string.cancel), null);
|
|
|
- builder.create().show();
|
|
|
- }
|
|
|
-
|
|
|
- private void showDeleteAllDialog(final BaseSortModel<Friend> sortFriend) {
|
|
|
- if (sortFriend.getBean().getStatus() == Friend.STATUS_UNKNOW) {
|
|
|
- return;
|
|
|
- }
|
|
|
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle(R.string.prompt_title).setMessage(R.string.delete_all_prompt)
|
|
|
- .setPositiveButton(getString(R.string.sure), new DialogInterface.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
- deleteFriend(sortFriend, 1);
|
|
|
- }
|
|
|
- }).setNegativeButton(getString(R.string.cancel), null);
|
|
|
- builder.create().show();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param
|
|
|
- * @param type 0 取消关注 <br/>
|
|
|
- * 1、彻底删除<br/>
|
|
|
- */
|
|
|
- private void deleteFriend(final BaseSortModel<Friend> sortFriend, final int type) {
|
|
|
- HashMap<String, String> params = new HashMap<String, String>();
|
|
|
- params.put("access_token", MyApplication.getInstance().mAccessToken);
|
|
|
- params.put("toUserId", sortFriend.getBean().getUserId());
|
|
|
-
|
|
|
- String url = null;
|
|
|
- if (type == 0) {
|
|
|
- url = MyApplication.getInstance().getConfig().FRIENDS_ATTENTION_DELETE;// 取消关注
|
|
|
- } else {
|
|
|
- url = MyApplication.getInstance().getConfig().FRIENDS_DELETE;// 删除好友
|
|
|
- }
|
|
|
-
|
|
|
- ProgressDialogUtil.show(mProgressDialog);
|
|
|
- StringJsonObjectRequest<Void> request = new StringJsonObjectRequest<Void>(url, new Response.ErrorListener() {
|
|
|
- @Override
|
|
|
- public void onErrorResponse(VolleyError arg0) {
|
|
|
- ProgressDialogUtil.dismiss(mProgressDialog);
|
|
|
- ToastUtil.showErrorNet(getActivity());
|
|
|
- }
|
|
|
- }, new StringJsonObjectRequest.Listener<Void>() {
|
|
|
- @Override
|
|
|
- public void onResponse(ObjectResult<Void> result) {
|
|
|
- boolean success = Result.defaultParser(getActivity(), result, true);
|
|
|
- if (success) {
|
|
|
- if (type == 0) {
|
|
|
- ToastUtil.showToast(getActivity(), R.string.cancel_attention_succ);
|
|
|
- NewFriendMessage message = NewFriendMessage.createWillSendMessage(MyApplication.getInstance().mLoginUser,
|
|
|
- XmppMessage.TYPE_DELSEE, null, sortFriend.getBean());
|
|
|
- // ((CardcastActivity) getActivity()).sendNewFriendMessage(sortFriend.getBean().getUserId(), message);// 解除关注
|
|
|
- } else {
|
|
|
- ToastUtil.showToast(getActivity(), R.string.delete_all_succ);
|
|
|
- NewFriendMessage message = NewFriendMessage.createWillSendMessage(MyApplication.getInstance().mLoginUser,
|
|
|
- XmppMessage.TYPE_DELALL, null, sortFriend.getBean());
|
|
|
- // ((CardcastActivity) getActivity()).sendNewFriendMessage(sortFriend.getBean().getUserId(), message);// 解除好友
|
|
|
- }
|
|
|
-
|
|
|
- FriendHelper.removeAttentionOrFriend(mLoginUserId, sortFriend.getBean().getUserId());
|
|
|
-
|
|
|
- mSortFriends.remove(sortFriend);
|
|
|
- String firstLetter = sortFriend.getFirstLetter();
|
|
|
- mSideBar.removeExist(firstLetter);// 移除之前设置的首字母
|
|
|
- mAdapter.notifyDataSetInvalidated();
|
|
|
-
|
|
|
- // 更新消息界面
|
|
|
- MsgBroadcast.broadcastMsgUiUpdate(getActivity());
|
|
|
- }
|
|
|
- ProgressDialogUtil.dismiss(mProgressDialog);
|
|
|
- }
|
|
|
- }, Void.class, params);
|
|
|
-// mActivity.addDefaultRequest(request);
|
|
|
- MyApplication.getInstance().getFastVolley().addDefaultRequest(HASHCODE, request);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
- super.onCreateOptionsMenu(menu, inflater);
|
|
|
- inflater.inflate(R.menu.menu_nearby, menu);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onDestroy() {
|
|
|
- getActivity().unregisterReceiver(receiver);
|
|
|
- if (mServiceConnection != null && mActivity != null) {
|
|
|
- mActivity.unbindService(mServiceConnection);
|
|
|
- }
|
|
|
- if (manager != null) {
|
|
|
- manager.closeDB();
|
|
|
- }
|
|
|
- super.onDestroy();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
- if (item.getItemId() == R.id.search) {
|
|
|
- startActivity(new Intent(getActivity(), UserSearchActivity.class));
|
|
|
- }
|
|
|
- return super.onOptionsItemSelected(item);
|
|
|
- }
|
|
|
-
|
|
|
- private static final String TAG = "LinksManFragment";
|
|
|
- private static final int LOAD_COMPANYDATA_SUCESS = 11;
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc:检查是否加载企业通讯录数据
|
|
|
- * @author:Arison on 2016/10/24
|
|
|
- */
|
|
|
- public void loadCompanyData() {
|
|
|
- String master = CommonUtil.getSharedPreferences(ct, "erp_master");
|
|
|
- String commpany = CommonUtil.getSharedPreferences(ct, "erp_commpany");
|
|
|
- if (!StringUtils.isEmpty(master)) {
|
|
|
- String date = manager.select_getCacheTime(
|
|
|
- new String[]{commpany, master},
|
|
|
- "ed_company=? and ed_whichsys=?");
|
|
|
- Log.i(TAG, "loadCompanyData() 数据库缓存时间:" + date);
|
|
|
- String url = Constants.getAppBaseUrl(ct) + "mobile/getAllHrorgEmps.action";
|
|
|
- final Map<String, Object> param = new HashMap<>();
|
|
|
- param.put("master", master);
|
|
|
- if (date == null) {
|
|
|
- date = "";
|
|
|
- }
|
|
|
- param.put("lastdate", date);
|
|
|
- LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
- headers.put("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(ct, "sessionId"));
|
|
|
- ViewUtil.httpSendRequest(ct, url, param, mHandler, headers, LOAD_COMPANYDATA_SUCESS, null, null, "get");
|
|
|
- } else {
|
|
|
- Log.i(TAG, "master 为null");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @author Administrator
|
|
|
- * @功能:写入数据库 isFristLoad 标志是否是第一次加载(数据库是否有缓存);
|
|
|
- * 因为第一次,flag字段不管是更新或者是插入,都执行插入操作;
|
|
|
- */
|
|
|
- public void insertDataSqlite(boolean isFristLoad,
|
|
|
- List<HrorgsEntity> hrorgsEntities,
|
|
|
- List<EmployeesEntity> employeesEntities
|
|
|
- , String servertime) {
|
|
|
- Log.i(TAG, "开始时间:" + CommonUtil.getStringDate(System.currentTimeMillis()));
|
|
|
- if (isFristLoad) {
|
|
|
- manager.saveHrogrs(hrorgsEntities);
|
|
|
- manager.saveEmployees(employeesEntities);
|
|
|
- } else {
|
|
|
- synSqliteDataforServer(hrorgsEntities, employeesEntities);
|
|
|
- }
|
|
|
- manager.deleteHrogrsAndEmployees();
|
|
|
- Map<String, Object> dateCaches = new HashMap<String, Object>();
|
|
|
- String time = dateMinute(servertime);
|
|
|
- Log.i(TAG, "缓存时间相减后:" + time);
|
|
|
- dateCaches.put("ed_lastdate", time);
|
|
|
- dateCaches.put("ed_kind", "通讯录");
|
|
|
- dateCaches.put("ed_company", CommonUtil.getSharedPreferences(ct, "erp_commpany"));
|
|
|
- dateCaches.put("ed_whichsys", CommonUtil.getSharedPreferences(ct, "erp_master"));
|
|
|
- String db_time = manager.select_getCacheTime(new String[]{}, "ed_company=? and ed_whichsys=?");
|
|
|
- if (db_time != null) {
|
|
|
- manager.updateCacheTime(dateCaches);
|
|
|
- } else {
|
|
|
- manager.saveCacheTime(dateCaches);
|
|
|
- }
|
|
|
- Log.i(TAG, "结束时间:" + CommonUtil.getStringDate(System.currentTimeMillis()));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @author Administrator
|
|
|
- * @功能:时间减法
|
|
|
- */
|
|
|
- private String dateMinute(String datetime) {
|
|
|
- String str = datetime;
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- Date date = new Date();
|
|
|
- try {
|
|
|
- date = sdf.parse(str);
|
|
|
- } catch (ParseException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(date);
|
|
|
- calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) - 2);
|
|
|
- System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime()));
|
|
|
- return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @author Administrator
|
|
|
- * @功能:同步数据
|
|
|
- */
|
|
|
- private void synSqliteDataforServer(List<HrorgsEntity> hrorgsEntities, List<EmployeesEntity> employeesEntities) {
|
|
|
- if (!hrorgsEntities.isEmpty()) {
|
|
|
- List<HrorgsEntity> insertHrorgsList = new ArrayList<HrorgsEntity>();
|
|
|
- List<HrorgsEntity> updateHrorgsList = new ArrayList<HrorgsEntity>();
|
|
|
- for (int i = 0; i < hrorgsEntities.size(); i++) {
|
|
|
- HrorgsEntity entity = hrorgsEntities.get(i);
|
|
|
- String or_code = entity.getOr_code();
|
|
|
- String whichsys = entity.getWhichsys();
|
|
|
- if ("UPDATE".equals(entity.getFlag())) {
|
|
|
- HrorgsEntity hentity = manager.select_getRootData(new String[]{or_code, whichsys}, "or_code=? and whichsys=?");
|
|
|
- if (hentity != null) {
|
|
|
- updateHrorgsList.add(entity);
|
|
|
- } else {
|
|
|
- insertHrorgsList.add(entity);
|
|
|
- }
|
|
|
- } else if ("INSERT".equals(entity.getFlag())) {
|
|
|
- insertHrorgsList.add(entity);
|
|
|
- }
|
|
|
- }
|
|
|
- manager.saveHrogrs(insertHrorgsList);
|
|
|
- manager.updateHrogrs(updateHrorgsList);
|
|
|
- }
|
|
|
- if (!employeesEntities.isEmpty()) {
|
|
|
- List<EmployeesEntity> insertEmployeesList = new ArrayList<EmployeesEntity>();
|
|
|
- List<EmployeesEntity> updateEmployeesList = new ArrayList<EmployeesEntity>();
|
|
|
- for (int i = 0; i < employeesEntities.size(); i++) {
|
|
|
- EmployeesEntity eEntity = employeesEntities.get(i);
|
|
|
- String em_code = eEntity.getEM_CODE();
|
|
|
- String whichsys = eEntity.getWHICHSYS();
|
|
|
- if (StringUtils.isEmpty(em_code)) return;
|
|
|
- if ("UPDATE".equals(eEntity.getFLAG())) {
|
|
|
- List<EmployeesEntity> tempEntity = manager.select_getEmployee(new String[]{em_code, whichsys}, "em_code=? and whichsys=?");
|
|
|
- if (tempEntity.isEmpty()) {
|
|
|
- insertEmployeesList.add(eEntity);
|
|
|
- } else {
|
|
|
- updateEmployeesList.add(eEntity);
|
|
|
- }
|
|
|
- } else if ("INSERT".equals(eEntity.getFLAG())) {
|
|
|
- insertEmployeesList.add(eEntity);
|
|
|
- }
|
|
|
- }
|
|
|
- manager.saveEmployees(insertEmployeesList);
|
|
|
- manager.updateEmployees(updateEmployeesList);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|