Move 'Untagged' chip to end and center selected tag in subscription view (#8141)

This commit is contained in:
Aman Jain
2025-12-12 03:15:45 +05:30
committed by GitHub
parent a2fc75dff7
commit 4f4fd516d9
3 changed files with 34 additions and 3 deletions

View File

@ -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));

View File

@ -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) {