move a couple more intent handling to the Commons library

This commit is contained in:
tibbi 2017-10-29 19:08:45 +01:00
parent 437390cfa3
commit 4c80ba98fb
25 changed files with 8 additions and 76 deletions

View file

@ -37,7 +37,7 @@ android {
} }
dependencies { dependencies {
compile 'com.simplemobiletools:commons:2.33.3' compile 'com.simplemobiletools:commons:2.33.6'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'

View file

@ -22,6 +22,7 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE
import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.views.MyScalableRecyclerView import com.simplemobiletools.commons.views.MyScalableRecyclerView
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R

View file

@ -28,6 +28,8 @@ import com.simplemobiletools.commons.dialogs.RenameItemDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.IS_FROM_GALLERY import com.simplemobiletools.commons.helpers.IS_FROM_GALLERY
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE
import com.simplemobiletools.commons.helpers.REQUEST_SET_AS
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.MediaActivity.Companion.mMedia import com.simplemobiletools.gallery.activities.MediaActivity.Companion.mMedia
import com.simplemobiletools.gallery.adapters.MyPagerAdapter import com.simplemobiletools.gallery.adapters.MyPagerAdapter

View file

@ -3,7 +3,6 @@ package com.simplemobiletools.gallery.extensions
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.TransactionTooLargeException
import android.provider.MediaStore import android.provider.MediaStore
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.view.View import android.view.View
@ -21,8 +20,6 @@ import com.simplemobiletools.gallery.BuildConfig
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.helpers.NOMEDIA 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.Directory
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import com.simplemobiletools.gallery.views.MySquareImageView import com.simplemobiletools.gallery.views.MySquareImageView
@ -31,29 +28,11 @@ import java.io.File
import java.util.* import java.util.*
fun Activity.shareUri(uri: Uri) { fun Activity.shareUri(uri: Uri) {
val shareTitle = resources.getString(R.string.share_via) shareUri(uri, BuildConfig.APPLICATION_ID)
Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_STREAM, ensurePublicUri(uri, BuildConfig.APPLICATION_ID))
type = getMimeTypeFromUri(uri)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
startActivity(Intent.createChooser(this, shareTitle))
}
} }
fun Activity.shareUris(uris: ArrayList<Uri>) { fun Activity.shareUris(uris: ArrayList<Uri>) {
val shareTitle = resources.getString(R.string.share_via) shareUris(uris, BuildConfig.APPLICATION_ID)
Intent().apply {
action = Intent.ACTION_SEND_MULTIPLE
type = uris.getMimeType()
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
try {
startActivity(Intent.createChooser(this, shareTitle))
} catch (e: TransactionTooLargeException) {
toast(R.string.maximum_share_reached)
}
}
} }
fun Activity.shareMedium(medium: Medium) { fun Activity.shareMedium(medium: Medium) {
@ -67,19 +46,7 @@ fun Activity.shareMedia(media: List<Medium>) {
} }
fun Activity.setAs(uri: Uri) { fun Activity.setAs(uri: Uri) {
val newUri = ensurePublicUri(uri, BuildConfig.APPLICATION_ID) setAs(uri, BuildConfig.APPLICATION_ID)
Intent().apply {
action = Intent.ACTION_ATTACH_DATA
setDataAndType(newUri, getMimeTypeFromUri(newUri))
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
val chooser = Intent.createChooser(this, getString(R.string.set_as))
if (resolveActivity(packageManager) != null) {
startActivityForResult(chooser, REQUEST_SET_AS)
} else {
toast(R.string.no_capable_app_found)
}
}
} }
fun Activity.openFile(uri: Uri, forceChooser: Boolean) { fun Activity.openFile(uri: Uri, forceChooser: Boolean) {
@ -87,22 +54,7 @@ fun Activity.openFile(uri: Uri, forceChooser: Boolean) {
} }
fun Activity.openEditor(uri: Uri) { fun Activity.openEditor(uri: Uri) {
val newUri = ensurePublicUri(uri, BuildConfig.APPLICATION_ID) openEditor(uri, BuildConfig.APPLICATION_ID)
Intent().apply {
action = Intent.ACTION_EDIT
setDataAndType(newUri, getMimeTypeFromUri(newUri))
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
if (isNougatPlus()) {
putExtra(MediaStore.EXTRA_OUTPUT, uri)
}
if (resolveActivity(packageManager) != null) {
startActivityForResult(this, REQUEST_EDIT_IMAGE)
} else {
toast(R.string.no_editor_found)
}
}
} }
fun Activity.launchCamera() { fun Activity.launchCamera() {

View file

@ -68,9 +68,6 @@ val DIRECTORIES = "directories2"
val IS_VIEW_INTENT = "is_view_intent" val IS_VIEW_INTENT = "is_view_intent"
val PICKED_PATHS = "picked_paths" val PICKED_PATHS = "picked_paths"
val REQUEST_EDIT_IMAGE = 1
val REQUEST_SET_AS = 2
// rotations // rotations
val ROTATE_BY_SYSTEM_SETTING = 0 val ROTATE_BY_SYSTEM_SETTING = 0
val ROTATE_BY_DEVICE_ROTATION = 1 val ROTATE_BY_DEVICE_ROTATION = 1

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Change cover image</string> <string name="change_cover_image">Change cover image</string>
<string name="select_photo">Select photo</string> <string name="select_photo">Select photo</string>
<string name="use_default">Use default</string> <string name="use_default">Use default</string>
<string name="set_as">Set as</string>
<string name="volume">Volume</string> <string name="volume">Volume</string>
<string name="brightness">Brightness</string> <string name="brightness">Brightness</string>
<string name="do_not_ask_again">Do not ask again in this session</string> <string name="do_not_ask_again">Do not ask again in this session</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Change cover image</string> <string name="change_cover_image">Change cover image</string>
<string name="select_photo">Select photo</string> <string name="select_photo">Select photo</string>
<string name="use_default">Use default</string> <string name="use_default">Use default</string>
<string name="set_as">Nastavit jako</string>
<string name="volume">Volume</string> <string name="volume">Volume</string>
<string name="brightness">Brightness</string> <string name="brightness">Brightness</string>
<string name="do_not_ask_again">Do not ask again in this session</string> <string name="do_not_ask_again">Do not ask again in this session</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Coverbild ändern</string> <string name="change_cover_image">Coverbild ändern</string>
<string name="select_photo">Auswählen</string> <string name="select_photo">Auswählen</string>
<string name="use_default">Standard</string> <string name="use_default">Standard</string>
<string name="set_as">Festlegen als</string>
<string name="volume">Lautstärke</string> <string name="volume">Lautstärke</string>
<string name="brightness">Helligkeit</string> <string name="brightness">Helligkeit</string>
<string name="do_not_ask_again">Nicht erneut fragen (in dieser Session)</string> <string name="do_not_ask_again">Nicht erneut fragen (in dieser Session)</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Cambiar imagen de portada</string> <string name="change_cover_image">Cambiar imagen de portada</string>
<string name="select_photo">Seleccionar imagen</string> <string name="select_photo">Seleccionar imagen</string>
<string name="use_default">Uso por defecto</string> <string name="use_default">Uso por defecto</string>
<string name="set_as">Establecer como</string>
<string name="volume">Volume</string> <string name="volume">Volume</string>
<string name="brightness">Brightness</string> <string name="brightness">Brightness</string>
<string name="do_not_ask_again">Do not ask again in this session</string> <string name="do_not_ask_again">Do not ask again in this session</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Vaihda kansikuva</string> <string name="change_cover_image">Vaihda kansikuva</string>
<string name="select_photo">Valitse kuva</string> <string name="select_photo">Valitse kuva</string>
<string name="use_default">Käytä oletuksia</string> <string name="use_default">Käytä oletuksia</string>
<string name="set_as">Aseta</string>
<string name="volume">Äänenvoimakkuus</string> <string name="volume">Äänenvoimakkuus</string>
<string name="brightness">Kirkkaus</string> <string name="brightness">Kirkkaus</string>
<string name="do_not_ask_again">Do not ask again in this session</string> <string name="do_not_ask_again">Do not ask again in this session</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Changer l\'image de couverture</string> <string name="change_cover_image">Changer l\'image de couverture</string>
<string name="select_photo">Sélectionner une photo</string> <string name="select_photo">Sélectionner une photo</string>
<string name="use_default">Utiliser par défaut</string> <string name="use_default">Utiliser par défaut</string>
<string name="set_as">Définir comme</string>
<string name="volume">Volume</string> <string name="volume">Volume</string>
<string name="brightness">Luminosité</string> <string name="brightness">Luminosité</string>
<string name="do_not_ask_again">Ne pas redemander pour cette session</string> <string name="do_not_ask_again">Ne pas redemander pour cette session</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Change cover image</string> <string name="change_cover_image">Change cover image</string>
<string name="select_photo">Select photo</string> <string name="select_photo">Select photo</string>
<string name="use_default">Use default</string> <string name="use_default">Use default</string>
<string name="set_as">Set as</string>
<string name="volume">Volume</string> <string name="volume">Volume</string>
<string name="brightness">Brightness</string> <string name="brightness">Brightness</string>
<string name="do_not_ask_again">Do not ask again in this session</string> <string name="do_not_ask_again">Do not ask again in this session</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Cambia immagine copertina</string> <string name="change_cover_image">Cambia immagine copertina</string>
<string name="select_photo">Seleziona foto</string> <string name="select_photo">Seleziona foto</string>
<string name="use_default">Usa predefinita</string> <string name="use_default">Usa predefinita</string>
<string name="set_as">Imposta come</string>
<string name="volume">Volume</string> <string name="volume">Volume</string>
<string name="brightness">Luminosità</string> <string name="brightness">Luminosità</string>
<string name="do_not_ask_again">Non chiedere nuovamente in questa sessione</string> <string name="do_not_ask_again">Non chiedere nuovamente in questa sessione</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">カバー画像を変更</string> <string name="change_cover_image">カバー画像を変更</string>
<string name="select_photo">写真を選択</string> <string name="select_photo">写真を選択</string>
<string name="use_default">デフォルトに戻す</string> <string name="use_default">デフォルトに戻す</string>
<string name="set_as">他で使う</string>
<string name="volume">音量</string> <string name="volume">音量</string>
<string name="brightness">明るさ</string> <string name="brightness">明るさ</string>
<string name="do_not_ask_again">Do not ask again in this session</string> <string name="do_not_ask_again">Do not ask again in this session</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Afbeelding voor omslag veranderen</string> <string name="change_cover_image">Afbeelding voor omslag veranderen</string>
<string name="select_photo">Foto selecteren</string> <string name="select_photo">Foto selecteren</string>
<string name="use_default">Standaard gebruiken</string> <string name="use_default">Standaard gebruiken</string>
<string name="set_as">Instellen als</string>
<string name="volume">Volume</string> <string name="volume">Volume</string>
<string name="brightness">Helderheid</string> <string name="brightness">Helderheid</string>
<string name="do_not_ask_again">Onthouden voor deze sessie</string> <string name="do_not_ask_again">Onthouden voor deze sessie</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Zmień okładkę</string> <string name="change_cover_image">Zmień okładkę</string>
<string name="select_photo">Wybierz obraz</string> <string name="select_photo">Wybierz obraz</string>
<string name="use_default">Użyj domyślnej</string> <string name="use_default">Użyj domyślnej</string>
<string name="set_as">Ustaw jako</string>
<string name="volume">Głośność</string> <string name="volume">Głośność</string>
<string name="brightness">Jasność</string> <string name="brightness">Jasność</string>
<string name="do_not_ask_again">Nie pytaj więcej w tej sesji</string> <string name="do_not_ask_again">Nie pytaj więcej w tej sesji</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Trocar imagem de capa</string> <string name="change_cover_image">Trocar imagem de capa</string>
<string name="select_photo">Selecionar foto</string> <string name="select_photo">Selecionar foto</string>
<string name="use_default">Usar padrão</string> <string name="use_default">Usar padrão</string>
<string name="set_as">Definir como</string>
<string name="volume">Volume</string> <string name="volume">Volume</string>
<string name="brightness">Brilho</string> <string name="brightness">Brilho</string>
<string name="do_not_ask_again">Não perguntar novamente por enquanto</string> <string name="do_not_ask_again">Não perguntar novamente por enquanto</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Alterar imagem de capa</string> <string name="change_cover_image">Alterar imagem de capa</string>
<string name="select_photo">Selecionar foto</string> <string name="select_photo">Selecionar foto</string>
<string name="use_default">Predefinição</string> <string name="use_default">Predefinição</string>
<string name="set_as">Definir como</string>
<string name="volume">Volume</string> <string name="volume">Volume</string>
<string name="brightness">Brilho</string> <string name="brightness">Brilho</string>
<string name="do_not_ask_again">Não perguntar de novo para esta sessão</string> <string name="do_not_ask_again">Não perguntar de novo para esta sessão</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Изменить обложку</string> <string name="change_cover_image">Изменить обложку</string>
<string name="select_photo">Выбрать изображение</string> <string name="select_photo">Выбрать изображение</string>
<string name="use_default">Использовать по умолчанию</string> <string name="use_default">Использовать по умолчанию</string>
<string name="set_as">Установить как…</string>
<string name="volume">Громкость</string> <string name="volume">Громкость</string>
<string name="brightness">Яркость</string> <string name="brightness">Яркость</string>
<string name="do_not_ask_again">Do not ask again in this session</string> <string name="do_not_ask_again">Do not ask again in this session</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Zmeniť obal albumu</string> <string name="change_cover_image">Zmeniť obal albumu</string>
<string name="select_photo">Zvoliť foto</string> <string name="select_photo">Zvoliť foto</string>
<string name="use_default">Použiť predvolený</string> <string name="use_default">Použiť predvolený</string>
<string name="set_as">Nastaviť ako</string>
<string name="volume">Hlasitosť</string> <string name="volume">Hlasitosť</string>
<string name="brightness">Jas</string> <string name="brightness">Jas</string>
<string name="do_not_ask_again">Nepýtať sa už v tomto spustení</string> <string name="do_not_ask_again">Nepýtať sa už v tomto spustení</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Byt omslagsbild</string> <string name="change_cover_image">Byt omslagsbild</string>
<string name="select_photo">Välj foto</string> <string name="select_photo">Välj foto</string>
<string name="use_default">Använd standard</string> <string name="use_default">Använd standard</string>
<string name="set_as">Ange som</string>
<string name="volume">Volym</string> <string name="volume">Volym</string>
<string name="brightness">Ljusstyrka</string> <string name="brightness">Ljusstyrka</string>
<string name="do_not_ask_again">Do not ask again in this session</string> <string name="do_not_ask_again">Do not ask again in this session</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Change cover image</string> <string name="change_cover_image">Change cover image</string>
<string name="select_photo">Select photo</string> <string name="select_photo">Select photo</string>
<string name="use_default">Use default</string> <string name="use_default">Use default</string>
<string name="set_as">Set as</string>
<string name="volume">Volume</string> <string name="volume">Volume</string>
<string name="brightness">Brightness</string> <string name="brightness">Brightness</string>
<string name="do_not_ask_again">Do not ask again in this session</string> <string name="do_not_ask_again">Do not ask again in this session</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">更改封面图片</string> <string name="change_cover_image">更改封面图片</string>
<string name="select_photo">选择图片</string> <string name="select_photo">选择图片</string>
<string name="use_default">使用默认</string> <string name="use_default">使用默认</string>
<string name="set_as">设置为</string>
<string name="volume">音量</string> <string name="volume">音量</string>
<string name="brightness">亮度</string> <string name="brightness">亮度</string>
<string name="do_not_ask_again">不再提醒</string> <string name="do_not_ask_again">不再提醒</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">更換封面圖片</string> <string name="change_cover_image">更換封面圖片</string>
<string name="select_photo">選擇相片</string> <string name="select_photo">選擇相片</string>
<string name="use_default">使用預設</string> <string name="use_default">使用預設</string>
<string name="set_as">設為</string>
<string name="volume">音量</string> <string name="volume">音量</string>
<string name="brightness">亮度</string> <string name="brightness">亮度</string>
<string name="do_not_ask_again">Do not ask again in this session</string> <string name="do_not_ask_again">Do not ask again in this session</string>

View file

@ -20,7 +20,6 @@
<string name="change_cover_image">Change cover image</string> <string name="change_cover_image">Change cover image</string>
<string name="select_photo">Select photo</string> <string name="select_photo">Select photo</string>
<string name="use_default">Use default</string> <string name="use_default">Use default</string>
<string name="set_as">Set as</string>
<string name="volume">Volume</string> <string name="volume">Volume</string>
<string name="brightness">Brightness</string> <string name="brightness">Brightness</string>
<string name="do_not_ask_again">Do not ask again in this session</string> <string name="do_not_ask_again">Do not ask again in this session</string>