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

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

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

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

@ -32,16 +32,16 @@ class NewSessionFragment : PokerAnalyticsFragment(), DynamicRowCallback, BottomS
} }
override fun onRowSelected(row: DynamicRowInterface) { override fun onRowSelected(row: DynamicRowInterface) {
/*
val data = when (row.bottomSheetType) { val data = when (row.bottomSheetType) {
/*
BottomSheetType.BLINDS -> newSession BottomSheetType.BLINDS -> newSession
BottomSheetType.DATE -> newSession.timeFrame BottomSheetType.DATE -> newSession.timeFrame
BottomSheetType.GAME -> newSession.game BottomSheetType.GAME -> newSession.game
*/
else -> Any() else -> Any()
} }
*/
val data = newSession.getBottomSheetData(row)
BottomSheetFragment.create(fragmentManager, row, this, data) 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 package net.pokeranalytics.android.ui.fragment.components
import android.os.Bundle import android.os.Bundle
import android.text.InputType
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import kotlinx.android.synthetic.main.bottom_sheet_double_edit_text.* import kotlinx.android.synthetic.main.bottom_sheet_double_edit_text.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.* import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R 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?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
@ -27,25 +25,13 @@ class BottomSheetDoubleEditTextFragment : BottomSheetFragment(), DisplayableDele
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
smallBlind.requestFocus() editText1.requestFocus()
}
override fun data(position: Int): DisplayableDataSource {
return Game()
}
override fun onRowSelected(position: Int) {
}
override fun size(): Int {
return 0
} }
/** /**
* Init data * Init data
*/ */
private fun initData() { private fun initData() {
val data = getData()
} }
/** /**
@ -53,8 +39,24 @@ class BottomSheetDoubleEditTextFragment : BottomSheetFragment(), DisplayableDele
*/ */
private fun initUI() { private fun initUI() {
val data = getData()
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_double_edit_text, view?.bottomSheetContainer, true) 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 row: DynamicRowInterface
lateinit var valueDelegate: BottomSheetDelegate lateinit var valueDelegate: BottomSheetDelegate
private var data: Any? = null private var data: ArrayList<BottomSheetData> = ArrayList()
companion object { companion object {
fun create( fun create(
fragmentManager: FragmentManager?, fragmentManager: FragmentManager?,
row: DynamicRowInterface, row: DynamicRowInterface,
valueDelegate: BottomSheetDelegate, valueDelegate: BottomSheetDelegate,
data: Any? data: ArrayList<BottomSheetData>
): BottomSheetFragment { ): BottomSheetFragment {
val bottomSheetFragment = when (row.bottomSheetType) { 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 return data
} }

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