Skip to content

Commit

Permalink
arreglos finales
Browse files Browse the repository at this point in the history
  • Loading branch information
fpieschaconr committed Jun 9, 2019
1 parent e507181 commit ad8b81a
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
android:name="com.diesel.BankApp.presentation.activities.RegisterActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.diesel.BankApp.presentation.activities.AccountRegisterActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.diesel.BankApp.presentation.activities.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.diesel.BankApp.presentation.activities.TransactionActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />

<provider
android:name="com.android.tools.ir.server.InstantRunContentProvider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
android:name="com.diesel.BankApp.presentation.activities.RegisterActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.diesel.BankApp.presentation.activities.AccountRegisterActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.diesel.BankApp.presentation.activities.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.diesel.BankApp.presentation.activities.TransactionActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />

<provider
android:name="com.android.tools.ir.server.InstantRunContentProvider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
android:name="com.diesel.BankApp.presentation.activities.RegisterActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.diesel.BankApp.presentation.activities.AccountRegisterActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.diesel.BankApp.presentation.activities.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.diesel.BankApp.presentation.activities.TransactionActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />

<provider
android:name="com.android.tools.ir.server.InstantRunContentProvider"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
-- Merging decision tree log ---
manifest
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-29:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-29:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-29:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-29:12
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-41:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-41:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-41:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-41:12
MERGED from [com.android.support:design:28.0.0] C:\Users\Felipe Pieschacon\.gradle\caches\transforms-2\files-2.1\b4946e7ee174dd1c7970d3da607d3e4c\AndroidManifest.xml:17:1-24:12
MERGED from [com.android.support:appcompat-v7:28.0.0] C:\Users\Felipe Pieschacon\.gradle\caches\transforms-2\files-2.1\8b6fac6ee46d77d47ffc5490d9ae994d\AndroidManifest.xml:17:1-22:12
MERGED from [com.android.support.constraint:constraint-layout:1.1.3] C:\Users\Felipe Pieschacon\.gradle\caches\transforms-2\files-2.1\c2243a6ede911e5d84c9e2a62ec571fd\AndroidManifest.xml:2:1-11:12
Expand Down Expand Up @@ -35,25 +35,25 @@ MERGED from [com.android.support:interpolator:28.0.0] C:\Users\Felipe Pieschacon
MERGED from [android.arch.lifecycle:livedata:1.1.1] C:\Users\Felipe Pieschacon\.gradle\caches\transforms-2\files-2.1\d748fc603c78a7272c694ef3b46da06e\AndroidManifest.xml:17:1-22:12
MERGED from [android.arch.lifecycle:livedata-core:1.1.1] C:\Users\Felipe Pieschacon\.gradle\caches\transforms-2\files-2.1\85ce544e0ba6ff8c7ff0e850b7576bf8\AndroidManifest.xml:17:1-22:12
MERGED from [android.arch.core:runtime:1.1.1] C:\Users\Felipe Pieschacon\.gradle\caches\transforms-2\files-2.1\74a83b7fa7c9ef718a9f61e573e4aaeb\AndroidManifest.xml:17:1-22:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-29:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-29:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-29:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-41:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-41:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-41:12
package
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:3:5-33
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml
android:versionName
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-29:12
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-41:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml
android:versionCode
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-29:12
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:1-41:12
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml
xmlns:android
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:2:11-69
application
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:5:5-27:19
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:5:5-39:19
MERGED from [com.android.support:design:28.0.0] C:\Users\Felipe Pieschacon\.gradle\caches\transforms-2\files-2.1\b4946e7ee174dd1c7970d3da607d3e4c\AndroidManifest.xml:22:5-20
MERGED from [com.android.support:design:28.0.0] C:\Users\Felipe Pieschacon\.gradle\caches\transforms-2\files-2.1\b4946e7ee174dd1c7970d3da607d3e4c\AndroidManifest.xml:22:5-20
MERGED from [com.android.support.constraint:constraint-layout:1.1.3] C:\Users\Felipe Pieschacon\.gradle\caches\transforms-2\files-2.1\c2243a6ede911e5d84c9e2a62ec571fd\AndroidManifest.xml:9:5-20
Expand Down Expand Up @@ -102,6 +102,30 @@ ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\Andr
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:25:13-56
android:name
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:23:13-87
activity#com.diesel.BankApp.presentation.activities.AccountRegisterActivity
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:26:9-29:59
android:label
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:28:13-45
android:theme
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:29:13-56
android:name
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:27:13-94
activity#com.diesel.BankApp.presentation.activities.MainActivity
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:30:9-33:59
android:label
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:32:13-45
android:theme
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:33:13-56
android:name
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:31:13-83
activity#com.diesel.BankApp.presentation.activities.TransactionActivity
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:34:9-37:59
android:label
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:36:13-45
android:theme
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:37:13-56
android:name
ADDED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml:35:13-90
uses-sdk
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml reason: use-sdk injection requested
INJECTED from C:\Users\Felipe Pieschacon\bank\mobile-app\bank-app\app\src\main\AndroidManifest.xml
Expand Down
12 changes: 12 additions & 0 deletions mobile-app/bank-app/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
android:name="com.diesel.BankApp.presentation.activities.RegisterActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.diesel.BankApp.presentation.activities.AccountRegisterActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.diesel.BankApp.presentation.activities.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.diesel.BankApp.presentation.activities.TransactionActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />

