Fix Session conflict

dev_raz_wip
Laurent 7 years ago
commit 120e352bca
  1. 19
      app/src/main/java/net/pokeranalytics/android/model/realm/Bankroll.kt
  2. 22
      app/src/main/java/net/pokeranalytics/android/model/realm/Game.kt
  3. 22
      app/src/main/java/net/pokeranalytics/android/model/realm/Location.kt
  4. 355
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  5. 21
      app/src/main/java/net/pokeranalytics/android/model/realm/TournamentFeature.kt
  6. 21
      app/src/main/java/net/pokeranalytics/android/model/realm/TransactionType.kt
  7. 13
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DataListAdapter.kt
  8. 115
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DynamicRowInterface.kt
  9. 9
      app/src/main/java/net/pokeranalytics/android/ui/fragment/DataListFragment.kt
  10. 42
      app/src/main/java/net/pokeranalytics/android/ui/fragment/EditableDataFragment.kt
  11. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/NewSessionFragment.kt
  12. 11
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetData.kt
  13. 35
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetDoubleEditTextFragment.kt
  14. 48
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetEditTextFragment.kt
  15. 37
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetFragment.kt
  16. 54
      app/src/main/res/layout/bottom_sheet_double_edit_text.xml
  17. 43
      app/src/main/res/layout/bottom_sheet_edit_text.xml
  18. 3
      app/src/main/res/layout/fragment_bottom_sheet.xml
  19. 3
      app/src/main/res/layout/fragment_data_list.xml
  20. 83
      app/src/main/res/layout/fragment_editable_data.xml
  21. 6
      app/src/main/res/menu/bottom_sheet_menu.xml
  22. 1
      app/src/main/res/values/colors.xml
  23. 10
      app/src/main/res/values/strings.xml
  24. 16
      app/src/main/res/values/styles.xml

@ -38,11 +38,28 @@ open class Bankroll(name: String = "") : RealmObject(), DynamicRowDelegate, Disp
// @todo rate management
override var title: String = this.name
override val title: String get() = this.id
override val primaryKey: String get() = this.id
override fun adapterRows(): ArrayList<DynamicRowInterface> {
val rows = ArrayList<DynamicRowInterface>()
rows.addAll(BankrollRow.values())
return rows
}
override fun stringForRow(row: DynamicRowInterface): String {
return when (row) {
BankrollRow.NAME -> this.id
BankrollRow.LIVE -> if (this.live) "live" else "online"
BankrollRow.CURRENCY -> this.currency?.code?: ""
else -> return super.stringForRow(row)
}
}
override fun boolForRow(row: DynamicRowInterface): Boolean {
when (row) {
BankrollRow.LIVE -> return true
else -> return super.boolForRow(row)
}
}
}

