diff --git a/app/src/main/java/com/example/util/simpletimetracker/navigation/ActionResolverImpl.kt b/app/src/main/java/com/example/util/simpletimetracker/navigation/ActionResolverImpl.kt index 2a4d2e9e6..0ab984be5 100644 --- a/app/src/main/java/com/example/util/simpletimetracker/navigation/ActionResolverImpl.kt +++ b/app/src/main/java/com/example/util/simpletimetracker/navigation/ActionResolverImpl.kt @@ -10,6 +10,7 @@ import androidx.activity.ComponentActivity import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts.RequestPermission import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult +import com.example.util.simpletimetracker.core.extension.allowDiskRead import com.example.util.simpletimetracker.core.provider.ApplicationDataProvider import com.example.util.simpletimetracker.navigation.params.action.ActionParams import com.example.util.simpletimetracker.navigation.params.action.CreateFileParams @@ -19,7 +20,7 @@ import com.example.util.simpletimetracker.navigation.params.action.OpenMarketPar import com.example.util.simpletimetracker.navigation.params.action.OpenSystemSettings import com.example.util.simpletimetracker.navigation.params.action.RequestPermissionParams import com.example.util.simpletimetracker.navigation.params.action.SendEmailParams -import com.example.util.simpletimetracker.navigation.params.action.ShareImageParams +import com.example.util.simpletimetracker.navigation.params.action.ShareFileParams import javax.inject.Inject class ActionResolverImpl @Inject constructor( @@ -44,7 +45,7 @@ class ActionResolverImpl @Inject constructor( is CreateFileParams -> createFile(activity, data) is OpenFileParams -> openFile(activity, data) is OpenSystemSettings -> openSystemSettings(activity, data) - is ShareImageParams -> shareImage(activity, data) + is ShareFileParams -> shareFile(activity, data) is RequestPermissionParams -> requestPermission(data) is OpenLinkParams -> openLink(activity, data) } @@ -148,11 +149,12 @@ class ActionResolverImpl @Inject constructor( } } - private fun shareImage(activity: Activity?, data: ShareImageParams) { + private fun shareFile(activity: Activity?, data: ShareFileParams) { try { val uri = Uri.parse(data.uriString) + val type = allowDiskRead { data.type ?: activity?.contentResolver?.getType(uri) } val intent = Intent(Intent.ACTION_SEND).apply { - setDataAndType(uri, activity?.contentResolver?.getType(uri)) + setDataAndType(uri, type) putExtra(Intent.EXTRA_STREAM, uri) addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) } diff --git a/core/src/main/java/com/example/util/simpletimetracker/core/interactor/SharingInteractor.kt b/core/src/main/java/com/example/util/simpletimetracker/core/interactor/SharingInteractor.kt index 9d002505b..dec04507d 100644 --- a/core/src/main/java/com/example/util/simpletimetracker/core/interactor/SharingInteractor.kt +++ b/core/src/main/java/com/example/util/simpletimetracker/core/interactor/SharingInteractor.kt @@ -7,7 +7,7 @@ import com.example.util.simpletimetracker.domain.resolver.SharingRepo import com.example.util.simpletimetracker.feature_views.extension.getBitmapFromView import com.example.util.simpletimetracker.feature_views.extension.measureForSharing import com.example.util.simpletimetracker.navigation.Router -import com.example.util.simpletimetracker.navigation.params.action.ShareImageParams +import com.example.util.simpletimetracker.navigation.params.action.ShareFileParams import com.example.util.simpletimetracker.navigation.params.notification.SnackBarParams import javax.inject.Inject @@ -29,8 +29,9 @@ class SharingInteractor @Inject constructor( when (result) { is SharingRepo.Result.Success -> { - ShareImageParams( + ShareFileParams( uriString = result.uriString, + type = null, notHandledCallback = { R.string.message_app_not_found.let(::showMessage) }, ).let(router::execute) } diff --git a/features/feature_settings/src/main/java/com/example/util/simpletimetracker/feature_settings/viewModel/delegate/SettingsFileWorkDelegate.kt b/features/feature_settings/src/main/java/com/example/util/simpletimetracker/feature_settings/viewModel/delegate/SettingsFileWorkDelegate.kt index f8431d026..5ead772df 100644 --- a/features/feature_settings/src/main/java/com/example/util/simpletimetracker/feature_settings/viewModel/delegate/SettingsFileWorkDelegate.kt +++ b/features/feature_settings/src/main/java/com/example/util/simpletimetracker/feature_settings/viewModel/delegate/SettingsFileWorkDelegate.kt @@ -23,6 +23,7 @@ import com.example.util.simpletimetracker.navigation.Router import com.example.util.simpletimetracker.navigation.params.action.ActionParams import com.example.util.simpletimetracker.navigation.params.action.CreateFileParams import com.example.util.simpletimetracker.navigation.params.action.OpenFileParams +import com.example.util.simpletimetracker.navigation.params.action.ShareFileParams import com.example.util.simpletimetracker.navigation.params.notification.SnackBarParams import com.example.util.simpletimetracker.navigation.params.screen.DataExportSettingDialogParams import com.example.util.simpletimetracker.navigation.params.screen.DataExportSettingsResult @@ -250,7 +251,7 @@ class SettingsFileWorkDelegate @Inject constructor( private fun onSaveBackup(uriString: String?) { if (uriString == null) return val params = saveOptionsData ?: return - executeFileWork { + executeFileWork(shareUriString = uriString) { backupInteractor.saveBackupFile(uriString, params) } } @@ -353,7 +354,7 @@ class SettingsFileWorkDelegate @Inject constructor( private fun onSaveCsvFile(uriString: String?) { if (uriString == null) return - executeFileWork { + executeFileWork(shareUriString = uriString) { csvExportInteractor.saveCsvFile( uriString = uriString, range = getRange(), @@ -370,7 +371,7 @@ class SettingsFileWorkDelegate @Inject constructor( private fun onSaveIcsFile(uriString: String?) { if (uriString == null) return - executeFileWork { + executeFileWork(shareUriString = uriString) { icsExportInteractor.saveIcsFile( uriString = uriString, range = getRange(), @@ -392,13 +393,20 @@ class SettingsFileWorkDelegate @Inject constructor( // Need global scope or not cancelable scope. // Otherwise process will be stopped on navigation. private fun executeFileWork( + shareUriString: String? = null, doAfter: suspend () -> Unit = {}, doWork: suspend () -> ResultCode, ) = delegateScope.launch { fileWorkRepo.inProgress.set(true) val resultCode = doWork() - resultCode.message?.let(::showMessage) + val isSuccessful = resultCode is ResultCode.Success + resultCode.message?.let { + showMessage( + string = it, + shareUriString = shareUriString.takeIf { isSuccessful }, + ) + } fileWorkRepo.inProgress.set(false) @@ -413,11 +421,38 @@ class SettingsFileWorkDelegate @Inject constructor( showMessage(resourceRepo.getString(R.string.settings_file_create_error)) } - private fun showMessage(string: String) { - val params = SnackBarParams(message = string) + private fun showMessage( + string: String, + shareUriString: String? = null, + ) { + val isForSharing = shareUriString != null + val actionText = if (isForSharing) { + resourceRepo.getString(R.string.message_action_share) + } else { + "" + } + val params = SnackBarParams( + message = string, + actionText = actionText, + actionListener = { onShareClicked(shareUriString) }, + ) router.show(params) } + private fun onShareClicked( + shareUriString: String?, + ) { + val shareData = ShareFileParams( + uriString = shareUriString.orEmpty(), + type = FILE_TYPE_BIN_OPEN, + notHandledCallback = { + resourceRepo.getString(R.string.message_app_not_found) + .let(::showMessage) + }, + ) + router.execute(shareData) + } + private fun getFileNameTimeStamp(): String { return SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date()) } diff --git a/navigation/src/main/java/com/example/util/simpletimetracker/navigation/params/action/ShareImageParams.kt b/navigation/src/main/java/com/example/util/simpletimetracker/navigation/params/action/ShareFileParams.kt similarity index 75% rename from navigation/src/main/java/com/example/util/simpletimetracker/navigation/params/action/ShareImageParams.kt rename to navigation/src/main/java/com/example/util/simpletimetracker/navigation/params/action/ShareFileParams.kt index 76e2bcd50..6ceb93cd2 100644 --- a/navigation/src/main/java/com/example/util/simpletimetracker/navigation/params/action/ShareImageParams.kt +++ b/navigation/src/main/java/com/example/util/simpletimetracker/navigation/params/action/ShareFileParams.kt @@ -1,6 +1,7 @@ package com.example.util.simpletimetracker.navigation.params.action -data class ShareImageParams( +data class ShareFileParams( val uriString: String, + val type: String?, val notHandledCallback: (() -> Unit), ) : ActionParams \ No newline at end of file diff --git a/resources/src/main/res/values-ar/strings.xml b/resources/src/main/res/values-ar/strings.xml index de8dbe7e1..cb40508cd 100644 --- a/resources/src/main/res/values-ar/strings.xml +++ b/resources/src/main/res/values-ar/strings.xml @@ -416,6 +416,7 @@ اكتمل الاستيراد التتبعات المضافة: %s خطأ في الاستيراد + يشارك حدث خطأ في النسخ الاحتياطي التلقائي. حدث خطأ في التصدير التلقائي. حاول تحديد مكان مختلف diff --git a/resources/src/main/res/values-ca/strings.xml b/resources/src/main/res/values-ca/strings.xml index 64705542e..b430b5531 100644 --- a/resources/src/main/res/values-ca/strings.xml +++ b/resources/src/main/res/values-ca/strings.xml @@ -416,6 +416,7 @@ Exemple:
Importació completada Registres afegits: %s Error d\'importació + Comparteix Hi ha hagut un error amb la còpia de seguretat automàtica. Hi ha hagut un error amb l\'exportació automàtica. Proveu de seleccionar una ubicació diferent diff --git a/resources/src/main/res/values-de/strings.xml b/resources/src/main/res/values-de/strings.xml index c8a675026..d242e7a02 100644 --- a/resources/src/main/res/values-de/strings.xml +++ b/resources/src/main/res/values-de/strings.xml @@ -416,6 +416,7 @@ Beispiel:
Import abgeschlossen Hinzugefügte Datensätze: %s Importfehler + Aktie Bei der automatischen Sicherung ist ein Fehler aufgetreten. Beim automatischen Export ist ein Fehler aufgetreten. Versuchen Sie, einen anderen Ort auszuwählen diff --git a/resources/src/main/res/values-es/strings.xml b/resources/src/main/res/values-es/strings.xml index 785765392..41e41692e 100644 --- a/resources/src/main/res/values-es/strings.xml +++ b/resources/src/main/res/values-es/strings.xml @@ -416,6 +416,7 @@ Ejemplo:
Importación completada Registros agregados: %s Error de importación + Compartir Hubo un error con la copia de seguridad automática. Hubo un error con la exportación automática. Intenta seleccionar una ubicación diferente diff --git a/resources/src/main/res/values-fa/strings.xml b/resources/src/main/res/values-fa/strings.xml index 02bfab127..7217aabe7 100644 --- a/resources/src/main/res/values-fa/strings.xml +++ b/resources/src/main/res/values-fa/strings.xml @@ -416,6 +416,7 @@ واردات انجام شد سوابق اضافه شده: %s خطای واردات + به اشتراک بگذارید خطا در پشتیبانی خودکار. خطا در خروجی خودکار. سعی کنید محل ذخیره دیگیری را انتخاب کنید. diff --git a/resources/src/main/res/values-fr/strings.xml b/resources/src/main/res/values-fr/strings.xml index 75c0538b5..65364d8e8 100644 --- a/resources/src/main/res/values-fr/strings.xml +++ b/resources/src/main/res/values-fr/strings.xml @@ -416,6 +416,7 @@ Exemple:
Importation terminée Enregistrements ajoutés : %s Erreur d\'importation + Partager Une erreur s\'est produite lors de la sauvegarde automatique. Une erreur s\'est produite lors de l\'exportation automatique. Essayez de sélectionner un emplacement différent diff --git a/resources/src/main/res/values-hi/strings.xml b/resources/src/main/res/values-hi/strings.xml index ae9141b60..0bc8b25f6 100644 --- a/resources/src/main/res/values-hi/strings.xml +++ b/resources/src/main/res/values-hi/strings.xml @@ -416,6 +416,7 @@ csv फ़ाइल में कॉमा से अलग किए गए य आयात पूरा हुआ रिकॉर्ड जोड़े गए: %s आयात त्रुटि + शेयर करना स्वचालित बैकअप के साथ एक त्रुटि हुई थी। स्वचालित निर्यात में त्रुटि हुई थी। अलग स्थान का चयन करने का प्रयास करें diff --git a/resources/src/main/res/values-in/strings.xml b/resources/src/main/res/values-in/strings.xml index 853d5eeb4..548bf0d6c 100644 --- a/resources/src/main/res/values-in/strings.xml +++ b/resources/src/main/res/values-in/strings.xml @@ -416,6 +416,7 @@ Contoh:
Impor selesai Catatan ditambahkan: %s Kesalahan impor + Membagikan Terjadi kesalahan dengan pencadangan otomatis. Terjadi kesalahan dengan ekspor otomatis. Cobalah untuk memilih lokasi yang berbeda diff --git a/resources/src/main/res/values-it/strings.xml b/resources/src/main/res/values-it/strings.xml index 1a69294b4..63ae5429c 100644 --- a/resources/src/main/res/values-it/strings.xml +++ b/resources/src/main/res/values-it/strings.xml @@ -416,6 +416,7 @@ Esempio:
Importazione completata Record aggiunti: %s Errore di importazione + Condividere Si è verificato un errore con il backup automatico. Si è verificato un errore con l\'esportazione automatica. Prova a selezionare una posizione diversa diff --git a/resources/src/main/res/values-ja/strings.xml b/resources/src/main/res/values-ja/strings.xml index 23ec73540..2013aad37 100644 --- a/resources/src/main/res/values-ja/strings.xml +++ b/resources/src/main/res/values-ja/strings.xml @@ -416,6 +416,7 @@ CSV ファイルには、カンマで区切られた次の列が含まれてい インポートが完了しました 追加されたレコード: %s インポートエラー + 共有 自動バックアップでエラーが発生しました。 自動エクスポートでエラーが発生しました。 別の場所を選択してみてください diff --git a/resources/src/main/res/values-ko/strings.xml b/resources/src/main/res/values-ko/strings.xml index a42deaac9..e00ac8b50 100644 --- a/resources/src/main/res/values-ko/strings.xml +++ b/resources/src/main/res/values-ko/strings.xml @@ -416,6 +416,7 @@ csv 파일은 다음과 같은 열(column)들을 가져야합니다:
가져오기 완료 추가된 기록 수: %s 가져오기 오류 + 공유하다 자동 백업 오류 발생 자동 내보내기 오류 발생 다른 위치를 선택해 보세요 diff --git a/resources/src/main/res/values-nl/strings.xml b/resources/src/main/res/values-nl/strings.xml index bd9d6036e..c1790d351 100644 --- a/resources/src/main/res/values-nl/strings.xml +++ b/resources/src/main/res/values-nl/strings.xml @@ -416,6 +416,7 @@ Voorbeeld:
Importeren voltooid Records toegevoegd: %s Fout importeren + Deel Er is een fout opgetreden bij de automatische back-up. Er is een fout opgetreden bij het automatisch exporteren. Probeer een andere locatie te selecteren diff --git a/resources/src/main/res/values-pl/strings.xml b/resources/src/main/res/values-pl/strings.xml index 1eb770df0..1dcc39c7c 100644 --- a/resources/src/main/res/values-pl/strings.xml +++ b/resources/src/main/res/values-pl/strings.xml @@ -416,6 +416,7 @@ Przykład:
Import zakończony Dodano rekordy: %s Błąd importu + Udział Wystąpił błąd podczas automatycznego tworzenia kopii zapasowych. Wystąpił błąd podczas automatycznego eksportu. Spróbuj wybrać inną lokalizację diff --git a/resources/src/main/res/values-pt-rPT/strings.xml b/resources/src/main/res/values-pt-rPT/strings.xml index 98fd7a600..787d404e3 100644 --- a/resources/src/main/res/values-pt-rPT/strings.xml +++ b/resources/src/main/res/values-pt-rPT/strings.xml @@ -416,6 +416,7 @@ Exemplo:
Importação concluída Registos adicionados: %s Erro de importação + Compartilhar Ocorreu um erro com a cópia de segurança automática. Ocorreu um erro com a exportação automática. Selecionar uma pasta diferente diff --git a/resources/src/main/res/values-pt/strings.xml b/resources/src/main/res/values-pt/strings.xml index 22d1bcbb6..9fc7299ca 100644 --- a/resources/src/main/res/values-pt/strings.xml +++ b/resources/src/main/res/values-pt/strings.xml @@ -416,6 +416,7 @@ Exemplo:
Importação concluída Registros adicionados: %s Erro de importação + Compartilhar Ocorreu um erro com o backup automático. Ocorreu um erro com a exportação automática. Tente selecionar um local diferente diff --git a/resources/src/main/res/values-ro/strings.xml b/resources/src/main/res/values-ro/strings.xml index 0b5f146bb..1ec5b8c4e 100644 --- a/resources/src/main/res/values-ro/strings.xml +++ b/resources/src/main/res/values-ro/strings.xml @@ -416,6 +416,7 @@ Examplu:
Import completat Înregistrări adăugate %s Eroare la import + Distribuie A fost o eroare la backup-ul automat. A fost o eroare la exportul automat. Încearcă să alegi o altă locație diff --git a/resources/src/main/res/values-ru/strings.xml b/resources/src/main/res/values-ru/strings.xml index 739dbe8f9..9b6a4280b 100644 --- a/resources/src/main/res/values-ru/strings.xml +++ b/resources/src/main/res/values-ru/strings.xml @@ -416,6 +416,7 @@ CSV-файл должен содержать следующие столбцы, Импорт завершен Добавлено записей: %s Ошибка импорта + Поделиться Произошла ошибка с автоматическим резервным копированием. Произошла ошибка при автоматическом экспорте. Попробуйте выбрать другое место diff --git a/resources/src/main/res/values-sv/strings.xml b/resources/src/main/res/values-sv/strings.xml index ee2a2569c..3160bdca1 100644 --- a/resources/src/main/res/values-sv/strings.xml +++ b/resources/src/main/res/values-sv/strings.xml @@ -416,6 +416,7 @@ Exempel:
Importen slutförd Poster tillagda: %s Importfel + Dela Det uppstod ett fel med automatisk säkerhetskopiering. Det uppstod ett fel med automatisk export. Försök att välja en annan plats diff --git a/resources/src/main/res/values-tr/strings.xml b/resources/src/main/res/values-tr/strings.xml index dfe39f0d5..1909e1bea 100644 --- a/resources/src/main/res/values-tr/strings.xml +++ b/resources/src/main/res/values-tr/strings.xml @@ -416,6 +416,7 @@ CSV dosyası virgülle ayrılmış şu sütunları içermelidir:
İçe aktarma tamamlandı Eklenen kayıtlar: %s Alma hatası + Paylaşmak Otomatik yedeklemede bir hata oluştu. Otomatik dışa aktarmayla ilgili bir hata oluştu. Farklı bir konum seçmeyi deneyin diff --git a/resources/src/main/res/values-uk/strings.xml b/resources/src/main/res/values-uk/strings.xml index 03a59aeae..68d5ff1bf 100644 --- a/resources/src/main/res/values-uk/strings.xml +++ b/resources/src/main/res/values-uk/strings.xml @@ -416,6 +416,7 @@ Імпорт завершено Додано записів: %s Помилка імпорту + Поділіться Під час автоматичного резервного копіювання сталася помилка. Під час автоматичного експорту сталася помилка. Спробуйте вибрати інше місце diff --git a/resources/src/main/res/values-vi/strings.xml b/resources/src/main/res/values-vi/strings.xml index 648e6a473..efc5bace8 100644 --- a/resources/src/main/res/values-vi/strings.xml +++ b/resources/src/main/res/values-vi/strings.xml @@ -416,6 +416,7 @@ Ví dụ:
Đã nhập xong Bản ghi đã thêm: %s Lỗi nhập + Chia sẻ Đã xảy ra lỗi khi sao lưu tự động. Đã xảy ra lỗi khi xuất tự động. Hãy thử chọn vị trí khác diff --git a/resources/src/main/res/values-zh-rTW/strings.xml b/resources/src/main/res/values-zh-rTW/strings.xml index 058e01463..4807711c0 100644 --- a/resources/src/main/res/values-zh-rTW/strings.xml +++ b/resources/src/main/res/values-zh-rTW/strings.xml @@ -416,6 +416,7 @@ csv 文件必須包含以逗號分隔的這些列:
導入完成 添加的記錄:%s 導入錯誤 + 分享 自動備份出錯。 自動導出時出錯。 嘗試選擇不同的位置 diff --git a/resources/src/main/res/values-zh/strings.xml b/resources/src/main/res/values-zh/strings.xml index 5a5490cba..290414518 100644 --- a/resources/src/main/res/values-zh/strings.xml +++ b/resources/src/main/res/values-zh/strings.xml @@ -416,6 +416,7 @@ csv 文件必须包含以逗号分隔的这些列:
导入完成 添加的记录:%s 导入错误 + 分享 自动备份出错。 自动导出时出错。 尝试选择不同的位置 diff --git a/resources/src/main/res/values/strings.xml b/resources/src/main/res/values/strings.xml index 96c0ac5e0..d5ef897d5 100644 --- a/resources/src/main/res/values/strings.xml +++ b/resources/src/main/res/values/strings.xml @@ -416,6 +416,7 @@ Example:
Import completed Records added: %s Import error + Share There was an error with automatic backup. There was an error with automatic export. Try to select different location