diff options
author | Stephan Merker <merker.stephan@googlemail.com> | 2011-10-29 00:30:59 +0200 |
---|---|---|
committer | Stephan Merker <merker.stephan@googlemail.com> | 2011-10-30 13:18:11 +0100 |
commit | 5687446f0dd3c3b2db5f7dc18f95ee02f94f2ccc (patch) | |
tree | 973823a9f446eef7bd3173ecc8e39cd291d42622 /main/src/cgeo | |
parent | 6c74f71960125b5fefc6fbeb4b3d510ae2f921e8 (diff) | |
download | cgeo-5687446f0dd3c3b2db5f7dc18f95ee02f94f2ccc.zip cgeo-5687446f0dd3c3b2db5f7dc18f95ee02f94f2ccc.tar.gz cgeo-5687446f0dd3c3b2db5f7dc18f95ee02f94f2ccc.tar.bz2 |
Added tests for importing GPX and LOC files
- refactored import classes in cgeogpxes so that they can be tested
Diffstat (limited to 'main/src/cgeo')
-rw-r--r-- | main/src/cgeo/geocaching/cgeogpxes.java | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/main/src/cgeo/geocaching/cgeogpxes.java b/main/src/cgeo/geocaching/cgeogpxes.java index 865b9e7..ed8c526 100644 --- a/main/src/cgeo/geocaching/cgeogpxes.java +++ b/main/src/cgeo/geocaching/cgeogpxes.java @@ -112,12 +112,16 @@ public class cgeogpxes extends FileList<cgGPXListAdapter> { public void importGPX(final File file) { createProgressDialog((int) file.length()); - new ImportFileThread(file).start(); + if (StringUtils.endsWithIgnoreCase(file.getName(), GPXParser.GPX_FILE_EXTENSION)) { + new ImportGpxFileThread(file, listId, loadCachesHandler, changeParseDialogHandler).start(); + } else { + new ImportLocFileThread(file, listId, loadCachesHandler, changeParseDialogHandler).start(); + } } public void importGPX(final InputStream stream) { createProgressDialog(-1); - new ImportStreamThread(stream).start(); + new ImportStreamThread(stream, listId, loadCachesHandler, changeParseDialogHandler).start(); } private void createProgressDialog(int maxBytes) { @@ -130,45 +134,65 @@ public class cgeogpxes extends FileList<cgGPXListAdapter> { parseDialog.show(); } - private abstract class ImportThread extends Thread { + static abstract class ImportThread extends Thread { + final int listId; + final Handler importStepHandler; + final Handler progressHandler; + + public ImportThread(int listId, Handler importStepHandler, Handler progressHandler) { + this.listId = listId; + this.importStepHandler = importStepHandler; + this.progressHandler = progressHandler; + } @Override public void run() { final cgSearch search = doImport(); - loadCachesHandler.sendMessage(loadCachesHandler.obtainMessage(0, cgeoapplication.getCount(search), 0)); + importStepHandler.sendMessage(importStepHandler.obtainMessage(0, cgeoapplication.getCount(search), 0, search)); } protected abstract cgSearch doImport(); } - private class ImportFileThread extends ImportThread { + static class ImportGpxFileThread extends ImportThread { private final File file; - public ImportFileThread(final File file) { + public ImportGpxFileThread(final File file, int listId, Handler importStepHandler, Handler progressHandler) { + super(listId, importStepHandler, progressHandler); this.file = file; } @Override protected cgSearch doImport() { - if (StringUtils.endsWithIgnoreCase(file.getName(), GPXParser.GPX_FILE_EXTENSION)) { - return GPXParser.importGPX(file, listId, changeParseDialogHandler); - } - else { - return LocParser.parseLoc(file, listId, changeParseDialogHandler); - } + return GPXParser.importGPX(file, listId, progressHandler); + } + } + + static class ImportLocFileThread extends ImportThread { + private final File file; + + public ImportLocFileThread(final File file, int listId, Handler importStepHandler, Handler progressHandler) { + super(listId, importStepHandler, progressHandler); + this.file = file; + } + + @Override + protected cgSearch doImport() { + return LocParser.parseLoc(file, listId, progressHandler); } } - private class ImportStreamThread extends ImportThread { + static class ImportStreamThread extends ImportThread { private final InputStream stream; - public ImportStreamThread(InputStream stream) { + public ImportStreamThread(InputStream stream, int listId, Handler importStepHandler, Handler progressHandler) { + super(listId, importStepHandler, progressHandler); this.stream = stream; } @Override protected cgSearch doImport() { - return GPXParser.importGPX(stream, listId, changeParseDialogHandler); + return GPXParser.importGPX(stream, listId, progressHandler); } } |