diff --git a/android/src/net/sf/openrocket/android/thrustcurve/TCMissingMotorDownloadAction.java b/android/src/net/sf/openrocket/android/thrustcurve/TCMissingMotorDownloadAction.java index c64bb02d4..ce580e958 100644 --- a/android/src/net/sf/openrocket/android/thrustcurve/TCMissingMotorDownloadAction.java +++ b/android/src/net/sf/openrocket/android/thrustcurve/TCMissingMotorDownloadAction.java @@ -1,12 +1,16 @@ package net.sf.openrocket.android.thrustcurve; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import net.sf.openrocket.android.util.AndroidLogWrapper; import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder; public class TCMissingMotorDownloadAction extends TCQueryAction { + private final static String DESIGNATION_REGEX_STRING = "(Micro Maxx|Micro Maxx II|1/4A|1/2A|[A-O][0-9]*)"; + public static TCMissingMotorDownloadAction newInstance( Set missingMotors ) { TCMissingMotorDownloadAction frag = new TCMissingMotorDownloadAction(); frag.task = frag.new Downloader(missingMotors); @@ -16,16 +20,31 @@ public class TCMissingMotorDownloadAction extends TCQueryAction { private class Downloader extends TCQueryAction.TCQueryTask { private Set missingMotors; + private Pattern designation_pattern = null; private Downloader( Set missingMotors ) { this.missingMotors = missingMotors; + try { + designation_pattern = Pattern.compile(DESIGNATION_REGEX_STRING); + } catch ( Exception ex ) { + AndroidLogWrapper.e(TCMissingMotorDownloadAction.class, "Exception in pattern compile {}", ex); + } } private void downloadMissingMotor( ThrustCurveMotorPlaceholder motor ) { try { + SearchRequest request = new SearchRequest(); request.setManufacturer(motor.getManufacturer()); - request.setDesignation(motor.getDesignation()); + String designation = motor.getDesignation(); + if ( designation_pattern != null ) { + Matcher m = designation_pattern.matcher(designation); + if ( m.find() ) { + designation = m.group(); + } + } + AndroidLogWrapper.d(TCMissingMotorDownloadAction.class, "using designation {}", designation); + request.setCommon_name(designation); handler.post( new UpdateMessage("Looking for " + motor.getManufacturer() + " " + motor.getDesignation())); @@ -69,11 +88,11 @@ public class TCMissingMotorDownloadAction extends TCQueryAction { @Override protected String doInBackground(Void... arg0) { + for ( ThrustCurveMotorPlaceholder motor : missingMotors ) { AndroidLogWrapper.d(TCMissingMotorDownloadAction.class, "Motor: {}", motor); downloadMissingMotor(motor); } - dismiss(); return null; }