ElementMenuDelegate.mc 2.49 KB
Newer Older
Alexis Lecanu's avatar
Alexis Lecanu committed
1 2 3
using Toybox.WatchUi as Ui;

class ElementMenuDelegate extends MenuDelegate {
4

Alexis Lecanu's avatar
Alexis Lecanu committed
5 6 7 8 9 10 11 12
	hidden var timer;

    function initialize(menu) {
        MenuDelegate.initialize(menu);
		timer = Ui.loadResource(Rez.Strings.Timer);
    }

    function onMenuItem(item) {
13 14
    	if(item.id==:Continu){
    		Ui.pushView(new TimerView(item.data), new TimerDelegate(item.data), Ui.SLIDE_IMMEDIATE );
Alexis Lecanu's avatar
Alexis Lecanu committed
15 16
    	}else if(item.id==:Reset){
    		 models.get(item.data.name).resetTimer();
17
    	}else if(item.id==:Start){
Alexis Lecanu's avatar
Alexis Lecanu committed
18 19 20 21 22 23 24 25 26
    		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 );
27
    	}else if(item.id ==:Timer){
Alexis Lecanu's avatar
Alexis Lecanu committed
28 29 30 31 32 33 34 35 36
    		Ui.pushView(new TimePicker(timer,item.data), new TimePickerDelegate(item.data), Ui.SLIDE_IMMEDIATE);
    	}else if(item.id ==:Remove){
    		elements.remove(item.data);
    		Ui.popView (Ui.SLIDE_LEFT);
    	}else if(item.id ==:Rename){
    	    if (Ui has :TextPicker) {
                Ui.pushView(new Ui.TextPicker(item.data.name), new EditElementPicker(item.data), Ui.SLIDE_LEFT);
            }
    	}else if ( item.id == :Alarms){
37
		    var menu = new AlarmMenu (item.data);
Alexis Lecanu's avatar
Alexis Lecanu committed
38
            Ui.pushView(menu,new AlarmMenuDelegate(menu) ,  Ui.SLIDE_LEFT );
Alexis Lecanu's avatar
Alexis Lecanu committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    	}else if ( item.id == :Up){
		    var position=item.data.position;
		   	if(position>0){
		   		var temps= new [0];
		    	for(var i=0;i<elements.size();i++){
			    	if(i==position-1){
			    		item.data.setPosition(temps.size());
			    		temps.add(item.data);
		    		}
		    		if(i!=position){
		    			elements[i].setPosition(temps.size());
		    			temps.add(elements[i]);
		   			}
		   		}
		   		elements= new [0];
		    	elements.addAll(temps);
		   	}		   
		    Ui.popView (Ui.SLIDE_LEFT);
    	}else if ( item.id == :Down){
		    var position=item.data.position;
		    if(position<elements.size()-1){
		    	var temps= new [0];
		    	for(var i=0;i<elements.size();i++){
		    		if(i!=position){
		    			elements[i].setPosition(temps.size());
		    			temps.add(elements[i]);
		    		}
		    		if(i==position+1){
		    			item.data.setPosition(temps.size());
		    			temps.add(item.data);
		    		}		    	
		    	}
		    	elements= new [0];
		    	elements.addAll(temps);
			}
		    Ui.popView (Ui.SLIDE_LEFT);
75 76
    	}else if(item.id ==:AutoRestart){
    		item.data.autoRestart=!item.data.autoRestart;
Alexis Lecanu's avatar
Alexis Lecanu committed
77 78 79
    	}
    }
}