summaryrefslogtreecommitdiff
path: root/src/de/danoeh
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-07-23 14:26:31 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-07-23 14:26:31 +0200
commitd33b959e1197d1f2968530fe5a8d74842cbe118b (patch)
tree2dd03068241b61d8979d7db72f2240d1f1efaafc /src/de/danoeh
parent85e171ed994b8e31b3fae42754c25267fb0c2520 (diff)
downloadAntennaPod-d33b959e1197d1f2968530fe5a8d74842cbe118b.zip
integrated import worker into import activity
Diffstat (limited to 'src/de/danoeh')
-rw-r--r--src/de/danoeh/antennapod/activity/OpmlImportActivity.java71
-rw-r--r--src/de/danoeh/antennapod/asynctask/OpmlImportWorker.java1
2 files changed, 66 insertions, 6 deletions
diff --git a/src/de/danoeh/antennapod/activity/OpmlImportActivity.java b/src/de/danoeh/antennapod/activity/OpmlImportActivity.java
index a84450e81..3acf96f55 100644
--- a/src/de/danoeh/antennapod/activity/OpmlImportActivity.java
+++ b/src/de/danoeh/antennapod/activity/OpmlImportActivity.java
@@ -1,34 +1,52 @@
package de.danoeh.antennapod.activity;
import java.io.File;
+import java.util.ArrayList;
import android.os.Bundle;
import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockActivity;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuItem;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.asynctask.OpmlImportWorker;
+import de.danoeh.antennapod.opml.OpmlElement;
import de.danoeh.antennapod.util.StorageUtils;
public class OpmlImportActivity extends SherlockActivity {
private static final String TAG = "OpmlImportActivity";
-
+
private static final String IMPORT_DIR = "import/";
-
+
private TextView txtvPath;
private Button butStart;
+ private String importPath;
+
+ private OpmlImportWorker importWorker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.opml_import);
-
+
txtvPath = (TextView) findViewById(R.id.txtvPath);
butStart = (Button) findViewById(R.id.butStartImport);
+
+ butStart.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ startImport();
+ }
+
+ });
}
@Override
@@ -37,21 +55,62 @@ public class OpmlImportActivity extends SherlockActivity {
StorageUtils.checkStorageAvailability(this);
setImportPath();
}
-
+
private void setImportPath() {
File importDir = getExternalFilesDir(IMPORT_DIR);
boolean success = true;
if (!importDir.exists()) {
- if (AppConfig.DEBUG) Log.d(TAG, "Import directory doesn't exist. Creating...");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Import directory doesn't exist. Creating...");
success = importDir.mkdir();
if (!success) {
Log.e(TAG, "Could not create directory");
- }
+ }
}
if (success) {
txtvPath.setText(importDir.toString());
+ importPath = importDir.toString();
} else {
txtvPath.setText(R.string.opml_directory_error);
}
}
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ private void startImport() {
+ File dir = new File(importPath);
+ if (dir.isDirectory()) {
+ File[] fileList = dir.listFiles();
+ if (fileList.length > 1) {
+ Log.w(TAG,
+ "Import directory contains more than one file. Might choose the wrong one");
+ }
+ if (fileList.length > 0) {
+ importWorker = new OpmlImportWorker(this, fileList[0]) {
+
+ @Override
+ protected void onPostExecute(ArrayList<OpmlElement> result) {
+ super.onPostExecute(result);
+
+ }
+ };
+ } else {
+ Log.e(TAG, "Import directory is empty");
+ }
+ }
+ }
}
diff --git a/src/de/danoeh/antennapod/asynctask/OpmlImportWorker.java b/src/de/danoeh/antennapod/asynctask/OpmlImportWorker.java
index de2db951e..be026f1e0 100644
--- a/src/de/danoeh/antennapod/asynctask/OpmlImportWorker.java
+++ b/src/de/danoeh/antennapod/asynctask/OpmlImportWorker.java
@@ -88,6 +88,7 @@ public class OpmlImportWorker extends
}
});
+ alert.create().show();
}
}