|
|
@@ -1,31 +1,43 @@
|
|
|
package com.xzjmyk.pm.activity.ui.erp.fragment;
|
|
|
|
|
|
-import android.content.Intent;
|
|
|
-import android.view.View;
|
|
|
-import android.widget.AdapterView;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.util.Log;
|
|
|
import android.widget.ListView;
|
|
|
|
|
|
import com.handmark.pulltorefresh.library.PullToRefreshBase;
|
|
|
import com.handmark.pulltorefresh.library.PullToRefreshListView;
|
|
|
-import com.xzjmyk.pm.activity.ApplySubscribeActivity;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
import com.xzjmyk.pm.activity.adapter.AllSubscriptionAdapter;
|
|
|
-import com.xzjmyk.pm.activity.adapter.AllSubscriptionNumbersAdapter;
|
|
|
+import com.xzjmyk.pm.activity.bean.SubscriptionNumber;
|
|
|
import com.xzjmyk.pm.activity.bean.message.AllSubscriptonKindMessage;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.net.ViewUtil;
|
|
|
+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.view.EmptyLayout;
|
|
|
import com.xzjmyk.pm.activity.view.crouton.Crouton;
|
|
|
+import com.xzjmyk.pm.activity.view.crouton.Style;
|
|
|
+
|
|
|
+import org.json.JSONArray;
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
- * Created by PROD on 2016/9/5.
|
|
|
+ * 所有订阅
|
|
|
+ * Created by RaoMeng on 2016/9/5.
|
|
|
*/
|
|
|
public class SubscriptionAllFragment extends BaseFragment {
|
|
|
private PullToRefreshListView mPullToRefreshListView;
|
|
|
private AllSubscriptionAdapter mAllSubscriptionAdapter;
|
|
|
private List<AllSubscriptonKindMessage> mAllSubscriptonKindMessages;
|
|
|
- private AllSubscriptionNumbersAdapter mAllSubscriptionNumbersAdapter;
|
|
|
- private List<String> mStrings;
|
|
|
+ private EmptyLayout mEmptyLayout;
|
|
|
@Override
|
|
|
protected int getLayout() {
|
|
|
return R.layout.fragment_all_subscription;
|
|
|
@@ -35,16 +47,13 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
protected void initViews() {
|
|
|
mPullToRefreshListView = (PullToRefreshListView) root.findViewById(R.id.subscription_all_ptlv);
|
|
|
mAllSubscriptonKindMessages = new ArrayList<>();
|
|
|
- mStrings = new ArrayList<>();
|
|
|
-
|
|
|
- for (int i = 0; i < 10; i++) {
|
|
|
- AllSubscriptonKindMessage allSubscriptonKindMessage = new AllSubscriptonKindMessage();
|
|
|
- mAllSubscriptonKindMessages.add(allSubscriptonKindMessage);
|
|
|
- }
|
|
|
-
|
|
|
- mAllSubscriptionNumbersAdapter = new AllSubscriptionNumbersAdapter(getActivity(),mStrings);
|
|
|
mAllSubscriptionAdapter = new AllSubscriptionAdapter(getActivity(),mAllSubscriptonKindMessages);
|
|
|
|
|
|
+ mEmptyLayout = new EmptyLayout(getActivity(),mPullToRefreshListView.getRefreshableView());
|
|
|
+ mEmptyLayout.setShowLoadingButton(false);
|
|
|
+ mEmptyLayout.setShowEmptyButton(false);
|
|
|
+ mEmptyLayout.setShowErrorButton(false);
|
|
|
+ mEmptyLayout.setEmptyMessage("没有任何可订阅号");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -54,28 +63,13 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
mPullToRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
|
|
|
@Override
|
|
|
public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
|
|
|
- Crouton.makeText(getActivity(),"下拉刷新", 0xff99cc00,1500).show();
|
|
|
- for (int i = 0; i < 10; i++) {
|
|
|
- AllSubscriptonKindMessage allSubscriptonKindMessage = new AllSubscriptonKindMessage();
|
|
|
- mAllSubscriptonKindMessages.add(allSubscriptonKindMessage);
|
|
|
- }
|
|
|
- mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
- mPullToRefreshListView.postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- mPullToRefreshListView.onRefreshComplete();
|
|
|
-
|
|
|
- }
|
|
|
- },1000);
|
|
|
+ mAllSubscriptonKindMessages.clear();
|
|
|
+ sendAllSubscriptionRequest();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
|
|
|
- Crouton.makeText(getActivity(),"上拉加载", 0xffff4444,1500).show();
|
|
|
- AllSubscriptonKindMessage allSubscriptonKindMessage = new AllSubscriptonKindMessage();
|
|
|
- mAllSubscriptonKindMessages.add(allSubscriptonKindMessage);
|
|
|
-
|
|
|
- mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
+ Crouton.makeText(getActivity(), "上拉加载", 0xffff4444, 1500).show();
|
|
|
mPullToRefreshListView.postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
@@ -85,19 +79,85 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
}, 1000);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
- mPullToRefreshListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
- @Override
|
|
|
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
- Intent intent = new Intent();
|
|
|
- intent.setClass(getActivity(), ApplySubscribeActivity.class);
|
|
|
- startActivity(intent);
|
|
|
- }
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void initDatas() {
|
|
|
+ sendAllSubscriptionRequest();
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取全部订阅
|
|
|
+ */
|
|
|
+ private void sendAllSubscriptionRequest() {
|
|
|
+ progressDialog.show();
|
|
|
+ String allSubsUrl = Constants.getAppBaseUrl(getActivity()) + "common/charts/getApplySubs.action";
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("em_code", CommonUtil.getSharedPreferences(getActivity(),"erp_username"));
|
|
|
+
|
|
|
+ LinkedHashMap headers = new LinkedHashMap();
|
|
|
+ headers.put("Cookie","JSESSIONID="+CommonUtil.getSharedPreferences(getActivity(),"sessionId"));
|
|
|
+ ViewUtil.httpSendRequest(getActivity(),allSubsUrl,params,mHandler,headers,GET_ALL_SUBSCRIPTION,null,null,"post");
|
|
|
}
|
|
|
+
|
|
|
+ private final static int GET_ALL_SUBSCRIPTION = 44;
|
|
|
+ private Handler mHandler = new Handler(){
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ switch (msg.what){
|
|
|
+ case GET_ALL_SUBSCRIPTION:
|
|
|
+ progressDialog.dismiss();
|
|
|
+ String resultJson = msg.getData().getString("result");
|
|
|
+ Log.d("allsubscriptionResult: ", resultJson);
|
|
|
+ try {
|
|
|
+ JSONObject resultObject = new JSONObject(resultJson);
|
|
|
+ JSONArray datasArray = resultObject.getJSONArray("datas");
|
|
|
+ JSONObject datasObject = datasArray.getJSONObject(0);
|
|
|
+ Iterator<String> iterator = datasObject.keys();
|
|
|
+ if (!iterator.hasNext()){
|
|
|
+ mEmptyLayout.showEmpty();
|
|
|
+ if (mPullToRefreshListView.isRefreshing()){
|
|
|
+ mPullToRefreshListView.onRefreshComplete();
|
|
|
+ Crouton.makeText(getActivity(),"没有订阅数据", 0xff99cc00,1500).show();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ while (iterator.hasNext()){
|
|
|
+ String key = iterator.next().toString();
|
|
|
+ Log.d("allsubskeys: ",key);
|
|
|
+ AllSubscriptonKindMessage subscriptonKindMessage = new AllSubscriptonKindMessage();
|
|
|
+ subscriptonKindMessage.setSubscriptionKind(key);
|
|
|
+ List<SubscriptionNumber> subscriptionNumbers = new ArrayList<>();
|
|
|
+ JSONArray subsArray = datasObject.getJSONArray(key);
|
|
|
+ Log.d("allsubsarray: ", subsArray.toString());
|
|
|
+ for (int i = 0; i < subsArray.length(); i++) {
|
|
|
+ JSONObject subsObject = subsArray.getJSONObject(i);
|
|
|
+ SubscriptionNumber subscriptionNumber = new SubscriptionNumber();
|
|
|
+ subscriptionNumber.setId(subsObject.getInt("id"));
|
|
|
+ subscriptionNumber.setTitle(subsObject.getString("title"));
|
|
|
+ subscriptionNumber.setKind(subsObject.getString("kind"));
|
|
|
+ subscriptionNumber.setStatus(subsObject.getInt("status"));
|
|
|
+ subscriptionNumbers.add(subscriptionNumber);
|
|
|
+ }
|
|
|
+ subscriptonKindMessage.setSubscriptionNumbers(subscriptionNumbers);
|
|
|
+ mAllSubscriptonKindMessages.add(subscriptonKindMessage);
|
|
|
+ mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (mPullToRefreshListView.isRefreshing()){
|
|
|
+ mPullToRefreshListView.onRefreshComplete();
|
|
|
+ Crouton.makeText(getActivity(),"刷新成功", 0xff99cc00,1500).show();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Constants.APP_SOCKETIMEOUTEXCEPTION:
|
|
|
+ progressDialog.dismiss();
|
|
|
+ Crouton.makeText(getActivity(),msg.getData().getString("result"), Style.ALERT).show();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
}
|