Refactoring

feature/top10
Laurent 7 years ago
parent 5b6615ee53
commit 7fd812c25e
  1. 84
      app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableAdapter.kt
  2. 84
      app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableDataSource.kt

@ -1,102 +1,18 @@
package net.pokeranalytics.android.ui.adapter package net.pokeranalytics.android.ui.adapter
import android.content.Context
import android.os.Handler import android.os.Handler
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.fragment_settings.*
import net.pokeranalytics.android.ui.view.BindableHolder import net.pokeranalytics.android.ui.view.BindableHolder
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
interface RowRepresentableDataSource : DisplayableDataSource {
fun rowRepresentableForPosition(position:Int): RowRepresentable {
if (this.numberOfRows() > position) {
return this.adapterRows()[position]
} else {
throw IllegalStateException("Need to implement Data Source")
}
}
fun numberOfRows(): Int {
return this.adapterRows().size
}
fun viewTypeForPosition(position:Int): Int {
return this.rowRepresentableForPosition(position).viewType
}
fun indexForRow(row:RowRepresentable): Int {
return this.adapterRows().indexOf(row)
}
/**
* A list of [RowRepresentableEditDescriptor] object specifying the way the edition will be handled
*/
fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor> {
return ArrayList()
}
}
interface RowRepresentableDelegate { interface RowRepresentableDelegate {
fun onRowSelected(position: Int, row: RowRepresentable, fromAction:Boolean = false) {} fun onRowSelected(position: Int, row: RowRepresentable, fromAction:Boolean = false) {}
fun onRowValueChanged(value: Any?, row: RowRepresentable) {} fun onRowValueChanged(value: Any?, row: RowRepresentable) {}
} }
/**
* An interface used to provide RowRepresentableAdapter content and value in the form of rows
*/
interface DisplayableDataSource {
/**
* Returns a list of rows
*/
fun adapterRows(): ArrayList<RowRepresentable> {
return ArrayList()
}
/**
* Returns a boolean for a specific row
*/
fun boolForRow(row: RowRepresentable): Boolean {
return false
}
/**
* Returns a localized string for a specific row
*/
fun stringForRow(row: RowRepresentable, context: Context): String {
return stringForRow(row)
}
/**
* Returns a string for a specific row
*/
fun stringForRow(row: RowRepresentable): String {
return ""
}
/**
* Returns an action icon identifier for a specific row
*/
fun actionIconForRow(row: RowRepresentable): Int? {
return 0
}
/**
* Manages:
* - label (string)
* - segmented control (live/online)
* - textfield (string)
* - switch (bool)
* - static content
* */
}
/** /**
* An adapter capable of displaying a list of RowRepresentables * An adapter capable of displaying a list of RowRepresentables
* @param dataSource the datasource providing rows * @param dataSource the datasource providing rows

@ -0,0 +1,84 @@
package net.pokeranalytics.android.ui.adapter
import android.content.Context
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
interface RowRepresentableDataSource : DisplayableDataSource {
fun rowRepresentableForPosition(position:Int): RowRepresentable {
if (this.numberOfRows() > position) {
return this.adapterRows()[position]
} else {
throw IllegalStateException("Need to implement Data Source")
}
}
fun numberOfRows(): Int {
return this.adapterRows().size
}
fun viewTypeForPosition(position:Int): Int {
return this.rowRepresentableForPosition(position).viewType
}
fun indexForRow(row: RowRepresentable): Int {
return this.adapterRows().indexOf(row)
}
/**
* A list of [RowRepresentableEditDescriptor] object specifying the way the edition will be handled
*/
fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor> {
return ArrayList()
}
}
/**
* An interface used to provide RowRepresentableAdapter content and value in the form of rows
*
* Also returns the appropriate value for any RowRepresentable in the form of :
* - string
* - booleans
* - actionIcon
* to display the appropriate values in graphical components, such as labels, textfields, switchs...
*/
interface DisplayableDataSource {
/**
* Returns a list of rows
*/
fun adapterRows(): ArrayList<RowRepresentable> {
return ArrayList()
}
/**
* Returns a boolean for a specific row
*/
fun boolForRow(row: RowRepresentable): Boolean {
return false
}
/**
* Returns a localized string for a specific row
*/
fun stringForRow(row: RowRepresentable, context: Context): String {
return stringForRow(row)
}
/**
* Returns a string for a specific row
*/
fun stringForRow(row: RowRepresentable): String {
return ""
}
/**
* Returns an action icon identifier for a specific row
*/
fun actionIconForRow(row: RowRepresentable): Int? {
return 0
}
}
Loading…
Cancel
Save