Browse Source

隐藏订阅号添加

RaoMeng 9 years ago
parent
commit
7c1de1e60d

+ 57 - 27
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/activity/ManageAllSubscriptionActivity.java

@@ -2,14 +2,17 @@ package com.xzjmyk.pm.activity.ui.erp.activity;
 
 import android.content.Intent;
 import android.os.Bundle;
+import android.widget.ListView;
 
 import com.xzjmyk.pm.activity.R;
 import com.xzjmyk.pm.activity.bean.SubscriptionNumber;
+import com.xzjmyk.pm.activity.bean.message.AllSubscriptonKindMessage;
 import com.xzjmyk.pm.activity.ui.base.BaseActivity;
+import com.xzjmyk.pm.activity.ui.erp.adapter.AllRemovedSubsAdapter;
 import com.xzjmyk.pm.activity.ui.erp.db.DBManager;
 import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
+import com.xzjmyk.pm.activity.ui.erp.view.EmptyLayout;
 import com.xzjmyk.pm.activity.util.Constants;
-import com.xzjmyk.pm.activity.util.SharedUtil;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -22,9 +25,15 @@ public class ManageAllSubscriptionActivity extends BaseActivity {
     private DBManager mDbManager;
     private String currentMaster;//当前账套
     private String currentUser;//当前账号
-    private List<SubscriptionNumber> dbSubscriptionNumbers;
+    private List<SubscriptionNumber> dbSubscriptionNumbers;//数据库数据
+    private List<SubscriptionNumber> mSubscriptionNumbers;//被移除的订阅数据
     private List<Object> keyStrings;
-    private List<Object> allKeyStrings;
+    private List<Object> removedKeyStrings;
+
+    private ListView mRemovedListView;
+    private EmptyLayout mEmptyLayout;
+    private List<AllSubscriptonKindMessage> mAllSubscriptonKindMessages;
+    private AllRemovedSubsAdapter mAllRemovedSubsAdapter;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -46,20 +55,58 @@ public class ManageAllSubscriptionActivity extends BaseActivity {
         if (dbSubscriptionNumbers != null && dbSubscriptionNumbers.size() != 0) {
             for (int i = 0; i < dbSubscriptionNumbers.size(); i++) {
                 SubscriptionNumber subscriptionNumber = dbSubscriptionNumbers.get(i);
-                subscriptionNumber.setRemoved(0);
-                allKeyStrings.add(subscriptionNumber.getType());
+                if (subscriptionNumber.getRemoved() == 1 && subscriptionNumber.getStatus() != 1){
+                    mSubscriptionNumbers.add(subscriptionNumber);
+                }
+            }
+            if (mSubscriptionNumbers == null || mSubscriptionNumbers.size() == 0){
+                mEmptyLayout.showEmpty();
+            }else {
+                for (int i = 0; i < mSubscriptionNumbers.size(); i++) {
+                    removedKeyStrings.add(mSubscriptionNumbers.get(i).getType());
+                }
+                keyStrings = CommonUtil.getSingleElement(removedKeyStrings);
+
+                for (int i = 0; i < keyStrings.size(); i++) {
+                    List<SubscriptionNumber> tempSubscriptionNumbers = null;
+                    String key = keyStrings.get(i).toString();
+                    AllSubscriptonKindMessage subscriptonKindMessage = new AllSubscriptonKindMessage();
+                    subscriptonKindMessage.setSubscriptionKind(key);
+                    tempSubscriptionNumbers = new ArrayList<>();
+                    for (int j = 0; j < mSubscriptionNumbers.size(); j++) {
+                        SubscriptionNumber tempSubscriptionNumber = mSubscriptionNumbers.get(j);
+                        if (tempSubscriptionNumber.getType().equals(key)){
+                            tempSubscriptionNumbers.add(tempSubscriptionNumber);
+                        }
+                    }
+                    if (tempSubscriptionNumbers != null && tempSubscriptionNumbers.size() != 0){
+                        subscriptonKindMessage.setSubscriptionNumbers(tempSubscriptionNumbers);
+                    }
+                    mAllSubscriptonKindMessages.add(subscriptonKindMessage);
+                }
+                mAllRemovedSubsAdapter.notifyDataSetChanged();
             }
-            mDbManager.updateListAllSubs(dbSubscriptionNumbers);
+
+        }else {
+            mEmptyLayout.showEmpty();
         }
 
-        keyStrings = CommonUtil.getSingleElement(allKeyStrings);
-        initKeyStrings();
-//        Toast.makeText(this, "整理完成", Toast.LENGTH_SHORT).show();
     }
 
     private void initViews() {
+        mRemovedListView = (ListView) findViewById(R.id.manage_all_subs_lv);
+        mSubscriptionNumbers = new ArrayList<>();
+        mAllSubscriptonKindMessages = new ArrayList<>();
+
+        mAllRemovedSubsAdapter = new AllRemovedSubsAdapter(mAllSubscriptonKindMessages,this);
+        mRemovedListView.setAdapter(mAllRemovedSubsAdapter);
+        mEmptyLayout = new EmptyLayout(this, mRemovedListView);
+        mEmptyLayout.setShowLoadingButton(false);
+        mEmptyLayout.setShowErrorButton(false);
+        mEmptyLayout.setShowEmptyButton(false);
+        mEmptyLayout.setEmptyMessage("您没有隐藏的订阅号");
         keyStrings = new ArrayList<>();
-        allKeyStrings = new ArrayList<>();
+        removedKeyStrings = new ArrayList<>();
         mDbManager = new DBManager(this);
         currentMaster = CommonUtil.getSharedPreferences(this, "erp_master");
         currentUser = CommonUtil.getSharedPreferences(this, "erp_username");
@@ -68,23 +115,6 @@ public class ManageAllSubscriptionActivity extends BaseActivity {
 
     }
 
-    private void initKeyStrings() {
-        StringBuilder keyStringBuilder = null;
-        if (keyStrings.size() != 0) {
-            keyStringBuilder = new StringBuilder();
-            for (int i = 0; i < keyStrings.size(); i++) {
-                keyStringBuilder.append("," + keyStrings.get(i));
-            }
-            if (keyStringBuilder.length() > 2) {
-                keyStringBuilder.delete(0, 1);
-            }
-            SharedUtil.putString(currentMaster + currentUser + "subs", keyStringBuilder.toString());
-        } else {
-            SharedUtil.putString(currentMaster + currentUser + "subs", null);
-        }
-
-    }
-
     @Override
     protected void onDestroy() {
         super.onDestroy();

+ 91 - 0
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/adapter/AllRemovedSubsAdapter.java

@@ -0,0 +1,91 @@
+package com.xzjmyk.pm.activity.ui.erp.adapter;
+
+import android.content.Context;
+import android.os.Handler;
+import android.os.Message;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+import com.xzjmyk.pm.activity.R;
+import com.xzjmyk.pm.activity.bean.SubscriptionNumber;
+import com.xzjmyk.pm.activity.bean.message.AllSubscriptonKindMessage;
+import com.xzjmyk.pm.activity.ui.erp.view.EmptyLayout;
+import com.xzjmyk.pm.activity.view.MyListView;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 被隐藏的所有订阅号的适配器
+ * Created by RaoMeng on 2016/10/31.
+ */
+public class AllRemovedSubsAdapter extends BaseAdapter {
+    private List<AllSubscriptonKindMessage> mAllSubscriptonKindMessages;
+    private Context mContext;
+    private List<SubscriptionNumber> mSubscriptionNumbers;
+    private AllRemovedSubsItemAdapter mAllRemovedSubsItemAdapter;
+    public AllRemovedSubsAdapter(List<AllSubscriptonKindMessage> mAllSubscriptonKindMessages, Context mContext) {
+        this.mAllSubscriptonKindMessages = mAllSubscriptonKindMessages;
+        this.mContext = mContext;
+
+        mSubscriptionNumbers = new ArrayList<>();
+    }
+
+    @Override
+    public int getCount() {
+        return mAllSubscriptonKindMessages.size();
+    }
+
+    @Override
+    public Object getItem(int position) {
+        return mAllSubscriptonKindMessages.get(position);
+    }
+
+    @Override
+    public long getItemId(int position) {
+        return position;
+    }
+
+    @Override
+    public View getView(int position, View convertView, ViewGroup parent) {
+        ViewHolder viewHolder = null;
+        if (convertView == null){
+            convertView = View.inflate(mContext, R.layout.layout_list_manage_all_subs,null);
+            viewHolder = new ViewHolder();
+            viewHolder.subsListView = (MyListView) convertView.findViewById(R.id.manage_all_subs_list_mlv);
+            viewHolder.typeTextView = (TextView) convertView.findViewById(R.id.manage_all_subs_list_type_tv);
+            convertView.setTag(viewHolder);
+        }else {
+            viewHolder = (ViewHolder) convertView.getTag();
+        }
+
+        viewHolder.typeTextView.setText(mAllSubscriptonKindMessages.get(position).getSubscriptionKind());
+        mSubscriptionNumbers = mAllSubscriptonKindMessages.get(position).getSubscriptionNumbers();
+        mAllRemovedSubsItemAdapter = new AllRemovedSubsItemAdapter(mSubscriptionNumbers,mContext,mHandler);
+        viewHolder.subsListView.setAdapter(mAllRemovedSubsItemAdapter);
+        return convertView;
+    }
+
+    private Handler mHandler = new Handler(){
+        @Override
+        public void handleMessage(Message msg) {
+            super.handleMessage(msg);
+            if (msg.what == 111){
+                String key = (String) msg.obj;
+                for (int i = 0; i < mAllSubscriptonKindMessages.size(); i++) {
+                    if (mAllSubscriptonKindMessages.get(i).getSubscriptionKind().equals(key)){
+                        mAllSubscriptonKindMessages.remove(i);
+                        notifyDataSetChanged();
+                    }
+                }
+            }
+        }
+    };
+
+    class ViewHolder{
+        TextView typeTextView;
+        MyListView subsListView;
+    }
+}

+ 128 - 0
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/adapter/AllRemovedSubsItemAdapter.java

@@ -0,0 +1,128 @@
+package com.xzjmyk.pm.activity.ui.erp.adapter;
+
+import android.content.Context;
+import android.os.Handler;
+import android.os.Message;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+import com.xzjmyk.pm.activity.R;
+import com.xzjmyk.pm.activity.bean.SubscriptionNumber;
+import com.xzjmyk.pm.activity.ui.erp.db.DBManager;
+import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
+import com.xzjmyk.pm.activity.util.SharedUtil;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 被移除订阅号的item适配器
+ * Created by RaoMeng on 2016/10/31.
+ */
+public class AllRemovedSubsItemAdapter extends BaseAdapter {
+    private List<SubscriptionNumber> mSubscriptionNumbers;
+    private Context mContext;
+    private List<Object> keyStrings;
+    private List<Object> cacheKeyStrings;
+    private String currentMaster;//当前账套
+    private String currentUser;//当前账号
+    private DBManager mDbManager;
+    private Handler mHandler;
+    public AllRemovedSubsItemAdapter(List<SubscriptionNumber> mSubscriptionNumbers, Context mContext, Handler mHandler) {
+        this.mSubscriptionNumbers = mSubscriptionNumbers;
+        this.mContext = mContext;
+        this.mHandler = mHandler;
+        keyStrings = new ArrayList<>();
+        cacheKeyStrings = new ArrayList<>();
+        mDbManager = new DBManager(mContext);
+        currentMaster = CommonUtil.getSharedPreferences(mContext, "erp_master");
+        currentUser = CommonUtil.getSharedPreferences(mContext, "erp_username");
+
+        String cacheKeys = SharedUtil.getString(currentMaster + currentUser + "subs");
+        if (cacheKeys != null) {
+            String[] cacheKeysArray = cacheKeys.split(",");
+            for (int i = 0; i < cacheKeysArray.length; i++) {
+                cacheKeyStrings.add(cacheKeysArray[i]);
+            }
+        }
+    }
+
+    @Override
+    public int getCount() {
+        return mSubscriptionNumbers.size();
+    }
+
+    @Override
+    public Object getItem(int position) {
+        return mSubscriptionNumbers.get(position);
+    }
+
+    @Override
+    public long getItemId(int position) {
+        return position;
+    }
+
+    @Override
+    public View getView(final int position, View convertView, ViewGroup parent) {
+        ViewHolder viewHolder = null;
+        if (convertView == null){
+            convertView = View.inflate(mContext, R.layout.layout_list_manage_all_subs_item,null);
+            viewHolder = new ViewHolder();
+            viewHolder.addTextView = (TextView) convertView.findViewById(R.id.manage_all_subs_list_item_add_tv);
+            viewHolder.nameTextView = (TextView) convertView.findViewById(R.id.manage_all_subs_list_item_name_tv);
+            convertView.setTag(viewHolder);
+        }else {
+            viewHolder = (ViewHolder) convertView.getTag();
+        }
+        viewHolder.nameTextView.setText(mSubscriptionNumbers.get(position).getTitle());
+        viewHolder.addTextView.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                mSubscriptionNumbers.get(position).setRemoved(0);
+                mDbManager.updateAllSubs(mSubscriptionNumbers.get(position));
+                cacheKeyStrings.add(mSubscriptionNumbers.get(position).getType());
+                String type = mSubscriptionNumbers.get(position).getType();
+                mSubscriptionNumbers.remove(position);
+                notifyDataSetChanged();
+                keyStrings = CommonUtil.getSingleElement(cacheKeyStrings);
+                initKeyStrings();
+
+                if (mSubscriptionNumbers.size() == 0){
+                    Message message = Message.obtain();
+                    message.what = 111;
+                    message.obj = type;
+                    mHandler.sendMessage(message);
+                }
+            }
+        });
+        return convertView;
+    }
+
+
+    private void initKeyStrings() {
+        StringBuilder keyStringBuilder = null;
+        if (keyStrings.size() != 0) {
+            keyStringBuilder = new StringBuilder();
+            for (int i = 0; i < keyStrings.size(); i++) {
+                keyStringBuilder.append("," + keyStrings.get(i));
+            }
+            if (keyStringBuilder.length() > 2) {
+                keyStringBuilder.delete(0, 1);
+            }
+            SharedUtil.putString(currentMaster + currentUser + "subs", keyStringBuilder.toString());
+        } else {
+            SharedUtil.putString(currentMaster + currentUser + "subs", null);
+        }
+
+    }
+
+
+    class ViewHolder{
+        TextView nameTextView;
+        TextView addTextView;
+    }
+}

