-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
55 additions
and
10 deletions.
There are no files selected for viewing
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
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
27 changes: 27 additions & 0 deletions
27
core/src/main/java/com/techchallenge/core/util/price/MarketPriceFormatter.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.techchallenge.core.util.price | ||
|
||
import com.techchallenge.core.util.ext.removeNonDigitCharacters | ||
import javax.inject.Inject | ||
|
||
class MarketPriceFormatter @Inject constructor() : PriceFormatter { | ||
override fun format(price: Float?): String { | ||
return if (price != null) String.format(PATTERN_PRICE, price) else EMPTY | ||
} | ||
|
||
override fun format(price: String?): String { | ||
val priceOnlyDigits = price?.removeNonDigitCharacters() | ||
return if (!priceOnlyDigits.isNullOrEmpty()) { | ||
format(priceOnlyDigits.replace(DOT, COMMA).toFloat()) | ||
} else { | ||
EMPTY | ||
} | ||
} | ||
|
||
companion object { | ||
private const val CURRENCY = "TL" | ||
private const val PATTERN_PRICE = "%.2f $CURRENCY" | ||
private const val EMPTY = "" | ||
private const val COMMA = "," | ||
private const val DOT = "." | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
core/src/main/java/com/techchallenge/core/util/price/PriceFormatter.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.techchallenge.core.util.price | ||
|
||
interface PriceFormatter { | ||
fun format(price: Float?): String | ||
fun format(price: String?): String | ||
} |
9 changes: 6 additions & 3 deletions
9
data/src/main/java/com/techchallenge/data/MarketimViewItemMapper.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