|
fun shareImages( |
|
contextActibity: Activity, |
|
listOfImages: List<String>, |
|
description: String? = null, |
|
price: String? = null, |
|
name: String? = "", |
|
details: String = "", |
|
catalogName: String = "" |
|
) { |
|
Log.e("list", listOfImages.toString()) |
|
val context = MarkazApp.getInstance().baseContext |
|
val cachePath = File(context.cacheDir, "images") |
|
cachePath.mkdirs() |
|
val uriList: ArrayList<Uri> = ArrayList() |
|
val intent = Intent(Intent.ACTION_SEND_MULTIPLE) |
|
intent.type = "image/*" |
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) |
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
|
GlobalScope.launch { |
|
listOfImages.forEach { |
|
val loader = ImageLoader(context) |
|
val request = ImageRequest.Builder(context) |
|
.data( |
|
it |
|
) |
|
.allowHardware(false) |
|
.build() |
|
|
|
when (loader.execute(request)) { |
|
is SuccessResult -> { |
|
val result = (loader.execute(request) as SuccessResult).drawable |
|
val bitmap = (result as BitmapDrawable).bitmap |
|
|
|
val UUID = it |
|
val stream = FileOutputStream("$cachePath/${UUID}.jpeg") |
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream) |
|
|
|
val newFile = File(cachePath, "$UUID.jpeg") |
|
val contentUri: Uri = FileProvider.getUriForFile( |
|
context, |
|
"${BuildConfig.APPLICATION_ID}.provider", |
|
newFile |
|
) |
|
uriList.add(contentUri) |
|
} |
|
|
|
|
|
} |
|
|
|
} |
|
}.invokeOnCompletion { |
|
|
|
|
|
description?.let { |
|
intent.putExtra( |
|
Intent.EXTRA_TEXT, |
|
"*Catalog Name*: $catalogName \n \n*Product Name*: $name \n \n*Product Description*: $description\n \n*Product Details*:\n \n$details \n " |
|
) |
|
|
|
} |
|
price?.let { |
|
intent.putExtra( |
|
Intent.EXTRA_TEXT, |
|
"$description\n Price = $price" |
|
) |
|
} |
|
|
|
|
|
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList) |
|
|
|
|
|
try { |
|
contextActibity.startActivity( |
|
Intent.createChooser( |
|
intent, |
|
"Choose the app you want to share on" |
|
) |
|
) |
|
} catch (e: Exception) { |
|
Log.e( |
|
"e", |
|
e.toString() + " " + e.cause + " " + e.message + " " + e.localizedMessage |
|
) |
|
} |
|
|
|
|
|
} |
|
} |