Skip to content

Commit

Permalink
Merge pull request #53 from RedMadRobot/feature/remove-self-impl-text
Browse files Browse the repository at this point in the history
resource-ktx: Removed Text implementation
  • Loading branch information
sonulen authored May 15, 2024
2 parents 65a8aa8 + 4d97908 commit 4a3476d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 95 deletions.
4 changes: 1 addition & 3 deletions resources-ktx/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

### Changed

- **Text**: added abstract methods `equals`, `hashCode`
- **Text**: added `Parcelable` implementation
- **Text**: added `companion object` and `Text.EMPTY` implementation
- **Breaking change**: `Text` moved to a separate library [com.redmadrobot.textvalue](https://github.com/RedMadRobot/TextValue).

## [1.3.1-0] (2021-10-03)

Expand Down
25 changes: 0 additions & 25 deletions resources-ktx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,6 @@ Dimension converters for `Context` (the same available for `Resources`):
- `Context.pxToDp(px: Int): Float`
- `Context.pxToDp(px: Float): Float`

### Wrapper `Text`

**Text** is a wrapper to make it possible to work with plain `String` and `StringRes` in the same way.
It may be useful for cases when you want to fallback to `StringRes` if desired string value is `null`.

You can wrap `String` and `StringRes` into `Text` using `Text.Plain(String)` and `Text.Resource(Int)`, accordingly and use method `Text.get(Context)` to retrieve `String`:

```kotlin
// in some place where we can't access Context
val errorMessage = exception.message?.let(Text::Plain) ?: Text.Resource(R.string.unknown_error)
showMessage(errorMessage)

// in Activity, Fragment or View
fun showMessage(text: Text) {
val messageText = text.get(context)
//...
}
```

There are extensions to work with `Text` like with `StringRes`:

- `Context.getString(text: Text): String`
- `Fragment.getString(text: Text): String`
- `View.getString(text: Text): String`

## Contributing

Merge requests are welcome.
Expand Down
67 changes: 0 additions & 67 deletions resources-ktx/src/main/kotlin/Text.kt

This file was deleted.

0 comments on commit 4a3476d

Please sign in to comment.