|
|
@@ -12,9 +12,12 @@ import android.widget.LinearLayout;
|
|
|
import android.widget.ListView;
|
|
|
import android.widget.RadioButton;
|
|
|
import android.widget.RadioGroup;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import com.handmark.pulltorefresh.library.PullToRefreshBase;
|
|
|
import com.handmark.pulltorefresh.library.PullToRefreshListView;
|
|
|
+import com.lidroid.xutils.exception.DbException;
|
|
|
+import com.xzjmyk.pm.activity.MyApplication;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
import com.xzjmyk.pm.activity.adapter.AllSubscriptionAdapter;
|
|
|
import com.xzjmyk.pm.activity.bean.SubscriptionNumber;
|
|
|
@@ -24,6 +27,7 @@ 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.util.SharedUtil;
|
|
|
import com.xzjmyk.pm.activity.view.crouton.Crouton;
|
|
|
import com.xzjmyk.pm.activity.view.crouton.Style;
|
|
|
|
|
|
@@ -53,6 +57,7 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
private List<String> keyStrings = new ArrayList<>();
|
|
|
private final static int SUBSCRIBE_DETAIL_REQUEST = 33;
|
|
|
private static int mClickedPos = -1;
|
|
|
+ String currentMaster;
|
|
|
|
|
|
@Override
|
|
|
protected int getLayout() {
|
|
|
@@ -62,11 +67,11 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
@Override
|
|
|
protected void initViews() {
|
|
|
mRadioGroup = (RadioGroup) root.findViewById(R.id.subscription_all_rg);
|
|
|
-
|
|
|
+ currentMaster = CommonUtil.getSharedPreferences(getActivity(),"erp_master");
|
|
|
mPullToRefreshListView = (PullToRefreshListView) root.findViewById(R.id.subscription_all_ptlv);
|
|
|
- mAllSubscriptonKindMessages = new ArrayList<>();
|
|
|
mSubscriptionNumbers = new ArrayList<>();
|
|
|
mAllSubscriptionAdapter = new AllSubscriptionAdapter(getActivity(), mSubscriptionNumbers);
|
|
|
+ mAllSubscriptonKindMessages = new ArrayList<>();
|
|
|
|
|
|
mEmptyLayout = new EmptyLayout(getActivity(), mPullToRefreshListView.getRefreshableView());
|
|
|
mEmptyLayout.setShowLoadingButton(false);
|
|
|
@@ -116,7 +121,76 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
|
|
|
@Override
|
|
|
protected void initDatas() {
|
|
|
- sendAllSubscriptionRequest();
|
|
|
+// mAllSubscriptonKindMessages = (List<AllSubscriptonKindMessage>) MyApplication.getDataCacheFromMap("all_subs_cache");
|
|
|
+ Log.d("currentMaster: ",currentMaster);
|
|
|
+ String cacheKeys = SharedUtil.getString(currentMaster+"subs");
|
|
|
+ if (cacheKeys != null){
|
|
|
+ String[] cacheKeysArray = cacheKeys.split(",");
|
|
|
+ for (int i = 0; i < cacheKeysArray.length; i++) {
|
|
|
+ keyStrings.add(cacheKeysArray[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ List<SubscriptionNumber> dbSubscriptionNumbers = MyApplication.mDbUtils.findAll(SubscriptionNumber.class);
|
|
|
+ if (dbSubscriptionNumbers == null){
|
|
|
+ sendAllSubscriptionRequest();
|
|
|
+ Toast.makeText(getActivity(),"网络加载",Toast.LENGTH_SHORT).show();
|
|
|
+ }else {
|
|
|
+ Toast.makeText(getActivity(),"本地加载",Toast.LENGTH_SHORT).show();
|
|
|
+ List<SubscriptionNumber> tempSubscriptionNumbers = new ArrayList<>();
|
|
|
+ AllSubscriptonKindMessage tempSubscriptonKindMessage = new AllSubscriptonKindMessage();
|
|
|
+ for (int i = 0; i < keyStrings.size(); i++) {
|
|
|
+ String currentKey = keyStrings.get(i);
|
|
|
+ for (int j = 0; j < dbSubscriptionNumbers.size(); j++) {
|
|
|
+ if (currentMaster.equals(dbSubscriptionNumbers.get(j).getMaster())){
|
|
|
+ SubscriptionNumber currentSubscriptionNumber = dbSubscriptionNumbers.get(j);
|
|
|
+ if (currentSubscriptionNumber.getType().equals(currentKey)){
|
|
|
+ tempSubscriptionNumbers.add(currentSubscriptionNumber);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tempSubscriptonKindMessage.setSubscriptionKind(currentKey);
|
|
|
+ tempSubscriptonKindMessage.setSubscriptionNumbers(tempSubscriptionNumbers);
|
|
|
+
|
|
|
+ mAllSubscriptonKindMessages.add(tempSubscriptonKindMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (keyStrings.size() == 0) {
|
|
|
+ mRadioGroup.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ mRadioGroup.setVisibility(View.VISIBLE);
|
|
|
+ for (int i = 0; i < keyStrings.size(); i++) {
|
|
|
+ RadioButton radioButton = new RadioButton(getActivity());
|
|
|
+ radioButton.setButtonDrawable(null);
|
|
|
+ radioButton.setGravity(Gravity.CENTER);
|
|
|
+ radioButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
|
|
|
+ radioButton.setBackground(getResources().getDrawable(R.drawable.selector_subscribe_bg));
|
|
|
+ radioButton.setText(keyStrings.get(i));
|
|
|
+ radioButton.setTextColor(getResources().getColor(R.color.selector_subscribe_tv));
|
|
|
+ radioButton.setPadding(0, 30, 0, 30);
|
|
|
+ radioButton.setId(i);
|
|
|
+
|
|
|
+ if (i == rbPos) {
|
|
|
+// radioButton.setTextColor(getResources().getColor(R.color.red));
|
|
|
+ radioButton.setChecked(true);
|
|
|
+ } else {
|
|
|
+// radioButton.setTextColor(getResources().getColor(R.color.black));
|
|
|
+ radioButton.setChecked(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ mRadioGroup.addView(radioButton, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
+ }
|
|
|
+
|
|
|
+ mSubscriptionNumbers.clear();
|
|
|
+ mSubscriptionNumbers.addAll(mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
+ Log.d("allsubscription:", mSubscriptionNumbers.toString());
|
|
|
+ mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (DbException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -140,6 +214,11 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
switch (msg.what) {
|
|
|
case GET_ALL_SUBSCRIPTION:
|
|
|
progressDialog.dismiss();
|
|
|
+ try {
|
|
|
+ MyApplication.mDbUtils.deleteAll(SubscriptionNumber.class);
|
|
|
+ } catch (DbException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
String resultJson = msg.getData().getString("result");
|
|
|
Log.d("allsubscriptionResult: ", resultJson);
|
|
|
try {
|
|
|
@@ -151,8 +230,10 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
mEmptyLayout.showEmpty();
|
|
|
if (mPullToRefreshListView.isRefreshing()) {
|
|
|
mPullToRefreshListView.onRefreshComplete();
|
|
|
- Crouton.makeText(getActivity(), "没有订阅数据", 0xff99cc00, 1500).show();
|
|
|
+ Crouton.makeText(getActivity(), "没有未订阅数据", 0xff99cc00, 1500).show();
|
|
|
}
|
|
|
+ keyStrings.clear();
|
|
|
+ mRadioGroup.removeAllViews();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -175,6 +256,8 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
subscriptionNumber.setTitle(subsObject.getString("title"));
|
|
|
subscriptionNumber.setKind(subsObject.getString("kind"));
|
|
|
subscriptionNumber.setStatus(subsObject.getInt("status"));
|
|
|
+ subscriptionNumber.setType(key);
|
|
|
+ subscriptionNumber.setMaster(currentMaster);
|
|
|
if (subsObject.getInt("status") != 1) {
|
|
|
subscriptionNumbers.add(subscriptionNumber);
|
|
|
}
|
|
|
@@ -182,6 +265,11 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
if (subscriptionNumbers.size() != 0) {
|
|
|
keyStrings.add(key);
|
|
|
subscriptonKindMessage.setSubscriptionNumbers(subscriptionNumbers);
|
|
|
+ try {
|
|
|
+ MyApplication.mDbUtils.saveAll(subscriptionNumbers);
|
|
|
+ } catch (DbException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
mAllSubscriptonKindMessages.add(subscriptonKindMessage);
|
|
|
}
|
|
|
|
|
|
@@ -194,7 +282,9 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
mRadioGroup.setVisibility(View.GONE);
|
|
|
} else {
|
|
|
mRadioGroup.setVisibility(View.VISIBLE);
|
|
|
+ StringBuilder keyStringBuilder = new StringBuilder();
|
|
|
for (int i = 0; i < keyStrings.size(); i++) {
|
|
|
+ keyStringBuilder.append("," + keyStrings.get(i));
|
|
|
RadioButton radioButton = new RadioButton(getActivity());
|
|
|
radioButton.setButtonDrawable(null);
|
|
|
radioButton.setGravity(Gravity.CENTER);
|
|
|
@@ -215,11 +305,17 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
|
|
|
mRadioGroup.addView(radioButton, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
}
|
|
|
+ if (keyStringBuilder.length() > 2){
|
|
|
+ keyStringBuilder.delete(0, 1);
|
|
|
+ }
|
|
|
+ SharedUtil.putString(currentMaster+"subs",keyStringBuilder.toString());
|
|
|
+
|
|
|
}
|
|
|
mSubscriptionNumbers.clear();
|
|
|
mSubscriptionNumbers.addAll(mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
Log.d("allsubscription:", mSubscriptionNumbers.toString());
|
|
|
mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
+
|
|
|
if (mPullToRefreshListView.isRefreshing()) {
|
|
|
mPullToRefreshListView.onRefreshComplete();
|
|
|
Crouton.makeText(getActivity(), "刷新成功", 0xff99cc00, 1500).show();
|