From fe93c95f40b847046840ca3e8077acb252bda06c Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Thu, 11 Jun 2015 21:02:01 +0200 Subject: [PATCH] Added some improvements to the demo application --- .gitignore | 5 ++- .../dissem/bitmessage/demo/Application.java | 35 ++++++++++++------- .../java/ch/dissem/bitmessage/demo/Main.java | 4 +-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 273f257..fd29962 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ # Created by https://www.gitignore.io +*.log + ### Gradle ### .gradle build/ @@ -115,7 +117,8 @@ local.properties .LSOverride # Icon must end with two \r -Icon +Icon + # Thumbnails ._* diff --git a/demo/src/main/java/ch/dissem/bitmessage/demo/Application.java b/demo/src/main/java/ch/dissem/bitmessage/demo/Application.java index 6bd271c..cd48f21 100644 --- a/demo/src/main/java/ch/dissem/bitmessage/demo/Application.java +++ b/demo/src/main/java/ch/dissem/bitmessage/demo/Application.java @@ -150,7 +150,7 @@ public class Application { System.out.println(); BitmessageAddress identity = ctx.createIdentity(yesNo("would you like a shorter address? This will take some time to calculate."), Pubkey.Feature.DOES_ACK); System.out.println("Please enter an alias for this identity, or an empty string for none"); - String alias = nextCommand(); + String alias = scanner.nextLine().trim(); if (alias.length() > 0) { identity.setAlias(alias); } @@ -346,19 +346,30 @@ public class Application { private void compose(boolean broadcast) { System.out.println(); BitmessageAddress from = selectAddress(true); + if (from == null) { + return; + } BitmessageAddress to = (broadcast ? null : selectAddress(false)); + if (!broadcast && to == null) { + return; + } compose(from, to, null); } private BitmessageAddress selectAddress(boolean id) { - List identities = (id ? ctx.addresses().getIdentities() : ctx.addresses().getContacts()); - while (identities.size() == 0) { - addIdentity(); - identities = ctx.addresses().getIdentities(); + List addresses = (id ? ctx.addresses().getIdentities() : ctx.addresses().getContacts()); + while (addresses.size() == 0) { + if (id) { + addIdentity(); + addresses = ctx.addresses().getIdentities(); + } else { + addContact(false); + addresses = ctx.addresses().getContacts(); + } } - if (identities.size() == 1) { - return identities.get(0); + if (addresses.size() == 1) { + return addresses.get(0); } String command; @@ -371,7 +382,7 @@ public class Application { } int i = 0; - for (BitmessageAddress identity : identities) { + for (BitmessageAddress identity : addresses) { i++; System.out.print(i + ") "); if (identity.getAlias() != null) { @@ -389,8 +400,8 @@ public class Application { default: try { int index = Integer.parseInt(command) - 1; - if (identities.get(index) != null) { - return identities.get(index); + if (addresses.get(index) != null) { + return addresses.get(index); } } catch (NumberFormatException e) { System.out.println("Unknown command. Please try again."); @@ -411,13 +422,13 @@ public class Application { System.out.println("Subject: " + subject); } else { System.out.print("Subject: "); - subject = nextCommand(); + subject = scanner.nextLine().trim(); } System.out.println("Message:"); StringBuilder message = new StringBuilder(); String line; do { - line = nextCommand(); + line = scanner.nextLine(); message.append(line).append('\n'); } while (line.length() > 0 || !yesNo("Send message?")); if (broadcast) { diff --git a/demo/src/main/java/ch/dissem/bitmessage/demo/Main.java b/demo/src/main/java/ch/dissem/bitmessage/demo/Main.java index c0c433d..37b58e1 100644 --- a/demo/src/main/java/ch/dissem/bitmessage/demo/Main.java +++ b/demo/src/main/java/ch/dissem/bitmessage/demo/Main.java @@ -20,8 +20,8 @@ import java.io.IOException; public class Main { public static void main(String[] args) throws IOException { -// System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "TRACE"); -// System.setProperty("org.slf4j.simpleLogger.logFile", "./trace.log"); + System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "DEBUG"); + System.setProperty("org.slf4j.simpleLogger.logFile", "./jabit.log"); new Application(); } }