|
|
@@ -10,23 +10,25 @@ import android.view.View;
|
|
|
import android.widget.AdapterView;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.ListView;
|
|
|
+import android.widget.PopupWindow;
|
|
|
import android.widget.RadioButton;
|
|
|
import android.widget.RadioGroup;
|
|
|
+import android.widget.TextView;
|
|
|
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;
|
|
|
import com.xzjmyk.pm.activity.bean.message.AllSubscriptonKindMessage;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.activity.SubscribeDetailActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.db.DBManager;
|
|
|
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.DisplayUtil;
|
|
|
import com.xzjmyk.pm.activity.util.SharedUtil;
|
|
|
import com.xzjmyk.pm.activity.view.crouton.Crouton;
|
|
|
import com.xzjmyk.pm.activity.view.crouton.Style;
|
|
|
@@ -58,6 +60,8 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
private final static int SUBSCRIBE_DETAIL_REQUEST = 33;
|
|
|
private static int mClickedPos = -1;
|
|
|
String currentMaster;
|
|
|
+ private DBManager mDbManager;
|
|
|
+ private PopupWindow mDeletePopupWindow;
|
|
|
|
|
|
@Override
|
|
|
protected int getLayout() {
|
|
|
@@ -66,8 +70,9 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
|
|
|
@Override
|
|
|
protected void initViews() {
|
|
|
+ mDbManager = new DBManager(getActivity());
|
|
|
mRadioGroup = (RadioGroup) root.findViewById(R.id.subscription_all_rg);
|
|
|
- currentMaster = CommonUtil.getSharedPreferences(getActivity(),"erp_master");
|
|
|
+ currentMaster = CommonUtil.getSharedPreferences(getActivity(), "erp_master");
|
|
|
mPullToRefreshListView = (PullToRefreshListView) root.findViewById(R.id.subscription_all_ptlv);
|
|
|
mSubscriptionNumbers = new ArrayList<>();
|
|
|
mAllSubscriptionAdapter = new AllSubscriptionAdapter(getActivity(), mSubscriptionNumbers);
|
|
|
@@ -110,43 +115,127 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
mClickedPos = position;
|
|
|
Intent intent = new Intent();
|
|
|
intent.setClass(getActivity(), SubscribeDetailActivity.class);
|
|
|
- intent.putExtra("flag","all");
|
|
|
+ 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());
|
|
|
startActivityForResult(intent, SUBSCRIBE_DETAIL_REQUEST);
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ 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);
|
|
|
+ TextView deleteTv = (TextView) popView.findViewById(R.id.pop_subs_delete_tv);
|
|
|
+ deleteTv.setText("删除订阅号");
|
|
|
+ deleteTv.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ Toast.makeText(getActivity(), position + "", Toast.LENGTH_SHORT).show();
|
|
|
+ mDbManager.deleteFromAllSubs(mSubscriptionNumbers.get(position - 1));
|
|
|
+ mSubscriptionNumbers.remove(position - 1);
|
|
|
+ mAllSubscriptonKindMessages.get(rbPos).setSubscriptionNumbers(mSubscriptionNumbers);
|
|
|
+ mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
+ if (mSubscriptionNumbers.size() == 0) {
|
|
|
+ mAllSubscriptonKindMessages.remove(rbPos);
|
|
|
+ keyStrings.remove(rbPos);
|
|
|
+ if (keyStrings.size() == 0) {
|
|
|
+ mRadioGroup.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ rbPos = 0;
|
|
|
+ mRadioGroup.removeAllViews();
|
|
|
+ initRadioGroup();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ closeDeletePopupWindow();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mDeletePopupWindow = new PopupWindow(popView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
+ mDeletePopupWindow.setOutsideTouchable(true);
|
|
|
+ mDeletePopupWindow.setFocusable(true);
|
|
|
+ mDeletePopupWindow.showAtLocation(getActivity().getWindow().getDecorView(), Gravity.CENTER, 0, 0);
|
|
|
+ DisplayUtil.backgroundAlpha(getActivity(), 0.5f);
|
|
|
+ mDeletePopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ closeDeletePopupWindow();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initRadioGroup() {
|
|
|
+ StringBuilder keyStringBuilder = new StringBuilder();
|
|
|
+ for (int i = 0; i < keyStrings.size(); i++) {
|
|
|
+ keyStringBuilder.append("," + keyStrings.get(i));
|
|
|
+ final 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);
|
|
|
+ }
|
|
|
+ if (keyStringBuilder.length() > 2) {
|
|
|
+ keyStringBuilder.delete(0, 1);
|
|
|
+ }
|
|
|
+ SharedUtil.putString(currentMaster + "subs", keyStringBuilder.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void closeDeletePopupWindow() {
|
|
|
+ if (mDeletePopupWindow != null) {
|
|
|
+ mDeletePopupWindow.dismiss();
|
|
|
+ mDeletePopupWindow = null;
|
|
|
+ DisplayUtil.backgroundAlpha(getActivity(), 1f);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void initDatas() {
|
|
|
// mAllSubscriptonKindMessages = (List<AllSubscriptonKindMessage>) MyApplication.getDataCacheFromMap("all_subs_cache");
|
|
|
- Log.d("currentMaster: ",currentMaster);
|
|
|
- String cacheKeys = SharedUtil.getString(currentMaster+"subs");
|
|
|
- if (cacheKeys != null){
|
|
|
+ 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){
|
|
|
+// List<SubscriptionNumber> dbSubscriptionNumbers = MyApplication.mDbUtils.findAll(SubscriptionNumber.class);
|
|
|
+ List<SubscriptionNumber> dbSubscriptionNumbers
|
|
|
+ = mDbManager.queryFromAllSubs(new String[]{currentMaster}, "subs_master=?");
|
|
|
+ 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();
|
|
|
+ Toast.makeText(getActivity(), "网络加载", Toast.LENGTH_SHORT).show();
|
|
|
+ } else {
|
|
|
+ Toast.makeText(getActivity(), "本地加载", Toast.LENGTH_SHORT).show();
|
|
|
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++) {
|
|
|
- if (currentMaster.equals(dbSubscriptionNumbers.get(j).getMaster())){
|
|
|
- SubscriptionNumber currentSubscriptionNumber = dbSubscriptionNumbers.get(j);
|
|
|
- if (currentSubscriptionNumber.getType().equals(currentKey)){
|
|
|
- tempSubscriptionNumbers.add(currentSubscriptionNumber);
|
|
|
- }
|
|
|
+ SubscriptionNumber currentSubscriptionNumber = dbSubscriptionNumbers.get(j);
|
|
|
+ if (currentSubscriptionNumber.getType().equals(currentKey)) {
|
|
|
+ tempSubscriptionNumbers.add(currentSubscriptionNumber);
|
|
|
}
|
|
|
}
|
|
|
tempSubscriptonKindMessage.setSubscriptionKind(currentKey);
|
|
|
@@ -157,38 +246,18 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
|
|
|
if (keyStrings.size() == 0) {
|
|
|
mRadioGroup.setVisibility(View.GONE);
|
|
|
+ mEmptyLayout.showEmpty();
|
|
|
} 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();
|
|
|
+ initRadioGroup();
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- } catch (DbException e) {
|
|
|
+ }
|
|
|
+ mSubscriptionNumbers.clear();
|
|
|
+ mSubscriptionNumbers.addAll(mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
+ Log.d("allsubscription:", mSubscriptionNumbers.toString());
|
|
|
+ mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
@@ -214,11 +283,12 @@ 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();
|
|
|
- }
|
|
|
+// try {
|
|
|
+// MyApplication.mDbUtils.deleteAll(SubscriptionNumber.class);
|
|
|
+// } catch (DbException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+ mDbManager.deleteMasterSubs(currentMaster);
|
|
|
String resultJson = msg.getData().getString("result");
|
|
|
Log.d("allsubscriptionResult: ", resultJson);
|
|
|
try {
|
|
|
@@ -265,11 +335,12 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
if (subscriptionNumbers.size() != 0) {
|
|
|
keyStrings.add(key);
|
|
|
subscriptonKindMessage.setSubscriptionNumbers(subscriptionNumbers);
|
|
|
- try {
|
|
|
+ /*try {
|
|
|
MyApplication.mDbUtils.saveAll(subscriptionNumbers);
|
|
|
} catch (DbException e) {
|
|
|
e.printStackTrace();
|
|
|
- }
|
|
|
+ }*/
|
|
|
+ mDbManager.saveListToAllSubs(subscriptionNumbers);
|
|
|
mAllSubscriptonKindMessages.add(subscriptonKindMessage);
|
|
|
}
|
|
|
|
|
|
@@ -282,34 +353,7 @@ 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);
|
|
|
- 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);
|
|
|
- }
|
|
|
- if (keyStringBuilder.length() > 2){
|
|
|
- keyStringBuilder.delete(0, 1);
|
|
|
- }
|
|
|
- SharedUtil.putString(currentMaster+"subs",keyStringBuilder.toString());
|
|
|
-
|
|
|
+ initRadioGroup();
|
|
|
}
|
|
|
mSubscriptionNumbers.clear();
|
|
|
mSubscriptionNumbers.addAll(mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
@@ -342,7 +386,7 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
}
|
|
|
}*/
|
|
|
mSubscriptionNumbers.clear();
|
|
|
- if (mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers().size() != 0){
|
|
|
+ if (mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers().size() != 0) {
|
|
|
mSubscriptionNumbers.addAll(mAllSubscriptonKindMessages.get(rbPos).getSubscriptionNumbers());
|
|
|
mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
}
|
|
|
@@ -352,8 +396,9 @@ public class SubscriptionAllFragment extends BaseFragment implements RadioGroup.
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
if (requestCode == SUBSCRIBE_DETAIL_REQUEST && resultCode == 9 && data != null) {
|
|
|
int statu = data.getIntExtra("status", 0);
|
|
|
- if (mClickedPos != -1){
|
|
|
+ if (mClickedPos != -1) {
|
|
|
mSubscriptionNumbers.get(mClickedPos - 1).setStatus(statu);
|
|
|
+ mDbManager.updateAllSubs(mSubscriptionNumbers.get(mClickedPos - 1));
|
|
|
mAllSubscriptionAdapter.notifyDataSetChanged();
|
|
|
}
|
|
|
}
|