These two weeks I’ve been working on refactoring extensively. The code I am working on is responsible for saving the map as an image. It creates a screenshot of the scene and saves to the device’s (Android or iOS) gallery. The first bug I’ve encountered was not showing the recently saved image. Turns out the Show button was missing in the dialog box that’s shown when the save process is over. Then another bug arises when retrieving the image. The device couldn’t read the image while it was working in the Editor on PC.
On iOS, the real reason was unknown but we fixed the bug by telling to iPhone “would you be so kind to open up the photo library” (opening the photo library), instead of “open THAT EXACT file” by giving the exact file path. I guess it was due to an update for iOS that cancels opening the image particularly. Instead of this, we open up photo library so the user can see the latest images from the gallery.
For Android, the file name consisted parenthesis and when I removed the parenthesis from the name, it started to show the image. Before that, the device tried to open the image as a pdf document but failed to do so. The device couldn’t read parenthesis in the name and that mixed up the extensions. The third bug I’ve encountered was a dialog box that’s stuck in the saving process. It was misleading the user that the process is stuck in the middle of the saving process but actually it is done successfully, but there was a problem with updating the UI and hiding the dialog box. I’ve seen that the bug is caused by a forgotten dialog box that code didn’t close. So, please, don’t neglect UI. It needs attention. It needs our care…
These were actually hotfixes that is crucial to meet the expectations of users. But there should be an extensive refactoring of the whole screenshot system. So I started to examine the code and realized it was a monolithic, giant code that governs every single function that’s needed for the screenshot. To be precise it was 800 line of code and it almost does everything. Also, the pro and simple screenshot classes are unrelated classes that do the exact same thing, like saving and opening the file. So I created a class that executes the similar functions of the two modes (aka Factory Pattern). Then I refactored the pro screenshot class and split it into several different classes that handle image size, quality, how many pages it’ll be and show events and props on the map.
After splitting and renaming, I started to test the outcome.
I’ll be updating so stay in tune!