From d4d8d18c5c63158de1ea0e1570f9258187ffa8fe Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Fri, 4 Mar 2016 12:07:26 +0100 Subject: [PATCH] Add ability to open feed after subscribing --- .../antennapod/activity/MainActivity.java | 14 +++++-- .../activity/OnlineFeedViewActivity.java | 39 ++++++++++++++----- core/src/main/res/values/strings.xml | 1 + 3 files changed, 40 insertions(+), 14 deletions(-) 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 bd7da7c03..34070d471 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -86,6 +86,7 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity public static final String EXTRA_NAV_INDEX = "nav_index"; public static final String EXTRA_FRAGMENT_TAG = "fragment_tag"; public static final String EXTRA_FRAGMENT_ARGS = "fragment_args"; + public static final String EXTRA_FEED_ID = "fragment_feed_id"; public static final String SAVE_BACKSTACK_COUNT = "backstackCount"; public static final String SAVE_TITLE = "title"; @@ -464,8 +465,9 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity StorageUtils.checkStorageAvailability(this); Intent intent = getIntent(); - if (navDrawerData != null && intent.hasExtra(EXTRA_NAV_TYPE) && - (intent.hasExtra(EXTRA_NAV_INDEX) || intent.hasExtra(EXTRA_FRAGMENT_TAG))) { + if (intent.hasExtra(EXTRA_FEED_ID) || + (navDrawerData != null && intent.hasExtra(EXTRA_NAV_TYPE) && + (intent.hasExtra(EXTRA_NAV_INDEX) || intent.hasExtra(EXTRA_FRAGMENT_TAG)))) { handleNavIntent(); } loadData(); @@ -709,15 +711,19 @@ public class MainActivity extends AppCompatActivity implements NavDrawerActivity private void handleNavIntent() { Log.d(TAG, "handleNavIntent()"); Intent intent = getIntent(); - if (intent.hasExtra(EXTRA_NAV_TYPE) && - intent.hasExtra(EXTRA_NAV_INDEX) || intent.hasExtra(EXTRA_FRAGMENT_TAG)) { + if (intent.hasExtra(EXTRA_FEED_ID) || + (intent.hasExtra(EXTRA_NAV_TYPE) && + (intent.hasExtra(EXTRA_NAV_INDEX) || intent.hasExtra(EXTRA_FRAGMENT_TAG)))) { int index = intent.getIntExtra(EXTRA_NAV_INDEX, -1); String tag = intent.getStringExtra(EXTRA_FRAGMENT_TAG); Bundle args = intent.getBundleExtra(EXTRA_FRAGMENT_ARGS); + long feedId = intent.getLongExtra(EXTRA_FEED_ID, 0); if (index >= 0) { loadFragment(index, args); } else if (tag != null) { loadFragment(tag, args); + } else if(feedId > 0) { + loadFeedFragmentById(feedId, args); } } setIntent(new Intent(MainActivity.this, MainActivity.class)); // to avoid handling the intent twice when the configuration changes 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 c7426c006..9d8048acf 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -408,18 +408,25 @@ public class OnlineFeedViewActivity extends ActionBarActivity { description.setText(feed.getDescription()); subscribeButton.setOnClickListener(v -> { - try { + if(feed != null && feedInFeedlist(feed)) { + Intent intent = new Intent(OnlineFeedViewActivity.this, MainActivity.class); + // feed.getId() is always 0, we have to retrieve the id from the feed list from + // the database + intent.putExtra(MainActivity.EXTRA_FEED_ID, getFeedId(feed)); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(intent); + } else { Feed f = new Feed(selectedDownloadUrl, null, feed.getTitle()); f.setPreferences(feed.getPreferences()); this.feed = f; - - DownloadRequester.getInstance().downloadFeed(this, f); - } catch (DownloadRequestException e) { - e.printStackTrace(); - DownloadRequestErrorDialogCreator.newRequestErrorDialog(OnlineFeedViewActivity.this, - e.getMessage()); + try { + DownloadRequester.getInstance().downloadFeed(this, f); + } catch (DownloadRequestException e) { + Log.e(TAG, Log.getStackTraceString(e)); + DownloadRequestErrorDialogCreator.newRequestErrorDialog(this, e.getMessage()); + } + setSubscribeButtonState(feed); } - setSubscribeButtonState(feed); }); if (alternateFeedUrls.isEmpty()) { @@ -462,8 +469,8 @@ public class OnlineFeedViewActivity extends ActionBarActivity { subscribeButton.setEnabled(false); subscribeButton.setText(R.string.downloading_label); } else if (feedInFeedlist(feed)) { - subscribeButton.setEnabled(false); - subscribeButton.setText(R.string.subscribed_label); + subscribeButton.setEnabled(true); + subscribeButton.setText(R.string.open_podcast); } else { subscribeButton.setEnabled(true); subscribeButton.setText(R.string.subscribe_label); @@ -483,6 +490,18 @@ public class OnlineFeedViewActivity extends ActionBarActivity { return false; } + private long getFeedId(Feed feed) { + if (feeds == null || feed == null) { + return 0; + } + for (Feed f : feeds) { + if (f.getIdentifyingValue().equals(feed.getIdentifyingValue())) { + return f.getId(); + } + } + return 0; + } + private void showErrorDialog(String errorMsg) { assert(Looper.myLooper() == Looper.getMainLooper()); // run on UI thread if (!isFinishing() && !isPaused) { diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 912a60f55..b64d7b073 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -134,6 +134,7 @@ Not downloaded Filtered {fa-exclamation-circle} Last Refresh failed + Open Podcast Download