-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Refatoring Account and Transaction classes.
- Loading branch information
1 parent
ad70e78
commit 80c375d
Showing
66 changed files
with
1,944 additions
and
443 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 18 additions & 3 deletions
21
app/src/main/java/br/com/samilaruane/carteiravirtual/domain/BTCoin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,35 @@ | ||
package br.com.samilaruane.carteiravirtual.domain | ||
|
||
import br.com.samilaruane.carteiravirtual.domain.entities.BitcoinTicker | ||
import br.com.samilaruane.carteiravirtual.utils.EventResponseListener | ||
import br.com.samilaruane.carteiravirtual.utils.constants.BaseConstants | ||
|
||
/** | ||
* Created by samila on 18/12/17. | ||
*/ | ||
class BTCoin : Coin { | ||
class BTCoin : Coin, EventResponseListener<BitcoinTicker> { | ||
|
||
var saleResult: Double = 0.0 | ||
var purchaseResult: Double = 0.0 | ||
|
||
override fun getSalePrice(): Double { | ||
return 1.0 | ||
return saleResult | ||
} | ||
|
||
override fun getPurchaseQuotation(): Double { | ||
return 1.0 | ||
return purchaseResult | ||
} | ||
|
||
override fun getCoinInitials(): String { | ||
return BaseConstants.BITCOIN_ACCOUNT | ||
} | ||
|
||
override fun onSuccess(obj: BitcoinTicker) { | ||
saleResult = obj.sell | ||
purchaseResult = obj.buy | ||
} | ||
|
||
override fun onError(errorMessage: String) { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
} |
29 changes: 24 additions & 5 deletions
29
app/src/main/java/br/com/samilaruane/carteiravirtual/domain/BritaCoin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,41 @@ | ||
package br.com.samilaruane.carteiravirtual.domain | ||
|
||
import br.com.samilaruane.carteiravirtual.domain.entities.DollarExchangeRate | ||
import br.com.samilaruane.carteiravirtual.repository.remote.ServiceManager | ||
import br.com.samilaruane.carteiravirtual.utils.EventResponseListener | ||
import br.com.samilaruane.carteiravirtual.utils.constants.BaseConstants | ||
|
||
/** | ||
* Created by samila on 18/12/17. | ||
*/ | ||
class BritaCoin : Coin { | ||
class BritaCoin : Coin, EventResponseListener<DollarExchangeRate> { | ||
|
||
var saleResult: Double = 0.0 | ||
var purchaseResult: Double = 0.0 | ||
|
||
constructor() { | ||
ServiceManager().getBritaQuotation(this) | ||
} | ||
|
||
|
||
override fun getSalePrice(): Double { | ||
//TODO checar cotação retornada pela API | ||
return 1.0 | ||
return saleResult | ||
} | ||
|
||
override fun getPurchaseQuotation(): Double { | ||
//TODO checar cotação retornada pela API | ||
return 1.0 | ||
return purchaseResult | ||
} | ||
|
||
override fun getCoinInitials(): String { | ||
return BaseConstants.BRITA_ACCOUNT | ||
} | ||
|
||
override fun onSuccess(obj: DollarExchangeRate) { | ||
saleResult = obj.cotacaoVenda | ||
purchaseResult = obj.cotacaoCompra | ||
} | ||
|
||
override fun onError(errorMessage: String) { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 64 additions & 4 deletions
68
app/src/main/java/br/com/samilaruane/carteiravirtual/repository/db/AccountRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,72 @@ | ||
package br.com.samilaruane.carteiravirtual.repository.db | ||
|
||
import android.content.ContentValues | ||
import android.content.Context | ||
import br.com.samilaruane.carteiravirtual.utils.constants.BaseConstants | ||
import br.com.samilaruane.carteiravirtual.utils.constants.DatabaseConstants | ||
import br.com.samilaruane.carteiravirtual.domain.* | ||
import br.com.samilaruane.carteiravirtual.domain.entities.Account | ||
|
||
|
||
/** | ||
* Created by samila on 07/01/18. | ||
*/ | ||
interface AccountRepository { | ||
fun insert (account : Account) : Int | ||
fun select (userId : String) : MutableList<Account> | ||
class AccountRepository private constructor(ctx : Context) : Repository<Account>{ | ||
var mWalletDatabaseHelper = WalletDatabaseHelper (ctx) | ||
|
||
companion object { | ||
var sInstance : Repository<Account>? = null | ||
|
||
fun getInstance (ctx : Context) : AccountRepository { | ||
if(sInstance == null){ | ||
sInstance = AccountRepository(ctx) | ||
} | ||
|
||
return sInstance as AccountRepository | ||
} | ||
} | ||
|
||
override fun create(item: Account): Long { | ||
val db = mWalletDatabaseHelper.writableDatabase | ||
val insertValues = ContentValues() | ||
insertValues.put(DatabaseConstants.ACCOUNT.COLUMNS.USER_ID, item.getUserId()) | ||
insertValues.put(DatabaseConstants.ACCOUNT.COLUMNS.BALANCE, item.getAccountBalance()) | ||
insertValues.put(DatabaseConstants.ACCOUNT.COLUMNS.COIN_INITIALS, item.getCoin().getCoinInitials()) | ||
|
||
return db.insert(DatabaseConstants.ACCOUNT.TABLE_NAME, null, insertValues) | ||
} | ||
|
||
override fun delete(item: Account) { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun update(item: Account) { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun select(statment: Statment): List<Account> { | ||
|
||
val db = mWalletDatabaseHelper.writableDatabase | ||
val querySQL = statment.getQuery() | ||
|
||
val list = mutableListOf<Account>() | ||
val cursor = db.rawQuery(querySQL, null) | ||
|
||
while (cursor.moveToNext()){ | ||
val userId = cursor.getLong(cursor.getColumnIndex(DatabaseConstants.ACCOUNT.COLUMNS.USER_ID)) | ||
val balance = cursor.getDouble(cursor.getColumnIndex(DatabaseConstants.ACCOUNT.COLUMNS.BALANCE)) | ||
val coin = cursor.getString(cursor.getColumnIndex(DatabaseConstants.ACCOUNT.COLUMNS.COIN_INITIALS)) | ||
|
||
var coinReference : Coin = BRLCoin () | ||
|
||
when (coin){ | ||
BaseConstants.BITCOIN_ACCOUNT -> {coinReference = BTCoin()} | ||
BaseConstants.BRITA_ACCOUNT-> {coinReference = BritaCoin ()} | ||
} | ||
|
||
val item = Account(userId, coinReference, balance) | ||
|
||
list.add(item) | ||
} | ||
return list | ||
} | ||
} |
Oops, something went wrong.