|
|
|
|
@ -6,7 +6,6 @@ import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
|
import io.realm.RealmResults |
|
|
|
|
import io.realm.Sort |
|
|
|
|
import io.realm.kotlin.where |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_top_10.* |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
@ -36,9 +35,11 @@ class Top10Fragment : RealmFragment(), RowRepresentableDataSource, RowRepresenta |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private lateinit var positiveSessions: RealmResults<Session> |
|
|
|
|
private lateinit var dataListAdapter: RowRepresentableAdapter |
|
|
|
|
private lateinit var realmCashGames: RealmResults<Session> |
|
|
|
|
private lateinit var realmTournaments: RealmResults<Session> |
|
|
|
|
|
|
|
|
|
private var realmCashGames: List<Session> = mutableListOf() |
|
|
|
|
private var realmTournaments: List<Session> = mutableListOf() |
|
|
|
|
|
|
|
|
|
private var currentTab: Tab = Tab.CASH_GAMES |
|
|
|
|
|
|
|
|
|
@ -54,63 +55,12 @@ class Top10Fragment : RealmFragment(), RowRepresentableDataSource, RowRepresenta |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Init data |
|
|
|
|
* Init UI |
|
|
|
|
*/ |
|
|
|
|
private fun initData() { |
|
|
|
|
|
|
|
|
|
this.realmCashGames = getRealm().where<Session>() |
|
|
|
|
.equalTo("type", Session.Type.CASH_GAME.ordinal) |
|
|
|
|
.greaterThanOrEqualTo("result.net", 0.0) |
|
|
|
|
.sort("result.net", Sort.DESCENDING) |
|
|
|
|
.limit(10) |
|
|
|
|
.findAll() |
|
|
|
|
this.realmCashGames.addChangeListener { _, _ -> |
|
|
|
|
this.dataListAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.realmTournaments = getRealm().where<Session>() |
|
|
|
|
.equalTo("type", Session.Type.TOURNAMENT.ordinal) |
|
|
|
|
.greaterThanOrEqualTo("result.net", 0.0) |
|
|
|
|
.sort("result.net", Sort.DESCENDING) |
|
|
|
|
.limit(10) |
|
|
|
|
.findAll() |
|
|
|
|
this.realmTournaments.addChangeListener { _, _ -> |
|
|
|
|
this.dataListAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
dataListAdapter = RowRepresentableAdapter(this, this) |
|
|
|
|
recyclerView.adapter = dataListAdapter |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
|
return when (currentTab) { |
|
|
|
|
Tab.CASH_GAMES -> realmCashGames |
|
|
|
|
Tab.TOURNAMENTS -> realmTournaments |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun rowRepresentableForPosition(position: Int): RowRepresentable? { |
|
|
|
|
return when (currentTab) { |
|
|
|
|
Tab.CASH_GAMES -> realmCashGames[position] |
|
|
|
|
Tab.TOURNAMENTS -> realmTournaments[position] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun numberOfRows(): Int { |
|
|
|
|
return when (currentTab) { |
|
|
|
|
Tab.CASH_GAMES -> realmCashGames.size |
|
|
|
|
Tab.TOURNAMENTS -> realmTournaments.size |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun viewTypeForPosition(position: Int): Int { |
|
|
|
|
return RowViewType.ROW_TOP_10.ordinal |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Init UI |
|
|
|
|
*/ |
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
setDisplayHomeAsUpEnabled(true) |
|
|
|
|
|
|
|
|
|
@ -144,4 +94,82 @@ class Top10Fragment : RealmFragment(), RowRepresentableDataSource, RowRepresenta |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Init data |
|
|
|
|
*/ |
|
|
|
|
private fun initData() { |
|
|
|
|
|
|
|
|
|
this.positiveSessions = getRealm().where<Session>() |
|
|
|
|
.isNotNull("endDate") |
|
|
|
|
.greaterThan("result.net", 0.0) |
|
|
|
|
.findAll() |
|
|
|
|
|
|
|
|
|
updateTop10() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun updateTop10() { |
|
|
|
|
|
|
|
|
|
val cashGames = mutableListOf<Session>() |
|
|
|
|
val tournaments = mutableListOf<Session>() |
|
|
|
|
|
|
|
|
|
// filter by type: cash game or tournament |
|
|
|
|
this.positiveSessions.forEach { |
|
|
|
|
when (it.type) { |
|
|
|
|
Session.Type.CASH_GAME.ordinal -> { |
|
|
|
|
cashGames.add(it) |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
tournaments.add(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Sort by rated net |
|
|
|
|
val sortedCashGames = cashGames.sortedByDescending { |
|
|
|
|
it.computableResult?.ratedNet |
|
|
|
|
}.toMutableList() |
|
|
|
|
val sortedTournaments = tournaments.sortedByDescending { |
|
|
|
|
it.computableResult?.ratedNet |
|
|
|
|
}.toMutableList() |
|
|
|
|
|
|
|
|
|
// Keep 10 items |
|
|
|
|
if (sortedCashGames.size > 10) { |
|
|
|
|
sortedCashGames.subList(10, sortedCashGames.size).clear() |
|
|
|
|
} |
|
|
|
|
if (sortedTournaments.size > 10) { |
|
|
|
|
sortedTournaments.subList(10, sortedTournaments.size).clear() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.realmCashGames = sortedCashGames |
|
|
|
|
this.realmTournaments = sortedTournaments |
|
|
|
|
|
|
|
|
|
dataListAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
|
return when (currentTab) { |
|
|
|
|
Tab.CASH_GAMES -> realmCashGames |
|
|
|
|
Tab.TOURNAMENTS -> realmTournaments |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun rowRepresentableForPosition(position: Int): RowRepresentable? { |
|
|
|
|
return when (currentTab) { |
|
|
|
|
Tab.CASH_GAMES -> realmCashGames[position] |
|
|
|
|
Tab.TOURNAMENTS -> realmTournaments[position] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun numberOfRows(): Int { |
|
|
|
|
return when (currentTab) { |
|
|
|
|
Tab.CASH_GAMES -> realmCashGames.size |
|
|
|
|
Tab.TOURNAMENTS -> realmTournaments.size |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun viewTypeForPosition(position: Int): Int { |
|
|
|
|
return RowViewType.ROW_TOP_10.ordinal |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |