diff --git a/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt b/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt index 20940c89..d0e3d06e 100644 --- a/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt +++ b/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt @@ -22,6 +22,7 @@ import io.flutter.plugin.common.ErrorLogResult import org.json.JSONObject import java.util.concurrent.TimeUnit +import java.io.File import android.net.Uri import android.provider.DocumentsContract @@ -57,9 +58,11 @@ class MainActivity: FlutterActivity() { // "Download to..." prompt extra arguments private val FILEPICKER_REQUEST_CODE = 234 + private val PREVIEW_EXPORT_REQUEST_CODE = 235 private var dlToProfile = "" private var dlToHandle = "" private var dlToFileKey = "" + private var exportFromPath = "" // handles clicks received from outside the app (ie, notifications) override fun onNewIntent(intent: Intent) { @@ -102,6 +105,11 @@ class MainActivity: FlutterActivity() { "manifestpath" to manifestPath, "filekey" to this.dlToFileKey )), ErrorLogResult(""));//placeholder; this Result is never actually invoked + } else if (requestCode == PREVIEW_EXPORT_REQUEST_CODE) { + val targetPath = intent!!.getData().toString() + var srcFile = File(this.exportFromPath) + Log.i("MainActivity:PREVIEW_EXPORT", "exporting previewed file") + srcFile.copyTo(File(targetPath)); } } @@ -170,6 +178,26 @@ class MainActivity: FlutterActivity() { } startActivityForResult(intent, FILEPICKER_REQUEST_CODE) return + } else if (call.method == "ExportPreviewedFile") { + this.exportFromPath = argmap["Path"] ?: "" + val suggestion = argmap["FileName"] ?: "filename.ext" + var imgType = "jpeg" + if (suggestion.endsWith("png")) { + imgType = "png" + } else if (suggestion.endsWith("webp")) { + imgType = "webp" + } else if (suggestion.endsWith("bmp")) { + imgType = "bmp" + } else if (suggestion.endsWith("gif")) { + imgType = "gif" + } + val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply { + addCategory(Intent.CATEGORY_OPENABLE) + type = "image/" + imgType + putExtra(Intent.EXTRA_TITLE, suggestion) + } + startActivityForResult(intent, PREVIEW_EXPORT_REQUEST_CODE) + return } // ...otherwise fallthru to a normal ffi method call (and return the result using the result callback) diff --git a/lib/cwtch/cwtch.dart b/lib/cwtch/cwtch.dart index f7ce4262..8a2c740e 100644 --- a/lib/cwtch/cwtch.dart +++ b/lib/cwtch/cwtch.dart @@ -55,6 +55,8 @@ abstract class Cwtch { void CheckDownloadStatus(String profile, String fileKey); // ignore: non_constant_identifier_names void VerifyOrResumeDownload(String profile, int handle, String filekey); + // ignore: non_constant_identifier_names + void ExportPreviewedFile(String sourceFile, String suggestion); // ignore: non_constant_identifier_names void ArchiveConversation(String profile, int handle); diff --git a/lib/cwtch/ffi.dart b/lib/cwtch/ffi.dart index f585438f..3c829794 100644 --- a/lib/cwtch/ffi.dart +++ b/lib/cwtch/ffi.dart @@ -402,6 +402,11 @@ class CwtchFfi implements Cwtch { // android only - do nothing } + // ignore: non_constant_identifier_names + void ExportPreviewedFile(String sourceFile, String suggestion) { + // android only - do nothing + } + @override // ignore: non_constant_identifier_names void CheckDownloadStatus(String profileOnion, String fileKey) { diff --git a/lib/cwtch/gomobile.dart b/lib/cwtch/gomobile.dart index ccf7833d..c121ff28 100644 --- a/lib/cwtch/gomobile.dart +++ b/lib/cwtch/gomobile.dart @@ -149,6 +149,11 @@ class CwtchGomobile implements Cwtch { cwtchPlatform.invokeMethod("CreateDownloadableFile", {"ProfileOnion": profileOnion, "conversation": conversation, "filename": filenameSuggestion, "filekey": filekey}); } + // ignore: non_constant_identifier_names + void ExportPreviewedFile(String sourceFile, String suggestion) { + cwtchPlatform.invokeMethod("ExportPreviewedFile", {"Path": sourceFile, "FileName": suggestion,}); + } + @override // ignore: non_constant_identifier_names void CheckDownloadStatus(String profileOnion, String fileKey) { diff --git a/lib/views/globalsettingsview.dart b/lib/views/globalsettingsview.dart index 428eb553..2179e4a4 100644 --- a/lib/views/globalsettingsview.dart +++ b/lib/views/globalsettingsview.dart @@ -227,7 +227,6 @@ class _GlobalSettingsViewState extends State { inactiveTrackColor: settings.theme.defaultButtonDisabledColor(), secondary: Icon(Icons.attach_file, color: settings.current().mainTextColor()), ), -<<<<<<< HEAD Visibility( visible: settings.isExperimentEnabled(FileSharingExperiment), child: Column(children:[ diff --git a/lib/widgets/filebubble.dart b/lib/widgets/filebubble.dart index 5a254657..4a2b6e40 100644 --- a/lib/widgets/filebubble.dart +++ b/lib/widgets/filebubble.dart @@ -322,8 +322,13 @@ class FileBubbleState extends State { fit: BoxFit.scaleDown ) ), - ),Icon(Icons.arrow_downward)]), + ),IconButton(icon: Icon(Icons.arrow_downward), onPressed: androidExport), + ]), )) ); } + + void androidExport() async { + + } }