mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-04 23:28:19 -05:00
Slight refactoring of BibleMenu
Needs a test case, but having issues with the emulator on Windows
This commit is contained in:
parent
6c139eacab
commit
8d6a3b0d84
@ -11,6 +11,8 @@ import android.widget.TextView
|
|||||||
import org.bspeice.minimalbible.R
|
import org.bspeice.minimalbible.R
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.content.res.Resources
|
||||||
|
import android.support.annotation.IdRes
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by bspeice on 10/24/14.
|
* Created by bspeice on 10/24/14.
|
||||||
@ -28,10 +30,9 @@ class BibleMenu(val b: Book) : BaseExpandableListAdapter() {
|
|||||||
|
|
||||||
override fun getGroupCount(): Int = menuMappings.count()
|
override fun getGroupCount(): Int = menuMappings.count()
|
||||||
|
|
||||||
override fun getChildrenCount(group: Int): Int = menuMappings.elementAt(group).component2()
|
override fun getChildrenCount(group: Int): Int = menuMappings[group].second
|
||||||
|
|
||||||
override fun getGroup(group: Int): String =
|
override fun getGroup(group: Int): String = b.bookName(menuMappings[group].first)
|
||||||
b.bookName(menuMappings.elementAt(group).component1())
|
|
||||||
|
|
||||||
override fun getChild(group: Int, child: Int): Int = child + 1 // Index offset
|
override fun getChild(group: Int, child: Int): Int = child + 1 // Index offset
|
||||||
|
|
||||||
@ -43,42 +44,42 @@ class BibleMenu(val b: Book) : BaseExpandableListAdapter() {
|
|||||||
|
|
||||||
override fun isChildSelectable(group: Int, child: Int): Boolean = true
|
override fun isChildSelectable(group: Int, child: Int): Boolean = true
|
||||||
|
|
||||||
private fun doBinding(convertView: View?, parent: ViewGroup?,
|
private fun doBinding(convertView: View?, parent: ViewGroup,
|
||||||
obj: Any, highlight: Boolean): View {
|
obj: Any, highlight: Boolean): View {
|
||||||
val finalView: View = if (convertView != null) convertView
|
val finalView: View = convertView ?:
|
||||||
else {
|
(parent.getContext()
|
||||||
val inflater = parent!!.getContext()
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater)
|
||||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
.inflate(R.layout.list_navigation_drawer, parent, false)
|
||||||
inflater.inflate(R.layout.list_navigation_drawer, parent, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
val holder: NavItemHolder = if (finalView.getTag() != null) finalView.getTag() as NavItemHolder
|
val holder: NavItemHolder =
|
||||||
else NavItemHolder(finalView, R.id.navlist_content)
|
if (finalView.getTag() != null) finalView.getTag() as NavItemHolder
|
||||||
|
else NavItemHolder(finalView, R.id.navlist_content)
|
||||||
|
|
||||||
holder.bind(obj, highlight)
|
holder.bind(obj, highlight)
|
||||||
finalView.setTag(holder)
|
finalView setTag holder
|
||||||
return finalView
|
return finalView
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getGroupView(position: Int, expanded: Boolean,
|
override fun getGroupView(position: Int, expanded: Boolean,
|
||||||
convertView: View?, parent: ViewGroup?): View =
|
convertView: View?, parent: ViewGroup): View =
|
||||||
doBinding(convertView, parent, getGroup(position), position == groupHighlighted)
|
doBinding(convertView, parent, getGroup(position), position == groupHighlighted)
|
||||||
|
|
||||||
override fun getChildView(group: Int, child: Int, isLast: Boolean,
|
override fun getChildView(group: Int, child: Int, isLast: Boolean,
|
||||||
convertView: View?, parent: ViewGroup?): View =
|
convertView: View?, parent: ViewGroup): View =
|
||||||
doBinding(convertView, parent, getChild(group, child), child == childHighlighted)
|
doBinding(convertView, parent, getChild(group, child), child == childHighlighted)
|
||||||
|
|
||||||
// Resource should be IdRes
|
class NavItemHolder(val bindTo: View, IdRes resource: Int) {
|
||||||
class NavItemHolder(val bindTo: View, resource: Int) {
|
val content = bindTo.findViewById(resource) as TextView
|
||||||
val content: TextView = bindTo.findViewById(resource) as TextView
|
val resources = bindTo.getResources(): Resources
|
||||||
|
|
||||||
|
fun getHighlightedColor(highlighted: Boolean) = when(highlighted) {
|
||||||
|
true -> resources getColor R.color.navbar_highlight
|
||||||
|
else -> resources getColor R.color.navbar_unhighlighted // false
|
||||||
|
}
|
||||||
|
|
||||||
fun bind(obj: Any, highlighted: Boolean) {
|
fun bind(obj: Any, highlighted: Boolean) {
|
||||||
content.setText(obj.toString())
|
content setText obj.toString()
|
||||||
if (highlighted)
|
content setTextColor getHighlightedColor(highlighted)
|
||||||
content.setTextColor(bindTo.getResources().getColor(R.color.navbar_highlight))
|
|
||||||
else
|
|
||||||
content.setTextColor(bindTo.getResources().getColor(R.color.navbar_unhighlighted))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user