diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleMenu.kt b/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleMenu.kt index d8dbd51..271aa21 100644 --- a/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleMenu.kt +++ b/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleMenu.kt @@ -11,6 +11,8 @@ import android.widget.TextView import org.bspeice.minimalbible.R import android.content.Context import android.view.LayoutInflater +import android.content.res.Resources +import android.support.annotation.IdRes /** * 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 getChildrenCount(group: Int): Int = menuMappings.elementAt(group).component2() + override fun getChildrenCount(group: Int): Int = menuMappings[group].second - override fun getGroup(group: Int): String = - b.bookName(menuMappings.elementAt(group).component1()) + override fun getGroup(group: Int): String = b.bookName(menuMappings[group].first) 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 - private fun doBinding(convertView: View?, parent: ViewGroup?, + private fun doBinding(convertView: View?, parent: ViewGroup, obj: Any, highlight: Boolean): View { - val finalView: View = if (convertView != null) convertView - else { - val inflater = parent!!.getContext() - .getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater - inflater.inflate(R.layout.list_navigation_drawer, parent, false) - } + val finalView: View = convertView ?: + (parent.getContext() + .getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater) + .inflate(R.layout.list_navigation_drawer, parent, false) - val holder: NavItemHolder = if (finalView.getTag() != null) finalView.getTag() as NavItemHolder - else NavItemHolder(finalView, R.id.navlist_content) + val holder: NavItemHolder = + if (finalView.getTag() != null) finalView.getTag() as NavItemHolder + else NavItemHolder(finalView, R.id.navlist_content) holder.bind(obj, highlight) - finalView.setTag(holder) + finalView setTag holder return finalView } override fun getGroupView(position: Int, expanded: Boolean, - convertView: View?, parent: ViewGroup?): View = + convertView: View?, parent: ViewGroup): View = doBinding(convertView, parent, getGroup(position), position == groupHighlighted) 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) - // Resource should be IdRes - class NavItemHolder(val bindTo: View, resource: Int) { - val content: TextView = bindTo.findViewById(resource) as TextView + class NavItemHolder(val bindTo: View, IdRes resource: Int) { + val content = 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) { - content.setText(obj.toString()) - if (highlighted) - content.setTextColor(bindTo.getResources().getColor(R.color.navbar_highlight)) - else - content.setTextColor(bindTo.getResources().getColor(R.color.navbar_unhighlighted)) + content setText obj.toString() + content setTextColor getHighlightedColor(highlighted) } } - } \ No newline at end of file