From b1c7c6f9b19aeeaac43763263cd645867d2cadc0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 21:47:09 +0100 Subject: [PATCH] fix #121, handle Select Ringtone intent --- app/src/main/AndroidManifest.xml | 5 ++++ .../filemanager/activities/MainActivity.kt | 24 ++++++++++++++----- .../filemanager/fragments/ItemsFragment.kt | 12 ++++++---- app/src/main/res/values-cs/strings.xml | 1 + app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-hu/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-ko-rKR/strings.xml | 1 + app/src/main/res/values-nl/strings.xml | 1 + app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-pt/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values-sk/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values-tr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 20 files changed, 48 insertions(+), 10 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fc40f52b..75f1e880 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,6 +33,11 @@ + + + + + diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt index 9b08e281..5e031997 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt @@ -3,6 +3,7 @@ package com.simplemobiletools.filemanager.activities import android.app.Activity import android.content.ClipData import android.content.Intent +import android.media.RingtoneManager import android.os.Bundle import android.os.Handler import android.view.Menu @@ -37,11 +38,11 @@ class MainActivity : SimpleActivity() { setContentView(R.layout.activity_main) storeStoragePaths() - fragment = fragment_holder as ItemsFragment - val isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT - val allowPickingMultiple = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false) - fragment.isGetContentIntent = isGetContentIntent - fragment.isPickMultipleIntent = allowPickingMultiple + fragment = (fragment_holder as ItemsFragment).apply { + isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER + isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT + isPickMultipleIntent = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false) + } tryInitFileManager() checkWhatsNewDialog() @@ -241,12 +242,23 @@ class MainActivity : SimpleActivity() { val resultIntent = Intent() val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID) val type = path.getMimeTypeFromPath() - resultIntent.setDataAndTypeAndNormalize(uri, type) + resultIntent.setDataAndType(uri, type) resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION setResult(Activity.RESULT_OK, resultIntent) finish() } + fun pickedRingtone(path: String) { + val resultIntent = Intent() + val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID) + val type = path.getMimeTypeFromPath() + resultIntent.setDataAndType(uri, type) + resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION + resultIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, uri) + setResult(Activity.RESULT_OK, resultIntent) + finish() + } + fun pickedPaths(paths: ArrayList) { val uris = paths.map { getFilePublicUri(File(it), BuildConfig.APPLICATION_ID) } as ArrayList val clipData = ClipData("Attachment", arrayOf(uris.getMimeType()), ClipData.Item(uris.removeAt(0))) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt index 41ff4ae5..0ade30f2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt @@ -10,10 +10,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.simplemobiletools.commons.dialogs.StoragePickerDialog -import com.simplemobiletools.commons.extensions.deleteFiles -import com.simplemobiletools.commons.extensions.getFilenameFromPath -import com.simplemobiletools.commons.extensions.toast -import com.simplemobiletools.commons.extensions.updateTextColors +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.views.Breadcrumbs import com.simplemobiletools.commons.views.MyScalableRecyclerView @@ -36,6 +33,7 @@ import kotlin.collections.ArrayList class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrumbs.BreadcrumbsListener { var currentPath = "" var isGetContentIntent = false + var isGetRingtonePicker = false var isPickMultipleIntent = false private var storedTextColor = 0 @@ -223,6 +221,12 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum val path = item.path if (isGetContentIntent) { (activity as MainActivity).pickedPath(path) + } else if (isGetRingtonePicker) { + if (path.isAudioFast()) { + (activity as MainActivity).pickedRingtone(path) + } else { + activity?.toast(R.string.select_audio_file) + } } else { val file = File(path) activity!!.openFile(Uri.fromFile(file), false) diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 65704cac..0a35250f 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -9,6 +9,7 @@ Domovská složka aktualizována Copy path to clipboard Path copied + Please select an audio file Compress diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index ea694368..fbab7d21 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -9,6 +9,7 @@ Home-Ordner aktualisiert Kopiere Pfad in die Zwischenablage Pfad kopiert + Please select an audio file Komprimieren diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 5a24b6b5..a637f531 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -9,6 +9,7 @@ Carpeta principal actualizada Copy path to clipboard Path copied + Please select an audio file Compress diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 12b7fb91..889ac068 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -9,6 +9,7 @@ Dossier par défaut mis à jour Copy path to clipboard Path copied + Please select an audio file Compresser diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 2a34a1c1..039a1800 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -9,6 +9,7 @@ Kezdőmappa frissítve Copy path to clipboard Path copied + Please select an audio file Compress diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 3feb245e..fef7dd5d 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -9,6 +9,7 @@ Cartella home aggiornata Copia percorso negli appunti Percorso copiato + Please select an audio file Comprimi diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 39abd711..9e38f19c 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -9,6 +9,7 @@ Home folder updated Copy path to clipboard Path copied + Please select an audio file Compress diff --git a/app/src/main/res/values-ko-rKR/strings.xml b/app/src/main/res/values-ko-rKR/strings.xml index af3f4436..4865c9dd 100644 --- a/app/src/main/res/values-ko-rKR/strings.xml +++ b/app/src/main/res/values-ko-rKR/strings.xml @@ -9,6 +9,7 @@ 홈 폴더 설정완료 Copy path to clipboard Path copied + Please select an audio file Compress diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 2e6cb02e..cd07547c 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -9,6 +9,7 @@ Beginmap ingesteld Pad naar klembord kopiëren Pad gekopieerd + Please select an audio file Inpakken diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 72babba1..1db61ccb 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -9,6 +9,7 @@ Folder główny został zaktulizowany Copy path to clipboard Path copied + Please select an audio file Compress diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 625f2521..5254f862 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -9,6 +9,7 @@ Pasta pessoal atualizada Copy path to clipboard Path copied + Please select an audio file Compress diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 91c9b517..e4f75663 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -9,6 +9,7 @@ Pasta pessoal atualizada Copiar caminho para a área de transferência Caminho copiado + Please select an audio file Comprimir diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 8bb775e5..78f0db2e 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -9,6 +9,7 @@ Домашняя папка установлена Copy path to clipboard Path copied + Please select an audio file Сжать diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index f5bfd5b7..ec6206a8 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -9,6 +9,7 @@ Domovský priečinok bol nastavený Kopírovať cestu do schránky Cesta skopírovaná + Prosím zvoľte audio súbor Komprimovať diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 9ddc4fd6..1ad58ec5 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -9,6 +9,7 @@ Hemmappen har uppdaterats Copy path to clipboard Path copied + Please select an audio file Komprimera diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index b5325d75..19677bad 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -9,6 +9,7 @@ Home folder updated Copy path to clipboard Path copied + Please select an audio file Compress diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bfbf66d4..86884b00 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -9,6 +9,7 @@ Home folder updated Copy path to clipboard Path copied + Please select an audio file Compress