-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_data.java
155 lines (132 loc) · 6 KB
/
user_data.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.example.myapplication;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class user_data extends AppCompatActivity {
ProgressDialog progressDialog;
String phonenumber;
Double newbalance;
TextView name, phoneNumber, email, account_no, ifsc_code, balance;
Button transfer_button;
AlertDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_userdata);
name = findViewById(R.id.username);
phoneNumber = findViewById(R.id.userphonenumber);
email = findViewById(R.id.email);
account_no = findViewById(R.id.account_no);
ifsc_code = findViewById(R.id.ifsc_code);
balance = findViewById(R.id.balance);
transfer_button = findViewById(R.id.transfer_button);
progressDialog = new ProgressDialog(user_data.this);
progressDialog.setTitle("Loading data...");
progressDialog.show();
Bundle bundle = getIntent().getExtras();
if(bundle != null){
phonenumber = bundle.getString("phonenumber");
showData(phonenumber);
}
transfer_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
enterAmount();
}
});
}
private void showData(String phonenumber) {
Cursor cursor = new DatabaseHelper(this).readparticulardata(phonenumber);
while(cursor.moveToNext()) {
String balancefromdb = cursor.getString(2);
newbalance = Double.parseDouble(balancefromdb);
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setGroupingUsed(true);
nf.setMaximumFractionDigits(2);
nf.setMinimumFractionDigits(2);
String price = nf.format(newbalance);
progressDialog.dismiss();
phoneNumber.setText(cursor.getString(0));
name.setText(cursor.getString(1));
email.setText(cursor.getString(3));
balance.setText(price);
account_no.setText(cursor.getString(4));
ifsc_code.setText(cursor.getString(5));
}
}
private void enterAmount() {
final AlertDialog.Builder mBuilder = new AlertDialog.Builder(user_data.this);
View mView = getLayoutInflater().inflate(R.layout.activity_transfer_money, null);
mBuilder.setTitle("Enter amount").setView(mView).setCancelable(false);
final EditText mAmount = (EditText) mView.findViewById(R.id.enter_money);
mBuilder.setPositiveButton("SEND", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
}).setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
transactionCancel();
}
});
dialog = mBuilder.create();
dialog.show();
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(mAmount.getText().toString().isEmpty()){
mAmount.setError("Amount can't be empty");
}else if(Double.parseDouble(mAmount.getText().toString()) > newbalance){
mAmount.setError("Your account don't have enough balance");
}else if(Double.parseDouble(mAmount.getText().toString()) < 1) {
mAmount.setError("Enter amount atleast Rs.1");
}else{
Intent intent = new Intent(user_data.this, sendtouser.class);
intent.putExtra("phonenumber", phoneNumber.getText().toString());
intent.putExtra("name", name.getText().toString());
intent.putExtra("currentamount", newbalance.toString());
intent.putExtra("transferamount", mAmount.getText().toString());
startActivity(intent);
finish();
}
}
});
}
private void transactionCancel() {
AlertDialog.Builder builder_exitbutton = new AlertDialog.Builder(user_data.this);
builder_exitbutton.setTitle("Do you want to cancel the transaction?").setCancelable(false)
.setPositiveButton("yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yyyy, hh:mm a");
String date = simpleDateFormat.format(calendar.getTime());
new DatabaseHelper(user_data.this).insertTransferData(date, name.getText().toString(), "Not selected", "0", "Failed");
Toast.makeText(user_data.this, "Transaction Cancelled!", Toast.LENGTH_LONG).show();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
enterAmount();
}
});
AlertDialog alertexit = builder_exitbutton.create();
alertexit.show();
}
}