mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
Adding extra top margin between sections
This commit is contained in:
parent
bf88c16c9d
commit
92888b666c
2 changed files with 31 additions and 6 deletions
|
@ -22,6 +22,7 @@ import im.vector.app.R
|
|||
import im.vector.app.core.date.DateFormatKind
|
||||
import im.vector.app.core.date.VectorDateFormatter
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.core.utils.DimensionConverter
|
||||
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -30,6 +31,7 @@ class SessionDetailsController @Inject constructor(
|
|||
private val checkIfSectionDeviceIsVisibleUseCase: CheckIfSectionDeviceIsVisibleUseCase,
|
||||
private val stringProvider: StringProvider,
|
||||
private val dateFormatter: VectorDateFormatter,
|
||||
private val dimensionConverter: DimensionConverter,
|
||||
) : TypedEpoxyController<DeviceInfo>() {
|
||||
|
||||
var callback: Callback? = null
|
||||
|
@ -40,27 +42,30 @@ class SessionDetailsController @Inject constructor(
|
|||
|
||||
override fun buildModels(data: DeviceInfo?) {
|
||||
data?.let { info ->
|
||||
if (hasSectionSession(data)) {
|
||||
val hasSectionSession = hasSectionSession(data)
|
||||
if (hasSectionSession) {
|
||||
buildSectionSession(info)
|
||||
}
|
||||
|
||||
if (hasSectionDevice(data)) {
|
||||
// TODO add a marginTop of 48dp if the session section is visible
|
||||
buildSectionDevice(info)
|
||||
buildSectionDevice(info, addExtraTopMargin = hasSectionSession)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildHeaderItem(@StringRes titleResId: Int) {
|
||||
private fun buildHeaderItem(@StringRes titleResId: Int, addExtraTopMargin: Boolean = false) {
|
||||
val host = this
|
||||
sessionDetailsHeaderItem {
|
||||
id(titleResId)
|
||||
title(host.stringProvider.getString(titleResId))
|
||||
addExtraTopMargin(addExtraTopMargin)
|
||||
dimensionConverter(host.dimensionConverter)
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildContentItem(@StringRes titleResId: Int, value: String) {
|
||||
val host = this
|
||||
// TODO bind the longClickListener to copy the description to the clipboard
|
||||
sessionDetailsContentItem {
|
||||
id(titleResId)
|
||||
title(host.stringProvider.getString(titleResId))
|
||||
|
@ -96,10 +101,10 @@ class SessionDetailsController @Inject constructor(
|
|||
return checkIfSectionDeviceIsVisibleUseCase.execute(data)
|
||||
}
|
||||
|
||||
private fun buildSectionDevice(data: DeviceInfo) {
|
||||
private fun buildSectionDevice(data: DeviceInfo, addExtraTopMargin: Boolean) {
|
||||
val lastSeenIp = data.lastSeenIp
|
||||
|
||||
buildHeaderItem(R.string.device_manager_session_details_section_device_title)
|
||||
buildHeaderItem(R.string.device_manager_session_details_section_device_title, addExtraTopMargin)
|
||||
|
||||
// TODO hide divider on the last visible item
|
||||
lastSeenIp?.let {
|
||||
|
|
|
@ -16,12 +16,18 @@
|
|||
|
||||
package im.vector.app.features.settings.devices.v2.details
|
||||
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.view.updateMargins
|
||||
import com.airbnb.epoxy.EpoxyAttribute
|
||||
import com.airbnb.epoxy.EpoxyModelClass
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.epoxy.VectorEpoxyHolder
|
||||
import im.vector.app.core.epoxy.VectorEpoxyModel
|
||||
import im.vector.app.core.utils.DimensionConverter
|
||||
|
||||
private const val EXTRA_TOP_MARGIN_DP = 48
|
||||
|
||||
@EpoxyModelClass
|
||||
abstract class SessionDetailsHeaderItem : VectorEpoxyModel<SessionDetailsHeaderItem.Holder>(R.layout.item_session_details_header) {
|
||||
|
@ -29,9 +35,23 @@ abstract class SessionDetailsHeaderItem : VectorEpoxyModel<SessionDetailsHeaderI
|
|||
@EpoxyAttribute
|
||||
var title: String? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var addExtraTopMargin: Boolean = false
|
||||
|
||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
|
||||
var dimensionConverter: DimensionConverter? = null
|
||||
|
||||
override fun bind(holder: Holder) {
|
||||
super.bind(holder)
|
||||
holder.sessionDetailsHeaderTitle.text = title
|
||||
val topMargin = if (addExtraTopMargin) {
|
||||
dimensionConverter?.dpToPx(EXTRA_TOP_MARGIN_DP) ?: 0
|
||||
} else {
|
||||
0
|
||||
}
|
||||
holder.sessionDetailsHeaderTitle.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
updateMargins(top = topMargin)
|
||||
}
|
||||
}
|
||||
|
||||
class Holder : VectorEpoxyHolder() {
|
||||
|
|
Loading…
Reference in a new issue