TagView icon indicating copy to clipboard operation
TagView copied to clipboard

Optimization with adding list of items

Open mtychyna opened this issue 9 years ago • 2 comments

In class TagView in method addTags(List<Tag> tags)you do addTag(item); But what are doing here?

    public void addTag(Tag tag) {
        mTags.add(tag);
        drawTags();
    }

After adding of each tag to addTag you draw tags... Inside drawTags() first removeAllViews(); and then for (Tag item : mTags) Are you jokking? Why if you are going to remove and redraw all, you do it after adding of each element to inner list? Sorry guys but it have to be optimized!

mtychyna avatar Apr 26 '16 09:04 mtychyna

Why if you are going to remove and redraw all, you do it after adding of each element to inner list?

I agree with you here. I don't understand it either. It's just so slow to load tags.

But I can see that was 9 months ago and no response. Why even bother...

masquadel avatar Jan 07 '17 23:01 masquadel

:/ I decided to Inherit from TagView to override this method...

    @Override
    public void addTags(List<Tag> tags)
    {
        //        super.addTags(tags);
        try
        {
            Field tagsField = TagView.class.getDeclaredField("mTags");
            tagsField.setAccessible(true);
            
            ArrayList<Tag> mTags = new ArrayList<>();

            Method drawTagsMethod = TagView.class.getDeclaredMethod("drawTags");
            drawTagsMethod.setAccessible(true);

            if (tags != null)
            {
                for (Tag tag : tags)
                {
                    mTags.add(tag);
                }

                tagsField.set(this, mTags);
                drawTagsMethod.invoke(this);
            }
        }
        catch (NoSuchFieldException e)
        {
            e.printStackTrace();
        }
        catch (IllegalAccessException e)
        {
            e.printStackTrace();
        }
        catch (NoSuchMethodException e)
        {
            e.printStackTrace();
        }
        catch (InvocationTargetException e)
        {
            e.printStackTrace();
        }
    }

ChristopheCVBWDG avatar May 03 '17 15:05 ChristopheCVBWDG