Use fixed IDs for home sections (#8611)

### Description

Use fixed IDs for home sections. Otherwise view restoration can get
confused by non-existing views. Also, sneak in new agent instructions :)

### Checklist
<!-- 
To help us keep the issue tracker clean and work as efficient as
possible,
  please make sure that you have done all of the following.
You can tick the boxes below by placing an x inside the brackets like
this: [x]
-->
- [x] I have read the contribution guidelines:
https://github.com/AntennaPod/AntennaPod/blob/develop/CONTRIBUTING.md#submit-a-pull-request
- [x] I have performed a self-review of my code, going through my
changes line by line and carefully considering why this line change is
necessary
- [x] I have run the automated code checks using `./gradlew checkstyle
lint`
- [x] My code follows the style guidelines of the AntennaPod project:
https://antennapod.org/contribute/develop/app/code-style
- [x] I have mentioned the corresponding issue and the relevant keyword
(e.g., "Closes: #xy") in the description (see
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
- [x] If it is a core feature, I have added automated tests
This commit is contained in:
Hans-Peter Lehmann
2026-07-20 21:59:12 +02:00
committed by GitHub
parent bfa37a3025
commit c4441c8348
3 changed files with 33 additions and 20 deletions

View File

@ -83,37 +83,42 @@ public class HomeFragment extends Fragment implements Toolbar.OnMenuItemClickLis
SharedPreferences prefs = getContext().getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE);
if (EchoConfig.isCurrentlyVisible() && prefs.getInt(PREF_HIDE_ECHO, 0) != EchoConfig.RELEASE_YEAR) {
addSection(new EchoSection());
addSection(new EchoSection(), R.id.home_section_echo);
}
List<String> sectionTags = HomePreferences.getSortedSectionTags(getContext());
for (String sectionTag : sectionTags) {
addSection(getSection(sectionTag));
addSection(getSection(sectionTag), getSectionContainerId(sectionTag));
}
}
private void addSection(Fragment section) {
private void addSection(Fragment section, int id) {
FragmentContainerView containerView = new FragmentContainerView(getContext());
containerView.setId(View.generateViewId());
containerView.setId(id);
viewBinding.homeContainer.addView(containerView);
getChildFragmentManager().beginTransaction().replace(containerView.getId(), section).commit();
}
private int getSectionContainerId(String sectionTag) {
return switch (sectionTag) {
case QueueSection.TAG -> R.id.home_section_queue;
case InboxSection.TAG -> R.id.home_section_inbox;
case EpisodesSurpriseSection.TAG -> R.id.home_section_surprise;
case SubscriptionsSection.TAG -> R.id.home_section_subscriptions;
case DownloadsSection.TAG -> R.id.home_section_downloads;
default -> throw new IllegalArgumentException("Unknown section tag: " + sectionTag);
};
}
private Fragment getSection(String tag) {
switch (tag) {
case QueueSection.TAG:
return new QueueSection();
case InboxSection.TAG:
return new InboxSection();
case EpisodesSurpriseSection.TAG:
return new EpisodesSurpriseSection();
case SubscriptionsSection.TAG:
return new SubscriptionsSection();
case DownloadsSection.TAG:
return new DownloadsSection();
default:
return null;
}
return switch (tag) {
case QueueSection.TAG -> new QueueSection();
case InboxSection.TAG -> new InboxSection();
case EpisodesSurpriseSection.TAG -> new EpisodesSurpriseSection();
case SubscriptionsSection.TAG -> new SubscriptionsSection();
case DownloadsSection.TAG -> new DownloadsSection();
default -> null;
};
}
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)

View File

@ -18,6 +18,14 @@
<item name="view_type_subscription_grid_without_title" type="id"/>
<item name="view_type_subscription_list" type="id"/>
<!-- Home sections -->
<item name="home_section_echo" type="id"/>
<item name="home_section_queue" type="id"/>
<item name="home_section_inbox" type="id"/>
<item name="home_section_surprise" type="id"/>
<item name="home_section_subscriptions" type="id"/>
<item name="home_section_downloads" type="id"/>
<!-- Bottom navigation -->
<item name="bottom_navigation_home" type="id"/>
<item name="bottom_navigation_queue" type="id"/>