From 73856e676984fa063f3f3ac3f8a4d1d2e0f124a2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 29 Oct 2017 18:28:28 +0100 Subject: [PATCH] reuse the OpenFile intent handling from Commons --- app/build.gradle | 2 +- .../gallery/activities/PhotoVideoActivity.kt | 2 +- .../gallery/activities/ViewPagerActivity.kt | 1 + .../gallery/extensions/activity.kt | 29 +++++-------------- .../gallery/extensions/context.kt | 20 ------------- .../gallery/helpers/Constants.kt | 1 - app/src/main/res/values-ca/strings.xml | 2 -- app/src/main/res/values-cs/strings.xml | 2 -- app/src/main/res/values-de/strings.xml | 2 -- app/src/main/res/values-es/strings.xml | 2 -- app/src/main/res/values-fi/strings.xml | 2 -- app/src/main/res/values-fr/strings.xml | 2 -- app/src/main/res/values-hu/strings.xml | 2 -- app/src/main/res/values-it/strings.xml | 2 -- app/src/main/res/values-ja/strings.xml | 2 -- app/src/main/res/values-nl/strings.xml | 2 -- app/src/main/res/values-pl/strings.xml | 2 -- app/src/main/res/values-pt-rBR/strings.xml | 2 -- app/src/main/res/values-pt/strings.xml | 2 -- app/src/main/res/values-ru/strings.xml | 2 -- app/src/main/res/values-sk/strings.xml | 2 -- app/src/main/res/values-sv/strings.xml | 2 -- app/src/main/res/values-tr/strings.xml | 2 -- app/src/main/res/values-zh-rCN/strings.xml | 2 -- app/src/main/res/values-zh-rTW/strings.xml | 2 -- app/src/main/res/values/strings.xml | 2 -- 26 files changed, 10 insertions(+), 85 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3705db051..df3495aa0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,7 +37,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.33.2' + compile 'com.simplemobiletools:commons:2.33.3' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt index 0b57d68fb..d0879b481 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -13,6 +13,7 @@ import com.simplemobiletools.commons.extensions.getFilenameFromUri import com.simplemobiletools.commons.extensions.getRealPathFromURI import com.simplemobiletools.commons.extensions.scanPath import com.simplemobiletools.commons.extensions.toast +import com.simplemobiletools.commons.helpers.IS_FROM_GALLERY import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.REAL_FILE_PATH import com.simplemobiletools.gallery.R @@ -20,7 +21,6 @@ import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.fragments.PhotoFragment import com.simplemobiletools.gallery.fragments.VideoFragment import com.simplemobiletools.gallery.fragments.ViewPagerFragment -import com.simplemobiletools.gallery.helpers.IS_FROM_GALLERY import com.simplemobiletools.gallery.helpers.IS_VIEW_INTENT import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.helpers.PATH diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 57946761e..967f1ce21 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -26,6 +26,7 @@ import android.view.animation.DecelerateInterpolator import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.helpers.IS_FROM_GALLERY import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.MediaActivity.Companion.mMedia diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 3e4c91de9..675f67b2b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -20,7 +20,9 @@ import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity -import com.simplemobiletools.gallery.helpers.* +import com.simplemobiletools.gallery.helpers.NOMEDIA +import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE +import com.simplemobiletools.gallery.helpers.REQUEST_SET_AS import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.views.MySquareImageView @@ -32,7 +34,7 @@ fun Activity.shareUri(uri: Uri) { val shareTitle = resources.getString(R.string.share_via) Intent().apply { action = Intent.ACTION_SEND - putExtra(Intent.EXTRA_STREAM, ensurePublicUri(uri)) + putExtra(Intent.EXTRA_STREAM, ensurePublicUri(uri, BuildConfig.APPLICATION_ID)) type = getMimeTypeFromUri(uri) addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) startActivity(Intent.createChooser(this, shareTitle)) @@ -71,7 +73,7 @@ fun Activity.shareMedia(media: List) { } fun Activity.setAs(uri: Uri) { - val newUri = ensurePublicUri(uri) + val newUri = ensurePublicUri(uri, BuildConfig.APPLICATION_ID) Intent().apply { action = Intent.ACTION_ATTACH_DATA setDataAndType(newUri, getMimeTypeFromUri(newUri)) @@ -87,28 +89,11 @@ fun Activity.setAs(uri: Uri) { } fun Activity.openFile(uri: Uri, forceChooser: Boolean) { - val newUri = ensurePublicUri(uri) - Intent().apply { - action = Intent.ACTION_VIEW - setDataAndType(newUri, getMimeTypeFromUri(newUri)) - addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - putExtra(IS_FROM_GALLERY, true) - - if (isNougatPlus()) { - putExtra(REAL_FILE_PATH, uri) - } - - if (resolveActivity(packageManager) != null) { - val chooser = Intent.createChooser(this, getString(R.string.open_with)) - startActivity(if (forceChooser) chooser else this) - } else { - toast(R.string.no_app_found) - } - } + openFile(uri, forceChooser, BuildConfig.APPLICATION_ID) } fun Activity.openEditor(uri: Uri) { - val newUri = ensurePublicUri(uri) + val newUri = ensurePublicUri(uri, BuildConfig.APPLICATION_ID) Intent().apply { action = Intent.ACTION_EDIT setDataAndType(newUri, getMimeTypeFromUri(newUri)) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt index 9bbbf9acf..d4b01c633 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -78,23 +78,3 @@ fun Context.getSortedDirectories(source: ArrayList): ArrayListGallery Edit Open camera - Open with - No valid app found (hidden) Pin folder Unpin folder diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 0a789d2b9..58607210b 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -4,8 +4,6 @@ Galerie Upravit Spustit fotoaparát - Otevřít pomocí - Nebyla nalezena žádná vhodná aplikace (skryté) Připnout složku Odepnout složku diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index cc3cf7217..c61f4ddcf 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -4,8 +4,6 @@ Galerie Bearbeiten Kamera öffnen - Öffnen mit - Keine passende App gefunden (versteckt) Ordner anheften Ordner loslösen diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index a734b1cd3..da0f6fcc5 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -4,8 +4,6 @@ Galería Editar Abrir cámara - Abrir con… - No se encontró una aplicación válida (oculto) Fijar carpeta No fijar carpeta diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 9e037de4c..6b52c8944 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -4,8 +4,6 @@ Galleria Muokkaa Avaa kamera - Avaa - Sovelluksia ei löydetty (piilotettu) Kiinnitä kansio Poista kiinnitys diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index eb5ff60f6..04ef9738b 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -4,8 +4,6 @@ Galerie Édition Ouvrir appareil photo - Ouvrir avec - Aucune application valide trouvée (caché) Épingler le dossier Désépingler le dossier diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 7db801366..64b823830 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -4,8 +4,6 @@ Gallery Edit Open camera - Open with - No valid app found (hidden) Pin folder Unpin folder diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index cc6924dc3..5e242277b 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -4,8 +4,6 @@ Galleria Modifica Apri fotocamera - Apri con - Nessun app valida trovata (nascosta) Blocca cartella Sblocca cartella diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index f91558821..b2ad7e4b3 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -4,8 +4,6 @@ ギャラリー 編集 カメラを開く - 別のアプリで開く - 有効なアプリが見つかりません (非表示) フォルダーをピン留めする フォルダーのピン留めを外す diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 82f9b4bff..f8d0b97e1 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -4,8 +4,6 @@ Gallerij Bewerken Camera - Openen met - Geen app gevonden om dit bestand mee te openen (verborgen) Map vastzetten Map losmaken diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index c5ab80af2..5540e8018 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -4,8 +4,6 @@ Simple Gallery Edytuj Uruchom aplikację aparatu - Otwórz w - Nie znaleziono danych aplikacji (ukryty) Przypnij folder Wypakuj folder diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 1e39213db..f3c706810 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -4,8 +4,6 @@ Galeria Editar Abrir câmera - Abrir com - Nenhum aplicativo encontrado     (oculto) Fixar pasta Desfixar pasta diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index bf1efa4af..0cb7291f2 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -4,8 +4,6 @@ Galeria Editar Abrir câmara - Abrir com - Nenhuma aplicação encontrada (oculta) Fixar pasta Desafixar pasta diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index b66903eef..b2e684e73 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -4,8 +4,6 @@ Галерея Редактировать Открыть камеру - Открыть в - Приложение не найдено (Скрытый) Закрепить папку Открепить папку diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 8f004a004..6239471e7 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -4,8 +4,6 @@ Galéria Upraviť Otvoriť fotoaparát - Otvoriť pomocou - Nenašla sa žiadna vhodná aplikácia (skryté) Pripnúť priečinok Odopnúť priečinok diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index b4c2aef0d..63e5194d9 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -4,8 +4,6 @@ Galleri Redigera Starta kameran - Öppna med - Hittade ingen giltig app (dold) Fäst mappen Släpp mappen diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 811d06fb6..5179f74ef 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -4,8 +4,6 @@ Galeri Düzenle Kamerayı aç - Bununla aç - Geçerli bir uygulama bulunamadı (gizli) Pin klasör Klasörü çöz diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index a33042254..497b9247d 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -4,8 +4,6 @@ 简约图库 编辑 打开相机 - 打开方式 - 未找到可用应用 (隐藏) 锁定目录 解除锁定目录 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 0bae980b9..3be9815c9 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -4,8 +4,6 @@ 簡易相簿 編輯 開啟相機 - 以其他應用程式開啟 - 找不到應用程式 (隱藏) 釘選資料夾 取消釘選資料夾 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7d13156d9..99c1c1e81 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,8 +4,6 @@ Gallery Edit Open camera - Open with - No valid app found (hidden) Pin folder Unpin folder