reuse the OpenFile intent handling from Commons
This commit is contained in:
parent
972a1d4a39
commit
73856e6769
26 changed files with 10 additions and 85 deletions
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Medium>) {
|
|||
}
|
||||
|
||||
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))
|
||||
|
|
|
@ -78,23 +78,3 @@ fun Context.getSortedDirectories(source: ArrayList<Directory>): ArrayList<Direct
|
|||
dirs.sort()
|
||||
return movePinnedDirectoriesToFront(dirs)
|
||||
}
|
||||
|
||||
fun Context.getMimeTypeFromUri(uri: Uri): String {
|
||||
var mimetype = uri.path.getMimeTypeFromPath()
|
||||
if (mimetype.isEmpty()) {
|
||||
try {
|
||||
mimetype = contentResolver.getType(uri)
|
||||
} catch (e: IllegalStateException) {
|
||||
}
|
||||
}
|
||||
return mimetype
|
||||
}
|
||||
|
||||
fun Context.ensurePublicUri(uri: Uri): Uri {
|
||||
return if (uri.scheme == "content") {
|
||||
uri
|
||||
} else {
|
||||
val file = File(uri.path)
|
||||
getFilePublicUri(file, BuildConfig.APPLICATION_ID)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,6 @@ val GET_ANY_INTENT = "get_any_intent"
|
|||
val SET_WALLPAPER_INTENT = "set_wallpaper_intent"
|
||||
val DIRECTORIES = "directories2"
|
||||
val IS_VIEW_INTENT = "is_view_intent"
|
||||
val IS_FROM_GALLERY = "is_from_gallery"
|
||||
val PICKED_PATHS = "picked_paths"
|
||||
|
||||
val REQUEST_EDIT_IMAGE = 1
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Gallery</string>
|
||||
<string name="edit">Edit</string>
|
||||
<string name="open_camera">Open camera</string>
|
||||
<string name="open_with">Open with</string>
|
||||
<string name="no_app_found">No valid app found</string>
|
||||
<string name="hidden">(hidden)</string>
|
||||
<string name="pin_folder">Pin folder</string>
|
||||
<string name="unpin_folder">Unpin folder</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Galerie</string>
|
||||
<string name="edit">Upravit</string>
|
||||
<string name="open_camera">Spustit fotoaparát</string>
|
||||
<string name="open_with">Otevřít pomocí</string>
|
||||
<string name="no_app_found">Nebyla nalezena žádná vhodná aplikace</string>
|
||||
<string name="hidden">(skryté)</string>
|
||||
<string name="pin_folder">Připnout složku</string>
|
||||
<string name="unpin_folder">Odepnout složku</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Galerie</string>
|
||||
<string name="edit">Bearbeiten</string>
|
||||
<string name="open_camera">Kamera öffnen</string>
|
||||
<string name="open_with">Öffnen mit</string>
|
||||
<string name="no_app_found">Keine passende App gefunden</string>
|
||||
<string name="hidden">(versteckt)</string>
|
||||
<string name="pin_folder">Ordner anheften</string>
|
||||
<string name="unpin_folder">Ordner loslösen</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Galería</string>
|
||||
<string name="edit">Editar</string>
|
||||
<string name="open_camera">Abrir cámara</string>
|
||||
<string name="open_with">Abrir con…</string>
|
||||
<string name="no_app_found">No se encontró una aplicación válida</string>
|
||||
<string name="hidden">(oculto)</string>
|
||||
<string name="pin_folder">Fijar carpeta</string>
|
||||
<string name="unpin_folder">No fijar carpeta</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Galleria</string>
|
||||
<string name="edit">Muokkaa</string>
|
||||
<string name="open_camera">Avaa kamera</string>
|
||||
<string name="open_with">Avaa</string>
|
||||
<string name="no_app_found">Sovelluksia ei löydetty</string>
|
||||
<string name="hidden">(piilotettu)</string>
|
||||
<string name="pin_folder">Kiinnitä kansio</string>
|
||||
<string name="unpin_folder">Poista kiinnitys</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Galerie</string>
|
||||
<string name="edit">Édition</string>
|
||||
<string name="open_camera">Ouvrir appareil photo</string>
|
||||
<string name="open_with">Ouvrir avec</string>
|
||||
<string name="no_app_found">Aucune application valide trouvée</string>
|
||||
<string name="hidden">(caché)</string>
|
||||
<string name="pin_folder">Épingler le dossier</string>
|
||||
<string name="unpin_folder">Désépingler le dossier</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Gallery</string>
|
||||
<string name="edit">Edit</string>
|
||||
<string name="open_camera">Open camera</string>
|
||||
<string name="open_with">Open with</string>
|
||||
<string name="no_app_found">No valid app found</string>
|
||||
<string name="hidden">(hidden)</string>
|
||||
<string name="pin_folder">Pin folder</string>
|
||||
<string name="unpin_folder">Unpin folder</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Galleria</string>
|
||||
<string name="edit">Modifica</string>
|
||||
<string name="open_camera">Apri fotocamera</string>
|
||||
<string name="open_with">Apri con</string>
|
||||
<string name="no_app_found">Nessun app valida trovata</string>
|
||||
<string name="hidden">(nascosta)</string>
|
||||
<string name="pin_folder">Blocca cartella</string>
|
||||
<string name="unpin_folder">Sblocca cartella</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">ギャラリー</string>
|
||||
<string name="edit">編集</string>
|
||||
<string name="open_camera">カメラを開く</string>
|
||||
<string name="open_with">別のアプリで開く</string>
|
||||
<string name="no_app_found">有効なアプリが見つかりません</string>
|
||||
<string name="hidden">(非表示)</string>
|
||||
<string name="pin_folder">フォルダーをピン留めする</string>
|
||||
<string name="unpin_folder">フォルダーのピン留めを外す</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Gallerij</string>
|
||||
<string name="edit">Bewerken</string>
|
||||
<string name="open_camera">Camera</string>
|
||||
<string name="open_with">Openen met</string>
|
||||
<string name="no_app_found">Geen app gevonden om dit bestand mee te openen</string>
|
||||
<string name="hidden">(verborgen)</string>
|
||||
<string name="pin_folder">Map vastzetten</string>
|
||||
<string name="unpin_folder">Map losmaken</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Simple Gallery</string>
|
||||
<string name="edit">Edytuj</string>
|
||||
<string name="open_camera">Uruchom aplikację aparatu</string>
|
||||
<string name="open_with">Otwórz w</string>
|
||||
<string name="no_app_found">Nie znaleziono danych aplikacji</string>
|
||||
<string name="hidden">(ukryty)</string>
|
||||
<string name="pin_folder">Przypnij folder</string>
|
||||
<string name="unpin_folder">Wypakuj folder</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Galeria</string>
|
||||
<string name="edit">Editar</string>
|
||||
<string name="open_camera">Abrir câmera</string>
|
||||
<string name="open_with">Abrir com</string>
|
||||
<string name="no_app_found">Nenhum aplicativo encontrado</string>
|
||||
<string name="hidden">(oculto)</string>
|
||||
<string name="pin_folder">Fixar pasta</string>
|
||||
<string name="unpin_folder">Desfixar pasta</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Galeria</string>
|
||||
<string name="edit">Editar</string>
|
||||
<string name="open_camera">Abrir câmara</string>
|
||||
<string name="open_with">Abrir com</string>
|
||||
<string name="no_app_found">Nenhuma aplicação encontrada</string>
|
||||
<string name="hidden">(oculta)</string>
|
||||
<string name="pin_folder">Fixar pasta</string>
|
||||
<string name="unpin_folder">Desafixar pasta</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Галерея</string>
|
||||
<string name="edit">Редактировать</string>
|
||||
<string name="open_camera">Открыть камеру</string>
|
||||
<string name="open_with">Открыть в</string>
|
||||
<string name="no_app_found">Приложение не найдено</string>
|
||||
<string name="hidden">(Скрытый)</string>
|
||||
<string name="pin_folder">Закрепить папку</string>
|
||||
<string name="unpin_folder">Открепить папку</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Galéria</string>
|
||||
<string name="edit">Upraviť</string>
|
||||
<string name="open_camera">Otvoriť fotoaparát</string>
|
||||
<string name="open_with">Otvoriť pomocou</string>
|
||||
<string name="no_app_found">Nenašla sa žiadna vhodná aplikácia</string>
|
||||
<string name="hidden">(skryté)</string>
|
||||
<string name="pin_folder">Pripnúť priečinok</string>
|
||||
<string name="unpin_folder">Odopnúť priečinok</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Galleri</string>
|
||||
<string name="edit">Redigera</string>
|
||||
<string name="open_camera">Starta kameran</string>
|
||||
<string name="open_with">Öppna med</string>
|
||||
<string name="no_app_found">Hittade ingen giltig app</string>
|
||||
<string name="hidden">(dold)</string>
|
||||
<string name="pin_folder">Fäst mappen</string>
|
||||
<string name="unpin_folder">Släpp mappen</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Galeri</string>
|
||||
<string name="edit">Düzenle</string>
|
||||
<string name="open_camera">Kamerayı aç</string>
|
||||
<string name="open_with">Bununla aç</string>
|
||||
<string name="no_app_found">Geçerli bir uygulama bulunamadı</string>
|
||||
<string name="hidden">(gizli)</string>
|
||||
<string name="pin_folder">Pin klasör</string>
|
||||
<string name="unpin_folder">Klasörü çöz</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">简约图库</string>
|
||||
<string name="edit">编辑</string>
|
||||
<string name="open_camera">打开相机</string>
|
||||
<string name="open_with">打开方式</string>
|
||||
<string name="no_app_found">未找到可用应用</string>
|
||||
<string name="hidden">(隐藏)</string>
|
||||
<string name="pin_folder">锁定目录</string>
|
||||
<string name="unpin_folder">解除锁定目录</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">簡易相簿</string>
|
||||
<string name="edit">編輯</string>
|
||||
<string name="open_camera">開啟相機</string>
|
||||
<string name="open_with">以其他應用程式開啟</string>
|
||||
<string name="no_app_found">找不到應用程式</string>
|
||||
<string name="hidden">(隱藏)</string>
|
||||
<string name="pin_folder">釘選資料夾</string>
|
||||
<string name="unpin_folder">取消釘選資料夾</string>
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<string name="app_launcher_name">Gallery</string>
|
||||
<string name="edit">Edit</string>
|
||||
<string name="open_camera">Open camera</string>
|
||||
<string name="open_with">Open with</string>
|
||||
<string name="no_app_found">No valid app found</string>
|
||||
<string name="hidden">(hidden)</string>
|
||||
<string name="pin_folder">Pin folder</string>
|
||||
<string name="unpin_folder">Unpin folder</string>
|
||||
|
|
Loading…
Reference in a new issue