Add Dividers to ControllerActivity's RecyclerView

Dividers after titles were missing in `ControllerActivity` which made it look inconsistent with `SettingsActivity` which did have them. They have now been added by extending `DividerItemDecoration` to be drawn before any `ControllerHeaderItem`.
This commit is contained in:
PixelyIon 2021-11-11 20:19:30 +05:30
parent b230afcd35
commit 69ef93bfa8
5 changed files with 35 additions and 0 deletions

View File

@ -3,7 +3,17 @@
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="../../../../../layout/custom_preview.xml" value="0.16875" />
<entry key="app/src/main/res/drawable/logo_skyline.xml" value="0.152" />
<entry key="app/src/main/res/layout/app_dialog.xml" value="0.22335526315789472" />
<entry key="app/src/main/res/layout/button_dialog.xml" value="0.33" />
<entry key="app/src/main/res/layout/controller_activity.xml" value="0.22335526315789472" />
<entry key="app/src/main/res/layout/controller_header.xml" value="0.22335526315789472" />
<entry key="app/src/main/res/layout/header_rom_filter.xml" value="0.22335526315789472" />
<entry key="app/src/main/res/layout/license_dialog.xml" value="0.1" />
<entry key="app/src/main/res/layout/main_activity.xml" value="0.2028688524590164" />
<entry key="app/src/main/res/layout/on_screen_edit_activity.xml" value="0.67" />
<entry key="app/src/main/res/layout/on_screen_edit_mini_fab.xml" value="0.22335526315789472" />
<entry key="app/src/main/res/layout/settings_activity.xml" value="0.22302631578947368" />
<entry key="app/src/main/res/menu/toolbar_log.xml" value="0.11019736842105263" />
</map>

View File

@ -52,6 +52,8 @@ class GenericAdapter : RecyclerView.Adapter<GenericViewHolder<ViewBinding>>(), F
override fun getItemCount() = currentItems.size
fun getFactoryViewType(factory : ViewBindingFactory) = viewTypesMapping.get(factory)
override fun getItemViewType(position : Int) = viewTypesMapping.getOrPut(currentItems[position].getViewBindingFactory()) { viewTypesMapping.size }
fun setHeaderItems(items : List<GenericListItem<*>>) {

View File

@ -6,9 +6,12 @@
package emu.skyline.input
import android.content.Intent
import android.graphics.Canvas
import android.os.Bundle
import android.view.KeyEvent
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.marginTop
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -187,6 +190,24 @@ class ControllerActivity : AppCompatActivity() {
}
})
val dividerItemDecoration = object : DividerItemDecoration(this, DividerItemDecoration.VERTICAL) {
override fun onDraw(canvas : Canvas, parent : RecyclerView, state : RecyclerView.State) {
val divider = drawable!!
for (i in 0 until parent.childCount) {
val view = parent.getChildAt(i)
if (parent.adapter!!.getItemViewType(parent.getChildAdapterPosition(view)) == adapter.getFactoryViewType(ControllerHeaderBindingFactory)) {
val bottom = view.top - view.marginTop
val top = bottom - divider.intrinsicHeight
divider.setBounds(0, top, parent.width, bottom)
divider.draw(canvas)
}
}
}
}
dividerItemDecoration.drawable.let { it?.setTint(getColor(R.color.dividerColor)); it }
binding.controllerList.addItemDecoration(dividerItemDecoration)
update()
}

View File

@ -3,4 +3,5 @@
<color name="colorPrimary">#FF4285F4</color>
<color name="backgroundColor">#FF121212</color>
<color name="backgroundColorVariant">#323232</color>
<color name="dividerColor">@android:color/white</color>
</resources>

View File

@ -4,4 +4,5 @@
<color name="colorPrimary">#FF1E58F0</color>
<color name="backgroundColor">@android:color/white</color>
<color name="backgroundColorVariant">#F8F8F8</color>
<color name="dividerColor">@android:color/black</color>
</resources>