make room for another way of Opml import

This commit is contained in:
ligi 2013-01-23 14:44:28 +01:00
parent c75640d274
commit 60546a7bd7
7 changed files with 59 additions and 33 deletions

View File

@ -162,7 +162,7 @@
android:label="@string/about_pref" >
</activity>
<activity
android:name=".activity.OpmlImportActivity"
android:name=".activity.OpmlImportFromPathActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/opml_import_label" >
</activity>

View File

@ -73,7 +73,7 @@ public class AddFeedActivity extends SherlockActivity {
@Override
public void onClick(View v) {
startActivity(new Intent(AddFeedActivity.this,
OpmlImportActivity.class));
OpmlImportFromPathActivity.class));
}
});

View File

@ -90,8 +90,8 @@ public class OpmlFeedChooserActivity extends SherlockActivity {
private List<String> getTitleList() {
List<String> result = new ArrayList<String>();
if (OpmlImportActivity.getReadElements() != null) {
for (OpmlElement element : OpmlImportActivity.getReadElements()) {
if (OpmlImportHolder.getReadElements() != null) {
for (OpmlElement element : OpmlImportHolder.getReadElements()) {
result.add(element.getText());
}

View File

@ -27,7 +27,7 @@ import de.danoeh.antennapod.opml.OpmlElement;
import de.danoeh.antennapod.util.StorageUtils;
/** Lets the user start the OPML-import process. */
public class OpmlImportActivity extends SherlockActivity {
public class OpmlImportFromPathActivity extends SherlockActivity {
private static final String TAG = "OpmlImportActivity";
public static final String IMPORT_DIR = "import/";
@ -38,8 +38,6 @@ public class OpmlImportActivity extends SherlockActivity {
private OpmlImportWorker importWorker;
private static ArrayList<OpmlElement> readElements;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(PodcastApp.getThemeResourceId());
@ -144,9 +142,9 @@ public class OpmlImportActivity extends SherlockActivity {
if (result != null) {
if (AppConfig.DEBUG)
Log.d(TAG, "Parsing was successful");
readElements = result;
OpmlImportHolder.setReadElements(result);
startActivityForResult(new Intent(
OpmlImportActivity.this,
OpmlImportFromPathActivity.this,
OpmlFeedChooserActivity.class), 0);
} else {
if (AppConfig.DEBUG)
@ -211,7 +209,7 @@ public class OpmlImportActivity extends SherlockActivity {
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
Intent intent = new Intent(OpmlImportActivity.this, MainActivity.class);
Intent intent = new Intent(OpmlImportFromPathActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
@ -226,8 +224,5 @@ public class OpmlImportActivity extends SherlockActivity {
}
}
public static ArrayList<OpmlElement> getReadElements() {
return readElements;
}
}

View File

@ -0,0 +1,29 @@
package de.danoeh.antennapod.activity;
import de.danoeh.antennapod.opml.OpmlElement;
import java.util.ArrayList;
/**
* Hold infos gathered by Ompl-Import
* <p/>
* Created with IntelliJ IDEA.
* User: ligi
* Date: 1/23/13
* Time: 2:15 PM
*/
public class OpmlImportHolder {
private static ArrayList<OpmlElement> readElements;
public static ArrayList<OpmlElement> getReadElements() {
return readElements;
}
public static void setReadElements(ArrayList<OpmlElement> _readElements) {
readElements = _readElements;
}
}

View File

@ -7,7 +7,8 @@ import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.OpmlImportActivity;
import de.danoeh.antennapod.activity.OpmlImportFromPathActivity;
import de.danoeh.antennapod.activity.OpmlImportHolder;
import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.opml.OpmlElement;
import de.danoeh.antennapod.storage.DownloadRequestException;
@ -43,7 +44,7 @@ public class OpmlFeedQueuer extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
DownloadRequester requester = DownloadRequester.getInstance();
for (int idx = 0; idx < selection.length; idx++) {
OpmlElement element = OpmlImportActivity.getReadElements().get(
OpmlElement element = OpmlImportHolder.getReadElements().get(
selection[idx]);
Feed feed = new Feed(element.getXmlUrl(), new Date(),
element.getText());

View File

@ -1,9 +1,6 @@
package de.danoeh.antennapod.asynctask;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.*;
import java.util.ArrayList;
import org.xmlpull.v1.XmlPullParserException;
@ -26,35 +23,39 @@ public class OpmlImportWorker extends
private static final String TAG = "OpmlImportWorker";
private Context context;
private File file; // path to opml file
private Exception exception;
private ProgressDialog progDialog;
private Reader mReader;
public OpmlImportWorker(Context context, File file) {
super();
this.context = context;
this.file = file;
// Create reader
try {
mReader = new FileReader(file);
if (AppConfig.DEBUG) Log.d(TAG, "Parsing " + file.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
exception = e;
}
}
@Override
protected ArrayList<OpmlElement> doInBackground(Void... params) {
if (AppConfig.DEBUG)
Log.d(TAG, "Starting background work");
FileReader reader = null;
// Create reader
try {
reader = new FileReader(file);
if (AppConfig.DEBUG) Log.d(TAG, "Parsing " + file.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
exception = e;
return null;
}
if (mReader==null) {
return null;
}
OpmlReader opmlReader = new OpmlReader();
try {
ArrayList<OpmlElement> result = opmlReader.readDocument(reader);
reader.close();
ArrayList<OpmlElement> result = opmlReader.readDocument(mReader);
mReader.close();
return result;
} catch (XmlPullParserException e) {
e.printStackTrace();