Add BottomSheet sum for Buy In management

dev_raz_wip
Aurelien Hubert 7 years ago
parent 1248aa213e
commit e2fefb778f
  1. 58
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  2. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetFragment.kt
  3. 124
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetSumFragment.kt
  4. 7
      app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt
  5. 12
      app/src/main/java/net/pokeranalytics/android/util/Extensions.kt
  6. 119
      app/src/main/res/layout/bottom_sheet_sum.xml
  7. 17
      app/src/main/res/values/styles.xml

@ -17,6 +17,7 @@ import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.SessionRow import net.pokeranalytics.android.ui.view.SessionRow
import net.pokeranalytics.android.util.data.sessionDao import net.pokeranalytics.android.util.data.sessionDao
import net.pokeranalytics.android.util.short import net.pokeranalytics.android.util.short
import net.pokeranalytics.android.util.toCurrency
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
@ -202,6 +203,7 @@ open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource
override fun stringForRow(row: RowRepresentable): String { override fun stringForRow(row: RowRepresentable): String {
return when (row) { return when (row) {
SessionRow.BUY_IN -> buyin.toCurrency()
SessionRow.BLINDS -> if (cgSmallBlind != null && cgBigBlind != null) "$cgSmallBlind / $cgBigBlind" else "--" SessionRow.BLINDS -> if (cgSmallBlind != null && cgBigBlind != null) "$cgSmallBlind / $cgBigBlind" else "--"
SessionRow.GAME -> game?.title ?: "--" SessionRow.GAME -> game?.title ?: "--"
SessionRow.LOCATION -> location?.title ?: "--" SessionRow.LOCATION -> location?.title ?: "--"
@ -231,26 +233,35 @@ open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource
val data = ArrayList<BottomSheetData>() val data = ArrayList<BottomSheetData>()
when (row) { when (row) {
SessionRow.BUY_IN -> {
// Add first & second buttons values, current value & set the 2 edit texts
data.add(BottomSheetData(100.0 * (cgBigBlind ?: 0.0)))
data.add(BottomSheetData(200.0 * (cgBigBlind ?: 0.0)))
data.add(BottomSheetData(buyin))
data.add(BottomSheetData("",inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL))
data.add(BottomSheetData("",inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL))
}
SessionRow.TIPS -> {
// Disable the buttons with value = 0, add current value & set the 2 edit texts
// TODO: manage tips
data.add(BottomSheetData(cgSmallBlind ?: 0.0))
data.add(BottomSheetData(cgBigBlind ?: 0.0))
data.add(BottomSheetData(0))
data.add(BottomSheetData("", inputType = InputType.TYPE_CLASS_NUMBER))
data.add(BottomSheetData("", inputType = InputType.TYPE_CLASS_NUMBER))
}
SessionRow.GAME -> { SessionRow.GAME -> {
data.add(BottomSheetData(game, inputType = InputType.TYPE_NULL, data = LiveData.GAME.items(realm))) // Add current game & games list
data.add(BottomSheetData(game, data = LiveData.GAME.items(realm)))
} }
SessionRow.LOCATION -> { SessionRow.LOCATION -> {
data.add( // Add current location and locations list
BottomSheetData( data.add(BottomSheetData(location, data = LiveData.LOCATION.items(realm)))
location,
inputType = InputType.TYPE_NULL,
data = LiveData.LOCATION.items(realm)
)
)
} }
SessionRow.BANKROLL -> { SessionRow.BANKROLL -> {
data.add( // Add current bankroll and bankrolls list
BottomSheetData( data.add(BottomSheetData(bankroll, data = LiveData.BANKROLL.items(realm)))
bankroll,
inputType = InputType.TYPE_NULL,
data = LiveData.BANKROLL.items(realm)
)
)
} }
SessionRow.BLINDS -> { SessionRow.BLINDS -> {
data.add(BottomSheetData(cgSmallBlind, R.string.smallblind, InputType.TYPE_CLASS_NUMBER)) data.add(BottomSheetData(cgSmallBlind, R.string.smallblind, InputType.TYPE_CLASS_NUMBER))
@ -267,6 +278,13 @@ open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource
override fun updateValue(value: Any?, row: RowRepresentable) { override fun updateValue(value: Any?, row: RowRepresentable) {
realm.beginTransaction() realm.beginTransaction()
when (row) { when (row) {
SessionRow.BUY_IN -> {
val localResult = if (result != null) result as Result else realm.createObject(Result::class.java)
localResult.buyin = value as Double
result = localResult
}
SessionRow.GAME -> game = value as Game? SessionRow.GAME -> game = value as Game?
SessionRow.BANKROLL -> bankroll = value as Bankroll? SessionRow.BANKROLL -> bankroll = value as Bankroll?
SessionRow.LOCATION -> location = value as Location? SessionRow.LOCATION -> location = value as Location?
@ -285,19 +303,15 @@ open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource
} }
//TODO: Update //TODO: Update
SessionRow.START_DATE -> if (value is Date) { SessionRow.START_DATE -> if (value is Date) {
/* val timeFrameToUpdate = if (timeFrame != null) timeFrame as TimeFrame else realm.createObject(TimeFrame::class.java)
val timeFrameToUpdate = timeFrame ?: TimeFrame()
timeFrameToUpdate.setDate(value, null) timeFrameToUpdate.setDate(value, null)
timeFrame = timeFrameToUpdate timeFrame = timeFrameToUpdate
*/
} }
//TODO: Update //TODO: Update
SessionRow.END_DATE -> if (value is Date) { SessionRow.END_DATE -> if (value is Date) {
/* val timeFrameToUpdate = if (timeFrame != null) timeFrame as TimeFrame else realm.createObject(TimeFrame::class.java)
val timeFrameToUpdate = timeFrame ?: TimeFrame() timeFrameToUpdate.setDate(null, value)
timeFrameToUpdate.setDate(timeFrame?.startDate ?: Date(), value)
timeFrame = timeFrameToUpdate timeFrame = timeFrameToUpdate
*/
} }
} }
realm.commitTransaction() realm.commitTransaction()

@ -15,10 +15,10 @@ enum class BottomSheetType {
NONE, NONE,
LIST, LIST,
DOUBLE_LIST, DOUBLE_LIST,
DATE,
GRID, GRID,
EDIT_TEXT, EDIT_TEXT,
DOUBLE_EDIT_TEXT, DOUBLE_EDIT_TEXT,
SUM
} }
interface BottomSheetDelegate { interface BottomSheetDelegate {
@ -48,6 +48,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
BottomSheetType.DOUBLE_LIST -> BottomSheetDoubleListFragment() BottomSheetType.DOUBLE_LIST -> BottomSheetDoubleListFragment()
BottomSheetType.EDIT_TEXT -> BottomSheetEditTextFragment() BottomSheetType.EDIT_TEXT -> BottomSheetEditTextFragment()
BottomSheetType.DOUBLE_EDIT_TEXT -> BottomSheetDoubleEditTextFragment() BottomSheetType.DOUBLE_EDIT_TEXT -> BottomSheetDoubleEditTextFragment()
BottomSheetType.SUM -> BottomSheetSumFragment()
else -> BottomSheetFragment() else -> BottomSheetFragment()
} }

@ -0,0 +1,124 @@
package net.pokeranalytics.android.ui.fragment.components.bottomsheet
import android.os.Bundle
import android.text.InputType
import android.view.LayoutInflater
import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.core.widget.addTextChangedListener
import kotlinx.android.synthetic.main.bottom_sheet_sum.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.util.round
import net.pokeranalytics.android.util.toCurrency
class BottomSheetSumFragment : BottomSheetFragment() {
private var value = 0.0
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initData()
initUI()
}
override fun onStart() {
super.onStart()
editText1.requestFocus()
}
override fun getValue(): Any {
return value
}
/**
* Init data
*/
private fun initData() {
}
/**
* Init UI
*/
private fun initUI() {
val data = getData()
setAddButtonVisible(false)
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_sum, view?.bottomSheetContainer, true)
if (data.size == 5) {
// Default value for the sum
val currentDefaultValue = try {
data[2].defaultValue as Double
} catch (e: Exception) {
0.0
}
currentValue.text = currentDefaultValue.toCurrency()
// First value
val defaultValue1 = try {
data[0].defaultValue as Double
} catch (e: Exception) {
0.0
}
button1.text = defaultValue1.toCurrency()
button1.visibility = if (defaultValue1 > 0) View.VISIBLE else View.GONE
button1.setOnClickListener {
bottomSheetDelegate.setValue(currentDefaultValue + defaultValue1, row)
dismiss()
}
// Second value
val defaultValue2 = try {
data[1].defaultValue as Double
} catch (e: Exception) {
0.0
}
button2.text = defaultValue2.toCurrency()
button2.visibility = if (defaultValue2 > 0) View.VISIBLE else View.GONE
button2.setOnClickListener {
bottomSheetDelegate.setValue(currentDefaultValue + defaultValue2, row)
dismiss()
}
// First edit text
data[3].hint?.let { editText1.hint = getString(it) }
editText1.inputType = data[3].inputType ?: InputType.TYPE_CLASS_TEXT
editText1.addTextChangedListener {
val valueToAdd = try {
editText1.text.toString().toDouble()
} catch (e: Exception) {
0.0
}
editText2.setText((currentDefaultValue + valueToAdd).round())
}
// Second edit text
data[4].hint?.let { editText2.hint = getString(it) }
editText2.inputType = data[4].inputType ?: InputType.TYPE_CLASS_TEXT
editText2.addTextChangedListener {
value = it.toString().toDouble()
}
editText2.setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
bottomSheetDelegate.setValue(value, row)
dismiss()
true
} else {
false
}
}
}
}
}

@ -142,10 +142,11 @@ enum class SessionRow : RowRepresentable {
override val bottomSheetType: BottomSheetType override val bottomSheetType: BottomSheetType
get() { get() {
return when (this) { return when (this) {
CASHED_OUT, BREAK_TIME -> BottomSheetType.EDIT_TEXT
BUY_IN, TIPS -> BottomSheetType.SUM
BLINDS -> BottomSheetType.DOUBLE_EDIT_TEXT BLINDS -> BottomSheetType.DOUBLE_EDIT_TEXT
GAME -> BottomSheetType.LIST GAME, LOCATION, BANKROLL -> BottomSheetType.LIST
LOCATION -> BottomSheetType.LIST TABLE_SIZE -> BottomSheetType.GRID
BANKROLL -> BottomSheetType.LIST
COMMENT -> BottomSheetType.EDIT_TEXT COMMENT -> BottomSheetType.EDIT_TEXT
else -> BottomSheetType.NONE else -> BottomSheetType.NONE
} }

@ -4,9 +4,21 @@ import android.widget.Toast
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
import java.text.DateFormat import java.text.DateFormat
import java.text.DecimalFormat
import java.util.* import java.util.*
// Double
fun Double.round(): String {
val formatter = DecimalFormat("##.##")
return formatter.format(this)
}
fun Double.toCurrency(): String {
val formatter = DecimalFormat("##.##")
return "$ ${formatter.format(this)}"
}
// Date // Date

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:background="@color/gray_darker">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button1"
style="@style/PokerAnalyticsTheme.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toStartOf="@+id/button2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="+ 1000 $" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button2"
style="@style/PokerAnalyticsTheme.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/button1"
app:layout_constraintTop_toTopOf="parent"
android:text="+ 2000 $" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/currentValue"
style="@style/PokerAnalyticsTheme.TextView.BottomSheetValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="@+id/editText1"
app:layout_constraintEnd_toStartOf="@+id/more"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/editText1"
tools:text="0 $" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/more"
style="@style/PokerAnalyticsTheme.TextView.BottomSheetValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="center"
android:padding="4dp"
android:text="+"
app:layout_constraintBottom_toBottomOf="@+id/editText1"
app:layout_constraintEnd_toStartOf="@+id/editText1"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/currentValue"
app:layout_constraintTop_toTopOf="@+id/editText1" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/editText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:imeOptions="actionNext"
android:lines="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/equal"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/more"
app:layout_constraintTop_toBottomOf="@+id/button1"
tools:text="1000000" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/equal"
style="@style/PokerAnalyticsTheme.TextView.BottomSheetValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="center"
android:padding="4dp"
android:text="="
app:layout_constraintBottom_toBottomOf="@+id/editText1"
app:layout_constraintEnd_toStartOf="@+id/editText2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/editText1"
app:layout_constraintTop_toTopOf="@+id/editText1" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/editText2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:gravity="center"
android:imeOptions="actionDone"
android:lines="1"
app:layout_constraintBottom_toBottomOf="@+id/editText1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/equal"
app:layout_constraintTop_toTopOf="@+id/editText1"
tools:text="20" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -92,14 +92,27 @@
<item name="android:fontFamily">@font/roboto</item> <item name="android:fontFamily">@font/roboto</item>
</style> </style>
<style name="PokerAnalyticsTheme.TextView.BottomSheetValue">
<item name="android:textSize">22sp</item>
<item name="android:textColor">@color/white</item>
<item name="android:fontFamily">@font/roboto</item>
</style>
<!-- EditText --> <!-- EditText -->
<style name="PokerAnalyticsTheme.EditText" parent="Widget.AppCompat.EditText"> <style name="PokerAnalyticsTheme.EditText" parent="Widget.AppCompat.EditText">
<item name="android:textColor">@color/white</item> <item name="android:textColor">@color/white</item>
<item name="android:fontFamily">@font/roboto</item> <item name="android:fontFamily">@font/roboto</item>
<item name="android:textColorHint">@color/white_transparent</item> <item name="android:textColorHint">@color/white_transparent</item>
<item name="android:textSize">22sp</item> <item name="android:textSize">20sp</item>
<item name="android:padding">16dp</item> <item name="android:paddingBottom">16dp</item>
</style>
<!-- Button -->
<style name="PokerAnalyticsTheme.Button.Borderless" parent="Widget.MaterialComponents.Button">
<item name="android:background">?selectableItemBackgroundBorderless</item>
<item name="android:textColor">@color/green</item>
<item name="android:fontFamily">@font/roboto_bold</item>
</style> </style>

Loading…
Cancel
Save