From 30476a119f37991aa260f66b183fe0e93bb41060 Mon Sep 17 00:00:00 2001 From: skydoves Date: Sun, 4 Sep 2022 00:15:51 +0900 Subject: [PATCH] Implement isWrapItemContent for deciding width & height sizez --- .editorconfig | 5 + CODE_OF_CONDUCT.md | 128 ++++++++++++++++++ CONTRIBUTING.md | 20 +++ .../androidveil/VeilRecyclerFrameView.kt | 56 +++++--- .../com/skydoves/androidveil/VeiledAdapter.kt | 25 ++-- .../src/main/res/values/attrs_veil.xml | 2 + 6 files changed, 208 insertions(+), 28 deletions(-) create mode 100644 .editorconfig create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..376f7bb --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +root = true +[*] +# Most of the standard properties are supported +indent_size=2 +max_line_length=100 \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..1c1cab1 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +skydoves2@gmail.com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..91a3b23 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,20 @@ +## How to contribute +We'd love to accept your patches and contributions to this project. There are just a few small guidelines you need to follow. + +## Preparing a pull request for review +Ensure your change is properly formatted by running: + +```gradle +./gradlew spotlessApply +``` + +Then dump binary API of this library that is public in sense of Kotlin visibilities and ensures that the public binary API wasn't changed in a way that make this change binary incompatible. + +```gradle +./gradlew apiDump +``` + +Please correct any failures before requesting a review. + +## Code reviews +All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult [GitHub Help](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) for more information on using pull requests. diff --git a/androidveil/src/main/java/com/skydoves/androidveil/VeilRecyclerFrameView.kt b/androidveil/src/main/java/com/skydoves/androidveil/VeilRecyclerFrameView.kt index b8cfe78..10bd0ff 100644 --- a/androidveil/src/main/java/com/skydoves/androidveil/VeilRecyclerFrameView.kt +++ b/androidveil/src/main/java/com/skydoves/androidveil/VeilRecyclerFrameView.kt @@ -67,8 +67,9 @@ class VeilRecyclerFrameView : RelativeLayout { var shimmer: Shimmer? = null var shimmerEnable: Boolean = true var defaultChildVisible = false + private var isItemWrapContentWidth = false + private var isItemWrapContentHeight = true private val threshold = 10 - private var isItemWrapContent = false constructor(context: Context) : super(context) { onCreate() @@ -131,6 +132,18 @@ class VeilRecyclerFrameView : RelativeLayout { R.styleable.VeilRecyclerFrameView_veilFrame_defaultChildVisible, defaultChildVisible ) + if (a.hasValue(R.styleable.VeilRecyclerFrameView_veilFrame_isItemWrapContentWidth)) { + isItemWrapContentWidth = a.getBoolean( + R.styleable.VeilRecyclerFrameView_veilFrame_isItemWrapContentWidth, + isItemWrapContentWidth + ) + } + if (a.hasValue(R.styleable.VeilRecyclerFrameView_veilFrame_isItemWrapContentHeight)) { + isItemWrapContentHeight = a.getBoolean( + R.styleable.VeilRecyclerFrameView_veilFrame_isItemWrapContentHeight, + isItemWrapContentHeight + ) + } } finally { a.recycle() } @@ -147,14 +160,18 @@ class VeilRecyclerFrameView : RelativeLayout { } if (this.layout != -1) { - setVeilLayout(this.layout, isItemWrapContent) + setVeilLayout(this.layout) } } /** Sets mask layout. */ - fun setVeilLayout(@LayoutRes layout: Int, isItemWrapContent: Boolean) { - this.isItemWrapContent = isItemWrapContent - this.veiledAdapter = VeiledAdapter(layout, isListItemWrapContent = isItemWrapContent) + fun setVeilLayout(@LayoutRes layout: Int) { + this.veiledAdapter = + VeiledAdapter( + userLayout = layout, + isListItemWrapContentWidth = isItemWrapContentWidth, + isListItemWrapContentHeight = isItemWrapContentHeight, + ) this.veiledRecyclerView.adapter = this.veiledAdapter requestLayout() } @@ -165,13 +182,18 @@ class VeilRecyclerFrameView : RelativeLayout { onItemClickListener: VeiledItemOnClickListener ) { this.veiledAdapter = - VeiledAdapter(layout, onItemClickListener, isListItemWrapContent = isItemWrapContent) + VeiledAdapter( + userLayout = layout, + onItemClickListener = onItemClickListener, + isListItemWrapContentWidth = isItemWrapContentWidth, + isListItemWrapContentHeight = isItemWrapContentHeight, + ) this.veiledRecyclerView.adapter = this.veiledAdapter } /** Sets mask layout and adds masked items. */ fun setVeilLayout(@LayoutRes layout: Int, size: Int) { - this.setVeilLayout(layout, isItemWrapContent) + this.setVeilLayout(layout) this.addVeiledItems(size) requestLayout() } @@ -192,16 +214,16 @@ class VeilRecyclerFrameView : RelativeLayout { for (i in 0 until size) { paramList.add( VeilParams( - baseColor, - highlightColor, - drawable, - radius, - baseAlpha, - highlightAlpha, - dropOff, - shimmerEnable, - shimmer, - defaultChildVisible + baseColor = baseColor, + highlightColor = highlightColor, + drawable = drawable, + radius = radius, + baseAlpha = baseAlpha, + highlightAlpha = highlightAlpha, + dropOff = dropOff, + shimmerEnable = shimmerEnable, + shimmer = shimmer, + defaultChildVisible = defaultChildVisible ) ) } diff --git a/androidveil/src/main/java/com/skydoves/androidveil/VeiledAdapter.kt b/androidveil/src/main/java/com/skydoves/androidveil/VeiledAdapter.kt index 7f03fc4..a68a273 100644 --- a/androidveil/src/main/java/com/skydoves/androidveil/VeiledAdapter.kt +++ b/androidveil/src/main/java/com/skydoves/androidveil/VeiledAdapter.kt @@ -25,7 +25,8 @@ import com.skydoves.androidveil.databinding.ItemVeiledLayoutAndroidveilSkydovesB internal class VeiledAdapter( @LayoutRes private val userLayout: Int, private val onItemClickListener: VeiledItemOnClickListener? = null, - private val isListItemWrapContent: Boolean = false + private val isListItemWrapContentWidth: Boolean = false, + private val isListItemWrapContentHeight: Boolean = true, ) : RecyclerView.Adapter() { private val veilParamList: MutableList = mutableListOf() @@ -48,16 +49,10 @@ internal class VeiledAdapter( override fun onBindViewHolder(holder: VeiledViewHolder, position: Int) { val veilParams = getVeilParams(position) with(holder.binding.itemVeilLayoutMain) { - layoutParams = if (isListItemWrapContent) - ViewGroup.LayoutParams( - ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ) - else - ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ) + layoutParams = ViewGroup.LayoutParams( + getLayoutParams(isListItemWrapContentWidth), + getLayoutParams(isListItemWrapContentHeight), + ) if (layout == -1) { layout = userLayout veilParams.shimmer?.let { @@ -82,6 +77,14 @@ internal class VeiledAdapter( } } + private fun getLayoutParams(isWrapContent: Boolean): Int { + return if (isWrapContent) { + ViewGroup.LayoutParams.WRAP_CONTENT + } else { + ViewGroup.LayoutParams.MATCH_PARENT + } + } + private fun getVeilParams(position: Int): VeilParams = veilParamList[position] fun updateParams(params: List) { diff --git a/androidveil/src/main/res/values/attrs_veil.xml b/androidveil/src/main/res/values/attrs_veil.xml index 8eb0bf1..8bdbead 100644 --- a/androidveil/src/main/res/values/attrs_veil.xml +++ b/androidveil/src/main/res/values/attrs_veil.xml @@ -24,6 +24,8 @@ + + \ No newline at end of file