Skip to content

Utility extensions for master-koin#60

Merged
hrodrick merged 6 commits into
rootstrap:master-koinfrom
hrodrick:feature/utility-extensions
Apr 21, 2022
Merged

Utility extensions for master-koin#60
hrodrick merged 6 commits into
rootstrap:master-koinfrom
hrodrick:feature/utility-extensions

Conversation

@hrodrick
Copy link
Copy Markdown
Contributor

Description

  • Added some utilty extensions and classes that can be used in any project to reduce the amount of code needed to do some tasks and to not re-engineer them again. I've used them in a lot of projects so hope they will be useful for future devs!
  • This is the same PR as Utility extensions #59 but aims to be merged into the master-koin template

Preview

  • There is a CustomTypeFaceSpan that allows to set a custom font to parts of a text.
  • Added a Fragment.collectOnLifeCycle(...) extension to reduce the boiler plate code and annoying indentation when collecting flows from a fragment. (It can be easily adapted to activities)
  • Added a ProgressBar.progressTo(...) extension to animate progress updates in one line with ease and good support for older android versions.
  • Added a TextView.setClickableKeyword(...) extension to add clickable functions to words or prhases inside a Textview, allowing to also change their color, font (for example, to bold the keyword), and underline. It recycles the LinkMovementMethod if the TextView already have it.
  • Added a TextView.setColoredKeyword(...) to change the color of a word or prhase to a Textview.
    These two last functions uses the getTextAsSpannable() private extension to avoid creating unuseful spannables.

Sync master from origin repo
Sync Master-koin from original repo
@hrodrick hrodrick changed the title Feature/utility extensions Utility extensions for master-koin Feb 25, 2022
paint.isFakeBoldText = true
}
if (fake and Typeface.ITALIC != 0) {
paint.textSkewX = -0.25f
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning of 0.25 ? can be a constant ?

Copy link
Copy Markdown
Contributor Author

@hrodrick hrodrick Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it is the skew factor needed to simulate an italic typeface. You can think of it as the angle the letters are moved to look like this

I created a constant for it so it's not a magic number anymore

* > Just appending a trailing "," and adding a new Pair allows you to collect an additional
* flow per pair
*/
fun <T> Fragment.collectOnLifeCycle(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! :D It simplifies a lot the fragment's code haha

Comment on lines +19 to +23
val animation: ObjectAnimator = ObjectAnimator
.ofInt(this, "progress", progress, newlyProgress)
animation.duration = timeInMillis
animation.interpolator = DecelerateInterpolator()
animation.setAutoCancel(true)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use scope function here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks!
Used apply as suggested by the official kotlin docs to configure objects

import com.rootstrap.android.R
import com.rootstrap.android.ui.custom.CustomTypefaceSpan

fun TextView.setClickableKeyword(
Copy link
Copy Markdown
Collaborator

@amaury901130 amaury901130 Mar 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment description here. //** ...... *//

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a KDoc with an example usage 👍🏼

text = span
}

fun TextView.setColoredKeyword(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a KDoc here too. Thanks! 👍🏼

Copy link
Copy Markdown
Collaborator

@amaury901130 amaury901130 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, made sure to add a mini description of these extensions in the readme file.

@hrodrick hrodrick self-assigned this Apr 21, 2022
@hrodrick hrodrick added the enhancement New feature or request label Apr 21, 2022
@hrodrick hrodrick force-pushed the feature/utility-extensions branch from 73898e5 to 9b71ae8 Compare April 21, 2022 16:12
@hrodrick hrodrick merged commit 79b5be3 into rootstrap:master-koin Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants