Show subscribe nag only after interacting with episode (#7378)

This commit is contained in:
ByteHamster 2024-09-03 19:41:48 +02:00 committed by GitHub
parent 4fd3696d7f
commit 2ad713772d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 21 deletions

View File

@ -87,7 +87,6 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
MaterialToolbar.OnMenuItemClickListener, EpisodeItemListAdapter.OnSelectModeListener {
public static final String TAG = "ItemlistFragment";
private static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id";
private static final String ARGUMENT_IS_FIRST_TIME = "argument.de.danoeh.antennapod.first_time";
private static final String KEY_UP_ARROW = "up_arrow";
protected static final int EPISODES_PER_PAGE = 150;
protected int page = 1;
@ -99,7 +98,6 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
private MoreContentListFooterUtil nextPageLoader;
private boolean displayUpArrow;
private long feedID;
private boolean isFirstTime = false;
private Feed feed;
private Disposable disposable;
private FeedItemListFragmentBinding viewBinding;
@ -112,14 +110,9 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
* @return the newly created instance of an ItemlistFragment
*/
public static FeedItemlistFragment newInstance(long feedId) {
return newInstance(feedId, false);
}
public static FeedItemlistFragment newInstance(long feedId, boolean isFirstTime) {
FeedItemlistFragment i = new FeedItemlistFragment();
Bundle b = new Bundle();
b.putLong(ARGUMENT_FEED_ID, feedId);
b.putBoolean(ARGUMENT_IS_FIRST_TIME, isFirstTime);
i.setArguments(b);
return i;
}
@ -131,7 +124,6 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
Bundle args = getArguments();
Validate.notNull(args);
feedID = args.getLong(ARGUMENT_FEED_ID);
isFirstTime = args.getBoolean(ARGUMENT_IS_FIRST_TIME, false);
}
@Nullable
@ -486,7 +478,8 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
if (feed.getState() != Feed.STATE_SUBSCRIBED) {
viewBinding.header.descriptionContainer.setVisibility(View.VISIBLE);
viewBinding.header.headerDescriptionLabel.setText(HtmlToPlainText.getPlainText(feed.getDescription()));
viewBinding.header.subscribeNagLabel.setVisibility(isFirstTime ? View.GONE : View.VISIBLE);
viewBinding.header.subscribeNagLabel.setVisibility(
feed.hasInteractedWithEpisode() ? View.VISIBLE : View.GONE);
} else if (feed.getItemFilter() != null) {
FeedItemFilter filter = feed.getItemFilter();
if (filter.getValues().length > 0) {

View File

@ -234,7 +234,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
if (subscribedFeed.getState() == Feed.STATE_SUBSCRIBED) {
openFeed(subscribedFeed.getId());
} else {
showFeedFragment(subscribedFeed.getId(), false);
showFeedFragment(subscribedFeed.getId());
}
}, error -> Log.e(TAG, Log.getStackTraceString(error)), () -> startFeedDownload(url));
return null;
@ -292,7 +292,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
})
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(id -> showFeedFragment(id, true), error -> {
.subscribe(this::showFeedFragment, error -> {
error.printStackTrace();
showErrorDialog(error.getMessage(), "");
});
@ -333,13 +333,13 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
}
}
private void showFeedFragment(long id, boolean isFirstTime) {
private void showFeedFragment(long id) {
if (isFeedFoundBySearch) {
Toast.makeText(this, R.string.no_feed_url_podcast_found_by_search, Toast.LENGTH_LONG).show();
}
viewBinding.progressBar.setVisibility(View.GONE);
FeedItemlistFragment fragment = FeedItemlistFragment.newInstance(id, isFirstTime);
FeedItemlistFragment fragment = FeedItemlistFragment.newInstance(id);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragmentContainer, fragment, FeedItemlistFragment.TAG)

View File

@ -483,6 +483,38 @@ public class Feed {
this.state = state;
}
public boolean hasEpisodeInApp() {
if (items == null) {
return false;
}
for (FeedItem item : items) {
if (item.isTagged(FeedItem.TAG_FAVORITE)
|| item.isTagged(FeedItem.TAG_QUEUE)
|| item.isDownloaded()) {
return true;
}
}
return false;
}
public boolean hasInteractedWithEpisode() {
if (items == null) {
return false;
}
for (FeedItem item : items) {
if (item.isTagged(FeedItem.TAG_FAVORITE)
|| item.isTagged(FeedItem.TAG_QUEUE)
|| item.isDownloaded()
|| item.isPlayed()) {
return true;
}
if (item.getMedia() != null && item.getMedia().getPosition() > 0) {
return true;
}
}
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@ -3,7 +3,6 @@ package de.danoeh.antennapod.storage.database;
import android.content.Context;
import android.util.Log;
import de.danoeh.antennapod.model.feed.Feed;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedItemFilter;
import de.danoeh.antennapod.model.feed.SortOrder;
@ -33,14 +32,9 @@ public class NonSubscribedFeedsCleaner {
return false;
} else if (feed.getItems() == null) {
return false;
}
for (FeedItem item : feed.getItems()) {
if (item.isTagged(FeedItem.TAG_FAVORITE)
|| item.isTagged(FeedItem.TAG_QUEUE)
|| item.isDownloaded()) {
} else if (feed.hasEpisodeInApp()) {
return false;
}
}
return feed.getLastRefreshAttempt() < System.currentTimeMillis() - TIME_TO_KEEP;
}
}