https://github.com/mutkuensert/android-phase
An Android library to hold any data within states.
https://github.com/mutkuensert/android-phase
android android-library library
Last synced: 8 months ago
JSON representation
An Android library to hold any data within states.
- Host: GitHub
- URL: https://github.com/mutkuensert/android-phase
- Owner: mutkuensert
- License: apache-2.0
- Created: 2023-08-22T18:30:15.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-08-29T15:24:41.000Z (almost 3 years ago)
- Last Synced: 2023-08-29T22:29:02.943Z (almost 3 years ago)
- Topics: android, android-library, library
- Language: Kotlin
- Homepage:
- Size: 87.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Android Phase
## Table of Contents
* [About The Library](#about-the-library)
* [Adding The Dependency](#adding-the-dependency)
* [Example Use](#example-use)
* [License](#license)
* [Contact](#contact)
## About The Library
An Android library to hold any data within states.
For the example use of this library, you can look at my [Movee](https://github.com/mutkuensert/Movee) project on Github.
If you want, you can also use this class [GetPhaseFlow](https://gist.github.com/mutkuensert/11093b3c8b48fa130b0b35bcb5e9faf1).
## Adding The Dependency
Add jitpack into the repositories
```gradle
maven { url 'https://jitpack.io' }
```
Add the dependency in build.gradle file.
```gradle
implementation 'com.github.mutkuensert:Android-Phase:v2.0.0'
```
**You can also add the library locally. To do that:**
Clone the project.
Run in the terminal:
```gradle
./gradlew build
```
Find generated aar file under build folder and copy & paste it into your project. You can create a directory called "libs" under your app module and paste the file into there.
Then you can add the dependency:
```gradle
implementation files('libs/AndroidPhase-release.aar')
```
## Example Use
```kotlin
suspend fun getTvShowDetails(tvShowId: Int): Phase {
val response = tvShowsApi.getTvShowDetails(tvShowId)
return if (response.isSuccessful) {
Phase.Success(data = response.body()?.mapToDomainModel())
} else {
Phase.Error(message = "Unsuccessful response.")
}
}
```
You can use Compose extension: [Phase Compose Extension](https://github.com/mutkuensert/Android-Phase-Compose-Extension)
```kotlin
@Composable
private fun TvShowDetails(
phase: Phase,
loadTvCastIfSuccessful: () -> Unit
) {
phase.Execute(
onLoading = { Loading() },
onSuccess = { //it: TvShowDetails
TvDetailsItem(it)
LaunchedEffect(Unit) { loadTvCastIfSuccessful() }
},
onError = { //it: Phase.Error
LocalContext.current.showToastIfNotNull(it.message)
})
}
```
## License
```xml
Copyright 2023 Mustafa Utku Ensert
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
## Contact
[ensertyazilim@gmail.com](#)