Skip to content

Commit

Permalink
chore: merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ghasemdev committed Aug 21, 2022
2 parents 8cbc17a + 4814ca7 commit 4a9c048
Show file tree
Hide file tree
Showing 230 changed files with 16,536 additions and 641 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [🎉 1.4.0 Structure, Metrica] - 2022-08-21

### 🚀 Features

* Add New Structure Class.
* lazy singleton object
* object pool pattern
* validator class `EmailChecker`, `PasswordChecker`, `PhoneChecker` and `IRPhoneChecker`
* Add `Metrica` Module.
* metrica builder `yandexMetrica("api-key") {}`, `yandexMetricaConfig("api-key") {}`
, `withLogs(isDebugMode)`, `withSessionTimeout(duration)`
* metrica reporter for serialized class `YandexMetricaX.reportEvent("key", data-class)`
* metrica profile builder `metricaProfile {}`, `withValue(Int)`

### 💥 Breaking Changes

* Remove additional classes from affogato-coroutines-android

### 💭 Other

* rename `block` -> `runBlock`
* rename `isNotNullOrEmpty` -> `isNotNullNotEmpty`, `isNotNullOrBlank` -> `isNotNullNotBlank`

## [🎉 1.3.0 Structure] - 2022-08-18

### 🚀 Features
Expand Down
45 changes: 41 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Coroutines module contains suspended try-catch from Core-ktx and `DispatchersPro
coroutines context in main and test source.

```Kotlin
// Old way
// Normal way
suspend fun foo() = withContext(Dispatchers.Default) {
return try {
// do something return value
Expand All @@ -35,15 +35,45 @@ suspend fun foo() = withContext(Dispatchers.Default) {
}
}

// New way
// Affogato way
suspend fun foo() = suspendedTryCatchNull {
// do something return value
// do something return value
}
```

### [Metrica-ktx](https://github.com/ghasemdev/affogato/wiki/Metrica-Ktx)

This module adds Yandex Metrica to your project. You can use it for crashlytics and reporting events
and push notifications.

```kotlin
yandexMetrica("api-key") {
// configuration
}

@Serializable
data class Foo(val bar: String)
YandexMetricaX.reportEvent("event_name", Foo("bar"))
```

### [Structure](https://github.com/ghasemdev/affogato/wiki/Structure)

This module contains useful struct class like `DataState` and `EntityMapper`.
This module contains useful structure class like `DataState` and `EntityMapper`. Also, it contains
`SingletonHolder` for creating singleton classes or `ObjectPool` for creating heavy objects to save
time. You can use checker class for validate phone, email and password.

```kotlin
class SharedPref private constructor(private val context: Context) {
// ...
companion object : SingletonHolder<SharedPref, Context>(::SharedPref)
}

StringPool["key"] = "token"
StringPool["key"] // token

PhoneChecker("09123456789").isValid() // true
PhoneChecker("09123456789").format("IR") // +98 912 345 6789
```

### [Compose Unit Size](https://github.com/ghasemdev/affogato/wiki/Unit-Size)

Expand All @@ -52,6 +82,13 @@ screen sizes in `sdp`, `ssp` and custom create with `@Dimen`. Also, we can
use `rememberWindowSize()` to know in which device we are (Compact, Medium, Expanded) or
use `postureState` to build adaptive and responsive UIs in **Foldables**.

```kotlin
@Dimen(type = "dp", values = ["320:70", "480:80", "600:180", "720:180"])
val icon = 80.dp

dimen.icon // 80.dp in device with width 480.dp
```

# Links

Affogato is currently available for maven/gradle builds
Expand Down
4 changes: 2 additions & 2 deletions affogato-core-ktx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tasks.test {

dependencies {
// Serialization ---------------------------------------------------------------------------------
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0-RC")
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0")

// Immutable Collections -------------------------------------------------------------------------
api("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.5")
Expand All @@ -47,7 +47,7 @@ afterEvaluate {
create<MavenPublication>("java") {
groupId = "com.parsuomash.affogato"
artifactId = "affogato-core-ktx"
version = "1.3.0"
version = "1.4.0"

from(components["java"])
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
package com.parsuomash.affogato.core.ktx

/**
* Return the value before run the execution block.
*
* Example:
* ```Kotlin
* var value = "Hello"
* val blockString = value.runBlock { string += " World" }
* blockString // "Hello"
* value //Hello World"
* ```
* @since 1.4.0
* @see run
* @see with
* @see apply
* @see let
* @see also
*/
inline fun <T> T.runBlock(block: () -> Unit): T {
val old = this
block()
return old
}

// TODO v2.0.0 remove deprecated functions ---------------------------------------------------------

/**
* Return the value before run the execution block.
*
Expand All @@ -17,6 +42,15 @@ package com.parsuomash.affogato.core.ktx
* @see let
* @see also
*/
@Deprecated(
message = "This function is deprecated and will be removed in next major release." +
"Use runBlock() instead.",
replaceWith = ReplaceWith(
expression = "runBlock(block)",
imports = ["com.parsuomash.affogato.core.ktx.runBlock"]
),
level = DeprecationLevel.WARNING
)
inline fun <T> T.block(block: () -> Unit): T {
val old = this
block()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ fun String.toCalendarOrNull(pattern: String = "EEE MMM dd HH:mm:ss zzz yyyy"): C
simpleDateFormat.parse(this).toCalendar()
}

/**
* Formats a [Calendar] into a date-time [String].
* @since 1.1.1
* @throws IllegalArgumentException if the given pattern is invalid
* @return The formatted date-time string.
* @see SimpleDateFormat
*/
fun Calendar.format(pattern: String): String {
simpleDateFormat.applyPattern(pattern)
return simpleDateFormat.format(time)
}

// TODO v2.0.0 remove deprecated functions ---------------------------------------------------------

/**
* Formats a [Calendar] into a date-time [String].
* @since 1.1.0
Expand All @@ -155,7 +169,7 @@ fun String.toCalendarOrNull(pattern: String = "EEE MMM dd HH:mm:ss zzz yyyy"): C
message = "This function is deprecated and will be removed in next major release." +
"Use format() instead.",
replaceWith = ReplaceWith(
expression = "format",
expression = "format(format)",
imports = ["com.parsuomash.affogato.core.ktx.datetime.format"]
),
level = DeprecationLevel.WARNING
Expand All @@ -164,15 +178,3 @@ fun Calendar.toString(format: String): String {
simpleDateFormat.applyPattern(format)
return simpleDateFormat.format(time)
}

/**
* Formats a [Calendar] into a date-time [String].
* @since 1.1.1
* @throws IllegalArgumentException if the given pattern is invalid
* @return The formatted date-time string.
* @see SimpleDateFormat
*/
fun Calendar.format(pattern: String): String {
simpleDateFormat.applyPattern(pattern)
return simpleDateFormat.format(time)
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,40 +146,42 @@ fun String.toDateOrNull(pattern: String = "EEE MMM dd HH:mm:ss zzz yyyy"): Date?
*
* Example:
* ```Kotlin
* 1659814200000.toDate().toString("MM/dd/yyyy") // 08/07/2022
* 1659814200000.toDate().format("MM/dd/yyyy") // 08/07/2022
* ```
* @since 1.1.0
* @since 1.1.1
* @throws IllegalArgumentException if the given pattern is invalid
* @return The formatted date-time string.
* @see SimpleDateFormat
*/
@Deprecated(
message = "This function is deprecated and will be removed in next major release." +
"Use format() instead.",
replaceWith = ReplaceWith(
expression = "format",
imports = ["com.parsuomash.affogato.core.ktx.datetime.format"]
),
level = DeprecationLevel.WARNING
)
fun Date.toString(format: String): String {
simpleDateFormat.applyPattern(format)
fun Date.format(pattern: String): String {
simpleDateFormat.applyPattern(pattern)
return simpleDateFormat.format(this)
}

// TODO v2.0.0 remove deprecated functions ---------------------------------------------------------

/**
* Formats a [Date] into a date-time [String].
*
* Example:
* ```Kotlin
* 1659814200000.toDate().format("MM/dd/yyyy") // 08/07/2022
* 1659814200000.toDate().toString("MM/dd/yyyy") // 08/07/2022
* ```
* @since 1.1.1
* @since 1.1.0
* @throws IllegalArgumentException if the given pattern is invalid
* @return The formatted date-time string.
* @see SimpleDateFormat
*/
fun Date.format(pattern: String): String {
simpleDateFormat.applyPattern(pattern)
@Deprecated(
message = "This function is deprecated and will be removed in next major release." +
"Use format() instead.",
replaceWith = ReplaceWith(
expression = "format(format)",
imports = ["com.parsuomash.affogato.core.ktx.datetime.format"]
),
level = DeprecationLevel.WARNING
)
fun Date.toString(format: String): String {
simpleDateFormat.applyPattern(format)
return simpleDateFormat.format(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,40 +108,42 @@ fun String.toInstantOrNull(pattern: String = "EEE MMM dd HH:mm:ss zzz yyyy"): In
*
* Example:
* ```Kotlin
* 1659814200000.toInstant().toString("MM/dd/yyyy") // 08/07/2022
* 1659814200000.toInstant().format("MM/dd/yyyy") // 08/07/2022
* ```
* @since 1.1.0
* @since 1.1.1
* @throws IllegalArgumentException if the given pattern is invalid
* @return The formatted date-time string.
* @see SimpleDateFormat
*/
@Deprecated(
message = "This function is deprecated and will be removed in next major release." +
"Use format() instead.",
replaceWith = ReplaceWith(
expression = "format",
imports = ["com.parsuomash.affogato.core.ktx.datetime.format"]
),
level = DeprecationLevel.WARNING
)
fun Instant.toString(format: String): String {
simpleDateFormat.applyPattern(format)
fun Instant.format(pattern: String): String {
simpleDateFormat.applyPattern(pattern)
return simpleDateFormat.format(toDate())
}

// TODO v2.0.0 remove deprecated functions ---------------------------------------------------------

/**
* Formats a [Instant] into a date-time [String].
*
* Example:
* ```Kotlin
* 1659814200000.toInstant().format("MM/dd/yyyy") // 08/07/2022
* 1659814200000.toInstant().toString("MM/dd/yyyy") // 08/07/2022
* ```
* @since 1.1.1
* @since 1.1.0
* @throws IllegalArgumentException if the given pattern is invalid
* @return The formatted date-time string.
* @see SimpleDateFormat
*/
fun Instant.format(pattern: String): String {
simpleDateFormat.applyPattern(pattern)
@Deprecated(
message = "This function is deprecated and will be removed in next major release." +
"Use format() instead.",
replaceWith = ReplaceWith(
expression = "format(format)",
imports = ["com.parsuomash.affogato.core.ktx.datetime.format"]
),
level = DeprecationLevel.WARNING
)
fun Instant.toString(format: String): String {
simpleDateFormat.applyPattern(format)
return simpleDateFormat.format(toDate())
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,40 +131,42 @@ fun String.toLocalDateOrNull(pattern: String = "EEE MMM dd HH:mm:ss zzz yyyy"):
*
* Example:
* ```Kotlin
* 1659814200000.toLocalDate().toString("MM/dd/yyyy") // 08/07/2022
* 1659814200000.toLocalDate().format("MM/dd/yyyy") // 08/07/2022
* ```
* @since 1.1.0
* @since 1.1.1
* @throws IllegalArgumentException if the given pattern is invalid
* @return The formatted date-time string.
* @see SimpleDateFormat
*/
@Deprecated(
message = "This function is deprecated and will be removed in next major release." +
"Use format() instead.",
replaceWith = ReplaceWith(
expression = "format",
imports = ["com.parsuomash.affogato.core.ktx.datetime.format"]
),
level = DeprecationLevel.WARNING
)
fun LocalDate.toString(format: String): String {
simpleDateFormat.applyPattern(format)
fun LocalDate.format(pattern: String): String {
simpleDateFormat.applyPattern(pattern)
return simpleDateFormat.format(toDate())
}

// TODO v2.0.0 remove deprecated functions ---------------------------------------------------------

/**
* Formats a [LocalDate] into a date-time [String].
*
* Example:
* ```Kotlin
* 1659814200000.toLocalDate().format("MM/dd/yyyy") // 08/07/2022
* 1659814200000.toLocalDate().toString("MM/dd/yyyy") // 08/07/2022
* ```
* @since 1.1.1
* @since 1.1.0
* @throws IllegalArgumentException if the given pattern is invalid
* @return The formatted date-time string.
* @see SimpleDateFormat
*/
fun LocalDate.format(pattern: String): String {
simpleDateFormat.applyPattern(pattern)
@Deprecated(
message = "This function is deprecated and will be removed in next major release." +
"Use format() instead.",
replaceWith = ReplaceWith(
expression = "format(format)",
imports = ["com.parsuomash.affogato.core.ktx.datetime.format"]
),
level = DeprecationLevel.WARNING
)
fun LocalDate.toString(format: String): String {
simpleDateFormat.applyPattern(format)
return simpleDateFormat.format(toDate())
}
Loading

0 comments on commit 4a9c048

Please sign in to comment.