|
|
|
|
@ -4,37 +4,64 @@ import android.content.Context |
|
|
|
|
import net.pokeranalytics.android.calculus.TextFormat |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor |
|
|
|
|
import org.w3c.dom.Text |
|
|
|
|
|
|
|
|
|
interface RowRepresentableDataSource : DisplayableDataSource { |
|
|
|
|
interface RowRepresentableDataSource: EditableDataSource, DisplayableDataSource { |
|
|
|
|
/** |
|
|
|
|
* Returns a list of rows |
|
|
|
|
*/ |
|
|
|
|
fun adapterRows(): List<out RowRepresentable>? |
|
|
|
|
|
|
|
|
|
fun rowRepresentableForPosition(position:Int): RowRepresentable? |
|
|
|
|
fun numberOfRows(): Int |
|
|
|
|
fun viewTypeForPosition(position:Int): Int |
|
|
|
|
fun indexForRow(row: RowRepresentable): Int |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun rowRepresentableForPosition(position:Int): RowRepresentable { |
|
|
|
|
if (this.numberOfRows() > position) { |
|
|
|
|
return this.adapterRows()[position] |
|
|
|
|
} else { |
|
|
|
|
throw IllegalStateException("Need to implement Data Source") |
|
|
|
|
interface StaticRowRepresentableDataSource: RowRepresentableDataSource { |
|
|
|
|
override fun rowRepresentableForPosition(position:Int): RowRepresentable? { |
|
|
|
|
this.adapterRows()?.let { |
|
|
|
|
return it[position] |
|
|
|
|
} |
|
|
|
|
throw IllegalStateException("Need to implement Data Source") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun numberOfRows(): Int { |
|
|
|
|
return this.adapterRows().size |
|
|
|
|
override fun numberOfRows(): Int { |
|
|
|
|
this.adapterRows()?.let { |
|
|
|
|
return it.size |
|
|
|
|
} |
|
|
|
|
throw IllegalStateException("Need to implement Data Source") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun viewTypeForPosition(position:Int): Int { |
|
|
|
|
return this.rowRepresentableForPosition(position).viewType |
|
|
|
|
override fun viewTypeForPosition(position:Int): Int { |
|
|
|
|
this.rowRepresentableForPosition(position)?.let { |
|
|
|
|
return it.viewType |
|
|
|
|
} |
|
|
|
|
throw IllegalStateException("Need to implement Data Source") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun indexForRow(row: RowRepresentable): Int { |
|
|
|
|
return this.adapterRows().indexOf(row) |
|
|
|
|
override fun indexForRow(row: RowRepresentable): Int { |
|
|
|
|
this.adapterRows()?.let { |
|
|
|
|
return it.indexOf(row) |
|
|
|
|
} |
|
|
|
|
throw IllegalStateException("Need to implement Data Source") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* A list of [RowRepresentableEditDescriptor] object specifying the way the edition will be handled |
|
|
|
|
*/ |
|
|
|
|
fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor> { |
|
|
|
|
return ArrayList() |
|
|
|
|
interface LiveRowRepresentableDataSource: RowRepresentableDataSource { |
|
|
|
|
override fun adapterRows(): List<out RowRepresentable>? { |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class DisplayDescriptor( |
|
|
|
|
var boolValue: Boolean? = null, |
|
|
|
|
var stringValue: String? = null, |
|
|
|
|
var textFormat: TextFormat? = null, |
|
|
|
|
var actionIcon: Int? = null, |
|
|
|
|
var context: Context? = null) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* An interface used to provide RowRepresentableAdapter content and value in the form of rows |
|
|
|
|
* |
|
|
|
|
@ -46,11 +73,9 @@ interface RowRepresentableDataSource : DisplayableDataSource { |
|
|
|
|
*/ |
|
|
|
|
interface DisplayableDataSource { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns a list of rows |
|
|
|
|
*/ |
|
|
|
|
fun adapterRows(): ArrayList<RowRepresentable> { |
|
|
|
|
return ArrayList() |
|
|
|
|
|
|
|
|
|
fun contentDescriptorForRow(row: RowRepresentable): DisplayDescriptor? { |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -89,3 +114,12 @@ interface DisplayableDataSource { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface EditableDataSource { |
|
|
|
|
/** |
|
|
|
|
* A list of [RowRepresentableEditDescriptor] object specifying the way the edition will be handled |
|
|
|
|
*/ |
|
|
|
|
fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor> { |
|
|
|
|
return ArrayList() |
|
|
|
|
} |
|
|
|
|
} |