131 lines
4.3 KiB
Java
131 lines
4.3 KiB
Java
package monnethic.mobile.transaction;
|
|
|
|
import android.app.ProgressDialog;
|
|
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.TextView;
|
|
import android.widget.Toast;
|
|
import com.example.monnthic.monnethicmobile.R;
|
|
import monnethic.mobile.restApi.SessionApiHandler;
|
|
import monnethic.mobile.restApi.TransactionApiHandler;
|
|
|
|
public class ApprovePayementActivity extends AppCompatActivity {
|
|
TextView destAddress;
|
|
TextView amountDisplay;
|
|
Button buttonCancel;
|
|
Button buttonVal;
|
|
|
|
private String wallet_hash;
|
|
private String user_hash;
|
|
private String user_password;
|
|
private String session_id;
|
|
|
|
String wallet_dest;
|
|
String amount;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_approve_payement);
|
|
|
|
Intent intent = getIntent();
|
|
String[] value = intent.getStringExtra("VALUE").split(";");
|
|
wallet_dest = value[0];
|
|
amount = value[1];
|
|
|
|
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(){
|
|
destAddress = findViewById(R.id.destAddress);
|
|
amountDisplay = findViewById(R.id.amountApprove);
|
|
buttonCancel = findViewById(R.id.buttonCancel);
|
|
buttonVal = findViewById(R.id.buttonValidate);
|
|
|
|
destAddress.setText(wallet_dest);
|
|
amountDisplay.setText(amount);
|
|
|
|
buttonCancel.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
finish();
|
|
}
|
|
});
|
|
|
|
buttonVal.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
sendTransaction();
|
|
}
|
|
});
|
|
}
|
|
|
|
public void sendTransaction(){
|
|
SendingTransaction sendingTransaction = new SendingTransaction(user_hash,user_password,wallet_hash,wallet_dest,amount,"gonette");
|
|
try {
|
|
|
|
String transaction_hash = new TransactionTask().execute(sendingTransaction).get();
|
|
if(transaction_hash!=null){
|
|
Toast.makeText(this, "transaction id : "+transaction_hash, Toast.LENGTH_LONG).show();
|
|
} else {
|
|
Toast.makeText(this, "couldn't get transaction id", Toast.LENGTH_SHORT).show();
|
|
}
|
|
} catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
finish();
|
|
}
|
|
|
|
private class TransactionTask extends AsyncTask<SendingTransaction,String,String> {
|
|
@Override
|
|
protected void onPreExecute() {
|
|
super.onPreExecute();
|
|
ProgressDialog progDailog = new ProgressDialog(ApprovePayementActivity.this);
|
|
progDailog.setMessage("Sending transaction...");
|
|
progDailog.setIndeterminate(false);
|
|
progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
|
progDailog.setCancelable(true);
|
|
progDailog.show();
|
|
}
|
|
|
|
@Override
|
|
protected String doInBackground(SendingTransaction... sendingTransactions) {
|
|
try{
|
|
|
|
TransactionApiHandler transactionApiHandler = new TransactionApiHandler();
|
|
return transactionApiHandler.doTransaction(sendingTransactions[0]);
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onStop() {
|
|
super.onStop(); // Always call the superclass method first
|
|
new EndSessionTask().execute(session_id);
|
|
}
|
|
|
|
private class EndSessionTask extends AsyncTask<String,Void,Void> {
|
|
@Override
|
|
protected Void doInBackground(String... strings) {
|
|
try{
|
|
SessionApiHandler sessionApiHandler = new SessionApiHandler();
|
|
sessionApiHandler.endSession(strings[0]);
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|