Merge pull request #1731 from mfietz/issue/775-open-feed-after-subscribing

Add ability to open feed after subscribing
This commit is contained in:
Tom Hennen 2016-03-18 16:14:59 -04:00
commit 12ff1d6254
3 changed files with 40 additions and 14 deletions

View File

@ -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

View File

@ -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) {

View File

@ -134,6 +134,7 @@
<string name="hide_not_downloaded_episodes_label">Not downloaded</string>
<string name="filtered_label">Filtered</string>
<string name="refresh_failed_msg">{fa-exclamation-circle} Last Refresh failed</string>
<string name="open_podcast">Open Podcast</string>
<!-- actions on feeditems -->
<string name="download_label">Download</string>