+ 3 - 1
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/fragment/SubscriptionAllFragment.java

@@ -348,7 +348,9 @@ public class SubscriptionAllFragment extends BaseFragment {
                     String currentKey = keyStrings.get(i);
                     for (int j = 0; j < dbSubscriptionNumbers.size(); j++) {
                         SubscriptionNumber currentSubscriptionNumber = dbSubscriptionNumbers.get(j);
-                        if (currentSubscriptionNumber.getType().equals(currentKey)) {
+                        if (currentSubscriptionNumber.getType().equals(currentKey)
+                                && currentSubscriptionNumber.getRemoved() != 1
+                                && currentSubscriptionNumber.getStatus() != 1) {
                             tempSubscriptionNumbers.add(currentSubscriptionNumber);
                         }
                     }

+ 3 - 4
WeiChat/src/main/res/layout/activity_manage_all_subs.xml

@@ -4,9 +4,8 @@
     android:layout_height="match_parent"
     android:orientation="vertical">
 
-    <TextView
+    <ListView
+        android:id="@+id/manage_all_subs_lv"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:gravity="center"
-        android:text="未订阅整理页面"/>
+        android:layout_height="match_parent"/>
 </LinearLayout>

+ 31 - 0
WeiChat/src/main/res/layout/layout_list_manage_all_subs.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="45dp"
+    android:orientation="vertical"
+    android:padding="5dp">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="10dp"
+        android:orientation="horizontal">
+        <ImageView
+            android:layout_width="35dp"
+            android:layout_height="35dp"
+            android:src="@drawable/ic_subscription_number"/>
+        <TextView
+            android:id="@+id/manage_all_subs_list_type_tv"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical"
+            android:text="销售管理"
+            android:layout_marginLeft="10dp"
+            android:textSize="16sp"/>
+    </LinearLayout>
+    <com.xzjmyk.pm.activity.view.MyListView
+        android:id="@+id/manage_all_subs_list_mlv"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="5dp"/>
+</LinearLayout>

+ 28 - 0
WeiChat/src/main/res/layout/layout_list_manage_all_subs_item.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:padding="3dp">
+
+    <TextView
+        android:id="@+id/manage_all_subs_list_item_name_tv"
+        android:layout_width="200dp"
+        android:layout_height="30dp"
+        android:layout_centerInParent="true"
+        android:paddingLeft="5dp"
+        android:gravity="center_vertical"
+        android:textColor="@color/white"
+        android:text="毛利润分析"
+        android:singleLine="true"
+        android:background="@drawable/shape_subscribe_bg"/>
+
+    <TextView
+        android:id="@+id/manage_all_subs_list_item_add_tv"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_toRightOf="@id/manage_all_subs_list_item_name_tv"
+        android:layout_marginLeft="10dp"
+        android:text="+添加"
+        android:layout_centerVertical="true"
+        android:textColor="@color/blue"/>
+</RelativeLayout>