update wallet

Added wallet api, updated wallet process
This commit is contained in:
GME 2019-04-11 19:38:23 +02:00
parent 40309edc95
commit 873b93a788
14 changed files with 331 additions and 157 deletions

View file

@ -9,14 +9,10 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
import com.example.monnthic.monnethicmobile.R; import com.example.monnthic.monnethicmobile.R;
import org.json.JSONObject; import org.json.JSONObject;
import monnethic.mobile.restApi.Config; import monnethic.mobile.restApi.Config;
import monnethic.mobile.restApi.HttpCallHandler; import monnethic.mobile.restApi.HttpCallHandler;
import monnethic.mobile.user.UserAccountActivity;
import monnethic.mobile.wallet.HomeWalletActivity; import monnethic.mobile.wallet.HomeWalletActivity;
public class LoginActivity extends AppCompatActivity { public class LoginActivity extends AppCompatActivity {
@ -27,7 +23,6 @@ public class LoginActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login); setContentView(R.layout.activity_login);
email = findViewById(R.id.editTextEmail); email = findViewById(R.id.editTextEmail);
password = findViewById(R.id.editTextPassword); password = findViewById(R.id.editTextPassword);
Button buttonCancel = findViewById(R.id.buttonCancel); Button buttonCancel = findViewById(R.id.buttonCancel);
@ -82,9 +77,8 @@ public class LoginActivity extends AppCompatActivity {
try{ try{
if(result!=null){ if(result!=null){
if(result.getInt("status") == 200){ if(result.getInt("status") == 200){
//Intent accountIntent = new Intent(LoginActivity.this, UserAccountActivity.class);
Intent walletHomeIntent = new Intent(LoginActivity.this, HomeWalletActivity.class); Intent walletHomeIntent = new Intent(LoginActivity.this, HomeWalletActivity.class);
walletHomeIntent.putExtra("USER_HASH", result.getString("userHash")); walletHomeIntent.putExtra("USER_HASH", result.getString("user_hash"));
walletHomeIntent.putExtra("USER_PWD",password.getText().toString()); walletHomeIntent.putExtra("USER_PWD",password.getText().toString());
walletHomeIntent.putExtra("SESSION_ID","0"); walletHomeIntent.putExtra("SESSION_ID","0");
LoginActivity.this.startActivity(walletHomeIntent); LoginActivity.this.startActivity(walletHomeIntent);
@ -104,7 +98,7 @@ public class LoginActivity extends AppCompatActivity {
try{ try{
String url = Config.USER_LOGIN; String url = Config.USER_LOGIN;
String[] paramsList = {params[0],params[1]}; String[] paramsList = {params[0],params[1]};
HttpCallHandler httpCallHandler = new HttpCallHandler(); HttpCallHandler httpCallHandler = new HttpCallHandler(); //TODO UserApiHandler
return new JSONObject(httpCallHandler.executeLoginHttp(url,paramsList)); return new JSONObject(httpCallHandler.executeLoginHttp(url,paramsList));
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
@ -113,4 +107,10 @@ public class LoginActivity extends AppCompatActivity {
} }
} }
@Override
protected void onStop() {
super.onStop(); // Always call the superclass method first
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
}
} }

View file

@ -32,10 +32,10 @@ public class QrCodeActivity extends AppCompatActivity {
amountView=findViewById(R.id.textViewAmountDisplay); amountView=findViewById(R.id.textViewAmountDisplay);
Intent intent = getIntent(); Intent intent = getIntent();
String adresse = intent.getStringExtra("adresse"); String wallet_hash = intent.getStringExtra("WALLET_HASH");
String value = intent.getStringExtra("value"); String amount = intent.getStringExtra("AMOUNT");
try{ try{
generateQrCode(adresse,value); generateQrCode(wallet_hash,amount);
}catch(Exception e){ }catch(Exception e){
e.getMessage(); e.getMessage();
} }
@ -47,16 +47,16 @@ public class QrCodeActivity extends AppCompatActivity {
}); });
} }
private void generateQrCode(String adresse, String value) throws WriterException { private void generateQrCode(String wallet_hash, String amount) throws WriterException {
BitMatrix bitMatrix; BitMatrix bitMatrix;
String valueToEncode = adresse+";"+value; String valueToEncode = wallet_hash+";"+amount;
try{ try{
bitMatrix = new MultiFormatWriter().encode(valueToEncode, BarcodeFormat.QR_CODE,350,350); bitMatrix = new MultiFormatWriter().encode(valueToEncode, BarcodeFormat.QR_CODE,350,350);
BarcodeEncoder barcodeEncoder = new BarcodeEncoder(); BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix); Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
qrCode.setImageBitmap(bitmap); qrCode.setImageBitmap(bitmap);
adresseView.setText(adresse); adresseView.setText(wallet_hash);
amountView.setText(value); amountView.setText(amount);
}catch (Exception e){ }catch (Exception e){
e.getMessage(); e.getMessage();
} }

View file

@ -83,8 +83,9 @@ public class QrCodeScannerActivity extends AppCompatActivity {
intentData = barcodes.valueAt(0).displayValue; intentData = barcodes.valueAt(0).displayValue;
Intent scannedQrIntent = new Intent(QrCodeScannerActivity.this, ApprovePayementActivity.class); Intent scannedQrIntent = new Intent(QrCodeScannerActivity.this, ApprovePayementActivity.class);
scannedQrIntent.putExtra("valueScanned",intentData); scannedQrIntent.putExtra("valueScanned",intentData);
//TODO INTENT
QrCodeScannerActivity.this.startActivity(scannedQrIntent); QrCodeScannerActivity.this.startActivity(scannedQrIntent);
finish();
} }
} }
}); });
@ -101,4 +102,10 @@ public class QrCodeScannerActivity extends AppCompatActivity {
super.onResume(); super.onResume();
initialiseDetector(); initialiseDetector();
} }
@Override
protected void onStop() {
super.onStop(); // Always call the superclass method first
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
}
} }

