Browse Source

common editor adds support for implant menu -- common editor 增加植入菜单支持(resolve: #14555)
Edit function adds save, submit and delete functions -- 编辑功能增加保存,提交,删除功能(issue20: #14556)

Ray Zhang 4 năm trước cách đây
mục cha
commit
9caac03f07

+ 42 - 4
ApexDrivers/CommonEditorLib/src/main/java/com/usai/commoneditorlib/CommonEditorActivity.java

@@ -128,8 +128,11 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
 //        return pd;
 //    }
 
+    private Menu editor_menu;
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
+        editor_menu = menu;
+        injectMenu();
         getMenuInflater().inflate(R.menu.action_bar_menu,menu);
         return true;
     }
@@ -137,10 +140,10 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
 
-        if (item.getItemId() == R.id.save_item) {
-            JSONObject obj = check_cancomit(true);
-            Log.d("Check Can Commit", "onOptionsItemSelected: ");
-        }
+//        if (item.getItemId() == R.id.save_item) {
+//            JSONObject obj = check_cancomit(true);
+//            Log.d("Check Can Commit", "onOptionsItemSelected: ");
+//        }
 
         return true;
     }
@@ -295,6 +298,13 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
                                         content_data_download = copyDirtyTo(content_data_download,obj);
                                         content_data_control = translateChange(content_data_download,changed_data);
 
+                                        JSONArray arr_menu = obj.optJSONArray("menu");
+
+                                        injectMenu=arr_menu;
+
+
+
+                                            injectMenu();
 
                                         download_success();
                                         defaulExpandSections();
@@ -362,6 +372,34 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
     }
 
 
