Some parts of developing the app
Last time I
was writing about me and the app. Now I am writing about development of the
app. Making a good app will always take time and I have been using a lot of
time for the development. There are some common mistakes in development and one
of them you shouldn’t try implement whole app without feedback. So, I have done
many iterations and our group’s testers Jere and Atte have tested them.
Our first
goal for the app was that we can make posts and view them. Achieving it didn’t
take long using Firebase. I recommend trying Firebase with a project for
everyone because you can try things so fast without implementing the whole backend.
In Firestore you can make collections that hold documents. Documents can hold a
many kind of data. I think that the best way of saving posts is to make a post
class in your code so you can easily save posts and load them. Many would think
that then you should add data structure in the post class for saving the
comments in post, but that isn’t the case. Documents size limit is only 1MB so
you can easily run out of the space. So, the next question would be how you can
overcome this. I made the comments as a sub collection of the post. Collections
doesn’t have limit for the documents and the database is designed to scale so
querying is efficient.
Now you
know something about our services backend, and you are probably interested in
the app itself also. If you do not know anything about Android development,
there are two languages for making native apps and these ones are Java and
Kotlin. Java is old and widely used language and Kotlin is a newer one by
Google. Both are good options for development, but Kotlin is better because it
is a preferred language for Android. I chose Java for our app because I already
knew it. I am still also interested in learning Kotlin and maybe Flutter for
both Android and IOS.
Making the
Android app with your chosen language you also must write XML (Extensible
Markup Language) that makes the UI. The app contains three activities time of
the writing. The activities are posts, comments and post. In posts activity you
can see all the posts, choose a category, open a post to see comments that it
contains and make a new post. Considering previous it is obvious that posts
activity is app’s main activity. Post class and Comment class that I mentioned
earlier are important for keeping the code clean and working. Both classes are
simple and one thing that you should keep in your mind when working with
Firestore is that you need empty constructor in your class.
In my
earlier blog post I told about an open source library called
Firebase-UI-Android. I am not familiar with all its features but it is a very
good library if you need RecyclerView to show data from Firestore. I am using
it in posts and comments activities. With it is easy to make the query data
changes in real time. You can do that by yourself, but that library is tested
and well-known so it is preferred. The library contains Firestore
RecyclerAdapter that can be extended. If you want to use it, you should make
your own adapter. I have an adapter called PostAdapter that extends it for
posts. Firestore RecyclerAdapter does the querying with database in real time.
It is very impressive to see how well your app works with it. It’s obvious that
you must start listening database, but also do not forget to end listening. I
implemented the listening ending by overriding the onStop method. That works
well for example if a user opens comments then the app stops listening database
changes from posts and start listening from comments.
Sometimes
programmers are so interested in making new features and coding that UI is
forgotten. We do not have any designer for it, so I am also responsible for it.
I am also interested in UI and after the last blog post UI got a big update.
User can now even choose the color for a post. That make a little change for
the data structure and the adapter because the color had to be saved and
changed for post’s CardView in adapter. I chose colors for posts quickly just
for testing and I will change them better soon.
There you
can see my post when I was programming and choosing the colors. “Valmista tälle
iltaa” means “ready from tonight” and timestamp shows 02.40. I also redesigned
Post view and the comment view. I think post view looks
clean and enjoyable.
Comments