|
|
|
|
@ -4,7 +4,10 @@ import android.app.Activity.RESULT_OK |
|
|
|
|
import android.content.Intent |
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.view.View |
|
|
|
|
import io.realm.kotlin.where |
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
import kotlinx.coroutines.GlobalScope |
|
|
|
|
import kotlinx.coroutines.delay |
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.model.realm.Bankroll |
|
|
|
|
import net.pokeranalytics.android.ui.activity.CurrenciesActivity |
|
|
|
|
@ -37,8 +40,8 @@ class BankrollDataFragment : EditableDataFragment(), StaticRowRepresentableDataS |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private lateinit var defaultCurrency: Currency |
|
|
|
|
|
|
|
|
|
val rows = ArrayList<RowRepresentable>() |
|
|
|
|
private val rows = ArrayList<RowRepresentable>() |
|
|
|
|
private var isRefreshingRate = false |
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
|
@ -89,6 +92,14 @@ class BankrollDataFragment : EditableDataFragment(), StaticRowRepresentableDataS |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun boolForRow(row: RowRepresentable): Boolean { |
|
|
|
|
return when(row) { |
|
|
|
|
BankrollRow.LIVE -> !bankroll.live |
|
|
|
|
BankrollRow.REFRESH_RATE -> isRefreshingRate |
|
|
|
|
else -> super.boolForRow(row) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor>? { |
|
|
|
|
return when (row) { |
|
|
|
|
SimpleRow.NAME -> row.editingDescriptors(mapOf("defaultValue" to this.bankroll.name)) |
|
|
|
|
@ -97,13 +108,20 @@ class BankrollDataFragment : EditableDataFragment(), StaticRowRepresentableDataS |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun boolForRow(row: RowRepresentable): Boolean { |
|
|
|
|
return super.boolForRow(row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
|
when (row) { |
|
|
|
|
BankrollRow.CURRENCY -> CurrenciesActivity.newInstanceForResult(this@BankrollDataFragment, BankrollDataFragment.REQUEST_CODE_CURRENCY) |
|
|
|
|
BankrollRow.REFRESH_RATE -> { |
|
|
|
|
isRefreshingRate = true |
|
|
|
|
|
|
|
|
|
//TODO: Call web-service to get the currency rate |
|
|
|
|
GlobalScope.launch(Dispatchers.Main) { |
|
|
|
|
delay(1500) |
|
|
|
|
isRefreshingRate = false |
|
|
|
|
rowRepresentableAdapter.refreshRow(BankrollRow.REFRESH_RATE) |
|
|
|
|
} |
|
|
|
|
rowRepresentableAdapter.refreshRow(BankrollRow.REFRESH_RATE) |
|
|
|
|
} |
|
|
|
|
else -> super.onRowSelected(position, row, fromAction) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -114,14 +132,17 @@ class BankrollDataFragment : EditableDataFragment(), StaticRowRepresentableDataS |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Init data |
|
|
|
|
*/ |
|
|
|
|
private fun initData() { |
|
|
|
|
|
|
|
|
|
defaultCurrency = Currency.getInstance(Preferences.getCurrencyLocale(this.parentActivity)) |
|
|
|
|
|
|
|
|
|
if (bankroll.currency == null) { |
|
|
|
|
val realm = getRealm() |
|
|
|
|
val currency = realm.where<net.pokeranalytics.android.model.realm.Currency>().equalTo("code", defaultCurrency.currencyCode).findFirst() |
|
|
|
|
bankroll.currency = currency |
|
|
|
|
if (!isUpdating) { |
|
|
|
|
bankroll.currency = net.pokeranalytics.android.model.realm.Currency() |
|
|
|
|
bankroll.currency?.code = defaultCurrency.currencyCode |
|
|
|
|
bankroll.currency?.rate = 1.0 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|