Nasa APOD

Intro

This app delivers Nasa’s astronomical picture of the day (APOD) to android. Simple and intuitively you search through the calendar with access to Nasa’s APOD history. You can save your favorit APOD’s for viewing later, enable daily notifications and enable the app to set a new wallpaper for your device as soon as a new APOD is available.

Project

Own school project during 4 weeks, first individual app at Malmö Yrkeshögskola.

As I browsed through Nasa’s open API in search for interesting app idéas, I got hooked on the APOD API. Although several APOD apps are available on the Google-Play store, none of them had the simplicity and beautiful UI I envisioned.

The JSON-request and response handling was really straight-forward using Google’s Volley library. I decided for a bottom navigation controller and having three different fragment in one main-activity, just replacing the fragments when switching tab. I set up a view-model, so all the fragments could share the data between each other and that way the data is safe for orientation changes. The data is saved on the device in the Room-database and the connection to LiveData updates the UI and syncs with the database. The favorite tab was made from a customised grid-recycleview.

Recyclerview move and swipe to delete

Instead of using another external library to enhance the functionality of recyclerview, I decided to dive into the documentation. The ItemTouchHelper.Callback class turned out to have all I needed to implement swipe to delete and move items around. After adapting the callbacks to the application I connected the ItemTouchHelper to the recycleview.

Notifications and Wallpaper update

This was the most challenging and fun part of this project. This feature has to be implemented in the background on a system-level on a background thread, so the UI will remain unaffected. To describe to process briefly, I use the alarmmanager to trigger a pending-intent once a day to the broadcast-receiver. The broadcast-receiver is also notified after a reboot, and  will start a jobservice that will trigger an AsyncronousTask, creating a notification or setting the device wallpaper. This is done in the background even if the app is dead and the device is sleeping. When the jobservice starts the AsyncTask , an API request is sent to Nasa’s APOD server and the response is sent to the user as a notification that links to the app. The only problem is that when rebooting the device, all alarms are reset. To work around this problem, I gave the app permission to send an intent to the broadcast-receiver upon reboot, that triggers the receiver to check the shared-preferences if daily notifications or wallpaper update was activated and depending on the setting starts the alarm again.

If you prefer code, checkout the latest update on Github.