@ -2,10 +2,10 @@ package net.pokeranalytics.android.model.realm
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.ui.adapter.components.DisplayableDataSource
import net.pokeranalytics.android.ui.adapter.components.*
import java.util.*
open class Game : RealmObject(), DisplayableDataSource {
open class Game : RealmObject(), DynamicRowDelegate, DisplayableDataSource {
@PrimaryKey
var id = UUID.randomUUID().toString()
@ -16,8 +16,20 @@ open class Game : RealmObject(), DisplayableDataSource {
// A shorter name for the game
var shortName: String? = null
override var title: String = ""
get() {
return name
override val title: String get() = this.id
override val primaryKey: String get() = this.id
override fun adapterRows(): ArrayList<DynamicRowInterface> {
val rows = ArrayList<DynamicRowInterface>()
rows.addAll(GameRow.values())
return rows
}
override fun stringForRow(row: DynamicRowInterface): String {
return when (row) {
GameRow.NAME -> this.id
else -> return super.stringForRow(row)
}
}
}

@ -2,10 +2,14 @@ package net.pokeranalytics.android.model.realm
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
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.LocationRow
import java.util.*
open class Location : RealmObject() {
open class Location : RealmObject(), DynamicRowDelegate, DisplayableDataSource {
@PrimaryKey
var id = UUID.randomUUID().toString()
@ -19,4 +23,20 @@ open class Location : RealmObject() {
// the latitude of the location
var latitude: Double? = null
override val title: String get() = this.id
override val primaryKey: String get() = this.id
override fun adapterRows(): ArrayList<DynamicRowInterface> {
val rows = ArrayList<DynamicRowInterface>()
rows.addAll(LocationRow.values())
return rows
}
override fun stringForRow(row: DynamicRowInterface): String {
return when (row) {
LocationRow.NAME -> this.id
else -> return super.stringForRow(row)
}
}
}

@ -1,157 +1,178 @@
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
}
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"
@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 -> if (cgSmallBlind != null && cgBigBlind != null) "$cgSmallBlind / $cgBigBlind" else "--"
SessionRow.GAME -> game?.title ?: "--"
SessionRow.DATE -> if (timeFrame != null) timeFrame?.startDate.toString() else "--"
else -> "--"
}
}
override var title: String = "Change that: $creationDate"
override val primaryKey: String get() = this.id
override fun getBottomSheetData(row: DynamicRowInterface): ArrayList<BottomSheetData> {
val data = ArrayList<BottomSheetData>()
// Todo: Localize & set real data
when (row) {
SessionRow.GAME -> {
data.add(BottomSheetData(game, "", 0, arrayListOf(Game(), Game(), Game())))
}
SessionRow.DATE -> {
data.add(BottomSheetData(timeFrame?.startDate, "Start date"))
data.add(BottomSheetData(timeFrame?.endDate, "End date"))
}
SessionRow.BLINDS -> {
data.add(BottomSheetData(cgSmallBlind, "Small blind", InputType.TYPE_CLASS_NUMBER))
data.add(BottomSheetData(cgBigBlind, "Big blind", InputType.TYPE_CLASS_NUMBER))
}
}
return data
}
}
enum class TournamentKind {
MTT,
SNG
MTT,
SNG
}
@ -160,63 +181,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()
}
}

