-
Notifications
You must be signed in to change notification settings - Fork 0
/
dFavorites.deltaj
170 lines (134 loc) · 5.79 KB
/
dFavorites.deltaj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
delta dFavorites {
//package lancs.mobilemedia.core.ui.controller
modifies lancs.mobilemedia.core.ui.controller.BaseController {
modifies initCommandsMap() {
original();
commands.put("Set Favorite", new SetFavorite());
commands.put("View Favorites", new ViewFavorites());
}
}
modifies lancs.mobilemedia.core.ui.controller.PhotoListController {
adds public static final int SHOW_IMAGE_LIST_FAVORITES_MODE = 3; //used as showImageList parameter
modifies fillImageList(PhotoListScreen imageList, ImageData [] images, int
imageListMode) {
if(imageListMode == SHOW_IMAGE_LIST_FAVORITES_MODE) {
for(int i = 0;
i < images.length;
i ++) {
if(images[i] != null && images[i].isFavorite()) {
imageList.append(images[i].getImageLabel(), null);
}
}
}
else {
original(imageList, images, imageListMode);
}
}
}
adds {
package lancs.mobilemedia.core.ui.controller;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;
import javax.microedition.rms.RecordStoreFullException;
import lancs.mobilemedia.core.ui.datamodel.AlbumData;
import lancs.mobilemedia.core.ui.datamodel.ImageData;
import lancs.mobilemedia.lib.exceptions.ImageNotFoundException;
import lancs.mobilemedia.lib.exceptions.ImagePathNotValidException;
import lancs.mobilemedia.lib.exceptions.InvalidImageDataException;
import lancs.mobilemedia.lib.exceptions.NullAlbumDataReference;
import lancs.mobilemedia.lib.exceptions.PersistenceMechanismException;
public class SetFavorite implements ControllerCommandInterface {
public boolean execute(AbstractController controller) {
String selectedImageName = ((PhotoController) controller).getSelectedImageName();
try {
ImageData image = controller.getAlbumData().getImageInfo(selectedImageName);
image.toggleFavorite();
((PhotoController) controller).updateImage(image);
System.out.println("<* BaseController.handleCommand() *> Image = " + selectedImageName + "; Favorite = " + image.isFavorite());
} catch (ImageNotFoundException e) {
Alert alert = new Alert("Error", "The selected photo was not found in the mobile device", null, AlertType.ERROR);
Display.getDisplay(controller.getMidlet()).setCurrent(alert, Display.getDisplay(controller.getMidlet()).getCurrent());
} catch (NullAlbumDataReference e) {
controller.setAlbumData(new AlbumData());
Alert alert = new Alert("Error", "The operation is not available. Try again later !", null, AlertType.ERROR);
Display.getDisplay(controller.getMidlet()).setCurrent(alert, Display.getDisplay(controller.getMidlet()).getCurrent());
}
catch (InvalidImageDataException e) {
Alert alert = null;
if (e instanceof ImagePathNotValidException)
alert = new Alert("Error", "The path is not valid", null, AlertType.ERROR);
else
alert = new Alert("Error", "The image file format is not valid", null, AlertType.ERROR);
Display.getDisplay(controller.getMidlet()).setCurrent(alert, Display.getDisplay(controller.getMidlet()).getCurrent());
} catch (PersistenceMechanismException e) {
Alert alert = null;
if (e.getCause() instanceof RecordStoreFullException)
alert = new Alert( "Error", "The mobile database is full", null, AlertType.ERROR);
else
alert = new Alert( "Error", "The mobile database can not update new informations", null, AlertType.ERROR);
Display.getDisplay(controller.getMidlet()).setCurrent(alert, Display.getDisplay(controller.getMidlet()).getCurrent());
}
return true;
}
}
}
adds {
package lancs.mobilemedia.core.ui.controller;
import lancs.mobilemedia.core.util.Constants;
public class ViewFavorites implements ControllerCommandInterface {
public boolean execute(AbstractController controller) {((
PhotoListController )
controller).showImageList(controller.getCurrentStoreName(),
PhotoListController.SHOW_IMAGE_LIST_FAVORITES_MODE);
ScreenSingleton.getInstance().setCurrentScreenName(Constants.IMAGELIST_SCREEN);
return true;
}
}
}
//package lancs.mobilemedia.core.ui.datamodel
modifies lancs.mobilemedia.core.ui.datamodel.ImageData {
adds private boolean favorite = false;
adds public void toggleFavorite() {
favorite = ! favorite;
}
adds public boolean isFavorite() {
return favorite;
}
adds public void setFavorite(boolean favoriteParam) {
favorite = favoriteParam;
}
}
//package lancs.mobilemedia.core.ui.screens
modifies lancs.mobilemedia.core.ui.screens.PhotoListScreen {
adds public static final Command favoriteCommand = new
Command("Set Favorite", Command.ITEM, 1);
adds public static final Command viewFavoritesCommand = new
Command("View Favorites", Command.ITEM, 1);
modifies initMenu() {
original();
this.addCommand(favoriteCommand);
this.addCommand(viewFavoritesCommand);
}
}
//package lancs.mobilemedia.core.util
modifies lancs.mobilemedia.core.util.ImageUtil {
adds protected void setImageFavorite(ImageData ii, String iiString,
int startIndex, int endIndex, String delimiter) {
boolean favorite = false;
startIndex = endIndex + 1;
endIndex = iiString.indexOf(delimiter, startIndex);
if(endIndex == - 1) endIndex = iiString.length();
favorite =(iiString.substring(startIndex,
endIndex)).equalsIgnoreCase("true");
ii.setFavorite(favorite);
}
modifies retrieveImageByteString(ImageData ii) {
String byteString = original(ii);
byteString = byteString.concat(DELIMITER);
if (ii.isFavorite()) byteString = byteString.concat("true");
else byteString = byteString.concat("false");
return byteString;
}
}
}