View file

@ -28,9 +28,4 @@ public class Config {
static public String WALLET_DELETE = BASE_URL_WALLET+"delete"; static public String WALLET_DELETE = BASE_URL_WALLET+"delete";
static public String WALLET_TRANSFER = BASE_URL_WALLET+"transfer"; static public String WALLET_TRANSFER = BASE_URL_WALLET+"transfer";
//BLOCKCHAIN
static private String BASE_URL_QUERY = BASE_URL+"/api/rest/query/";
static public String QUERY_BALANCE = BASE_URL_QUERY+"/balance?userHash=";
} }

View file

@ -9,6 +9,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.Map;
import monnethic.mobile.database.User; import monnethic.mobile.database.User;
@ -44,96 +45,51 @@ public class HttpCallHandler {
} }
public String executeGetHttp(String urlParam, String[] params){ public String postHttp(URL url, Map<String,String> params) throws Exception {
InputStream inputStream; String returnValue=null;
BufferedReader bufferedReader = null;
HttpURLConnection urlConnection = null; HttpURLConnection urlConnection = null;
try{
URL url = new URL(urlParam);
urlConnection = (HttpURLConnection) url.openConnection(); urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET"); urlConnection.setRequestMethod("POST");
urlConnection.connect(); urlConnection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
urlConnection.setRequestProperty("Accept","application/json");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
int response = urlConnection.getResponseCode(); JSONObject jsonParam = new JSONObject();
if(response != 200){ for(Map.Entry<String,String> pair : params.entrySet()){
System.out.println("Error response"); jsonParam.put(pair.getKey(),pair.getValue());
}
inputStream = urlConnection.getInputStream();
if(inputStream == null){
System.out.println("Error inputStream");
} }
DataOutputStream os = new DataOutputStream(urlConnection.getOutputStream());
os.writeBytes(jsonParam.toString());
int statusCode = urlConnection.getResponseCode();
if(statusCode != 200){
JSONObject jsonReturn = new JSONObject();
if(statusCode == 404){
jsonReturn.put("status",404);
jsonReturn.put("response","Not Found");
returnValue = jsonReturn.toString();
}else if(statusCode == 403){
jsonReturn.put("status",403);
jsonReturn.put("response","Forbidden");
returnValue = jsonReturn.toString();
}
} else {
BufferedReader bufferedReader = null;
bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine())!=null){
stringBuilder.append(line);
}
return stringBuilder.toString();
}catch (Exception e){
e.printStackTrace();
return null;
} finally {
if(urlConnection != null){
urlConnection.disconnect();
}
if(bufferedReader != null){
try {
bufferedReader.close();
}catch (IOException e){
e.printStackTrace();
}
}
}
}
public String executeGetBalance(String urlParam){
BufferedReader bufferedReader = null;
HttpURLConnection connection = null;
String res = null;
try{
URL url = new URL(urlParam);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int statusCode = connection.getResponseCode();
if(statusCode != 200){
return null;
}else {
bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder stringBuilder = new StringBuilder();
String line; String line;
while ((line = bufferedReader.readLine())!=null){ while ((line = bufferedReader.readLine())!=null){
stringBuilder.append(line); stringBuilder.append(line);
} }
JSONObject jsonSuccess = new JSONObject(stringBuilder.toString()); returnValue = stringBuilder.toString();
jsonSuccess.put("status",200);
res = jsonSuccess.toString();
}
return res;
}catch (Exception e){
e.printStackTrace();
return null;
} finally {
if(connection!=null){
connection.disconnect();
}
if(bufferedReader != null){
try{
bufferedReader.close();
}catch (IOException e){
e.printStackTrace();
}
}
} }
return returnValue;
} }
public String executeLoginHttp(String urlParam, String[] params){ public String executeLoginHttp(String urlParam, String[] params){
BufferedReader bufferedReader = null; BufferedReader bufferedReader = null;
HttpURLConnection connection = null; HttpURLConnection connection = null;

View file

@ -5,6 +5,8 @@ import org.json.JSONObject;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import monnethic.mobile.wallet.Wallet; import monnethic.mobile.wallet.Wallet;
@ -14,7 +16,7 @@ public class WalletApiHandler {
ArrayList<Wallet> walletList = new ArrayList<>(); ArrayList<Wallet> walletList = new ArrayList<>();
HttpCallHandler httpCallHandler = new HttpCallHandler(); HttpCallHandler httpCallHandler = new HttpCallHandler();
try { try {
String url = Config.WALLET_GET_USER_WALLETS+"?userHash="+params[0]; String url = Config.WALLET_GET_USER_WALLETS+"?user_hash="+params[0];
String responseCall = httpCallHandler.getHttp(new URL(url)); String responseCall = httpCallHandler.getHttp(new URL(url));
JSONArray jsonArray = new JSONArray(responseCall); JSONArray jsonArray = new JSONArray(responseCall);
@ -26,7 +28,7 @@ public class WalletApiHandler {
wallet.setWallet_hash(jsonObject.getJSONObject("Record").getJSONObject("id").getString("string")); wallet.setWallet_hash(jsonObject.getJSONObject("Record").getJSONObject("id").getString("string"));
wallet.setUser_hash(jsonObject.getJSONObject("Record").getJSONObject("owner").getString("string")); wallet.setUser_hash(jsonObject.getJSONObject("Record").getJSONObject("owner").getString("string"));
String urlGetWallet = Config.WALLET_GET_WALLET+"?walletHash="+wallet.getWallet_hash(); String urlGetWallet = Config.WALLET_GET_WALLET+"?wallet_hash="+wallet.getWallet_hash();
String responseWallet = httpCallHandler.getHttp(new URL(urlGetWallet)); String responseWallet = httpCallHandler.getHttp(new URL(urlGetWallet));
JSONObject jsonWallet = new JSONObject(responseWallet); JSONObject jsonWallet = new JSONObject(responseWallet);
@ -36,7 +38,40 @@ public class WalletApiHandler {
} catch (Exception e){ } catch (Exception e){
e.printStackTrace(); e.printStackTrace();
} }
return walletList; return walletList;
} }
public Double getWalletBalance(String [] params){
HttpCallHandler httpCallHandler = new HttpCallHandler();
try{
String url = Config.WALLET_GET_WALLET+"?wallet_hash="+params[0];
String responseCall = httpCallHandler.getHttp(new URL(url));
JSONObject jsonObject = new JSONObject(responseCall);
return jsonObject.getDouble("balance");
}catch (Exception e){
e.printStackTrace();
}
return null;
}
public Wallet createWallet(Wallet wallet){
HttpCallHandler httpCallHandler = new HttpCallHandler();
try {
String url = Config.WALLET_CREATE;
Map<String, String> map = new HashMap<>();
map.put("user_hash",wallet.getUser_hash());
map.put("type",wallet.getType());
String responseCall = httpCallHandler.postHttp(new URL(url), map);
JSONObject jsonObject = new JSONObject(responseCall);
wallet.setWallet_hash(jsonObject.getString("wallet_hash"));
wallet.setBalance(jsonObject.getDouble("balance"));
return wallet;
} catch (Exception e){
e.printStackTrace();
}
return null;
}
} }

View file

@ -5,6 +5,7 @@ import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.Toast;
import com.example.monnthic.monnethicmobile.R; import com.example.monnthic.monnethicmobile.R;
@ -12,24 +13,58 @@ import monnethic.mobile.qrcode.QrCodeScannerActivity;
public class MakePayementActivity extends AppCompatActivity { public class MakePayementActivity extends AppCompatActivity {
Button btnScanQr; Button btnScanQr;
Button btnSendWithAddress;
private String user_hash;
private String user_password;
private String session_id;
private String wallet_hash;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_make_payement); setContentView(R.layout.activity_make_payement);
Intent intent = getIntent();
user_hash = intent.getStringExtra("USER_HASH");
user_password = intent.getStringExtra("USER_PWD");
session_id = intent.getStringExtra("SESSION_ID");
wallet_hash = intent.getStringExtra("WALLET_HASH");
initViews(); initViews();
} }
private void initViews(){ private void initViews(){
btnScanQr = findViewById(R.id.buttonScanQr); btnScanQr = findViewById(R.id.buttonScanQr);
btnSendWithAddress = findViewById(R.id.buttonSendWithAddress);
btnScanQr.setOnClickListener(new View.OnClickListener() { btnScanQr.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Intent payementIntent = new Intent(MakePayementActivity.this, QrCodeScannerActivity.class); Intent payementIntent = new Intent(MakePayementActivity.this, QrCodeScannerActivity.class);
payementIntent.putExtra("USER_HASH",user_hash);
payementIntent.putExtra("USER_PDW",user_password);
payementIntent.putExtra("WALLET_HASH",wallet_hash);
payementIntent.putExtra("SESSION_ID",session_id);
MakePayementActivity.this.startActivity(payementIntent);
}
});
btnSendWithAddress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent payementIntent = new Intent(MakePayementActivity.this, TransactionActivity.class);
payementIntent.putExtra("USER_HASH",user_hash);
payementIntent.putExtra("USER_PDW",user_password);
payementIntent.putExtra("WALLET_HASH",wallet_hash);
payementIntent.putExtra("SESSION_ID",session_id);
MakePayementActivity.this.startActivity(payementIntent); MakePayementActivity.this.startActivity(payementIntent);
} }
}); });
} }
@Override
protected void onStop() {
super.onStop(); // Always call the superclass method first
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
}
} }

View file

@ -6,6 +6,7 @@ import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast;
import com.example.monnthic.monnethicmobile.R; import com.example.monnthic.monnethicmobile.R;
@ -16,6 +17,11 @@ public class ReceivePayementActivity extends AppCompatActivity {
Button validateButton; Button validateButton;
EditText amountValueEdit; EditText amountValueEdit;
private String user_hash;
private String user_password;
private String session_id;
private String wallet_hash;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -24,6 +30,12 @@ public class ReceivePayementActivity extends AppCompatActivity {
validateButton=findViewById(R.id.buttonValidate); validateButton=findViewById(R.id.buttonValidate);
amountValueEdit=findViewById(R.id.amountValue); amountValueEdit=findViewById(R.id.amountValue);
Intent intent = getIntent();
user_hash = intent.getStringExtra("USER_HASH");
user_password = intent.getStringExtra("USER_PWD");
session_id = intent.getStringExtra("SESSION_ID");
wallet_hash = intent.getStringExtra("WALLET_HASH");
cancelButton.setOnClickListener(new View.OnClickListener() { cancelButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -38,10 +50,16 @@ public class ReceivePayementActivity extends AppCompatActivity {
}); });
} }
public void generateQrCodeWithValue(String value){ public void generateQrCodeWithValue(String amount){
Intent generateQrIntent = new Intent(ReceivePayementActivity.this, QrCodeActivity.class); Intent generateQrIntent = new Intent(ReceivePayementActivity.this, QrCodeActivity.class);
generateQrIntent.putExtra("adresse","addresseAAAA"); generateQrIntent.putExtra("WALLET_HASH",wallet_hash);
generateQrIntent.putExtra("value",value); generateQrIntent.putExtra("AMOUNT",amount);
ReceivePayementActivity.this.startActivity(generateQrIntent); ReceivePayementActivity.this.startActivity(generateQrIntent);
} }
@Override
protected void onStop() {
super.onStop(); // Always call the superclass method first
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
}
} }

View file

@ -13,21 +13,27 @@ import com.example.monnthic.monnethicmobile.R;
import java.math.BigInteger; import java.math.BigInteger;
public class TransactionActivity extends AppCompatActivity { public class TransactionActivity extends AppCompatActivity {
private String address; private String wallet_hash;
private String user_hash;
private String user_password;
private String session_id;
private EditText addressDestination; private EditText addressDestination;
private EditText amount; private EditText amountEditText;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transaction); setContentView(R.layout.activity_transaction);
addressDestination = findViewById(R.id.destination_address); addressDestination = findViewById(R.id.destination_address);
amount = findViewById(R.id.amount); amountEditText = findViewById(R.id.amount);
Button buttonCancel = findViewById(R.id.btn_cancel); Button buttonCancel = findViewById(R.id.btn_cancel);
Button buttonOk = findViewById(R.id.btn_send); Button buttonOk = findViewById(R.id.btn_send);
Intent intent = getIntent(); Intent intent = getIntent();
address = intent.getStringExtra("WALLET_ADDRESS"); user_hash = intent.getStringExtra("USER_HASH");
user_password = intent.getStringExtra("USER_PWD");
session_id = intent.getStringExtra("SESSION_ID");
wallet_hash = intent.getStringExtra("WALLET_HASH");
buttonCancel.setOnClickListener(new View.OnClickListener() { buttonCancel.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -45,15 +51,23 @@ public class TransactionActivity extends AppCompatActivity {
} }
public void sendTransaction(){ public void sendTransaction(){
String adD = addressDestination.getText().toString(); String wallet_dest = addressDestination.getText().toString();
BigInteger amt = new BigInteger(amount.getText().toString()); String amount = amountEditText.getText().toString();
/* /*
if(AccessBlockchain.sendTransationTo(address, adD, amt)){ if(AccessBlockchain.sendTransationTo(address, adD, amt)){
Toast.makeText(this, "OK.", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "OK.", Toast.LENGTH_SHORT).show();
} }
*/ */
String message = "Comming soon, addressDestination "+adD+" Amount : "+amt.toString(); String message = "Comming soon, addressDestination "+wallet_dest+" Amount : "+amount;
Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
finish();
}
@Override
protected void onStop() {
super.onStop(); // Always call the superclass method first
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
} }
} }

View file

@ -4,6 +4,7 @@ import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
@ -23,11 +24,16 @@ import java.net.URL;
import monnethic.mobile.database.User; import monnethic.mobile.database.User;
import monnethic.mobile.restApi.Config; import monnethic.mobile.restApi.Config;
import monnethic.mobile.restApi.HttpCallHandler; import monnethic.mobile.restApi.HttpCallHandler;
import monnethic.mobile.restApi.WalletApiHandler;
import monnethic.mobile.transaction.MakePayementActivity; import monnethic.mobile.transaction.MakePayementActivity;
import monnethic.mobile.transaction.ReceivePayementActivity; import monnethic.mobile.transaction.ReceivePayementActivity;
public class UserAccountActivity extends AppCompatActivity { public class UserAccountActivity extends AppCompatActivity {
private TextView balance; private TextView balance;
private String wallet_hash;
private String user_hash;
private String user_password;
private String session_id;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -39,9 +45,17 @@ public class UserAccountActivity extends AppCompatActivity {
Button buttonReceive = findViewById(R.id.buttonReceive); Button buttonReceive = findViewById(R.id.buttonReceive);
Button buttonSettings = findViewById(R.id.buttonSettings); Button buttonSettings = findViewById(R.id.buttonSettings);
Button buttonRefresh = findViewById(R.id.buttonRefreshBalance); Button buttonRefresh = findViewById(R.id.buttonRefreshBalance);
Intent intent = getIntent(); Intent intent = getIntent();
String userHash = intent.getStringExtra("userHash"); user_hash = intent.getStringExtra("USER_HASH");
userHashView.setText(userHash); user_password = intent.getStringExtra("USER_PWD");
session_id = intent.getStringExtra("SESSION_ID");
wallet_hash = intent.getStringExtra("WALLET_HASH");
String wallet_type = intent.getStringExtra("WALLET_TYPE");
String wallet_balance = intent.getStringExtra("WALLET_BALANCE");
userHashView.setText(wallet_hash);
balance.setText(wallet_balance);
buttonPayement.setOnClickListener(new View.OnClickListener() { buttonPayement.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -64,37 +78,40 @@ public class UserAccountActivity extends AppCompatActivity {
buttonRefresh.setOnClickListener(new View.OnClickListener() { buttonRefresh.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
refreshBalance("b"); new GetUserBalanceTask().execute(wallet_hash);
} }
}); });
String[] params = {userHash}; Log.i("UserAccountActivity", "user_hash : "+user_hash);
Log.i("UserAccountActivity", "user_password : "+user_password);
Log.i("UserAccountActivity", "session_id : "+session_id);
Log.i("UserAccountActivity", "wallet_hash : "+wallet_hash);
String[] params = {wallet_hash};
new GetUserBalanceTask().execute(params); new GetUserBalanceTask().execute(params);
} }
public void sendPayement(){ public void sendPayement(){
Intent payementIntent = new Intent(UserAccountActivity.this, MakePayementActivity.class); Intent payementIntent = new Intent(UserAccountActivity.this, MakePayementActivity.class);
payementIntent.putExtra("USER_HASH",user_hash);
payementIntent.putExtra("USER_PDW",user_password);
payementIntent.putExtra("WALLET_HASH",wallet_hash);
payementIntent.putExtra("SESSION_ID",session_id);
UserAccountActivity.this.startActivity(payementIntent); UserAccountActivity.this.startActivity(payementIntent);
} }
public void receivePayement(){ public void receivePayement(){
Intent receivePayementIntent = new Intent(UserAccountActivity.this, ReceivePayementActivity.class); Intent receivePayementIntent = new Intent(UserAccountActivity.this, ReceivePayementActivity.class);
receivePayementIntent.putExtra("USER_HASH",user_hash);
receivePayementIntent.putExtra("USER_PDW",user_password);
receivePayementIntent.putExtra("WALLET_HASH",wallet_hash);
receivePayementIntent.putExtra("SESSION_ID",session_id);
UserAccountActivity.this.startActivity(receivePayementIntent); UserAccountActivity.this.startActivity(receivePayementIntent);
} }
public void settings(){ public void settings(){
Toast.makeText(this, "Coming soon", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Coming soon", Toast.LENGTH_SHORT).show();
} }
public void refreshBalance(String userHash){ public class GetUserBalanceTask extends AsyncTask<String,String,Double>
String url = Config.QUERY_BALANCE+userHash;
new GetUserBalanceTask().execute(url);
}
public void setBalance(String value){
balance.setText(value);
}
public class GetUserBalanceTask extends AsyncTask<String,String,String>
{ {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
@ -102,32 +119,34 @@ public class UserAccountActivity extends AppCompatActivity {
} }
@Override @Override
protected void onPostExecute(String s) { protected void onPostExecute(Double b) {
if(s!=null){ if(b!=null){
balance.setText(s); balance.setText(String.valueOf(b));
}else{ }else{
balance.setText("0"); balance.setText("0");
} }
} }
@Override @Override
protected String doInBackground(String... params) { protected Double doInBackground(String... params) {
try{ try{
String url = Config.QUERY_BALANCE+params[0]; WalletApiHandler walletApiHandler = new WalletApiHandler();
HttpCallHandler httpCallHandler = new HttpCallHandler(); Double newBalance = walletApiHandler.getWalletBalance(params);
JSONObject json = new JSONObject(httpCallHandler.executeGetBalance(url)); if(newBalance!=null){
if(json.get("userBalance")!=null){ return newBalance;
Double balance = json.getDouble("userBalance");
return balance.toString();
}else{ }else{
return null; return null;
} }
} catch (Exception e){ } catch (Exception e){
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
} }
} }
@Override
protected void onStop() {
super.onStop(); // Always call the superclass method first
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
}
} }

View file

@ -1,15 +1,96 @@
package monnethic.mobile.wallet; package monnethic.mobile.wallet;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.monnthic.monnethicmobile.R; import com.example.monnthic.monnethicmobile.R;
import monnethic.mobile.restApi.WalletApiHandler;
import monnethic.mobile.user.UserAccountActivity;
public class CreateWalletActivity extends AppCompatActivity { public class CreateWalletActivity extends AppCompatActivity {
private String user_hash;
private String user_password;
private int session_id;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_wallet); setContentView(R.layout.activity_create_wallet);
EditText wallet_type = findViewById(R.id.editTextWalletType);
Button buttonValidate = findViewById(R.id.buttonValidate);
Button buttonCancel = findViewById(R.id.buttonCancel);
Context context = this;
Intent intent = getIntent();
user_hash = intent.getStringExtra("USER_HASH");
user_password = intent.getStringExtra("USER_PWD");
session_id = Integer.parseInt(intent.getStringExtra("SESSION_ID"));
buttonValidate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//TODO ASYNC wallet_type
Wallet wallet = new Wallet(wallet_type.toString(),user_hash);
new CreateWalletTask(context).execute(wallet);
}
});
buttonCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
private class CreateWalletTask extends AsyncTask<Wallet,String,Wallet> {
Context mContext;
private CreateWalletTask(final Context context){
mContext = context;
}
@Override
protected void onPostExecute(Wallet w) {
try{
Intent accountIntent = new Intent(CreateWalletActivity.this, UserAccountActivity.class);
accountIntent.putExtra("USER_HASH", user_hash);
accountIntent.putExtra("USER_PWD",user_password);
accountIntent.putExtra("SESSION_ID",session_id);
accountIntent.putExtra("WALLET_HASH",w.getWallet_hash());
accountIntent.putExtra("WALLET_BALANCE",String.valueOf(w.getBalance()));
accountIntent.putExtra("WALLET_TYPE",w.getType());
CreateWalletActivity.this.startActivity(accountIntent);
finish();
}catch (Exception e){
e.printStackTrace();
}
}
@Override
protected Wallet doInBackground(Wallet... w) {
try{
WalletApiHandler walletApiHandler = new WalletApiHandler();
return walletApiHandler.createWallet(w[0]);
}catch (Exception e){
e.printStackTrace();
}
return null;
}
}
@Override
protected void onStop() {
super.onStop(); // Always call the superclass method first
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
} }
} }

View file

@ -6,6 +6,7 @@ import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.Toast;
import com.example.monnthic.monnethicmobile.R; import com.example.monnthic.monnethicmobile.R;
@ -28,10 +29,6 @@ public class HomeWalletActivity extends AppCompatActivity {
user_password = intent.getStringExtra("USER_PWD"); user_password = intent.getStringExtra("USER_PWD");
session_id = Integer.parseInt(intent.getStringExtra("SESSION_ID")); session_id = Integer.parseInt(intent.getStringExtra("SESSION_ID"));
Log.i("HomeWalletActivity","user_hash: "+user_hash);
Log.i("HomeWalletActivity","user_password: "+user_password);
Log.i("HomeWalletActivity","session_id: "+session_id);
buttonCreateWallet.setOnClickListener(new View.OnClickListener() { buttonCreateWallet.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -48,8 +45,6 @@ public class HomeWalletActivity extends AppCompatActivity {
} }
public void launchCreateWalletActivity() { public void launchCreateWalletActivity() {
Log.i("HomeWalletActivity","launchCreateWalletActivity");
Log.i("HomeWalletActivity",user_hash);
Intent createWalletIntent = new Intent(HomeWalletActivity.this, CreateWalletActivity.class); Intent createWalletIntent = new Intent(HomeWalletActivity.this, CreateWalletActivity.class);
createWalletIntent.putExtra("USER_HASH",user_hash); createWalletIntent.putExtra("USER_HASH",user_hash);
createWalletIntent.putExtra("USER_PWD",user_password); createWalletIntent.putExtra("USER_PWD",user_password);
@ -58,12 +53,16 @@ public class HomeWalletActivity extends AppCompatActivity {
} }
public void launchSelectWalletActivity() { public void launchSelectWalletActivity() {
Log.i("HomeWalletActivity","launchSelectWalletActivity");
Log.i("HomeWalletActivity",user_hash);
Intent selectWalletIntent = new Intent(HomeWalletActivity.this, SelectWalletActivity.class); Intent selectWalletIntent = new Intent(HomeWalletActivity.this, SelectWalletActivity.class);
selectWalletIntent.putExtra("USER_HASH",user_hash); selectWalletIntent.putExtra("USER_HASH",user_hash);
selectWalletIntent.putExtra("USER_PWD",user_password); selectWalletIntent.putExtra("USER_PWD",user_password);
selectWalletIntent.putExtra("SESSION_ID",String.valueOf(session_id)); selectWalletIntent.putExtra("SESSION_ID",String.valueOf(session_id));
HomeWalletActivity.this.startActivity(selectWalletIntent); HomeWalletActivity.this.startActivity(selectWalletIntent);
} }
@Override
protected void onStop() {
super.onStop(); // Always call the superclass method first
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
}
} }

View file

@ -7,16 +7,19 @@ import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
import com.example.monnthic.monnethicmobile.R; import com.example.monnthic.monnethicmobile.R;
import java.util.ArrayList; import java.util.ArrayList;
import monnethic.mobile.restApi.WalletApiHandler; import monnethic.mobile.restApi.WalletApiHandler;
import monnethic.mobile.user.UserAccountActivity;
public class SelectWalletActivity extends AppCompatActivity { public class SelectWalletActivity extends AppCompatActivity {
private ArrayList<Wallet> userWallets; private ArrayList<Wallet> userWallets;
private String user_hash;
private String user_password;
private String session_id;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -25,33 +28,41 @@ public class SelectWalletActivity extends AppCompatActivity {
ListView listView = (ListView) findViewById(R.id.listViewWallet); ListView listView = (ListView) findViewById(R.id.listViewWallet);
Intent intent = getIntent(); Intent intent = getIntent();
String user_hash = intent.getStringExtra("USER_HASH"); user_hash = intent.getStringExtra("USER_HASH");
user_password = intent.getStringExtra("USER_PWD");
session_id = intent.getStringExtra("SESSION_ID");
String[] params = {user_hash}; String[] params = {user_hash};
Log.i("SelectWalletActivity", "user_hash : "+user_hash);
try { try {
userWallets = new getUserWalletTask().execute(params).get(); userWallets = new getUserWalletTask().execute(params).get();
} catch (Exception e){ } catch (Exception e){
e.printStackTrace(); e.printStackTrace();
} }
Log.i("SelectWalletActivity", "userWallets : "+userWallets);
WalletAdapter adapter = new WalletAdapter(this,userWallets); WalletAdapter adapter = new WalletAdapter(this,userWallets);
//ArrayAdapter<Wallet> adapter = new ArrayAdapter<Wallet>(this, R.layout.activity_select_wallet, userWallets);
listView.setAdapter(adapter); listView.setAdapter(adapter);
//TODO
//ON CLICK ITEM
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Wallet w = (Wallet) listView.getItemAtPosition(i); Wallet w = (Wallet) listView.getItemAtPosition(i);
Toast.makeText(getBaseContext(),w.getType(),Toast.LENGTH_SHORT).show(); launchAcountActivity(w);
} }
}); });
} }
//AsyncTask for login public void launchAcountActivity(Wallet w) {
Intent accountIntent = new Intent(SelectWalletActivity.this, UserAccountActivity.class);
accountIntent.putExtra("USER_HASH",user_hash);
accountIntent.putExtra("USER_PWD",user_password);
accountIntent.putExtra("SESSION_ID",session_id);
accountIntent.putExtra("WALLET_HASH",w.getWallet_hash());
accountIntent.putExtra("WALLET_BALANCE",String.valueOf(w.getBalance()));
accountIntent.putExtra("WALLET_TYPE",w.getType());
SelectWalletActivity.this.startActivity(accountIntent);
}
//AsyncTask to get user wallets
static private class getUserWalletTask extends AsyncTask<String,String,ArrayList<Wallet>> { static private class getUserWalletTask extends AsyncTask<String,String,ArrayList<Wallet>> {
@Override @Override
protected ArrayList<Wallet> doInBackground(String... params) { protected ArrayList<Wallet> doInBackground(String... params) {
@ -59,12 +70,16 @@ public class SelectWalletActivity extends AppCompatActivity {
try{ try{
WalletApiHandler walletApiHandler = new WalletApiHandler(); WalletApiHandler walletApiHandler = new WalletApiHandler();
walletsList = walletApiHandler.getUserWallets(params); walletsList = walletApiHandler.getUserWallets(params);
Log.i("SelectWalletActivity", "walletsList : "+walletsList);
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
} }
Log.i("SelectWalletActivity", "BEFORE RETURN : walletsList : "+walletsList);
return walletsList; return walletsList;
} }
} }
@Override
protected void onStop() {
super.onStop(); // Always call the superclass method first
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
}
} }

View file

@ -26,7 +26,7 @@
android:layout_below="@+id/buttonSettings" android:layout_below="@+id/buttonSettings"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="1dp" android:layout_marginTop="1dp"
android:text="ACCOUNT" android:text="WALLET"
android:textSize="15sp" android:textSize="15sp"
android:textStyle="bold" /> android:textStyle="bold" />