-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
APPS-7260 Add option to support the three types of assets defined by design #32
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0d7add8
APPS-7260 Add option to add background to the assets in the list
jeslat 43c3403
APPS-7260 Add asset types enum to lists
jeslat 451950d
Merge branch 'master' into apps/APPS-7260-asset-background
jeslat b94d8bc
APPS-7260 WIP crop the image as a circle
jeslat 1e459b3
APPS-7260 Use just coil-base
jeslat be22b2e
APPS-7260 Generate test version with coil-base
jeslat 0793f5b
APPS-7260 Add java 8 to catalog
jeslat d395dbb
APPS-7260 Add java 8 to app module
jeslat 10d79d7
APPS-7260 Version using glide
jeslat a708aca
APPS-7260 Using circle image view
jeslat 32b6182
APPS-7260 Use ShapeableImageView to render a circle image
jeslat 26abde5
APPS-7260 Update version
jeslat fd91aa5
APPS-7260 Replace netflix image for existing one
jeslat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package com.telefonica.mistica.list | |
import android.content.Context | ||
import android.graphics.drawable.Drawable | ||
import android.util.AttributeSet | ||
import android.util.Log | ||
import android.util.TypedValue | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
|
@@ -11,6 +12,7 @@ import android.widget.ImageView | |
import android.widget.LinearLayout | ||
import android.widget.TextView | ||
import androidx.annotation.DrawableRes | ||
import androidx.annotation.IntDef | ||
import androidx.annotation.LayoutRes | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import androidx.constraintlayout.widget.ConstraintSet | ||
|
@@ -54,13 +56,13 @@ import com.telefonica.mistica.util.convertDpToPx | |
), | ||
BindingMethod( | ||
type = ListRowView::class, | ||
attribute = "listRowIsBoxed", | ||
method = "setBoxed" | ||
attribute = "listRowAssetType", | ||
method = "setAssetType" | ||
), | ||
BindingMethod( | ||
type = ListRowView::class, | ||
attribute = "listRowHasSmallAsset", | ||
method = "setSmallAsset" | ||
attribute = "listRowIsBoxed", | ||
method = "setBoxed" | ||
Comment on lines
-57
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The diff is a bit weird because I've changed the order but the result is that I've removed |
||
), | ||
BindingMethod( | ||
type = ListRowView::class, | ||
|
@@ -79,8 +81,18 @@ class ListRowView @JvmOverloads constructor( | |
defStyleAttr: Int = 0 | ||
) : ConstraintLayout(context, attrs, defStyleAttr) { | ||
|
||
@Retention(AnnotationRetention.SOURCE) | ||
@IntDef( | ||
TYPE_IMAGE, | ||
TYPE_SMALL_ICON, | ||
TYPE_LARGE_ICON | ||
) | ||
annotation class AssetType | ||
|
||
private val textsContainer: LinearLayout | ||
private val assetImageView: ImageView | ||
private val assetCircularImageView: ImageView | ||
private val assetImageLayout: FrameLayout | ||
private val headlineContainer: FrameLayout | ||
private val titleTextView: TextView | ||
private val subtitleTextView: TextView | ||
|
@@ -90,7 +102,7 @@ class ListRowView @JvmOverloads constructor( | |
|
||
private var currentHeadlineLayoutRes: Int = HEADLINE_NONE | ||
private var currentActionLayoutRes: Int = ACTION_NONE | ||
private var isSmallAsset: Boolean = false | ||
private var assetType: Int = TYPE_SMALL_ICON | ||
|
||
init { | ||
LayoutInflater.from(context).inflate(R.layout.list_row_item, this, true) | ||
|
@@ -101,6 +113,8 @@ class ListRowView @JvmOverloads constructor( | |
|
||
textsContainer = findViewById(R.id.row_texts_container) | ||
assetImageView = findViewById(R.id.row_asset_image) | ||
assetCircularImageView = findViewById(R.id.row_asset_circular_image) | ||
assetImageLayout = findViewById(R.id.row_asset_image_layout) | ||
headlineContainer = findViewById(R.id.row_headline) | ||
titleTextView = findViewById(R.id.row_title_text) | ||
subtitleTextView = findViewById(R.id.row_subtitle_text) | ||
|
@@ -131,12 +145,7 @@ class ListRowView @JvmOverloads constructor( | |
setSubtitle(styledAttrs.getText(R.styleable.ListRowView_listRowSubtitle)) | ||
setDescription(styledAttrs.getText(R.styleable.ListRowView_listRowDescription)) | ||
setBoxed(styledAttrs.getBoolean(R.styleable.ListRowView_listRowIsBoxed, false)) | ||
setSmallAsset( | ||
styledAttrs.getBoolean( | ||
R.styleable.ListRowView_listRowHasSmallAsset, | ||
false | ||
) | ||
) | ||
setAssetType(styledAttrs.getType(R.styleable.ListRowView_listRowAssetType)) | ||
setAssetDrawable(styledAttrs.getDrawable(R.styleable.ListRowView_listRowAssetDrawable)) | ||
setBadgeCount(styledAttrs.getInt(R.styleable.ListRowView_listRowBadgeCount, BADGE_GONE)) | ||
styledAttrs.getResourceId( | ||
|
@@ -149,25 +158,49 @@ class ListRowView @JvmOverloads constructor( | |
} | ||
} | ||
|
||
fun setSmallAsset(isSmall: Boolean) { | ||
isSmallAsset = isSmall | ||
assetImageView.setSize(if (isSmall) 24 else 40) | ||
recalculateAssetPosition() | ||
} | ||
|
||
fun setAssetResource(@DrawableRes resource: Int? = null) { | ||
setAssetDrawable(resource?.let { ContextCompat.getDrawable(context, it) }) | ||
} | ||
|
||
fun setAssetDrawable(drawable: Drawable? = null) { | ||
assetImageView.setImageDrawable(drawable) | ||
assetImageView.visibility = if (drawable != null) { | ||
View.VISIBLE | ||
if (drawable != null) { | ||
if (assetType == TYPE_IMAGE) { | ||
assetCircularImageView.setImageDrawable(drawable) | ||
assetCircularImageView.visibility = VISIBLE | ||
assetImageView.visibility = GONE | ||
} else { | ||
assetImageView.setImageDrawable(drawable) | ||
assetCircularImageView.visibility = GONE | ||
assetImageView.visibility = VISIBLE | ||
} | ||
assetImageLayout.visibility = VISIBLE | ||
} else { | ||
View.GONE | ||
assetImageLayout.visibility = GONE | ||
} | ||
} | ||
|
||
fun setAssetType(@AssetType type: Int) { | ||
assetType = type | ||
configureAsset() | ||
} | ||
|
||
private fun configureAsset() { | ||
when (assetType) { | ||
TYPE_IMAGE -> { | ||
assetImageLayout.setBackgroundResource(0) | ||
} | ||
TYPE_SMALL_ICON -> { | ||
assetImageView.setSize(24) | ||
assetImageLayout.setBackgroundResource(0) | ||
} | ||
TYPE_LARGE_ICON -> { | ||
assetImageView.setSize(24) | ||
assetImageLayout.setBackgroundResource(R.drawable.bg_list_image) | ||
} | ||
} | ||
recalculateAssetPosition() | ||
} | ||
|
||
fun setTitle(text: CharSequence?) { | ||
titleTextView.text = text | ||
recalculateTitleBottomConstraints() | ||
|
@@ -263,15 +296,15 @@ class ListRowView @JvmOverloads constructor( | |
} | ||
|
||
private fun recalculateAssetPosition() { | ||
with(assetImageView.layoutParams as LayoutParams) { | ||
with(assetImageLayout.layoutParams as LayoutParams) { | ||
if (isAnyTextDifferentThanTitleVisible()) { | ||
bottomToBottom = ConstraintSet.UNSET | ||
topMargin = context.convertDpToPx(if (isSmallAsset) 8 else 4) | ||
topMargin = context.convertDpToPx(if (assetType == TYPE_SMALL_ICON) 8 else 4) | ||
} else { | ||
bottomToBottom = ConstraintSet.PARENT_ID | ||
topMargin = context.convertDpToPx(0) | ||
} | ||
assetImageView.layoutParams = this | ||
assetImageLayout.layoutParams = this | ||
} | ||
} | ||
|
||
|
@@ -303,5 +336,8 @@ class ListRowView @JvmOverloads constructor( | |
const val BADGE_GONE = -1 | ||
const val ACTION_NONE = -1 | ||
const val HEADLINE_NONE = -1 | ||
const val TYPE_IMAGE = 0 | ||
const val TYPE_SMALL_ICON = 1 | ||
const val TYPE_LARGE_ICON = 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="oval"> | ||
<size | ||
android:width="40dp" | ||
android:height="40dp" /> | ||
<solid android:color="?colorIconDisabled" /> | ||
</shape> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor detail. But maybe we can use a simple vector asset here? Just to avoid the 13kb of it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can use
highlighted_card_custom_background.png
which is already in the catalog.