|
|
@@ -50,6 +50,7 @@ public class SubscriptionMyFragment extends BaseFragment {
|
|
|
private DBManager mDbManager;
|
|
|
private String currentMaster;
|
|
|
private String currentUser;
|
|
|
+
|
|
|
@Override
|
|
|
protected int getLayout() {
|
|
|
return R.layout.fragment_my_subscription;
|
|
|
@@ -62,7 +63,7 @@ public class SubscriptionMyFragment extends BaseFragment {
|
|
|
currentUser = CommonUtil.getSharedPreferences(getActivity(), "erp_username");
|
|
|
mPersonalSubscriptionBeans = new ArrayList<>();
|
|
|
mPullListView = (PullToRefreshListView) root.findViewById(R.id.my_subscripton_smlv);
|
|
|
- mMySubscriptionAdapter = new MySubscriptionAdapter(getActivity(),mPersonalSubscriptionBeans);
|
|
|
+ mMySubscriptionAdapter = new MySubscriptionAdapter(getActivity(), mPersonalSubscriptionBeans);
|
|
|
mEmptyLayout = new EmptyLayout(getActivity(), mPullListView.getRefreshableView());
|
|
|
mEmptyLayout.setShowLoadingButton(false);
|
|
|
mEmptyLayout.setShowEmptyButton(false);
|
|
|
@@ -114,18 +115,18 @@ public class SubscriptionMyFragment extends BaseFragment {
|
|
|
|
|
|
@Override
|
|
|
protected void initDatas() {
|
|
|
- if (CommonUtil.isNetWorkConnected(getActivity().getApplicationContext())){
|
|
|
+ if (CommonUtil.isNetWorkConnected(getActivity().getApplicationContext())) {
|
|
|
sendSubscriptionRequest();
|
|
|
- }else {
|
|
|
- List<PersonalSubscriptionBean> dbPersonalSubscriptionBeans = mDbManager.queryFromMySubs(new String[]{currentMaster,currentUser}, "subs_master=? and subs_username=? ");
|
|
|
- if (dbPersonalSubscriptionBeans != null){
|
|
|
+ } else {
|
|
|
+ List<PersonalSubscriptionBean> dbPersonalSubscriptionBeans = mDbManager.queryFromMySubs(new String[]{currentMaster, currentUser}, "subs_master=? and subs_username=? ");
|
|
|
+ if (dbPersonalSubscriptionBeans != null) {
|
|
|
mPersonalSubscriptionBeans.clear();
|
|
|
mPersonalSubscriptionBeans.addAll(dbPersonalSubscriptionBeans);
|
|
|
mMySubscriptionAdapter.notifyDataSetChanged();
|
|
|
- if (mPersonalSubscriptionBeans.size() == 0){
|
|
|
+ if (mPersonalSubscriptionBeans.size() == 0) {
|
|
|
mEmptyLayout.showEmpty();
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
mEmptyLayout.setErrorMessage("网络未连接");
|
|
|
mEmptyLayout.showError();
|
|
|
}
|
|
|
@@ -139,42 +140,44 @@ public class SubscriptionMyFragment extends BaseFragment {
|
|
|
progressDialog.show();
|
|
|
String subsUrl = Constants.getAppBaseUrl(getActivity()) + "common/charts/getPersonalSubs.action";
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
- params.put("em_code", CommonUtil.getSharedPreferences(getActivity(),"erp_username"));
|
|
|
+ params.put("em_code", CommonUtil.getSharedPreferences(getActivity(), "erp_username"));
|
|
|
|
|
|
LinkedHashMap headers = new LinkedHashMap();
|
|
|
- headers.put("Cookie","JSESSIONID=" + CommonUtil.getSharedPreferences(getActivity(),"sessionId"));
|
|
|
+ headers.put("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(getActivity(), "sessionId"));
|
|
|
ViewUtil.httpSendRequest(getActivity(), subsUrl, params, mHandler, headers, GET_MY_SUBSCRIPTION, null, null, "post");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
- if (requestCode == SUBSCRIBE_MY_DETAIL_REQUEST && resultCode == 44){
|
|
|
+ if (requestCode == SUBSCRIBE_MY_DETAIL_REQUEST && resultCode == 44) {
|
|
|
mDbManager.deleteFromMySubs(mPersonalSubscriptionBeans.get(mClickedPosition - 1));
|
|
|
mPersonalSubscriptionBeans.remove(mClickedPosition - 1);
|
|
|
mMySubscriptionAdapter.notifyDataSetChanged();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Handler mHandler = new Handler(){
|
|
|
+ private Handler mHandler = new Handler() {
|
|
|
@Override
|
|
|
public void handleMessage(Message msg) {
|
|
|
- switch (msg.what){
|
|
|
+ switch (msg.what) {
|
|
|
case GET_MY_SUBSCRIPTION:
|
|
|
progressDialog.dismiss();
|
|
|
- mDbManager.deleteMasterMySubs(currentMaster,currentUser);
|
|
|
+ if (mDbManager.getDb().isOpen()) {
|
|
|
+ mDbManager.deleteMasterMySubs(currentMaster, currentUser);
|
|
|
+ }
|
|
|
String resultJson = msg.getData().getString("result");
|
|
|
- Log.d("subscriptionResult",resultJson);
|
|
|
+ Log.d("subscriptionResult", resultJson);
|
|
|
try {
|
|
|
JSONObject resultObject = new JSONObject(resultJson);
|
|
|
JSONArray resultArray = resultObject.getJSONArray("datas");
|
|
|
- if (resultArray != null){
|
|
|
- if (resultArray.length() == 0){
|
|
|
+ if (resultArray != null) {
|
|
|
+ if (resultArray.length() == 0) {
|
|
|
mEmptyLayout.showEmpty();
|
|
|
- if (mPullListView.isRefreshing()){
|
|
|
+ if (mPullListView.isRefreshing()) {
|
|
|
mPullListView.onRefreshComplete();
|
|
|
- Crouton.makeText(getActivity(),"您没有任何订阅号", 0xff99cc00, 1500).show();
|
|
|
+ Crouton.makeText(getActivity(), "您没有任何订阅号", 0xff99cc00, 1500).show();
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
for (int i = 0; i < resultArray.length(); i++) {
|
|
|
JSONObject currentObject = resultArray.getJSONObject(i);
|
|
|
PersonalSubscriptionBean personalSubscriptionBean = new PersonalSubscriptionBean();
|
|
|
@@ -185,18 +188,25 @@ public class SubscriptionMyFragment extends BaseFragment {
|
|
|
personalSubscriptionBean.setISAPPLED(currentObject.optInt("ISAPPLIED_"));
|
|
|
personalSubscriptionBean.setMASTER(currentMaster);
|
|
|
personalSubscriptionBean.setUSERNAME(currentUser);
|
|
|
- personalSubscriptionBean.setIMG(Base64.decode(currentObject.optString("IMG_"),Base64.DEFAULT));
|
|
|
+ String s = currentObject.optString("IMG_");
|
|
|
+ if ("null".equals(currentObject.optString("IMG_")) || "".equals(currentObject.optString("IMG_"))){
|
|
|
+ personalSubscriptionBean.setIMG(new byte[0]);
|
|
|
+ }else {
|
|
|
+ personalSubscriptionBean.setIMG(Base64.decode(currentObject.optString("IMG_"), Base64.DEFAULT));
|
|
|
+ }
|
|
|
mPersonalSubscriptionBeans.add(personalSubscriptionBean);
|
|
|
}
|
|
|
mMySubscriptionAdapter.notifyDataSetChanged();
|
|
|
- mDbManager.saveListToMySubs(mPersonalSubscriptionBeans);
|
|
|
- if (mPullListView.isRefreshing()){
|
|
|
+ if (mDbManager.getDb().isOpen()) {
|
|
|
+ mDbManager.saveListToMySubs(mPersonalSubscriptionBeans);
|
|
|
+ }
|
|
|
+ if (mPullListView.isRefreshing()) {
|
|
|
mPullListView.onRefreshComplete();
|
|
|
- Crouton.makeText(getActivity(),"刷新成功", 0xff99cc00, 1500).show();
|
|
|
+ Crouton.makeText(getActivity(), "刷新成功", 0xff99cc00, 1500).show();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (mPullListView.isRefreshing()){
|
|
|
+ if (mPullListView.isRefreshing()) {
|
|
|
mPullListView.onRefreshComplete();
|
|
|
}
|
|
|
} catch (JSONException e) {
|
|
|
@@ -207,7 +217,7 @@ public class SubscriptionMyFragment extends BaseFragment {
|
|
|
case Constants.APP_SOCKETIMEOUTEXCEPTION:
|
|
|
progressDialog.dismiss();
|
|
|
Crouton.makeText(getActivity(), msg.getData().getString("result"), 0xffff4444, 1500).show();
|
|
|
- if (mPullListView.isRefreshing()){
|
|
|
+ if (mPullListView.isRefreshing()) {
|
|
|
mPullListView.onRefreshComplete();
|
|
|
}
|
|
|
break;
|