Commit 7e753be2 authored by Alexis Lecanu's avatar Alexis Lecanu

many timer started

parent 9148a054
......@@ -2,7 +2,7 @@ using Toybox.Application as App;
using Toybox.WatchUi as Ui;
var elements= new [0];
var model;
var models = {};
class TimerApp extends App.AppBase {
function initialize() {
......
......@@ -15,11 +15,12 @@ class TimerDelegate extends Ui.BehaviorDelegate {
bip = Ui.loadResource(Rez.Strings.Bip);
bip5S = Ui.loadResource(Rez.Strings.Bip5s);
vibrate = Ui.loadResource(Rez.Strings.Vibrate);
models.get(data.name).setVisible(true);
}
function onSelect() {
if(model.status==:Stop){
model.dropTimer();
if(models.get(data.name).status==:Stop){
models.get(data.name).dropTimer();
Ui.popView(Ui.SLIDE_RIGHT);
}
}
......@@ -44,8 +45,8 @@ class TimerDelegate extends Ui.BehaviorDelegate {
Ui.pushView(menu,new AlarmMenuDelegate(menu) , Ui.SLIDE_RIGHT );
}
function onBack() {
model.dropTimer();
function onBack() {
models.get(data.name).setVisible(false);
}
}
......@@ -9,23 +9,26 @@ using Toybox.Time as Time;
class TimerModel{
var counter;
var status=:Work;
var status=:Wait;
var data;
hidden var refreshTimer = new Timer.Timer();
hidden var displayTimer = new Timer.Timer();
var viewVisible=true;
function initialize(data){
self.data=data;
counter = data.time;
startTimer();
}
function startTimer(){
refreshTimer.stop();
displayTimer.stop();
refreshTimer.start(method(:refresh), 1000, true);
startBuzz();
Ui.requestUpdate();
if(status!=:Work){
counter = data.time;
status=:Work;
refreshTimer.stop();
displayTimer.stop();
refreshTimer.start(method(:refresh), 1000, true);
startBuzz();
Ui.requestUpdate();
}
}
function stopTimer(beep){
......@@ -51,6 +54,9 @@ class TimerModel{
counter--;
if (counter <= 5) {
buzz();
if(!viewVisible){
Ui.pushView(new TimerView(data), new TimerDelegate(data), Ui.SLIDE_IMMEDIATE );
}
}
} else {
status=:Stop;
......@@ -105,4 +111,7 @@ class TimerModel{
}
}
function setVisible(visible){
self.viewVisible=visible;
}
}
......@@ -8,9 +8,11 @@ class TimerView extends Ui.View {
hidden var text_width_point;
hidden var cx;
hidden var cy;
hidden var data;
function initialize () {
function initialize (data) {
View.initialize();
self.data=data;
}
function onShow () {
......@@ -26,11 +28,12 @@ class TimerView extends Ui.View {
function onUpdate (dc) {
dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_WHITE);
dc.clear();
if(model.status==:Work) {
drawTime(model.counter, dc);
drawArc(dc,model.counter, model.data.time);
if(models.get(data.name).status==:Work) {
drawTime(models.get(data.name).counter, dc);
bottomText(data.name,dc);
drawArc(dc,models.get(data.name).counter, data.time);
}else{
dc.drawText(dc.getWidth()/2, dc.getHeight()/2, Gfx.FONT_LARGE, model.data.name, Gfx.TEXT_JUSTIFY_VCENTER|Gfx.TEXT_JUSTIFY_CENTER);
dc.drawText(dc.getWidth()/2, dc.getHeight()/2, Gfx.FONT_LARGE, data.name, Gfx.TEXT_JUSTIFY_VCENTER|Gfx.TEXT_JUSTIFY_CENTER);
}
}
......@@ -70,4 +73,8 @@ class TimerView extends Ui.View {
dc.drawArc(cx,cy,dc.getHeight()/2-6,Gfx.ARC_CLOCKWISE,90,(360-angle.toLong()+90)%360);
}
}
function bottomText (text, dc) {
dc.drawText(dc.getWidth()/2, dc.getHeight()*0.825, Gfx.FONT_MEDIUM, text, Gfx.TEXT_JUSTIFY_VCENTER |Gfx.TEXT_JUSTIFY_CENTER);
}
}
......@@ -18,8 +18,15 @@ class ElementMenuDelegate extends MenuDelegate {
function onMenuItem(item) {
if(item.id==:Start){
model = new TimerModel(item.data);
Ui.pushView(new TimerView(), new TimerDelegate(item.data), Ui.SLIDE_IMMEDIATE );
var model;
if(models.hasKey(item.data.name)){
model = models.get(item.data.name);
}else{
model = new TimerModel(item.data);
models.put(item.data.name,model);
}
model.startTimer();
Ui.pushView(new TimerView(item.data), new TimerDelegate(item.data), Ui.SLIDE_IMMEDIATE );
}
if(item.id ==:Timer){
Ui.pushView(new TimePicker(timer,item.data), new TimePickerDelegate(item.data), Ui.SLIDE_IMMEDIATE);
......
......@@ -32,4 +32,11 @@ class HomeMenuDelegate extends MenuDelegate {
Ui.pushView(menu,new ElementMenuDelegate(menu) , Ui.SLIDE_LEFT );
}
}
function onBack() {
var values = models.values();
for( var i=0; i<values.size();i++){
values[i].dropTimer();
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment