Skip to content
This repository has been archived by the owner on Aug 15, 2021. It is now read-only.

Commit

Permalink
2020-05-02 Version 2.3.0: Refactored project structure and updated UI
Browse files Browse the repository at this point in the history
  • Loading branch information
fartem committed May 2, 2020
1 parent ecbccc8 commit 79d4bd4
Show file tree
Hide file tree
Showing 23 changed files with 88 additions and 54 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName '2.2.4'
versionName '2.3.0'
testInstrumentationRunner "com.smlnskgmail.jaman.cryptotracker.runner.AndroidJacocoTestRunner"

buildConfigField 'String', 'API', "\"\""
Expand Down Expand Up @@ -59,7 +59,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
implementation "androidx.preference:preference:1.1.0"
implementation "androidx.preference:preference:1.1.1"

// Dagger 2
implementation 'com.google.dagger:dagger:2.24'
Expand All @@ -70,7 +70,7 @@ dependencies {
implementation 'org.mapdb:mapdb:2.0-beta13'

// AdaptiveRecyclerView
implementation 'com.smlnskgmail.jaman:adaptiverecyclerview:0.1.2'
implementation 'com.smlnskgmail.jaman:adaptiverecyclerview:1.1.0'

// Retrofit
//noinspection GradleDependency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class BaseThemeFragment : Fragment() {
val contextThemeWrapper = ContextThemeWrapper(
activity,
PreferencesManager.theme(
context!!
requireContext()
).themeResId
)
val localInflater = inflater.cloneInContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.smlnskgmail.jaman.cryptotracker.model.api.currency

interface CurrencyListing {

fun currentPrice(): CurrencyPriceValue
fun changeHour(): CurrencyPriceValue
fun currentPrice(): CurrencyPrice
fun changeHour(): CurrencyPricePercentChangeDay

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.smlnskgmail.jaman.cryptotracker.model.api.currency

import java.text.NumberFormat
import java.util.*

class CurrencyPrice(
private val price: Float
) {

fun value(): Float {
return price
}

override fun toString(): String {
val numberFormat = NumberFormat.getCurrencyInstance(
Locale.US
)
return numberFormat.format(
price
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package com.smlnskgmail.jaman.cryptotracker.model.api.currency

import java.text.DecimalFormat

class CurrencyPriceValue(
private val price: Float
class CurrencyPricePercentChangeDay(
private val value: Float
) {

fun value(): Float {
return price
return value
}

override fun toString(): String {
return DecimalFormat("0.###").format(price)
return "${DecimalFormat("0.##").format(value)}%"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class MapDbCurrencySerializer(
input: DataInput,
available: Int
): Currency {
return currencyInstanceProvider.currencyFrom(input)
return currencyInstanceProvider.currencyFrom(
input
)
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.smlnskgmail.jaman.cryptotracker.model.impl.currency.coinmarketcup

import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyListing
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyPriceValue
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyPricePercentChangeDay
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyPrice

data class CmcCurrencyListing(
private val currentPrice: CurrencyPriceValue,
private val changeHourPrice: CurrencyPriceValue
private val currentPrice: CurrencyPrice,
private val changeHourPrice: CurrencyPricePercentChangeDay
) : CurrencyListing {

companion object {
Expand All @@ -15,11 +16,11 @@ data class CmcCurrencyListing(

}

override fun currentPrice(): CurrencyPriceValue {
override fun currentPrice(): CurrencyPrice {
return currentPrice
}

override fun changeHour(): CurrencyPriceValue {
override fun changeHour(): CurrencyPricePercentChangeDay {
return changeHourPrice
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package com.smlnskgmail.jaman.cryptotracker.model.impl.currency.coinmarketcup.ca

import com.smlnskgmail.jaman.cryptotracker.model.api.cache.CurrencyInstanceProvider
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.Currency
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyPriceValue
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyPricePercentChangeDay
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyPrice
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyType
import com.smlnskgmail.jaman.cryptotracker.model.impl.currency.coinmarketcup.CmcCurrency
import com.smlnskgmail.jaman.cryptotracker.model.impl.currency.coinmarketcup.CmcCurrencyListing
Expand Down Expand Up @@ -46,10 +47,10 @@ class CmcCurrencyMapDbInstanceProvider : CurrencyInstanceProvider {
reader.readUTF(),
reader.readUTF(),
CmcCurrencyListing(
CurrencyPriceValue(
CurrencyPrice(
reader.readFloat()
),
CurrencyPriceValue(
CurrencyPricePercentChangeDay(
reader.readFloat()
)
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.smlnskgmail.jaman.cryptotracker.model.impl.currency.coinmarketcup.deserializers

import com.google.gson.Gson
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.reflect.TypeToken
import com.google.gson.JsonObject
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyPricePercentChangeDay
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyPrice
import com.smlnskgmail.jaman.cryptotracker.model.impl.currency.coinmarketcup.CmcCurrencyListing
import com.smlnskgmail.jaman.cryptotracker.model.impl.currency.coinmarketcup.retrofit.responses.CurrencyListingResponse
import java.lang.reflect.Type
Expand All @@ -16,18 +17,19 @@ class CurrencyListingResponseDeserializer : JsonDeserializer<CurrencyListingResp
typeOfT: Type?,
context: JsonDeserializationContext?
): CurrencyListingResponse {
val gson = Gson()

val currencyListingTypeToken = object : TypeToken<CmcCurrencyListing>() {}.type

val dataJson = json!!.asJsonObject.get("data")
val quoteUSD = dataJson.asJsonObject.entrySet().first()
.value.asJsonObject
.get("quote").asJsonObject
.get("USD")
val currencyListing: CmcCurrencyListing = gson.fromJson(
quoteUSD,
currencyListingTypeToken
.get("USD") as JsonObject

val currencyListing = CmcCurrencyListing(
CurrencyPrice(
quoteUSD.get("price").asFloat
),
CurrencyPricePercentChangeDay(
quoteUSD.get("percent_change_24h").asFloat
)
)
return CurrencyListingResponse(
currencyListing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.reflect.TypeToken
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.Currency
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyPriceValue
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyPricePercentChangeDay
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyPrice
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyType
import com.smlnskgmail.jaman.cryptotracker.model.impl.currency.coinmarketcup.CmcCurrency
import com.smlnskgmail.jaman.cryptotracker.model.impl.currency.coinmarketcup.CmcCurrencyListing
Expand Down Expand Up @@ -40,14 +41,14 @@ class CurrencyResponseDeserializer : JsonDeserializer<CurrencyResponse> {
.get("USD")
.asJsonObject
val currencyListing = CmcCurrencyListing(
CurrencyPriceValue(
CurrencyPrice(
priceInfo.get(
"price"
).asFloat
),
CurrencyPriceValue(
CurrencyPricePercentChangeDay(
priceInfo.get(
"percent_change_1h"
"percent_change_24h"
).asFloat
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.smlnskgmail.jaman.cryptotracker.model.impl.currency.debug

import com.smlnskgmail.jaman.cryptotracker.model.api.currency.Currency
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyListing
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyPriceValue
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.CurrencyType
import com.smlnskgmail.jaman.cryptotracker.model.api.currency.*

// CPD-OFF
class DebugCurrency(
Expand Down Expand Up @@ -48,14 +45,14 @@ class DebugCurrency(
if (currencyListing == null) {
currencyListing = object :
CurrencyListing {
override fun currentPrice(): CurrencyPriceValue {
return CurrencyPriceValue(
override fun currentPrice(): CurrencyPrice {
return CurrencyPrice(
1000.751f
)
}

override fun changeHour(): CurrencyPriceValue {
return CurrencyPriceValue(
override fun changeHour(): CurrencyPricePercentChangeDay {
return CurrencyPricePercentChangeDay(
0.19f
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class CurrenciesListPresenterImpl : CurrenciesListPresenter {
currencies
)
} else {
currenciesListView.showCurrencies(
emptyList()
)
currenciesListView.showLoadError()
}
action()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BottomSheetCurrencyInfo : BaseThemeBottomSheet(), CurrencyInfoView {
currencyInfoPresenter = CurrencyInfoPresenterImpl()
currencyInfoPresenter.init(
this,
arguments!!.getSerializable("currency") as Currency
requireArguments().getSerializable("currency") as Currency
)
}

Expand All @@ -41,13 +41,13 @@ class BottomSheetCurrencyInfo : BaseThemeBottomSheet(), CurrencyInfoView {
}

override fun context(): Context {
return context!!
return requireContext()
}

override fun showCurrencyInfo(currency: Currency) {
currency_image.setImageDrawable(
ContextCompat.getDrawable(
context!!,
requireContext(),
currency.currencyType().iconResId
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CurrenciesListFragment : BaseThemeFragment(), CurrenciesListView {
currencies_list_refresh.isEnabled = false
currencies_list_refresh.setColorSchemeColors(
ContextCompat.getColor(
context!!,
requireContext(),
R.color.colorAccent
)
)
Expand Down Expand Up @@ -127,7 +127,7 @@ class CurrenciesListFragment : BaseThemeFragment(), CurrenciesListView {
val bottomSheetCurrencyInfo = BottomSheetCurrencyInfo()
bottomSheetCurrencyInfo.arguments = arguments
bottomSheetCurrencyInfo.show(
activity!!.supportFragmentManager,
requireActivity().supportFragmentManager,
BottomSheetCurrencyInfo::class.java.canonicalName
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ class CurrencyHolder(
accentColor
)
itemView.currency_refresh_listing.setOnClickListener {
currencyRefreshClickTarget.onCurrencyRefreshClick(currency)
currencyRefreshClickTarget.onCurrencyRefreshClick(
currency
)
}

itemView.setOnClickListener {
currencyClickTarget.onCurrencyClick(currency)
currencyClickTarget.onCurrencyClick(
currency
)
}

showCurrencyListing(
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/bottom_sheet_currency.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
style="@style/AppCurrencyItemTextPrimary"
app:layout_constraintBottom_toBottomOf="@+id/currency_name"
app:layout_constraintEnd_toEndOf="parent"
tools:text="8,891.17 $" />
tools:text="$8,891.17" />

<TextView
android:id="@+id/currency_first_historical_data"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_currencies_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
xmlns:arv="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/currencies_list_root"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="?attr/colorBackground">

<ProgressBar
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/item_currency.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
app:layout_constraintBottom_toBottomOf="@+id/currency_symbol"
app:layout_constraintEnd_toStartOf="@+id/currency_refresh_listing"
app:layout_constraintTop_toTopOf="@+id/currency_symbol"
tools:text="8,891.17 $" />
tools:text="$8,891.17" />

<TextView
android:id="@+id/currency_price_at_last_hour"
Expand All @@ -53,7 +53,7 @@
app:layout_constraintEnd_toEndOf="@+id/currency_price"
app:layout_constraintTop_toBottomOf="@+id/currency_price"
tools:textColor="@color/colorCurrencyPriceUp"
tools:text="0.191 $" />
tools:text="0.191%" />

<ImageView
android:id="@+id/currency_refresh_listing"
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
buildscript {
ext.kotlin_version = '1.3.70'
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "de.aaschmid:gradle-cpd-plugin:3.1"
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.4'
Expand Down
Binary file modified media/screenshots/screenshot_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/screenshots/screenshot_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/screenshots/screenshot_03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/screenshots/screenshot_04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 79d4bd4

Please sign in to comment.