146 lines
5.5 KiB
Java
146 lines
5.5 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.util.Log;
|
|
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.homepage.InputController;
|
|
import monnethic.mobile.restApi.TransactionApiHandler;
|
|
import monnethic.mobile.search.SearchUser;
|
|
|
|
public class TransactionActivity extends AppCompatActivity {
|
|
private String wallet_hash;
|
|
private String user_hash;
|
|
private String user_password;
|
|
private String session_id;
|
|
private EditText addressDestination;
|
|
private EditText amountEditText;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_transaction);
|
|
addressDestination = findViewById(R.id.destination_address);
|
|
amountEditText = findViewById(R.id.amount);
|
|
Button buttonCancel = findViewById(R.id.btn_cancel);
|
|
Button buttonOk = findViewById(R.id.btn_send);
|
|
Button buttonSearch = findViewById(R.id.buttonSearch);
|
|
|
|
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");
|
|
|
|
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);
|
|
|
|
buttonCancel.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
finish();
|
|
}
|
|
});
|
|
|
|
buttonOk.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
sendTransaction();
|
|
}
|
|
});
|
|
|
|
buttonSearch.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
launchSearchActivity();
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
public void sendTransaction(){
|
|
if(InputController.isEmptyEdit(addressDestination)){
|
|
Toast.makeText(this, "No destination address", Toast.LENGTH_SHORT).show();
|
|
} else if(InputController.isEmptyEdit(amountEditText)) {
|
|
Toast.makeText(this, "No amount", Toast.LENGTH_SHORT).show();
|
|
} else {
|
|
System.out.println("HERE");
|
|
String wallet_dest = addressDestination.getText().toString();
|
|
System.out.println("wallet_dest : "+wallet_dest);
|
|
String amount = amountEditText.getText().toString();
|
|
System.out.println("amount : "+amount);
|
|
System.out.println("user_hash : "+user_hash);
|
|
System.out.println("user_password : "+user_password);
|
|
System.out.println("wallet_hash : "+wallet_hash);
|
|
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();
|
|
}
|
|
finish();
|
|
} catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void launchSearchActivity(){
|
|
Intent searchIntent = new Intent(TransactionActivity.this, SearchUser.class);
|
|
startActivityForResult(searchIntent,1);
|
|
}
|
|
|
|
@Override
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data){
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
if(requestCode==1){
|
|
String walletHash = data.getStringExtra("walletHash");
|
|
addressDestination.setText(walletHash);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onStop() {
|
|
super.onStop(); // Always call the superclass method first
|
|
Toast.makeText(getApplicationContext(), "onStop called", Toast.LENGTH_LONG).show();
|
|
}
|
|
|
|
private class TransactionTask extends AsyncTask<SendingTransaction,String,String> {
|
|
|
|
@Override
|
|
protected void onPreExecute() {
|
|
super.onPreExecute();
|
|
ProgressDialog progDailog = new ProgressDialog(TransactionActivity.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();
|
|
System.out.println("SEND TRANSACTION");
|
|
return transactionApiHandler.doTransaction(sendingTransactions[0]);
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
}
|