|
@@ -1,5 +1,8 @@
|
|
|
package com.xzjmyk.pm.activity.ui.erp.fragment;
|
|
package com.xzjmyk.pm.activity.ui.erp.fragment;
|
|
|
|
|
|
|
|
|
|
+import android.os.Handler;
|
|
|
|
|
+import android.os.Message;
|
|
|
|
|
+import android.util.Log;
|
|
|
import android.view.Gravity;
|
|
import android.view.Gravity;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.widget.LinearLayout;
|
|
import android.widget.LinearLayout;
|
|
@@ -15,11 +18,23 @@ import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
|
|
|
import com.xzjmyk.pm.activity.MySwipeMenuCreator;
|
|
import com.xzjmyk.pm.activity.MySwipeMenuCreator;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
import com.xzjmyk.pm.activity.adapter.MySubscriptionAdapter;
|
|
import com.xzjmyk.pm.activity.adapter.MySubscriptionAdapter;
|
|
|
|
|
+import com.xzjmyk.pm.activity.bean.PersonalSubscriptionBean;
|
|
|
|
|
+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.util.DisplayUtil;
|
|
import com.xzjmyk.pm.activity.util.DisplayUtil;
|
|
|
import com.xzjmyk.pm.activity.view.crouton.Crouton;
|
|
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.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Created by PROD on 2016/9/5.
|
|
* Created by PROD on 2016/9/5.
|
|
@@ -27,12 +42,17 @@ import java.util.List;
|
|
|
public class SubscriptionMyFragment extends BaseFragment {
|
|
public class SubscriptionMyFragment extends BaseFragment {
|
|
|
private PullToRefreshScrollView mPullToRefreshScrollView;
|
|
private PullToRefreshScrollView mPullToRefreshScrollView;
|
|
|
private SwipeMenuListView mSwipeMenuListView;
|
|
private SwipeMenuListView mSwipeMenuListView;
|
|
|
- private List<String> mStrings = new ArrayList<>();
|
|
|
|
|
|
|
+ private List<PersonalSubscriptionBean> mPersonalSubscriptionBeans;
|
|
|
private MySwipeMenuCreator mMySwipeMenuCreator;
|
|
private MySwipeMenuCreator mMySwipeMenuCreator;
|
|
|
private MySubscriptionAdapter mMySubscriptionAdapter;
|
|
private MySubscriptionAdapter mMySubscriptionAdapter;
|
|
|
private PopupWindow mCancleWindow;
|
|
private PopupWindow mCancleWindow;
|
|
|
private int mStartSwipe;
|
|
private int mStartSwipe;
|
|
|
private int mEndSwipe;
|
|
private int mEndSwipe;
|
|
|
|
|
+
|
|
|
|
|
+ private final static int GET_MY_SUBSCRIPTION = 12;
|
|
|
|
|
+ private final static int REMOVE_MY_SUBSCRIPTION = 13;
|
|
|
|
|
+
|
|
|
|
|
+ private int mCanclePosition;
|
|
|
@Override
|
|
@Override
|
|
|
protected int getLayout() {
|
|
protected int getLayout() {
|
|
|
return R.layout.fragment_my_subscription;
|
|
return R.layout.fragment_my_subscription;
|
|
@@ -40,13 +60,10 @@ public class SubscriptionMyFragment extends BaseFragment {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void initViews() {
|
|
protected void initViews() {
|
|
|
- for (int i = 0; i < 10; i++) {
|
|
|
|
|
- mStrings.add("this is item "+i);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ mPersonalSubscriptionBeans = new ArrayList<>();
|
|
|
mPullToRefreshScrollView = (PullToRefreshScrollView) root.findViewById(R.id.my_subscription_ptrsv);
|
|
mPullToRefreshScrollView = (PullToRefreshScrollView) root.findViewById(R.id.my_subscription_ptrsv);
|
|
|
mSwipeMenuListView = (SwipeMenuListView) root.findViewById(R.id.my_subscripton_smlv);
|
|
mSwipeMenuListView = (SwipeMenuListView) root.findViewById(R.id.my_subscripton_smlv);
|
|
|
- mMySubscriptionAdapter = new MySubscriptionAdapter(getActivity(),mStrings);
|
|
|
|
|
|
|
+ mMySubscriptionAdapter = new MySubscriptionAdapter(getActivity(),mPersonalSubscriptionBeans);
|
|
|
mMySwipeMenuCreator = new MySwipeMenuCreator(getActivity());
|
|
mMySwipeMenuCreator = new MySwipeMenuCreator(getActivity());
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -66,7 +83,7 @@ public class SubscriptionMyFragment extends BaseFragment {
|
|
|
@Override
|
|
@Override
|
|
|
public void onSwipeEnd(int position) {
|
|
public void onSwipeEnd(int position) {
|
|
|
mEndSwipe = position;
|
|
mEndSwipe = position;
|
|
|
- if ((mStartSwipe % 2) == 0) {
|
|
|
|
|
|
|
+ if (mPersonalSubscriptionBeans.get(mStartSwipe).getISAPPLED() == 0) {
|
|
|
mSwipeMenuListView.smoothCloseMenu();
|
|
mSwipeMenuListView.smoothCloseMenu();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -74,7 +91,7 @@ public class SubscriptionMyFragment extends BaseFragment {
|
|
|
});
|
|
});
|
|
|
mSwipeMenuListView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
|
|
mSwipeMenuListView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
|
|
|
@Override
|
|
@Override
|
|
|
- public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
|
|
|
|
|
|
|
+ public boolean onMenuItemClick(final int position, SwipeMenu menu, int index) {
|
|
|
View cancleView = View.inflate(getActivity(), R.layout.pop_cancle_my_subscribe, null);
|
|
View cancleView = View.inflate(getActivity(), R.layout.pop_cancle_my_subscribe, null);
|
|
|
TextView cancleTextView = (TextView) cancleView.findViewById(R.id.cancel_subscribe_cancle_tv);
|
|
TextView cancleTextView = (TextView) cancleView.findViewById(R.id.cancel_subscribe_cancle_tv);
|
|
|
TextView contineTextView = (TextView) cancleView.findViewById(R.id.cancel_subscribe_contine_tv);
|
|
TextView contineTextView = (TextView) cancleView.findViewById(R.id.cancel_subscribe_contine_tv);
|
|
@@ -83,6 +100,8 @@ public class SubscriptionMyFragment extends BaseFragment {
|
|
|
@Override
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
public void onClick(View v) {
|
|
|
Crouton.makeText(getActivity(), "取消成功", 0xff99cc00, 1500).show();
|
|
Crouton.makeText(getActivity(), "取消成功", 0xff99cc00, 1500).show();
|
|
|
|
|
+ mCanclePosition = position;
|
|
|
|
|
+ sendRemoveRequest(mCanclePosition);
|
|
|
closeWarningPopupWindow();
|
|
closeWarningPopupWindow();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -113,21 +132,12 @@ public class SubscriptionMyFragment extends BaseFragment {
|
|
|
mPullToRefreshScrollView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
|
|
mPullToRefreshScrollView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
|
|
public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
|
|
|
- mStrings.clear();
|
|
|
|
|
- for (int i = 0; i < 10; i++) {
|
|
|
|
|
- mStrings.add("this is item "+i);
|
|
|
|
|
- }
|
|
|
|
|
- mMySubscriptionAdapter.notifyDataSetChanged();
|
|
|
|
|
-
|
|
|
|
|
- Toast.makeText(getActivity(), "refresh down success", Toast.LENGTH_SHORT).show();
|
|
|
|
|
- mPullToRefreshScrollView.onRefreshComplete();
|
|
|
|
|
|
|
+ mPersonalSubscriptionBeans.clear();
|
|
|
|
|
+ sendSubscriptionRequest();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
|
|
public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
|
|
|
- mStrings.add("add item");
|
|
|
|
|
- mMySubscriptionAdapter.notifyDataSetChanged();
|
|
|
|
|
-
|
|
|
|
|
Toast.makeText(getActivity(), "refresh up success", Toast.LENGTH_SHORT).show();
|
|
Toast.makeText(getActivity(), "refresh up success", Toast.LENGTH_SHORT).show();
|
|
|
mPullToRefreshScrollView.onRefreshComplete();
|
|
mPullToRefreshScrollView.onRefreshComplete();
|
|
|
}
|
|
}
|
|
@@ -136,9 +146,87 @@ public class SubscriptionMyFragment extends BaseFragment {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void initDatas() {
|
|
protected void initDatas() {
|
|
|
|
|
+ sendSubscriptionRequest();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取当前用户的订阅号
|
|
|
|
|
+ */
|
|
|
|
|
+ private void sendSubscriptionRequest() {
|
|
|
|
|
+ String subsUrl = Constants.getAppBaseUrl(getActivity()) + "common/charts/getPersonalSubs.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(), subsUrl, params, mHandler, headers, GET_MY_SUBSCRIPTION, null, null, "post");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 取消订阅
|
|
|
|
|
+ */
|
|
|
|
|
+ private void sendRemoveRequest(int position) {
|
|
|
|
|
+ String subsUrl = Constants.getAppBaseUrl(getActivity()) + "common/charts/removeSubsMans.action";
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ params.put("em_code", CommonUtil.getSharedPreferences(getActivity(),"erp_username"));
|
|
|
|
|
+ params.put("numIds", mPersonalSubscriptionBeans.get(position).getNUM_ID());
|
|
|
|
|
+
|
|
|
|
|
+ LinkedHashMap headers = new LinkedHashMap();
|
|
|
|
|
+ headers.put("Cookie","JSESSIONID=" + CommonUtil.getSharedPreferences(getActivity(),"sessionId"));
|
|
|
|
|
+ ViewUtil.httpSendRequest(getActivity(), subsUrl, params, mHandler, headers, REMOVE_MY_SUBSCRIPTION, null, null, "post");
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private Handler mHandler = new Handler(){
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
|
|
+ switch (msg.what){
|
|
|
|
|
+ case GET_MY_SUBSCRIPTION:
|
|
|
|
|
+ String resultJson = msg.getData().getString("result");
|
|
|
|
|
+ Log.d("subscriptionResult",resultJson);
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSONObject resultObject = new JSONObject(resultJson);
|
|
|
|
|
+ JSONArray resultArray = resultObject.getJSONArray("datas");
|
|
|
|
|
+ for (int i = 0; i < resultArray.length(); i++) {
|
|
|
|
|
+ JSONObject currentObject = resultArray.getJSONObject(i);
|
|
|
|
|
+ PersonalSubscriptionBean personalSubscriptionBean = new PersonalSubscriptionBean();
|
|
|
|
|
+ personalSubscriptionBean.setNUM_ID(currentObject.getInt("NUM_ID"));
|
|
|
|
|
+ personalSubscriptionBean.setTITLE(currentObject.getString("TITLE_"));
|
|
|
|
|
+ personalSubscriptionBean.setKIND(currentObject.getString("KIND_"));
|
|
|
|
|
+ personalSubscriptionBean.setTYPE(currentObject.getString("TYPE_"));
|
|
|
|
|
+ personalSubscriptionBean.setISAPPLED(currentObject.getInt("ISAPPLIED_"));
|
|
|
|
|
+
|
|
|
|
|
+ mPersonalSubscriptionBeans.add(personalSubscriptionBean);
|
|
|
|
|
+ }
|
|
|
|
|
+ mMySubscriptionAdapter.notifyDataSetChanged();
|
|
|
|
|
+ Crouton.makeText(getActivity(),"刷新成功", Style.CONFIRM).show();
|
|
|
|
|
+ if (mPullToRefreshScrollView.isRefreshing()){
|
|
|
|
|
+ mPullToRefreshScrollView.onRefreshComplete();
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (JSONException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case REMOVE_MY_SUBSCRIPTION:
|
|
|
|
|
+ Crouton.makeText(getActivity(), "取消订阅成功", 0xff99cc00, 1500).show();
|
|
|
|
|
+ mPersonalSubscriptionBeans.remove(mCanclePosition);
|
|
|
|
|
+ mMySubscriptionAdapter.notifyDataSetChanged();
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case Constants.APP_SOCKETIMEOUTEXCEPTION:
|
|
|
|
|
+ Crouton.makeText(getActivity(), msg.getData().getString("result"), Style.CONFIRM).show();
|
|
|
|
|
+ if (mPullToRefreshScrollView.isRefreshing()){
|
|
|
|
|
+ mPullToRefreshScrollView.onRefreshComplete();
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
private void closeWarningPopupWindow() {
|
|
private void closeWarningPopupWindow() {
|
|
|
if (mCancleWindow != null) {
|
|
if (mCancleWindow != null) {
|
|
|
mCancleWindow.dismiss();
|
|
mCancleWindow.dismiss();
|