diff --git a/android/assets/skin/uiskin.json b/android/assets/skin/uiskin.json index e8838ea..ecfe55b 100644 --- a/android/assets/skin/uiskin.json +++ b/android/assets/skin/uiskin.json @@ -50,6 +50,8 @@ com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle: { com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: { default: { font: default-font, fontColor: white } redlabel: { font: default-font, fontColor: red } + bluelabel: { font: default-font, fontColor: blue } + greenlabel: { font: default-font, fontColor: green } }, com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle: { default: { selection: selection, background: textfield, font: default-font, fontColor: white, cursor: cursor } diff --git a/core/src/com/jw/lightwallet/LightWallet.java b/core/src/com/jw/lightwallet/LightWallet.java index d4f64b2..cb8fe55 100644 --- a/core/src/com/jw/lightwallet/LightWallet.java +++ b/core/src/com/jw/lightwallet/LightWallet.java @@ -7,7 +7,7 @@ import java.io.IOException; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; -import com.jw.lightwallet.screens.MainScreen; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.jw.lightwallet.screens.PasswordScreen; import com.jw.lightwallet.screens.WizardScreen; import com.jw.lightwallet.utils.WalletValues; @@ -15,6 +15,7 @@ import com.jw.lightwallet.utils.WalletValues; public class LightWallet extends Game { public static final String LOG = LightWallet.class.getSimpleName(); // Logging constant + public Skin uiSkin; public String dir; public String os; @@ -37,8 +38,9 @@ public class LightWallet extends Game { System.out.println(simplewalletloc); } - // Initialize logger + // Initialize logger and user interface skin Gdx.app.log(LightWallet.LOG, "Launching application in " + dir + " on " + os); + uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json")); // Check if config file exists, if not launch setup wizard File f = new File("lightwallet.conf"); diff --git a/core/src/com/jw/lightwallet/screens/CreateScreen.java b/core/src/com/jw/lightwallet/screens/CreateScreen.java index 30d226a..805a436 100644 --- a/core/src/com/jw/lightwallet/screens/CreateScreen.java +++ b/core/src/com/jw/lightwallet/screens/CreateScreen.java @@ -248,7 +248,7 @@ public class CreateScreen extends AbstractScreen { confwriter.close(); PrintWriter txwriter = new PrintWriter(name + "tx.txt", "UTF-8"); - txwriter.println("Transaction history: "); + txwriter.println("Transaction history (Type | Amount | Tx ID): "); txwriter.close(); success_dialog.show(stage); diff --git a/core/src/com/jw/lightwallet/screens/DaemonView.java b/core/src/com/jw/lightwallet/screens/DaemonView.java index ffcca91..8f7df9c 100644 --- a/core/src/com/jw/lightwallet/screens/DaemonView.java +++ b/core/src/com/jw/lightwallet/screens/DaemonView.java @@ -2,6 +2,7 @@ package com.jw.lightwallet.screens; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.jw.lightwallet.LightWallet; @@ -13,6 +14,8 @@ public class DaemonView { LightWallet game; + Skin uiSkin; + Table daemonlayout; Label nodelabel; @@ -35,7 +38,7 @@ public class DaemonView { this.game = game; - Skin uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json")); + uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json")); daemonlayout = new Table(); padvalue = 15; @@ -70,11 +73,15 @@ public class DaemonView { rewardvalue = new Label(null, uiSkin); daemonlayout.add(rewardlabel).pad(padvalue); daemonlayout.add(rewardvalue).pad(padvalue).row(); + + daemonlayout.add(new Label("", uiSkin)).fill().expand(); } public void Update(DaemonValues daemonvalues) { nodevalue.setText(game.walletvalues.getNode()); statusvalue.setText(daemonvalues.getStatus()); + Gdx.app.log(LightWallet.LOG, "Status value is: " + statusvalue.getText()); + if (statusvalue.getText().toString().equals("OK")) {statusvalue.setStyle(uiSkin.get("greenlabel", LabelStyle.class));} heightvalue.setText(String.valueOf(daemonvalues.getBlockheight())); hashratevalue.setText(new DecimalFormat("##.##").format(daemonvalues.getHashrate()) + " Mh/s"); timevalue.setText(String.valueOf(new java.util.Date(daemonvalues.getLastblocktime()*1000))); diff --git a/core/src/com/jw/lightwallet/screens/HistoryView.java b/core/src/com/jw/lightwallet/screens/HistoryView.java index 4614687..607d02b 100644 --- a/core/src/com/jw/lightwallet/screens/HistoryView.java +++ b/core/src/com/jw/lightwallet/screens/HistoryView.java @@ -1,5 +1,49 @@ package com.jw.lightwallet.screens; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.scenes.scene2d.ui.Table; + public class HistoryView { + + Table historylayout; + + ScrollPane scroller; + Table container; + + int padvalue; + + + public HistoryView () { + + Skin uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json")); + + historylayout = new Table(); + padvalue = 15; + + container = new Table(); + scroller = new ScrollPane(container, uiSkin); + + + historylayout.add(new Label("Transaction history (click to copy txid)", uiSkin)).row(); + historylayout.add(new Label("Type | Amount | Transaction ID", uiSkin)).row(); + historylayout.add(scroller).fill().expand(); + + + } + + + public Table getContainer() { + return container; + } + + + public void setContainer(Table container) { + this.container = container; + } + + } diff --git a/core/src/com/jw/lightwallet/screens/ImportKeysScreen.java b/core/src/com/jw/lightwallet/screens/ImportKeysScreen.java index ce6d495..cea27b8 100644 --- a/core/src/com/jw/lightwallet/screens/ImportKeysScreen.java +++ b/core/src/com/jw/lightwallet/screens/ImportKeysScreen.java @@ -279,7 +279,7 @@ public class ImportKeysScreen extends AbstractScreen { confwriter.close(); PrintWriter txwriter = new PrintWriter(name + "tx.txt", "UTF-8"); - txwriter.println("Transaction history: "); + txwriter.println("Transaction history (Type | Amount | Tx ID): "); txwriter.close(); successlabel.setText("Wallet successfully imported. " + game.walletvalues.getName() + " file is your binary wallet file. " diff --git a/core/src/com/jw/lightwallet/screens/MainScreen.java b/core/src/com/jw/lightwallet/screens/MainScreen.java index bac0185..56ac0a7 100644 --- a/core/src/com/jw/lightwallet/screens/MainScreen.java +++ b/core/src/com/jw/lightwallet/screens/MainScreen.java @@ -2,6 +2,7 @@ package com.jw.lightwallet.screens; import java.io.BufferedReader; import java.io.BufferedWriter; +import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; @@ -12,13 +13,13 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.ui.Button; import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.AtomicQueue; -import com.badlogic.gdx.utils.Timer; import com.jw.lightwallet.LightWallet; import com.jw.lightwallet.daemon.DaemonRPC; import com.jw.lightwallet.utils.BalanceValues; @@ -69,7 +70,10 @@ public class MainScreen extends AbstractScreen { Process wp; BufferedReader wr; AtomicQueue wq; + + // Transaction processing stuff ArrayList txlist; + int txcount; public MainScreen(final LightWallet game) { @@ -77,6 +81,7 @@ public class MainScreen extends AbstractScreen { wq = new AtomicQueue(1000); txlist = new ArrayList(); + txcount = 0; Skin uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json")); @@ -104,7 +109,7 @@ public class MainScreen extends AbstractScreen { public void clicked (InputEvent event, float x, float y) { System.out.println("Daemon button Pressed"); viewcontainer.removeActor(viewcontainer.getChildren().get(0)); - viewcontainer.add(daemonview.daemonlayout).expand().bottom(); + viewcontainer.add(daemonview.daemonlayout); } }); walletbutton = new TextButton("Wallet", uiSkin); @@ -113,7 +118,7 @@ public class MainScreen extends AbstractScreen { public void clicked (InputEvent event, float x, float y) { System.out.println("Wallet button Pressed"); viewcontainer.removeActor(viewcontainer.getChildren().get(0)); - viewcontainer.add(walletview.walletlayout).expand().bottom(); + viewcontainer.add(walletview.walletlayout); } }); transferbutton = new TextButton("Transfer", uiSkin); @@ -122,7 +127,7 @@ public class MainScreen extends AbstractScreen { public void clicked (InputEvent event, float x, float y) { System.out.println("Transfer button Pressed"); viewcontainer.removeActor(viewcontainer.getChildren().get(0)); - viewcontainer.add(transactionview.txlayout).expand().bottom(); + viewcontainer.add(transactionview.txlayout); } }); txhistorybutton = new TextButton("History", uiSkin); @@ -131,7 +136,7 @@ public class MainScreen extends AbstractScreen { public void clicked (InputEvent event, float x, float y) { System.out.println("History button Pressed"); viewcontainer.removeActor(viewcontainer.getChildren().get(0)); - viewcontainer.add(transactionview.txlayout).expand().bottom(); + viewcontainer.add(historyview.historylayout); } }); @@ -139,7 +144,7 @@ public class MainScreen extends AbstractScreen { buttonrow.add(walletbutton).width(Constants.WORLD_WIDTH/4); buttonrow.add(transferbutton).width(Constants.WORLD_WIDTH/4); buttonrow.add(txhistorybutton).width(Constants.WORLD_WIDTH/4); - screenlayout.add(buttonrow).row(); + screenlayout.add(buttonrow).top().row(); screenlayout.add(logo).pad(10).center().row(); @@ -268,6 +273,8 @@ public class MainScreen extends AbstractScreen { } else if (queuepoll != null && queuepoll.contains("money")) { txlist.add(Tx.StringToTx(queuepoll)); + // Gdx.app.log(LightWallet.LOG, "Found tx: " + txlist.get(txlist.size()-1).txid + + // " of type " + txlist.get(txlist.size()-1).type + " and amount " + txlist.get(txlist.size()-1).amount); } } catch (NullPointerException e){e.printStackTrace();} } @@ -278,7 +285,7 @@ public class MainScreen extends AbstractScreen { Tx temptx = new Tx(); // Cycle through list of transactions from queue in last 60 s if (txlist.size() > 0) { - for (int i = 0; i <= txlist.size(); i++) { + for (int i = 0; i < txlist.size(); i++) { // If newtx flag then create a new temporary tx if (newtx == true) { temptx = new Tx(); @@ -290,11 +297,11 @@ public class MainScreen extends AbstractScreen { else if (newtx = false) { temptx.amount += txlist.get(i).amount; } - + newtx = false; // Change flag then run check in next if statement // If the next tx is different or at the end of list, write current one to file and set flag - if ((i < txlist.size()-1 && - (txlist.get(i).txid != txlist.get(i+1).txid || txlist.get(i).type != txlist.get(i+1).type)) - || i == txlist.size()-1) { + if (i < txlist.size()-1 && + (!(txlist.get(i).txid.equals(txlist.get(i+1).txid)) || !(txlist.get(i).type.equals(txlist.get(i+1).type)) + || i == txlist.size()-1)) { PrintWriter txout; try { txout = new PrintWriter(new BufferedWriter(new FileWriter(game.walletvalues.getName() + "tx.txt", true))); @@ -306,10 +313,41 @@ public class MainScreen extends AbstractScreen { } newtx = true; } - } + + // Clear tx list so don't rewrite same txs + txlist.clear(); } + // Read lines from tx file into history view and make buttons + try (BufferedReader br = new BufferedReader(new FileReader(game.walletvalues.getName() + "tx.txt"))) { + + String line; + int linenum = 0; + while ((line = br.readLine()) != null) { + + System.out.println(linenum + ": " + line); + + if (linenum > 0) { + if (txcount < linenum) { + final TextButton tmpbtn = new TextButton(line, game.uiSkin); + tmpbtn.addListener(new ClickListener() { + @Override + public void clicked (InputEvent event, float x, float y) { + // Gdx.app.getClipboard().setContents(((String) tmpbtn.getText()).split(" | ")[2]); + Gdx.app.getClipboard().setContents(tmpbtn.getText().toString()); + } + }); + historyview.getContainer().add(tmpbtn).row(); + } + } + + linenum += 1; + } + + } catch (IOException e) { + e.printStackTrace(); + } } } diff --git a/core/src/com/jw/lightwallet/screens/TransactionView.java b/core/src/com/jw/lightwallet/screens/TransactionView.java index ec1ce40..596d274 100644 --- a/core/src/com/jw/lightwallet/screens/TransactionView.java +++ b/core/src/com/jw/lightwallet/screens/TransactionView.java @@ -6,7 +6,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextField; -import com.jw.lightwallet.LightWallet; public class TransactionView { @@ -54,7 +53,7 @@ public class TransactionView { txlayout.add(idvalue).pad(padvalue).width(600).row(); sendbtn = new TextButton("Payola!", uiSkin); - txlayout.add(sendbtn).row(); + txlayout.add(sendbtn).fill().expand().row(); } diff --git a/core/src/com/jw/lightwallet/screens/WalletView.java b/core/src/com/jw/lightwallet/screens/WalletView.java index b5c5fcb..4a8aec8 100644 --- a/core/src/com/jw/lightwallet/screens/WalletView.java +++ b/core/src/com/jw/lightwallet/screens/WalletView.java @@ -30,42 +30,40 @@ public class WalletView { public WalletView (final LightWallet game) { - - Skin uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json")); - + walletlayout = new Table(); padvalue = 16; - namelabel = new Label("Name: ", uiSkin); - namevalue = new Label(game.walletvalues.getName(), uiSkin); + namelabel = new Label("Name: ", game.uiSkin); + namevalue = new Label(game.walletvalues.getName(), game.uiSkin); walletlayout.add(namelabel).pad(padvalue); walletlayout.add(namevalue).pad(padvalue).row(); - addresslabel = new TextButton("Address (click to copy): ", uiSkin); - addressvalue = new Label(game.walletvalues.getAddress(), uiSkin); + addresslabel = new TextButton("Address (click to copy): ", game.uiSkin); + addressvalue = new Label(game.walletvalues.getAddress(), game.uiSkin); addressvalue.setFontScale(0.6f, 0.6f); walletlayout.add(addresslabel).pad(padvalue); walletlayout.add(addressvalue).pad(padvalue).row(); - synclabel = new Label("Wallet sync: ", uiSkin); - syncvalue = new Label("0 / A lot", uiSkin, "redlabel"); + synclabel = new Label("Wallet sync: ", game.uiSkin); + syncvalue = new Label("0 / A lot", game.uiSkin, "redlabel"); walletlayout.add(synclabel).pad(padvalue); walletlayout.add(syncvalue).pad(padvalue).row(); - unlockedlabel = new Label("Unlocked balance: ", uiSkin); - unlockedvalue = new Label("Loading...", uiSkin, "redlabel"); + unlockedlabel = new Label("Unlocked balance: ", game.uiSkin); + unlockedvalue = new Label("Loading...", game.uiSkin, "redlabel"); walletlayout.add(unlockedlabel).pad(padvalue); walletlayout.add(unlockedvalue).pad(padvalue).row(); - lockedlabel = new Label("Locked balance: ", uiSkin); - lockedvalue = new Label("Loading...", uiSkin, "redlabel"); + lockedlabel = new Label("Locked balance: ", game.uiSkin); + lockedvalue = new Label("Loading...", game.uiSkin, "redlabel"); walletlayout.add(lockedlabel).pad(padvalue); walletlayout.add(lockedvalue).pad(padvalue).row(); - savewalletbtn = new TextButton("Save wallet\n(will attempt autosave every 60 s)", uiSkin); - savewalletlabel = new Label("Not saved :(", uiSkin, "redlabel"); + savewalletbtn = new TextButton("Save wallet\n(will attempt autosave every 60 s)", game.uiSkin); + savewalletlabel = new Label("Not saved :(", game.uiSkin, "redlabel"); walletlayout.add(savewalletbtn); - walletlayout.add(savewalletlabel); + walletlayout.add(savewalletlabel).fill().expand(); addresslabel.addListener(new ClickListener() { @Override diff --git a/core/src/com/jw/lightwallet/utils/Tx.java b/core/src/com/jw/lightwallet/utils/Tx.java index bbf8f32..0291bdd 100644 --- a/core/src/com/jw/lightwallet/utils/Tx.java +++ b/core/src/com/jw/lightwallet/utils/Tx.java @@ -19,7 +19,7 @@ public class Tx { Tx tx = new Tx(); // Get tx type - if (txstring.split(" money")[0].split(" ")[2] == "Received") { + if (txstring.split(" money")[0].split(" ")[2].equals("Received")) { tx.type = Type.RECEIVED; } else {tx.type = Type.SPENT;} @@ -33,5 +33,30 @@ public class Tx { return tx; } + + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } + + public long getAmount() { + return amount; + } + + public void setAmount(long amount) { + this.amount = amount; + } + + public String getTxid() { + return txid; + } + + public void setTxid(String txid) { + this.txid = txid; + } + }