Hide rating if there's no data

Thanks to an anonymous contributor
This commit is contained in:
xynngh 2020-09-05 19:38:45 +04:00
parent f9430571d4
commit abcd94a052
1 changed files with 11 additions and 10 deletions

View File

@ -3,24 +3,25 @@ package dummydomain.yetanothercallblocker;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import java.util.HashMap; import androidx.annotation.IdRes;
import java.util.Map;
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem; import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem;
public class ReviewsSummaryHelper { public class ReviewsSummaryHelper {
public static void populateSummary(View reviewsSummary, CommunityDatabaseItem item) { public static void populateSummary(View reviewsSummary, CommunityDatabaseItem item) {
reviewsSummary.setVisibility(View.VISIBLE); boolean visible = item != null && item.hasRatings();
Map<Integer, Integer> map = new HashMap<>(3); reviewsSummary.setVisibility(visible ? View.VISIBLE : View.GONE);
map.put(R.id.summary_text_negative, item != null ? item.getNegativeRatingsCount() : 0); if (visible) {
map.put(R.id.summary_text_neutral, item != null ? item.getNeutralRatingsCount() : 0); setValue(reviewsSummary, R.id.summary_text_negative, item.getNegativeRatingsCount());
map.put(R.id.summary_text_positive, item != null ? item.getPositiveRatingsCount() : 0); setValue(reviewsSummary, R.id.summary_text_neutral, item.getNeutralRatingsCount());
for (Map.Entry<Integer, Integer> e : map.entrySet()) { setValue(reviewsSummary, R.id.summary_text_positive, item.getPositiveRatingsCount());
((TextView) reviewsSummary.findViewById(e.getKey())).setText(
String.valueOf(e.getValue()));
} }
} }
private static void setValue(View parentView, @IdRes int id, int value) {
parentView.<TextView>findViewById(id).setText(String.valueOf(value));
}
} }