|
|
@@ -1,13 +1,17 @@
|
|
|
package com.xzjmyk.pm.activity.ui.erp.fragment;
|
|
|
|
|
|
import android.content.Intent;
|
|
|
+import android.graphics.drawable.BitmapDrawable;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
import android.util.Log;
|
|
|
+import android.view.Gravity;
|
|
|
import android.view.View;
|
|
|
import android.widget.AdapterView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
import android.widget.ListView;
|
|
|
import android.widget.PopupWindow;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
import com.handmark.pulltorefresh.library.PullToRefreshBase;
|
|
|
import com.handmark.pulltorefresh.library.PullToRefreshListView;
|
|
|
@@ -42,12 +46,13 @@ import java.util.Map;
|
|
|
* 所有订阅
|
|
|
* Created by RaoMeng on 2016/9/5.
|
|
|
*/
|
|
|
+
|
|
|
public class SubscriptionAllFragment extends BaseFragment {
|
|
|
private PullToRefreshListView mPullToRefreshListView;
|
|
|
private AllSubscriptionAdapter mAllSubscriptionAdapter;
|
|
|
private EmptyLayout mEmptyLayout;
|
|
|
private int rbPos = 0;
|
|
|
- private List<String> keyStrings = new ArrayList<>();
|
|
|
+ private List<String> keyStrings = new ArrayList<>();//当前显示的订阅类
|
|
|
private final static int SUBSCRIBE_DETAIL_REQUEST = 33;
|
|
|
private static int mClickedPos = -1;
|
|
|
private String currentMaster;//当前账套
|
|
|
@@ -80,8 +85,8 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
currentUser = CommonUtil.getSharedPreferences(getActivity(), "erp_username");
|
|
|
mPullToRefreshListView = (PullToRefreshListView) root.findViewById(R.id.subscription_all_ptlv);
|
|
|
mSubscriptionNumbers = new ArrayList<>();
|
|
|
- mAllSubscriptionAdapter = new AllSubscriptionAdapter(getActivity(), mSubscriptionNumbers);
|
|
|
mAllSubscriptonKindMessages = new ArrayList<>();
|
|
|
+ mAllSubscriptionAdapter = new AllSubscriptionAdapter(getActivity(), mSubscriptionNumbers);
|
|
|
|
|
|
mDbAllSubscriptonKindMessages = new ArrayList<>();
|
|
|
mDbSubscriptionNumbers = new ArrayList<>();
|
|
|
@@ -128,14 +133,14 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
Intent intent = new Intent();
|
|
|
intent.setClass(getActivity(), SubscribeDetailActivity.class);
|
|
|
intent.putExtra("flag", "all");
|
|
|
- intent.putExtra("subId", mSubscriptionNumbers.get(position - 1).getId());
|
|
|
- intent.putExtra("subTitle", mSubscriptionNumbers.get(position - 1).getTitle());
|
|
|
- intent.putExtra("subStatus", mSubscriptionNumbers.get(position - 1).getStatus());
|
|
|
+ intent.putExtra("subId", mAllSubscriptionAdapter.getmSubscriptionNumbers().get(position - 1).getId());
|
|
|
+ intent.putExtra("subTitle", mAllSubscriptionAdapter.getmSubscriptionNumbers().get(position - 1).getTitle());
|
|
|
+ intent.putExtra("subStatus", mAllSubscriptionAdapter.getmSubscriptionNumbers().get(position - 1).getStatus());
|
|
|
startActivityForResult(intent, SUBSCRIBE_DETAIL_REQUEST);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- /*mPullToRefreshListView.getRefreshableView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
|
|
+ mPullToRefreshListView.getRefreshableView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
|
|
@Override
|
|
|
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
|
|
|
View popView = View.inflate(getActivity(), R.layout.pop_subs_delete, null);
|
|
|
@@ -147,10 +152,9 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
mAllSubscriptionAdapter.getmSubscriptionNumbers().get(position - 1).setRemoved(1);
|
|
|
mDbManager.updateAllSubs(mAllSubscriptionAdapter.getmSubscriptionNumbers().get(position - 1));
|
|
|
mAllSubscriptionAdapter.getmSubscriptionNumbers().remove(position - 1);
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
- mAllSubscriptonKindMessages.get(rbPos).setSubscriptionNumbers( mAllSubscriptionAdapter.getmSubscriptionNumbers());
|
|
|
+ mAllSubscriptonKindMessages.get(rbPos).setSubscriptionNumbers(mAllSubscriptionAdapter.getmSubscriptionNumbers());
|
|
|
|
|
|
if (mAllSubscriptionAdapter.getmSubscriptionNumbers().size() == 0) {
|
|
|
mAllSubscriptonKindMessages.remove(rbPos);
|
|
|
@@ -170,6 +174,8 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
mAllSubscriptionAdapter.getmSubscriptionNumbers().clear();
|
|
|
mAllSubscriptionAdapter.getmSubscriptionNumbers().addAll(mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
+// mAllSubscriptionAdapter = new AllSubscriptionAdapter(getActivity(), mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
+// mPullToRefreshListView.getRefreshableView().setAdapter(mAllSubscriptionAdapter);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
@@ -192,7 +198,7 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
- });*/
|
|
|
+ });
|
|
|
|
|
|
mTypeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
@Override
|
|
|
@@ -201,15 +207,11 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
mSubsTypeAdapter.notifyDataSetChanged();
|
|
|
rbPos = position;
|
|
|
if (mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers().size() != 0) {
|
|
|
-// mSubscriptionNumbers.clear();
|
|
|
-// mSubscriptionNumbers.addAll(mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
-// mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
- mAllSubscriptionAdapter =new AllSubscriptionAdapter(getActivity(),mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
+ mAllSubscriptionAdapter = new AllSubscriptionAdapter(getActivity(), mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
mPullToRefreshListView.getRefreshableView().setAdapter(mAllSubscriptionAdapter);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
-/*
|
|
|
mTypeListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
|
|
@Override
|
|
|
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
|
|
|
@@ -263,7 +265,7 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
- });*/
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private void initKeyStrings() {
|
|
|
@@ -300,68 +302,73 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
|
|
|
@Override
|
|
|
protected void initDatas() {
|
|
|
- //每次初始化页面都需要访问网络数据用来更新本地缓存
|
|
|
- sendAllSubscriptionRequest();
|
|
|
+ if (CommonUtil.isNetWorkConnected(getActivity().getApplicationContext())){
|
|
|
+ //每次初始化页面都需要访问网络数据用来更新本地缓存
|
|
|
+ sendAllSubscriptionRequest();
|
|
|
+ }else {
|
|
|
+ //没有网络时,取本地数据库数据
|
|
|
+ getDbSubsData();
|
|
|
+ }
|
|
|
|
|
|
- /*Log.d("currentMaster: ", currentMaster);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取本地数据库全部订阅
|
|
|
+ */
|
|
|
+ public void getDbSubsData() {
|
|
|
+ mAllSubscriptonKindMessages.clear();
|
|
|
String cacheKeys = SharedUtil.getString(currentMaster + currentUser + "subs");
|
|
|
if (cacheKeys != null) {
|
|
|
String[] cacheKeysArray = cacheKeys.split(",");
|
|
|
+ keyStrings.clear();
|
|
|
for (int i = 0; i < cacheKeysArray.length; i++) {
|
|
|
keyStrings.add(cacheKeysArray[i]);
|
|
|
}
|
|
|
}
|
|
|
- try {
|
|
|
- List<SubscriptionNumber> dbSubscriptionNumbers
|
|
|
- = mDbManager.queryFromAllSubs(new String[]{currentMaster, currentUser}, "subs_master=? and subs_username=? ");
|
|
|
- if (dbSubscriptionNumbers == null || dbSubscriptionNumbers.size() == 0) {
|
|
|
-// if (true) {
|
|
|
- sendAllSubscriptionRequest();
|
|
|
-// Toast.makeText(getActivity(), "网络加载", Toast.LENGTH_SHORT).show();
|
|
|
+ rbPos = 0;
|
|
|
+ List<SubscriptionNumber> dbSubscriptionNumbers
|
|
|
+ = mDbManager.queryFromAllSubs(new String[]{currentMaster,currentUser}, "subs_master=? and subs_username=? ");
|
|
|
+ if (dbSubscriptionNumbers == null || dbSubscriptionNumbers.size() == 0) {
|
|
|
+ mEmptyLayout.showEmpty();
|
|
|
+ } else {
|
|
|
+ if (keyStrings.size() == 0) {
|
|
|
+ mSubsTypeAdapter.notifyDataSetChanged();
|
|
|
+ initKeyStrings();
|
|
|
+ mTypeListView.setVisibility(View.GONE);
|
|
|
+ mEmptyLayout.showEmpty();
|
|
|
+ mSubscriptionNumbers.clear();
|
|
|
+ mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
} else {
|
|
|
-// Toast.makeText(getActivity(), "本地加载", Toast.LENGTH_SHORT).show();
|
|
|
- if (keyStrings.size() == 0) {
|
|
|
- mSubsTypeAdapter.notifyDataSetChanged();
|
|
|
- initKeyStrings();
|
|
|
- mTypeListView.setVisibility(View.GONE);
|
|
|
- mEmptyLayout.showEmpty();
|
|
|
- mSubscriptionNumbers.clear();
|
|
|
- mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
- } else {
|
|
|
- mTypeListView.setVisibility(View.VISIBLE);
|
|
|
- mSubsTypeAdapter.notifyDataSetChanged();
|
|
|
- initKeyStrings();
|
|
|
- for (int i = 0; i < keyStrings.size(); i++) {
|
|
|
- AllSubscriptonKindMessage tempSubscriptonKindMessage = new AllSubscriptonKindMessage();
|
|
|
- List<SubscriptionNumber> tempSubscriptionNumbers = new ArrayList<>();
|
|
|
- String currentKey = keyStrings.get(i);
|
|
|
- for (int j = 0; j < dbSubscriptionNumbers.size(); j++) {
|
|
|
- SubscriptionNumber currentSubscriptionNumber = dbSubscriptionNumbers.get(j);
|
|
|
- if (currentSubscriptionNumber.getType().equals(currentKey)) {
|
|
|
- tempSubscriptionNumbers.add(currentSubscriptionNumber);
|
|
|
- }
|
|
|
+ mTypeListView.setVisibility(View.VISIBLE);
|
|
|
+ mSubsTypeAdapter.notifyDataSetChanged();
|
|
|
+ initKeyStrings();
|
|
|
+ for (int i = 0; i < keyStrings.size(); i++) {
|
|
|
+ AllSubscriptonKindMessage tempSubscriptonKindMessage = new AllSubscriptonKindMessage();
|
|
|
+ List<SubscriptionNumber> tempSubscriptionNumbers = new ArrayList<>();
|
|
|
+ String currentKey = keyStrings.get(i);
|
|
|
+ for (int j = 0; j < dbSubscriptionNumbers.size(); j++) {
|
|
|
+ SubscriptionNumber currentSubscriptionNumber = dbSubscriptionNumbers.get(j);
|
|
|
+ if (currentSubscriptionNumber.getType().equals(currentKey)) {
|
|
|
+ tempSubscriptionNumbers.add(currentSubscriptionNumber);
|
|
|
}
|
|
|
- tempSubscriptonKindMessage.setSubscriptionKind(currentKey);
|
|
|
- tempSubscriptonKindMessage.setSubscriptionNumbers(tempSubscriptionNumbers);
|
|
|
-
|
|
|
- mAllSubscriptonKindMessages.add(tempSubscriptonKindMessage);
|
|
|
}
|
|
|
- mSubscriptionNumbers.clear();
|
|
|
- mSubscriptionNumbers.addAll(mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
- Log.d("allsubscription:", mSubscriptionNumbers.toString());
|
|
|
- mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
+ tempSubscriptonKindMessage.setSubscriptionKind(currentKey);
|
|
|
+ tempSubscriptonKindMessage.setSubscriptionNumbers(tempSubscriptionNumbers);
|
|
|
+ mAllSubscriptonKindMessages.add(tempSubscriptonKindMessage);
|
|
|
}
|
|
|
-
|
|
|
+ mAllSubscriptionAdapter.getmSubscriptionNumbers().clear();
|
|
|
+ mAllSubscriptionAdapter.getmSubscriptionNumbers().addAll(mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
+ Log.d("allsubscription:", mSubscriptionNumbers.toString());
|
|
|
+ mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }*/
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 获取全部订阅
|
|
|
+ * 获取网络数据全部订阅
|
|
|
*/
|
|
|
- private void sendAllSubscriptionRequest() {
|
|
|
+ public void sendAllSubscriptionRequest() {
|
|
|
//取出本地缓存数据
|
|
|
mDbSubscriptionNumbers = mDbManager.queryFromAllSubs(new String[]{currentMaster, currentUser}, "subs_master=? and subs_username=? ");
|
|
|
progressDialog.show();
|
|
|
@@ -461,15 +468,16 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
if (keyStrings.size() == 0) {
|
|
|
mTypeListView.setVisibility(View.GONE);
|
|
|
initKeyStrings();
|
|
|
- mSubscriptionNumbers.clear();
|
|
|
+ mEmptyLayout.showEmpty();
|
|
|
+ mAllSubscriptionAdapter.getmSubscriptionNumbers().clear();
|
|
|
mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
} else {
|
|
|
mTypeListView.setVisibility(View.VISIBLE);
|
|
|
mSubsTypeAdapter.notifyDataSetChanged();
|
|
|
initKeyStrings();
|
|
|
- mSubscriptionNumbers.clear();
|
|
|
- mSubscriptionNumbers.addAll(mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
- Log.d("allsubscription:", mSubscriptionNumbers.toString());
|
|
|
+ mAllSubscriptionAdapter.getmSubscriptionNumbers().clear();
|
|
|
+ mAllSubscriptionAdapter.getmSubscriptionNumbers().addAll(mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
+ Log.d("allsubscription:", mAllSubscriptionAdapter.getmSubscriptionNumbers().toString());
|
|
|
mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
}
|
|
|
|
|
|
@@ -481,6 +489,9 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
case Constants.APP_SOCKETIMEOUTEXCEPTION:
|
|
|
progressDialog.dismiss();
|
|
|
Crouton.makeText(getActivity(), msg.getData().getString("result"), Style.ALERT).show();
|
|
|
+ if (mPullToRefreshListView.isRefreshing()){
|
|
|
+ mPullToRefreshListView.onRefreshComplete();
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -491,10 +502,16 @@ public class SubscriptionAllFragment extends BaseFragment {
|
|
|
if (requestCode == SUBSCRIBE_DETAIL_REQUEST && resultCode == 9 && data != null) {
|
|
|
int statu = data.getIntExtra("status", 0);
|
|
|
if (mClickedPos != -1) {
|
|
|
- mSubscriptionNumbers.get(mClickedPos - 1).setStatus(statu);
|
|
|
- mDbManager.updateAllSubs(mSubscriptionNumbers.get(mClickedPos - 1));
|
|
|
+ mAllSubscriptionAdapter.getmSubscriptionNumbers().get(mClickedPos - 1).setStatus(statu);
|
|
|
+ mDbManager.updateAllSubs(mAllSubscriptionAdapter.getmSubscriptionNumbers().get(mClickedPos - 1));
|
|
|
mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ mDbManager.closeDB();
|
|
|
+ }
|
|
|
}
|