Update Currency management

feature/top10
Aurelien Hubert 7 years ago
parent fe6aef088d
commit ad815ea029
  1. 15
      app/src/main/java/net/pokeranalytics/android/ui/fragment/CurrenciesFragment.kt
  2. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt

@ -1,6 +1,7 @@
package net.pokeranalytics.android.ui.fragment
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -16,12 +17,14 @@ import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.SeparatorRowRepresentable
import net.pokeranalytics.android.util.Preferences
import java.util.*
class CurrenciesFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate {
companion object {
const val INTENT_CURRENCY_CODE = "INTENT_CURRENCY_CODE"
val rowRepresentation : List<RowRepresentable> by lazy {
val rows = ArrayList<RowRepresentable>()
rows.addAll(mostUsedCurrencies)
@ -30,9 +33,8 @@ class CurrenciesFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataS
rows
}
val mostUsedCurrencyCodes = arrayListOf("EUR", "USD", "CAD", "GBP", "AUD", "CNY")
val systemCurrencies = Currency.getAvailableCurrencies()
private val mostUsedCurrencyCodes = arrayListOf("EUR", "USD", "CAD", "GBP", "AUD", "CNY")
private val systemCurrencies = Currency.getAvailableCurrencies()
private val mostUsedCurrencies = this.mostUsedCurrencyCodes.map { code ->
CurrencyRow(
@ -89,8 +91,9 @@ class CurrenciesFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataS
// RowRepresentableDelegate
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
Preferences.setCurrencyCode((row as CurrencyRow).currency.currencyCode, this.context!!)
this.activity?.setResult(Activity.RESULT_OK)
val intent = Intent()
intent.putExtra(INTENT_CURRENCY_CODE, (row as CurrencyRow).currency.currencyCode)
this.activity?.setResult(Activity.RESULT_OK, intent)
this.activity?.finish()
}

@ -76,9 +76,12 @@ class SettingsFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Sta
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == SettingsFragment.REQUEST_CODE_CURRENCY && resultCode == Activity.RESULT_OK) {
data?.let {
Preferences.setCurrencyCode(data.getStringExtra(CurrenciesFragment.INTENT_CURRENCY_CODE), requireContext())
settingsAdapterRow.refreshRow(SettingRow.CURRENCY)
}
}
}
override fun adapterRows(): List<RowRepresentable>? {
return SettingsFragment.rowRepresentation

Loading…
Cancel
Save