Fixes small issues with transactions and data edition

od
Laurent 6 years ago
parent f32d8eee3c
commit dc41ad36e6
  1. 38
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/CustomFieldDataFragment.kt
  3. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/EditableDataFragment.kt
  4. 7
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/TransactionDataFragment.kt
  5. 1
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/TransactionRow.kt

@ -11,6 +11,10 @@ import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.DiffUtil
import com.crashlytics.android.Crashlytics
import kotlinx.android.synthetic.main.fragment_session.*
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.calculus.bankroll.BankrollReportManager
import net.pokeranalytics.android.exceptions.PAIllegalStateException
@ -31,6 +35,7 @@ import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableDiffCallback
import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager
import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow
import net.pokeranalytics.android.ui.view.rowrepresentable.TransactionRow
import net.pokeranalytics.android.ui.viewmodel.SessionViewModel
import net.pokeranalytics.android.util.extensions.findById
import net.pokeranalytics.android.util.extensions.getNextMinuteInMilliseconds
@ -226,20 +231,43 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate {
}
override fun onRowValueChanged(value: Any?, row: RowRepresentable) {
sessionHasBeenUserCustomized = true
this.sessionHasBeenUserCustomized = true
try {
currentSession.updateValue(value, row)
this.currentSession.updateValue(value, row)
} catch (e: PAIllegalStateException) {
Toast.makeText(context, e.message, Toast.LENGTH_LONG).show()
return
}
sessionAdapter.refreshRow(row)
this.sessionAdapter.refreshRow(row)
when (row) {
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT, SessionRow.BUY_IN, SessionRow.TIPS,
SessionRow.START_DATE, SessionRow.END_DATE, SessionRow.BANKROLL, SessionRow.BREAK_TIME -> updateSessionUI()
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT,
SessionRow.BUY_IN, SessionRow.TIPS, SessionRow.START_DATE,
SessionRow.END_DATE, SessionRow.BANKROLL, SessionRow.BREAK_TIME -> updateSessionUI()
}
}
/***
* Selects the next row to ease the data capture
*/
private fun selectNextRow(currentRow: RowRepresentable) {
if (this.viewModel.sessionId == null) {
GlobalScope.launch(Dispatchers.Main) {
delay(200)
when (currentRow) {
// TransactionRow.BANKROLL -> onRowSelected(0, TransactionRow.TYPE)
// TransactionRow.TYPE -> onRowSelected(0, TransactionRow.AMOUNT)
// TransactionRow.AMOUNT -> onRowSelected(0, TransactionRow.DATE)
// TransactionRow.DATE -> onRowSelected(0, TransactionRow.COMMENT)
}
}
}
}
/**
* Update the UI with the session data
* Should be called after the initialization of the session

@ -130,7 +130,7 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa
override fun boolForRow(row: RowRepresentable): Boolean {
return when (row) {
CustomFieldRow.COPY_ON_DUPLICATE -> customField.duplicateValue
CustomFieldRow.TYPE -> isUpdating
// CustomFieldRow.TYPE -> isUpdating // very weird
else -> super.boolForRow(row)
}
}

@ -50,8 +50,8 @@ open class EditableDataFragment : DataManagerFragment(), RowRepresentableDelegat
// When creating an object, open automatically the keyboard for the first row
if (!deleteButtonShouldAppear && shouldOpenKeyboard) {
val row = dataSource.adapterRows()?.firstOrNull()
row?.let {
onRowSelected(0, it)
if (row != null && this.viewModel.primaryKey == null) {
onRowSelected(0, row)
}
}
}

@ -21,6 +21,7 @@ import net.pokeranalytics.android.util.extensions.round
import net.pokeranalytics.android.util.extensions.shortDate
import net.pokeranalytics.android.util.extensions.sorted
import java.util.*
import kotlin.math.abs
/**
* Custom EditableDataFragment to manage the Transaction data
@ -50,7 +51,7 @@ class TransactionDataFragment : EditableDataFragment(), StaticRowRepresentableDa
return when (row) {
TransactionRow.BANKROLL -> this.transaction.bankroll?.name ?: NULL_TEXT
TransactionRow.TYPE -> this.transaction.type?.name ?: NULL_TEXT
TransactionRow.AMOUNT -> if (this.transaction.amount != 0.0) this.transaction.amount.round() else NULL_TEXT
TransactionRow.AMOUNT -> if (this.transaction.amount != 0.0) abs(this.transaction.amount).round() else NULL_TEXT
TransactionRow.COMMENT -> if (this.transaction.comment.isNotEmpty()) this.transaction.comment else NULL_TEXT
TransactionRow.DATE -> this.transaction.date.shortDate()
else -> super.stringForRow(row)
@ -71,7 +72,7 @@ class TransactionDataFragment : EditableDataFragment(), StaticRowRepresentableDa
"data" to getRealm().sorted<TransactionType>()
)
)
TransactionRow.AMOUNT -> row.editingDescriptors(mapOf("defaultValue" to (if (this.transaction.amount != 0.0) this.transaction.amount.round() else "")))
TransactionRow.AMOUNT -> row.editingDescriptors(mapOf("defaultValue" to (if (this.transaction.amount != 0.0) abs(this.transaction.amount).round() else "")))
TransactionRow.COMMENT -> row.editingDescriptors(mapOf("defaultValue" to this.transaction.comment))
else -> super.editDescriptors(row)
}
@ -120,7 +121,7 @@ class TransactionDataFragment : EditableDataFragment(), StaticRowRepresentableDa
super.willSaveData()
val additive = this.transaction.type?.additive ?: true
if (!additive) {
this.transaction.amount *= -1
this.transaction.amount = abs(this.transaction.amount) * -1
}
}

@ -73,7 +73,6 @@ enum class TransactionRow : RowRepresentable, DefaultEditDataSource {
defaultValue,
inputType = InputType.TYPE_CLASS_NUMBER
or InputType.TYPE_NUMBER_FLAG_DECIMAL
or InputType.TYPE_NUMBER_FLAG_SIGNED
))
}
COMMENT -> {

Loading…
Cancel
Save