Working on bottom sheet management

dev_raz_wip
Aurelien Hubert 7 years ago
parent 1c651e6ebe
commit a3b5efdbcf
  1. 351
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  2. 5
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DataListAdapter.kt
  3. 1
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DynamicRowInterface.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/EditableDataFragment.kt
  5. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/NewSessionFragment.kt
  6. 12
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetData.kt
  7. 36
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetDoubleEditTextFragment.kt
  8. 48
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetEditTextFragment.kt
  9. 8
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetFragment.kt
  10. 14
      app/src/main/res/layout/bottom_sheet_double_edit_text.xml
  11. 42
      app/src/main/res/layout/bottom_sheet_edit_text.xml

@ -1,158 +1,179 @@
package net.pokeranalytics.android.model.realm
import android.text.InputType
import io.realm.*
import io.realm.annotations.Ignore
import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.calculus.SessionInterface
import net.pokeranalytics.android.ui.adapter.components.DisplayableDataSource
import net.pokeranalytics.android.ui.adapter.components.DynamicRowDelegate
import net.pokeranalytics.android.ui.adapter.components.DynamicRowInterface
import net.pokeranalytics.android.ui.adapter.components.SessionRow
import net.pokeranalytics.android.ui.adapter.components.*
import net.pokeranalytics.android.ui.fragment.components.BottomSheetData
import net.pokeranalytics.android.util.data.sessionDao
import java.util.*
import kotlin.collections.ArrayList
open class Session : RealmObject(), SessionInterface, DynamicRowDelegate, DisplayableDataSource {
open class Session : RealmObject(), SessionInterface, DynamicRowDelegate, DisplayableDataSource, EditableDataSource {
@PrimaryKey
var id = UUID.randomUUID().toString()
@PrimaryKey
var id = UUID.randomUUID().toString()
// The result of the main user
var result: Result? = null
// The result of the main user
var result: Result? = null
// The time frame of the Session, i.e. the start & end date
var timeFrame: TimeFrame? = null
// The time frame of the Session, i.e. the start & end date
var timeFrame: TimeFrame? = null
// The time frame sessionGroup, which can contain multiple sessions
override var sessionSet: SessionSet? = null
// The time frame sessionGroup, which can contain multiple sessions
override var sessionSet: SessionSet? = null
// the date of creation of the app
var creationDate: Date = Date()
// the date of creation of the app
var creationDate: Date = Date()
// The bankroll hosting the results
var bankroll: Bankroll? = null
// The bankroll hosting the results
var bankroll: Bankroll? = null
// The limit type: NL, PL...
var limit: Int? = null
// The limit type: NL, PL...
var limit: Int? = null
// The game played during the Session
var game: Game? = null
// The game played during the Session
var game: Game? = null
// The number of players at the table
var tableSize: Int? = null
// The number of players at the table
var tableSize: Int? = null
// the location where the session is played
var location: Location? = null
// the location where the session is played
var location: Location? = null
// The number of tables played at the same time
var numberOfTables: Int = 1
// The number of tables played at the same time
var numberOfTables: Int = 1
// The hands list associated with the Session
var hands: RealmList<HandHistory> = RealmList()
// The hands list associated with the Session
var hands: RealmList<HandHistory> = RealmList()
// The list of opponents who participated to the session
var opponents: RealmList<Player> = RealmList()
// The list of opponents who participated to the session
var opponents: RealmList<Player> = RealmList()
// A comment written by the user
var comment: String = ""
// A comment written by the user
var comment: String = ""
// Cash Game
// Cash Game
// The small blind value
var cgSmallBlind: Double? = null
// The small blind value
var cgSmallBlind: Double? = null
// The big blind value
var cgBigBlind: Double? = null
// The big blind value
var cgBigBlind: Double? = null
// Tournament
// Tournament
// The entry fee of the tournament
var tournamentEntryFee: Double? = null
// The entry fee of the tournament
var tournamentEntryFee: Double? = null
// The total number of players who participated in the tournament
var tournamentNumberOfPlayers: Int? = null
// The total number of players who participated in the tournament
var tournamentNumberOfPlayers: Int? = null
// The name of the tournament
var tournamentType: TournamentName? = null
// The name of the tournament
var tournamentType: TournamentName? = null
// The kind of the tournament, MTT or SnG
var tournamentKind: Int? = null
// The kind of the tournament, MTT or SnG
var tournamentKind: Int? = null
// The features of the tournament, like Knockout, Shootout, Turbo...
var tournamentFeatures: RealmList<TournamentFeature> = RealmList()
// The features of the tournament, like Knockout, Shootout, Turbo...
var tournamentFeatures: RealmList<TournamentFeature> = RealmList()
companion object {
companion object {
fun newInstance(): Session {
var session: Session = Session()
session.result = Result()
session.timeFrame = TimeFrame()
return session
}
fun newInstance(): Session {
var session: Session = Session()
session.result = Result()
session.timeFrame = TimeFrame()
return session
}
}
}
@Ignore // SessionInterface value
override var value: Double = 0.0
get() {
return this.result?.net ?: 0.0
}
@Ignore // SessionInterface value
override var value: Double = 0.0
get() {
return this.result?.net ?: 0.0
}
@Ignore
override var estimatedHands: Double = 0.0
@Ignore
override var estimatedHands: Double = 0.0
@Ignore
override var bbNetResult: Double = 0.0
get() {
this.cgBigBlind?.let { bb ->
this.result?.let { result ->
return result.net / bb
}
}
return 0.0
}
@Ignore
override var bbNetResult: Double = 0.0
get() {
this.cgBigBlind?.let { bb ->
this.result?.let { result ->
return result.net / bb
}
}
return 0.0
}
@Ignore
override var bigBlindSessionCount: Int = if (this.cgBigBlind != null) 1 else 0
@Ignore
override var bigBlindSessionCount: Int = if (this.cgBigBlind != null) 1 else 0
@Ignore
override var buyin: Double = 0.0
get() {
this.result?.let {
it.buyin?.let {
return it
}
}
return 0.0
}
@Ignore
override var buyin: Double = 0.0
get() {
this.result?.let {
it.buyin?.let {
return it
}
}
return 0.0
}
override fun adapterRows(): ArrayList<DynamicRowInterface> {
val rows = ArrayList<DynamicRowInterface>()
rows.addAll(SessionRow.values())
return rows
}
override fun boolForRow(row: DynamicRowInterface): Boolean {
return false
}
override fun stringForRow(row: DynamicRowInterface): String {
return when (row) {
SessionRow.BLINDS -> "Blinds"
SessionRow.GAME -> "Game"
SessionRow.DATE -> "Date"
else -> "--"
}
}
override var title: String = "Change that: $creationDate"
override fun adapterRows(): ArrayList<DynamicRowInterface> {
val rows = ArrayList<DynamicRowInterface>()
rows.addAll(SessionRow.values())
return rows
}
override fun boolForRow(row: DynamicRowInterface): Boolean {
return false
}
override fun stringForRow(row: DynamicRowInterface): String {
return when (row) {
SessionRow.BLINDS -> "Blinds"
SessionRow.GAME -> "Game"
SessionRow.DATE -> "Date"
else -> "--"
}
}
override var title: String = "Change that: $creationDate"
override fun getBottomSheetData(row: DynamicRowInterface): ArrayList<BottomSheetData> {
val data = ArrayList<BottomSheetData>()
// Todo: Localize & set real data
when (row) {
SessionRow.GAME -> {
data.add(BottomSheetData("Game", game, "", 0, arrayListOf(Game(), Game(), Game())))
}
SessionRow.DATE -> {
data.add(BottomSheetData("Date", timeFrame?.startDate, "Start date"))
data.add(BottomSheetData("Date", timeFrame?.endDate, "End date"))
}
SessionRow.BLINDS -> {
data.add(BottomSheetData("Blind", cgSmallBlind, "Small blind", InputType.TYPE_CLASS_NUMBER))
data.add(BottomSheetData("Blind", cgBigBlind, "Big blind", InputType.TYPE_CLASS_NUMBER))
}
}
return data
}
}
enum class TournamentKind {
MTT,
SNG
MTT,
SNG
}
@ -161,63 +182,63 @@ enum class TournamentKind {
*/
class SessionDao(realmDb: Realm) {
var realm: Realm = realmDb
/**
* Create or update session
*/
fun createOrUpdateSession(session: Session): Session {
realm.beginTransaction()
val sessionToSave = realm.copyToRealmOrUpdate(session)
realm.commitTransaction()
return realm.copyFromRealm(sessionToSave)
}
/**
* Create or update sessions
*/
fun createOrUpdateSessions(sessions: List<Session>): List<Session> {
realm.beginTransaction()
// Update
val sessionsToSave = realm.copyToRealmOrUpdate(sessions)
realm.commitTransaction()
return realm.copyFromRealm(sessionsToSave)
}
/**
* Find all sessions
*/
fun findAllSessions(): RealmResults<Session> {
return realm.where(Session::class.java).findAll().sort("creationDate", Sort.DESCENDING)
}
/**
* Find session by id
*/
fun findSessionById(sessionId: Int): Session? {
return realm.copyFromRealm(realm.where(Session::class.java).equalTo("id", sessionId).findFirst())
}
/**
* Delete session
*/
fun deleteSession(sessionId: Int) {
realm.beginTransaction()
realm.sessionDao().findSessionById(sessionId)?.deleteFromRealm()
realm.commitTransaction()
}
/**
* Delete all sessions
*/
fun deleteAllSessions() {
realm.beginTransaction()
realm.sessionDao().findAllSessions().deleteAllFromRealm()
realm.commitTransaction()
}
var realm: Realm = realmDb
/**
* Create or update session
*/
fun createOrUpdateSession(session: Session): Session {
realm.beginTransaction()
val sessionToSave = realm.copyToRealmOrUpdate(session)
realm.commitTransaction()
return realm.copyFromRealm(sessionToSave)
}
/**
* Create or update sessions
*/
fun createOrUpdateSessions(sessions: List<Session>): List<Session> {
realm.beginTransaction()
// Update
val sessionsToSave = realm.copyToRealmOrUpdate(sessions)
realm.commitTransaction()
return realm.copyFromRealm(sessionsToSave)
}
/**
* Find all sessions
*/
fun findAllSessions(): RealmResults<Session> {
return realm.where(Session::class.java).findAll().sort("creationDate", Sort.DESCENDING)
}
/**
* Find session by id
*/
fun findSessionById(sessionId: Int): Session? {
return realm.copyFromRealm(realm.where(Session::class.java).equalTo("id", sessionId).findFirst())
}
/**
* Delete session
*/
fun deleteSession(sessionId: Int) {
realm.beginTransaction()
realm.sessionDao().findSessionById(sessionId)?.deleteFromRealm()
realm.commitTransaction()
}
/**
* Delete all sessions
*/
fun deleteAllSessions() {
realm.beginTransaction()
realm.sessionDao().findAllSessions().deleteAllFromRealm()
realm.commitTransaction()
}
}

@ -7,6 +7,7 @@ import androidx.appcompat.widget.AppCompatTextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.fragment.components.BottomSheetData
interface DisplayableDelegate {
fun data(position: Int) : DisplayableDataSource
@ -18,6 +19,10 @@ interface DisplayableDataSource {
var title: String
}
interface EditableDataSource {
fun getBottomSheetData(row: DynamicRowInterface): ArrayList<BottomSheetData>
}
class DataListAdapter(var delegate: DisplayableDelegate, var layout: Int? = null) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
inner class DataViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

@ -59,6 +59,7 @@ enum class SessionRow(val resId: Int) : DynamicRowInterface {
DATE -> BottomSheetType.DATE
}
}
}
enum class BankrollRow(val resId: Int) : DynamicRowInterface {

@ -36,7 +36,7 @@ class EditableDataFragment : PokerAnalyticsFragment(), DynamicRowCallback, Botto
override fun onRowSelected(row: DynamicRowInterface) {
val data = item
BottomSheetFragment.create(fragmentManager, row, this, data)
BottomSheetFragment.create(fragmentManager, row, this, ArrayList())
}
override fun setValue(value: Any, row: DynamicRowInterface) {

@ -32,16 +32,16 @@ class NewSessionFragment : PokerAnalyticsFragment(), DynamicRowCallback, BottomS
}
override fun onRowSelected(row: DynamicRowInterface) {
/*
val data = when (row.bottomSheetType) {
/*
BottomSheetType.BLINDS -> newSession
BottomSheetType.DATE -> newSession.timeFrame
BottomSheetType.GAME -> newSession.game
*/
else -> Any()
}
*/
val data = newSession.getBottomSheetData(row)
BottomSheetFragment.create(fragmentManager, row, this, data)
}

@ -0,0 +1,12 @@
package net.pokeranalytics.android.ui.fragment.components
import android.text.InputType
import net.pokeranalytics.android.ui.adapter.components.DisplayableDataSource
class BottomSheetData(
var title: String? = "",
var defaultValue: Any? = null,
var hint: String? = "",
var inputType: Int? = InputType.TYPE_CLASS_TEXT,
var data: ArrayList<DisplayableDataSource>? = ArrayList()
)

@ -1,17 +1,15 @@
package net.pokeranalytics.android.ui.fragment.components
import android.os.Bundle
import android.text.InputType
import android.view.LayoutInflater
import android.view.View
import kotlinx.android.synthetic.main.bottom_sheet_double_edit_text.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Game
import net.pokeranalytics.android.ui.adapter.components.DisplayableDataSource
import net.pokeranalytics.android.ui.adapter.components.DisplayableDelegate
class BottomSheetDoubleEditTextFragment : BottomSheetFragment(), DisplayableDelegate {
class BottomSheetDoubleEditTextFragment : BottomSheetFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@ -27,25 +25,13 @@ class BottomSheetDoubleEditTextFragment : BottomSheetFragment(), DisplayableDele
override fun onStart() {
super.onStart()
smallBlind.requestFocus()
}
override fun data(position: Int): DisplayableDataSource {
return Game()
}
override fun onRowSelected(position: Int) {
}
override fun size(): Int {
return 0
editText1.requestFocus()
}
/**
* Init data
*/
private fun initData() {
val data = getData()
}
/**
@ -53,8 +39,24 @@ class BottomSheetDoubleEditTextFragment : BottomSheetFragment(), DisplayableDele
*/
private fun initUI() {
val data = getData()
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_double_edit_text, view?.bottomSheetContainer, true)
if (data.size == 2) {
title.text = data[0].title
editText1.hint = data[0].hint
editText1.setText((data[0].defaultValue ?: "").toString())
editText1.inputType = data[0].inputType ?: InputType.TYPE_CLASS_TEXT
editText2.hint = data[1].hint
editText2.setText((data[1].defaultValue ?: "").toString())
editText2.inputType = data[1].inputType ?: InputType.TYPE_CLASS_TEXT
}
}
}

