package de.tsschulz.tt_tagebuch.app.pdf

import android.content.Context
import android.content.Intent
import androidx.core.content.FileProvider
import de.tsschulz.tt_tagebuch.BuildConfig
import java.io.File

fun shareFileWithMime(context: Context, file: File, mimeType: String, chooserTitle: String) {
    val uri = FileProvider.getUriForFile(
        context,
        "${BuildConfig.APPLICATION_ID}.fileprovider",
        file,
    )
    val send = Intent(Intent.ACTION_SEND).apply {
        type = mimeType
        putExtra(Intent.EXTRA_STREAM, uri)
        addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
    }
    val chooser = Intent.createChooser(send, chooserTitle).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
    context.startActivity(chooser)
}

fun sharePdfFile(context: Context, file: File, chooserTitle: String) {
    shareFileWithMime(context, file, "application/pdf", chooserTitle)
}
