Added some improvements to the demo application
This commit is contained in:
parent
b40d2e9f73
commit
fe93c95f40
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,5 +1,7 @@
|
|||||||
# Created by https://www.gitignore.io
|
# Created by https://www.gitignore.io
|
||||||
|
|
||||||
|
*.log
|
||||||
|
|
||||||
### Gradle ###
|
### Gradle ###
|
||||||
.gradle
|
.gradle
|
||||||
build/
|
build/
|
||||||
@ -115,7 +117,8 @@ local.properties
|
|||||||
.LSOverride
|
.LSOverride
|
||||||
|
|
||||||
# Icon must end with two \r
|
# Icon must end with two \r
|
||||||
Icon
|
Icon
|
||||||
|
|
||||||
|
|
||||||
# Thumbnails
|
# Thumbnails
|
||||||
._*
|
._*
|
||||||
|
@ -150,7 +150,7 @@ public class Application {
|
|||||||
System.out.println();
|
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);
|
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");
|
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) {
|
if (alias.length() > 0) {
|
||||||
identity.setAlias(alias);
|
identity.setAlias(alias);
|
||||||
}
|
}
|
||||||
@ -346,19 +346,30 @@ public class Application {
|
|||||||
private void compose(boolean broadcast) {
|
private void compose(boolean broadcast) {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
BitmessageAddress from = selectAddress(true);
|
BitmessageAddress from = selectAddress(true);
|
||||||
|
if (from == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
BitmessageAddress to = (broadcast ? null : selectAddress(false));
|
BitmessageAddress to = (broadcast ? null : selectAddress(false));
|
||||||
|
if (!broadcast && to == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
compose(from, to, null);
|
compose(from, to, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BitmessageAddress selectAddress(boolean id) {
|
private BitmessageAddress selectAddress(boolean id) {
|
||||||
List<BitmessageAddress> identities = (id ? ctx.addresses().getIdentities() : ctx.addresses().getContacts());
|
List<BitmessageAddress> addresses = (id ? ctx.addresses().getIdentities() : ctx.addresses().getContacts());
|
||||||
while (identities.size() == 0) {
|
while (addresses.size() == 0) {
|
||||||
addIdentity();
|
if (id) {
|
||||||
identities = ctx.addresses().getIdentities();
|
addIdentity();
|
||||||
|
addresses = ctx.addresses().getIdentities();
|
||||||
|
} else {
|
||||||
|
addContact(false);
|
||||||
|
addresses = ctx.addresses().getContacts();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (identities.size() == 1) {
|
if (addresses.size() == 1) {
|
||||||
return identities.get(0);
|
return addresses.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
String command;
|
String command;
|
||||||
@ -371,7 +382,7 @@ public class Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (BitmessageAddress identity : identities) {
|
for (BitmessageAddress identity : addresses) {
|
||||||
i++;
|
i++;
|
||||||
System.out.print(i + ") ");
|
System.out.print(i + ") ");
|
||||||
if (identity.getAlias() != null) {
|
if (identity.getAlias() != null) {
|
||||||
@ -389,8 +400,8 @@ public class Application {
|
|||||||
default:
|
default:
|
||||||
try {
|
try {
|
||||||
int index = Integer.parseInt(command) - 1;
|
int index = Integer.parseInt(command) - 1;
|
||||||
if (identities.get(index) != null) {
|
if (addresses.get(index) != null) {
|
||||||
return identities.get(index);
|
return addresses.get(index);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
System.out.println("Unknown command. Please try again.");
|
System.out.println("Unknown command. Please try again.");
|
||||||
@ -411,13 +422,13 @@ public class Application {
|
|||||||
System.out.println("Subject: " + subject);
|
System.out.println("Subject: " + subject);
|
||||||
} else {
|
} else {
|
||||||
System.out.print("Subject: ");
|
System.out.print("Subject: ");
|
||||||
subject = nextCommand();
|
subject = scanner.nextLine().trim();
|
||||||
}
|
}
|
||||||
System.out.println("Message:");
|
System.out.println("Message:");
|
||||||
StringBuilder message = new StringBuilder();
|
StringBuilder message = new StringBuilder();
|
||||||
String line;
|
String line;
|
||||||
do {
|
do {
|
||||||
line = nextCommand();
|
line = scanner.nextLine();
|
||||||
message.append(line).append('\n');
|
message.append(line).append('\n');
|
||||||
} while (line.length() > 0 || !yesNo("Send message?"));
|
} while (line.length() > 0 || !yesNo("Send message?"));
|
||||||
if (broadcast) {
|
if (broadcast) {
|
||||||
|
@ -20,8 +20,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
// System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "TRACE");
|
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "DEBUG");
|
||||||
// System.setProperty("org.slf4j.simpleLogger.logFile", "./trace.log");
|
System.setProperty("org.slf4j.simpleLogger.logFile", "./jabit.log");
|
||||||
new Application();
|
new Application();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user