Fixes issue where pending sessions were displayed twice

dev
Laurent 7 years ago
parent c598211c15
commit dc4635f9e8
  1. 197
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FeedFragment.kt

@ -85,12 +85,12 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate {
deleteSelectedTransaction()
}
} else if (requestCode == FilterActivityRequestCode.CREATE_FILTER.ordinal && resultCode == RESULT_OK) {
data?.let {
this.saveFilter(this.requireContext(), it.getStringExtra(FiltersActivity.IntentKey.FILTER_ID.keyName))
}
}
data?.let {
this.saveFilter(this.requireContext(), it.getStringExtra(FiltersActivity.IntentKey.FILTER_ID.keyName))
}
}
}
}
override fun onDestroyView() {
super.onDestroyView()
@ -116,7 +116,12 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate {
is Transaction -> {
selectedTransaction = row
selectedTransactionPosition = position
EditableDataActivity.newInstanceForResult(this, LiveData.TRANSACTION, row.id, REQUEST_CODE_TRANSACTION_DETAILS)
EditableDataActivity.newInstanceForResult(
this,
LiveData.TRANSACTION,
row.id,
REQUEST_CODE_TRANSACTION_DETAILS
)
}
}
}
@ -149,13 +154,13 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate {
override fun onTabSelected(tab: TabLayout.Tab) {
when (tab.position) {
0 -> {
currentFilterable = FilterableType.SESSION
recyclerView.adapter = feedSessionAdapter
}
currentFilterable = FilterableType.SESSION
recyclerView.adapter = feedSessionAdapter
}
1 -> {
currentFilterable = FilterableType.TRANSACTION
recyclerView.adapter = feedTransactionAdapter
}
currentFilterable = FilterableType.TRANSACTION
recyclerView.adapter = feedTransactionAdapter
}
}
}
@ -173,63 +178,73 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate {
*/
private fun initData() {
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm", Locale.getDefault())
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm", Locale.getDefault())
betaLimitDate = sdf.parse("17/7/2019 10:00")
val viewManager = SmoothScrollLinearLayoutManager(requireContext())
recyclerView.apply {
setHasFixedSize(true)
layoutManager = viewManager
}
val viewManager = SmoothScrollLinearLayoutManager(requireContext())
recyclerView.apply {
setHasFixedSize(true)
layoutManager = viewManager
}
applyFilter()
}
}
private fun loadSessions(filter : Filter? = null) {
val sessionFilter: Filter? = filter?.let {
if (it.filterableType == FilterableType.SESSION) {
it
} else {
null
}
}
private fun loadSessions(filter: Filter? = null) {
val sessionFilter: Filter? = filter?.let {
if (it.filterableType == FilterableType.SESSION) {
it
} else {
null
}
}
// Sessions
this.realmSessions = sessionFilter?.results() ?: run { getRealm().where<Session>().findAll() }
this.realmSessions = this.realmSessions.sort("startDate", Sort.DESCENDING)
this.realmSessions.addChangeListener { _, _ ->
this.feedSessionAdapter.refreshData()
this.feedSessionAdapter.notifyDataSetChanged()
}
// Sessions
this.realmSessions = sessionFilter?.results() ?: run { getRealm().where<Session>().isNotNull("startDate").findAll() }
this.realmSessions = this.realmSessions.sort("startDate", Sort.DESCENDING)
this.realmSessions.addChangeListener { _, _ ->
this.feedSessionAdapter.refreshData()
this.feedSessionAdapter.notifyDataSetChanged()
}
val pendingSessions = sessionFilter?.let { getRealm().where<Session>().alwaysFalse().findAll() } ?: run { getRealm().where<Session>().isNull("year").isNull("month").findAll().sort("startDate", Sort.DESCENDING) }
var distinctDateSessions = sessionFilter?.results("year", "month") ?: run { getRealm().where<Session>().distinct("year", "month").findAll() }
distinctDateSessions = distinctDateSessions.sort("startDate", Sort.DESCENDING)
this.feedSessionAdapter = FeedSessionRowRepresentableAdapter(this, realmSessions, pendingSessions, distinctDateSessions)
}
val pendingSessions = sessionFilter?.let {
getRealm().where<Session>().alwaysFalse().findAll()
} ?: run {
getRealm().where<Session>().isNull("year").isNull("month").findAll().sort("startDate", Sort.DESCENDING)
}
var distinctDateSessions = sessionFilter?.results("year", "month") ?: run {
getRealm().where<Session>().distinct("year", "month").findAll()
}
distinctDateSessions = distinctDateSessions.sort("startDate", Sort.DESCENDING)
this.feedSessionAdapter =
FeedSessionRowRepresentableAdapter(this, realmSessions, pendingSessions, distinctDateSessions)
}
private fun loadTransactions(filter : Filter? = null) {
val transactionFilter: Filter? = filter?.let {
if (it.filterableType == FilterableType.TRANSACTION) {
it
} else {
null
}
}
private fun loadTransactions(filter: Filter? = null) {
val transactionFilter: Filter? = filter?.let {
if (it.filterableType == FilterableType.TRANSACTION) {
it
} else {
null
}
}
// Transactions
this.realmTransactions = transactionFilter?.results() ?: run { getRealm().where<Transaction>().findAll()}
this.realmTransactions = this.realmTransactions.sort("date", Sort.DESCENDING)
this.realmTransactions.addChangeListener { _, _ ->
this.feedTransactionAdapter.refreshData()
this.feedTransactionAdapter.notifyDataSetChanged()
}
// Transactions
this.realmTransactions = transactionFilter?.results() ?: run { getRealm().where<Transaction>().findAll() }
this.realmTransactions = this.realmTransactions.sort("date", Sort.DESCENDING)
this.realmTransactions.addChangeListener { _, _ ->
this.feedTransactionAdapter.refreshData()
this.feedTransactionAdapter.notifyDataSetChanged()
}
var distinctDateTransactions = transactionFilter?.results("year", "month") ?: run { getRealm().where<Transaction>().distinct("year", "month").findAll() }
distinctDateTransactions = distinctDateTransactions.sort("date", Sort.DESCENDING)
this.feedTransactionAdapter = FeedTransactionRowRepresentableAdapter(this, realmTransactions, distinctDateTransactions)
var distinctDateTransactions = transactionFilter?.results("year", "month") ?: run {
getRealm().where<Transaction>().distinct("year", "month").findAll()
}
distinctDateTransactions = distinctDateTransactions.sort("date", Sort.DESCENDING)
this.feedTransactionAdapter =
FeedTransactionRowRepresentableAdapter(this, realmTransactions, distinctDateTransactions)
}
}
/**
* Create a new cash game
@ -280,45 +295,49 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate {
* Show end of beta message
*/
private fun showEndOfBetaMessage() {
Toast.makeText(context, "Beta has ended. Thanks a lot for your participation! Please update with the Google Play version to continue using the app", Toast.LENGTH_LONG).show()
Toast.makeText(
context,
"Beta has ended. Thanks a lot for your participation! Please update with the Google Play version to continue using the app",
Toast.LENGTH_LONG
).show()
}
// Filter Handler
// Filter Handler
override fun applyFilter() {
super.applyFilter()
override fun applyFilter() {
super.applyFilter()
val filter: Filter? = this.currentFilter(this.requireContext(), getRealm())
this.loadSessions(filter)
this.loadTransactions(filter)
val filter: Filter? = this.currentFilter(this.requireContext(), getRealm())
this.loadSessions(filter)
this.loadTransactions(filter)
filter?.let {
if (it.filterableType == FilterableType.SESSION) {
recyclerView.adapter = feedSessionAdapter
} else {
recyclerView.adapter = feedTransactionAdapter
}
adapterHasBeenSet = true
}
filter?.let {
if (it.filterableType == FilterableType.SESSION) {
recyclerView.adapter = feedSessionAdapter
} else {
recyclerView.adapter = feedTransactionAdapter
}
adapterHasBeenSet = true
}
if (!adapterHasBeenSet) {
adapterHasBeenSet = true
recyclerView.adapter = feedSessionAdapter
}
}
if (!adapterHasBeenSet) {
adapterHasBeenSet = true
recyclerView.adapter = feedSessionAdapter
}
}
override fun removeFilter() {
super.removeFilter()
override fun removeFilter() {
super.removeFilter()
this.loadSessions()
this.loadTransactions()
if (currentFilterable== FilterableType.SESSION) {
recyclerView.adapter = feedSessionAdapter
} else {
recyclerView.adapter = feedTransactionAdapter
}
}
this.loadSessions()
this.loadTransactions()
if (currentFilterable == FilterableType.SESSION) {
recyclerView.adapter = feedSessionAdapter
} else {
recyclerView.adapter = feedTransactionAdapter
}
}
override var currentFilterable: FilterableType = FilterableType.SESSION
override var currentFilterable: FilterableType = FilterableType.SESSION
}
Loading…
Cancel
Save