Hide rating if there's no data
Thanks to an anonymous contributor
This commit is contained in:
parent
f9430571d4
commit
abcd94a052
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue