import via intent working initially
This commit is contained in:
parent
eb11da53c7
commit
e54dbbcdce
|
@ -166,6 +166,63 @@
|
||||||
android:configChanges="keyboardHidden|orientation"
|
android:configChanges="keyboardHidden|orientation"
|
||||||
android:label="@string/opml_import_label" >
|
android:label="@string/opml_import_label" >
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".activity.OpmlImportFromIntentActivity"
|
||||||
|
android:configChanges="keyboardHidden|orientation"
|
||||||
|
android:label="@string/opml_import_label" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<category android:name="android.intent.category.BROWSABLE"/>
|
||||||
|
|
||||||
|
<data
|
||||||
|
android:host="*"
|
||||||
|
android:pathPattern=".*\\.xml"
|
||||||
|
android:scheme="https"/>
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<category android:name="android.intent.category.BROWSABLE"/>
|
||||||
|
|
||||||
|
<data
|
||||||
|
android:host="*"
|
||||||
|
android:pathPattern=".*\\.xml"
|
||||||
|
android:scheme="http"/>
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<category android:name="android.intent.category.BROWSABLE"/>
|
||||||
|
|
||||||
|
<data
|
||||||
|
android:pathPattern=".*\\.xml"
|
||||||
|
android:scheme="file"/>
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<category android:name="android.intent.category.BROWSABLE"/>
|
||||||
|
|
||||||
|
<data android:mimeType="application/xml"/>
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<category android:name="android.intent.category.BROWSABLE"/>
|
||||||
|
|
||||||
|
<data android:mimeType="text/xml"/>
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.OpmlFeedChooserActivity"
|
android:name=".activity.OpmlFeedChooserActivity"
|
||||||
android:label="@string/opml_import_label" >
|
android:label="@string/opml_import_label" >
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
package de.danoeh.antennapod.activity;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
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 android.widget.Toast;
|
||||||
|
import com.actionbarsherlock.app.SherlockActivity;
|
||||||
|
import com.actionbarsherlock.view.Menu;
|
||||||
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
import de.danoeh.antennapod.AppConfig;
|
||||||
|
import de.danoeh.antennapod.PodcastApp;
|
||||||
|
import de.danoeh.antennapod.R;
|
||||||
|
import de.danoeh.antennapod.asynctask.OpmlFeedQueuer;
|
||||||
|
import de.danoeh.antennapod.asynctask.OpmlImportWorker;
|
||||||
|
import de.danoeh.antennapod.opml.OpmlElement;
|
||||||
|
import de.danoeh.antennapod.util.StorageUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base activity for Opml Import - e.g. with code what to do afterwards
|
||||||
|
* */
|
||||||
|
public class OpmlImportBaseActivity extends SherlockActivity {
|
||||||
|
|
||||||
|
private static final String TAG = "OpmlImportBaseActivity";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the choices made by the user in the OpmlFeedChooserActivity and
|
||||||
|
* starts the OpmlFeedQueuer if necessary.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Received result");
|
||||||
|
if (resultCode == RESULT_CANCELED) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Activity was cancelled");
|
||||||
|
if (finishWhenCanceled())
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
|
int[] selected = data
|
||||||
|
.getIntArrayExtra(OpmlFeedChooserActivity.EXTRA_SELECTED_ITEMS);
|
||||||
|
if (selected != null && selected.length > 0) {
|
||||||
|
OpmlFeedQueuer queuer = new OpmlFeedQueuer(this, selected) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void result) {
|
||||||
|
super.onPostExecute(result);
|
||||||
|
Intent intent = new Intent(OpmlImportBaseActivity.this, MainActivity.class);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
|
| Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
queuer.executeAsync();
|
||||||
|
} else {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "No items were selected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean finishWhenCanceled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
package de.danoeh.antennapod.activity;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
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 android.widget.Toast;
|
||||||
|
import com.actionbarsherlock.view.Menu;
|
||||||
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
import de.danoeh.antennapod.AppConfig;
|
||||||
|
import de.danoeh.antennapod.PodcastApp;
|
||||||
|
import de.danoeh.antennapod.R;
|
||||||
|
import de.danoeh.antennapod.asynctask.OpmlImportWorker;
|
||||||
|
import de.danoeh.antennapod.opml.OpmlElement;
|
||||||
|
import de.danoeh.antennapod.util.StorageUtils;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/** Lets the user start the OPML-import process. */
|
||||||
|
public class OpmlImportFromIntentActivity extends OpmlImportBaseActivity {
|
||||||
|
private static final String TAG = "OpmlImportFromPathActivity";
|
||||||
|
|
||||||
|
public static final String IMPORT_DIR = "import/";
|
||||||
|
|
||||||
|
private OpmlImportWorker importWorker;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
setTheme(PodcastApp.getThemeResourceId());
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
URL mOpmlURL = new URL(getIntent().getData().toString());
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(mOpmlURL.openStream()));
|
||||||
|
startImport(in);
|
||||||
|
} catch (Exception e) {
|
||||||
|
new AlertDialog.Builder(this).setMessage("Cannot open XML - Reason: " + e.getMessage()).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Starts the import process. */
|
||||||
|
private void startImport(Reader reader) {
|
||||||
|
|
||||||
|
if (reader != null) {
|
||||||
|
importWorker = new OpmlImportWorker(this, reader) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(ArrayList<OpmlElement> result) {
|
||||||
|
super.onPostExecute(result);
|
||||||
|
if (result != null) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Parsing was successful");
|
||||||
|
OpmlImportHolder.setReadElements(result);
|
||||||
|
startActivityForResult(new Intent(
|
||||||
|
OpmlImportFromIntentActivity.this,
|
||||||
|
OpmlFeedChooserActivity.class), 0);
|
||||||
|
} else {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Parser error occured");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
importWorker.executeAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean finishWhenCanceled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -27,8 +27,8 @@ import de.danoeh.antennapod.opml.OpmlElement;
|
||||||
import de.danoeh.antennapod.util.StorageUtils;
|
import de.danoeh.antennapod.util.StorageUtils;
|
||||||
|
|
||||||
/** Lets the user start the OPML-import process. */
|
/** Lets the user start the OPML-import process. */
|
||||||
public class OpmlImportFromPathActivity extends SherlockActivity {
|
public class OpmlImportFromPathActivity extends OpmlImportBaseActivity {
|
||||||
private static final String TAG = "OpmlImportActivity";
|
private static final String TAG = "OpmlImportFromPathActivity";
|
||||||
|
|
||||||
public static final String IMPORT_DIR = "import/";
|
public static final String IMPORT_DIR = "import/";
|
||||||
|
|
||||||
|
@ -189,40 +189,5 @@ public class OpmlImportFromPathActivity extends SherlockActivity {
|
||||||
dialog.create().show();
|
dialog.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles the choices made by the user in the OpmlFeedChooserActivity and
|
|
||||||
* starts the OpmlFeedQueuer if necessary.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
if (AppConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Received result");
|
|
||||||
if (resultCode == RESULT_CANCELED) {
|
|
||||||
if (AppConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Activity was cancelled");
|
|
||||||
} else {
|
|
||||||
int[] selected = data
|
|
||||||
.getIntArrayExtra(OpmlFeedChooserActivity.EXTRA_SELECTED_ITEMS);
|
|
||||||
if (selected != null && selected.length > 0) {
|
|
||||||
OpmlFeedQueuer queuer = new OpmlFeedQueuer(this, selected) {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Void result) {
|
|
||||||
super.onPostExecute(result);
|
|
||||||
Intent intent = new Intent(OpmlImportFromPathActivity.this, MainActivity.class);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
|
|
||||||
| Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
queuer.executeAsync();
|
|
||||||
} else {
|
|
||||||
if (AppConfig.DEBUG)
|
|
||||||
Log.d(TAG, "No items were selected");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue