cyfung1031 / Emoji

A library to add Emoji support to your Android / JVM Application
Apache License 2.0
0 stars 0 forks source link

Intermediate Update #3

Closed cyfung1031 closed 1 year ago

cyfung1031 commented 1 year ago

This PR is for file record purpose only.

The focus is to change the EmojiView to be high performance with less memory usage.

Major Changes

1. ViewPager is successfully migrated to ViewPager2.

ViewPager2 is the recommended way by Google to handle the View Page Transition. Even I asked GPT-4 the advantages of ViewPager over ViewPager2, I have to reiterate twice to get its answer. However, the answer is not really the merit it has. From the first trial, I tried the suggestion from GPT-4 that to use RecycleView + GridLayoutManager + ViewPager2. I found that it is even slower. After trial and errors, the root cause is that RecycleView + GridLayoutManager cannot render the emoji as smooth as ArrayAdapter + GridView. The latest decision is GridView + ViewPager2. I have already fixed the layout issue related to ViewPager2, now it is good to use as the same as ViewPager.

2. UI Improvement

The color and some visual effects are similar to Whatsapp which looks better.

3. Recent Emoji Manager

I asked GPT-4 to rewrite as per my request. It did it and no error found in both complier and runtime. The revised logic is to compare the clicking record count first, then clicking timestamp.

4. Builder

The builder concept was not a good approach, and there are many event listener callback to be passed across the views. This make the code become messy and easy for memory leakage. Now Just pass one object which is combined the controller and the builder settings. All object references are weak references such that it will not create memory leakage. All sub components just need to store one reference copy to that controller object, and let the controller to decide how to make changes. Therefore, it is now much feasible that the handling can be customized from the external.

5. Removed AsyncTask for image loading, and added some coding for background thread.

Loading Drawable in Background is definitely a wrong decision. There are so many emojis, it will just consume the RAM and no much benefit. Now there is already setOffScreenPageLimit(1) such that there is always one in left and one in right for the paging. This is already preloaded. It has been tested that it is as smooth as with preloading all images. And if such loading action in setEmoji is delayed, the UX might not be good when the user try to swipe the pages.

6. Reorganized some nested function coding style.

In the past, there are many nested functions (e.g. Callable, Runner, etc.) which might lead to memory leakage. As now all these things are moved to the controller, such nested function are much reduced.

Remarks

The files are updated and can be used, but those class naming and builder etc shall have been finalized first. There are many no use java class and to be deleted. Therefore, this PR just serves as a historical record.

The next update shall remove the old files.