@ -2,9 +2,13 @@ package net.pokeranalytics.android.model.realm
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
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.TournamentFeatureRow
import java.util.*
open class TournamentFeature : RealmObject() {
open class TournamentFeature : RealmObject(), DynamicRowDelegate, DisplayableDataSource {
@PrimaryKey
var id = UUID.randomUUID().toString()
@ -12,4 +16,19 @@ open class TournamentFeature : RealmObject() {
// The name of the feature
var name: String = ""
override val title: String get() = this.id
override val primaryKey: String get() = this.id
override fun adapterRows(): ArrayList<DynamicRowInterface> {
val rows = ArrayList<DynamicRowInterface>()
rows.addAll(TournamentFeatureRow.values())
return rows
}
override fun stringForRow(row: DynamicRowInterface): String {
return when (row) {
TournamentFeatureRow.NAME -> this.id
else -> return super.stringForRow(row)
}
}
}

@ -2,10 +2,14 @@ package net.pokeranalytics.android.model.realm
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
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.TransactionTypeRow
import java.util.*
open class TransactionType : RealmObject() {
open class TransactionType : RealmObject(), DynamicRowDelegate, DisplayableDataSource {
@PrimaryKey
var id = UUID.randomUUID().toString()
@ -22,6 +26,21 @@ open class TransactionType : RealmObject() {
// The predefined kind, if necessary, like: Withdrawal, deposit, or tips
var kind: Int? = null
override val title: String get() = this.id
override val primaryKey: String get() = this.id
override fun adapterRows(): ArrayList<DynamicRowInterface> {
val rows = ArrayList<DynamicRowInterface>()
rows.addAll(TransactionTypeRow.values())
return rows
}
override fun stringForRow(row: DynamicRowInterface): String {
return when (row) {
TransactionTypeRow.NAME -> this.id
else -> return super.stringForRow(row)
}
}
}
enum class TransactionKind {

@ -6,7 +6,9 @@ import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatTextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.fragment_data_list.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.fragment.components.BottomSheetData
interface DisplayableDelegate {
fun data(position: Int) : DisplayableDataSource
@ -15,16 +17,18 @@ interface DisplayableDelegate {
}
interface DisplayableDataSource {
var title: String
val title: String
val primaryKey: 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) {
fun bind(row: DisplayableDataSource, listener: View.OnClickListener) {
//itemView.title.text = row.title
//itemView.container.setOnClickListener(listener)
try {
itemView.findViewById<AppCompatTextView>(R.id.title).text = row.title
itemView.findViewById<ConstraintLayout>(R.id.container).setOnClickListener(listener)
@ -54,5 +58,4 @@ class DataListAdapter(var delegate: DisplayableDelegate, var layout: Int? = null
}
(holder as DataViewHolder).bind(this.delegate.data(position), listener)
}
}

@ -36,9 +36,9 @@ class SectionRow(stringRes: Int) : DynamicRowInterface {
}
enum class SessionRow(val resId: Int) : DynamicRowInterface {
BLINDS(R.string.app_name),
GAME(R.string.title_history),
DATE(R.string.title_settings);
BLINDS(R.string.blinds),
GAME(R.string.game),
DATE(R.string.date);
override fun localizedTitle(context: Context): String {
return context.getString(this.resId)
@ -59,24 +59,119 @@ enum class SessionRow(val resId: Int) : DynamicRowInterface {
DATE -> BottomSheetType.DATE
}
}
}
enum class BankrollRow(val resId: Int) : DynamicRowInterface {
NAME(R.string.app_name),
LIVE(R.string.app_name),
CURRENCY(R.string.app_name);
NAME(R.string.name),
LIVE(R.string.live),
CURRENCY(R.string.currency);
override fun localizedTitle(context: Context): String {
return context.getString(this.resId)
}
override var viewType: Int = RowViewType.HEADER.ordinal
get() {
return when (this) {
NAME, LIVE, CURRENCY -> RowViewType.TITLE_VALUE.ordinal
}
}
override var bottomSheetType: BottomSheetType = BottomSheetType.NONE
get() {
return when (this) {
NAME -> BottomSheetType.EDIT_TEXT
LIVE -> BottomSheetType.NONE
CURRENCY -> BottomSheetType.LIST
}
}
}
enum class GameRow(val resId: Int) : DynamicRowInterface {
NAME(R.string.name);
override fun localizedTitle(context: Context): String {
return context.getString(this.resId)
}
override var viewType: Int = RowViewType.HEADER.ordinal
get() {
return when (this) {
NAME -> RowViewType.TITLE_VALUE.ordinal
}
}
override var bottomSheetType: BottomSheetType = BottomSheetType.NONE
get() {
return when (this) {
NAME -> BottomSheetType.EDIT_TEXT
}
}
}
enum class LocationRow(val resId: Int) : DynamicRowInterface {
NAME(R.string.name);
override fun localizedTitle(context: Context): String {
return context.getString(this.resId)
}
override var viewType: Int = RowViewType.HEADER.ordinal
get() {
return when (this) {
NAME -> RowViewType.TITLE_VALUE.ordinal
}
}
override var bottomSheetType: BottomSheetType = BottomSheetType.NONE
get() {
return when (this) {
NAME -> BottomSheetType.EDIT_TEXT
}
}
}
enum class TransactionTypeRow(val resId: Int) : DynamicRowInterface {
NAME(R.string.name);
override fun localizedTitle(context: Context): String {
return context.getString(this.resId)
}
override var viewType: Int = RowViewType.HEADER.ordinal
get() {
return when (this) {
NAME -> RowViewType.TITLE_VALUE.ordinal
}
}
override var bottomSheetType: BottomSheetType = BottomSheetType.NONE
get() {
return when (this) {
NAME -> BottomSheetType.EDIT_TEXT
}
}
}
enum class TournamentFeatureRow(val resId: Int) : DynamicRowInterface {
NAME(R.string.name);
override fun localizedTitle(context: Context): String {
return context.getString(this.resId)
}
override var viewType: Int = 1
override var viewType: Int = RowViewType.HEADER.ordinal
get() {
return when (this) {
NAME -> RowViewType.TITLE_VALUE.ordinal
}
}
override var bottomSheetType: BottomSheetType = BottomSheetType.NONE
get() {
return when (this) {
NAME -> BottomSheetType.DATE
LIVE -> BottomSheetType.DATE
CURRENCY -> BottomSheetType.DATE
NAME -> BottomSheetType.EDIT_TEXT
}
}
}

@ -6,12 +6,14 @@ import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import io.realm.Realm
import io.realm.RealmChangeListener
import io.realm.RealmResults
import kotlinx.android.synthetic.main.fragment_data_list.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.activity.EditableDataActivity
import net.pokeranalytics.android.ui.adapter.components.*
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
import timber.log.Timber
class DataListFragment : PokerAnalyticsFragment(), DisplayableDelegate {
@ -34,7 +36,7 @@ class DataListFragment : PokerAnalyticsFragment(), DisplayableDelegate {
}
override fun onRowSelected(position: Int) {
EditableDataActivity.newInstance(requireContext(), this.dataType.ordinal, null)
EditableDataActivity.newInstance(requireContext(), this.dataType.ordinal, this.data(position).primaryKey)
}
override fun size(): Int {
@ -70,7 +72,12 @@ class DataListFragment : PokerAnalyticsFragment(), DisplayableDelegate {
*/
fun setData(dataType: Int) {
this.dataType = SettingRow.values()[dataType]
this.title.text = this.dataType.name.toLowerCase().capitalize()
val realm = Realm.getDefaultInstance()
this.items = this.dataType.items(realm)
this.items.addChangeListener { newItems ->
Timber.d("newItems: ${newItems.size}")
this.recyclerView.adapter?.notifyDataSetChanged()
}
}
}

@ -8,11 +8,13 @@ import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
import io.realm.Realm
import io.realm.RealmObject
import kotlinx.android.synthetic.main.fragment_new_session.*
import kotlinx.android.synthetic.main.bottom_sheet_bankroll.*
import kotlinx.android.synthetic.main.fragment_editable_data.*
import kotlinx.android.synthetic.main.fragment_editable_data.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.adapter.components.DynamicRowCallback
import net.pokeranalytics.android.ui.adapter.components.DynamicRowInterface
import net.pokeranalytics.android.ui.adapter.components.SettingRow
import net.pokeranalytics.android.model.realm.Bankroll
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.adapter.components.*
import net.pokeranalytics.android.ui.fragment.components.BottomSheetDelegate
import net.pokeranalytics.android.ui.fragment.components.BottomSheetFragment
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
@ -23,9 +25,8 @@ class EditableDataFragment : PokerAnalyticsFragment(), DynamicRowCallback, Botto
private lateinit var item: RealmObject
private var dataType: SettingRow = SettingRow.BANKROLL
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_data_list, container, false)
return inflater.inflate(R.layout.fragment_editable_data, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -36,7 +37,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) {
@ -44,12 +45,15 @@ class EditableDataFragment : PokerAnalyticsFragment(), DynamicRowCallback, Botto
}
private fun initData() {
}
}
/**
* Init UI
*/
private fun initUI() {
val activity = activity as PokerAnalyticsActivity
activity.setSupportActionBar(toolbar)
activity.supportActionBar?.setDisplayHomeAsUpEnabled(true)
val viewManager = LinearLayoutManager(requireContext())
@ -63,26 +67,30 @@ class EditableDataFragment : PokerAnalyticsFragment(), DynamicRowCallback, Botto
* Set fragment data
*/
fun setData(dataType: Int, primaryKey: String?) {
this.dataType = SettingRow.values()[dataType]
val realm = Realm.getDefaultInstance()
var _item : RealmObject? = null
var proxyItem : RealmObject? = null
primaryKey?.let {
val t = realm.where(this.dataType.clazz()).equalTo("id", it).findFirst()
t?.let {
_item = t
proxyItem = t
}
}
realm.beginTransaction()
_item?.let {
proxyItem?.let {
this.item = realm.copyFromRealm(it)
this.appBar.toolbar.title = "Update ${this.dataType.name.toLowerCase().capitalize()}"
} ?: run {
this.item = realm.createObject(this.dataType.clazz(), UUID.randomUUID().toString())
realm.beginTransaction()
val t = realm.createObject(this.dataType.clazz(), UUID.randomUUID().toString())
realm.commitTransaction()
this.item = realm.copyFromRealm(t)
this.appBar.toolbar.title = "New ${this.dataType.name.toLowerCase().capitalize()}"
}
realm.commitTransaction()
//TODO: Crash happens here
//val dynamicListAdapter = DynamicListAdapter((this.item as DynamicRowDelegate), this)
//this.recyclerView.adapter = dynamicListAdapter
val dynamicListAdapter = DynamicListAdapter((this.item as DynamicRowDelegate), this)
this.recyclerView.adapter = dynamicListAdapter
}
}

@ -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,11 @@
package net.pokeranalytics.android.ui.fragment.components
import android.text.InputType
import net.pokeranalytics.android.ui.adapter.components.DisplayableDataSource
class BottomSheetData(
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,23 @@ 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) {
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) {
@ -99,33 +99,36 @@ open class BottomSheetFragment : BottomSheetDialogFragment(), BottomSheetInterfa
* Init UI
*/
private fun initUI() {
row.let {
bottomSheetToolbar.title = row.localizedTitle(requireContext())
bottomSheetToolbar.inflateMenu(net.pokeranalytics.android.R.menu.bottom_sheet_menu)
bottomSheetToolbar.setOnMenuItemClickListener {
false
}
}
// Menu
bottomSheetToolbar.menu.findItem(R.id.actionClear).setOnMenuItemClickListener {
clickOnClear()
true
}
bottomSheetToolbar.menu.findItem(R.id.actionAdd).setOnMenuItemClickListener {
clickOnAdd()
true
}
bottomSheetToolbar.menu.findItem(R.id.actionCheck).setOnMenuItemClickListener {
clickOnCheck()
true
// Menu
bottomSheetToolbar.menu.findItem(R.id.actionClear).setOnMenuItemClickListener {
clickOnClear()
true
}
bottomSheetToolbar.menu.findItem(R.id.actionAdd).setOnMenuItemClickListener {
clickOnAdd()
true
}
bottomSheetToolbar.menu.findItem(R.id.actionCheck).setOnMenuItemClickListener {
clickOnCheck()
true
}
}
}
/**
* Return the data object
* Return the data list
*/
fun getData(): Any? {
fun getData(): ArrayList<BottomSheetData> {
return data
}

@ -7,53 +7,41 @@
android:orientation="vertical"
tools:background="@color/gray_darker">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/appCompatTextView"
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/editText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginEnd="16dp"
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_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/smallBlind"
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:gravity="center"
android:imeOptions="actionNext"
android:inputType="numberDecimal"
android:lines="1"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/bigBlind"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintEnd_toStartOf="@+id/editText2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="10" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/bigBlind"
android:layout_width="96dp"
android:id="@+id/editText2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="end|center_vertical"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:gravity="center"
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" />
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/editText1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:text="20" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,43 @@
<?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"
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"
tools:text="Blinds" />
<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"
tools:hint="Test" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -4,11 +4,12 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#222222">
android:background="@color/gray_dark">
<androidx.appcompat.widget.Toolbar
android:id="@+id/bottomSheetToolbar"
android:layout_width="0dp"
style="@style/PokerAnalyticsTheme.Toolbar"
android:layout_height="?actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

@ -12,7 +12,7 @@
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="Data List"
tools:text="Data List"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -38,4 +38,5 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -1,68 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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="match_parent">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="400dp">
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title"
style="@style/PokerAnalyticsTheme.TextView.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="Edit Data"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title" />
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="128dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="128dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="bottom"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="bottom"
app:expandedTitleMarginStart="72dp"
app:expandedTitleTextAppearance="@style/PokerAnalyticsTheme.Toolbar.ExpandedTitleAppearance"
app:collapsedTitleTextAppearance="@style/PokerAnalyticsTheme.Toolbar.CollapsedTitleAppearance"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="Poker Analytics"
app:titleTextColor="@color/white"
app:layout_collapseMode="pin" />
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="Poker Analytics"
app:titleTextColor="@color/white"
app:layout_collapseMode="pin" />
</com.google.android.material.appbar.CollapsingToolbarLayout>

@ -5,19 +5,19 @@
<item
android:id="@+id/actionClear"
android:orderInCategory="100"
android:title="@string/app_name"
android:title="@string/clear"
android:icon="@drawable/ic_close_white_24dp"
app:showAsAction="always" />
<item
android:id="@+id/actionAdd"
android:icon="@drawable/ic_add_white_24dp"
android:orderInCategory="200"
android:title="Search"
android:title="@string/add"
app:showAsAction="ifRoom" />
<item
android:id="@+id/actionCheck"
android:icon="@drawable/ic_check_white_24dp"
android:orderInCategory="300"
android:title="User"
android:title="@string/done"
app:showAsAction="ifRoom" />
</menu>

@ -6,6 +6,7 @@
<color name="black">#000000</color>
<color name="white">#FFFFFF</color>
<color name="white_transparent">#30FFFFFF</color>
<color name="gray_light">#6AFFFFFF</color>
<color name="gray_darker">#141414</color>

@ -6,10 +6,20 @@
<string name="title_settings">Settings</string>
<string name="bankroll">Bankroll</string>
<string name="blinds">Blinds</string>
<string name="game">Game</string>
<string name="date">Date</string>
<string name="location">Location</string>
<string name="session">Session</string>
<string name="tournament_type">Tournament Type</string>
<string name="transaction_type">Transaction Type</string>
<string name="name">Name</string>
<string name="live">Live</string>
<string name="currency">Currency</string>
<string name="clear">Clear</string>
<string name="add">Add</string>
<string name="done">Done</string>
</resources>

@ -11,6 +11,7 @@
<item name="bottomNavigationStyle">@style/PokerAnalyticsTheme.BottomNavigationView</item>
<item name="toolbarStyle">@style/PokerAnalyticsTheme.Toolbar</item>
<item name="editTextStyle">@style/PokerAnalyticsTheme.EditText</item>
<item name="android:textViewStyle">@style/PokerAnalyticsTheme.TextView</item>
</style>
@ -54,26 +55,35 @@
<item name="android:fontFamily">@font/roboto</item>
</style>
<style name="PokerAnalyticsTheme.TextView.Title" parent="PokerAnalyticsTheme">
<style name="PokerAnalyticsTheme.TextView.Title">
<item name="android:textSize">22sp</item>
<item name="android:textColor">@color/white</item>
<item name="android:fontFamily">@font/roboto_bold</item>
<item name="android:paddingTop">8dp</item>
</style>
<style name="PokerAnalyticsTheme.TextView.Header" parent="PokerAnalyticsTheme">
<style name="PokerAnalyticsTheme.TextView.Header">
<item name="android:textSize">22sp</item>
<item name="android:textColor">@color/gray_darker</item>
<item name="android:fontFamily">@font/roboto_bold</item>
<item name="android:paddingTop">8dp</item>
</style>
<style name="PokerAnalyticsTheme.TextView.TitleRow" parent="PokerAnalyticsTheme">
<style name="PokerAnalyticsTheme.TextView.TitleRow">
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/gray_darker</item>
<item name="android:fontFamily">@font/roboto</item>
<item name="android:paddingTop">8dp</item>
</style>
<!-- EditText -->
<style name="PokerAnalyticsTheme.EditText" parent="Widget.AppCompat.EditText">
<item name="android:textColor">@color/white</item>
<item name="android:fontFamily">@font/roboto</item>
<item name="android:textColorHint">@color/white_transparent</item>
<item name="android:textSize">22sp</item>
<item name="android:padding">16dp</item>
</style>
</resources>

Loading…
Cancel
Save