소스 검색

common editor adds the editing function for date type -- common editor 增加对日期类型的编辑功能 (issue50: #14532)

Ray Zhang 4 년 전
부모
커밋
18984365ed

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

@@ -2,6 +2,7 @@ package com.usai.commoneditorlib;
 
 import android.app.AlertDialog;
 //import android.app.ProgressDialog;/**/
+import android.app.DatePickerDialog;
 import android.app.ProgressDialog;
 import android.content.Context;
 import android.content.Intent;
@@ -13,6 +14,7 @@ import android.os.Bundle;
 import android.text.Editable;
 import android.text.InputFilter;
 import android.text.InputType;
+import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.util.Log;
 import android.view.LayoutInflater;
@@ -27,6 +29,7 @@ import android.widget.AutoCompleteTextView;
 import android.widget.BaseExpandableListAdapter;
 import android.widget.Button;
 import android.widget.CompoundButton;
+import android.widget.DatePicker;
 import android.widget.EditText;
 import android.widget.ExpandableListView;
 import android.widget.Switch;
@@ -63,6 +66,7 @@ import java.net.HttpURLConnection;
 import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
@@ -481,7 +485,10 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
 
         // date picker
         if (requestCode == 11) {
-
+//            int group = data.getIntExtra(AddressEditorActivity.GROUP,0);
+//            int child = data.getIntExtra(AddressEditorActivity.CHILD,0);
+//            String key = data.getStringExtra("value");
+//            handle_action_return(value,group,child,ACTION_FILL_SECTION);
         }
 
         // month picker
@@ -2271,7 +2278,43 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
                     int pickerMode = 0;
                     if (type.toLowerCase().equals("date")) {
                         pickerMode = 0; // Date
-                        dateFormatter.applyPattern("yyyy/MM/dd");
+                        dateFormatter.applyPattern("MM/dd/yyyy");
+
+                        Date date = dateFormatter.parse(value);
+                        final Calendar c = Calendar.getInstance();
+                        c.setTime(date);
+                        new DatePickerDialog(CommonEditorActivity.this,
+                                new DatePickerDialog.OnDateSetListener()
+                                {
+
+                                    @Override
+                                    public void onDateSet(DatePicker view,
+                                                          int year, int monthOfYear,
+                                                          int dayOfMonth)
+                                    {
+
+
+                                        String returnvalue = (monthOfYear+1)+"/"+dayOfMonth+"/"+year;
+
+                                        DateTimeValueChanged(returnvalue,groupPosition,childPosition);
+//                                        handle_action_return(new JSONObject(),groupPosition,childPosition,ACTION_SAVE_DATA);
+//                                        edit_to.setText((monthOfYear + 1) + "/"
+//                                                + dayOfMonth + "/" + year);
+//                                        hashMap.put(name + "_to",
+//                                                (monthOfYear + 1) + "/"
+//                                                        + dayOfMonth + "/"
+//                                                        + year);
+
+                                    }
+
+                                }, c.get(Calendar.YEAR), c.get(Calendar.MONTH),
+                                c.get(Calendar.DAY_OF_MONTH)).show();
+
+
+                        return true;
+
+
+
                     }
                     else if (type.toLowerCase().equals("time")) {
                         pickerMode = 1; // time
@@ -2282,8 +2325,11 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
                         dateFormatter.applyPattern("yyyy/MM/dd HH:mm:ss");
                     }
 
-                    Date date = dateFormatter.parse(value);
-                    intent = new DatePickerActivity.Builder().build(mCtx,date,dateFormatter,pickerMode,value,groupPosition,childPosition);
+//                    Date date = dateFormatter.parse(value);
+//                    intent = new DatePickerActivity.Builder().build(mCtx,date,dateFormatter,pickerMode,value,groupPosition,childPosition);
+
+
+
 
 
                 } // date picker
@@ -2317,6 +2363,93 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
         }
     }
 
+  void DateTimeValueChanged(String value ,int groupindex, int itemindex)
+    {
+
+
+        JSONObject section_json = null;
+        JSONObject item_json = content_data_control.optJSONArray(groupindex).optJSONObject(itemindex);
+
+//        boolean is_subaction = item_json.optBoolean("is_subaction");
+//        int subaction_tag = item_json.optInt("subaction_tag");
+//        value.remove("is_subaction");
+//        value.remove("subaction_tag");
+
+
+
+        int refresh = item_json.optInt("refresh");
+        boolean discardDirty = item_json.optBoolean("discard_dirty");
+        String refresh_trigger = item_json.optString("name");
+        String subid=item_json.optString("subid");
+
+
+        //    NSArray* imgs=[RAUtils string2arr:url_up separator:@","];
+
+
+        //    imgs[index];
+
+        try
+        {
+            item_json.put("value",value);
+            item_json.put("dirty",true);
+        } catch (JSONException e)
+        {
+            e.printStackTrace();
+        }
+
+        if(TextUtils.isEmpty(subid))
+        {
+            section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
+            int count=0;
+
+            count=[[section_json valueForKey:@"count"] intValue];
+
+            for(int i=0;i<count;i++)
+            {
+                NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
+                if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
+                [section_json setObject:item_json  forKey:[NSString stringWithFormat:@"item_%d",i ]];
+
+
+            }
+
+        }
+        else
+        {
+            NSArray* idarr=[subid componentsSeparatedByString:@"_"];
+            int section = [(String)idarr[0] intValue];
+            int item=[(String)idarr[1] intValue];
+
+
+            section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
+            NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
+            item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
+        [item_json setValue:@"true" forKey:@"dirty"];
+        [section_json setObject:item_json  forKey:[NSString stringWithFormat:@"item_%d",item ]];
+        }
+
+
+
+    [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
+
+        self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
+
+        //  NSRange range = NSMakeRange(indexPath.section, 1);
+        //   NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
+        //  [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
+
+
+        if(refresh==1)
+        {
+            if(!discardDirty)
+            [self refresh:refresh_trigger] ;
+        else
+            [self refresh:refresh_trigger discardDirty:true];
+        }
+    [self.editorTable reloadData ];
+    }
+
+
     public boolean cancommit = false;
 
 

+ 3 - 0
ApexDrivers/CommonEditorLib/src/main/java/com/usai/commoneditorlib/DatePickerActivity.java

@@ -23,6 +23,9 @@ public class DatePickerActivity extends AppCompatActivity
             }
             Intent intent = new Intent(context,DatePickerActivity.class);
 
+
+
+
             if (date != null) {
 
             }