Wednesday, July 8, 2015

More ways to help

  Hello again, it's time for a blog today!

  So it's my 7th week along with moVirt, as I said previously I have finished with my feature which was to implement  AR in moVirt. In past two weeks I've been focused on bug fixes, requests from users and other improvements which should make moVirt more stable and friendly to the users.

  The first task was to add notifications about Internet connection which came from user request. It's very important to keep user informed about connection state and how information is old while you work with remote data. So we decided just to put simple icon that warns if sync request was failed and Internet connection lost. "Looks like quite simple task with few lines of code" - what I was thinking. The first thing that I realized about android applications, that it's not that simple to keep application scope data if you have more that one activity and one of appropriate way to share some piece of information between all the activities is to put it into database. Well, ok, I'm familiar with SQL, and there is guides inside Android SDK documentation how to perform actions with SQLite. But if you are developing inside big enough project like moVirt then you find that it uses couple of frameworks and classes that hides low-level actions and I just can't connect to DB and insert a record into table. And I stepped into stupid situation where high-level concept confuses more then low-level. Hopefully my mentor guided me through part of the maze of classes and frameworks. And all this misadventures just to save a one variable available across all the activities. So the next step was to put an icon... into every activity in app. I thought: "Oh no, do I really need to copy&past code across all the activities?" I was about to start blaming Google for this Activity concept, but actually there are a couple of techniques to share logic and views between different activities: you can use fragments or overlays, but the best solution with minimal copy&pasting is to inherit activities! I'm quite experienced in OOP, but I haven't realized that we can inherit activities, before my mentor suggested this to me. Even though this trick requires significant refactoring, but it has lots of advantages. Following this solution and implemented parent activity as super class now we can add any code in one place in it would automatically work in every activity. After adding connection warning icon into parent activity I also grabbed sync action button to appear on every screen and now we can sync everywhere! And there could be even more things to appear in every activity.

  Yet another task was to extend moVirt's notification system. Since we now have connection state, information, we can inform user about failed synchronizations via android notifications. And since it was me who created NotificationHelper class (during initial contribution) adding new notifications is the easiest part.

  There were a couple of small fixes which I don't want to concentrate on. The last thing I want to write is about testing. My mentor insists that we need implement some unit tests for moVirt project, so that project may become more stable and bugless, and I agree with him, since I was interested in unit testing and this tasks now assigned to me. However my first attempts was failed. Android is not that simple to write unit tests, especially if you are not following TDD from beginning. But we'll see what I can do in the next two weeks.


Pic. 1. Foretasting of unit testing.

No comments:

Post a Comment