Drkcore

23 11 2012 javascript iPhone Ti Tweet

Alloyでつくる簡易RSSリーダー

Titanium Mobile iPhone/Androidアプリ開発入門の簡易RSSリーダーをAlloyで書きなおしてみた

alloy rssreader

CoffeeScrptで開発する方法については、ここを参照のこと。

軽くハマったのはviewかな。

views/index.xml

最初TabGroupにidを設定したら、$.index.openでエラーがでた。

結局$.indexってなんじゃろか?とドキュメントを読んだら解決した。

要するにViewのトップレベルには

  • Ti.UI.Window
  • Ti.UI.TabGroup
  • Ti.UI.iPad.SplitWindow

のいずれかが必要で、idが明示的に指定されてない場合には、そのファイル名がidとして利用される。

規約に従うことにしたらxmlはシンプルになった。

<Alloy>
    <TabGroup>
    </TabGroup>
</Alloy>

controllers/index.coffee

コントローラーは本の通りに。スタイルとかも全部コントローラーに書いちゃったのでindex.tssはいじってない。

createApplicationTabGroup =  ->
  tab1 = createRSSTab 'Developer Blog', 'http://developer.appcelerator.com/blog/feed'
  tab2 = createRSSTab 'Q&A', 'http://developer.appcelerator.com/questions/feed/newest'
  $.index.addTab tab1
  $.index.addTab tab2
  return

createRSSTab = (title, url) ->
  win = Ti.UI.createWindow
    title: title

  tab = Ti.UI.createTab
    title: title
    icon: 'KS_nav_views.png'
    window: win

  tableView = Ti.UI.createTableView {data:[]}
  win.add(tableView)

  win.addEventListener 'open', ->
    query = String.format "select * from rss where url = '%s'", url
    Ti.Yahoo.yql query, (res) -> 
      if res.success is false
        alert("Yahoo YQL error.")
        return
      res.data.item.forEach (item) ->
        tableView.appendRow
          title: item.title
          color: '#000'
          link: item.link
          hasChild: true
    return

  tableView.addEventListener 'click', (event) ->
    detailWin = Ti.UI.createWindow {title: event.rowData.title, backgroundColor: '#fff'}
    webView = Ti.UI.createWebView {url: event.rowData.link}
    detailWin.add(webView)
    tab.open(detailWin)
    return

  return tab

createApplicationTabGroup()

$.index.open()

ProductName Titanium Mobile iPhone/Androidアプリ開発入門―JavaScriptだけで作る
小澤 栄一
秀和システム / 2520円 ( 2012-02 )


About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021