forked from upstream-mirrors/OpenTracks
code cleanup: rename Importer classes
This commit is contained in:
+5
-5
@@ -54,12 +54,12 @@ import org.xml.sax.SAXException;
|
|||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class for various importers like {@link GpxImporter} and
|
* Abstract class for various file track importers like {@link GpxFileTrackImporter} and
|
||||||
* {@link KmlImporter}.
|
* {@link KmlFileTrackImporter}.
|
||||||
*
|
*
|
||||||
* @author Jimmy Shih
|
* @author Jimmy Shih
|
||||||
*/
|
*/
|
||||||
abstract class AbstractImporter extends DefaultHandler {
|
abstract class AbstractFileTrackImporter extends DefaultHandler implements TrackImporter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data for the current track.
|
* Data for the current track.
|
||||||
@@ -131,12 +131,12 @@ abstract class AbstractImporter extends DefaultHandler {
|
|||||||
* @param importTrackId the track id to import to. -1L to import to a new
|
* @param importTrackId the track id to import to. -1L to import to a new
|
||||||
* track.
|
* track.
|
||||||
*/
|
*/
|
||||||
protected AbstractImporter(Context context, long importTrackId) {
|
protected AbstractFileTrackImporter(Context context, long importTrackId) {
|
||||||
this(context, importTrackId, MyTracksProviderUtils.Factory.get(context));
|
this(context, importTrackId, MyTracksProviderUtils.Factory.get(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected AbstractImporter(
|
protected AbstractFileTrackImporter(
|
||||||
Context context, long importTrackId, MyTracksProviderUtils myTracksProviderUtils) {
|
Context context, long importTrackId, MyTracksProviderUtils myTracksProviderUtils) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.importTrackId = importTrackId;
|
this.importTrackId = importTrackId;
|
||||||
+3
-3
@@ -31,7 +31,7 @@ import org.xml.sax.SAXException;
|
|||||||
*
|
*
|
||||||
* @author Jimmy Shih
|
* @author Jimmy Shih
|
||||||
*/
|
*/
|
||||||
public class GpxImporter extends AbstractImporter {
|
public class GpxFileTrackImporter extends AbstractFileTrackImporter {
|
||||||
|
|
||||||
private static final String TAG_DESCRIPTION = "desc";
|
private static final String TAG_DESCRIPTION = "desc";
|
||||||
private static final String TAG_COMMENT = "cmt";
|
private static final String TAG_COMMENT = "cmt";
|
||||||
@@ -54,12 +54,12 @@ public class GpxImporter extends AbstractImporter {
|
|||||||
* @param context the context
|
* @param context the context
|
||||||
* @param importTrackId track id to import to. -1L to import to a new track.
|
* @param importTrackId track id to import to. -1L to import to a new track.
|
||||||
*/
|
*/
|
||||||
public GpxImporter(Context context, long importTrackId) {
|
public GpxFileTrackImporter(Context context, long importTrackId) {
|
||||||
super(context, importTrackId);
|
super(context, importTrackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public GpxImporter(Context context, MyTracksProviderUtils myTracksProviderUtils) {
|
public GpxFileTrackImporter(Context context, MyTracksProviderUtils myTracksProviderUtils) {
|
||||||
super(context, -1L, myTracksProviderUtils);
|
super(context, -1L, myTracksProviderUtils);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,10 +158,10 @@ public class ImportAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
*/
|
*/
|
||||||
private boolean importFile(final File file) {
|
private boolean importFile(final File file) {
|
||||||
try {
|
try {
|
||||||
AbstractImporter importer = trackFileFormat == TrackFileFormat.KML ? new KmlImporter(
|
TrackImporter trackImporter = trackFileFormat == TrackFileFormat.KML ? new KmlFileTrackImporter(
|
||||||
context, -1L)
|
context, -1L)
|
||||||
: new GpxImporter(context, -1L);
|
: new GpxFileTrackImporter(context, -1L);
|
||||||
long trackIds[] = importer.importFile(new FileInputStream(file));
|
long trackIds[] = trackImporter.importFile(new FileInputStream(file));
|
||||||
int length = trackIds.length;
|
int length = trackIds.length;
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
trackId = trackIds[length - 1];
|
trackId = trackIds[length - 1];
|
||||||
|
|||||||
+3
-3
@@ -36,7 +36,7 @@ import org.xml.sax.SAXException;
|
|||||||
*
|
*
|
||||||
* @author Jimmy Shih
|
* @author Jimmy Shih
|
||||||
*/
|
*/
|
||||||
public class KmlImporter extends AbstractImporter {
|
public class KmlFileTrackImporter extends AbstractFileTrackImporter {
|
||||||
|
|
||||||
private static final String CADENCE = "cadence";
|
private static final String CADENCE = "cadence";
|
||||||
private static final String HEART_RATE = "heart_rate";
|
private static final String HEART_RATE = "heart_rate";
|
||||||
@@ -74,12 +74,12 @@ public class KmlImporter extends AbstractImporter {
|
|||||||
* @param context the context
|
* @param context the context
|
||||||
* @param importTrackId track id to import to. -1L to import to a new track.
|
* @param importTrackId track id to import to. -1L to import to a new track.
|
||||||
*/
|
*/
|
||||||
public KmlImporter(Context context, long importTrackId) {
|
public KmlFileTrackImporter(Context context, long importTrackId) {
|
||||||
super(context, importTrackId);
|
super(context, importTrackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public KmlImporter(Context context, MyTracksProviderUtils myTracksProviderUtils) {
|
public KmlFileTrackImporter(Context context, MyTracksProviderUtils myTracksProviderUtils) {
|
||||||
super(context, -1L, myTracksProviderUtils);
|
super(context, -1L, myTracksProviderUtils);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 Google Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package com.google.android.apps.mytracks.io.file;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for a track importer.
|
||||||
|
*
|
||||||
|
* @author Jimmy Shih
|
||||||
|
*/
|
||||||
|
public interface TrackImporter {
|
||||||
|
|
||||||
|
public long[] importFile(InputStream inputStream)
|
||||||
|
throws SAXException, IOException, ParserConfigurationException;
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ package com.google.android.apps.mytracks.io.sync;
|
|||||||
|
|
||||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||||
import com.google.android.apps.mytracks.content.Track;
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.io.file.KmlImporter;
|
import com.google.android.apps.mytracks.io.file.KmlFileTrackImporter;
|
||||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
|
import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.gms.auth.GoogleAuthException;
|
import com.google.android.gms.auth.GoogleAuthException;
|
||||||
@@ -348,9 +348,9 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
if (driveFile != null) {
|
if (driveFile != null) {
|
||||||
InputStream inputStream = downloadDriveFile(driveFile, true);
|
InputStream inputStream = downloadDriveFile(driveFile, true);
|
||||||
if (inputStream != null) {
|
if (inputStream != null) {
|
||||||
KmlImporter kmlImporter = new KmlImporter(context, -1L);
|
KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(context, -1L);
|
||||||
try {
|
try {
|
||||||
long[] trackIds = kmlImporter.importFile(inputStream);
|
long[] trackIds = kmlFileTrackImporter.importFile(inputStream);
|
||||||
if (trackIds.length == 1) {
|
if (trackIds.length == 1) {
|
||||||
Track track = myTracksProviderUtils.getTrack(trackIds[0]);
|
Track track = myTracksProviderUtils.getTrack(trackIds[0]);
|
||||||
if (track == null) {
|
if (track == null) {
|
||||||
@@ -494,9 +494,9 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
Log.e(TAG, "Unable to update track. Input stream is null for track " + track.getName());
|
Log.e(TAG, "Unable to update track. Input stream is null for track " + track.getName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
KmlImporter kmlImporter = new KmlImporter(context, track.getId());
|
KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(context, track.getId());
|
||||||
try {
|
try {
|
||||||
long[] trackIds = kmlImporter.importFile(inputStream);
|
long[] trackIds = kmlFileTrackImporter.importFile(inputStream);
|
||||||
if (trackIds.length == 1) {
|
if (trackIds.length == 1) {
|
||||||
Track newTrack = myTracksProviderUtils.getTrack(trackIds[0]);
|
Track newTrack = myTracksProviderUtils.getTrack(trackIds[0]);
|
||||||
if (newTrack == null) {
|
if (newTrack == null) {
|
||||||
|
|||||||
+2
-2
@@ -42,11 +42,11 @@ import java.util.SimpleTimeZone;
|
|||||||
import org.easymock.Capture;
|
import org.easymock.Capture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class for testing importer.
|
* Abstract class for testing file track importers.
|
||||||
*
|
*
|
||||||
* @author Jimmy Shih.
|
* @author Jimmy Shih.
|
||||||
*/
|
*/
|
||||||
public class AbstractTestImporter extends AndroidTestCase {
|
public class AbstractTestFileTrackImporter extends AndroidTestCase {
|
||||||
|
|
||||||
protected static final String TRACK_NAME_0 = "blablub";
|
protected static final String TRACK_NAME_0 = "blablub";
|
||||||
protected static final String TRACK_DESCRIPTION_0 = "s'Laebe isch koi Schlotzer";
|
protected static final String TRACK_DESCRIPTION_0 = "s'Laebe isch koi Schlotzer";
|
||||||
+17
-12
@@ -31,11 +31,11 @@ import org.easymock.Capture;
|
|||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link GpxImporter}.
|
* Tests for {@link GpxFileTrackImporter}.
|
||||||
*
|
*
|
||||||
* @author Steffen Horlacher
|
* @author Steffen Horlacher
|
||||||
*/
|
*/
|
||||||
public class GpxImporterTest extends AbstractTestImporter {
|
public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
||||||
|
|
||||||
private static String getNameAndDescription(String name, String description) {
|
private static String getNameAndDescription(String name, String description) {
|
||||||
return "<name><![CDATA[" + name + "]]></name>" + "<desc><![CDATA[" + description + "]]></desc>";
|
return "<name><![CDATA[" + name + "]]></name>" + "<desc><![CDATA[" + description + "]]></desc>";
|
||||||
@@ -107,8 +107,9 @@ public class GpxImporterTest extends AbstractTestImporter {
|
|||||||
AndroidMock.replay(myTracksProviderUtils);
|
AndroidMock.replay(myTracksProviderUtils);
|
||||||
|
|
||||||
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes());
|
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes());
|
||||||
GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils);
|
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
|
||||||
long[] trackIds = gpxImporter.importFile(inputStream);
|
getContext(), myTracksProviderUtils);
|
||||||
|
long[] trackIds = gpxFileTrackImporter.importFile(inputStream);
|
||||||
assertEquals(1, trackIds.length);
|
assertEquals(1, trackIds.length);
|
||||||
assertEquals(TRACK_ID_0, trackIds[0]);
|
assertEquals(TRACK_ID_0, trackIds[0]);
|
||||||
|
|
||||||
@@ -140,8 +141,9 @@ public class GpxImporterTest extends AbstractTestImporter {
|
|||||||
AndroidMock.replay(myTracksProviderUtils);
|
AndroidMock.replay(myTracksProviderUtils);
|
||||||
|
|
||||||
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes());
|
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes());
|
||||||
GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils);
|
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
|
||||||
long[] trackIds = gpxImporter.importFile(inputStream);
|
getContext(), myTracksProviderUtils);
|
||||||
|
long[] trackIds = gpxFileTrackImporter.importFile(inputStream);
|
||||||
assertEquals(1, trackIds.length);
|
assertEquals(1, trackIds.length);
|
||||||
assertEquals(TRACK_ID_0, trackIds[0]);
|
assertEquals(TRACK_ID_0, trackIds[0]);
|
||||||
|
|
||||||
@@ -177,8 +179,9 @@ public class GpxImporterTest extends AbstractTestImporter {
|
|||||||
|
|
||||||
InputStream inputStream = new ByteArrayInputStream(
|
InputStream inputStream = new ByteArrayInputStream(
|
||||||
VALID_ONE_TRACK_TWO_SEGMENTS_NO_TIME_GPX.getBytes());
|
VALID_ONE_TRACK_TWO_SEGMENTS_NO_TIME_GPX.getBytes());
|
||||||
GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils);
|
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
|
||||||
long[] trackIds = gpxImporter.importFile(inputStream);
|
getContext(), myTracksProviderUtils);
|
||||||
|
long[] trackIds = gpxFileTrackImporter.importFile(inputStream);
|
||||||
|
|
||||||
assertEquals(1, trackIds.length);
|
assertEquals(1, trackIds.length);
|
||||||
assertEquals(TRACK_ID_0, trackIds[0]);
|
assertEquals(TRACK_ID_0, trackIds[0]);
|
||||||
@@ -212,8 +215,9 @@ public class GpxImporterTest extends AbstractTestImporter {
|
|||||||
AndroidMock.replay(myTracksProviderUtils);
|
AndroidMock.replay(myTracksProviderUtils);
|
||||||
|
|
||||||
InputStream inputStream = new ByteArrayInputStream(VALID_TWO_TRACKS_GPX.getBytes());
|
InputStream inputStream = new ByteArrayInputStream(VALID_TWO_TRACKS_GPX.getBytes());
|
||||||
GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils);
|
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
|
||||||
long[] trackIds = gpxImporter.importFile(inputStream);
|
getContext(), myTracksProviderUtils);
|
||||||
|
long[] trackIds = gpxFileTrackImporter.importFile(inputStream);
|
||||||
assertEquals(2, trackIds.length);
|
assertEquals(2, trackIds.length);
|
||||||
assertEquals(TRACK_ID_0, trackIds[0]);
|
assertEquals(TRACK_ID_0, trackIds[0]);
|
||||||
assertEquals(TRACK_ID_1, trackIds[1]);
|
assertEquals(TRACK_ID_1, trackIds[1]);
|
||||||
@@ -279,8 +283,9 @@ public class GpxImporterTest extends AbstractTestImporter {
|
|||||||
|
|
||||||
InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
|
InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
|
||||||
try {
|
try {
|
||||||
GpxImporter gpxImporter = new GpxImporter(getContext(), myTracksProviderUtils);
|
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(
|
||||||
gpxImporter.importFile(inputStream);
|
getContext(), myTracksProviderUtils);
|
||||||
|
gpxFileTrackImporter.importFile(inputStream);
|
||||||
} catch (SAXException e) {
|
} catch (SAXException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
+8
-6
@@ -30,11 +30,11 @@ import java.io.InputStream;
|
|||||||
import org.easymock.Capture;
|
import org.easymock.Capture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link KmlImporter}.
|
* Tests for {@link KmlFileTrackImporter}.
|
||||||
*
|
*
|
||||||
* @author Jimmy Shih
|
* @author Jimmy Shih
|
||||||
*/
|
*/
|
||||||
public class KmlImporterTest extends AbstractTestImporter {
|
public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
||||||
|
|
||||||
private static String getNameAndDescription(String name, String description) {
|
private static String getNameAndDescription(String name, String description) {
|
||||||
return "<name><![CDATA[" + name + "]]></name><description><![CDATA[" + description
|
return "<name><![CDATA[" + name + "]]></name><description><![CDATA[" + description
|
||||||
@@ -85,8 +85,9 @@ public class KmlImporterTest extends AbstractTestImporter {
|
|||||||
AndroidMock.replay(myTracksProviderUtils);
|
AndroidMock.replay(myTracksProviderUtils);
|
||||||
|
|
||||||
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes());
|
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes());
|
||||||
KmlImporter kmlImporter = new KmlImporter(getContext(), myTracksProviderUtils);
|
KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(
|
||||||
long[] trackIds = kmlImporter.importFile(inputStream);
|
getContext(), myTracksProviderUtils);
|
||||||
|
long[] trackIds = kmlFileTrackImporter.importFile(inputStream);
|
||||||
assertEquals(1, trackIds.length);
|
assertEquals(1, trackIds.length);
|
||||||
assertEquals(TRACK_ID_0, trackIds[0]);
|
assertEquals(TRACK_ID_0, trackIds[0]);
|
||||||
|
|
||||||
@@ -118,8 +119,9 @@ public class KmlImporterTest extends AbstractTestImporter {
|
|||||||
AndroidMock.replay(myTracksProviderUtils);
|
AndroidMock.replay(myTracksProviderUtils);
|
||||||
|
|
||||||
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes());
|
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes());
|
||||||
KmlImporter kmlImporter = new KmlImporter(getContext(), myTracksProviderUtils);
|
KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(
|
||||||
long[] trackIds = kmlImporter.importFile(inputStream);
|
getContext(), myTracksProviderUtils);
|
||||||
|
long[] trackIds = kmlFileTrackImporter.importFile(inputStream);
|
||||||
assertEquals(1, trackIds.length);
|
assertEquals(1, trackIds.length);
|
||||||
assertEquals(TRACK_ID_0, trackIds[0]);
|
assertEquals(TRACK_ID_0, trackIds[0]);
|
||||||
|
|
||||||
Reference in New Issue
Block a user