greenfrvr / hashtag-view

Android fully customizable widget for representing data like hashtags collection and similiar.
MIT License
337 stars 54 forks source link

If more tag the app is no responsed #11

Closed phamthangnd closed 8 years ago

phamthangnd commented 8 years ago

if we had more 200 tags, the app is no response.

greenfrvr commented 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?

phamthangnd commented 8 years ago

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: no response sampledata device-2015-10-26-104419

martinzarzar commented 8 years ago

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;
            }
        });
    }

tag

greenfrvr commented 8 years ago

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.

martinzarzar commented 8 years ago

Thanks @greenfrvr !

yankeppey commented 8 years ago

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;
            }
        }
    }
}