https://github.com/only-icesoul/jjkit-intentchooser-compose
https://github.com/only-icesoul/jjkit-intentchooser-compose
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/only-icesoul/jjkit-intentchooser-compose
- Owner: Only-IceSoul
- License: apache-2.0
- Created: 2024-07-08T03:58:03.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-07-18T22:44:51.000Z (11 months ago)
- Last Synced: 2025-01-22T21:11:56.581Z (4 months ago)
- Language: Kotlin
- Size: 924 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# IntentChooser Compose
Simple intent chooser
API SDK >= 24
## INSTALLATION
1.-Add it in your settings.gradle.kts at the end of repositories:
```
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral() //this
maven { url 'https://jitpack.io' } or maven("https://jitpack.io") //this
}
}
```
2.-gradle-wrapper.properties 8.6 to 8.7
```
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists```
2B.-libs.versions.toml
```
intentChooser = "1.4"jjkit-intentchooser = { module = "com.github.Only-IceSoul:jjkit-intentchooser-compose", version.ref = "intentChooser" }
```
3.-build gradle APP```
dependencies {///
implementation(libs.jjkit.intentchooser)
}```
## USAGE
[Example With Animation](./app\src\main\java\com\jjkit\sampleintentchooser/MainActivity.kt)
Example: a IntentChooser for image
```kotlin
@Composable
fun IntentChooserImage(enabled:Boolean,authorityFilerProvider:String,
imageName:String = "a0ImageResult",imageExt:String= "jpeg",
ignoreActivityInfoNames: List = listOf(".document","docs"),
contentLayout: IntentChooser.Layout = IntentChooser.defaultLayout,
contentTheme: IntentChooser.Theme = IntentChooser.defaultTheme,
textStyle:TextStyle = LocalTextStyle.current.copy(fontSize = 13.sp),
top: @Composable ()->Unit = {}, bottom:@Composable ()->Unit = {},
onImageResult:(uri: Uri?)->Unit) {val ctx = LocalContext.current
val permissionCamera = IntentChooser.rememberRequestPermission(permission = Manifest.permission.CAMERA)
val permissionReadWrite = IntentChooser.rememberRequestMultiplePermissions(
permissions = arrayOf(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE
)
)val launcher = rememberLauncherForActivityResult(IntentChooser.GetActivityResult()) {
if(it.resultCode == Activity.RESULT_OK){
val uri = IntentChooser.Helper.getImageUriFromResult(ctx,imageName,imageExt,it.intent,authorityFilerProvider)
onImageResult(uri)
}else{
onImageResult(null)
}
}val data : IntentChooser.Data = remember {+
//SET YOUR INTENTS
IntentChooser.Builder(ctx).setIntent(IntentChooser.Helper.getCameraIntentForQuery(ctx,imageName,imageExt,authorityFilerProvider))
.setSecondariesIntent(listOf(IntentChooser.Helper.makePhotoIntentForQuery()
)).setIgnore(ignoreActivityInfoNames)
.build()
}IntentChooser(
data, contentLayout,contentTheme, textStyle = textStyle,onClick = {if (it?.resolveInfo == null || !enabled) {
return@IntentChooser
}val ri = it.resolveInfo
if (ri.activityInfo.name.contains("camera", true)) {
if (permissionCamera.state.value == IntentChooser.PermissionStatus.GRANTED) {
launcher.launch(it)
} else {
permissionCamera.launch()
}
} else if (ri.activityInfo.packageName.contains("document", true)) {if (permissionReadWrite.state[permissionReadWrite.permissions[0]] == IntentChooser.PermissionStatus.GRANTED) {
launcher.launch(it)
} else {
permissionReadWrite.launch()
}
} else {
launcher.launch(it)
//start activity
}}, top = top, bottom = bottom)
}
```## LICENSE
**Apache 2.0**