Wednesday, September 16, 2015

App a Day Challenge - Day 1: One Table

I'm starting an App a Day challenge. And I'm starting it today. The challenge ends when I get a job.

The Rules


The App a Day Challenge must result in one mobile app, which performs its intended function, posted to my github page once per day, 5 days a week. For my purposes the 5 days will be Tuesday through Saturday.

www.github.com/victorman

The app must compile, must perform its intended function without crashing, and it must be posted by midnight or 11:59 PM for the day it is made. I will be making changes to existing apps as some dailies but I will try to ensure that the added feature is not trivial.

A missed day will result in punishment; until better punishment is decided on, I will jog 5 kilometers. Every 2 failures will increase the punishment by 1 kilometer.

This does not mean that I will be starting and ending an app in one day. If I'm going to be able to do this I will need to make sure more complex apps get more time.



Day 1: OneTable

Click here for code.
In this app I just wanted to learn the basics of using a SQLite Database for persistent storage. It falls just short of doing something useful, allowing a user to keep short simple notes and displaying them in a list ordered newest to oldest. Each list item has a delete button.

If I had more time I'd obviously clean up the looks. I also wanted to make the list items more compact and then expand when focused.

I should be able to save a lot of time on future projects by starting with copies of the Contract, Helper, and Adapter classes and modifying those.

I used a lot of code and concepts from this Android training page on SQLite and from this code from the one of Udacity's Android courses.

So first I needed to define the database. This is done in the Contract and Helper classes.


Create an instance of the Helper. Also create an instance of the adapter. The Adapter simply extends cursor adapter and overrides newView and bindView.


After this part I defined functions that insert and query the database following almost exactly the related sections in the aforementioned Android training documentation regarding SQLite. You may have noticed the call to getLogTimes() which is just what they have there. It returns the cursor from SQLiteDatabase.query(). Whenever you run this function, take the cursor and put it into the swapCursor function of the adapter: mAdapter.swapCursor(getLogTimes(db)). This will update the list view with the new stuff.

I'm writing a shitty blog post so I'm going to come back and make this better another day. But for now, day one complete.

2 comments: