Merge branch 'features/wallet' into develop
This commit is contained in:
commit
40bbcc12b6
|
@ -9,14 +9,10 @@ import android.view.View;
|
|||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.monnthic.monnethicmobile.R;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import monnethic.mobile.restApi.Config;
|
||||
import monnethic.mobile.restApi.HttpCallHandler;
|
||||
import monnethic.mobile.user.UserAccountActivity;
|
||||
import monnethic.mobile.wallet.HomeWalletActivity;
|
||||
|
||||
public class LoginActivity extends AppCompatActivity {
|
||||
|
@ -27,7 +23,6 @@ public class LoginActivity extends AppCompatActivity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
|
||||
email = findViewById(R.id.editTextEmail);
|
||||
password = findViewById(R.id.editTextPassword);
|
||||
Button buttonCancel = findViewById(R.id.buttonCancel);
|
||||
|
@ -82,9 +77,8 @@ public class LoginActivity extends AppCompatActivity {
|
|||
try{
|
||||
if(result!=null){
|
||||
if(result.getInt("status") == 200){
|
||||
//Intent accountIntent = new Intent(LoginActivity.this, UserAccountActivity.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("SESSION_ID","0");
|
||||
LoginActivity.this.startActivity(walletHomeIntent);
|
||||
|
@ -104,7 +98,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||
try{
|
||||
String url = Config.USER_LOGIN;
|
||||
String[] paramsList = {params[0],params[1]};
|
||||
HttpCallHandler httpCallHandler = new HttpCallHandler();
|
||||
HttpCallHandler httpCallHandler = new HttpCallHandler(); //TODO UserApiHandler
|
||||
return new JSONObject(httpCallHandler.executeLoginHttp(url,paramsList));
|
||||
}catch (Exception e){
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,10 +32,10 @@ public class QrCodeActivity extends AppCompatActivity {
|
|||
amountView=findViewById(R.id.textViewAmountDisplay);
|
||||
|
||||
Intent intent = getIntent();
|
||||
String adresse = intent.getStringExtra("adresse");
|
||||
String value = intent.getStringExtra("value");
|
||||
String wallet_hash = intent.getStringExtra("WALLET_HASH");
|
||||
String amount = intent.getStringExtra("AMOUNT");
|
||||
try{
|
||||
generateQrCode(adresse,value);
|
||||
generateQrCode(wallet_hash,amount);
|
||||
}catch(Exception e){
|
||||
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;
|
||||
String valueToEncode = adresse+";"+value;
|
||||
String valueToEncode = wallet_hash+";"+amount;
|
||||
try{
|
||||
bitMatrix = new MultiFormatWriter().encode(valueToEncode, BarcodeFormat.QR_CODE,350,350);
|
||||
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
|
||||
Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
|
||||
qrCode.setImageBitmap(bitmap);
|
||||
adresseView.setText(adresse);
|
||||
amountView.setText(value);
|
||||
adresseView.setText(wallet_hash);
|
||||
amountView.setText(amount);
|
||||
}catch (Exception e){
|
||||
e.getMessage();
|
||||
}
|
||||
|
|
|
@ -83,8 +83,9 @@ public class QrCodeScannerActivity extends AppCompatActivity {
|
|||
intentData = barcodes.valueAt(0).displayValue;
|
||||
Intent scannedQrIntent = new Intent(QrCodeScannerActivity.this, ApprovePayementActivity.class);
|
||||
scannedQrIntent.putExtra("valueScanned",intentData);
|
||||
//TODO INTENT
|
||||
QrCodeScannerActivity.this.startActivity(scannedQrIntent);
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -101,4 +102,10 @@ public class QrCodeScannerActivity extends AppCompatActivity {
|
|||
super.onResume();
|
||||
initialiseDetector();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop(); // Always call the superclass method first
|
||||
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,4 @@ public class Config {
|
|||
static public String WALLET_DELETE = BASE_URL_WALLET+"delete";
|
||||
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=";
|
||||
}
|
|
@ -9,6 +9,7 @@ import java.io.InputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
import monnethic.mobile.database.User;
|
||||
|
||||
|
@ -44,95 +45,50 @@ public class HttpCallHandler {
|
|||
}
|
||||
|
||||
|
||||
public String executeGetHttp(String urlParam, String[] params){
|
||||
InputStream inputStream;
|
||||
BufferedReader bufferedReader = null;
|
||||
public String postHttp(URL url, Map<String,String> params) throws Exception {
|
||||
String returnValue=null;
|
||||
HttpURLConnection urlConnection = null;
|
||||
urlConnection = (HttpURLConnection) url.openConnection();
|
||||
urlConnection.setRequestMethod("POST");
|
||||
urlConnection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
||||
urlConnection.setRequestProperty("Accept","application/json");
|
||||
urlConnection.setDoOutput(true);
|
||||
urlConnection.setDoInput(true);
|
||||
|
||||
try{
|
||||
URL url = new URL(urlParam);
|
||||
urlConnection = (HttpURLConnection) url.openConnection();
|
||||
urlConnection.setRequestMethod("GET");
|
||||
urlConnection.connect();
|
||||
JSONObject jsonParam = new JSONObject();
|
||||
for(Map.Entry<String,String> pair : params.entrySet()){
|
||||
jsonParam.put(pair.getKey(),pair.getValue());
|
||||
}
|
||||
|
||||
int response = urlConnection.getResponseCode();
|
||||
if(response != 200){
|
||||
System.out.println("Error response");
|
||||
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();
|
||||
}
|
||||
inputStream = urlConnection.getInputStream();
|
||||
if(inputStream == null){
|
||||
System.out.println("Error inputStream");
|
||||
}
|
||||
|
||||
} else {
|
||||
BufferedReader bufferedReader = null;
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
String line;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
returnValue = stringBuilder.toString();
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
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;
|
||||
while ((line = bufferedReader.readLine())!=null){
|
||||
stringBuilder.append(line);
|
||||
}
|
||||
JSONObject jsonSuccess = new JSONObject(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String executeLoginHttp(String urlParam, String[] params){
|
||||
BufferedReader bufferedReader = null;
|
||||
|
|
|
@ -5,6 +5,8 @@ import org.json.JSONObject;
|
|||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import monnethic.mobile.wallet.Wallet;
|
||||
|
||||
|
@ -14,7 +16,7 @@ public class WalletApiHandler {
|
|||
ArrayList<Wallet> walletList = new ArrayList<>();
|
||||
HttpCallHandler httpCallHandler = new HttpCallHandler();
|
||||
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));
|
||||
JSONArray jsonArray = new JSONArray(responseCall);
|
||||
|
||||
|
@ -26,7 +28,7 @@ public class WalletApiHandler {
|
|||
wallet.setWallet_hash(jsonObject.getJSONObject("Record").getJSONObject("id").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));
|
||||
JSONObject jsonWallet = new JSONObject(responseWallet);
|
||||
|
||||
|
@ -36,7 +38,40 @@ public class WalletApiHandler {
|
|||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.support.v7.app.AppCompatActivity;
|
|||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.monnthic.monnethicmobile.R;
|
||||
|
||||
|
@ -12,24 +13,58 @@ import monnethic.mobile.qrcode.QrCodeScannerActivity;
|
|||
|
||||
public class MakePayementActivity extends AppCompatActivity {
|
||||
Button btnScanQr;
|
||||
Button btnSendWithAddress;
|
||||
private String user_hash;
|
||||
private String user_password;
|
||||
private String session_id;
|
||||
private String wallet_hash;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
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();
|
||||
}
|
||||
|
||||
private void initViews(){
|
||||
btnScanQr = findViewById(R.id.buttonScanQr);
|
||||
btnSendWithAddress = findViewById(R.id.buttonSendWithAddress);
|
||||
|
||||
btnScanQr.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop(); // Always call the superclass method first
|
||||
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ 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;
|
||||
|
||||
|
@ -16,6 +17,11 @@ public class ReceivePayementActivity extends AppCompatActivity {
|
|||
Button validateButton;
|
||||
EditText amountValueEdit;
|
||||
|
||||
private String user_hash;
|
||||
private String user_password;
|
||||
private String session_id;
|
||||
private String wallet_hash;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -24,6 +30,12 @@ public class ReceivePayementActivity extends AppCompatActivity {
|
|||
validateButton=findViewById(R.id.buttonValidate);
|
||||
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() {
|
||||
@Override
|
||||
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);
|
||||
generateQrIntent.putExtra("adresse","addresseAAAA");
|
||||
generateQrIntent.putExtra("value",value);
|
||||
generateQrIntent.putExtra("WALLET_HASH",wallet_hash);
|
||||
generateQrIntent.putExtra("AMOUNT",amount);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,21 +13,27 @@ import com.example.monnthic.monnethicmobile.R;
|
|||
import java.math.BigInteger;
|
||||
|
||||
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 amount;
|
||||
private EditText amountEditText;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_transaction);
|
||||
addressDestination = findViewById(R.id.destination_address);
|
||||
amount = findViewById(R.id.amount);
|
||||
amountEditText = findViewById(R.id.amount);
|
||||
Button buttonCancel = findViewById(R.id.btn_cancel);
|
||||
Button buttonOk = findViewById(R.id.btn_send);
|
||||
|
||||
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() {
|
||||
@Override
|
||||
|
@ -45,15 +51,23 @@ public class TransactionActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
public void sendTransaction(){
|
||||
String adD = addressDestination.getText().toString();
|
||||
BigInteger amt = new BigInteger(amount.getText().toString());
|
||||
String wallet_dest = addressDestination.getText().toString();
|
||||
String amount = amountEditText.getText().toString();
|
||||
|
||||
/*
|
||||
if(AccessBlockchain.sendTransationTo(address, adD, amt)){
|
||||
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();
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop(); // Always call the superclass method first
|
||||
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Intent;
|
|||
import android.os.AsyncTask;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
@ -23,11 +24,16 @@ import java.net.URL;
|
|||
import monnethic.mobile.database.User;
|
||||
import monnethic.mobile.restApi.Config;
|
||||
import monnethic.mobile.restApi.HttpCallHandler;
|
||||
import monnethic.mobile.restApi.WalletApiHandler;
|
||||
import monnethic.mobile.transaction.MakePayementActivity;
|
||||
import monnethic.mobile.transaction.ReceivePayementActivity;
|
||||
|
||||
public class UserAccountActivity extends AppCompatActivity {
|
||||
private TextView balance;
|
||||
private String wallet_hash;
|
||||
private String user_hash;
|
||||
private String user_password;
|
||||
private String session_id;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -39,9 +45,17 @@ public class UserAccountActivity extends AppCompatActivity {
|
|||
Button buttonReceive = findViewById(R.id.buttonReceive);
|
||||
Button buttonSettings = findViewById(R.id.buttonSettings);
|
||||
Button buttonRefresh = findViewById(R.id.buttonRefreshBalance);
|
||||
|
||||
Intent intent = getIntent();
|
||||
String userHash = intent.getStringExtra("userHash");
|
||||
userHashView.setText(userHash);
|
||||
user_hash = intent.getStringExtra("USER_HASH");
|
||||
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() {
|
||||
@Override
|
||||
|
@ -64,37 +78,40 @@ public class UserAccountActivity extends AppCompatActivity {
|
|||
buttonRefresh.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
public void sendPayement(){
|
||||
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);
|
||||
}
|
||||
public void receivePayement(){
|
||||
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);
|
||||
}
|
||||
public void settings(){
|
||||
Toast.makeText(this, "Coming soon", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public void refreshBalance(String userHash){
|
||||
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>
|
||||
public class GetUserBalanceTask extends AsyncTask<String,String,Double>
|
||||
{
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
|
@ -102,32 +119,34 @@ public class UserAccountActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String s) {
|
||||
if(s!=null){
|
||||
balance.setText(s);
|
||||
protected void onPostExecute(Double b) {
|
||||
if(b!=null){
|
||||
balance.setText(String.valueOf(b));
|
||||
}else{
|
||||
balance.setText("0");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
protected Double doInBackground(String... params) {
|
||||
try{
|
||||
String url = Config.QUERY_BALANCE+params[0];
|
||||
HttpCallHandler httpCallHandler = new HttpCallHandler();
|
||||
JSONObject json = new JSONObject(httpCallHandler.executeGetBalance(url));
|
||||
if(json.get("userBalance")!=null){
|
||||
Double balance = json.getDouble("userBalance");
|
||||
return balance.toString();
|
||||
WalletApiHandler walletApiHandler = new WalletApiHandler();
|
||||
Double newBalance = walletApiHandler.getWalletBalance(params);
|
||||
if(newBalance!=null){
|
||||
return newBalance;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,96 @@
|
|||
package monnethic.mobile.wallet;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
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 monnethic.mobile.restApi.WalletApiHandler;
|
||||
import monnethic.mobile.user.UserAccountActivity;
|
||||
|
||||
public class CreateWalletActivity extends AppCompatActivity {
|
||||
private String user_hash;
|
||||
private String user_password;
|
||||
private int session_id;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.os.Bundle;
|
|||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.monnthic.monnethicmobile.R;
|
||||
|
||||
|
@ -28,10 +29,6 @@ public class HomeWalletActivity extends AppCompatActivity {
|
|||
user_password = intent.getStringExtra("USER_PWD");
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -48,8 +45,6 @@ public class HomeWalletActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
public void launchCreateWalletActivity() {
|
||||
Log.i("HomeWalletActivity","launchCreateWalletActivity");
|
||||
Log.i("HomeWalletActivity",user_hash);
|
||||
Intent createWalletIntent = new Intent(HomeWalletActivity.this, CreateWalletActivity.class);
|
||||
createWalletIntent.putExtra("USER_HASH",user_hash);
|
||||
createWalletIntent.putExtra("USER_PWD",user_password);
|
||||
|
@ -58,12 +53,16 @@ public class HomeWalletActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
public void launchSelectWalletActivity() {
|
||||
Log.i("HomeWalletActivity","launchSelectWalletActivity");
|
||||
Log.i("HomeWalletActivity",user_hash);
|
||||
Intent selectWalletIntent = new Intent(HomeWalletActivity.this, SelectWalletActivity.class);
|
||||
selectWalletIntent.putExtra("USER_HASH",user_hash);
|
||||
selectWalletIntent.putExtra("USER_PWD",user_password);
|
||||
selectWalletIntent.putExtra("SESSION_ID",String.valueOf(session_id));
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -7,16 +7,19 @@ import android.os.Bundle;
|
|||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.monnthic.monnethicmobile.R;
|
||||
import java.util.ArrayList;
|
||||
import monnethic.mobile.restApi.WalletApiHandler;
|
||||
import monnethic.mobile.user.UserAccountActivity;
|
||||
|
||||
public class SelectWalletActivity extends AppCompatActivity {
|
||||
private ArrayList<Wallet> userWallets;
|
||||
private String user_hash;
|
||||
private String user_password;
|
||||
private String session_id;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -25,33 +28,41 @@ public class SelectWalletActivity extends AppCompatActivity {
|
|||
|
||||
ListView listView = (ListView) findViewById(R.id.listViewWallet);
|
||||
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};
|
||||
|
||||
Log.i("SelectWalletActivity", "user_hash : "+user_hash);
|
||||
try {
|
||||
userWallets = new getUserWalletTask().execute(params).get();
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Log.i("SelectWalletActivity", "userWallets : "+userWallets);
|
||||
WalletAdapter adapter = new WalletAdapter(this,userWallets);
|
||||
//ArrayAdapter<Wallet> adapter = new ArrayAdapter<Wallet>(this, R.layout.activity_select_wallet, userWallets);
|
||||
listView.setAdapter(adapter);
|
||||
|
||||
//TODO
|
||||
//ON CLICK ITEM
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
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>> {
|
||||
@Override
|
||||
protected ArrayList<Wallet> doInBackground(String... params) {
|
||||
|
@ -59,12 +70,16 @@ public class SelectWalletActivity extends AppCompatActivity {
|
|||
try{
|
||||
WalletApiHandler walletApiHandler = new WalletApiHandler();
|
||||
walletsList = walletApiHandler.getUserWallets(params);
|
||||
Log.i("SelectWalletActivity", "walletsList : "+walletsList);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.i("SelectWalletActivity", "BEFORE RETURN : walletsList : "+walletsList);
|
||||
return walletsList;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop(); // Always call the superclass method first
|
||||
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
android:layout_below="@+id/buttonSettings"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="1dp"
|
||||
android:text="ACCOUNT"
|
||||
android:text="WALLET"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
|
|
Loading…
Reference in a new issue