Преглед на файлове

1.修改Android Apex Mobile Result Menu动态生成。

Pen Li преди 7 години
родител
ревизия
a62e604e21

+ 41 - 18
ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/ApexResultActivity.java

@@ -35,6 +35,7 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import java.util.ArrayList;
 import java.util.Iterator;
 
 
@@ -314,31 +315,53 @@ public class ApexResultActivity extends AppCompatActivity implements ApexResultP
 
     private void menuItemClick() {
 
-        ActionSheet actionSheet = new ActionSheet(mCtx);
+        ArrayList<ApexResultMenuItem> menuItems = mPresenter.getMenuItems();
+        if (menuItems != null && menuItems.size() > 0) {
 
-        actionSheet.addAction("Setting", ActionSheet.ActionType.ActionTypeDefault, new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                showFieldsSetting();
-            }
-        });
+            ActionSheet actionSheet = new ActionSheet(mCtx);
 
-        actionSheet.addAction("Save", ActionSheet.ActionType.ActionTypeDefault, new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                saveSearchParameters();
-            }
-        });
+            int len = menuItems.size();
+            for (int i = 0; i < len; i++) {
 
-        actionSheet.addAction("Cancel", ActionSheet.ActionType.ACtionTypeCancel, new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
+                final ApexResultMenuItem menuItem = menuItems.get(i);
+                actionSheet.addAction(menuItem.title, ActionSheet.ActionType.ActionTypeDefault, new View.OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        if (menuItem.action != null) {
 
+                            if (menuItem.action.equals("save")) {
+
+                                saveSearchParameters();
+                            } else if (menuItem.action.equals("field_setting")) {
+                                showFieldsSetting();
+                            }
+                        }
+                    }
+                });
             }
-        });
 
-        actionSheet.show();
+            actionSheet.addAction("Cancel", ActionSheet.ActionType.ACtionTypeCancel, new View.OnClickListener() {
+                @Override
+                public void onClick(View v) {
+
+                }
+            });
+
+            actionSheet.show();
 
+        } else {
+
+            new AlertDialog.Builder(mCtx)
+                    .setTitle("Warning")
+                    .setMessage("there is no menu field to response")
+                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+                        @Override
+                        public void onClick(DialogInterface dialog, int which) {
+
+                        }
+                    })
+                    .show();
+        }
     }
 
     private void saveSearchParameters() {

+ 10 - 0
ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/ApexResultMenuItem.java

@@ -0,0 +1,10 @@
+package com.usai.apex.apexresult;
+
+import com.usai.apex.base.BaseObject;
+
+public class ApexResultMenuItem extends BaseObject {
+
+    public String title;
+    public String action;
+
+}

+ 25 - 0
ApexDrivers/apexmobile/src/main/java/com/usai/apex/apexresult/ApexResultPresenter.java

@@ -58,6 +58,9 @@ public class ApexResultPresenter implements ApexResultAdapter.ApexResultAdapterD
     private JSONArray rowActions;
     private JSONArray actions;
     public boolean dirty = true;
+    private ArrayList<ApexResultMenuItem> mMenuItems;
+
+
 
     public ApexResultPresenter(ApexResultProtocol delegate, Bundle params) {
         if (delegate == null) {
@@ -234,6 +237,10 @@ public class ApexResultPresenter implements ApexResultAdapter.ApexResultAdapterD
         return mParams;
     }
 
+    public ArrayList<ApexResultMenuItem> getMenuItems() {
+        return mMenuItems;
+    }
+
     // endregion
 
     // region DataSource
@@ -356,6 +363,24 @@ public class ApexResultPresenter implements ApexResultAdapter.ApexResultAdapterD
                     rowActions = json.optJSONArray("row_actions");
                     actions = json.optJSONArray("actions");
 
+                    JSONArray menu = json.optJSONArray("menu");
+                    if (menu != null) {
+
+                        ArrayList<ApexResultMenuItem> menuItems = new ArrayList<>();
+                        int len = menu.length();
+                        for (int i = 0; i < len; i++) {
+
+                            JSONObject item = menu.optJSONObject(i);
+                            if (item != null) {
+
+                                ApexResultMenuItem menuItem = new ApexResultMenuItem();
+                                menuItem.setValuesForKeysWithJSON(item);
+                                menuItems.add(menuItem);
+                            }
+                        }
+                        mMenuItems = menuItems;
+                    }
+
                     mDataArray = models;
                     if (getDelegate() != null) {
                         getDelegate().onSuccess(title);