Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package io.github.vinceglb.filekit.dialogs

import io.github.vinceglb.filekit.FileKit
import io.github.vinceglb.filekit.context

/**
* Android implementation of [FileKitOpenCameraSettings].
*
* @property authority The content authority string used for creating a [android.net.Uri].
* Defaults to "{applicationId}.FileKitFileProvider".
* Defaults to "{applicationId}.FileKitFileProvider" when null.
*/
public actual class FileKitOpenCameraSettings(
public val authority: String = "${FileKit.context.packageName}.FileKitFileProvider",
public val authority: String? = null,
) {
public actual companion object {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package io.github.vinceglb.filekit.dialogs

import io.github.vinceglb.filekit.FileKit
import io.github.vinceglb.filekit.context

/**
* Android implementation of [FileKitOpenFileSettings].
*
* @property authority The content authority string used for creating a [android.net.Uri].
* Defaults to "{applicationId}.FileKitFileProvider".
* Defaults to "{applicationId}.FileKitFileProvider" when null.
*/
public actual class FileKitOpenFileSettings(
public val authority: String = "${FileKit.context.packageName}.FileKitFileProvider",
public val authority: String? = null,
) {
public actual companion object {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package io.github.vinceglb.filekit.dialogs

import android.content.Intent
import io.github.vinceglb.filekit.FileKit
import io.github.vinceglb.filekit.context

/**
* Android implementation of [FileKitShareSettings].
*
* @property authority The content authority string used for creating a [android.net.Uri].
* Defaults to "{applicationId}.FileKitFileProvider".
* Defaults to "{applicationId}.FileKitFileProvider" when null.
* @property addOptionChooseIntent Callback to customize the choose intent.
*/
public actual class FileKitShareSettings(
public val authority: String = "${FileKit.context.packageName}.FileKitFileProvider",
public val authority: String? = null,
public val addOptionChooseIntent: (Intent) -> Unit = {},
) {
public actual companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ import io.github.vinceglb.filekit.FileKit
import io.github.vinceglb.filekit.PlatformFile
import io.github.vinceglb.filekit.context

public fun PlatformFile.toAndroidUri(authority: String): Uri =
/**
* Returns the default authority string for FileProvider operations.
* Uses the pattern "{applicationId}.FileKitFileProvider".
*/
internal fun getDefaultAuthority(): String =
"${FileKit.context.packageName}.FileKitFileProvider"

public fun PlatformFile.toAndroidUri(authority: String? = null): Uri =
when (val androidFile = androidFile) {
is AndroidFile.UriWrapper -> androidFile.uri

is AndroidFile.FileWrapper -> FileProvider.getUriForFile(
FileKit.context,
authority,
authority ?: getDefaultAuthority(),
androidFile.file,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.github.vinceglb.filekit.PlatformFile
import io.github.vinceglb.filekit.dialogs.compose.rememberFilePickerLauncher
Expand All @@ -23,6 +24,7 @@ import io.github.vinceglb.filekit.sample.shared.ui.components.AppScreenHeaderBut
import io.github.vinceglb.filekit.sample.shared.ui.icons.LucideIcons
import io.github.vinceglb.filekit.sample.shared.ui.icons.MessageCircleCode
import io.github.vinceglb.filekit.sample.shared.ui.theme.AppMaxWidth
import io.github.vinceglb.filekit.sample.shared.ui.theme.AppTheme
import io.github.vinceglb.filekit.sample.shared.util.plus

@Composable
Expand All @@ -44,9 +46,6 @@ private fun DebugScreen(
var buttonState by remember { mutableStateOf(AppScreenHeaderButtonState.Enabled) }
var files by remember { mutableStateOf(emptyList<PlatformFile>()) }

// ========================================
// CUSTOMIZE YOUR PICKER HERE
// ========================================
val picker = rememberFilePickerLauncher { file ->
buttonState = AppScreenHeaderButtonState.Enabled
files = file?.let(::listOf) ?: emptyList()
Expand Down Expand Up @@ -82,10 +81,6 @@ private fun DebugScreen(
)
}

// ========================================
// ADD YOUR CUSTOM DEBUG UI HERE
// ========================================

item {
AppPickerResultsCard(
files = files,
Expand All @@ -98,3 +93,14 @@ private fun DebugScreen(
}
}
}

@Preview
@Composable
private fun DebugScreenPreview() {
AppTheme {
DebugScreen(
onNavigateBack = {},
onDisplayFileDetails = {},
)
}
}