mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-17 11:48:51 +03:00
Avoid code duplication. Move ItemStyle to its own file.
This commit is contained in:
parent
eac8938186
commit
7aa4066a25
8 changed files with 67 additions and 44 deletions
|
@ -40,7 +40,7 @@ abstract class GenericFooterItem : VectorEpoxyModel<GenericFooterItem.Holder>()
|
|||
var text: CharSequence? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var style: GenericItem.STYLE = GenericItem.STYLE.NORMAL_TEXT
|
||||
var style: ItemStyle = ItemStyle.NORMAL_TEXT
|
||||
|
||||
@EpoxyAttribute
|
||||
var itemClickAction: GenericItem.Action? = null
|
||||
|
@ -56,16 +56,8 @@ abstract class GenericFooterItem : VectorEpoxyModel<GenericFooterItem.Holder>()
|
|||
super.bind(holder)
|
||||
|
||||
holder.text.setTextOrHide(text)
|
||||
holder.text.typeface = Typeface.DEFAULT
|
||||
when (style) {
|
||||
GenericItem.STYLE.BIG_TEXT -> holder.text.textSize = 18f
|
||||
GenericItem.STYLE.NORMAL_TEXT -> holder.text.textSize = 14f
|
||||
GenericItem.STYLE.SUBHEADER -> holder.text.textSize = 16f
|
||||
GenericItem.STYLE.TITLE -> {
|
||||
holder.text.textSize = 20f
|
||||
holder.text.typeface = Typeface.DEFAULT_BOLD
|
||||
}
|
||||
}
|
||||
holder.text.typeface = style.toTypeFace()
|
||||
holder.text.textSize = style.toTextSize()
|
||||
holder.text.gravity = if (centered) Gravity.CENTER_HORIZONTAL else Gravity.START
|
||||
|
||||
if (textColor != null) {
|
||||
|
|
|
@ -38,13 +38,6 @@ import im.vector.app.core.extensions.setTextOrHide
|
|||
@EpoxyModelClass(layout = R.layout.item_generic_list)
|
||||
abstract class GenericItem : VectorEpoxyModel<GenericItem.Holder>() {
|
||||
|
||||
enum class STYLE {
|
||||
BIG_TEXT,
|
||||
NORMAL_TEXT,
|
||||
TITLE,
|
||||
SUBHEADER
|
||||
}
|
||||
|
||||
class Action(var title: String) {
|
||||
var perform: Runnable? = null
|
||||
}
|
||||
|
@ -56,7 +49,7 @@ abstract class GenericItem : VectorEpoxyModel<GenericItem.Holder>() {
|
|||
var description: CharSequence? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var style: STYLE = STYLE.NORMAL_TEXT
|
||||
var style: ItemStyle = ItemStyle.NORMAL_TEXT
|
||||
|
||||
@EpoxyAttribute
|
||||
@DrawableRes
|
||||
|
@ -89,12 +82,7 @@ abstract class GenericItem : VectorEpoxyModel<GenericItem.Holder>() {
|
|||
holder.titleIcon.isVisible = false
|
||||
}
|
||||
|
||||
holder.titleText.textSize = when (style) {
|
||||
STYLE.BIG_TEXT -> 18f
|
||||
STYLE.NORMAL_TEXT -> 14f
|
||||
STYLE.TITLE -> 20f
|
||||
STYLE.SUBHEADER -> 16f
|
||||
}
|
||||
holder.titleText.textSize = style.toTextSize()
|
||||
|
||||
holder.descriptionText.setTextOrHide(description)
|
||||
|
||||
|
|
43
vector/src/main/java/im/vector/app/core/ui/list/ItemStyle.kt
Normal file
43
vector/src/main/java/im/vector/app/core/ui/list/ItemStyle.kt
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.core.ui.list
|
||||
|
||||
import android.graphics.Typeface
|
||||
|
||||
enum class ItemStyle {
|
||||
BIG_TEXT,
|
||||
NORMAL_TEXT,
|
||||
TITLE,
|
||||
SUBHEADER;
|
||||
|
||||
fun toTypeFace(): Typeface {
|
||||
return if (this == TITLE) {
|
||||
Typeface.DEFAULT_BOLD
|
||||
} else {
|
||||
Typeface.DEFAULT
|
||||
}
|
||||
}
|
||||
|
||||
fun toTextSize(): Float {
|
||||
return when (this) {
|
||||
BIG_TEXT -> 18f
|
||||
NORMAL_TEXT -> 14f
|
||||
TITLE -> 20f
|
||||
SUBHEADER -> 16f
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ import im.vector.app.R
|
|||
import im.vector.app.core.epoxy.errorWithRetryItem
|
||||
import im.vector.app.core.epoxy.loadingItem
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.core.ui.list.GenericItem
|
||||
import im.vector.app.core.ui.list.ItemStyle
|
||||
import im.vector.app.core.ui.list.genericItem
|
||||
import im.vector.app.features.settings.VectorPreferences
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
|
@ -72,7 +72,7 @@ class KeysBackupSettingsRecyclerViewController @Inject constructor(private val s
|
|||
genericItem {
|
||||
id("summary")
|
||||
title(stringProvider.getString(R.string.keys_backup_settings_status_not_setup))
|
||||
style(GenericItem.STYLE.BIG_TEXT)
|
||||
style(ItemStyle.BIG_TEXT)
|
||||
|
||||
if (data.keysBackupVersionTrust()?.usable == false) {
|
||||
description(stringProvider.getString(R.string.keys_backup_settings_untrusted_backup))
|
||||
|
@ -87,7 +87,7 @@ class KeysBackupSettingsRecyclerViewController @Inject constructor(private val s
|
|||
genericItem {
|
||||
id("summary")
|
||||
title(stringProvider.getString(R.string.keys_backup_settings_status_ko))
|
||||
style(GenericItem.STYLE.BIG_TEXT)
|
||||
style(ItemStyle.BIG_TEXT)
|
||||
if (data.keysBackupVersionTrust()?.usable == false) {
|
||||
description(stringProvider.getString(R.string.keys_backup_settings_untrusted_backup))
|
||||
} else {
|
||||
|
@ -102,7 +102,7 @@ class KeysBackupSettingsRecyclerViewController @Inject constructor(private val s
|
|||
genericItem {
|
||||
id("summary")
|
||||
title(stringProvider.getString(R.string.keys_backup_settings_status_ok))
|
||||
style(GenericItem.STYLE.BIG_TEXT)
|
||||
style(ItemStyle.BIG_TEXT)
|
||||
if (data.keysBackupVersionTrust()?.usable == false) {
|
||||
description(stringProvider.getString(R.string.keys_backup_settings_untrusted_backup))
|
||||
} else {
|
||||
|
@ -118,7 +118,7 @@ class KeysBackupSettingsRecyclerViewController @Inject constructor(private val s
|
|||
genericItem {
|
||||
id("summary")
|
||||
title(stringProvider.getString(R.string.keys_backup_settings_status_ok))
|
||||
style(GenericItem.STYLE.BIG_TEXT)
|
||||
style(ItemStyle.BIG_TEXT)
|
||||
hasIndeterminateProcess(true)
|
||||
|
||||
val totalKeys = session.cryptoService().inboundGroupSessionsCount(false)
|
||||
|
|
|
@ -27,7 +27,7 @@ import im.vector.app.core.epoxy.errorWithRetryItem
|
|||
import im.vector.app.core.epoxy.loadingItem
|
||||
import im.vector.app.core.resources.ColorProvider
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.core.ui.list.GenericItem
|
||||
import im.vector.app.core.ui.list.ItemStyle
|
||||
import im.vector.app.core.ui.list.genericFooterItem
|
||||
import im.vector.app.core.ui.list.genericItem
|
||||
import im.vector.app.core.ui.list.genericItemWithValue
|
||||
|
@ -74,7 +74,7 @@ class DeviceListEpoxyController @Inject constructor(private val stringProvider:
|
|||
|
||||
genericItem {
|
||||
id("title")
|
||||
style(GenericItem.STYLE.BIG_TEXT)
|
||||
style(ItemStyle.BIG_TEXT)
|
||||
titleIconResourceId(if (allGreen) R.drawable.ic_shield_trusted else R.drawable.ic_shield_warning)
|
||||
title(
|
||||
stringProvider.getString(
|
||||
|
@ -91,7 +91,7 @@ class DeviceListEpoxyController @Inject constructor(private val stringProvider:
|
|||
|
||||
genericItem {
|
||||
id("sessions")
|
||||
style(GenericItem.STYLE.BIG_TEXT)
|
||||
style(ItemStyle.BIG_TEXT)
|
||||
title(stringProvider.getString(R.string.room_member_profile_sessions_section_title))
|
||||
}
|
||||
if (deviceList.isEmpty()) {
|
||||
|
|
|
@ -20,7 +20,7 @@ import com.airbnb.epoxy.TypedEpoxyController
|
|||
import im.vector.app.R
|
||||
import im.vector.app.core.resources.ColorProvider
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.core.ui.list.GenericItem
|
||||
import im.vector.app.core.ui.list.ItemStyle
|
||||
import im.vector.app.core.ui.list.genericFooterItem
|
||||
import im.vector.app.core.ui.list.genericItem
|
||||
import im.vector.app.core.ui.list.genericItemWithValue
|
||||
|
@ -48,7 +48,7 @@ class DeviceTrustInfoEpoxyController @Inject constructor(private val stringProvi
|
|||
val isVerified = it.trustLevel?.isVerified() == true
|
||||
genericItem {
|
||||
id("title")
|
||||
style(GenericItem.STYLE.BIG_TEXT)
|
||||
style(ItemStyle.BIG_TEXT)
|
||||
titleIconResourceId(if (isVerified) R.drawable.ic_shield_trusted else R.drawable.ic_shield_warning)
|
||||
title(
|
||||
stringProvider.getString(
|
||||
|
|
|
@ -21,7 +21,7 @@ import im.vector.app.core.epoxy.dividerItem
|
|||
import im.vector.app.core.epoxy.loadingItem
|
||||
import im.vector.app.core.resources.ColorProvider
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.core.ui.list.GenericItem
|
||||
import im.vector.app.core.ui.list.ItemStyle
|
||||
import im.vector.app.core.ui.list.genericFooterItem
|
||||
import im.vector.app.core.ui.list.genericItem
|
||||
import im.vector.app.core.ui.views.toDrawableRes
|
||||
|
@ -85,7 +85,7 @@ class DeviceVerificationInfoBottomSheetController @Inject constructor(
|
|||
if (currentSessionIsTrusted) {
|
||||
genericItem {
|
||||
id("trust${cryptoDeviceInfo.deviceId}")
|
||||
style(GenericItem.STYLE.BIG_TEXT)
|
||||
style(ItemStyle.BIG_TEXT)
|
||||
titleIconResourceId(shield)
|
||||
title(stringProvider.getString(R.string.encryption_information_verified))
|
||||
description(stringProvider.getString(R.string.settings_active_sessions_verified_device_desc))
|
||||
|
@ -94,7 +94,7 @@ class DeviceVerificationInfoBottomSheetController @Inject constructor(
|
|||
// You need to complete security, only if there are other session(s) available, or if 4S contains secrets
|
||||
genericItem {
|
||||
id("trust${cryptoDeviceInfo.deviceId}")
|
||||
style(GenericItem.STYLE.BIG_TEXT)
|
||||
style(ItemStyle.BIG_TEXT)
|
||||
titleIconResourceId(shield)
|
||||
title(stringProvider.getString(R.string.crosssigning_verify_this_session))
|
||||
if (data.hasOtherSessions) {
|
||||
|
@ -114,7 +114,7 @@ class DeviceVerificationInfoBottomSheetController @Inject constructor(
|
|||
if (trust) {
|
||||
genericItem {
|
||||
id("trust${cryptoDeviceInfo.deviceId}")
|
||||
style(GenericItem.STYLE.BIG_TEXT)
|
||||
style(ItemStyle.BIG_TEXT)
|
||||
titleIconResourceId(shield)
|
||||
title(stringProvider.getString(R.string.encryption_information_verified))
|
||||
description(stringProvider.getString(R.string.settings_active_sessions_verified_device_desc))
|
||||
|
@ -123,7 +123,7 @@ class DeviceVerificationInfoBottomSheetController @Inject constructor(
|
|||
genericItem {
|
||||
id("trust${cryptoDeviceInfo.deviceId}")
|
||||
titleIconResourceId(shield)
|
||||
style(GenericItem.STYLE.BIG_TEXT)
|
||||
style(ItemStyle.BIG_TEXT)
|
||||
title(stringProvider.getString(R.string.encryption_information_not_verified))
|
||||
description(stringProvider.getString(R.string.settings_active_sessions_unverified_device_desc))
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ class DeviceVerificationInfoBottomSheetController @Inject constructor(
|
|||
if (cryptoDeviceInfo.trustLevel?.isLocallyVerified() == true) {
|
||||
genericItem {
|
||||
id("trust${cryptoDeviceInfo.deviceId}")
|
||||
style(GenericItem.STYLE.BIG_TEXT)
|
||||
style(ItemStyle.BIG_TEXT)
|
||||
titleIconResourceId(shield)
|
||||
title(stringProvider.getString(R.string.encryption_information_verified))
|
||||
description(stringProvider.getString(R.string.settings_active_sessions_verified_device_desc))
|
||||
|
@ -181,7 +181,7 @@ class DeviceVerificationInfoBottomSheetController @Inject constructor(
|
|||
genericItem {
|
||||
id("trust${cryptoDeviceInfo.deviceId}")
|
||||
titleIconResourceId(shield)
|
||||
style(GenericItem.STYLE.BIG_TEXT)
|
||||
style(ItemStyle.BIG_TEXT)
|
||||
title(stringProvider.getString(R.string.encryption_information_not_verified))
|
||||
description(stringProvider.getString(R.string.settings_active_sessions_unverified_device_desc))
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import com.google.android.material.textfield.TextInputLayout
|
|||
import im.vector.app.R
|
||||
import im.vector.app.core.resources.ColorProvider
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.core.ui.list.GenericItem
|
||||
import im.vector.app.core.ui.list.ItemStyle
|
||||
import im.vector.app.core.ui.list.genericFooterItem
|
||||
import im.vector.app.features.form.formEditTextItem
|
||||
import javax.inject.Inject
|
||||
|
@ -38,7 +38,7 @@ class SpaceDefaultRoomEpoxyController @Inject constructor(
|
|||
override fun buildModels(data: CreateSpaceState?) {
|
||||
genericFooterItem {
|
||||
id("info_help_header")
|
||||
style(GenericItem.STYLE.TITLE)
|
||||
style(ItemStyle.TITLE)
|
||||
text(stringProvider.getString(R.string.create_spaces_room_public_header, data?.name))
|
||||
textColor(colorProvider.getColorFromAttribute(R.attr.riot_primary_text_color))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue