From a3b5efdbcfc95f81975609e2dde46f9d6811b489 Mon Sep 17 00:00:00 2001 From: Aurelien Hubert Date: Mon, 18 Feb 2019 14:22:05 +0100 Subject: [PATCH] Working on bottom sheet management --- .../android/model/realm/Session.kt | 351 ++++++++++-------- .../ui/adapter/components/DataListAdapter.kt | 5 + .../adapter/components/DynamicRowInterface.kt | 1 + .../ui/fragment/EditableDataFragment.kt | 2 +- .../android/ui/fragment/NewSessionFragment.kt | 6 +- .../ui/fragment/components/BottomSheetData.kt | 12 + .../BottomSheetDoubleEditTextFragment.kt | 36 +- .../components/BottomSheetEditTextFragment.kt | 48 +++ .../components/BottomSheetFragment.kt | 8 +- .../layout/bottom_sheet_double_edit_text.xml | 14 +- .../res/layout/bottom_sheet_edit_text.xml | 42 +++ 11 files changed, 328 insertions(+), 197 deletions(-) create mode 100644 app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetData.kt create mode 100644 app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetEditTextFragment.kt create mode 100644 app/src/main/res/layout/bottom_sheet_edit_text.xml diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt index 74c482ea..9e41130e 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt @@ -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 = RealmList() + // The hands list associated with the Session + var hands: RealmList = RealmList() - // The list of opponents who participated to the session - var opponents: RealmList = RealmList() + // The list of opponents who participated to the session + var opponents: RealmList = 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 = RealmList() + // The features of the tournament, like Knockout, Shootout, Turbo... + var tournamentFeatures: RealmList = 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 { - val rows = ArrayList() - 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 { + val rows = ArrayList() + 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 { + + val data = ArrayList() + + // 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): List { - - realm.beginTransaction() - - // Update - val sessionsToSave = realm.copyToRealmOrUpdate(sessions) - realm.commitTransaction() - - return realm.copyFromRealm(sessionsToSave) - } - - /** - * Find all sessions - */ - fun findAllSessions(): RealmResults { - 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): List { + + realm.beginTransaction() + + // Update + val sessionsToSave = realm.copyToRealmOrUpdate(sessions) + realm.commitTransaction() + + return realm.copyFromRealm(sessionsToSave) + } + + /** + * Find all sessions + */ + fun findAllSessions(): RealmResults { + 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() + } } \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DataListAdapter.kt b/app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DataListAdapter.kt index 404a15e1..ea3def8b 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DataListAdapter.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DataListAdapter.kt @@ -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 +} + class DataListAdapter(var delegate: DisplayableDelegate, var layout: Int? = null) : RecyclerView.Adapter() { inner class DataViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DynamicRowInterface.kt b/app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DynamicRowInterface.kt index 5f811a14..1c3f1aa1 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DynamicRowInterface.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DynamicRowInterface.kt @@ -59,6 +59,7 @@ enum class SessionRow(val resId: Int) : DynamicRowInterface { DATE -> BottomSheetType.DATE } } + } enum class BankrollRow(val resId: Int) : DynamicRowInterface { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/EditableDataFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/EditableDataFragment.kt index 217e5716..3819da10 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/EditableDataFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/EditableDataFragment.kt @@ -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) { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/NewSessionFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/NewSessionFragment.kt index 582775d4..3f3f27f9 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/NewSessionFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/NewSessionFragment.kt @@ -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) } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetData.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetData.kt new file mode 100644 index 00000000..e73fccc8 --- /dev/null +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetData.kt @@ -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? = ArrayList() +) \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetDoubleEditTextFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetDoubleEditTextFragment.kt index b9a07d76..bba204c5 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetDoubleEditTextFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetDoubleEditTextFragment.kt @@ -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 + } + + + } } \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetEditTextFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetEditTextFragment.kt new file mode 100644 index 00000000..1120a2b6 --- /dev/null +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetEditTextFragment.kt @@ -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) + + + + } + +} \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetFragment.kt index a88045e3..57d85fb2 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetFragment.kt @@ -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 = ArrayList() companion object { fun create( fragmentManager: FragmentManager?, row: DynamicRowInterface, valueDelegate: BottomSheetDelegate, - data: Any? + data: ArrayList ): 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 { return data } diff --git a/app/src/main/res/layout/bottom_sheet_double_edit_text.xml b/app/src/main/res/layout/bottom_sheet_double_edit_text.xml index 08fb4cb2..e5a70e50 100644 --- a/app/src/main/res/layout/bottom_sheet_double_edit_text.xml +++ b/app/src/main/res/layout/bottom_sheet_double_edit_text.xml @@ -8,23 +8,23 @@ tools:background="@color/gray_darker"> + app:layout_constraintTop_toTopOf="parent" + tools:text="Blinds" /> + + + + + + + \ No newline at end of file