Fix several item update events not being handled (#7377)

This lead to inconsistent display state.
Also, users were able to access items that no longer exist.
This commit is contained in:
ByteHamster 2024-09-03 22:13:50 +02:00 committed by GitHub
parent 2ad713772d
commit 18b63dd75c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
import de.danoeh.antennapod.event.UnreadItemsUpdateEvent;
import de.danoeh.antennapod.model.feed.Feed;
import de.danoeh.antennapod.ui.appstartintent.OnlineFeedviewActivityStarter;
import org.greenrobot.eventbus.EventBus;
@ -171,6 +172,11 @@ public class ItemPagerFragment extends Fragment implements MaterialToolbar.OnMen
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(UnreadItemsUpdateEvent event) {
refreshToolbarState();
}
private void openPodcast() {
if (item == null) {
return;

View File

@ -12,6 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.event.UnreadItemsUpdateEvent;
import de.danoeh.antennapod.ui.episodeslist.EpisodeItemListAdapter;
import de.danoeh.antennapod.event.DownloadLogEvent;
import de.danoeh.antennapod.ui.MenuItemUtils;
@ -111,6 +112,11 @@ public class DownloadsSection extends HomeSection {
loadItems();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onUnreadItemsUpdateEvent(UnreadItemsUpdateEvent event) {
loadItems();
}
@Override
protected String getSectionTitle() {
return getString(R.string.home_downloads_title);

View File

@ -12,6 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.event.FeedListUpdateEvent;
import de.danoeh.antennapod.ui.episodeslist.HorizontalItemListAdapter;
import de.danoeh.antennapod.ui.MenuItemUtils;
import de.danoeh.antennapod.storage.database.DBReader;
@ -123,6 +124,11 @@ public class EpisodesSurpriseSection extends HomeSection {
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(FeedListUpdateEvent event) {
loadItems();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(PlaybackPositionEvent event) {
if (listAdapter == null) {

View File

@ -362,7 +362,10 @@ public class AudioPlayerFragment extends Fragment implements
int currentPosition = converter.convert(event.getPosition());
int duration = converter.convert(event.getDuration());
int remainingTime = converter.convert(Math.max(event.getDuration() - event.getPosition(), 0));
currentChapterIndex = Chapter.getAfterPosition(controller.getMedia().getChapters(), currentPosition);
@Nullable Playable media = controller.getMedia();
if (media != null) {
currentChapterIndex = Chapter.getAfterPosition(media.getChapters(), currentPosition);
}
Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition));
if (currentPosition == Playable.INVALID_TIME || duration == Playable.INVALID_TIME) {
Log.w(TAG, "Could not react to position observer update because of invalid time");