Skip to content

Commit b1c7c6f

Browse files
committed
fix #121, handle Select Ringtone intent
1 parent 27da8b4 commit b1c7c6f

File tree

20 files changed

+48
-10
lines changed

20 files changed

+48
-10
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
<category android:name="android.intent.category.DEFAULT"/>
3434
</intent-filter>
3535

36+
<intent-filter>
37+
<action android:name="android.intent.action.RINGTONE_PICKER"/>
38+
<category android:name="android.intent.category.DEFAULT"/>
39+
</intent-filter>
40+
3641
<intent-filter>
3742
<action android:name="android.intent.action.VIEW"/>
3843
<category android:name="android.intent.category.DEFAULT"/>

app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.simplemobiletools.filemanager.activities
33
import android.app.Activity
44
import android.content.ClipData
55
import android.content.Intent
6+
import android.media.RingtoneManager
67
import android.os.Bundle
78
import android.os.Handler
89
import android.view.Menu
@@ -37,11 +38,11 @@ class MainActivity : SimpleActivity() {
3738
setContentView(R.layout.activity_main)
3839
storeStoragePaths()
3940

40-
fragment = fragment_holder as ItemsFragment
41-
val isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT
42-
val allowPickingMultiple = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
43-
fragment.isGetContentIntent = isGetContentIntent
44-
fragment.isPickMultipleIntent = allowPickingMultiple
41+
fragment = (fragment_holder as ItemsFragment).apply {
42+
isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
43+
isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT
44+
isPickMultipleIntent = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
45+
}
4546

4647
tryInitFileManager()
4748
checkWhatsNewDialog()
@@ -241,8 +242,19 @@ class MainActivity : SimpleActivity() {
241242
val resultIntent = Intent()
242243
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
243244
val type = path.getMimeTypeFromPath()
244-
resultIntent.setDataAndTypeAndNormalize(uri, type)
245+
resultIntent.setDataAndType(uri, type)
246+
resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
247+
setResult(Activity.RESULT_OK, resultIntent)
248+
finish()
249+
}
250+
251+
fun pickedRingtone(path: String) {
252+
val resultIntent = Intent()
253+
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
254+
val type = path.getMimeTypeFromPath()
255+
resultIntent.setDataAndType(uri, type)
245256
resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
257+
resultIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, uri)
246258
setResult(Activity.RESULT_OK, resultIntent)
247259
finish()
248260
}

app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import android.view.LayoutInflater
1010
import android.view.View
1111
import android.view.ViewGroup
1212
import com.simplemobiletools.commons.dialogs.StoragePickerDialog
13-
import com.simplemobiletools.commons.extensions.deleteFiles
14-
import com.simplemobiletools.commons.extensions.getFilenameFromPath
15-
import com.simplemobiletools.commons.extensions.toast
16-
import com.simplemobiletools.commons.extensions.updateTextColors
13+
import com.simplemobiletools.commons.extensions.*
1714
import com.simplemobiletools.commons.models.FileDirItem
1815
import com.simplemobiletools.commons.views.Breadcrumbs
1916
import com.simplemobiletools.commons.views.MyScalableRecyclerView
@@ -36,6 +33,7 @@ import kotlin.collections.ArrayList
3633
class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrumbs.BreadcrumbsListener {
3734
var currentPath = ""
3835
var isGetContentIntent = false
36+
var isGetRingtonePicker = false
3937
var isPickMultipleIntent = false
4038

4139
private var storedTextColor = 0
@@ -223,6 +221,12 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum
223221
val path = item.path
224222
if (isGetContentIntent) {
225223
(activity as MainActivity).pickedPath(path)
224+
} else if (isGetRingtonePicker) {
225+
if (path.isAudioFast()) {
226+
(activity as MainActivity).pickedRingtone(path)
227+
} else {
228+
activity?.toast(R.string.select_audio_file)
229+
}
226230
} else {
227231
val file = File(path)
228232
activity!!.openFile(Uri.fromFile(file), false)

app/src/main/res/values-cs/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<string name="home_folder_updated">Domovská složka aktualizována</string>
1010
<string name="copy_path">Copy path to clipboard</string>
1111
<string name="path_copied">Path copied</string>
12+
<string name="select_audio_file">Please select an audio file</string>
1213

1314
<!-- Compression -->
1415
<string name="compress">Compress</string>

app/src/main/res/values-de/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<string name="home_folder_updated">Home-Ordner aktualisiert</string>
1010
<string name="copy_path">Kopiere Pfad in die Zwischenablage</string>
1111
<string name="path_copied">Pfad kopiert</string>
12+
<string name="select_audio_file">Please select an audio file</string>
1213

1314
<!-- Compression -->
1415
<string name="compress">Komprimieren</string>

app/src/main/res/values-es/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<string name="home_folder_updated">Carpeta principal actualizada</string>
1010
<string name="copy_path">Copy path to clipboard</string>
1111
<string name="path_copied">Path copied</string>
12+
<string name="select_audio_file">Please select an audio file</string>
1213

1314
<!-- Compression -->
1415
<string name="compress">Compress</string>

app/src/main/res/values-fr/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<string name="home_folder_updated">Dossier par défaut mis à jour</string>
1010
<string name="copy_path">Copy path to clipboard</string>
1111
<string name="path_copied">Path copied</string>
12+
<string name="select_audio_file">Please select an audio file</string>
1213

1314
<!-- Compression -->
1415
<string name="compress">Compresser</string>

app/src/main/res/values-hu/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<string name="home_folder_updated">Kezdőmappa frissítve</string>
1010
<string name="copy_path">Copy path to clipboard</string>
1111
<string name="path_copied">Path copied</string>
12+
<string name="select_audio_file">Please select an audio file</string>
1213

1314
<!-- Compression -->
1415
<string name="compress">Compress</string>

app/src/main/res/values-it/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<string name="home_folder_updated">Cartella home aggiornata</string>
1010
<string name="copy_path">Copia percorso negli appunti</string>
1111
<string name="path_copied">Percorso copiato</string>
12+
<string name="select_audio_file">Please select an audio file</string>
1213

1314
<!-- Compression -->
1415
<string name="compress">Comprimi</string>

app/src/main/res/values-ja/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<string name="home_folder_updated">Home folder updated</string>
1010
<string name="copy_path">Copy path to clipboard</string>
1111
<string name="path_copied">Path copied</string>
12+
<string name="select_audio_file">Please select an audio file</string>
1213

1314
<!-- Compression -->
1415
<string name="compress">Compress</string>

0 commit comments

Comments
 (0)