Improve Game management

feature/top10
Aurelien Hubert 7 years ago
parent 8fe25094de
commit 3c952a13c6
  1. 36
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  3. 50
      app/src/main/java/net/pokeranalytics/android/ui/adapter/LimitTypesAdapter.kt
  4. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetFragment.kt
  5. 1
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetListFragment.kt
  6. 47
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetListGameFragment.kt
  7. 3
      app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt
  8. 24
      app/src/main/res/layout/bottom_sheet_game_list.xml

@ -4,12 +4,15 @@ import android.app.Application
import io.realm.Realm
import io.realm.RealmConfiguration
import io.realm.RealmResults
import io.realm.kotlin.where
import net.pokeranalytics.android.model.realm.Game
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.util.PokerAnalyticsLogs
import timber.log.Timber
import java.util.*
class PokerAnalyticsApplication: Application() {
class PokerAnalyticsApplication : Application() {
var sessions: RealmResults<Session>? = null
@ -43,9 +46,9 @@ class PokerAnalyticsApplication: Application() {
this.sessions = realm.where(Session::class.java).findAll() // monitor session deletions
this.sessions?.addChangeListener { t, changeSet ->
val deletedSessions = realm.where(Session::class.java).`in`("id", changeSet.deletions.toTypedArray()).findAll()
val deletedSessions =
realm.where(Session::class.java).`in`("id", changeSet.deletions.toTypedArray()).findAll()
deletedSessions.forEach { it.cleanup() }
}
if (BuildConfig.DEBUG) {
@ -55,6 +58,33 @@ class PokerAnalyticsApplication: Application() {
//Fabric.with(this, Crashlytics())
}
if (BuildConfig.DEBUG) {
createDefaultData()
}
}
/**
* Create default data
*/
private fun createDefaultData() {
val gamesName = resources.getStringArray(R.array.game_name)
val gamesShortName = resources.getStringArray(R.array.game_name)
val realm = Realm.getDefaultInstance()
if (realm.where<Game>().findAll().isEmpty()) {
realm.executeTransaction {
for ((index, name) in gamesName.withIndex()) {
val game = Game()
game.id = UUID.randomUUID().toString()
game.name = name
game.shortName = gamesShortName[index]
realm.copyToRealmOrUpdate(game)
}
}
}
}
}

@ -188,7 +188,6 @@ open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource
return gameTitle
}
companion object {
fun newInstance(): Session {
var session: Session = Session()
@ -296,6 +295,7 @@ open class Session : RealmObject(), SessionInterface, RowRepresentableDataSource
SessionRow.TABLE_SIZE -> {data.add(BottomSheetData(tableSize))}
SessionRow.GAME -> {
// Add current game & games list
data.add(BottomSheetData(limit))
data.add(BottomSheetData(game, data = LiveData.GAME.items(realm)))
}
SessionRow.LOCATION -> {

@ -0,0 +1,50 @@
package net.pokeranalytics.android.ui.adapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.row_bottom_sheet_grid_title.view.*
import net.pokeranalytics.android.R
class LimitTypesAdapter(private var tableSizes: ArrayList<String>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
companion object {
const val ROW_LIMIT: Int = 100
}
var onClickOnItem: ((position: Int) -> Unit)? = null
inner class CellSessionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(tableSize: String) {
itemView.title.text = tableSize
itemView.container.setOnClickListener {
onClickOnItem?.invoke(adapterPosition)
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
when (viewType) {
ROW_LIMIT -> return CellSessionViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_bottom_sheet_title, parent, false))
else -> throw IllegalStateException("Need to implement type $viewType in HistoryAdapter")
}
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (getItemViewType(position)) {
ROW_LIMIT -> (holder as LimitTypesAdapter.CellSessionViewHolder).bind(tableSizes[position])
}
}
override fun getItemCount(): Int {
return tableSizes.size
}
override fun getItemViewType(position: Int): Int {
return ROW_LIMIT
}
}

@ -14,6 +14,7 @@ import net.pokeranalytics.android.ui.view.RowRepresentable
enum class BottomSheetType {
NONE,
LIST,
LIST_GAME,
DOUBLE_LIST,
GRID,
EDIT_TEXT,
@ -45,8 +46,9 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
val bottomSheetFragment = when (row.bottomSheetType) {
BottomSheetType.LIST -> BottomSheetListFragment()
BottomSheetType.LIST_GAME -> BottomSheetListGameFragment()
BottomSheetType.GRID -> BottomSheetTableSizeGridFragment()
BottomSheetType.DOUBLE_LIST -> BottomSheetDoubleListFragment()
BottomSheetType.DOUBLE_LIST -> BottomSheetListGameFragment()
BottomSheetType.EDIT_TEXT -> BottomSheetEditTextFragment()
BottomSheetType.DOUBLE_EDIT_TEXT -> BottomSheetDoubleEditTextFragment()
BottomSheetType.SUM -> BottomSheetSumFragment()

@ -55,7 +55,6 @@ class BottomSheetListFragment : BottomSheetFragment(), LiveDataDelegate {
* Init data
*/
private fun initData() {
val bottomSheetData = getData()
if (bottomSheetData.isNotEmpty() && bottomSheetData.first().data != null) {
this.realmData = bottomSheetData.first().data as RealmResults<*>

@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import io.realm.RealmResults
import kotlinx.android.synthetic.main.bottom_sheet_game_list.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R
@ -12,9 +13,13 @@ import net.pokeranalytics.android.ui.adapter.LimitTypesAdapter
import net.pokeranalytics.android.ui.adapter.components.LiveDataAdapter
import net.pokeranalytics.android.ui.adapter.components.LiveDataDataSource
import net.pokeranalytics.android.ui.adapter.components.LiveDataDelegate
import timber.log.Timber
class BottomSheetGameListFragment : BottomSheetFragment(), LiveDataDelegate {
class BottomSheetListGameFragment : BottomSheetFragment(), LiveDataDelegate {
private var realmData: RealmResults<*>? = null
private lateinit var dataAdapter: LiveDataAdapter
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@ -22,55 +27,77 @@ class BottomSheetGameListFragment : BottomSheetFragment(), LiveDataDelegate {
initUI()
}
override fun onResume() {
super.onResume()
dataAdapter.notifyDataSetChanged()
}
override fun data(position: Int): LiveDataDataSource {
realmData?.let {
return it[position] as LiveDataDataSource
}
//TODO: Change that
return Game()
}
override fun onRowSelected(position: Int) {
realmData?.let {
val selectedData = it[position]
selectedData?.let {data ->
bottomSheetDelegate.setValue(data, row)
dismiss()
}
}
}
override fun size(): Int {
return 1
Timber.d("Games: ${realmData?.size}")
return realmData?.size ?: 0
}
/**
* Init data
*/
private fun initData() {
val data = getData()
//game = if (data is Game) data else Game()
//game.title = "Test"
val bottomSheetData = getData()
if (bottomSheetData.isNotEmpty() && bottomSheetData.size >= 2 && bottomSheetData[1].data != null) {
this.realmData = bottomSheetData[1].data as RealmResults<*>
}
}
/**
* Init UI
*/
private fun initUI() {
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_game_list, view?.bottomSheetContainer, true)
val limits = ArrayList<String>()
limits.add("--")
limits.addAll(resources.getStringArray(R.array.limit_short_name))
val viewManager1 = LinearLayoutManager(requireContext())
val gameDataAdapter1 = LimitTypesAdapter(limits)
reyclerView1.apply {
recyclerView1.apply {
setHasFixedSize(true)
layoutManager = viewManager1
adapter = gameDataAdapter1
isNestedScrollingEnabled = false
}
val viewManager2 = LinearLayoutManager(requireContext())
val gameDataAdapter2 = LiveDataAdapter(this, R.layout.row_bottom_sheet_title)
dataAdapter = LiveDataAdapter(this, R.layout.row_bottom_sheet_title)
reyclerView2.apply {
recyclerView2.apply {
setHasFixedSize(true)
layoutManager = viewManager2
adapter = gameDataAdapter2
adapter = dataAdapter
}
}
}

@ -149,7 +149,8 @@ enum class SessionRow : RowRepresentable {
CASHED_OUT, BREAK_TIME -> BottomSheetType.EDIT_TEXT
BUY_IN, TIPS -> BottomSheetType.SUM
BLINDS -> BottomSheetType.DOUBLE_EDIT_TEXT
GAME, LOCATION, BANKROLL -> BottomSheetType.LIST
GAME -> BottomSheetType.LIST_GAME
LOCATION, BANKROLL -> BottomSheetType.LIST
TABLE_SIZE -> BottomSheetType.GRID
COMMENT -> BottomSheetType.EDIT_TEXT
else -> BottomSheetType.NONE

@ -1,19 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/reyclerView1"
android:id="@+id/recyclerView1"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:minHeight="200dp" />
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/reyclerView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="200dp" />
android:id="@+id/recyclerView2"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/recyclerView1"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save