https://github.com/boybeak/easypack
My easypack to start a new project.
https://github.com/boybeak/easypack
Last synced: 5 months ago
JSON representation
My easypack to start a new project.
- Host: GitHub
- URL: https://github.com/boybeak/easypack
- Owner: boybeak
- Created: 2021-03-20T15:19:23.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-03T07:33:42.000Z (over 5 years ago)
- Last Synced: 2025-06-24T09:51:37.873Z (about 1 year ago)
- Language: Java
- Size: 173 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# EasyPack 
## Install
In your root build.gradle
```groovy
buildscript {
repositories {
google()
mavenCentral()
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
```
In your module's build.gradle
```groovy
dependencies {
implementation "com.github.boybeak:easy-safr:$easy_pack_version"
implementation "com.github.boybeak:easy-fp:$easy_pack_version"
implementation "com.github.boybeak:easy-picker:$easy_pack_version"
}
```
## Summary
I create a principle called **WCWC**, means "Where calls, where callbacks". Aimed to put calls and callbacks together.
For example, `startActivityForResult` is a call, but the callback is in another method `onActivityResult`. This breaks **WCWC** principle.
**easy-safr:** SAFR is short for *startActivityForResult*.
**easy-fp:** A helper library for FileProvider.
**easy-picker:** A helper library for get or capture audio, image or video content from recorder, gallery or camera. This library based on easy-safr and easy-fp.
## Easy-safr
```kotlin
val it = Intent(this, ResultMakeActivity::class.java)
EasySAFR.startActivityForResult(applicationContext, it,
object : OnResultAdapter {
override fun onOk(id: String, requestCode: Int, data: Intent?) {
Toast.makeText(this@MainActivity, "onOk", Toast.LENGTH_SHORT).show()
}
override fun onCancel(id: String) {
Toast.makeText(this@MainActivity, "onCancel", Toast.LENGTH_SHORT).show()
}
}
)
```
There's no need to handle the result in onActivityResult method.
## Easy-fp
FileProvider is a bit complex. Easy-fp makes it easy to use and provide a uri-to-file access.
Make a paths.xml file in R.xml res folder.
```xml
```
> **Do not repeat any one of the path items above.**
>
> If you make 2 files-path items with the same name or path, this library not suite for you.
```xml
```
Get file from uri.
```kotlin
val uri = ...
val file = EasyFP.guess(this, uri)
```
In this example, the `uri` must be in the R.xml.paths items.
Get uri by dir and file name.
```kotlin
EasyFP.withAuthority(this, "your authority")
.cacheDir()
.name("xyz.jpg")
.uri()
//.file() or .uri()
```
Use a default FileProvider - The first FileProvider listed in manifest file.
```kotlin
EasyFP.withDefault(this)
.cacheDir()
.name("xyz.jpg")
.pair()
//.file() or .uri()
```
`uri()` means return uri, `file` means return file, `pair()`means return both uri and file.
## Easy-picker
```kotlin
class App : Application() {
override fun onCreate() {
super.onCreate()
EasyPicker.init(Config.defaultConfig(this))
// OR
EasyPicker.init(
Config.Builder()
.copyDir(File(cacheDir, "easy_picker"))
.noMedia()
.outputFactory { cxt ->
EasyFP.withDefault(cxt)
.cacheDir()
.mkdirs("easy_picker")
.name(UUID.randomUUID().toString())
.pair()
}
.build()
}
}
```
```kotlin
// Get mutiple images
EasyPicker.fromGallery(ImageType.any()).multipleGet(this) { uris, files ->
Log.v(TAG, "multipleGet ${uris.size} ${files.size}")
}
// Record an audio
EasyPicker.captureAudio().capture(this) { uri, file ->
Log.v(TAG, "uri=$uri file=$file")
}
// Capture an image
EasyPicker.captureImage()
.output(somePair) // If you do not provide somePair, it will auto generate in OutputFactory
.capture(this) { uri, file ->
}
```