+    protected JSONArray injectMenu;
+    protected  void injectMenu()
+    {
+        runOnUiThread(new Runnable() {
+
+            @Override
+            public void run() {
+                if(injectMenu!=null&&editor_menu!=null)
+                {
+
+                    editor_menu.removeGroup(-1);
+
+                    for(int i=0;i<injectMenu.length();i++)
+                    {
+                        JSONObject item= injectMenu.optJSONObject(i);
+
+
+//				public MenuItem add(int groupId, int itemId, int order, CharSequence title);
+                        editor_menu.add(-1,i,i,item.optString("title"));
+
+                    }
+
+                }
+                // Stuff that updates the UI
+
+            }
+        });
+    }
     @Override
     protected void onResume() {
         super.onResume();

+ 4 - 4
ApexDrivers/CommonEditorLib/src/main/res/menu/action_bar_menu.xml

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
 
-    <item
-        android:id="@+id/save_item"
-        android:title="Save"
-        />
+<!--    <item-->
+<!--        android:id="@+id/save_item"-->
+<!--        android:title="Save"-->
+<!--        />-->
 
 </menu>

+ 10 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/RAUtil.java

@@ -66,6 +66,16 @@ import java.util.regex.Pattern;
 public class RAUtil {
 
 
+    public  static void mergeJson(JSONObject obj1,JSONObject obj2)
+    {
+
+        Iterator<String> keys = obj2.keys();
+        while( keys.hasNext() ) {
+            String key =  keys.next();
+            obj1.put(key, obj2.optString(key);
+        }
+
+    }
     public static Activity getCurrentActivity () {
         try {
             Class activityThreadClass = Class.forName("android.app.ActivityThread");

+ 4 - 0
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/dataprovider/OfflineDataProvider.java

@@ -27,6 +27,10 @@ public class OfflineDataProvider {
         {
             commObj = getJsonFromAsset(TradeFilingApplication.get_instance().getApplicationContext(), "edit_"+subtype+".json");
         }
+        else if (subtype.equals("party"))
+        {
+            commObj = getJsonFromAsset(TradeFilingApplication.get_instance().getApplicationContext(), "edit_"+subtype+".json");
+        }
 
         if(commObj==null)
         {

+ 10 - 1
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/dataprovider/RADataProvider.java

@@ -28,7 +28,16 @@ public class RADataProvider {
 //    public static final int		RESULT_SESSION_EXPIRED			= -13;
 //    public static final int		RESULT_VER_LOW					= -15;
 
-
+    public static JSONObject save_editor(String url,Bundle param)
+    {
+        if(FAKE_DATA)
+        {
+            return OfflineDataProvider.save_editor(url,param);
+        }
+        else {
+            return OnlineDataProvider.save_editor(url,param);
+        }
+    }
 
     public static JSONObject request_editor(String url,Bundle param)
     {

+ 369 - 2
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/tfeditor/TFEditorActivity.java

@@ -1,9 +1,12 @@
 package com.usai.ratradefiling.tfeditor;
 
+import android.app.ProgressDialog;
 import android.content.Context;
 //import android.support.v7.app.AppCompatActivity;
 import android.content.Intent;
 import android.os.Bundle;
+import android.view.MenuItem;
+import android.view.View;
 
 //import com.usai.redant.CommonEditor.CommonEditorActivity;
 //import com.usai.redant.redantmobile.R;
@@ -13,14 +16,17 @@ import com.usai.commoneditorlib.CommonEditorActivity;
 import com.usai.commoneditorlib.EnumSlectOnlineActivity;
 import com.usai.ratradefiling.R;
 import com.usai.ratradefiling.dataprovider.RADataProvider;
+import com.usai.redant.rautils.utils.Network;
 import com.usai.redant.rautils.utils.RAUtil;
 
+import org.json.JSONException;
 import org.json.JSONObject;
 
 import java.lang.reflect.ParameterizedType;
 
 import static com.usai.ratradefiling.dataprovider.OnlineDataProvider.URL_CADEDATE;
 import static com.usai.ratradefiling.dataprovider.OnlineDataProvider.URL_EDIT;
+import static com.usai.redant.rautils.utils.RAUtil.getJsonFromAsset;
 
 public class TFEditorActivity extends CommonEditorActivity
 {
@@ -52,13 +58,374 @@ public class TFEditorActivity extends CommonEditorActivity
         return RADataProvider.request_editor(request_url, params);
     }
 
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item)
+    {
+
+        JSONObject jitem = injectMenu.optJSONObject(item.getItemId());
+
+        if(jitem==null)
+        {
+            return super.onOptionsItemSelected(item);
+        }
+        String type = jitem.optString("type");
+
+//        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
+
+
+        if (lastEditText != null) {
+            endEditting();
+        }
+        
+
+        JSONObject upparams = check_cancomit(false);
+
+
+        for(int i=0;i<injectMenu.length();i++)
+        {
+            
+            JSONObject subitem = injectMenu.get(i);
+
+
+
+//            UIAlertAction *injectAction = [UIAlertAction actionWithTitle:NSLocalizedString(item[@"title"], nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+
+            if(subitem.optString("name","").equals("save"))
+            {
+                JSONObject params= subitem.optJSONObject("params");
+
+                RAUtil.mergeJson(upparams,params);
+
+                final ProgressDialog pd = RAUtil.waiting_alert(mCtx,"Saving","please wait");
+
+                new Thread(new Runnable()
+                {
+                    @Override
+                    public void run()
+                    {
+
+
+                        JSONObject result_json = null;
+
+
+
+                        JSONObject finalResult_json = result_json;
+                        runOnUiThread(new Runnable()
+                        {
+                            @Override
+                            public void run()
+                            {
+
+                                pd.dismiss();
+
+
+//                        pd.dismiss();
+                                try
+                                {
+
+                                    int result = finalResult_json.optInt("result");
+                                    if (result == 2)
+                                    {
+
+                                        if (option != LoadDataOptionLoadMore)
+                                        {
+                                            mCadedate = new JSONObject();
+                                        }
+
+                                        int count = finalResult_json.optInt("count");
+                                        if (count >= limit)
+                                        {
+                                            hasmore = true;
+                                        }
+                                        else
+                                        {
+
+                                            mListFooterView.setText("No more data");
+                                            mListFooterView.setVisibility(View.VISIBLE);
+                                            hasmore = false;
+
+                                        }
+                                        int ccount = mCadedate.optInt("count");
+                                        for (int ipr = 0; ipr < count; ipr++)
+                                        {
+
+                                            JSONObject item = finalResult_json.optJSONObject("val_" + ipr);
+
+
+                                            mCadedate.put("val_" + (ccount + ipr), item);
+
+
+                                        }
+                                        mCadedate.put("count", ccount + count);
+                                        offset = ccount + count;
+
+                                        adapter.notifyDataSetChanged();
+
+                                    }
+                                    else
+                                    {
+                                        RAUtil.alertMessage(mCtx, "", finalResult_json.optString("err_msg"));
+                                    }
+                                } catch (JSONException e)
+                                {
+                                    e.printStackTrace();
+                                }
+                            }
+                        });
+                    }
+                }).start();
+
+
+
+                [RADataProvider SaveEditor:upparams completionHandler:^(NSMutableDictionary *result) {
+                int ret=[result[@"result"] intValue];
+
+                if (ret==RESULT_TRUE)
+                {
+                            
+                            
+                            [RAUtils message_alert:@"Successful" title:@"Save" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
+                                [self.navigationController popViewControllerAnimated:YES];
+                                [self prepareReturn:nil];
+                }  completion:^{
+
+
+
+                }];
+                    //            NSUser
+
+//                            [self.navigationController popViewControllerAnimated:true];
+
+
+
+                }
+                else
+                {
+                            
+                            [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_LOGIN_FAILED object:nil];
+                    //                int a = RESULT_NET_NOTAVAILABLE;
+                    NSString* message = nil;
+                    switch (ret) {
+                        case RESULT_NET_NOTAVAILABLE:
+                            message = NSLocalizedString(@"net_not_available", nil);
+                            break;
+                        case RESULT_NET_ERROR:
+                            message = NSLocalizedString(@"net_error", nil);
+                            break;
+                        case RESULT_FALSE:
+                            message = NSLocalizedString(@"auth_error", nil);
+                            break;
+                        case RESULT_VER_LOW:
+                            message = NSLocalizedString(@"ver_low", nil);
+                            break;
+                        case RESULT_FAILED_WITH_MESSAGE:
+                            message = result[@"err_msg"];
+                            break;
+                        default:
+                            message=[NSString stringWithFormat:@"Failed to login code %d",ret];
+                            break;
+                    }
+
+                    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_error", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
+                    UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+
+                }];
+                            
+                            [alertVC addAction:action];
+                            
+                            [self presentViewController:alertVC animated:YES completion:nil];
+
+                }
+
+            }];
+
+            }else
+            if([item[@"name"] isEqualToString:@"save&submit"])
+            {
+                JSONObject params= item[@"params"];
+                        [upparams addEntriesFromDictionary:params];
+                        
+                        [RADataProvider SaveEditor:upparams completionHandler:^(NSMutableDictionary *result) {
+                int ret=[result[@"result"] intValue];
+
+                if (ret==RESULT_TRUE)
+                {
+                                
+                                
+                                [RAUtils message_alert:@"Successful" title:@"Save" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
+                                    [self.navigationController popViewControllerAnimated:YES];
+                                    [self prepareReturn:nil];
+
+                }  completion:^{
+
+
+
+                }];
+                    //            NSUser
+
+                    //                            [self.navigationController popViewControllerAnimated:true];
+
+
+
+                }
+                else
+                {
+                                
+                                [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_LOGIN_FAILED object:nil];
+                    //                int a = RESULT_NET_NOTAVAILABLE;
+                    NSString* message = nil;
+                    switch (ret) {
+                        case RESULT_NET_NOTAVAILABLE:
+                            message = NSLocalizedString(@"net_not_available", nil);
+                            break;
+                        case RESULT_NET_ERROR:
+                            message = NSLocalizedString(@"net_error", nil);
+                            break;
+                        case RESULT_FALSE:
+                            message = NSLocalizedString(@"auth_error", nil);
+                            break;
+                        case RESULT_VER_LOW:
+                            message = NSLocalizedString(@"ver_low", nil);
+                            break;
+                        case RESULT_FAILED_WITH_MESSAGE:
+                            message = result[@"err_msg"];
+                            break;
+                        default:
+                            message=[NSString stringWithFormat:@"Failed to login code %d",ret];
+                            break;
+                    }
+
+                    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_error", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
+                    UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+
+                }];
+                                
+                                [alertVC addAction:action];
+                                
+                                [self presentViewController:alertVC animated:YES completion:nil];
+                }
+
+            }];
+
+            }
+                    else
+            if([item[@"name"] isEqualToString:@"delete"])
+            {
+                JSONObject params= item[@"params"];
+                            [upparams addEntriesFromDictionary:params];
+                            
+                            [RADataProvider SaveEditor:upparams completionHandler:^(NSMutableDictionary *result) {
+                int ret=[result[@"result"] intValue];
+
+                if (ret==RESULT_TRUE)
+                {
+                                    
+                                    
+                                    [RAUtils message_alert:@"Successful" title:@"Delete" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
+                                        [self.navigationController popViewControllerAnimated:YES];
+                                        [self prepareReturn:nil];
+                }  completion:^{
+
+
+
+                }];
+                    //            NSUser
+
+                    //                            [self.navigationController popViewControllerAnimated:true];
+
+
+
+                }
+                else
+                {
+                                    
+                                    [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_LOGIN_FAILED object:nil];
+                    //                int a = RESULT_NET_NOTAVAILABLE;
+                    NSString* message = nil;
+                    switch (ret) {
+                        case RESULT_NET_NOTAVAILABLE:
+                            message = NSLocalizedString(@"net_not_available", nil);
+                            break;
+                        case RESULT_NET_ERROR:
+                            message = NSLocalizedString(@"net_error", nil);
+                            break;
+                        case RESULT_FALSE:
+                            message = NSLocalizedString(@"auth_error", nil);
+                            break;
+                        case RESULT_VER_LOW:
+                            message = NSLocalizedString(@"ver_low", nil);
+                            break;
+                        case RESULT_FAILED_WITH_MESSAGE:
+                            message = result[@"err_msg"];
+                            break;
+                        default:
+                            message=[NSString stringWithFormat:@"Failed to login code %d",ret];
+                            break;
+                    }
+
+                    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_error", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
+                    UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+
+                }];
+                                    
+                                    [alertVC addAction:action];
+                                    
+                                    [self presentViewController:alertVC animated:YES completion:nil];
+                }
+
+            }];
+
+            }
+                
+                        else
+            if([item[@"name"] isEqualToString:@"save_party"])
+            {
+
+            }
+
+        }];
+            
+    
+        
+            [alertVC addAction:injectAction];
+
+        }
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
+
+    }];
+    
+    [alertVC addAction:cancelAction];
+    
+    [self presentViewController:alertVC animated:YES completion:nil];
+        
+        
+//        
+//        if(type.toLowerCase().equals("quickview"))
+//        {
+//            String url = jitem.optString("url");
+//            showQuickLook(url);
+//        }
+//        else if(type.toLowerCase().equals("editor"))
+//        {
+////			throw new AssertionError("Editor not impl");
+//
+//
+//            Bundle b=RAUtil.Json2Bundle(jitem.optJSONObject("params"));
+//            Intent intent = TFEditorActivity.build(mContext,TFEditorActivity.class,null,URL_REMOTE,URL_EDIT,b);
+//
+//            startActivity(intent);
+//
+//
+//        }
+//        return super.onOptionsItemSelected(item);
+    }
 
     @Override
     protected void commonAction(String value, int groupIndex, int itemIndex, JSONObject item_json)
     {
         if(value.equals("editor"))
         {
-//        NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
+//        JSONObject item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
             boolean readonly = content_data_download.optBoolean("readonly"); 
             
             int disable = item_json.optInt("disable");
@@ -122,7 +489,7 @@ public class TFEditorActivity extends CommonEditorActivity
 //            //    enumvc.single_select =[[single_select lowercaseString] isEqualToString:@"true"];
 //
 //            enumvc.from = indexPath;
-//            enumvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
+//            enumvc.returnValue = ^(JSONObject value,NSIndexPath* source){
 //
 //
 //                    [self handle_action_return:value[@"val_0"] indexPath:indexPath action:ACTION_FILL_SECTION];