|
|
|
|
@ -10,6 +10,7 @@ import io.realm.RealmQuery |
|
|
|
|
import io.realm.RealmResults |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
|
import net.pokeranalytics.android.model.filter.Filterable |
|
|
|
|
import net.pokeranalytics.android.model.realm.Filter |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
|
@ -18,12 +19,30 @@ import net.pokeranalytics.android.util.extensions.getMonthAndYear |
|
|
|
|
import java.util.* |
|
|
|
|
import kotlin.collections.HashMap |
|
|
|
|
|
|
|
|
|
interface DateModel : RowRepresentable, RealmModel { |
|
|
|
|
interface DateModel : RowRepresentable, RealmModel, Filterable { |
|
|
|
|
var date: Date |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface EntityDescriptor<T : DateModel> { |
|
|
|
|
|
|
|
|
|
class TransactionED : EntityDescriptor { |
|
|
|
|
override fun bindableHolder(view: View): RecyclerView.ViewHolder { |
|
|
|
|
TODO() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override val layout: Int = R.layout.row_transaction |
|
|
|
|
|
|
|
|
|
override val viewType: Int = RowViewType.ROW_TRANSACTION.ordinal |
|
|
|
|
|
|
|
|
|
override val sortFieldName: String = "date" |
|
|
|
|
|
|
|
|
|
override fun distinctHeaders(realmQuery: RealmQuery<out DateModel>): RealmQuery<out DateModel> { |
|
|
|
|
return realmQuery.distinct("year", "month") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface EntityDescriptor { |
|
|
|
|
|
|
|
|
|
fun bindableHolder(view: View): RecyclerView.ViewHolder |
|
|
|
|
|
|
|
|
|
@ -33,8 +52,9 @@ interface EntityDescriptor<T : DateModel> { |
|
|
|
|
|
|
|
|
|
val sortFieldName: String |
|
|
|
|
|
|
|
|
|
fun distinctHeaders(realmQuery: RealmQuery<T>): RealmQuery<T> |
|
|
|
|
fun distinctHeaders(realmQuery: RealmQuery<out DateModel>): RealmQuery<out DateModel> |
|
|
|
|
|
|
|
|
|
// val clazz: Class<T> |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -42,11 +62,11 @@ interface EntityDescriptor<T : DateModel> { |
|
|
|
|
* @param dataSource the datasource providing rows |
|
|
|
|
* @param delegate the delegate, notified of UI actions |
|
|
|
|
*/ |
|
|
|
|
class FilterSectionAdapter<T : DateModel>( |
|
|
|
|
class FilterSectionAdapter( |
|
|
|
|
override var delegate: RowRepresentableDelegate? = null, |
|
|
|
|
override var dataSource: RowRepresentableDataSource, |
|
|
|
|
var descriptor: EntityDescriptor<T>, |
|
|
|
|
var realmQuery: RealmQuery<T> |
|
|
|
|
var descriptor: EntityDescriptor, |
|
|
|
|
var realmQuery: RealmQuery<out DateModel> |
|
|
|
|
// var distinctTransactionsHeaders: RealmResults<Transaction> |
|
|
|
|
) : |
|
|
|
|
RecyclerView.Adapter<RecyclerView.ViewHolder>(), RecyclerAdapter { |
|
|
|
|
@ -54,28 +74,45 @@ class FilterSectionAdapter<T : DateModel>( |
|
|
|
|
private var headersPositions = HashMap<Int, Date?>() |
|
|
|
|
private lateinit var sortedHeaders: SortedMap<Int, Date?> |
|
|
|
|
|
|
|
|
|
private var realmEntities: RealmResults<T> |
|
|
|
|
private var realmHeaders: RealmResults<T> |
|
|
|
|
private var realmEntities: RealmResults<out DateModel> |
|
|
|
|
private var realmHeaders: RealmResults<out DateModel> |
|
|
|
|
|
|
|
|
|
var filter: Filter? = null |
|
|
|
|
// |
|
|
|
|
// companion object { |
|
|
|
|
// |
|
|
|
|
// inline fun <reified T : DateModel> build(delegate: RowRepresentableDelegate?, dataSource: RowRepresentableDataSource, descriptor: EntityDescriptor<T>, realmQuery: RealmQuery<T>) : FilterSectionAdapter<T> { |
|
|
|
|
// val adapter = FilterSectionAdapter(delegate, dataSource, descriptor, realmQuery) |
|
|
|
|
// adapter.load() |
|
|
|
|
// return adapter |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.realmEntities = this.realmQuery.findAll().sort(this.descriptor.sortFieldName) |
|
|
|
|
// this.realmEntities = this.filter?.results() ?: this.realmQuery.findAll().sort(this.descriptor.sortFieldName) |
|
|
|
|
// this.realmEntities = this.realmQuery.findAll().sort(this.descriptor.sortFieldName) |
|
|
|
|
this.realmEntities = this.filter?.results() ?: this.realmQuery.findAll().sort(this.descriptor.sortFieldName) |
|
|
|
|
this.realmHeaders = this.descriptor.distinctHeaders(this.realmQuery).findAll() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
refreshData() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// fun load() { |
|
|
|
|
// |
|
|
|
|
// val f = this.filter?.results()?: this.realmQuery.findAll().sort(this.descriptor.sortFieldName) |
|
|
|
|
// this.realmEntities = f |
|
|
|
|
// |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Display a transaction view |
|
|
|
|
*/ |
|
|
|
|
inner class RowEntityViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder { |
|
|
|
|
|
|
|
|
|
fun bind(position: Int, row: T?, adapter: FilterSectionAdapter<T>) { |
|
|
|
|
fun bind(position: Int, row: DateModel?, adapter: FilterSectionAdapter) { |
|
|
|
|
|
|
|
|
|
// itemView.transactionRow.setData(row as Transaction) |
|
|
|
|
// val listener = View.OnClickListener { |
|
|
|
|
@ -149,7 +186,7 @@ class FilterSectionAdapter<T : DateModel>( |
|
|
|
|
/** |
|
|
|
|
* Get real index |
|
|
|
|
*/ |
|
|
|
|
private fun getEntityForPosition(position: Int): T { |
|
|
|
|
private fun getEntityForPosition(position: Int): DateModel { |
|
|
|
|
|
|
|
|
|
// Row position |
|
|
|
|
var headersBefore = 0 |
|
|
|
|
|