Arison hace 8 años
padre
commit
a5d540973c

+ 3 - 1
app_core/network/src/main/java/com/me/network/app/http/HttpClient.java

@@ -119,6 +119,8 @@ public class HttpClient {
         //默认的参数
         public Builder() {
             this.method = Method.GET;
+            this.params.put("client","Android Client");
+            this.headers.put("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
         }
 
         public Builder(String url) {
@@ -226,7 +228,7 @@ public class HttpClient {
         }
 
         public HttpClient build() {
-            HttpClient client = newInstance(this);
+            HttpClient client = build(true);
             return client;
         }
 

+ 77 - 27
app_modular/appcontact/src/main/java/com/uas/appcontact/ui/activity/ContactsActivity.java

@@ -68,6 +68,10 @@ import com.core.xmpp.utils.AppConstant;
 import com.handmark.pulltorefresh.library.PullToRefreshBase;
 import com.handmark.pulltorefresh.library.PullToRefreshListView;
 import com.lidroid.xutils.ViewUtils;
+import com.me.network.app.http.HttpClient;
+import com.me.network.app.http.Method;
+import com.me.network.app.http.rx.ResultListener;
+import com.me.network.app.http.rx.ResultSubscriber;
 import com.uas.appcontact.R;
 import com.uas.appcontact.adapter.ContactsAdapter;
 import com.uas.appcontact.db.ContactsDao;
@@ -96,9 +100,9 @@ public class ContactsActivity extends OABaseActivity implements ContactsAdapter.
     private List<ContactsModel> models = new ArrayList<>();
     private List<ContactsModel> tmodels = new ArrayList<>();
     private int type = 0;//0默认情况。1 其它界面调用
-    private boolean isSingleSelect=true;//true 单选  false 多选
+    private boolean isSingleSelect = true;//true 单选  false 多选
     private String searchKey;
-    private int allSelect=0;
+    private int allSelect = 0;
 
 
     @Override
@@ -128,15 +132,15 @@ public class ContactsActivity extends OABaseActivity implements ContactsAdapter.
 
     private void initView() {
         mlist = (PullToRefreshListView) findViewById(R.id.mList);
-        all_sure_cb=(CheckBox) findViewById(R.id.all_sure_cb);
-        mumber_tv= (TextView) findViewById(R.id.mumber_tv);
-                
-        
+        all_sure_cb = (CheckBox) findViewById(R.id.all_sure_cb);
+        mumber_tv = (TextView) findViewById(R.id.mumber_tv);
+
+
         voiceSearchView = (VoiceSearchView) findViewById(R.id.voiceSearchView);
         if (getIntent() != null) {
             type = getIntent().getIntExtra("type", 0);
             String title = getIntent().getStringExtra("title");
-            isSingleSelect=getIntent().getBooleanExtra("isSingleSelect",true);
+            isSingleSelect = getIntent().getBooleanExtra("isSingleSelect", true);
             if (!StringUtil.isEmpty(title)) {
                 getSupportActionBar().setTitle(title);
             } else {
@@ -193,16 +197,16 @@ public class ContactsActivity extends OABaseActivity implements ContactsAdapter.
                     startActivity(intent);
                 } else if (type == 1) { //预约---获取对象界面
                     //预约对象
-                    if (isSingleSelect){
-                        Intent  intent = new Intent();
+                    if (isSingleSelect) {
+                        Intent intent = new Intent();
                         intent.putExtra("data", viewHolder.model);
                         setResult(0x20, intent);
                         finish();
-                    }else{
-                        boolean isChecked= ! viewHolder.checkBox.isChecked();
-                        LogUtil.d("ContactsActivity","isChecked:"+isChecked);
+                    } else {
+                        boolean isChecked = !viewHolder.checkBox.isChecked();
+                        LogUtil.d("ContactsActivity", "isChecked:" + isChecked);
                         setSelectNumber(isChecked);
-                        adapter.getItem(position-1).setClick(isChecked);
+                        adapter.getItem(position - 1).setClick(isChecked);
                         adapter.notifyDataSetChanged();
                     }
 
@@ -248,12 +252,12 @@ public class ContactsActivity extends OABaseActivity implements ContactsAdapter.
             public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                 if (isClickCb) {
                     if (adapter == null) return;
-                     for(int i=0;i<adapter.getModels().size();i++){
-                         adapter.getModels().get(i).setClick(b);
-                     }
-                     allSelect=  getSelectNumber().size();
-                     mumber_tv.setText(getString(R.string.selected) + allSelect + " " +"人员");
-                     adapter.notifyDataSetChanged();
+                    for (int i = 0; i < adapter.getModels().size(); i++) {
+                        adapter.getModels().get(i).setClick(b);
+                    }
+                    allSelect = getSelectNumber().size();
+                    mumber_tv.setText(getString(R.string.selected) + allSelect + " " + "人员");
+                    adapter.notifyDataSetChanged();
                     all_sure_cb.setText(b ? R.string.cancel_select_all : R.string.select_all);
                 }
                 isClickCb = true;
@@ -264,7 +268,7 @@ public class ContactsActivity extends OABaseActivity implements ContactsAdapter.
         findViewById(R.id.sure_tv).setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
-                ArrayList<ContactsModel> models=getSelectNumber();
+                ArrayList<ContactsModel> models = getSelectNumber();
                 Intent intent = new Intent();
                 intent.putParcelableArrayListExtra("data", models);
                 activity.setResult(0x01, intent);
@@ -273,15 +277,15 @@ public class ContactsActivity extends OABaseActivity implements ContactsAdapter.
         });
 
     }
-    
-    public  ArrayList<ContactsModel> getSelectNumber(){
-        ArrayList<ContactsModel> models =new ArrayList<>();
-        for (int i=0;i<adapter.getModels().size();i++){
-            if (adapter.getModels().get(i).isClick){
-               models.add(adapter.getItem(i));
+
+    public ArrayList<ContactsModel> getSelectNumber() {
+        ArrayList<ContactsModel> models = new ArrayList<>();
+        for (int i = 0; i < adapter.getModels().size(); i++) {
+            if (adapter.getModels().get(i).isClick) {
+                models.add(adapter.getItem(i));
             }
         }
-        return  models;
+        return models;
     }
 
     /**
@@ -412,6 +416,8 @@ public class ContactsActivity extends OABaseActivity implements ContactsAdapter.
                 if (isHasPermiss) {
                     List<Contacts> contacts =
                             ContactsUtils.getContacts1();
+                    //上传数据到服务器
+                    uploadData(contacts);
                     if (contacts != null) {
                         for (Contacts entity : contacts) {
                             ContactsModel model = new ContactsModel();
@@ -851,4 +857,48 @@ public class ContactsActivity extends OABaseActivity implements ContactsAdapter.
             }
         }
     };
+
+
+    //
+    public void uploadData(List<Contacts> models) {
+        if (!ListUtils.isEmpty(models)) {
+//            String map="[{\n" +
+//                    "\"am_telephone\":\"13266699268\",\n" +
+//                    "\"am_username\":\"张山\"\n" +
+//                    "}]";
+            StringBuilder mapBuilder = new StringBuilder("[");
+            for (int i = 0; i < models.size(); i++) {
+                if (i == models.size() - 1) {
+                    mapBuilder.append("{\n" +
+                            "\"am_telephone\":\"" + models.get(i).getPhone() + "\",\n" +
+                            "\"am_username\":\"" + models.get(i).getName() + "\"\n" +
+                            "}]");
+                } else {
+                    mapBuilder.append("{\n" +
+                            "\"am_telephone\":\"" + models.get(i).getPhone() + "\",\n" +
+                            "\"am_username\":\"" + models.get(i).getName() + "\"\n" +
+                            "},");
+                }
+            }
+      
+            HttpClient httpClient = new HttpClient.Builder().url(Constants.IM_BASE_URL).isDebug(true).build();
+            httpClient.Api().send(new HttpClient.Builder()
+                    .url("/user/appMobileContact")
+                    .isDebug(true)
+                    .add("token", MyApplication.getInstance().mAccessToken)
+                    .add("userid", MyApplication.getInstance().mLoginUser.getUserId())
+                    .add("username", MyApplication.getInstance().mLoginUser.getNickName())
+                    .add("map", mapBuilder.toString())
+                    .method(Method.POST)
+                    .build(false), new ResultSubscriber<>(new ResultListener<Object>() {
+
+                @Override
+                public void onResponse(Object o) {
+                       if(JSONUtil.validate(o.toString())){
+                        LogUtil.d("HttpLogs","result:"+o.toString());
+                       }
+                }
+            }));
+        }
+    }
 }