Refactoring

feature/top10
Laurent 7 years ago
parent f6bbffedba
commit 95864628fe
  1. 57
      app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt
  2. 33
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/HeaderRowRepresentable.kt

@ -4,37 +4,15 @@ import android.content.Context
import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
/**
* An interface to easily localize any object
*/
interface Localizable {
/**
* The resource identifier of the localized title
*/
val resId: Int?
get() {
return null
}
/**
* The localized title of the row
*/
fun localizedTitle(context: Context): String {
this.resId?.let {
return context.getString(it)
}
return "LOCALISATION NOT FOUND"
}
}
/**
* An interface extending Displayable to add a way to represent an object as a String
*/
interface RowRepresentable : Displayable {
fun getDisplayName(): String {
return "UNKNOWN NAME"
}
}
/**
@ -42,6 +20,7 @@ interface RowRepresentable : Displayable {
* as rows in RecyclerViews
*/
interface Displayable : Localizable {
/**
* The type of view associated with the row
*/
@ -81,31 +60,27 @@ interface Displayable : Localizable {
}
/**
* A class to display headers as row representable
* An interface to easily localize any object
*/
class HeaderRowRepresentable(
customViewType: RowViewType? = RowViewType.HEADER,
override var resId: Int? = null,
var title: String? = null,
var value: String? = null
) : RowRepresentable {
override fun localizedTitle(context: Context): String {
interface Localizable {
this.title?.let {
return it
/**
* The resource identifier of the localized title
*/
val resId: Int?
get() {
return null
}
/**
* The localized title of the row
*/
fun localizedTitle(context: Context): String {
this.resId?.let {
return context.getString(it)
}
return "LOCALISATION NOT FOUND"
}
override val viewType: Int = customViewType?.ordinal ?: RowViewType.HEADER.ordinal
override var displayHeader: Boolean = false
override var headerValues: ArrayList<String> = ArrayList()
}

@ -0,0 +1,33 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import android.content.Context
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
/**
* A class to display headers as row representable
*/
class HeaderRowRepresentable(
customViewType: RowViewType? = RowViewType.HEADER,
override var resId: Int? = null,
var title: String? = null,
var value: String? = null
) : RowRepresentable {
override fun localizedTitle(context: Context): String {
this.title?.let {
return it
}
this.resId?.let {
return context.getString(it)
}
return "LOCALISATION NOT FOUND"
}
override val viewType: Int = customViewType?.ordinal ?: RowViewType.HEADER.ordinal
override var displayHeader: Boolean = false
override var headerValues: ArrayList<String> = ArrayList()
}
Loading…
Cancel
Save