</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.diesel.BankApp.businessLogic.controllers;

import android.content.Context;

import com.diesel.BankApp.dataAccess.models.Account;
import com.diesel.BankApp.dataAccess.models.User;
import com.diesel.BankApp.dataAccess.repositories.AccountRepository;
import com.diesel.BankApp.dataAccess.repositories.UserRepository;

import java.sql.SQLException;
import java.util.List;

public class AccountRegisterController {
List<Account> result;
List<User> resultUser;
AccountRepository accRepo = new AccountRepository();
UserRepository userRepo = new UserRepository();


public boolean register(int numero, String linkedUsername, double balance, Context context) {
//verifica que exista la cuenta de usuario
try {
resultUser = userRepo.getUserByName(linkedUsername, context);
} catch (SQLException e) {
e.printStackTrace();
return false;
}
User usuario;
if (!(resultUser.isEmpty())) {
usuario = resultUser.get(0);
} else {
return false;
}
int idUsuario = usuario.getId();
//verifica que no exista ya la cuenta de ahorros
try {
result = accRepo.getAccountByNumber(numero, context);
//TODO la cuenta ya existe
if (!(result.isEmpty())) {
return false;
}
} catch (SQLException e) {
e.printStackTrace();
}
//crea la nueva cuenta
accRepo.createAccount(new Account(numero, idUsuario, balance, " "), context);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public int login(String username, String password, Context context){
return 0;
}
currentUser = result.get(0);
//verifica que la contraseña sea coerrecta.
if(currentUser.getPassword()!=password){
//verifica que la contraseña sea correcta.
if (!currentUser.getPassword().equals(password)) {
//TODO error contraseña incorrecta
return 0;
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public class MainController {
public static User usuario;
public static Account cuenta;
public static Administrator adminstrador;

}

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import android.content.Context;
import android.util.Base64;
import android.util.Log;

import com.diesel.BankApp.dataAccess.models.User;
import com.diesel.BankApp.dataAccess.repositories.UserRepository;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.sql.SQLException;
import java.util.Calendar;
Expand All @@ -24,9 +24,10 @@ public class RegisterController {
public boolean register(int ID, String username, String password, Context context){
try {
result = userRepo.getUserById(ID,context);
Log.d("demo account", result.toString());
//TODO la cuennta ya existe
return false;
if (!(result.isEmpty())) {
return false;
}
}catch (SQLException e){
e.printStackTrace();
}
Expand All @@ -44,7 +45,7 @@ private String encriptar(String datos, String password) throws Exception{
}
private SecretKeySpec generateKey(String password) throws Exception{
MessageDigest sha = MessageDigest.getInstance("SHA-256");
byte[] key = password.getBytes("UTF-8");
byte[] key = password.getBytes(StandardCharsets.UTF_8);
key = sha.digest(key);
SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
return secretKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.diesel.BankApp.businessLogic.controllers;

import android.content.Context;
import android.util.Log;

import com.diesel.BankApp.dataAccess.database.Database;
import com.diesel.BankApp.dataAccess.models.Account;
import com.diesel.BankApp.dataAccess.repositories.AccountRepository;


import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class TransactionController {
Expand All @@ -18,46 +18,60 @@ public class TransactionController {
Account cuentaReceptor;
double newBalance;

public boolean sendMoney(int idEmisor, double cantidad, int idReceptor, Context context){
public boolean sendMoney(int numeroEmisor, double cantidad, int numeroReceptor, Context context) {
//Busca la cuenta en la base de datos
try {
result = accRepo.getAccountByIdLinked(idEmisor,context);
Log.d("demo account", result.toString());
result = accRepo.getAccountByNumber(numeroEmisor, context);
} catch (SQLException e){
e.printStackTrace();
return false;
}

//Compara el balance de la cuenta del emisor con la cantidad que se queire enviar
cuentaEmisor = result.get(0);
//Compara el balance de la cuenta del emisor con la cantidad que se quiere enviar
if (!(result.isEmpty())) {
cuentaEmisor = result.get(0);
} else {
return false;
}

if(cuentaEmisor.getBalance()<cantidad){
//TODO error
return false;
}else{
//Obtiene la cuenta del receptor de la base de datos
try {
result = accRepo.getAccountByNumber(idReceptor,context);
Log.d("demo account", result.toString());
result = accRepo.getAccountByNumber(numeroReceptor, context);
} catch (SQLException e){
e.printStackTrace();
return false;
}

if (!(result.isEmpty())) {
cuentaReceptor = result.get(0);
} else {
return false;
}

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
//Resta la cantidad a enviar al balance del emisor
newBalance = cuentaEmisor.getBalance()-cantidad;
try {
accRepo.updateAccountBalance(idEmisor,newBalance,context);
accRepo.updateAccountBalance(numeroEmisor, newBalance, context);
String hist = cuentaEmisor.getHistory();
String newTran = dateFormat.format(date) + " | " + cuentaReceptor.getNumber() + " | -" + cantidad + ";";
accRepo.updateAccountHistory(numeroEmisor, newTran + hist, context);
}catch (SQLException e){
e.printStackTrace();
}



cuentaReceptor = result.get(0);
//Suma la cantidad a enviar al balance del receptor
newBalance = cuentaReceptor.getBalance()+cantidad;
try {
accRepo.updateAccountBalance(idReceptor,newBalance,context);
accRepo.updateAccountBalance(numeroReceptor, newBalance, context);
String hist = cuentaReceptor.getHistory();
String newTran = dateFormat.format(date) + " | " + cuentaEmisor.getNumber() + " | +" + cantidad + ";";
accRepo.updateAccountHistory(numeroReceptor, newTran + hist, context);
}catch (SQLException e){
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.widget.TextView;

import com.diesel.BankApp.R;
import com.diesel.BankApp.businessLogic.controllers.AccountRegisterController;


public class AccountRegisterActivity extends AppCompatActivity {
Expand Down Expand Up @@ -43,11 +44,15 @@ public void onClick(View view) {
double balance = Double.parseDouble(editTextBalance.getText().toString());

//Account register logic
AccountRegisterController controller = new AccountRegisterController();
boolean success = controller.register(number, username, balance, AccountRegisterActivity.this);
if (success == true) {
Snackbar.make(buttonRegister, "Account created successfully! Please Log in ", Snackbar.LENGTH_LONG).show();
} else {
Snackbar.make(buttonRegister, "Account creation failed! Please try again ", Snackbar.LENGTH_LONG).show();
}



Snackbar.make(buttonRegister, "Account created successfully! Please Login ", Snackbar.LENGTH_LONG).show();

}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
history = new ArrayList<>();
String[] splitter = MainController.cuenta.getHistory().split(";");
for (int i = 0; i < splitter.length; i++){
history.add(splitter[1]);
history.add(splitter[i]);
}
initViews();
initLogOutTextView();
Expand Down

0 comments on commit ad8b81a

Please sign in to comment.