Improve Dynamic row management

dev_raz_wip
Aurelien Hubert 7 years ago
parent f3f28b5886
commit e10e10797a
  1. 5
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  2. 207
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  3. 1
      app/src/main/java/net/pokeranalytics/android/ui/adapter/HistoryAdapter.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DynamicListAdapter.kt
  5. 8
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DynamicRowInterface.kt
  6. 35
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/RowViewType.kt
  7. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/NewSessionFragment.kt
  8. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt
  9. 56
      app/src/main/res/layout/row_session.xml
  10. 25
      app/src/main/res/layout/row_session_view.xml

@ -1,10 +1,7 @@
package net.pokeranalytics.android
import android.app.Application
import com.crashlytics.android.Crashlytics
import io.fabric.sdk.android.Fabric
import io.realm.Realm
import io.realm.Realm.setDefaultConfiguration
import io.realm.RealmConfiguration
import timber.log.Timber
@ -26,7 +23,7 @@ class PokerAnalyticsApplication: Application() {
// Logs
Timber.plant(Timber.DebugTree())
} else {
Fabric.with(this, Crashlytics())
//Fabric.with(this, Crashlytics())
}
}

@ -7,86 +7,109 @@ import io.realm.RealmResults
import io.realm.Sort
import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.*
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.util.data.sessionDao
import java.util.*
import java.util.UUID.randomUUID
import kotlin.collections.ArrayList
open class Session(comment: String = "") : RealmObject(), DynamicRowDelegate {
open class Session(comment: String = "") : RealmObject() {
@PrimaryKey
var id = UUID.randomUUID().toString()
@PrimaryKey
var id = UUID.randomUUID().toString()
// 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 group, which can contain multiple sessions
var timeFrameGroup: TimeFrameGroup? = null
// The time frame group, which can contain multiple sessions
var timeFrameGroup: TimeFrameGroup? = null
// the date of creation of the app
// the date of creation of the app
var creationDate: Date = Date()
// The limit type: NL, PL...
// The limit type: NL, PL...
var limit: Int? = null
// The number of tables played at the same time
// The number of tables played at the same time
var numberOfTables: Int = 1
// The number of players at the table
// The number of players at the table
var tableSize: Int? = null
// The game played during the Session
// The game played during the Session
var game: Game? = null
// The bankroll hosting the results
// The bankroll hosting the results
var bankroll: Bankroll? = null
// The hands list associated with the Session
// The hands list associated with the Session
var hands: RealmList<HandHistory> = RealmList()
// the location where the session is played
// the location where the session is played
var location: Location? = null
// The result of the main user
// The result of the main user
var result: Result? = null
// The list of opponents who participated to the session
// 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
// The entry fee of the tournament
// The entry fee of the tournament
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
// 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 features of the tournament, like Knockout, Shootout, Turbo...
var tournamentFeatures: RealmList<TournamentFeature> = RealmList()
override fun adapterRows(): ArrayList<DynamicRowInterface> {
val rows = ArrayList<DynamicRowInterface>()
rows.addAll(SessionRow.values())
return rows
}
// The kind of the tournament, MTT or SnG
var tournamentKind: Int? = null
override fun boolForRow(row: DynamicRowInterface): Boolean {
// The features of the tournament, like Knockout, Shootout, Turbo...
var tournamentFeatures: RealmList<TournamentFeature> = RealmList()
return false
}
override fun stringForRow(row: DynamicRowInterface): String {
return when (row) {
SessionRow.BLINDS -> "Blinds"
SessionRow.GAME -> "Game"
SessionRow.DATE -> "Date"
else -> "--"
}
}
}
enum class TournamentKind {
MTT,
SNG
MTT,
SNG
}
@ -95,63 +118,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()
}
}

@ -8,7 +8,6 @@ import io.realm.RealmResults
import kotlinx.android.synthetic.main.row_history_session.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.view.SessionRowView
import timber.log.Timber
class HistoryAdapter(private var sessions: RealmResults<Session>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

@ -23,7 +23,7 @@ interface DynamicRowDelegate {
class DynamicListAdapter(delegate: DynamicRowDelegate) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var rows: ArrayList<DynamicRowInterface> = ArrayList<DynamicRowInterface>()
private var rows: ArrayList<DynamicRowInterface> = ArrayList()
private var delegate: DynamicRowDelegate = delegate
init {

@ -25,8 +25,8 @@ interface DynamicRowInterface {
enum class SessionRow(val resId: Int) : DynamicRowInterface {
BLINDS(R.string.app_name),
GAME(R.string.app_name),
DATE(R.string.app_name);
GAME(R.string.title_history),
DATE(R.string.title_settings);
override fun localizedTitle(context: Context): String {
return context.getString(this.resId)
@ -35,9 +35,7 @@ enum class SessionRow(val resId: Int) : DynamicRowInterface {
override var viewType: Int = RowViewType.HEADER.ordinal
get() {
return when (this) {
BLINDS -> 1
GAME -> 2
DATE -> 1
BLINDS, GAME, DATE -> RowViewType.TITLE_VALUE.ordinal
}
}

@ -1,8 +1,12 @@
package net.pokeranalytics.android.ui.adapter.components
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.row_session.view.*
import net.pokeranalytics.android.R
interface DynamicHolder {
@ -12,22 +16,35 @@ interface DynamicHolder {
enum class RowViewType {
HEADER,
TEXTFIELD,
LEFTRIGHTLABEL;
EDIT_TEXT,
TITLE_VALUE;
inner class FakeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), DynamicHolder {
override fun bind(row: DynamicRowInterface, delegate: DynamicRowDelegate) {
// this.textView.text = delegate.stringForRow(row)
}
}
inner class TitleValueViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), DynamicHolder {
override fun bind(row: DynamicRowInterface, delegate: DynamicRowDelegate) {
itemView.title.text = row.localizedTitle(itemView.context)
itemView.value.text = delegate.stringForRow(row)
itemView.container.setOnClickListener {
Toast.makeText(itemView.context, "Clicked", Toast.LENGTH_SHORT).show()
}
}
}
fun viewHolder(parent: ViewGroup) : RecyclerView.ViewHolder {
return FakeViewHolder(parent)
fun viewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
return when (this) {
TITLE_VALUE -> TitleValueViewHolder(
LayoutInflater.from(parent.context).inflate(
R.layout.row_session,
parent,
false
)
)
else -> FakeViewHolder(parent)
}
}
}

@ -9,6 +9,7 @@ import kotlinx.android.synthetic.main.fragment_new_session.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.adapter.NewSessionAdapter
import net.pokeranalytics.android.ui.adapter.components.DynamicListAdapter
import net.pokeranalytics.android.util.PokerAnalyticsFragment
class NewSessionFragment: PokerAnalyticsFragment() {
@ -36,7 +37,7 @@ class NewSessionFragment: PokerAnalyticsFragment() {
private fun initUI() {
val viewManager = LinearLayoutManager(requireContext())
val newSessionAdapter = NewSessionAdapter(newSession)
val newSessionAdapter = DynamicListAdapter(newSession)
recyclerView.apply {
setHasFixedSize(true)

@ -6,7 +6,7 @@ import android.graphics.Color
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import kotlinx.android.synthetic.main.row_session.view.*
import kotlinx.android.synthetic.main.row_session_view.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Session
import timber.log.Timber
@ -38,7 +38,7 @@ class SessionRowView : FrameLayout {
*/
private fun init() {
val layoutInflater = LayoutInflater.from(context)
rowHistorySession = layoutInflater.inflate(R.layout.row_session, this, false) as ConstraintLayout
rowHistorySession = layoutInflater.inflate(R.layout.row_session_view, this, false) as ConstraintLayout
val layoutParams = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT

@ -1,25 +1,41 @@
<?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:padding="16dp">
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:background="?selectableItemBackground"
android:id="@+id/container"
android:padding="16dp">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:textSize="16sp"
tools:text="This date"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:textSize="18sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/value"
tools:text="Title"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/value"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:textSize="16sp"
tools:text="Value"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,25 @@
<?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:padding="16dp">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:textSize="16sp"
tools:text="This date"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save