use the built in recyclerview divider

This commit is contained in:
tibbi 2017-07-01 12:55:05 +02:00
parent 0ea7ce8293
commit 3376e5f223
2 changed files with 7 additions and 32 deletions

View file

@ -4,6 +4,7 @@ import android.graphics.Rect
import android.os.Environment
import android.os.Parcelable
import android.support.v7.app.AlertDialog
import android.support.v7.widget.DividerItemDecoration
import android.support.v7.widget.LinearLayoutManager
import android.view.KeyEvent
import android.view.LayoutInflater
@ -17,7 +18,6 @@ import com.simplemobiletools.commons.extensions.internalStoragePath
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.views.Breadcrumbs
import com.simplemobiletools.commons.views.RecyclerViewDivider
import kotlinx.android.synthetic.main.dialog_filepicker.view.*
import java.io.File
import java.util.*
@ -138,8 +138,12 @@ class FilePickerDialog(val activity: BaseSimpleActivity,
mScrollStates.put(mPrevPath.trimEnd('/'), layoutManager.onSaveInstanceState())
mDialogView.apply {
if (filepicker_list.adapter == null)
filepicker_list.addItemDecoration(RecyclerViewDivider(context))
if (filepicker_list.adapter == null) {
DividerItemDecoration(context, DividerItemDecoration.VERTICAL).apply {
setDrawable(context.resources.getDrawable(R.drawable.divider))
filepicker_list.addItemDecoration(this)
}
}
filepicker_list.adapter = adapter
filepicker_breadcrumbs.setBreadcrumb(currPath)

View file

@ -1,29 +0,0 @@
package com.simplemobiletools.commons.views
import android.content.Context
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import android.support.v7.widget.RecyclerView
import com.simplemobiletools.commons.R
class RecyclerViewDivider(context: Context) : RecyclerView.ItemDecoration() {
private val mDivider: Drawable = context.resources.getDrawable(R.drawable.divider)
override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
val left = parent.paddingLeft
val right = parent.width - parent.paddingRight
val childCount = parent.childCount
for (i in 0..childCount - 1) {
val child = parent.getChildAt(i)
val params = child.layoutParams as RecyclerView.LayoutParams
val top = child.bottom + params.bottomMargin
val bottom = top + mDivider.intrinsicHeight
mDivider.setBounds(left, top, right, bottom)
mDivider.draw(c)
}
}
}