Message-Data

Message-Data classes for easier handling

License

License

Categories

Categories

Data
GroupId

GroupId

ro.dragossusi
ArtifactId

ArtifactId

messagedata-metadata
Last Version

Last Version

1.0.7
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

Message-Data
Message-Data classes for easier handling
Project URL

Project URL

https://github.com/dragossusi/Message-Data/
Source Code Management

Source Code Management

https://github.com/dragossusi/Message-Data/

Download messagedata-metadata

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-common jar 1.4.32

Project Modules

There are no modules declared in this project.

Message-Data

Maven Central

Message data classes for easier handling.

Download

Gradle:

dependencies {
  implementation 'ro.dragossusi:messagedata:1.0.5'
}

Usage

You can create simple messages from things out of the box

//using constructors
val message = StringMessageData("Message")

//using extensions
val messageExtension = "Message".toMessageData()

To parse the message, create a message parser.

val message = StringMessageData("Message")
val parser = DefaultDataParser()
println(message.getMessage(parser)) // prints Message

You can combine multiple message datas:

val parser = DefaultDataParser()
val list = listOf(
    "1".toMessageData(),
    "2".toMessageData(),
    "3".toMessageData(),
)
val combined = list.join(",")
println(combined.getMessage(parser)) // prints "1,2,3"

val first = "First".toMessageData()
val second = "Second".toMessageData()

val concat = ConcatMessageData(
    first,
    second,
    " "
)
println(concat.getMessage(parser)) // prints "First Second"

//also works with operators
println((first + second).getMEssage(parser)) // prints "FirstSecond"

Android

Download

Gradle:

dependencies {
  implementation 'ro.dragossusi:messagedata-android:1.0.5'
}

Usage

You can create localized messages from android resources.

Supports: strings, string formats(only using %s) and plurals.

String Res

<string name="localized_string">Localized</string>
val localizedString = LocalizedMessageData(R.string.loclized_string)

val parser = ContextMessageDataParser(context)

//or use FragmentMessageDataParser(fragment) for fragments

println(localizedString.getMessage(parser)) // prints "Localized"

String format Res

<string name="localized_string">Localized %s</string>
val text = "Text".toMessageData()

val localizedString = LocalizedFormatMessageData(
    R.string.loclized_string,
    text
)

val parser = ContextMessageDataParser(context)

println(localizedString.getMessage(parser)) // prints "Localized Text"

Versions

Version
1.0.7
1.0.6
1.0.5