Skip to content

Commit

Permalink
chore: merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ghasemdev committed Aug 16, 2022
2 parents 84da0af + d48d25e commit 02c225a
Show file tree
Hide file tree
Showing 96 changed files with 6,181 additions and 47 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ 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.2.0 Coroutines] - 2022-08-16

### 🚀 Features

* `DispatchersProvider`.
* suspended try-catch.

## [🐛 v1.1.2 Core-ktx] - 2022-08-15

### 🚀 Features
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Version](https://shields.io/badge/VERSION-1.1.2-blue?style=for-the-badge)](https://github.com/ghasemdev/affogato/releases/tag/1.1.2)
[![Version](https://shields.io/badge/VERSION-1.2.0-blue?style=for-the-badge)](https://github.com/ghasemdev/affogato/releases/tag/1.2.0)
[![Kotlin](https://shields.io/badge/Kotlin-1.7.10-pink?style=for-the-badge)](https://kotlinlang.org/)
[![API](https://shields.io/badge/Api-+21-green?style=for-the-badge)](https://www.android.com/)
[![License MIT](https://shields.io/badge/LICENSE-MIT-orange?style=for-the-badge)](https://opensource.org/licenses/MIT)
Expand Down Expand Up @@ -30,7 +30,7 @@ use `postureState` to build adaptive and responsive UIs in **Foldables**.
# Links

Affogato is currently available for maven/gradle builds
at [Jitpack](https://jitpack.io/#ghasemdev/affogato/1.1.2) (
at [Jitpack](https://jitpack.io/#ghasemdev/affogato/1.2.0) (
read [Getting started](https://github.com/ghasemdev/affogato/wiki/Getting-Started)).

* [Wiki](https://github.com/ghasemdev/affogato/wiki)
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 @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("java-library")
id("org.jetbrains.kotlin.jvm")
kotlin("jvm")
id("maven-publish")
}

Expand Down Expand Up @@ -44,7 +44,7 @@ afterEvaluate {
create<MavenPublication>("java") {
groupId = "com.parsuomash.affogato"
artifactId = "affogato-core-ktx"
version = "1.1.2"
version = "1.2.0"

from(components["java"])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ package com.parsuomash.affogato.core.ktx
* @see groupingBy
* @see eachCount
*/
fun counter(content: String): Map<Char, Int> = content.groupingBy { it }.eachCount()
fun counter(content: String): Map<Char, Int> =
content.groupingBy { it }.eachCount()

/**
* Calculate count of each value by group in the Array.
Expand All @@ -29,7 +30,8 @@ fun counter(content: String): Map<Char, Int> = content.groupingBy { it }.eachCou
* @see eachCount
* @see arrayOf
*/
fun <T> counter(content: Array<T>): Map<T, Int> = content.groupingBy { it }.eachCount()
fun <T> counter(content: Array<T>): Map<T, Int> =
content.groupingBy { it }.eachCount()

/**
* Calculate count of each value by group in the byte array.
Expand All @@ -44,7 +46,8 @@ fun <T> counter(content: Array<T>): Map<T, Int> = content.groupingBy { it }.each
* @see eachCount
* @see byteArrayOf
*/
fun counter(content: ByteArray): Map<Byte, Int> = content.toList().groupingBy { it }.eachCount()
fun counter(content: ByteArray): Map<Byte, Int> =
content.toList().groupingBy { it }.eachCount()

/**
* Calculate count of each value by group in the char array.
Expand All @@ -59,7 +62,8 @@ fun counter(content: ByteArray): Map<Byte, Int> = content.toList().groupingBy {
* @see eachCount
* @see charArrayOf
*/
fun counter(content: CharArray): Map<Char, Int> = content.toList().groupingBy { it }.eachCount()
fun counter(content: CharArray): Map<Char, Int> =
content.toList().groupingBy { it }.eachCount()

/**
* Calculate count of each value by group in the short array.
Expand All @@ -74,7 +78,8 @@ fun counter(content: CharArray): Map<Char, Int> = content.toList().groupingBy {
* @see eachCount
* @see shortArrayOf
*/
fun counter(content: ShortArray): Map<Short, Int> = content.toList().groupingBy { it }.eachCount()
fun counter(content: ShortArray): Map<Short, Int> =
content.toList().groupingBy { it }.eachCount()

/**
* Calculate count of each value by group in the int array.
Expand All @@ -89,7 +94,8 @@ fun counter(content: ShortArray): Map<Short, Int> = content.toList().groupingBy
* @see eachCount
* @see intArrayOf
*/
fun counter(content: IntArray): Map<Int, Int> = content.toList().groupingBy { it }.eachCount()
fun counter(content: IntArray): Map<Int, Int> =
content.toList().groupingBy { it }.eachCount()

/**
* Calculate count of each value by group in the long array.
Expand All @@ -104,7 +110,8 @@ fun counter(content: IntArray): Map<Int, Int> = content.toList().groupingBy { it
* @see eachCount
* @see longArrayOf
*/
fun counter(content: LongArray): Map<Long, Int> = content.toList().groupingBy { it }.eachCount()
fun counter(content: LongArray): Map<Long, Int> =
content.toList().groupingBy { it }.eachCount()

/**
* Calculate count of each value by group in the float array.
Expand All @@ -119,7 +126,8 @@ fun counter(content: LongArray): Map<Long, Int> = content.toList().groupingBy {
* @see eachCount
* @see floatArrayOf
*/
fun counter(content: FloatArray): Map<Float, Int> = content.toList().groupingBy { it }.eachCount()
fun counter(content: FloatArray): Map<Float, Int> =
content.toList().groupingBy { it }.eachCount()

/**
* Calculate count of each value by group in the double array.
Expand All @@ -134,7 +142,8 @@ fun counter(content: FloatArray): Map<Float, Int> = content.toList().groupingBy
* @see eachCount
* @see doubleArrayOf
*/
fun counter(content: DoubleArray): Map<Double, Int> = content.toList().groupingBy { it }.eachCount()
fun counter(content: DoubleArray): Map<Double, Int> =
content.toList().groupingBy { it }.eachCount()

/**
* Calculate count of each value by group in the boolean array.
Expand Down Expand Up @@ -165,7 +174,8 @@ fun counter(content: BooleanArray): Map<Boolean, Int> =
* @see eachCount
* @see listOf
*/
fun <T> counter(content: Iterable<T>): Map<T, Int> = content.groupingBy { it }.eachCount()
fun <T> counter(content: Iterable<T>): Map<T, Int> =
content.groupingBy { it }.eachCount()

/**
* when variable is null default value maintained.
Expand All @@ -178,7 +188,8 @@ fun <T> counter(content: Iterable<T>): Map<T, Int> = content.groupingBy { it }.e
* @since 1.1.0
* @return [T] value or **default**
*/
fun <T> T?.orDefault(default: T): T = this ?: default
fun <T> T?.orDefault(default: T): T =
this ?: default

/**
* Checking nullability.
Expand All @@ -194,7 +205,8 @@ fun <T> T?.orDefault(default: T): T = this ?: default
* @since 1.1.0
* @return [Boolean]
*/
fun <T> T?.isNull(): Boolean = this == null
fun <T> T?.isNull(): Boolean =
this == null

/**
* Checking none nullability.
Expand All @@ -210,7 +222,8 @@ fun <T> T?.isNull(): Boolean = this == null
* @since 1.1.0
* @return [Boolean]
*/
fun <T> T?.isNotNull(): Boolean = this != null
fun <T> T?.isNotNull(): Boolean =
this != null

/**
* ifNull execute when value is null.
Expand All @@ -234,7 +247,8 @@ fun <T> T?.isNotNull(): Boolean = this != null
* @since 1.1.0
* @return value or [Unit]
*/
inline fun <T> T?.ifNull(block: (T?) -> Any): Any = this ?: block(this)
inline fun <T> T?.ifNull(block: (T?) -> Any): Any =
this ?: block(this)

/**
* ifNotNull execute when value isn't null.
Expand All @@ -258,10 +272,11 @@ inline fun <T> T?.ifNull(block: (T?) -> Any): Any = this ?: block(this)
* @since 1.1.0
* @return value or [Unit]
*/
inline fun <T, R> T?.ifNotNull(block: (T) -> R): R? = if (this != null) block(this) else this
inline fun <T, R> T?.ifNotNull(block: (T) -> R): R? =
if (this != null) block(this) else this

/**
* Sometimes we need try-catch block without error handling.
* tryCatchIgnore used when you want to ignore catch block if an exception is thrown.
*
* Example:
* ```Kotlin
Expand All @@ -280,7 +295,7 @@ inline fun tryCatchIgnore(block: () -> Unit) {
}

/**
* When try-catch block failed return false otherwise true.
* tryCatchBoolean used when you want to return false if an exception is thrown.
*
* Example:
* ```Kotlin
Expand All @@ -294,6 +309,7 @@ inline fun tryCatchIgnore(block: () -> Unit) {
* } // true
* ```
* @since 1.1.0
* @see tryCatchBool
*/
inline fun tryCatchBoolean(block: () -> Unit): Boolean {
return try {
Expand All @@ -305,7 +321,37 @@ inline fun tryCatchBoolean(block: () -> Unit): Boolean {
}

/**
* When try-catch block failed return null otherwise latest value.
* tryCatchBool used when you want to return a boolean value or return false
* if an exception is thrown.
*
* Example:
* ```Kotlin
* tryCatchBoolean {
* ...
* throw Exception("throw")
* } // false
*
* tryCatchBoolean {
* val result = false
* if(...) {
* result = true
* }
* result
* }
* ```
* @since 1.2.0
* @see tryCatchBoolean
*/
inline fun tryCatchBool(block: () -> Boolean): Boolean {
return try {
block()
} catch (_: Exception) {
false
}
}

/**
* tryCatchNull used when you want to return null if an exception is thrown.
*
* Example:
* ```Kotlin
Expand All @@ -330,7 +376,7 @@ inline fun <T> tryCatchNull(block: () -> T): T? {
}

/**
* When try-catch block failed return else block otherwise try block.
* tryCatchElse used when you want to return a default value if an exception is thrown.
*
* Example:
* ```Kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ internal class StandardKtTest {
print(num)
}
assertThat(result2).isTrue()

val result3 = tryCatchBool {
raiseError()
}
assertThat(result3).isFalse()

val result4 = tryCatchBool {
false
}
assertThat(result4).isFalse()
}

@Test
Expand Down
2 changes: 2 additions & 0 deletions affogato-coroutines-android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
.gradle
63 changes: 63 additions & 0 deletions affogato-coroutines-android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
plugins {
id("com.android.library")
kotlin("android")
id("maven-publish")
}

android {
compileSdk = 33
buildToolsVersion = "33.0.0"

defaultConfig {
minSdk = 21
targetSdk = 33

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
apiVersion = "1.7"
languageVersion = "1.7"
jvmTarget = "11"
}
}

dependencies {
implementation(project(":affogato-core-ktx"))

// Coroutines ------------------------------------------------------------------------------------
api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
api("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4")

// Test ------------------------------------------------------------------------------------------
testImplementation("junit:junit:4.13.2")
testImplementation("com.google.truth:truth:1.1.3")
}

afterEvaluate {
publishing {
publications {
create<MavenPublication>("release") {
groupId = "com.parsuomash.affogato"
artifactId = "affogato-coroutines-android"
version = "1.2.0"

from(components["release"])
}
}
}
}
Empty file.
21 changes: 21 additions & 0 deletions affogato-coroutines-android/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
2 changes: 2 additions & 0 deletions affogato-coroutines-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.parsuomash.affogato.coroutines.android" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.parsuomash.affogato.coroutines.android

import kotlinx.coroutines.CoroutineDispatcher

/**
* ## DispatcherProvider
* In coroutines, we need special dispatchers for a scope,
* and in a large project to manage these dispatchers in the main source and test source,
* we can use the implementation of this interface.
*
* @since 1.2.0
* @see CoroutineDispatcher
* @see StandardDispatchers
* @see TestDispatchers
*/
interface DispatchersProvider {
val main: CoroutineDispatcher
val io: CoroutineDispatcher
val default: CoroutineDispatcher
val unconfined: CoroutineDispatcher
}
Loading

0 comments on commit 02c225a

Please sign in to comment.