FeedItem Visit Website tweak: use feed website as a fallback,

analogous to how share FeedItem link work.
Applicable to both feed playback screen and feed information screen.
This commit is contained in:
orionlee 2018-04-30 15:44:19 -07:00
parent 36507eb506
commit 345fcc17d0
4 changed files with 35 additions and 20 deletions

View File

@ -42,6 +42,7 @@ import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.Flavors;
import de.danoeh.antennapod.core.util.ShareUtils;
import de.danoeh.antennapod.core.util.StorageUtils;
@ -320,7 +321,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
((FeedMedia) media).getItem().getFlattrStatus().flattrable()
);
boolean hasWebsiteLink = media != null && media.getWebsiteLink() != null;
boolean hasWebsiteLink = ( getWebsiteLinkWithFallback(media) != null );
menu.findItem(R.id.visit_website_item).setVisible(hasWebsiteLink);
boolean isItemAndHasLink = isFeedMedia &&
@ -560,7 +561,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
});
break;
case R.id.visit_website_item:
Uri uri = Uri.parse(media.getWebsiteLink());
Uri uri = Uri.parse(getWebsiteLinkWithFallback(media));
startActivity(new Intent(Intent.ACTION_VIEW, uri));
break;
case R.id.support_item:
@ -603,6 +604,19 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
}
}
private static String getWebsiteLinkWithFallback(Playable media) {
String link = null;
if (media != null) {
link = media.getWebsiteLink();
if (link == null) {
if (media instanceof FeedMedia) {
link = FeedItemUtil.getLinkWithFallback(((FeedMedia)media).getItem());
} // else case not a FeedMedia, return null
}
} // else no media, return null
return link;
}
@Override
protected void onResume() {
super.onResume();

View File

@ -17,6 +17,7 @@ import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.LongList;
import de.danoeh.antennapod.core.util.ShareUtils;
@ -216,7 +217,7 @@ public class FeedItemMenuHandler {
DBWriter.setFeedItemAutoDownload(selectedItem, false);
break;
case R.id.visit_website_item:
Uri uri = Uri.parse(selectedItem.getLink());
Uri uri = Uri.parse(FeedItemUtil.getLinkWithFallback(selectedItem));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if(IntentUtils.isCallable(context, intent)) {
context.startActivity(intent);

View File

@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.util;
import java.util.List;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedItem;
public class FeedItemUtil {
@ -75,4 +76,18 @@ public class FeedItemUtil {
return false;
}
/**
* Get the link for the feed item for the purpose of Share. It fallbacks to
* use the feed's link if the named feed item has no link.
*/
public static String getLinkWithFallback(FeedItem item) {
String link = item.getLink();
if (link == null) {
Feed feed = item.getFeed();
if (feed != null) {
link = feed.getLink();
}
}
return link;
}
}

View File

@ -50,27 +50,12 @@ public class ShareUtils {
return item.getFeed().getTitle() + ": " + item.getTitle();
}
/**
* Get the link for the feed item for the purpose of Share. It fallbacks to
* use the feed's link if the named feed item has no link.
*/
private static String getItemShareLink(FeedItem item) {
String link = item.getLink();
if (link == null) {
Feed feed = item.getFeed();
if (feed != null) {
link = feed.getLink();
}
}
return link;
}
public static boolean hasLinkToShare(FeedItem item) {
return ( item != null && getItemShareLink(item) != null );
return ( item != null && FeedItemUtil.getLinkWithFallback(item) != null );
}
public static void shareFeedItemLink(Context context, FeedItem item, boolean withPosition) {
String text = getItemShareText(item) + " " + getItemShareLink(item);
String text = getItemShareText(item) + " " + FeedItemUtil.getLinkWithFallback(item);
if(withPosition) {
int pos = item.getMedia().getPosition();
text += " [" + Converter.getDurationStringLong(pos) + "]";