Skip to content

Commit

Permalink
Merge pull request #12 from phansier/update
Browse files Browse the repository at this point in the history
Update dependencies versions
  • Loading branch information
phansier authored Aug 22, 2021
2 parents 87166ae + 5737b74 commit cc5669c
Show file tree
Hide file tree
Showing 29 changed files with 482 additions and 272 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: set up JDK 1.8
- name: set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11
- name: Run tests
run: ./gradlew test
- name: Build a library with Gradle
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# FlowReactiveNetwork on Coroutines
[![Download](https://img.shields.io/maven-central/v/ru.beryukhov/flowreactivenetwork?versionPrefix=1.0.3) ](https://repo1.maven.org/maven2/ru/beryukhov/flowreactivenetwork/1.0.3/)
[![Kotlin Version](https://img.shields.io/badge/Kotlin-1.4.30-blue.svg)](https://kotlinlang.org)
[![Download](https://img.shields.io/maven-central/v/ru.beryukhov/flowreactivenetwork?versionPrefix=1.0.4) ](https://repo1.maven.org/maven2/ru/beryukhov/flowreactivenetwork/1.0.4/)
[![Kotlin Version](https://img.shields.io/badge/Kotlin-1.5.20-blue.svg)](https://kotlinlang.org)

[![kotlinweekly](https://img.shields.io/badge/kotlinweekly.net-204-blue.svg)](https://mailchi.mp/kotlinweekly/kotlin-weekly-204)
![CI](https://github.com/AndreySBer/FlowReactiveNetwork/workflows/Android%20CI/badge.svg)
Expand All @@ -20,7 +20,7 @@ You can depend on the library through Gradle:

```groovy
dependencies {
implementation 'ru.beryukhov:flowreactivenetwork:1.0.3'
implementation 'ru.beryukhov:flowreactivenetwork:1.0.4'
}
// now the library is available in mavenCentral()
allprojects {
Expand Down
100 changes: 0 additions & 100 deletions artifact-pom-manager.gradle

This file was deleted.

9 changes: 4 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
buildscript {
val kotlin_version by extra("1.4.30")
val coroutines_version by extra("1.4.2")
val robolectric_version by extra("4.4")
val kotlin_version by extra("1.5.20")
val coroutines_version by extra("1.5.1")
val robolectric_version by extra("4.6.1")

repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.3")
classpath("com.android.tools.build:gradle:7.0.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
}
}
Expand All @@ -17,7 +17,6 @@ allprojects {
repositories {
google()
mavenCentral()
jcenter()
}
}

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ plugins {
}
repositories {
google()
jcenter()
mavenCentral()
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
18 changes: 11 additions & 7 deletions reactiveNetwork/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
plugins {
id("com.android.library")
kotlin("android")
id("maven")
}

android {
compileSdkVersion(29)
compileSdk = 29
//testOptions { unitTests { includeAndroidResources = true } }

defaultConfig {
minSdkVersion(14)
minSdk = 14
}
compileOptions {
targetCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -36,6 +35,10 @@ android {
explicitApi()
}

kotlinOptions {
freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn"
}

dependencies {
val kotlin_version = rootProject.extra["kotlin_version"]
val coroutines_version = rootProject.extra["coroutines_version"]
Expand All @@ -45,18 +48,19 @@ android {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version")

implementation("androidx.annotation:annotation:1.1.0")
implementation("androidx.annotation:annotation:1.2.0")


testImplementation ("org.jetbrains.kotlin:kotlin-test-common:$kotlin_version")
testImplementation ("org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version")

testImplementation ("com.google.truth:truth:1.0.1")
testImplementation ("org.robolectric:robolectric:$robolectric_version")
testImplementation ("io.mockk:mockk:1.10.4")
testImplementation ("io.mockk:mockk:1.12.0")

testImplementation ("at.florianschuster.test:coroutines-test-extensions:0.1.2")
testImplementation ("androidx.test:core:1.3.0")
testImplementation ("org.jetbrains.kotlin:kotlin-test:$kotlin_version")
testImplementation ("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version")
testImplementation ("androidx.test:core:1.4.0")
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ object Preconditions {
*
* @return boolean true if current Android version is Lollipop or higher
*/
@androidx.annotation.ChecksSdkIntAtLeast(api = Build.VERSION_CODES.LOLLIPOP)
fun isAtLeastAndroidLollipop(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
}
Expand All @@ -67,6 +68,7 @@ object Preconditions {
*
* @return boolean true if current Android version is Marshmallow or higher
*/
@androidx.annotation.ChecksSdkIntAtLeast(api = Build.VERSION_CODES.M)
fun isAtLeastAndroidMarshmallow():Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ru.beryukhov.reactivenetwork

import java.util.Timer
import kotlin.concurrent.schedule
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import java.util.*
import kotlin.concurrent.schedule

/**
* Creates a flow that produces the first item after the given initial delay and subsequent items with the
Expand All @@ -19,7 +19,7 @@ import kotlin.concurrent.schedule
* @param period period between each element in milliseconds.
* @param initialDelay delay after which the first element will be produced (it is equal to [period] by default) in milliseconds.
*/
@ExperimentalCoroutinesApi
@OptIn(ExperimentalCoroutinesApi::class)
internal fun tickerFlow(
period: Long,
initialDelay: Long = period
Expand All @@ -29,7 +29,7 @@ internal fun tickerFlow(

val timer = Timer()
timer.schedule(initialDelay, period) {
offer(Unit)
trySend(Unit)
}

awaitClose { timer.cancel() }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package ru.beryukhov.reactivenetwork.internet.observing.strategy

import kotlinx.coroutines.ExperimentalCoroutinesApi
import java.io.IOException
import java.net.InetSocketAddress
import java.net.Socket
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import ru.beryukhov.reactivenetwork.Preconditions
import ru.beryukhov.reactivenetwork.internet.observing.InternetObservingStrategy
import ru.beryukhov.reactivenetwork.internet.observing.error.ErrorHandler
import ru.beryukhov.reactivenetwork.tickerFlow
import java.io.IOException
import java.net.InetSocketAddress
import java.net.Socket

/**
* Socket strategy for monitoring connectivity with the Internet.
Expand All @@ -21,7 +20,6 @@ class SocketInternetObservingStrategy : InternetObservingStrategy {
return DEFAULT_HOST
}

@ExperimentalCoroutinesApi
override fun observeInternetConnectivity(
initialIntervalInMs: Int,
intervalInMs: Int,
Expand Down Expand Up @@ -135,8 +133,7 @@ class SocketInternetObservingStrategy : InternetObservingStrategy {
timeoutInMs: Int,
errorHandler: ErrorHandler
): Boolean {
val isConnected: Boolean
isConnected = try {
return try {
socket.connect(InetSocketAddress(host, port), timeoutInMs)
socket.isConnected
} catch (e: IOException) {
Expand All @@ -148,7 +145,6 @@ class SocketInternetObservingStrategy : InternetObservingStrategy {
errorHandler.handleError(exception, "Could not close the socket")
}
}
return isConnected
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package ru.beryukhov.reactivenetwork.internet.observing.strategy

import kotlinx.coroutines.ExperimentalCoroutinesApi
import java.io.IOException
import java.net.HttpURLConnection
import java.net.URL
import javax.net.ssl.HttpsURLConnection
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import ru.beryukhov.reactivenetwork.Preconditions
import ru.beryukhov.reactivenetwork.internet.observing.InternetObservingStrategy
import ru.beryukhov.reactivenetwork.internet.observing.error.ErrorHandler
import ru.beryukhov.reactivenetwork.tickerFlow
import java.io.IOException
import java.net.HttpURLConnection
import java.net.URL
import javax.net.ssl.HttpsURLConnection

/**
* Walled Garden Strategy for monitoring connectivity with the Internet.
Expand All @@ -25,7 +24,6 @@ class WalledGardenInternetObservingStrategy : InternetObservingStrategy {
return DEFAULT_HOST
}

@ExperimentalCoroutinesApi
override fun observeInternetConnectivity(
initialIntervalInMs: Int,
intervalInMs: Int, host: String, port: Int, timeoutInMs: Int,
Expand All @@ -42,13 +40,18 @@ class WalledGardenInternetObservingStrategy : InternetObservingStrategy {
)
checkGeneralPreconditions(host, port, timeoutInMs, httpResponse, errorHandler)
val adjustedHost = adjustHost(host)
return tickerFlow(period = intervalInMs.toLong(), initialDelay = initialIntervalInMs.toLong()).map{isConnected(
adjustedHost,
port,
timeoutInMs,
httpResponse,
errorHandler
)}.distinctUntilChanged()
return tickerFlow(
period = intervalInMs.toLong(),
initialDelay = initialIntervalInMs.toLong()
).map {
isConnected(
adjustedHost,
port,
timeoutInMs,
httpResponse,
errorHandler
)
}.distinctUntilChanged()
}

override suspend fun checkInternetConnectivity(
Expand Down
Loading

0 comments on commit cc5669c

Please sign in to comment.