Просмотр исходного кода

Edit function adds save, submit and delete functions -- 编辑功能增加保存,提交,删除功能(issue40: #14556)

Ray Zhang 4 лет назад
Родитель
Сommit
61c338fb79

+ 57 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/Network.java

@@ -991,6 +991,63 @@ public class Network {
             return null;
             return null;
         }
         }
     }
     }
+    public static JSONObject delete_editor(String request_url,Bundle params) {
+
+        if (request_url == null || request_url.isEmpty() || params == null) {
+            return null;
+        }
+
+        String json_string = getJson(request_url,params,REQUEST_TIMEOUT);
+
+        if (json_string == null || json_string.isEmpty()) {
+            json_string = "{\"result\" : \"1\"}";
+        }
+
+        try {
+            return new JSONObject(json_string);
+        } catch (JSONException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+    public static JSONObject submit_editor(String request_url,Bundle params) {
+
+        if (request_url == null || request_url.isEmpty() || params == null) {
+            return null;
+        }
+
+        String json_string = getJson(request_url,params,REQUEST_TIMEOUT);
+
+        if (json_string == null || json_string.isEmpty()) {
+            json_string = "{\"result\" : \"1\"}";
+        }
+
+        try {
+            return new JSONObject(json_string);
+        } catch (JSONException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+    public static JSONObject save_editor(String request_url,Bundle params) {
+
+        if (request_url == null || request_url.isEmpty() || params == null) {
+            return null;
+        }
+
+        String json_string = getJson(request_url,params,REQUEST_TIMEOUT);
+
+        if (json_string == null || json_string.isEmpty()) {
+            json_string = "{\"result\" : \"1\"}";
+        }
+
+        try {
+            return new JSONObject(json_string);
+        } catch (JSONException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
     public static JSONObject request_editor(String request_url,Bundle params) {
     public static JSONObject request_editor(String request_url,Bundle params) {
 
 
         if (request_url == null || request_url.isEmpty() || params == null) {
         if (request_url == null || request_url.isEmpty() || params == null) {

+ 7 - 1
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/RAUtil.java

@@ -72,7 +72,13 @@ public class RAUtil {
         Iterator<String> keys = obj2.keys();
         Iterator<String> keys = obj2.keys();
         while( keys.hasNext() ) {
         while( keys.hasNext() ) {
             String key =  keys.next();
             String key =  keys.next();
-            obj1.put(key, obj2.optString(key);
+            try
+            {
+                obj1.put(key, obj2.optString(key));
+            } catch (JSONException e)
+            {
+                e.printStackTrace();
+            }
         }
         }
 
 
     }
     }

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

@@ -17,6 +17,113 @@ import static java.lang.Thread.sleep;
 public class OfflineDataProvider {
 public class OfflineDataProvider {
 
 
 
 
+    public static JSONObject delete_editor(String url,Bundle param)
+    {
+        JSONObject commObj = null;
+
+//        String subtype = param.getString("sub_type");
+////        if (action_type.equals("Detail"))
+//        if (subtype.equals("isf"))
+//        {
+//            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)
+        {
+            String str = "{\"result\":2}";
+            try
+            {
+                commObj = new JSONObject(str);
+            } catch (JSONException e)
+            {
+                e.printStackTrace();
+            }
+        }
+        try
+        {
+            sleep(2000);
+        } catch (InterruptedException e)
+        {
+            e.printStackTrace();
+        }
+        return commObj;
+    }
+    public static JSONObject submit_editor(String url,Bundle param)
+    {
+        JSONObject commObj = null;
+
+//        String subtype = param.getString("sub_type");
+////        if (action_type.equals("Detail"))
+//        if (subtype.equals("isf"))
+//        {
+//            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)
+        {
+            String str = "{\"result\":2}";
+            try
+            {
+                commObj = new JSONObject(str);
+            } catch (JSONException e)
+            {
+                e.printStackTrace();
+            }
+        }
+        try
+        {
+            sleep(2000);
+        } catch (InterruptedException e)
+        {
+            e.printStackTrace();
+        }
+        return commObj;
+    }
+
+    public static JSONObject save_editor(String url,Bundle param)
+    {
+        JSONObject commObj = null;
+
+//        String subtype = param.getString("sub_type");
+////        if (action_type.equals("Detail"))
+//        if (subtype.equals("isf"))
+//        {
+//            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)
+        {
+            String str = "{\"result\":2}";
+            try
+            {
+                commObj = new JSONObject(str);
+            } catch (JSONException e)
+            {
+                e.printStackTrace();
+            }
+        }
+        try
+        {
+            sleep(2000);
+        } catch (InterruptedException e)
+        {
+            e.printStackTrace();
+        }
+        return commObj;
+    }
+
     public static JSONObject request_editor(String url,Bundle param)
     public static JSONObject request_editor(String url,Bundle param)
     {
     {
         JSONObject commObj = null;
         JSONObject commObj = null;

+ 20 - 0
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/dataprovider/RADataProvider.java

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

+ 85 - 245
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/tfeditor/TFEditorActivity.java

@@ -1,5 +1,6 @@
 package com.usai.ratradefiling.tfeditor;
 package com.usai.ratradefiling.tfeditor;
 
 
+import android.app.AlertDialog;
 import android.app.ProgressDialog;
 import android.app.ProgressDialog;
 import android.content.Context;
 import android.content.Context;
 //import android.support.v7.app.AppCompatActivity;
 //import android.support.v7.app.AppCompatActivity;
@@ -26,6 +27,7 @@ import java.lang.reflect.ParameterizedType;
 
 
 import static com.usai.ratradefiling.dataprovider.OnlineDataProvider.URL_CADEDATE;
 import static com.usai.ratradefiling.dataprovider.OnlineDataProvider.URL_CADEDATE;
 import static com.usai.ratradefiling.dataprovider.OnlineDataProvider.URL_EDIT;
 import static com.usai.ratradefiling.dataprovider.OnlineDataProvider.URL_EDIT;
+import static com.usai.ratradefiling.dataprovider.OnlineDataProvider.URL_SAVE_EDITOR;
 import static com.usai.redant.rautils.utils.RAUtil.getJsonFromAsset;
 import static com.usai.redant.rautils.utils.RAUtil.getJsonFromAsset;
 
 
 public class TFEditorActivity extends CommonEditorActivity
 public class TFEditorActivity extends CommonEditorActivity
@@ -83,18 +85,25 @@ public class TFEditorActivity extends CommonEditorActivity
 
 
         for(int i=0;i<injectMenu.length();i++)
         for(int i=0;i<injectMenu.length();i++)
         {
         {
-            
-            JSONObject subitem = injectMenu.get(i);
 
 
+            JSONObject subitem = null;
+            try
+            {
+                subitem = injectMenu.getJSONObject(i);
+            } catch (JSONException e)
+            {
+                e.printStackTrace();
+            }
 
 
 
 
 //            UIAlertAction *injectAction = [UIAlertAction actionWithTitle:NSLocalizedString(item[@"title"], nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
 //            UIAlertAction *injectAction = [UIAlertAction actionWithTitle:NSLocalizedString(item[@"title"], nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
 
 
             if(subitem.optString("name","").equals("save"))
             if(subitem.optString("name","").equals("save"))
             {
             {
-                JSONObject params= subitem.optJSONObject("params");
+                 JSONObject params= subitem.optJSONObject("params");
 
 
                 RAUtil.mergeJson(upparams,params);
                 RAUtil.mergeJson(upparams,params);
+                final Bundle b=RAUtil.Json2Bundle(params);
 
 
                 final ProgressDialog pd = RAUtil.waiting_alert(mCtx,"Saving","please wait");
                 final ProgressDialog pd = RAUtil.waiting_alert(mCtx,"Saving","please wait");
 
 
@@ -105,11 +114,11 @@ public class TFEditorActivity extends CommonEditorActivity
                     {
                     {
 
 
 
 
-                        JSONObject result_json = null;
+                        JSONObject result_json = RADataProvider.save_editor(URL_SAVE_EDITOR, b);;
 
 
 
 
 
 
-                        JSONObject finalResult_json = result_json;
+                        final JSONObject finalResult_json = result_json;
                         runOnUiThread(new Runnable()
                         runOnUiThread(new Runnable()
                         {
                         {
                             @Override
                             @Override
@@ -119,57 +128,19 @@ public class TFEditorActivity extends CommonEditorActivity
                                 pd.dismiss();
                                 pd.dismiss();
 
 
 
 
-//                        pd.dismiss();
-                                try
-                                {
 
 
                                     int result = finalResult_json.optInt("result");
                                     int result = finalResult_json.optInt("result");
                                     if (result == 2)
                                     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();
+                                        RAUtil.alertMessage(mCtx, "Message", "Save successful");
 
 
                                     }
                                     }
                                     else
                                     else
                                     {
                                     {
-                                        RAUtil.alertMessage(mCtx, "", finalResult_json.optString("err_msg"));
+                                        RAUtil.alertMessage(mCtx, "Warning", finalResult_json.optString("err_msg"));
                                     }
                                     }
-                                } catch (JSONException e)
-                                {
-                                    e.printStackTrace();
-                                }
+
                             }
                             }
                         });
                         });
                     }
                     }
@@ -177,247 +148,116 @@ public class TFEditorActivity extends CommonEditorActivity
 
 
 
 
 
 
-                [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
+                else if(subitem.optString("name","").equals("save&submit"))
                 {
                 {
-                            
-                            [[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];
+                    JSONObject params= subitem.optJSONObject("params");
 
 
-                }
+                    RAUtil.mergeJson(upparams,params);
+                    final Bundle b=RAUtil.Json2Bundle(params);
+                    final ProgressDialog pd = RAUtil.waiting_alert(mCtx,"Saving","please wait");
 
 
-            }];
+                    new Thread(new Runnable()
+                    {
+                        @Override
+                        public void run()
+                        {
 
 
-            }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];
+                            JSONObject result_json = RADataProvider.submit_editor(URL_SAVE_EDITOR, b);;
 
 
-                }  completion:^{
 
 
 
 
+                            final JSONObject finalResult_json = result_json;
+                            runOnUiThread(new Runnable()
+                            {
+                                @Override
+                                public void run()
+                                {
 
 
-                }];
-                    //            NSUser
+                                    pd.dismiss();
 
 
-                    //                            [self.navigationController popViewControllerAnimated:true];
 
 
 
 
+                                    int result = finalResult_json.optInt("result");
+                                    if (result == 2)
+                                    {
 
 
-                }
-                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;
-                    }
+                                        RAUtil.alertMessage(mCtx, "Message", "Submit successful");
 
 
-                    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) {
+                                    }
+                                    else
+                                    {
+                                        RAUtil.alertMessage(mCtx, "Warning", finalResult_json.optString("err_msg"));
+                                    }
 
 
-                }];
-                                
-                                [alertVC addAction:action];
-                                
-                                [self presentViewController:alertVC animated:YES completion:nil];
+                                }
+                            });
+                        }
+                    }).start();
                 }
                 }
 
 
-            }];
 
 
-            }
-                    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)
+
+            else if(subitem.optString("name","").equals("delete"))
+
                 {
                 {
-                                    
-                                    
-                                    [RAUtils message_alert:@"Successful" title:@"Delete" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
-                                        [self.navigationController popViewControllerAnimated:YES];
-                                        [self prepareReturn:nil];
-                }  completion:^{
 
 
 
 
+                    JSONObject params= subitem.optJSONObject("params");
 
 
-                }];
-                    //            NSUser
+                    RAUtil.mergeJson(upparams,params);
+                    final Bundle b=RAUtil.Json2Bundle(params);
+                    final ProgressDialog pd = RAUtil.waiting_alert(mCtx,"Deleting","please wait");
 
 
-                    //                            [self.navigationController popViewControllerAnimated:true];
+                    new Thread(new Runnable()
+                    {
+                        @Override
+                        public void run()
+                        {
 
 
 
 
+                            JSONObject result_json = RADataProvider.delete_editor(URL_SAVE_EDITOR, b);;
 
 
-                }
-                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];
-                }
+                            final JSONObject finalResult_json = result_json;
+                            runOnUiThread(new Runnable()
+                            {
+                                @Override
+                                public void run()
+                                {
 
 
-            }];
+                                    pd.dismiss();
 
 
-            }
-                
-                        else
-            if([item[@"name"] isEqualToString:@"save_party"])
-            {
 
 
-            }
 
 
-        }];
-            
-    
-        
-            [alertVC addAction:injectAction];
+                                    int result = finalResult_json.optInt("result");
+                                    if (result == 2)
+                                    {
 
 
-        }
-        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
+                                        RAUtil.alertMessage(mCtx, "Message", "Delete successful");
 
 
-    }];
-    
-    [alertVC addAction:cancelAction];
-    
-    [self presentViewController:alertVC animated:YES completion:nil];
-        
+                                    }
+                                    else
+                                    {
+                                        RAUtil.alertMessage(mCtx, "Warning", finalResult_json.optString("err_msg"));
+                                    }
+
+                                }
+                            });
+                        }
+                    }).start();
+                }
+        }
         
         
-//        
-//        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);
+        return true;
     }
     }
 
 
     @Override
     @Override