@@ -6,6 +6,7 @@ import android.content.Intent
66import android.net.Uri
77import android.os.Build
88import android.print.PdfPrintListener
9+ import android.view.View
910import androidx.annotation.RequiresApi
1011import androidx.core.net.toUri
1112import androidx.documentfile.provider.DocumentFile
@@ -44,6 +45,7 @@ import com.philkes.notallyx.presentation.activity.main.fragment.settings.Setting
4445import com.philkes.notallyx.presentation.getQuantityString
4546import com.philkes.notallyx.presentation.restartApplication
4647import com.philkes.notallyx.presentation.setCancelButton
48+ import com.philkes.notallyx.presentation.showSnackbar
4749import com.philkes.notallyx.presentation.showToast
4850import com.philkes.notallyx.presentation.view.misc.NotNullLiveData
4951import com.philkes.notallyx.presentation.view.misc.Progress
@@ -64,6 +66,7 @@ import com.philkes.notallyx.utils.backup.clearAllLabels
6466import com.philkes.notallyx.utils.backup.copyDatabase
6567import com.philkes.notallyx.utils.backup.exportAsZip
6668import com.philkes.notallyx.utils.backup.exportPdfFile
69+ import com.philkes.notallyx.utils.backup.exportPdfFileFolder
6770import com.philkes.notallyx.utils.backup.exportPlainTextFile
6871import com.philkes.notallyx.utils.backup.exportPlainTextFileFolder
6972import com.philkes.notallyx.utils.backup.getPreviousLabels
@@ -84,6 +87,7 @@ import com.philkes.notallyx.utils.security.encryptDatabase
8487import com.philkes.notallyx.utils.security.isEncryptedDatabase
8588import com.philkes.notallyx.utils.security.isUnencryptedDatabase
8689import com.philkes.notallyx.utils.toReadablePath
90+ import com.philkes.notallyx.utils.viewFile
8791import java.io.File
8892import java.util.concurrent.atomic.AtomicInteger
8993import javax.crypto.Cipher
@@ -441,7 +445,7 @@ class BaseNoteModel(private val app: Application) : AndroidViewModel(app) {
441445 }
442446 }
443447
444- fun exportNoteToFile (fileUri : Uri , note : BaseNote ) {
448+ fun exportNoteToFile (fileUri : Uri , note : BaseNote , snackbarView : View ) {
445449 val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
446450 app.log(TAG , throwable = throwable)
447451 actionMode.close(true )
@@ -459,7 +463,17 @@ class BaseNoteModel(private val app: Application) : AndroidViewModel(app) {
459463 override fun onSuccess (file : DocumentFile ) {
460464 actionMode.close(true )
461465 val message = app.getQuantityString(R .plurals.exported_notes, 1 )
462- app.showToast(" $message to '${app.toReadablePath(fileUri)} '" )
466+ snackbarView.showSnackbar(
467+ " $message to '${app.toReadablePath(fileUri)} '" ,
468+ R .string.open_link,
469+ ) {
470+ app.viewFile(fileUri, selectedExportMimeType.mimeType)
471+ }
472+ snackbarView.showFileSnackbar(
473+ " $message to '${app.toReadablePath(fileUri)} '" ,
474+ fileUri,
475+ ExportMimeType .PDF ,
476+ )
463477 }
464478
465479 override fun onFailure (message : CharSequence? ) {
@@ -478,13 +492,17 @@ class BaseNoteModel(private val app: Application) : AndroidViewModel(app) {
478492 )
479493 actionMode.close(true )
480494 val message = app.getQuantityString(R .plurals.exported_notes, 1 )
481- app.showToast(" $message to '${app.toReadablePath(fileUri)} '" )
495+ snackbarView.showFileSnackbar(
496+ " $message to '${app.toReadablePath(fileUri)} '" ,
497+ fileUri,
498+ selectedExportMimeType,
499+ )
482500 }
483501 }
484502 }
485503 }
486504
487- fun exportNotesToFolder (folderUri : Uri , notes : Collection <BaseNote >) {
505+ fun exportNotesToFolder (folderUri : Uri , notes : Collection <BaseNote >, snackbarView : View ) {
488506 val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
489507 app.log(TAG , throwable = throwable)
490508 actionMode.close(true )
@@ -497,7 +515,7 @@ class BaseNoteModel(private val app: Application) : AndroidViewModel(app) {
497515 when (selectedExportMimeType) {
498516 ExportMimeType .PDF -> {
499517 for (note in notes) {
500- exportPdfFile (
518+ exportPdfFileFolder (
501519 app,
502520 note,
503521 DocumentFile .fromTreeUri(app, folderUri)!! ,
@@ -514,7 +532,7 @@ class BaseNoteModel(private val app: Application) : AndroidViewModel(app) {
514532 R .plurals.exported_notes,
515533 counter.get(),
516534 )
517- app.showToast (
535+ snackbarView.showSnackbar (
518536 " $message to '${app.toReadablePath(folderUri)} '"
519537 )
520538 }
@@ -543,18 +561,22 @@ class BaseNoteModel(private val app: Application) : AndroidViewModel(app) {
543561 actionMode.close(true )
544562 progress.postValue(ExportNotesProgress (inProgress = false ))
545563 val message = app.getQuantityString(R .plurals.exported_notes, counter.get())
546- app.showToast (" $message to '${app.toReadablePath(folderUri)} '" )
564+ snackbarView.showSnackbar (" $message to '${app.toReadablePath(folderUri)} '" )
547565 }
548566 }
549567 }
550568 }
551569
552- fun exportSelectedNotesToFolder (folderUri : Uri ) {
553- exportNotesToFolder(folderUri, actionMode.selectedNotes.values)
570+ fun exportSelectedNotesToFolder (folderUri : Uri , snackbarView : View ) {
571+ exportNotesToFolder(folderUri, actionMode.selectedNotes.values, snackbarView)
572+ }
573+
574+ fun exportSelectedNoteToFile (fileUri : Uri , snackbarView : View ) {
575+ exportNoteToFile(fileUri, actionMode.selectedNotes.values.first(), snackbarView)
554576 }
555577
556- fun exportSelectedNoteToFile ( fileUri : Uri ) {
557- exportNoteToFile(fileUri, actionMode.selectedNotes.values.first())
578+ private fun View. showFileSnackbar ( msg : String , fileUri : Uri , mimeType : ExportMimeType ) {
579+ showSnackbar(msg, R .string.open_link) { app.viewFile(fileUri, mimeType.mimeType) }
558580 }
559581
560582 fun pinBaseNotes (pinned : Boolean ) {
0 commit comments