2
2009
Adding iPhone support to groovyblogs
Since being given an ipod touch, I’ve been keen to explore the issues with designing for iphone web apps. With Grails In Action in final copy edits, I’ve finally got some free time to invest in a big refactor of groovyblogs.
I’ve already reworked the security system to use JSecurity, moved all the custom search logic over to Searchable, and fixed the dread “numerous repost” problems when people mess with their feedburner/blog software/etc. It’s now checks the hash of the post content to perform more reliable duplicate checking that is independent of whatever their blogs software assigns to their “permalink”.
If you’re keen to tinker with developing websites with iphone support, and you don’t have a device, you can still use emulators to get a feel for what’s possible. I’ve been working with iPhoney which gives you a pretty good sense of what the site will look like – including the ability to rotate the device. Here’s what my new groovyblogs iphone menu page looks like on the iPhoney emulator:
Now, on to the meat of implementing this sort of stuff. Grails supports plugins for both iUI and iWebKit (two of the main iPhone development libraries). Given the wealth of documentation available for iWebKit, I thought I’d take that for a spin first. The iWebKit plugin has some docs online, but the best way to get familiar with it is to watch the great screencast on getting started.
After following the screencast, I was ready to go. I whipped up my page using the taglibs and I was up and running. You have to set the layout template name of your page to be “iphone” – after that you just use the tags and enjoy the styling. Here’s the body of the new ipod homepage shown above:
<iphone:topbar title="groovyblogs">
<iphone:leftnavigation navtype="button">
<iphone:navelement action="pc" content="PC Website"/>
</iphone:leftnavigation>
</iphone:topbar>
<iphone:content>
<iphone:section>
<iphone:list action="show" descriptionField="title" list="${entries}"/>
</iphone:section>
</iphone:content>
My first gotcha was that you’ve got to copy the /layouts/iphone.gsp from the plugin installation into your Grails app. The plugin page notes this saying that this would be fixed in Grails 1.1. No such luck. That still applies.
The iphone:list tag iterates over each of the entries in ${entries} and creates a menu item name ${entry.title} which is linked to the “show” action of the current controller. The id is also passed in. Once you’ve done that you get a nicely rendered menu page complete with a swipey link, rollovers and right arrow link. Here’s the same page running on my device:
Once you’ve chosen one of the menu options, the show action will fire to give you a more complete preview of the link. I wanted to make the structure of this page a little more “custom”, so I branched out of the iWebKit plugin taglibs to add some of my own markup.
<iphone:topbar title="${pageTitle}">
<iphone:leftnavigation navtype="arrow">
<iphone:navelement action="recent" content="Recent Entries"/>
</iphone:leftnavigation>
</iphone:topbar>
<iphone:content>
<iphone:section>
<iphone:textbox header="${entry.title}">
<div style="color: gray; font-size: smaller;">
${entry.blog.title} » ${entry.hitCount} clicks »
<g:dateFromNow date="${entry.dateAdded}"/>
</div>
</iphone:textbox>
<g:link controller="entries" action="jump" id="${entry.id}">
<img alt="no thumb" src="${g.createLink(controller: 'thumbnail', action: 'show', id: entry.id)}" style="float: left;"/>
</g:link>
<g:summariseEntry description="${entry.description}"/><br/><br/>
<g:link controller="entries" action="jump" id="${entry.id}">
Visit »
</g:link>
</iphone:section>
</iphone:content>
The iphone:textbox tag lets you do some funky stuff with those blue-headed entries that are common on iphone-friendly sites. I’ve reused my thumbnail code to render a preview (which looks pretty good even on a small device – and saves an expensive site launch if the content preview makes you lose interest). Here’s the new “show” action running on my touch:
So I’ve got to say that my first experiences with iWebKit were really great. The docs are fantastic, and the plugin saves you a ton of time getting up and running.
Now, on to some more groovyblogs feature updates before my next round of copy-edits come in…
1 Comment + Add Comment
Leave a comment
Glen Smith
Archives
- January 2012
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- April 2011
- March 2011
- January 2011
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- April 2005
- March 2005
- February 2005
- January 2005
- December 2004
- November 2004
- October 2004
- September 2004
- August 2004
- July 2004
- June 2004
- May 2004
- March 2004
- February 2004
- January 2004
- December 2003
- November 2003
- October 2003
- September 2003

An article by Glen





It might be neat to add Twitter Support too, . . . As you post new entries, sent a tweet out to @GroovyBlogs.