Skip to content

Commit

Permalink
refactor: applying necessary changes after code inspection.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamilaRuane committed May 6, 2018
1 parent 1885176 commit 202ce0d
Show file tree
Hide file tree
Showing 52 changed files with 90 additions and 336 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ui.main.MainActivity"></activity>
<activity android:name=".ui.main.MainActivity" />
<activity android:name=".ui.login.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -28,7 +28,7 @@
</activity>
<activity android:name=".ui.register.RegisterActivity" />
<activity android:name=".ui.transaction.TransactionActivity" />
<activity android:name=".ui.recoverypassw.RecoveryPasswordActivity"></activity>
<activity android:name=".ui.recoverypassw.RecoveryPasswordActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SharedPreferencesHelper @Inject constructor(val context: Context) {


fun keepTokenForConfirmation(userPhoneNumber: String, token: String) {
sharedPreference.edit().putString(SHARED_PREFERENCE_USER_TOKEN, token).commit()
sharedPreference.edit().putString(SHARED_PREFERENCE_USER_TOKEN, token).apply()
}

fun getToken(): String =
Expand All @@ -33,7 +33,7 @@ class SharedPreferencesHelper @Inject constructor(val context: Context) {

fun saveUserId(user: User) {
if (user.id != null) {
sharedPreference.edit().putLong(SHARED_PREFERENCE_USER_ID, user.id).commit()
sharedPreference.edit().putLong(SHARED_PREFERENCE_USER_ID, user.id).apply()
}
}

Expand All @@ -42,7 +42,7 @@ class SharedPreferencesHelper @Inject constructor(val context: Context) {
}

fun setIsAuth(auth: Boolean) {
sharedPreference.edit().putBoolean(SHARED_PREFERENCES_CHECK_IS_AUTH, auth).commit()
sharedPreference.edit().putBoolean(SHARED_PREFERENCES_CHECK_IS_AUTH, auth).apply()
}


Expand All @@ -51,15 +51,15 @@ class SharedPreferencesHelper @Inject constructor(val context: Context) {
}

fun setBritaQuotation(body: String) {
sharedPreference.edit().putString(SHARED_PREFERENCES_BRITA_QUOTATION, body).commit()
sharedPreference.edit().putString(SHARED_PREFERENCES_BRITA_QUOTATION, body).apply()
}

fun getBritaQuotation(): String {
return sharedPreference.getString(SHARED_PREFERENCES_BRITA_QUOTATION, "")
}

fun setBitcoinQuotation(body: String) {
sharedPreference.edit().putString(SHARED_PREFERENCES_BITCOIN_QUOTATION, body).commit()
sharedPreference.edit().putString(SHARED_PREFERENCES_BITCOIN_QUOTATION, body).apply()
}

fun getBitcoinQuotation(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AccountRepository @Inject constructor(val mWalletDatabaseHelper: WalletDat
val balance = cursor.getDouble(cursor.getColumnIndex(DatabaseConstants.ACCOUNT.COLUMNS.BALANCE))
val coin = cursor.getString(cursor.getColumnIndex(DatabaseConstants.ACCOUNT.COLUMNS.COIN_INITIALS))

var coinReference = Coin (coin, 1.0, 1.0)
val coinReference = Coin (coin, 1.0, 1.0)

val item = Account(id, userId, coinReference, balance)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package br.com.samilaruane.carteiravirtual.data.db
/**
* Created by samila on 14/03/18.
*/
class AllItensSearcher(val tableName : String): Statment {
class AllItensSearcher(private val tableName : String): Statment {

override fun getQuery(): String {
return "SELECT * FROM $tableName"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package br.com.samilaruane.carteiravirtual.data.db
/**
* Created by samila on 14/03/18.
*/
class ByArgumentSearcher (val tableName:String,
val argumentColumn:String,
val argument:String): Statment {
class ByArgumentSearcher (private val tableName:String,
private val argumentColumn:String,
private val argument:String): Statment {

override fun getQuery(): String {
return "SELECT * FROM $tableName WHERE $argumentColumn = \"$argument\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package br.com.samilaruane.carteiravirtual.data.db
/**
* Created by samila on 14/03/18.
*/
class ByIdSearcher(val tableName:String,
val idColumn:String,
class ByIdSearcher(private val tableName:String,
private val idColumn:String,
val id:String): Statment {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import br.com.samilaruane.carteiravirtual.utils.constants.DatabaseConstants
class WalletDatabaseHelper (context: Context?) : SQLiteOpenHelper (context, DATABASE_NAME, null, DATABASE_VERSION) {

companion object {
val DATABASE_NAME = "wallet.db"
val DATABASE_VERSION = 1
const val DATABASE_NAME = "wallet.db"
const val DATABASE_VERSION = 1
}

private val createTableUser = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import retrofit2.Response
class BitcoinService {
companion object {
fun getCoinQuotation(listener: ServiceListener.Bitcoin) {
val service = RetrofitInitializer()?.getMercadoBitcoinService()?.get()
val service = RetrofitInitializer().getMercadoBitcoinService()?.get()
service?.enqueue(object : Callback<MercadoBitcoinResponse> {
override fun onResponse(call: Call<MercadoBitcoinResponse>?, response: Response<MercadoBitcoinResponse>?) {
if (response?.isSuccessful!!) {
listener.onSuccess(response?.body()!!)
listener.onSuccess(response.body()!!)
} else {
listener.onError(BaseConstants.MESSAGES.GENERIC_ERROR)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import dagger.Provides
@Module
class AppModule(app: App) {

val mApp: App = app
private val mApp: App = app

@Provides
fun provideContext(): Context = mApp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ import dagger.Module
import dagger.Provides

@Module
class RecoveryPasswordModule {

private val mView: RecoveryPasswordContract.View

constructor(mView: RecoveryPasswordContract.View) {
this.mView = mView
}
class RecoveryPasswordModule(private val mView: RecoveryPasswordContract.View) {


@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AccountBusiness @Inject constructor(val gateway: AccountGateway) : Account
return result
}

fun getBrita(): Coin {
private fun getBrita(): Coin {

try {
brita.purchaseQuotation = JSONObject(gateway.getBritaQuotation())
Expand All @@ -104,7 +104,7 @@ class AccountBusiness @Inject constructor(val gateway: AccountGateway) : Account
return brita
}

fun getBitcoin(): Coin {
private fun getBitcoin(): Coin {

try {
bitcoin.purchaseQuotation = JSONObject(gateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AuthBusiness(private val gateway: AuthGateway) : AuthBoundary {

override fun sendToken(phoneNumber: String) {
val random = Random().generateToken()
val msg = "Use este token para recuperar sua senha"
val msg = "Token Carteira Virtual"
gateway.keepToken(phoneNumber, random)
val smsManager = SmsManager.getDefault()
smsManager.sendTextMessage(phoneNumber, null, "$msg - $random", null, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ data class Transaction(val date: Long,
val calendar = Calendar.getInstance()
calendar.timeInMillis = date
val transactionSummary: String
if (transactionType == BaseConstants.BUY)
transactionSummary = "${calendar.formatter("dd/MM/yyyy")} - $transactionType de $amount $destinationCoin"
else if (transactionType == BaseConstants.SELL)
transactionSummary = "${calendar.formatter("dd/MM/yyyy")} - $transactionType de $amount $sourceCoin"
else
transactionSummary = "${calendar.formatter("dd/MM/yyyy")} - $transactionType de $amount $sourceCoin por $destinationCoin"
transactionSummary = when (transactionType) {
BaseConstants.BUY -> "${calendar.formatter("dd/MM/yyyy")} - $transactionType de $amount $destinationCoin"
BaseConstants.SELL -> "${calendar.formatter("dd/MM/yyyy")} - $transactionType de $amount $sourceCoin"
else -> "${calendar.formatter("dd/MM/yyyy")} - $transactionType de $amount $sourceCoin por $destinationCoin"
}

return transactionSummary
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class User (val id : Long, var name : String,
var password: String ){

fun isValid() : Boolean {
return !name.isNullOrEmpty() && isEmailValid() && isPhoneValid() && !password.isNullOrEmpty()
return !name.isEmpty() && isEmailValid() && isPhoneValid() && !password.isEmpty()
}

private fun isEmailValid () : Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,41 @@ class TransactionBusiness @Inject constructor(val gateway: TransactionGateway) :
}

private fun sell(sourceAccount: Account, destinationAccount: Account, amount: Double) : Boolean {
try {
return try {
var saleValue = sourceAccount.getCoin().salePrice
saleValue = saleValue.times(amount)
sourceAccount.withdraw(amount)
destinationAccount.deposit(saleValue)
return true
true
} catch (e: InsufficientBalanceException) {
return false
false
}
}


private fun buy(sourceAccount: Account, destinationAccount: Account, amount: Double) : Boolean {
try {
return try {
var purchaseValue = destinationAccount.getCoin().purchaseQuotation
purchaseValue = purchaseValue.times(amount)
sourceAccount.withdraw(purchaseValue)
destinationAccount.deposit(amount)
return true
true
} catch (e: InsufficientBalanceException) {
return false
false
}
}

private fun trade(sourceAccount: Account, destinationAccount: Account, amount: Double) : Boolean {
try {
return try {
var saleValue = sourceAccount.getCoin().salePrice
saleValue = saleValue.times(amount)
val tradeValue = saleValue / destinationAccount.getCoin().purchaseQuotation

sourceAccount.withdraw(amount)
destinationAccount.deposit(tradeValue)
return true
true
} catch (e: InsufficientBalanceException) {
return false
false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import java.util.*
*/
fun Random.generateToken () : String{
val randomicNumber = this.nextInt(9999 - 1000) + 1000
val token = randomicNumber.toString()

return token
return randomicNumber.toString()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AccountExtractAdapter(private val transactions : List<Transaction> ) : Rec
}

class ViewHolder(itemView : View) : RecyclerView.ViewHolder (itemView){
val accountBalance : TextView? = itemView.txt_transaction
private val accountBalance : TextView? = itemView.txt_transaction

fun bindView (item : Transaction){
accountBalance?.text = item.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.support.v4.app.FragmentPagerAdapter
*/
class TabsPagerAdapter(fm: FragmentManager?) : FragmentPagerAdapter(fm) {

var mFragment = ArrayList<Fragment> ()
private var mFragment = ArrayList<Fragment> ()

fun addFragment (fragment : Fragment){
mFragment.add(fragment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LoginActivity : BaseActivity(), LoginContract.View {
@Inject
lateinit var loginPresenter: LoginContract.Presenter

private val REQUEST_DANGEROUS_PERMISSIONS_CODE = 1
private val REQUEST_PERMISSIONS = 1
private val permissions : Array<String> = arrayOf(Manifest.permission.SEND_SMS, Manifest.permission.READ_EXTERNAL_STORAGE)


Expand All @@ -43,7 +43,7 @@ class LoginActivity : BaseActivity(), LoginContract.View {
navigateTo(MainActivity::class.java)
}

PermissionManager.requestPermissions (this, permissions, REQUEST_DANGEROUS_PERMISSIONS_CODE )
PermissionManager.requestPermissions (this, permissions, REQUEST_PERMISSIONS)


val phoneNumberMask = SimpleMaskFormatter("+NN (NN) NNNNN-NNNN")
Expand All @@ -56,7 +56,7 @@ class LoginActivity : BaseActivity(), LoginContract.View {

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {

if(requestCode == REQUEST_DANGEROUS_PERMISSIONS_CODE){
if(requestCode == REQUEST_PERMISSIONS){
if(grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED){

}else{
Expand All @@ -75,7 +75,7 @@ class LoginActivity : BaseActivity(), LoginContract.View {
}

override fun showProgress() {
progress_text.text = "carregando"
progress_text.text = getString(R.string.loading)
progress_bar.visibility = View.VISIBLE
}

Expand All @@ -99,7 +99,7 @@ class LoginActivity : BaseActivity(), LoginContract.View {
!edt_login_password.text.equals("")) {
loginPresenter.login(edt_login_phone_number.text.toString(), edt_login_password.text.toString())
} else {
Toast.makeText(this, "Preencha todos os campos", Toast.LENGTH_SHORT)
Toast.makeText(this, "Preencha todos os campos", Toast.LENGTH_SHORT).show()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import kotlinx.android.synthetic.main.fragment_account_extract.*

class ExtractFragment : Fragment(), DataCallback<List<Transaction>> {

lateinit var transactions: List<Transaction>
private lateinit var transactions: List<Transaction>
lateinit var presenter: MainContract.Presenter

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -30,8 +30,7 @@ class ExtractFragment : Fragment(), DataCallback<List<Transaction>> {
}

override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = container?.inflate(R.layout.fragment_account_extract)
return view
return container?.inflate(R.layout.fragment_account_extract)
}

override fun onResume() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class MainFragment : Fragment(), DataCallback<List<Account>> {
}

override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater?.inflate(R.layout.fragment_main, container, false)
return view
return inflater?.inflate(R.layout.fragment_main, container, false)
}

override fun onResume() {
Expand All @@ -53,6 +52,8 @@ class MainFragment : Fragment(), DataCallback<List<Account>> {
this_month.text = date.formatter("MMM")
this_year.text = date.formatter("yyyy")
day_of_week.text = date.dayOfWeek()

update()
}
}

Expand All @@ -61,7 +62,7 @@ class MainFragment : Fragment(), DataCallback<List<Account>> {
}

fun update() {
val preferences = SharedPreferencesHelper(this?.activity)
val preferences = SharedPreferencesHelper(this.activity)
if (preferences.getBitcoinQuotation().isNotEmpty() && preferences.getBritaQuotation().isNotEmpty()) {
txt_brita_salePrice.text = JSONObject(preferences.getBritaQuotation()).get(BaseConstants.SALE_PRICE).toString().toDouble().roundTo(2).toString()
txt_brita_purchase_quot.text = JSONObject(preferences.getBritaQuotation()).get(BaseConstants.PURCHASE_QUOTATION).toString().toDouble().roundTo(2).toString()
Expand Down
Loading

0 comments on commit 202ce0d

Please sign in to comment.