mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2026-02-05 04:45:26 +00:00
Move 'Untagged' chip to end and center selected tag in subscription view (#8141)
This commit is contained in:
@ -416,6 +416,25 @@ public class SubscriptionFragment extends Fragment
|
||||
}
|
||||
}
|
||||
tagsRecycler.setVisibility(shouldShowTags ? View.VISIBLE : View.GONE);
|
||||
// Scroll to center the selected tag
|
||||
tagsRecycler.post(() -> {
|
||||
int selectedPosition = tagAdapter.getSelectedTagPosition();
|
||||
if (selectedPosition < 0) {
|
||||
return;
|
||||
}
|
||||
LinearLayoutManager layoutManager =
|
||||
(LinearLayoutManager) tagsRecycler.getLayoutManager();
|
||||
// Calculate offset to center the selected chip
|
||||
View selectedView = layoutManager.findViewByPosition(selectedPosition);
|
||||
if (selectedView != null) {
|
||||
int recyclerWidth = tagsRecycler.getWidth();
|
||||
int chipWidth = selectedView.getWidth();
|
||||
int offset = (recyclerWidth - chipWidth) / 2;
|
||||
layoutManager.scrollToPositionWithOffset(selectedPosition, offset);
|
||||
} else {
|
||||
tagsRecycler.scrollToPosition(selectedPosition);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, error -> {
|
||||
Log.e(TAG, Log.getStackTraceString(error));
|
||||
|
||||
@ -45,6 +45,18 @@ public class SubscriptionTagAdapter extends RecyclerView.Adapter<SubscriptionTag
|
||||
return selectedTag;
|
||||
}
|
||||
|
||||
public int getSelectedTagPosition() {
|
||||
if (selectedTag == null) {
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < tags.size(); i++) {
|
||||
if (tags.get(i).getTitle().equals(selectedTag)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public TagViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
||||
@ -814,15 +814,15 @@ public final class DBReader {
|
||||
}
|
||||
List<NavDrawerData.TagItem> tagsSorted = new ArrayList<>(tags.values());
|
||||
Collections.sort(tagsSorted, (o1, o2) -> o1.getTitle().compareToIgnoreCase(o2.getTitle()));
|
||||
if (!untaggedTag.getFeeds().isEmpty()) {
|
||||
tagsSorted.add(0, untaggedTag);
|
||||
}
|
||||
// Root tag here means "all feeds", this is different from the nav drawer.
|
||||
NavDrawerData.TagItem rootTag = new NavDrawerData.TagItem(FeedPreferences.TAG_ROOT);
|
||||
for (Feed feed : feeds) {
|
||||
rootTag.addFeed(feed, 0);
|
||||
}
|
||||
tagsSorted.add(0, rootTag);
|
||||
if (!untaggedTag.getFeeds().isEmpty()) {
|
||||
tagsSorted.add(untaggedTag);
|
||||
}
|
||||
return tagsSorted;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user