From c248c95644333cf4b7c1a70c2a92d51359b1a09e Mon Sep 17 00:00:00 2001 From: can yang Date: Fri, 8 Dec 2023 14:16:04 +0100 Subject: [PATCH] Draft implementation of sharing feature --- .../main/java/com/app/bugapp/MainActivity.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/app/src/main/java/com/app/bugapp/MainActivity.kt b/app/src/main/java/com/app/bugapp/MainActivity.kt index dbb7f67..009af02 100644 --- a/app/src/main/java/com/app/bugapp/MainActivity.kt +++ b/app/src/main/java/com/app/bugapp/MainActivity.kt @@ -1,7 +1,10 @@ package com.app.bugapp +import android.content.Intent import android.media.RingtoneManager +import android.net.Uri import android.os.Bundle +import android.os.Environment import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.Arrangement @@ -25,6 +28,8 @@ import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch +import java.io.File + @DelicateCoroutinesApi @@ -113,10 +118,47 @@ class MainActivity : ComponentActivity() { Text(text = "Take bugreport") } + // ---------------------------------------------------------------------------- + Button( + enabled = bugButtonEnabled.value, + onClick = { + if (bugButtonEnabled.value) { + bugButtonEnabled.value = false + val downloadsPath = Environment.getExternalStoragePublicDirectory( + Environment.DIRECTORY_DOWNLOADS) + val buggappDirectory = File("$downloadsPath/bugapp") + if ( buggappDirectory.exists() ) { + val shareIntent: Intent = Intent().apply { + action = Intent.ACTION_SEND + putExtra(Intent.EXTRA_STREAM, buggappDirectory) + type = "application/zip" + } + startActivity(Intent.createChooser(shareIntent, null)) + statusText.value = + statusText.value + "\n Sharing bugreport...\n" + statusText.value = + statusText.value + "\n Success, bugreport is shared \n" + + bugButtonEnabled.value = true + } + else { + statusText.value = + statusText.value + "Error, could not share to host\n" + statusText.value = + statusText.value + "Sharing failed\n" + bugButtonEnabled.value = true + } + } + }, + ) { + Text(text = "Sharing is caring") + } // LinearProgressIndicator to show the progress if (loading.value) { LinearProgressIndicator(modifier = Modifier.fillMaxWidth()) } + + //------------------------------------------------------------------------------------------ OutlinedTextField( value = statusText.value, readOnly = true,