diff options
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/activity')
4 files changed, 117 insertions, 105 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java index 8401b41a7..287ae3568 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java @@ -138,7 +138,7 @@ public class DefaultOnlineFeedViewActivity extends OnlineFeedViewActivity { @Override public void onClick(View v) { try { - Feed f = new Feed(selectedDownloadUrl, new Date(), feed.getTitle()); + Feed f = new Feed(selectedDownloadUrl, new Date(0), feed.getTitle()); f.setPreferences(feed.getPreferences()); DefaultOnlineFeedViewActivity.this.feed = f; diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index b3e95f0c0..2efee838d 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -66,8 +66,8 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity public static final String SAVE_TITLE = "title"; - public static final int POS_NEW = 0, - POS_QUEUE = 1, + public static final int POS_QUEUE = 0, + POS_NEW = 1, POS_DOWNLOADS = 2, POS_HISTORY = 3, POS_ADD = 4; diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java index 9f028000e..3b03ed2db 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -13,9 +13,21 @@ import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.RelativeLayout; + +import org.apache.commons.lang3.StringUtils; +import org.xml.sax.SAXException; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.ParserConfigurationException; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.dialog.AuthenticationDialog; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; @@ -31,16 +43,7 @@ import de.danoeh.antennapod.core.util.FileNameGenerator; import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.core.util.URLChecker; import de.danoeh.antennapod.core.util.syndication.FeedDiscoverer; -import org.apache.commons.lang3.StringUtils; -import org.xml.sax.SAXException; - -import javax.xml.parsers.ParserConfigurationException; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; +import de.danoeh.antennapod.dialog.AuthenticationDialog; /** * Downloads a feed from a feed URL and parses it. Subclasses can display the @@ -181,7 +184,7 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity { if (BuildConfig.DEBUG) Log.d(TAG, "Starting feed download"); url = URLChecker.prepareURL(url); - feed = new Feed(url, new Date()); + feed = new Feed(url, new Date(0)); if (username != null && password != null) { feed.setPreferences(new FeedPreferences(0, false, username, password)); } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java index 162a8f2e5..c1bbb7e52 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java @@ -1,7 +1,9 @@ package de.danoeh.antennapod.activity; -import android.app.AlertDialog; -import android.content.DialogInterface; +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.content.pm.ResolveInfo; +import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.Menu; @@ -10,23 +12,31 @@ import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; -import android.widget.Toast; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.List; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.LangUtils; import de.danoeh.antennapod.core.util.StorageUtils; -import java.io.*; - /** * Lets the user start the OPML-import process from a path */ public class OpmlImportFromPathActivity extends OpmlImportBaseActivity { + private static final String TAG = "OpmlImportFromPathActivity"; - private TextView txtvPath; - private Button butStart; - private String importPath; + + private static final int CHOOSE_OPML_FILE = 1; + + private Intent intentPickAction; + private Intent intentGetContentAction; @Override protected void onCreate(Bundle savedInstanceState) { @@ -36,47 +46,74 @@ public class OpmlImportFromPathActivity extends OpmlImportBaseActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.opml_import); - txtvPath = (TextView) findViewById(R.id.txtvPath); - butStart = (Button) findViewById(R.id.butStartImport); + final TextView txtvHeaderExplanation1 = (TextView) findViewById(R.id.txtvHeadingExplanation1); + final TextView txtvExplanation1 = (TextView) findViewById(R.id.txtvExplanation1); + final TextView txtvHeaderExplanation2 = (TextView) findViewById(R.id.txtvHeadingExplanation2); + final TextView txtvExplanation2 = (TextView) findViewById(R.id.txtvExplanation2); + final TextView txtvHeaderExplanation3 = (TextView) findViewById(R.id.txtvHeadingExplanation3); - butStart.setOnClickListener(new OnClickListener() { + Button butChooseFilesystem = (Button) findViewById(R.id.butChooseFileFromFilesystem); + butChooseFilesystem.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - checkFolderForFiles(); + chooseFileFromFilesystem(); } }); + + Button butChooseExternal = (Button) findViewById(R.id.butChooseFileFromExternal); + butChooseExternal.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + chooseFileFromExternal(); + } + }); + + int nextOption = 1; + intentPickAction = new Intent(Intent.ACTION_PICK); + intentPickAction.setData(Uri.parse("file://")); + List<ResolveInfo> intentActivities = getPackageManager() + .queryIntentActivities(intentPickAction, CHOOSE_OPML_FILE); + if(intentActivities.size() == 0) { + intentPickAction.setData(null); + intentActivities = getPackageManager() + .queryIntentActivities(intentPickAction, CHOOSE_OPML_FILE); + if(intentActivities.size() == 0) { + txtvHeaderExplanation1.setVisibility(View.GONE); + txtvExplanation1.setVisibility(View.GONE); + findViewById(R.id.divider1).setVisibility(View.GONE); + butChooseFilesystem.setVisibility(View.GONE); + } + } + if(txtvExplanation1.getVisibility() == View.VISIBLE) { + txtvHeaderExplanation1.setText("Option " + nextOption); + nextOption++; + } + + intentGetContentAction = new Intent(Intent.ACTION_GET_CONTENT); + intentGetContentAction.addCategory(Intent.CATEGORY_OPENABLE); + intentGetContentAction.setType("*/*"); + intentActivities = getPackageManager() + .queryIntentActivities(intentGetContentAction, CHOOSE_OPML_FILE); + if(intentActivities.size() == 0) { + txtvHeaderExplanation2.setVisibility(View.GONE); + txtvExplanation2.setVisibility(View.GONE); + findViewById(R.id.divider2).setVisibility(View.GONE); + butChooseExternal.setVisibility(View.GONE); + } else { + txtvHeaderExplanation2.setText("Option " + nextOption); + nextOption++; + } + + txtvHeaderExplanation3.setText("Option " + nextOption); } @Override protected void onResume() { super.onResume(); StorageUtils.checkStorageAvailability(this); - setImportPath(); } - /** - * Sets the importPath variable and makes txtvPath display the import - * directory. - */ - private void setImportPath() { - File importDir = UserPreferences.getDataFolder(this, UserPreferences.IMPORT_DIR); - boolean success = true; - if (!importDir.exists()) { - if (BuildConfig.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) { @@ -95,32 +132,6 @@ public class OpmlImportFromPathActivity extends OpmlImportBaseActivity { } } - /** - * Looks at the contents of the import directory and decides what to do. If - * more than one file is in the directory, a dialog will be created to let - * the user choose which item to import - */ - private void checkFolderForFiles() { - File dir = new File(importPath); - if (dir.isDirectory()) { - File[] fileList = dir.listFiles(); - if (fileList.length == 1) { - if (BuildConfig.DEBUG) - Log.d(TAG, "Found one file, choosing that one."); - startImport(fileList[0]); - } else if (fileList.length > 1) { - Log.w(TAG, "Import directory contains more than one file."); - askForFile(dir); - } else { - Log.e(TAG, "Import directory is empty"); - Toast toast = Toast - .makeText(this, R.string.opml_import_error_dir_empty, - Toast.LENGTH_LONG); - toast.show(); - } - } - } - private void startImport(File file) { Reader mReader = null; try { @@ -134,38 +145,36 @@ public class OpmlImportFromPathActivity extends OpmlImportBaseActivity { } } - /** - * Asks the user to choose from a list of files in a directory and returns - * his choice. + /* + * Creates an implicit intent to launch a file manager which lets + * the user choose a specific OPML-file to import from. */ - private void askForFile(File dir) { - final File[] fileList = dir.listFiles(); - String[] fileNames = dir.list(); - - AlertDialog.Builder dialog = new AlertDialog.Builder(this); - dialog.setTitle(R.string.choose_file_to_import_label); - dialog.setNeutralButton(android.R.string.cancel, - new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - if (BuildConfig.DEBUG) - Log.d(TAG, "Dialog was cancelled"); - dialog.dismiss(); - } - }); - dialog.setItems(fileNames, new DialogInterface.OnClickListener() { + private void chooseFileFromFilesystem() { + try { + startActivityForResult(intentPickAction, CHOOSE_OPML_FILE); + } catch (ActivityNotFoundException e) { + Log.e(TAG, "No activity found. Should never happen..."); + } + } - @Override - public void onClick(DialogInterface dialog, int which) { - if (BuildConfig.DEBUG) - Log.d(TAG, "File at index " + which + " was chosen"); - dialog.dismiss(); - startImport(fileList[which]); - } - }); - dialog.create().show(); + private void chooseFileFromExternal() { + try { + startActivityForResult(intentGetContentAction, CHOOSE_OPML_FILE); + } catch (ActivityNotFoundException e) { + Log.e(TAG, "No activity found. Should never happen..."); + } } + /** + * Gets the path of the file chosen with chooseFileToImport() + */ + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == RESULT_OK && requestCode == CHOOSE_OPML_FILE) { + String filename = data.getData().getPath(); + startImport(new File(filename)); + } + } } |