Skip to content

Предложения по улучшению #10

Description

@indrih17

"menu" переименовал бы на "menuId"
"click" на "clickListener"
fun processTitle(textTitle: TextView) на fun TextView.changeTitile()

var itemLayoutId = R.layout.item_linear`
if (layoutManager is GridLayoutManager) {
    itemLayoutId = R.layout.item_grid
}

Я бы поменял на

val itemLayoutId = when (layoutManager) {
    is GridLayoutManager -> R.layout.item_grid
    else -> R.layout.item_linear
}

Ещё бы из функции fun processRecycler(recycler: RecyclerView, dialog: BottomSheetDialog) вынес
if (menu > 0){}, и саму функцию вообще убрал бы. Например, вот так:

fun show(context: Context) {
    ...
    val recycler = root.findViewById(R.id.recycler_view) as RecyclerView
    if (menuId > 0) {
        if (layoutManager == null) {
            layoutManager = createVerticalLinearLayoutManager()
        }
        val itemLayoutId = when (layoutManager) {
            is GridLayoutManager -> R.layout.item_grid
            else -> R.layout.item_linear
        }
        if (adapter == null) {
            adapter = createAdapter(dialog, itemLayoutId)
        }
        recyclerView.adapter = adapter
        recyclerView.layoutManager = layoutManager
    }
    ...
}
MenuItem.OnMenuItemClickListener({
    click.onMenuItemClick(it)
    dialog.cancel()
    true
})

поменял бы на

MenuItem.OnMenuItemClickListener {
    click.onMenuItemClick(it)
    dialog.cancel()
    true
}
protected open fun processGrid(root: View) {
    if (root.findViewById<View>(R.id.text_title).visibility != View.VISIBLE) {
        if (layoutManager is GridLayoutManager) {
            root.marginTop(24)
        }
    }
}

изменил на

protected open fun GridLayoutManager.setTopMarginIfTitleIsVisible(root: View) {
    if (root.findViewById<View>(R.id.text_title).visibility != View.VISIBLE) {
        root.marginTop(24)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions