|
|
@@ -5,8 +5,6 @@ import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
import android.os.Bundle;
|
|
|
-import android.support.annotation.NonNull;
|
|
|
-import android.support.annotation.Nullable;
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
|
|
import android.text.Editable;
|
|
|
import android.text.TextUtils;
|
|
|
@@ -21,25 +19,20 @@ import android.widget.LinearLayout;
|
|
|
import android.widget.PopupWindow;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.common.data.ListUtils;
|
|
|
import com.common.data.StringUtil;
|
|
|
import com.common.system.DisplayUtil;
|
|
|
-import com.common.thread.ThreadPool;
|
|
|
+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.dao.DBManager;
|
|
|
import com.core.model.EmployeesEntity;
|
|
|
import com.core.model.Friend;
|
|
|
import com.core.net.http.http.OAHttpHelper;
|
|
|
-import com.core.utils.CommonInterface;
|
|
|
import com.core.utils.CommonUtil;
|
|
|
-import com.core.utils.CompanyHandlerInfoUtil;
|
|
|
import com.core.widget.CustomProgressDialog;
|
|
|
import com.core.widget.VoiceSearchView;
|
|
|
import com.core.widget.listener.EditChangeListener;
|
|
|
@@ -52,6 +45,7 @@ import com.core.xmpp.utils.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;
|
|
|
@@ -69,7 +63,7 @@ import java.util.List;
|
|
|
/**
|
|
|
* Created by pengminggong on 2016/10/12.
|
|
|
*/
|
|
|
-public class ContactFragment extends EasyFragment implements View.OnClickListener {
|
|
|
+public class ContactFragment extends EasyFragment implements View.OnClickListener,ContactsManager.OnEmployListener {
|
|
|
private SideBar sidebar;
|
|
|
private TextView text_dialog;
|
|
|
private StickyListHeadersListView refreshListView;
|
|
|
@@ -91,7 +85,7 @@ public class ContactFragment extends EasyFragment implements View.OnClickListene
|
|
|
@Override
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
if (intent.getAction().equals("com.app.home.update") || intent.getAction().equals(MsgBroadcast.ACTION_MSG_COMPANY_UPDATE)) {//账套变更,重新刷新数据,初始化任务
|
|
|
- loadDataInThread();
|
|
|
+ loadData();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
@@ -237,10 +231,8 @@ public class ContactFragment extends EasyFragment implements View.OnClickListene
|
|
|
if ("1".equals(CommonUtil.getUserRole())) {
|
|
|
mPullToRefreshView.setRefreshing(false, false);
|
|
|
mcProgressDialog.dismiss();
|
|
|
-
|
|
|
} else {
|
|
|
- loadFriendsNet();
|
|
|
-
|
|
|
+ ContactsManager.getInstance().loadContactByNet(ContactFragment.this);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -283,10 +275,7 @@ public class ContactFragment extends EasyFragment implements View.OnClickListene
|
|
|
sidebar.setTextView(text_dialog);
|
|
|
adapter = new FriendSortAdapter(ct, showDatas);
|
|
|
refreshListView.setAdapter(adapter);
|
|
|
- loadDataInThread();
|
|
|
- //mcProgressDialog.show();
|
|
|
-
|
|
|
-
|
|
|
+ loadData();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -327,38 +316,23 @@ public class ContactFragment extends EasyFragment implements View.OnClickListene
|
|
|
startActivity(intent);
|
|
|
}
|
|
|
|
|
|
+ void showLoading() {
|
|
|
|
|
|
- /*开启线程获取数据*/
|
|
|
- private void loadDataInThread() {
|
|
|
- ThreadPool.getThreadPool().addTask(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- List<BaseSortModel<Friend>> chche = null;//通过数据库获取数据
|
|
|
- try {
|
|
|
- chche = getFriendsByErpDB(getEmListByDB());
|
|
|
- if (ListUtils.isEmpty(chche)) {
|
|
|
- OAHttpHelper.getInstance().post(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- loadFriendsNet();
|
|
|
- }
|
|
|
- });
|
|
|
- } else loadDataInThread(chche);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ }//显示刷新
|
|
|
+
|
|
|
+ void dimssLoading() {
|
|
|
+
|
|
|
+ }//关闭刷新
|
|
|
+
|
|
|
+ private void loadData() {
|
|
|
+ showLoading();
|
|
|
+ ContactsManager.getInstance().loadContact(this);
|
|
|
}
|
|
|
|
|
|
- /*在线程中处理数据
|
|
|
- * 1.数据库获取
|
|
|
- * 2.网络获取
|
|
|
- * */
|
|
|
- private void loadDataInThread(List<BaseSortModel<Friend>> chche) throws Exception {
|
|
|
- allDatas = chche;
|
|
|
+ private void handlerData(List<BaseSortModel<Friend>> friends ) {
|
|
|
+ allDatas = friends;
|
|
|
if (voiceSearchView == null || TextUtils.isEmpty(voiceSearchView.getText())) {//没有搜索数据
|
|
|
- showDatas = chche;
|
|
|
+ showDatas = friends;
|
|
|
} else {//
|
|
|
String str = voiceSearchView.getText().toString();
|
|
|
upDataBySearch(str);
|
|
|
@@ -411,16 +385,6 @@ public class ContactFragment extends EasyFragment implements View.OnClickListene
|
|
|
}
|
|
|
|
|
|
|
|
|
- private List<EmployeesEntity> getEmListByDB() throws Exception {
|
|
|
- DBManager manager = new DBManager();
|
|
|
- String master = CommonUtil.getMaster();
|
|
|
- List<EmployeesEntity> emList = null;
|
|
|
- if (!StringUtil.isEmpty(master)) {
|
|
|
- emList = manager.select_getEmployee(new String[]{master}, "whichsys=?");
|
|
|
- }
|
|
|
- manager.closeDB();
|
|
|
- return emList;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 将Rep转化为Friend对象
|
|
|
@@ -474,30 +438,7 @@ public class ContactFragment extends EasyFragment implements View.OnClickListene
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void loadFriendsNet() {
|
|
|
- CommonInterface.getInstance().loadCompanyData(new CommonInterface.OnResultListener() {
|
|
|
- @Override
|
|
|
- public void result(@NonNull boolean success, @NonNull int what, @Nullable String message) {
|
|
|
- try {
|
|
|
- if (success) {
|
|
|
- boolean isB2b = ApiUtils.getApiModel() instanceof ApiPlatform;
|
|
|
- JSONObject object = JSON.parseObject(message);
|
|
|
- List<BaseSortModel<Friend>> chche = null;
|
|
|
- if (isB2b) {
|
|
|
- chche = getFriendsByErpDB(CompanyHandlerInfoUtil.getEmployeesByB2b(object));
|
|
|
- } else {
|
|
|
- List<EmployeesEntity> entities = CompanyHandlerInfoUtil.getEmployeesByNet(object);
|
|
|
- chche = getFriendsByErpDB(entities);
|
|
|
- }
|
|
|
- if (!ListUtils.isEmpty(chche))
|
|
|
- loadDataInThread(chche);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
@@ -521,6 +462,22 @@ public class ContactFragment extends EasyFragment implements View.OnClickListene
|
|
|
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();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|