|
|
|
@ -18,7 +18,6 @@ import io.realm.kotlin.where |
|
|
|
import kotlinx.android.synthetic.main.fragment_feed.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_feed.* |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
import net.pokeranalytics.android.model.filter.Query |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Editable |
|
|
|
import net.pokeranalytics.android.model.interfaces.Editable |
|
|
|
import net.pokeranalytics.android.model.realm.Filter |
|
|
|
import net.pokeranalytics.android.model.realm.Filter |
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
@ -138,8 +137,14 @@ class FeedFragment : RealmFragment(), RowRepresentableDelegate, FilterHandler { |
|
|
|
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
|
|
|
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) { |
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) { |
|
|
|
when (tab.position) { |
|
|
|
when (tab.position) { |
|
|
|
0 -> recyclerView.adapter = feedSessionAdapter |
|
|
|
0 -> { |
|
|
|
1 -> recyclerView.adapter = feedTransactionAdapter |
|
|
|
currentFilterable = FilterableType.SESSION |
|
|
|
|
|
|
|
recyclerView.adapter = feedSessionAdapter |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
1 -> { |
|
|
|
|
|
|
|
currentFilterable = FilterableType.TRANSACTION |
|
|
|
|
|
|
|
recyclerView.adapter = feedTransactionAdapter |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -162,27 +167,42 @@ class FeedFragment : RealmFragment(), RowRepresentableDelegate, FilterHandler { |
|
|
|
betaLimitDate = sdf.parse("17/7/2019 10:00") |
|
|
|
betaLimitDate = sdf.parse("17/7/2019 10:00") |
|
|
|
|
|
|
|
|
|
|
|
val filter : Filter? = this.currentFilter(this.requireContext(), getRealm()) |
|
|
|
val filter : Filter? = this.currentFilter(this.requireContext(), getRealm()) |
|
|
|
|
|
|
|
val sessionFilter: Filter? = filter?.let { |
|
|
|
|
|
|
|
if (it.filterableType == FilterableType.SESSION) { |
|
|
|
|
|
|
|
it |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val transactionFilter: Filter? = filter?.let { |
|
|
|
|
|
|
|
if (it.filterableType == FilterableType.TRANSACTION) { |
|
|
|
|
|
|
|
it |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Sessions |
|
|
|
// Sessions |
|
|
|
this.realmSessions = filter?.results() ?: run { getRealm().where<Session>().findAll() }.sort("startDate", Sort.DESCENDING) |
|
|
|
this.realmSessions = sessionFilter?.results() ?: run { getRealm().where<Session>().findAll() }.sort("startDate", Sort.DESCENDING) |
|
|
|
this.realmSessions.addChangeListener { _, _ -> |
|
|
|
this.realmSessions.addChangeListener { _, _ -> |
|
|
|
this.feedSessionAdapter.refreshData() |
|
|
|
this.feedSessionAdapter.refreshData() |
|
|
|
this.feedSessionAdapter.notifyDataSetChanged() |
|
|
|
this.feedSessionAdapter.notifyDataSetChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val pendingSessions = filter?.let { getRealm().where<Session>().alwaysFalse().findAll() } ?: run { getRealm().where<Session>().isNull("year").isNull("month").findAll().sort("startDate", Sort.DESCENDING) } |
|
|
|
val pendingSessions = sessionFilter?.let { getRealm().where<Session>().alwaysFalse().findAll() } ?: run { getRealm().where<Session>().isNull("year").isNull("month").findAll().sort("startDate", Sort.DESCENDING) } |
|
|
|
val distinctDateSessions = filter?.results("year", "month") ?: run { getRealm().where<Session>().distinct("year", "month").findAll() }.sort("startDate", Sort.DESCENDING) |
|
|
|
val distinctDateSessions = sessionFilter?.results("year", "month") ?: run { getRealm().where<Session>().distinct("year", "month").findAll() }.sort("startDate", Sort.DESCENDING) |
|
|
|
this.feedSessionAdapter = FeedSessionRowRepresentableAdapter(this, realmSessions, pendingSessions, distinctDateSessions) |
|
|
|
this.feedSessionAdapter = FeedSessionRowRepresentableAdapter(this, realmSessions, pendingSessions, distinctDateSessions) |
|
|
|
|
|
|
|
|
|
|
|
// Transactions |
|
|
|
// Transactions |
|
|
|
this.realmTransactions = getRealm().where<Transaction>().findAll().sort("date", Sort.DESCENDING) |
|
|
|
this.realmTransactions = transactionFilter?.results() ?: run { getRealm().where<Transaction>().findAll()}.sort("date", Sort.DESCENDING) |
|
|
|
this.realmTransactions.addChangeListener { _, _ -> |
|
|
|
this.realmTransactions.addChangeListener { _, _ -> |
|
|
|
this.feedTransactionAdapter.refreshData() |
|
|
|
this.feedTransactionAdapter.refreshData() |
|
|
|
this.feedTransactionAdapter.notifyDataSetChanged() |
|
|
|
this.feedTransactionAdapter.notifyDataSetChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val distinctDateTransactions = getRealm().where<Transaction>().distinct("year", "month").findAll().sort("date", Sort.DESCENDING) |
|
|
|
val distinctDateTransactions = transactionFilter?.results("year", "month") ?: run { getRealm().where<Transaction>().distinct("year", "month").findAll() }.sort("date", Sort.DESCENDING) |
|
|
|
this.feedTransactionAdapter = FeedTransactionRowRepresentableAdapter(this, realmTransactions, distinctDateTransactions) |
|
|
|
this.feedTransactionAdapter = FeedTransactionRowRepresentableAdapter(this, realmTransactions, distinctDateTransactions) |
|
|
|
|
|
|
|
|
|
|
|
val viewManager = SmoothScrollLinearLayoutManager(requireContext()) |
|
|
|
val viewManager = SmoothScrollLinearLayoutManager(requireContext()) |
|
|
|
|