Commit 66a0dea8 authored by Alexis Lecanu's avatar Alexis Lecanu

add button up and down

parent bf990361
......@@ -13,4 +13,6 @@
<string id="Disable">Désactivé</string>
<string id="Timer">Cpte. à Reb.</string>
<string id="Add">Ajouter</string>
<string id="Up">Monter</string>
<string id="Down">Descendre</string>
</strings>
......@@ -13,4 +13,6 @@
<string id="Disable">Disable</string>
<string id="Timer">Timer</string>
<string id="Add">Add</string>
<string id="Up">Up</string>
<string id="Down">Down</string>
</strings>
class Element {
var position;
var name;
var time;
var beep;
var beep5s;
var vibrate;
function initialize (json) {
function initialize (position,json) {
self.position=position;
self.name = extractValue("name",json);
var timeString = extractValue("time",json);
if(timeString.equals("")){
......@@ -18,6 +20,10 @@ class Element {
self.vibrate = !extractValue("vibrate",json).equals("false")?true:false;
}
function setPosition(position){
self.position=position;
}
function extractValue(key,json){
var index =json.find("\""+key+"\":");
if(index != null){
......
......@@ -26,11 +26,13 @@ class TimerApp extends App.AppBase {
function extract(json){
if(json!=null){
var index =json.find("{");
while(index != null){
var position = 0;
while(index != null){
json = json.substring(index +1 ,json.length());
var value = json.substring(0,json.find("}")+1);
elements.add(new Element("{"+value));
elements.add(new Element(position,"{"+value));
index =json.find("{");
position = position + 1;
}
}
}
......
......@@ -10,6 +10,8 @@ class ElementMenu extends Menu {
hidden var alarms;
hidden var remove;
hidden var rename;
hidden var up;
hidden var down;
function initialize (data) {
self.data=data;
......@@ -19,15 +21,25 @@ class ElementMenu extends Menu {
alarms = Ui.loadResource(Rez.Strings.Alarms);
remove = Ui.loadResource(Rez.Strings.Remove);
rename = Ui.loadResource(Rez.Strings.Rename);
up = Ui.loadResource(Rez.Strings.Up);
down = Ui.loadResource(Rez.Strings.Down);
var menuItems = new [0];
menuItems.add(new DataMenuItem (:Start,start, data));
menuItems.add(new TimeMenuItem (:Timer,data));
menuItems.addAll(defaultMenu());
Menu.initialize (menuItems, data.name);
}
function defaultMenu(){
var menuItems = new [0];
menuItems.add(new TimeMenuItem (:Timer,data));
menuItems.add(new DataMenuItem (:Alarms,alarms,data));
menuItems.add(new DataMenuItem (:Remove,remove,data));
menuItems.add(new DataMenuItem (:Up,up,data));
menuItems.add(new DataMenuItem (:Down,down,data));
menuItems.add(new DataMenuItem (:Rename,rename,data));
Menu.initialize (menuItems, data.name);
return menuItems;
}
function onShow() {
......@@ -35,10 +47,8 @@ class ElementMenu extends Menu {
var menuItems = new [0];
menuItems.add(new DataMenuItem (:Continu,continu, data));
menuItems.add(new DataMenuItem (:Reset,reset, data));
menuItems.add(new TimeMenuItem (:Timer,data));
menuItems.add(new DataMenuItem (:Alarms,alarms,data));
menuItems.add(new DataMenuItem (:Remove,remove,data));
menuItems.add(new DataMenuItem (:Rename,rename,data));
menuItems.addAll(defaultMenu());
Menu.setMenuArray(menuItems);
}
Menu.setTitle(data.name);
......@@ -49,10 +59,8 @@ class ElementMenu extends Menu {
if(models.hasKey(data.name) && models.get(data.name).status==:Reset){
var menuItems = new [0];
menuItems.add(new DataMenuItem (:Start,start, data));
menuItems.add(new TimeMenuItem (:Timer,data));
menuItems.add(new DataMenuItem (:Alarms,alarms,data));
menuItems.add(new DataMenuItem (:Remove,remove,data));
menuItems.add(new DataMenuItem (:Rename,rename,data));
menuItems.addAll(defaultMenu());
Menu.setMenuArray(menuItems);
Menu.resetPosition();
models.get(data.name).setStatus(:Wait);
......
......@@ -36,6 +36,42 @@ class ElementMenuDelegate extends MenuDelegate {
}else if ( item.id == :Alarms){
var menu = new AlarmMenu (item.data);
Ui.pushView(menu,new AlarmMenuDelegate(menu) , Ui.SLIDE_LEFT );
}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);
}
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ class AddElementPicker extends Ui.TextPickerDelegate {
}
function onTextEntered(text, changed) {
elements.add(new Element("{\"name\":\""+text+"\"}"));
elements.add(new Element(elements.size(),"{\"name\":\""+text+"\"}"));
}
function onCancel() {
......
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