Some improvements to the application

This commit is contained in:
Christian Basler 2016-04-15 17:18:11 +02:00
parent ddd5826f42
commit 61890b3da9

View File

@ -99,7 +99,7 @@ public class Application {
subscriptions(); subscriptions();
break; break;
case "m": case "m":
messages(); labels();
break; break;
case "?": case "?":
info(); info();
@ -280,22 +280,65 @@ public class Application {
} }
} }
private void messages() { private void labels() {
List<Label> labels = ctx.messages().getLabels();
String command; String command;
do { do {
List<Plaintext> messages = ctx.messages().findMessages(Plaintext.Status.RECEIVED); System.out.println();
int i = 0;
for (Label label : labels) {
i++;
System.out.println(i + ") " + label + " [" + ctx.messages().countUnread(label) + "]");
}
System.out.println("a) Archive");
System.out.println();
System.out.println("c) compose message");
System.out.println("s) compose broadcast");
System.out.println(COMMAND_BACK);
command = commandLine.nextCommand();
switch (command) {
case "a":
messages(null);
break;
case "c":
compose(false);
break;
case "s":
compose(true);
break;
case "b":
return;
default:
try {
int index = Integer.parseInt(command) - 1;
messages(labels.get(index));
} catch (NumberFormatException | IndexOutOfBoundsException e) {
System.out.println(ERROR_UNKNOWN_COMMAND);
}
}
} while (!"b".equalsIgnoreCase(command));
}
private void messages(Label label) {
String command;
do {
List<Plaintext> messages = ctx.messages().findMessages(label);
System.out.println(); System.out.println();
int i = 0; int i = 0;
for (Plaintext message : messages) { for (Plaintext message : messages) {
i++; i++;
System.out.println(i + ") From: " + message.getFrom() + "; Subject: " + message.getSubject()); System.out.println(i + (message.isUnread() ? ">" : ")") + " From: " + message.getFrom() + "; Subject: " + message.getSubject());
} }
if (i == 0) { if (i == 0) {
System.out.println("You have no messages."); System.out.println("There are no messages.");
} }
System.out.println(); System.out.println();
System.out.println("c) compose message"); System.out.println("c) compose message");
System.out.println("s) compose broadcast"); System.out.println("s) compose broadcast");
if (label.getType() == Label.Type.TRASH) {
System.out.println("e) empty trash");
}
System.out.println(COMMAND_BACK); System.out.println(COMMAND_BACK);
command = commandLine.nextCommand(); command = commandLine.nextCommand();
@ -306,6 +349,8 @@ public class Application {
case "s": case "s":
compose(true); compose(true);
break; break;
case "e":
messages.forEach(ctx.messages()::remove);
case "b": case "b":
return; return;
default: default:
@ -328,13 +373,15 @@ public class Application {
System.out.println(message.getText()); System.out.println(message.getText());
System.out.println(); System.out.println();
System.out.println(message.getLabels().stream().map(Label::toString).collect( System.out.println(message.getLabels().stream().map(Label::toString).collect(
Collectors.joining("Labels: ", ", ", ""))); Collectors.joining(", ", "Labels: ", "")));
System.out.println(); System.out.println();
ctx.labeler().markAsRead(message); ctx.labeler().markAsRead(message);
ctx.messages().save(message);
String command; String command;
do { do {
System.out.println("r) reply"); System.out.println("r) reply");
System.out.println("d) delete"); System.out.println("d) delete");
System.out.println("a) archive");
System.out.println(COMMAND_BACK); System.out.println(COMMAND_BACK);
command = commandLine.nextCommand(); command = commandLine.nextCommand();
switch (command) { switch (command) {
@ -342,7 +389,13 @@ public class Application {
compose(message.getTo(), message.getFrom(), "RE: " + message.getSubject()); compose(message.getTo(), message.getFrom(), "RE: " + message.getSubject());
break; break;
case "d": case "d":
ctx.messages().remove(message); ctx.labeler().delete(message);
ctx.messages().save(message);
return;
case "a":
ctx.labeler().archive(message);
ctx.messages().save(message);
return;
case "b": case "b":
return; return;
default: default: