Skip to content

Instantly share code, notes, and snippets.

@jasperkennis
Last active August 29, 2015 14:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jasperkennis/f84c5ccb5725feb9c35c to your computer and use it in GitHub Desktop.
getFormattedDate = ->
date = new Date()
date.getMonth() + "/" + date.getDate() + "/" + date.getFullYear() + " " + date.getHours() + ":" + date.getMinutes()
resetPullHeader = ->
actInd.hide()
imageArrow.transform = Ti.UI.create2DMatrix()
if refreshCount < 2
imageArrow.show()
labelStatus.text = "Pull down to refresh..."
labelLastUpdated.text = "Last Updated: " + getFormattedDate()
else
labelStatus.text = "Nothing To Refresh"
labelLastUpdated.text = "Last Updated: " + getFormattedDate()
listView.removeEventListener "pull", pullListener
listView.removeEventListener "pullend", pullendListener
eventStatus.text = "Removed event listeners."
listView.setContentInsets
top: 0
,
animated: true
return
loadTableData = ->
if refreshCount is 0
listView.appendSection vegSection
else listView.appendSection fishSection if refreshCount is 1
refreshCount++
resetPullHeader()
return
pullListener = (e) ->
eventStatus.text = "EVENT pull FIRED. e.active = " + e.active
if e.active is false
unrotate = Ti.UI.create2DMatrix()
imageArrow.animate
transform: unrotate
duration: 180
labelStatus.text = "Pull down to refresh..."
else
rotate = Ti.UI.create2DMatrix().rotate(180)
imageArrow.animate
transform: rotate
duration: 180
if refreshCount is 0
labelStatus.text = "Release to get Vegetables..."
else
labelStatus.text = "Release to get Fish..."
return
pullendListener = (e) ->
eventStatus.text = "EVENT pullend FIRED."
if refreshCount is 0
labelStatus.text = "Loading Vegetables..."
else
labelStatus.text = "Loading Fish..."
imageArrow.hide()
actInd.show()
listView.setContentInsets
top: 80
,
animated: true
setTimeout (->
loadTableData()
return
), 2000
return
win = Ti.UI.createWindow(backgroundColor: "white")
listView = Ti.UI.createListView(
height: "90%"
top: 0
)
sections = []
fruitSection = Ti.UI.createListSection(headerTitle: "Fruits")
fruitDataSet = [
{
properties:
title: "Apple"
}
{
properties:
title: "Banana"
}
]
fruitSection.setItems fruitDataSet
sections.push fruitSection
vegSection = Ti.UI.createListSection(headerTitle: "Vegetables")
vegDataSet = [
{
properties:
title: "Carrots"
}
{
properties:
title: "Potatoes"
}
]
vegSection.setItems vegDataSet
fishSection = Ti.UI.createListSection(headerTitle: "Fish")
fishDataSet = [
{
properties:
title: "Cod"
}
{
properties:
title: "Haddock"
}
]
fishSection.setItems fishDataSet
listView.sections = sections
refreshCount = 0
tableHeader = Ti.UI.createView(
backgroundColor: "#e2e7ed"
width: 320
height: 80
)
border = Ti.UI.createView(
backgroundColor: "#576c89"
bottom: 0
height: 2
)
tableHeader.add border
imageArrow = Ti.UI.createImageView(
image: "https://github.com/appcelerator/titanium_mobile/raw/master/demos/KitchenSink/Resources/images/whiteArrow.png"
left: 20
bottom: 10
width: 23
height: 60
)
tableHeader.add imageArrow
labelStatus = Ti.UI.createLabel(
color: "#576c89"
font:
fontSize: 13
fontWeight: "bold"
text: "Pull down to refresh..."
textAlign: "center"
left: 55
bottom: 30
width: 200
)
tableHeader.add labelStatus
labelLastUpdated = Ti.UI.createLabel(
color: "#576c89"
font:
fontSize: 12
text: "Last Updated: " + getFormattedDate()
textAlign: "center"
left: 55
bottom: 15
width: 200
)
tableHeader.add labelLastUpdated
actInd = Ti.UI.createActivityIndicator(
left: 20
bottom: 13
width: 30
height: 30
)
tableHeader.add actInd
listView.pullView = tableHeader
listView.addEventListener "pull", pullListener
listView.addEventListener "pullend", pullendListener
eventStatus = Ti.UI.createLabel(
font:
fontSize: 13
fontWeight: "bold"
text: "Event data will show here"
bottom: 0
height: "10%"
)
win.add listView
win.add eventStatus
win.open()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment