Skip to content

Commit

Permalink
8.0.0-alpha01
Browse files Browse the repository at this point in the history
  • Loading branch information
psteiger committed Nov 6, 2021
1 parent 3e6149e commit 254e567
Show file tree
Hide file tree
Showing 23 changed files with 436 additions and 422 deletions.
9 changes: 9 additions & 0 deletions .idea/kotlinScripting.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 24 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
val kotlinVersion = "1.5.31"
classpath("com.android.tools.build:gradle:7.1.0-alpha13")
classpath(kotlin("gradle-plugin", version = kotlinVersion))
}
plugins {
id("com.android.library") version "7.1.0-beta02" apply false
kotlin("android") version "1.6.0-RC2" apply false
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}

tasks.register("clean", Delete::class) {
tasks.register<Delete>("clean") {
delete(rootProject.buildDir)
}

apply(from = "$rootDir/scripts/publish-root.gradle.kts")

// Set up Sonatype repository
nexusPublishing {
repositories {
sonatype {
val ossrhUsername: String by extra
val ossrhPassword: String by extra
val sonatypeStagingProfileId: String by extra
stagingProfileId.set(sonatypeStagingProfileId)
username.set(ossrhUsername)
password.set(ossrhPassword)
// Add these lines if using new Sonatype infra
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}
79 changes: 65 additions & 14 deletions locationfetcher/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ plugins {
id("com.android.library")
kotlin("android")
`maven-publish`
signing
}

apply(from = "$rootDir/scripts/publish-root.gradle.kts")

group = "app.freel"
version = "8.0.0-alpha01"

android {
compileSdk = 31
defaultConfig {
Expand All @@ -15,46 +21,91 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
freeCompilerArgs += listOf(
"-Xexplicit-api=strict",
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
)
jvmTarget = "1.8"
languageVersion = "1.5"
}
}

dependencies {
coroutines()
jetpack()
implementation("com.google.android.gms:play-services-location:18.0.0")
implementation("javax.inject:javax.inject:1")
}

afterEvaluate {
publishing {
publications {
// Creates a Maven publication called "release".
register("release", MavenPublication::class) {
register<MavenPublication>("release") {
from(components["release"])
groupId = "app.freel"
version = "8.0.0-alpha01"
artifactId = project.name
pom {
name.set(project.name)
description.set("Easy Location fetching for Android apps.")
url.set("https://github.com/psteiger/LocationFetcher")
licenses {
license {
name.set("MIT License")
url.set("https://github.com/psteiger/LocationFetcher/blob/master/LICENSE")
}
}
developers {
developer {
id.set("psteiger")
name.set("Patrick Steiger")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:github.com/psteiger/LocationFetcher/LocationFetcher.git")
developerConnection.set("scm:git:ssh://github.com/psteiger/LocationFetcher/LocationFetcher.git")
url.set("https://github.com/LocationFetcher/psteiger/tree/master")
}
}
}
}
}
}

signing {
val signingKeyId: String by extra
val signingPassword: String by extra
val signingKey: String by extra
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign(publishing.publications)
}

dependencies {
coroutines()
jetpack()
arrow()
implementation("com.google.android.gms:play-services-location:18.0.0")
implementation("javax.inject:javax.inject:1")
}

fun DependencyHandlerScope.arrow() {
val version = "1.0.1"
// implementation(platform("io.arrow-kt:arrow-stack:$version"))
api("io.arrow-kt:arrow-core:$version")

}

fun DependencyHandlerScope.coroutines() {
val version = "1.5.2"
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version")
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$version")
}

fun DependencyHandlerScope.jetpack() {
implementation("androidx.activity:activity-ktx:1.4.0-beta01")
implementation("androidx.fragment:fragment-ktx:1.4.0-alpha10")
implementation("androidx.appcompat:appcompat:1.4.0-beta01")
implementation("androidx.core:core-ktx:1.6.0")
implementation("androidx.activity:activity-ktx:1.4.0")
implementation("androidx.fragment:fragment-ktx:1.4.0-rc01")
implementation("androidx.appcompat:appcompat:1.4.0-rc01")
implementation("androidx.core:core-ktx:1.7.0")
androidxLifecycle()
}

fun DependencyHandlerScope.androidxLifecycle() {
val lifecycleVersion = "2.4.0-rc01"
val lifecycleVersion = "2.4.0"
implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion")
implementation("androidx.lifecycle:lifecycle-common:$lifecycleVersion")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@ import com.freelapp.libs.locationfetcher.impl.LocationFetcherImpl
import com.freelapp.libs.locationfetcher.impl.LocationSourceImpl
import kotlinx.coroutines.CoroutineScope

fun ComponentActivity.locationFetcher(
public fun ComponentActivity.locationFetcher(
config: LocationFetcher.Config.() -> Unit = { }
): LocationFetcher =
LocationFetcher(this@locationFetcher, LocationFetcher.Config().apply(config))

fun Context.locationFetcher(
public fun Context.locationFetcher(
owner: LifecycleOwner,
config: LocationFetcher.Config.() -> Unit = { }
): LocationFetcher =
LocationFetcher(this@locationFetcher, owner, LocationFetcher.Config().apply(config))

fun LocationFetcher(
public fun LocationFetcher(
activity: ComponentActivity,
config: LocationFetcher.Config.() -> Unit = { }
): LocationFetcher =
LocationFetcher(activity, LocationFetcher.Config().apply(config))

fun LocationFetcher(
public fun LocationFetcher(
context: Context,
owner: LifecycleOwner,
config: LocationFetcher.Config.() -> Unit = { }
): LocationFetcher =
LocationFetcher(context, owner, LocationFetcher.Config().apply(config))

fun LocationFetcher(
public fun LocationFetcher(
activity: ComponentActivity,
config: LocationFetcher.Config
): LocationFetcher = LocationFetcherImpl(activity, config.copy())

fun LocationFetcher(
public fun LocationFetcher(
context: Context,
owner: LifecycleOwner,
config: LocationFetcher.Config
): LocationFetcher = LocationFetcherImpl(context, owner, config.copy())

fun LocationSource(
public fun LocationSource(
scope: CoroutineScope,
locationFetcher: LocationFetcher,
): LocationSource = LocationSourceImpl(scope, locationFetcher)
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ package com.freelapp.libs.locationfetcher
import android.location.Location
import android.location.LocationManager
import androidx.lifecycle.Lifecycle
import arrow.core.Either
import arrow.core.Nel
import com.google.android.gms.location.LocationRequest
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.SharedFlow

interface LocationFetcher {
companion object {
public interface LocationFetcher {
private companion object {
private val locationRequest = LocationRequest.create()
private const val FUSED_PROVIDER = "fused"
}

val location: StateFlow<Location?>
val permissionStatus: StateFlow<PermissionStatus>
val settingsStatus: StateFlow<SettingsStatus>
public val location: SharedFlow<Either<Nel<Error>, Location>>
public val permissionStatus: SharedFlow<Boolean>
public val settingsStatus: SharedFlow<Boolean>

suspend fun requestLocationPermissions()
suspend fun requestEnableLocationSettings()
public suspend fun requestLocationPermissions()
public suspend fun requestEnableLocationSettings()

data class Config(
public data class Config(
var replayLast: Boolean = true,
var fastestInterval: Long = locationRequest.fastestInterval,
var interval: Long = locationRequest.interval,
var maxWaitTime: Long = locationRequest.maxWaitTime,
Expand All @@ -33,13 +36,20 @@ interface LocationFetcher {
var debug: Boolean = false
)

sealed class Provider(val value: String) {
object GPS : Provider(LocationManager.GPS_PROVIDER)
object Network : Provider(LocationManager.NETWORK_PROVIDER)
object Fused : Provider(FUSED_PROVIDER)
public sealed class Provider(public val value: String) {
public object GPS : Provider(LocationManager.GPS_PROVIDER)
public object Network : Provider(LocationManager.NETWORK_PROVIDER)
public object Fused : Provider(FUSED_PROVIDER)
}

enum class PermissionStatus { UNKNOWN, ALLOWED, DENIED }
public sealed class Error {
public object PermissionDenied : Error()
public object SettingDisabled : Error()
}

@Deprecated("Permission status is now reported by 'location' flow in case of error")
public enum class PermissionStatus { UNKNOWN, ALLOWED, DENIED }

enum class SettingsStatus { UNKNOWN, ENABLED, DISABLED }
@Deprecated("Settings status is now reported by 'location' flow in case of error")
public enum class SettingsStatus { UNKNOWN, ENABLED, DISABLED }
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.freelapp.libs.locationfetcher

import android.location.Location
import kotlinx.coroutines.flow.StateFlow
import arrow.core.Either
import arrow.core.Nel
import kotlinx.coroutines.flow.SharedFlow

interface LocationSource {
val realLocation: StateFlow<Location?>
val location: StateFlow<Location?>
var customLocation: Location?
var locationSource: Source
enum class Source { REAL, CUSTOM }
public interface LocationSource {
public val realLocation: SharedFlow<Either<Nel<LocationFetcher.Error>, Location>>
public val location: SharedFlow<Either<Nel<LocationFetcher.Error>, Location>>
public var customLocation: Location?
public var locationSource: Source
public enum class Source { REAL, CUSTOM }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import javax.inject.Qualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class ActivityLocationFetcher
public annotation class ActivityLocationFetcher
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import javax.inject.Qualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class ApplicationLocationFetcher
public annotation class ApplicationLocationFetcher
Loading

0 comments on commit 254e567

Please sign in to comment.