create changelog entry
[debian/openrocket] / android / src / net / sf / openrocket / android / thrustcurve / TCMissingMotorDownloadAction.java
index c64bb02d4505b444c31bddfee7521b24464cf6f0..aafaf1bd5b326662682d10e35cb1fe5ee34ce624 100644 (file)
@@ -1,12 +1,18 @@
 package net.sf.openrocket.android.thrustcurve;\r
 \r
+import java.util.List;\r
 import java.util.Set;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
 \r
 import net.sf.openrocket.android.util.AndroidLogWrapper;\r
+import net.sf.openrocket.motor.ThrustCurveMotor;\r
 import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder;\r
 \r
 public class TCMissingMotorDownloadAction extends TCQueryAction {\r
 \r
+       private final static String DESIGNATION_REGEX_STRING = "(Micro Maxx|Micro Maxx II|1/4A|1/2A|[A-O][0-9]*)";\r
+       \r
        public static TCMissingMotorDownloadAction newInstance( Set<ThrustCurveMotorPlaceholder> missingMotors ) {\r
                TCMissingMotorDownloadAction frag = new TCMissingMotorDownloadAction();\r
                frag.task = frag.new Downloader(missingMotors);\r
@@ -16,20 +22,35 @@ public class TCMissingMotorDownloadAction extends TCQueryAction {
        private class Downloader extends TCQueryAction.TCQueryTask {\r
 \r
                private Set<ThrustCurveMotorPlaceholder> missingMotors;\r
+               private Pattern designation_pattern = null;\r
                \r
                private Downloader( Set<ThrustCurveMotorPlaceholder> missingMotors ) {\r
                        this.missingMotors = missingMotors;\r
+                       try {\r
+                               designation_pattern = Pattern.compile(DESIGNATION_REGEX_STRING);\r
+                       } catch ( Exception ex ) {\r
+                               AndroidLogWrapper.e(TCMissingMotorDownloadAction.class, "Exception in pattern compile {}", ex);\r
+                       }\r
                }\r
                \r
                private void downloadMissingMotor( ThrustCurveMotorPlaceholder motor ) {\r
                        try {\r
+                                       \r
                                SearchRequest request = new SearchRequest();\r
                                request.setManufacturer(motor.getManufacturer());\r
-                               request.setDesignation(motor.getDesignation());\r
+                               String designation = motor.getDesignation();\r
+                               if ( designation_pattern != null ) {\r
+                                       Matcher m = designation_pattern.matcher(designation);\r
+                                       if ( m.find() ) {\r
+                                               designation = m.group();\r
+                                       }\r
+                               }\r
+                               AndroidLogWrapper.d(TCMissingMotorDownloadAction.class, "using designation {}", designation);\r
+                               request.setCommon_name(designation);\r
 \r
                                handler.post( new UpdateMessage("Looking for " + motor.getManufacturer() + " " + motor.getDesignation()));\r
 \r
-                               SearchResponse res = new ThrustCurveAPI().doSearch(request);\r
+                               SearchResponse res = ThrustCurveAPI.doSearch(request);\r
 \r
                                int total = res.getResults().size();\r
                                int count = 1;\r
@@ -53,9 +74,10 @@ public class TCMissingMotorDownloadAction extends TCQueryAction {
 \r
                                        AndroidLogWrapper.d(TCQueryAction.class, mi.toString());\r
 \r
-                                       MotorBurnFile b = new ThrustCurveAPI().downloadData(mi.getMotor_id());\r
+                                       List<MotorBurnFile> listOfMotors = ThrustCurveAPI.downloadData(mi.getMotor_id());\r
 \r
-                                       writeMotor( mi, b);\r
+                                       ThrustCurveMotor bestMatch = ThrustCurveAPI.findBestMatch(motor, listOfMotors);\r
+                                       writeMotor( mi, bestMatch);\r
 \r
                                }\r
                        }\r
@@ -69,11 +91,11 @@ public class TCMissingMotorDownloadAction extends TCQueryAction {
 \r
                @Override\r
                protected String doInBackground(Void... arg0) {\r
+                       \r
                        for ( ThrustCurveMotorPlaceholder motor : missingMotors ) {\r
                                AndroidLogWrapper.d(TCMissingMotorDownloadAction.class, "Motor: {}", motor);\r
                                downloadMissingMotor(motor);\r
                        }\r
-                       dismiss();\r
                        return null;\r
                }\r
 \r