From d33b959e1197d1f2968530fe5a8d74842cbe118b Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Mon, 23 Jul 2012 14:26:31 +0200 Subject: [PATCH] integrated import worker into import activity --- res/values/strings.xml | 1 + .../activity/OpmlImportActivity.java | 71 +++++++++++++++++-- .../asynctask/OpmlImportWorker.java | 1 + 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 9debe78fb..37d1a57a1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -133,5 +133,6 @@ ERROR! Reading OPML file An error has occured while reading the opml document: + It seems like the import directory is empty. Please copy a OPML file into the directory to import it. \ No newline at end of file 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 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(); } }