Closed phamthangnd closed 8 years ago
are you sure that the problem is in amount of items? can you please tell some more information to help me investigate this issue?
In sample app, if you add more tag string (>200-300 tags), device is no response. BaseFragments, String[] DATA length >300 this is appeared. Tested on Samsung Note 3, Samsung S5
Here my captured screen:
So with 100 items. Detail code :
List<String> items = new ArrayList<>();
for(int i = 0; i <= 100; i++) {
items.add("#HashTag"+i);
}
hashtagView2.setData(items,new HashtagView.DataTransform<String>() {
@Override
public CharSequence prepare(String item) {
SpannableString spannableString = new SpannableString("#" + item);
spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FF0000")), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannableString;
}
});
}
Thanks guys. As an intermediate result of my investigation I got that the problem is not connected to the amount of items. It's more like layout positioning issue, some problem with sorting algorythm. Still working on it. Will try to fix on weekend and release new version.
Thanks @greenfrvr !
The temporary simple solution. It doesn't use "smart" positioning of tags, but it works. MutableInt from commons-lans (http://grepcode.com/file_/repo1.maven.org/maven2/commons-lang/commons-lang/2.3/org/apache/commons/lang/mutable/MutableInt.java/?v=source) is used. nosort()
method should be called instead of sort()
.
private int evaluateRowsQuantityNoSort() {
if (widthList == null || widthList.isEmpty()) return 0;
int rows = (int) Math.ceil(totalItemsWidth / getViewWidth());
ArrayList<MutableInt> rowsWidth = new ArrayList<>(rows);
for (Float item : widthList) {
boolean inserted = false;
for (int i = 0; i < rowsWidth.size(); i++) {
if (rowsWidth.get(i).intValue() + item <= getViewWidth()) {
inserted = true;
rowsWidth.get(i).add(item);
}
}
if (!inserted) {
rowsWidth.add(new MutableInt(item.intValue()));
}
}
return rowsWidth.size();
}
private void nosort() {
if (data == null || data.isEmpty()) return;
int rowsQuantity = rowCount == 0 ? evaluateRowsQuantityNoSort() : rowCount;
int[] rowsWidth = new int[rowsQuantity];
viewMap = ArrayListMultimap.create(rowsQuantity, data.size());
for (ItemData item : data) {
for (int i = 0; i < rowsQuantity; i++) {
if (rowCount > 0 || rowsWidth[i] + item.width <= getViewWidth()) {
rowsWidth[i] += item.width;
viewMap.put(i, item);
break;
}
}
}
}
if we had more 200 tags, the app is no response.