wip image previews

This commit is contained in:
erinn 2021-12-14 15:50:08 -08:00
parent 63fc1fe772
commit 8c4a5aee90
6 changed files with 46 additions and 2 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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) {

View File

@ -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) {

View File

@ -227,7 +227,6 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
inactiveTrackColor: settings.theme.defaultButtonDisabledColor(),
secondary: Icon(Icons.attach_file, color: settings.current().mainTextColor()),
),
<<<<<<< HEAD
Visibility(
visible: settings.isExperimentEnabled(FileSharingExperiment),
child: Column(children:[

View File

@ -322,8 +322,13 @@ class FileBubbleState extends State<FileBubble> {
fit: BoxFit.scaleDown
)
),
),Icon(Icons.arrow_downward)]),
),IconButton(icon: Icon(Icons.arrow_downward), onPressed: androidExport),
]),
))
);
}
void androidExport() async {
}
}