From 78af43e95bc938ba7115d6590c4522cf73660933 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Date: Sat, 10 Nov 2018 13:58:55 +0530 Subject: [PATCH] Categories with pipe suffix (#1873) * Bug fix issue #1826 Changes made : -Certain category names used to show suffixed with strings prefixed with pipe '|'. Removed everything after the pipe. As per the discussion on the thread, its safe to remove everything after the pipe, including the pipe * review suggested changes *Code formatting *Extracted out the index of pipe in a variable *Added issue link in comments --- .../nrw/commons/media/MediaDetailFragment.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java b/app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java index 8feed101e..43debf323 100644 --- a/app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java @@ -431,8 +431,19 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment { private void rebuildCatList() { categoryContainer.removeAllViews(); // @fixme add the category items - for (String cat : categoryNames) { - View catLabel = buildCatLabel(cat, categoryContainer); + + //As per issue #1826(see https://github.com/commons-app/apps-android-commons/issues/1826), some categories come suffixed with strings prefixed with |. As per the discussion + //that was meant for alphabetical sorting of the categories and can be safely removed. + for (int i = 0; i < categoryNames.size(); i++) { + String categoryName = categoryNames.get(i); + //Removed everything after '|' + int indexOfPipe = categoryName.indexOf('|'); + if (indexOfPipe != -1) { + categoryName = categoryName.substring(0, indexOfPipe); + //Set the updated category to the list as well + categoryNames.set(i, categoryName); + } + View catLabel = buildCatLabel(categoryName, categoryContainer); categoryContainer.addView(catLabel); } }