-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Publish library #3
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,77 @@ | ||
# SavedStateFlow | ||
A Kotlin StateFlow that persists the Android process death | ||
|
||
* [SavedStateFlow.kt](https://github.com/plusmobileapps/SavedStateFlow/blob/main/savedstateflow/src/main/java/com/plusmobileapps/savedstateflow/SavedStateFlow.kt) | ||
* [ViewModel example](https://github.com/plusmobileapps/SavedStateFlow/blob/main/sample/src/main/java/com/plusmobileapps/savedstateflow/MainViewModel.kt) | ||
A Kotlin [StateFlow](https://developer.android.com/kotlin/flow/stateflow-and-sharedflow) wrapper around [SavedStateHandle.getLiveData()](https://developer.android.com/topic/libraries/architecture/viewmodel-savedstate) | ||
|
||
![](docs/saved-state-flow.gif) | ||
* [SavedStateFlow.kt](https://github.com/plusmobileapps/SavedStateFlow/blob/main/savedstateflow/src/main/java/com/plusmobileapps/savedstateflow/SavedStateFlow.kt) - all the code for this simple library | ||
* [ViewModel example](https://github.com/plusmobileapps/SavedStateFlow/blob/main/sample/src/main/java/com/plusmobileapps/savedstateflow/MainViewModel.kt) - sample usage of `SavedStateFlow` in a `ViewModel` | ||
|
||
![](docs/saved-state-flow.gif) | ||
|
||
## Setup | ||
|
||
[![Maven Central](https://img.shields.io/maven-central/v/com.plusmobileapps/saved-state-flow?color=blue)](https://search.maven.org/artifact/com.plumobileapps/saved-state-flow) | ||
|
||
### Groovy Gradle | ||
|
||
```groovy | ||
implementation "com.plusmobileapps:saved-state-flow:<version>" | ||
``` | ||
|
||
### Kotlin Gradle | ||
|
||
```kotlin | ||
implementation("com.plusmobileapps:saved-state-flow:<version>") | ||
``` | ||
|
||
## Usage | ||
|
||
Inject a `SavedStateHandle` into a `ViewModel`, now use the `SavedStateFlow` extension function. | ||
|
||
```kotlin | ||
class MainViewModel(savedStateHandle: SavedStateHandle) : ViewModel() { | ||
|
||
private val query = SavedStateFlow( | ||
savedStateHandle = savedStateHandle, | ||
key = "main-viewmodel-query-key", | ||
defaultValue = "" | ||
) | ||
|
||
init { | ||
observeQuery() | ||
} | ||
|
||
fun updateQuery(query: String) { | ||
this.query.value = query | ||
} | ||
|
||
private fun observeQuery() { | ||
viewModelScope.launch { | ||
query.asStateFlow() | ||
.flatMapLatest { query -> | ||
NewsRepository.fetchQuery(query) // fetch latest query results | ||
} | ||
.collect { results -> | ||
// TODO post latest results | ||
} | ||
} | ||
} | ||
|
||
} | ||
``` | ||
|
||
## How To Publish Locally | ||
|
||
Add the following properties in your `local.properties` file. | ||
|
||
``` | ||
signing.keyId=gpg-key-id | ||
signing.password=gpg-key-passphrase | ||
signing.key=gpg-key | ||
ossrhUsername=jira-username | ||
ossrhPassword=jira-password | ||
sonatypeStagingProfileId=some-profile-id | ||
``` | ||
|
||
## Resources | ||
|
||
* [How to publish libraries in 2021](https://getstream.io/blog/publishing-libraries-to-mavencentral-2021/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
apply plugin: 'maven-publish' | ||
apply plugin: 'signing' | ||
apply plugin: 'org.jetbrains.dokka' | ||
|
||
task androidSourcesJar(type: Jar) { | ||
archiveClassifier.set('sources') | ||
if (project.plugins.findPlugin("com.android.library")) { | ||
// For Android libraries | ||
from android.sourceSets.main.java.srcDirs | ||
from android.sourceSets.main.kotlin.srcDirs | ||
} else { | ||
// For pure Kotlin libraries, in case you have them | ||
from sourceSets.main.java.srcDirs | ||
from sourceSets.main.kotlin.srcDirs | ||
} | ||
} | ||
|
||
artifacts { | ||
archives androidSourcesJar | ||
} | ||
|
||
group = PUBLISH_GROUP_ID | ||
version = PUBLISH_VERSION | ||
|
||
afterEvaluate { | ||
publishing { | ||
publications { | ||
release(MavenPublication) { | ||
// The coordinates of the library, being set from variables that | ||
// we'll set up later | ||
groupId PUBLISH_GROUP_ID | ||
artifactId PUBLISH_ARTIFACT_ID | ||
version PUBLISH_VERSION | ||
|
||
// Two artifacts, the `aar` (or `jar`) and the sources | ||
if (project.plugins.findPlugin("com.android.library")) { | ||
from components.release | ||
} else { | ||
from components.java | ||
} | ||
|
||
artifact androidSourcesJar | ||
// artifact javadocJar //FIXME | ||
|
||
// Mostly self-explanatory metadata | ||
pom { | ||
name = PUBLISH_ARTIFACT_ID | ||
description = 'SavedStateFlow - StateFlow wrapper around SavedStateHandle' | ||
url = 'https://github.com/plusmobileapps/SavedStateFlow' | ||
licenses { | ||
license { | ||
name = 'SavedStateFlow License' | ||
url = 'https://github.com/plusmobileapps/SavedStateFlow/blob/main/LICENSE' | ||
} | ||
} | ||
developers { | ||
developer { | ||
id = 'andrew@plusmobileapps.com' | ||
name = 'Andrew Steinmetz' | ||
email = 'andrew@plusmobileapps.com' | ||
} | ||
// Add all other devs here... | ||
} | ||
|
||
// Version control info - if you're using GitHub, follow the | ||
// format as seen here | ||
scm { | ||
connection = 'scm:git:github.com/plusmobileapps/SavedStateFlow.git' | ||
developerConnection = 'scm:git:ssh://github.com/plusmobileapps/SavedStateFlow.git' | ||
url = 'https://github.com/plusmobileapps/SavedStateFlow/tree/main' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
signing { | ||
useInMemoryPgpKeys( | ||
rootProject.ext["signing.keyId"], | ||
rootProject.ext["signing.key"], | ||
rootProject.ext["signing.password"], | ||
) | ||
sign publishing.publications | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Create variables with empty default values | ||
ext["signing.keyId"] = '' | ||
ext["signing.password"] = '' | ||
ext["signing.key"] = '' | ||
ext["ossrhUsername"] = '' | ||
ext["ossrhPassword"] = '' | ||
ext["sonatypeStagingProfileId"] = '' | ||
|
||
File secretPropsFile = project.rootProject.file('local.properties') | ||
if (secretPropsFile.exists()) { | ||
// Read local.properties file first if it exists | ||
Properties p = new Properties() | ||
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) } | ||
p.each { name, value -> ext[name] = value } | ||
} else { | ||
// Use system environment variables | ||
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME') | ||
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD') | ||
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID') | ||
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') | ||
ext["signing.password"] = System.getenv('SIGNING_PASSWORD') | ||
ext["signing.key"] = System.getenv('SIGNING_KEY') | ||
} | ||
|
||
// Set up Sonatype repository | ||
nexusPublishing { | ||
repositories { | ||
sonatype { | ||
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) | ||
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) | ||
stagingProfileId = sonatypeStagingProfileId | ||
username = ossrhUsername | ||
password = ossrhPassword | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why this was breaking the build