8000 GitHub - rootachieve/RequestResult: A convenient request and result state management library for Android
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

rootachieve/RequestResult

Repository files navigation

RequestResult

RequestResult is an open-source library that aims to provide convenient API request handling and response state management.

📌 Installation

Gradle

// setting.gradle.kts
dependencyResolutionManagement {
  repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
  repositories {
    mavenCentral()
    maven ( url = "https://jitpack.io" )
  }
}

// build.gradle.kts (modules)
implementation ("com.github.rootachieve:RequestResult:{latest_version}") 

Maven

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
 	</repository>
</repositories>

<dependency>
  <groupId>com.github.rootachieve</groupId>
  <artifactId>RequestResult</artifactId>
  <version>{latest_version}</version>
</dependency>

🎨 Usage

sealed class RequestResult

RequestResult is a sealed class that represents four states: None, Progress, Failure, and Success. It can be applied in many areas, including handling requests, managing responses, error handling, and controlling loading screens.

//android sample
//viewmodel
private val _dataState = MutableStateFlow<RequestResult<data>>(RequestResult.None)
val dataState: StateFlow<RequestResult<data>>
  get() = _dataState

//view
val dataState by viewmodel.dataState.collectAsStateWithLifecycle()
//--- Response
val data = dataState.getOrNull
//or
dataState.onSuccess { data ->
  //do something
}

//--- Progress
Column {
  //...
  if(dataState.isProgress){
    ProgressScreen()
  }
}

//--- Request
dataState.onNone {
  viewmodel.getSome()
}

//--- Error
dataState.onFailure {code, e ->
  when(code) {
    "404" ->
    "502" ->
    //...
  }
}

📚 Contributors

K_Gs
K_Gs

📆

📢 Report Issues

If you encounter any issues or have any questions about the library, please feel free to open an issue.

License

Copyright 2025 rootachieve.

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.

About

A convenient request and result state management library for Android

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages

0