import be.nikiroo.jvcard.Card;
import be.nikiroo.jvcard.Contact;
import be.nikiroo.jvcard.Data;
-import be.nikiroo.jvcard.i18n.Trans;
-import be.nikiroo.jvcard.resources.Bundles;
+import be.nikiroo.jvcard.launcher.Main;
+import be.nikiroo.jvcard.resources.bundles.DisplayBundle;
+import be.nikiroo.jvcard.resources.enums.DisplayOption;
+import be.nikiroo.jvcard.resources.enums.ColorOption;
+import be.nikiroo.jvcard.resources.enums.StringId;
import be.nikiroo.jvcard.tui.KeyAction;
import be.nikiroo.jvcard.tui.KeyAction.DataType;
import be.nikiroo.jvcard.tui.KeyAction.Mode;
-import be.nikiroo.jvcard.tui.UiColors;
-import be.nikiroo.jvcard.tui.UiColors.Element;
import com.googlecode.lanterna.input.KeyType;
private String format;
public ContactList(Card card) {
+ DisplayBundle map = new DisplayBundle();
formats = new LinkedList<String>();
- for (String format : Bundles.getBundle("display")
- .getString("CONTACT_LIST_FORMAT").split(",")) {
+ for (String format : map.getString(DisplayOption.CONTACT_LIST_FORMAT)
+ .split(",")) {
formats.add(format);
}
this.contacts = new LinkedList<Contact>();
if (card != null) {
- for (int i = 0; i < card.size(); i++) {
- Contact c = card.get(i);
+ for (Contact c : card) {
if (filter == null
- || c.toString(format).toLowerCase()
+ || c.toString(format, "|").toLowerCase()
.contains(filter.toLowerCase())) {
addItem("x");
contacts.add(c);
List<KeyAction> actions = new LinkedList<KeyAction>();
// TODO ui
- actions.add(new KeyAction(Mode.ASK_USER, 'a', Trans.StringId.DUMMY) {
+ actions.add(new KeyAction(Mode.ASK_USER, 'a',
+ StringId.KEY_ACTION_ADD) {
@Override
public Object getObject() {
return card;
@Override
public String getQuestion() {
- // TODO i18n
- return "new contact name: ";
+ return Main.trans(StringId.ASK_USER_CONTACT_NAME);
}
@Override
}
});
actions.add(new KeyAction(Mode.ASK_USER_KEY, 'd',
- Trans.StringId.KEY_ACTION_DELETE_CONTACT) {
+ StringId.KEY_ACTION_DELETE) {
@Override
public Object getObject() {
return getSelectedContact();
@Override
public String getQuestion() {
- // TODO i18n
- return "Delete contact? [Y/N]";
+ Contact contact = getSelectedContact();
+ String contactName = "null";
+ if (contact != null)
+ contactName = "" + contact.getPreferredDataValue("FN");
+
+ return Main.trans(
+ StringId.CONFIRM_USER_DELETE_CONTACT,
+ contactName);
}
@Override
return null;
}
- // TODO i18n
- return "Cannot delete contact";
+ String contactName = "null";
+ if (contact != null)
+ contactName = "" + contact.getPreferredDataValue("FN");
+
+ return Main.trans(
+ StringId.ERR_CANNOT_DELETE_CONTACT,
+ contactName);
}
return null;
}
});
actions.add(new KeyAction(Mode.ASK_USER_KEY, 's',
- Trans.StringId.KEY_ACTION_SAVE_CARD) {
+ StringId.KEY_ACTION_SAVE_CARD) {
@Override
public Object getObject() {
return card;
});
actions.add(new KeyAction(Mode.CONTACT_DETAILS, KeyType.Enter,
- Trans.StringId.KEY_ACTION_VIEW_CONTACT) {
+ StringId.KEY_ACTION_VIEW_CONTACT) {
@Override
public Object getObject() {
return getSelectedContact();
}
});
actions.add(new KeyAction(Mode.NONE, KeyType.Tab,
- Trans.StringId.KEY_ACTION_SWITCH_FORMAT) {
+ StringId.KEY_ACTION_SWITCH_FORMAT) {
@Override
public boolean onAction() {
switchFormat();
}
});
actions.add(new KeyAction(Mode.ASK_USER, 'w',
- Trans.StringId.KEY_ACTION_SEARCH) {
+ StringId.KEY_ACTION_SEARCH) {
@Override
public String getQuestion() {
if (contact == null)
return parts;
- Element el = (focused && selected) ? Element.CONTACT_LINE_SELECTED
- : Element.CONTACT_LINE;
- Element elSep = (focused && selected) ? Element.CONTACT_LINE_SEPARATOR_SELECTED
- : Element.CONTACT_LINE_SEPARATOR;
- Element elDirty = (focused && selected) ? Element.CONTACT_LINE_DIRTY_SELECTED
- : Element.CONTACT_LINE_DIRTY;
+ ColorOption el = (focused && selected) ? ColorOption.CONTACT_LINE_SELECTED
+ : ColorOption.CONTACT_LINE;
+ ColorOption elSep = (focused && selected) ? ColorOption.CONTACT_LINE_SEPARATOR_SELECTED
+ : ColorOption.CONTACT_LINE_SEPARATOR;
+ ColorOption elDirty = (focused && selected) ? ColorOption.CONTACT_LINE_DIRTY_SELECTED
+ : ColorOption.CONTACT_LINE_DIRTY;
width -= 2; // dirty mark space
String[] array = contact.toStringArray(format, getSeparator(), " ",
- width, UiColors.getInstance().isUnicode());
-
+ width, Main.isUnicode());
+
if (contact.isDirty()) {
parts.add(new TextPart(" ", el));
parts.add(new TextPart("*", elDirty));