Wednesday, May 1, 2013

The school project - pv calendar app

Today I'm going to shed some light on the project I'm working on at school.  I'm unsure about where this project is headed and right now it's completion seems extremely far away.  The goal is to make an android app for the pv google calendar.  I know there's plenty of apps that can import google calendars already but for whatever reason we (as in the other kid working with me and my teacher) wanted to remake it.

So beginning the project I figured we needed to use the java google calendar api because android apps are created in java.  The only problem with this was I could not import the needed libraries for the life of me.  I imported literally everything google gave me and couldn't get the needed ones (oauth2.draft10) to configure my app as they show: https://developers.google.com/google-apps/calendar/instantiate

For whatever reason I decided not to start off the working example, I think because I ran into another error, but I'm not sure cause that was so long ago.  Anyways I then came up with the idea to try using the api for a web language like javascript because importing the libraries should be very simple to do (which it was) and I got the api working correctly.  Since I have it working correctly I came up with the idea to make a webpage and just have a WebView on the android app load it.

Now by "got the api working correctly" I mean that I followed this dudes blog post to understand the basic configuration and api usage: http://googleappsdeveloper.blogspot.com/2011/12/using-new-js-library-to-unlock-power-of.html

I still have plenty of work to do to get the actual full working web page to load in the WebView and before I go any further into explaining the code I'm going to post entire current web page: http://pastebin.com/UaLqfkfJ

The first problem I had was the function firing twice which I took care of with the firedOnce boolean and the loops I used with it.  The second problem was getting the start and end date for all the events.  This following does grab the start and end date for each item:
var date = document.createTextNode('Start: ' + resp.items[i].start.date + ' End: ' + resp.items[i].end.date);
But the problem was that the .start.date and .end.date is undefined for a lot of the events and there are no other properties to read the date they start from.

With this in mind, I figured I just need to loop through every day of the month and pull the events from that day.  That way I'd know what the date of the event is and I wouldn't have to rely on google to get it.  To get a certain day's events I'd have to add in the timeMin and timeMax parameters to the google request like so:
'timeMin': 'year-month-dayT00:00:00-06:00'.replace('year', year).replace('month', month).replace('day', day),
'timeMax': 'year-month-dayT23:59:59-06:00'.replace('year', year).replace('month', month).replace('day', day)


Why use replace and not just concatenate the string using +?  Concatenation didn't work for me for whatever reason and replacement did.  Now if you look right after, gapi.client.load('calendar', 'v3', function() {, you'll see a commented out loop and an increment on the days variable.  This is the loop that's supposed to increment the days/months that doesn't work at all.  It's like it increments the days (cause that's all I was testing the increment on atm) till it's done and then does the google request and displays it on the screen.  If I could solve this issue the coding would pretty much be done and I'd be able to add it to the android app.

Now that I've explained all this the period is over and I'll start making progress on this next period tomorrow.

No comments:

Post a Comment