import ui, console, timer, sound

###leaving off - follow stack overflow and subclass thread
###give it a stop attribute, and when you hit clear button, set the stop attribute to true
sound.set_honors_silent_switch(False)
threadPool = []

def killThreads():
	global threadPool
	for thread in threadPool:
			thread.kill()

def button_tapped(sender):
	global threadPool
	view = sender.superview
	repButton = view['repButton']
	
	if sender.name == 'clearButton':
		repButton.title = '0'
		view['textField'].text = ''
		killThreads()
		
	else:
		repButton.title = str(int(repButton.title) + 1)
		try:
			seconds = view['textField'].text
			timer.countdown(int(seconds), view['textField'], threadPool)
		except:
			pass
			

console.set_idle_timer_disabled(True)

v = ui.load_view()
v.present('sheet')
