We cannot use the designation directly in the search. For some manufacturers (CTI...
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 16 Feb 2012 19:25:28 +0000 (19:25 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 16 Feb 2012 19:25:28 +0000 (19:25 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@425 180e2498-e6e9-4542-8430-84ac67f01cd8

android/src/net/sf/openrocket/android/thrustcurve/TCMissingMotorDownloadAction.java

index c64bb02d4505b444c31bddfee7521b24464cf6f0..ce580e9589fe7256d1f925637495a49cb42fe89b 100644 (file)
@@ -1,12 +1,16 @@
 package net.sf.openrocket.android.thrustcurve;\r
 \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.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,16 +20,31 @@ 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
@@ -69,11 +88,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