@ -0,0 +1,48 @@
package net.pokeranalytics.android.ui.fragment.components
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import kotlinx.android.synthetic.main.bottom_sheet_edit_text.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R
class BottomSheetEditTextFragment : BottomSheetFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initData()
initUI()
}
override fun clickOnCheck() {
super.clickOnCheck()
valueDelegate.setValue("", row)
dismiss()
}
override fun onStart() {
super.onStart()
editText1.requestFocus()
}
/**
* Init data
*/
private fun initData() {
val data = getData()
}
/**
* Init UI
*/
private fun initUI() {
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_edit_text, view?.bottomSheetContainer, true)
}
}

@ -38,14 +38,14 @@ open class BottomSheetFragment : BottomSheetDialogFragment(), BottomSheetInterfa
lateinit var row: DynamicRowInterface
lateinit var valueDelegate: BottomSheetDelegate
private var data: Any? = null
private var data: ArrayList<BottomSheetData> = ArrayList()
companion object {
fun create(
fragmentManager: FragmentManager?,
row: DynamicRowInterface,
valueDelegate: BottomSheetDelegate,
data: Any?
data: ArrayList<BottomSheetData>
): BottomSheetFragment {
val bottomSheetFragment = when (row.bottomSheetType) {
@ -123,9 +123,9 @@ open class BottomSheetFragment : BottomSheetDialogFragment(), BottomSheetInterfa
}
/**
* Return the data object
* Return the data list
*/
fun getData(): Any? {
fun getData(): ArrayList<BottomSheetData> {
return data
}

@ -8,23 +8,23 @@
tools:background="@color/gray_darker">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/appCompatTextView"
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
android:text="Blinds"
android:textColor="@color/white"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/smallBlind"
app:layout_constraintEnd_toStartOf="@+id/editText1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
tools:text="Blinds" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/smallBlind"
android:id="@+id/editText1"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
@ -36,12 +36,12 @@
android:lines="1"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/bigBlind"
app:layout_constraintEnd_toStartOf="@+id/editText2"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/bigBlind"
android:id="@+id/editText2"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"

@ -0,0 +1,42 @@
<?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.AppCompatTextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
tools:text="Blinds"
android:textColor="@color/white"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/editText1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/editText1"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="end|center_vertical"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:lines="1"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save