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
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
\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