Skip to content

Commit

Permalink
Fixing crash when saving period without values
Browse files Browse the repository at this point in the history
  • Loading branch information
MayconCardoso committed Mar 11, 2021
1 parent a3468ef commit 0c8757e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme">


<activity android:name=".SingleContainerActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
ANDROID_LIFECYCLE = '2.3.0'
ANDROID_LIFECYCLE_EXTENSION = '2.2.0'

VIEW_MATERIAL_DESIGN = '1.4.0-alpha01'
VIEW_MATERIAL_DESIGN = '1.1.0'
VIEW_SWIPE_REFRESH = '1.2.0-alpha01'
VIEW_CONSTRAINT_LAYOUT = '2.0.4'
VIEW_RECYCLER_VIEW = '1.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import com.mctech.library.view.ktx.getValue
import com.mctech.stocktradetracking.domain.stock_share.entity.StockShare
import com.mctech.stocktradetracking.feature.stock_share.StockShareNavigator
import com.mctech.stocktradetracking.feature.stock_share.databinding.FragmentStockShareBuyBinding
import com.mctech.stocktradetracking.library.design_system.entension.getDoubleValue
import com.mctech.stocktradetracking.library.design_system.entension.getLongValue
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel

Expand Down Expand Up @@ -73,8 +75,8 @@ class StockShareBuyFragment : Fragment() {
viewModel.interact(
StockShareBuyInteraction.AddPosition(
binding.etShareCode.getValue(),
binding.etShareAmount.getValue().toLong(),
binding.etSharePrice.getValue().toDouble()
binding.etShareAmount.getLongValue(),
binding.etSharePrice.getDoubleValue()
)
)

Expand All @@ -89,8 +91,8 @@ class StockShareBuyFragment : Fragment() {

private fun computeInvestment() {
binding?.let { binding ->
val purchasePrice = binding.etSharePrice.getValue().toDoubleOrNull() ?: 0.0
val shareAmount = binding.etShareAmount.getValue().toLongOrNull() ?: 0
val purchasePrice = binding.etSharePrice.getDoubleValue()
val shareAmount = binding.etShareAmount.getLongValue()

val stockShare = StockShare(
code = binding.etShareCode.getValue(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import com.mctech.stocktradetracking.feature.stock_share.R
import com.mctech.stocktradetracking.feature.stock_share.StockShareNavigator
import com.mctech.stocktradetracking.feature.stock_share.databinding.FragmentStockShareEditPriceBinding
import com.mctech.stocktradetracking.feature.stock_share.stockShareFromBundle
import com.mctech.stocktradetracking.library.design_system.entension.getDoubleValue
import com.mctech.stocktradetracking.library.design_system.entension.getLongValue
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel

Expand Down Expand Up @@ -124,9 +126,9 @@ class StockShareEditPositionFragment : Fragment() {
viewModel.interact(
StockShareEditPositionInteraction.UpdateStockPrice(
binding.etShareCode.getValue(),
binding.etShareAmount.getValue().toLong(),
binding.etSharePurchasePrice.getValue().toDouble(),
binding.etSharePrice.getValue().toDouble()
binding.etShareAmount.getLongValue(),
binding.etSharePurchasePrice.getDoubleValue(),
binding.etSharePrice.getDoubleValue()
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.mctech.library.keyboard.visibilitymonitor.extentions.closeKeyboard
import com.mctech.library.view.ktx.getValue
import com.mctech.stocktradetracking.feature.timeline_balance.TimelineBalanceNavigator
import com.mctech.stocktradetracking.feature.timeline_balance.databinding.FragmentTimelineAddPeriodBinding
import com.mctech.stocktradetracking.library.design_system.entension.getDoubleValue
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel

Expand Down Expand Up @@ -52,8 +53,8 @@ class TimelineBalanceAddPeriodFragment : Fragment() {
viewModel.interact(
TimelineBalanceAddInteraction.CreatePeriod(
binding.etPeriodTag.getValue(),
binding.etInvestment.getValue().toDouble(),
binding.etProfit.getValue().toDouble()
binding.etInvestment.getDoubleValue(),
binding.etProfit.getDoubleValue()
)
)

Expand All @@ -65,4 +66,6 @@ class TimelineBalanceAddPeriodFragment : Fragment() {
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.mctech.stocktradetracking.domain.timeline_balance.entity.TimelineBala
import com.mctech.stocktradetracking.feature.timeline_balance.TimelineBalanceNavigator
import com.mctech.stocktradetracking.feature.timeline_balance.databinding.FragmentTimelineEditPeriodBinding
import com.mctech.stocktradetracking.feature.timeline_balance.timelinePeriodFromBundle
import com.mctech.stocktradetracking.library.design_system.entension.getDoubleValue
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel

Expand Down Expand Up @@ -73,9 +74,9 @@ class TimelineBalanceEditPeriodFragment : Fragment() {
viewModel.interact(
TimelineBalanceEditInteraction.EditPeriod(
binding.etPeriodTag.getValue(),
binding.etInvestment.getValue().toDouble(),
binding.etProfit.getValue().toDouble(),
binding.etFinalBalance.getValue().toDouble()
binding.etInvestment.getDoubleValue(),
binding.etProfit.getDoubleValue(),
binding.etFinalBalance.getDoubleValue()
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mctech.stocktradetracking.library.design_system.entension

import android.widget.EditText

fun EditText.getDoubleValue(): Double {
return text.toString().takeIf { it.isNotBlank() }?.toDouble() ?: 0.0
}

fun EditText.getLongValue(): Long {
return text.toString().takeIf { it.isNotBlank() }?.toLong() ?: 0
}

0 comments on commit 0c8757e

Please sign in to comment.