Merge pull request #6025 from ByteHamster/filter-funding-by-length

When multiple funding tags reference the same URL, display the one with longer title
This commit is contained in:
ByteHamster 2022-08-20 21:08:49 +02:00 committed by GitHub
commit 0c8eb31b40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 7 deletions

View File

@ -57,7 +57,7 @@ import io.reactivex.schedulers.Schedulers;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
/**
* Displays information about a feed.
@ -236,13 +236,24 @@ public class FeedInfoFragment extends Fragment implements Toolbar.OnMenuItemClic
} else {
lblSupport.setVisibility(View.VISIBLE);
ArrayList<FeedFunding> fundingList = feed.getPaymentLinks();
StringBuilder str = new StringBuilder();
HashSet<String> seen = new HashSet<String>();
for (FeedFunding funding : fundingList) {
if (seen.contains(funding.url)) {
continue;
// Filter for duplicates, but keep items in the order that they have in the feed.
Iterator<FeedFunding> i = fundingList.iterator();
while (i.hasNext()) {
FeedFunding funding = i.next();
for (FeedFunding other : fundingList) {
if (TextUtils.equals(other.url, funding.url)) {
if (other.content != null && funding.content != null
&& other.content.length() > funding.content.length()) {
i.remove();
break;
}
}
}
seen.add(funding.url);
}
StringBuilder str = new StringBuilder();
for (FeedFunding funding : fundingList) {
str.append(funding.content.isEmpty()
? getContext().getResources().getString(R.string.support_podcast)
: funding.content).append(" ").append(funding.url);