diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/service/DownloadFile.java b/ultrasonic/src/main/java/org/moire/ultrasonic/service/DownloadFile.java
index fac7939f..eb71800f 100644
--- a/ultrasonic/src/main/java/org/moire/ultrasonic/service/DownloadFile.java
+++ b/ultrasonic/src/main/java/org/moire/ultrasonic/service/DownloadFile.java
@@ -409,20 +409,10 @@ public class DownloadFile
{
Util.renameFile(partialFile, saveFile);
mediaStoreService.saveInMediaStore(DownloadFile.this);
-
- if (Util.getShouldScanMedia(context))
- {
- Util.scanMedia(context, saveFile);
- }
}
else
{
Util.renameFile(partialFile, completeFile);
-
- if (Util.getShouldScanMedia(context))
- {
- Util.scanMedia(context, completeFile);
- }
}
}
}
diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/service/Downloader.java b/ultrasonic/src/main/java/org/moire/ultrasonic/service/Downloader.java
index 547b218b..6aa31584 100644
--- a/ultrasonic/src/main/java/org/moire/ultrasonic/service/Downloader.java
+++ b/ultrasonic/src/main/java/org/moire/ultrasonic/service/Downloader.java
@@ -188,10 +188,6 @@ public class Downloader
DownloadFile downloadFile = backgroundDownloadList.get(i);
if (downloadFile.isWorkDone() && (!downloadFile.shouldSave() || downloadFile.isSaved()))
{
- if (Util.getShouldScanMedia(context))
- {
- Util.scanMedia(context, downloadFile.getCompleteFile());
- }
// Don't need to keep list like active song list
backgroundDownloadList.remove(i);
diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/service/MediaStoreService.java b/ultrasonic/src/main/java/org/moire/ultrasonic/service/MediaStoreService.java
deleted file mode 100644
index 60a2e6de..00000000
--- a/ultrasonic/src/main/java/org/moire/ultrasonic/service/MediaStoreService.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- This file is part of Subsonic.
-
- Subsonic is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- Subsonic is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Subsonic. If not, see .
-
- Copyright 2009 (C) Sindre Mehus
- */
-package org.moire.ultrasonic.service;
-
-import java.io.File;
-
-import android.content.ContentResolver;
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.Cursor;
-import android.net.Uri;
-import android.provider.MediaStore;
-import timber.log.Timber;
-
-import org.moire.ultrasonic.domain.MusicDirectory;
-import org.moire.ultrasonic.util.FileUtil;
-
-/**
- * @author Sindre Mehus
- */
-public class MediaStoreService
-{
- private static final Uri ALBUM_ART_URI = Uri.parse("content://media/external/audio/albumart");
-
- private final Context context;
-
- public MediaStoreService(Context context)
- {
- this.context = context;
- }
-
- public void saveInMediaStore(DownloadFile downloadFile)
- {
- MusicDirectory.Entry song = downloadFile.getSong();
- File songFile = downloadFile.getCompleteFile();
-
- // Delete existing row in case the song has been downloaded before.
- deleteFromMediaStore(downloadFile);
-
- ContentResolver contentResolver = context.getContentResolver();
- ContentValues values = new ContentValues();
- values.put(MediaStore.MediaColumns.TITLE, song.getTitle());
- values.put(MediaStore.Audio.AudioColumns.ARTIST, song.getArtist());
- values.put(MediaStore.Audio.AudioColumns.ALBUM, song.getAlbum());
- values.put(MediaStore.Audio.AudioColumns.TRACK, song.getTrack());
- values.put(MediaStore.Audio.AudioColumns.YEAR, song.getYear());
- values.put(MediaStore.MediaColumns.DATA, songFile.getAbsolutePath());
- values.put(MediaStore.MediaColumns.MIME_TYPE, song.getContentType());
- values.put(MediaStore.Audio.AudioColumns.IS_MUSIC, 1);
-
- Uri uri = contentResolver.insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values);
-
- if (uri != null)
- {
- // Look up album, and add cover art if found.
- Cursor cursor = contentResolver.query(uri, new String[]{MediaStore.Audio.AudioColumns.ALBUM_ID}, null, null, null);
-
- if (cursor != null && cursor.moveToFirst())
- {
- int albumId = cursor.getInt(0);
- insertAlbumArt(albumId, downloadFile);
- cursor.close();
- }
- }
- }
-
- public void deleteFromMediaStore(DownloadFile downloadFile)
- {
- ContentResolver contentResolver = context.getContentResolver();
- MusicDirectory.Entry song = downloadFile.getSong();
- File file = downloadFile.getCompleteFile();
-
- int n = contentResolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, MediaStore.Audio.AudioColumns.TITLE_KEY + "=? AND " +
- MediaStore.MediaColumns.DATA + "=?", new String[]{MediaStore.Audio.keyFor(song.getTitle()), file.getAbsolutePath()});
- if (n > 0)
- {
- Timber.i("Deleting media store row for %s", song);
- }
- }
-
- private void insertAlbumArt(int albumId, DownloadFile downloadFile)
- {
- ContentResolver contentResolver = context.getContentResolver();
- Uri uri = Uri.withAppendedPath(ALBUM_ART_URI, String.valueOf(albumId));
-
- if (uri == null)
- {
- return;
- }
-
- Cursor cursor = contentResolver.query(uri, null, null, null, null);
-
- if (cursor != null && !cursor.moveToFirst())
- {
- // No album art found, add it.
- File albumArtFile = FileUtil.getAlbumArtFile(context, downloadFile.getSong());
- if (albumArtFile.exists())
- {
- ContentValues values = new ContentValues();
- values.put(MediaStore.Audio.AlbumColumns.ALBUM_ID, albumId);
- values.put(MediaStore.MediaColumns.DATA, albumArtFile.getPath());
- contentResolver.insert(ALBUM_ART_URI, values);
- Timber.i("Added album art: %s", albumArtFile);
- }
-
- cursor.close();
- }
- }
-}
\ No newline at end of file
diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/util/Constants.java b/ultrasonic/src/main/java/org/moire/ultrasonic/util/Constants.java
index 13c81c1c..92660026 100644
--- a/ultrasonic/src/main/java/org/moire/ultrasonic/util/Constants.java
+++ b/ultrasonic/src/main/java/org/moire/ultrasonic/util/Constants.java
@@ -125,7 +125,6 @@ public final class Constants
public static final String PREFERENCES_KEY_DEFAULT_SHARE_GREETING = "sharingDefaultGreeting";
public static final String PREFERENCES_KEY_DEFAULT_SHARE_EXPIRATION = "sharingDefaultExpiration";
public static final String PREFERENCES_KEY_SHOW_ALL_SONGS_BY_ARTIST = "showAllSongsByArtist";
- public static final String PREFERENCES_KEY_SCAN_MEDIA = "scanMedia";
public static final String PREFERENCES_KEY_IMAGE_LOADER_CONCURRENCY = "imageLoaderConcurrency";
public static final String PREFERENCES_KEY_FF_IMAGE_LOADER = "ff_new_image_loader";
public static final String PREFERENCES_KEY_USE_FIVE_STAR_RATING = "use_five_star_rating";
diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/util/Util.java b/ultrasonic/src/main/java/org/moire/ultrasonic/util/Util.java
index aac3eeea..ca1c5e0e 100644
--- a/ultrasonic/src/main/java/org/moire/ultrasonic/util/Util.java
+++ b/ultrasonic/src/main/java/org/moire/ultrasonic/util/Util.java
@@ -1394,18 +1394,6 @@ public class Util
return preferences.getBoolean(Constants.PREFERENCES_KEY_SHOW_ALL_SONGS_BY_ARTIST, false);
}
- public static boolean getShouldScanMedia(Context context)
- {
- SharedPreferences preferences = getPreferences(context);
- return preferences.getBoolean(Constants.PREFERENCES_KEY_SCAN_MEDIA, false);
- }
-
- public static void scanMedia(Context context, File file)
- {
- Uri uri = Uri.fromFile(file);
- Intent scanFileIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
- context.sendBroadcast(scanFileIntent);
- }
public static int getImageLoaderConcurrency(Context context)
{
diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaStoreService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaStoreService.kt
new file mode 100644
index 00000000..aca53951
--- /dev/null
+++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaStoreService.kt
@@ -0,0 +1,114 @@
+/*
+ * MediaStoreService.kt
+ * Copyright (C) 2009-2021 Ultrasonic developers
+ *
+ * Distributed under terms of the GNU GPLv3 license.
+ */
+
+package org.moire.ultrasonic.service
+
+import android.content.ContentValues
+import android.content.Context
+import android.net.Uri
+import android.os.Build
+import android.provider.MediaStore
+import org.moire.ultrasonic.util.FileUtil
+import timber.log.Timber
+
+/**
+ * By adding UltraSonics media files to the Android MediaStore
+ * they become available in the stock music apps
+ *
+ * @author Sindre Mehus
+ */
+
+class MediaStoreService(private val context: Context) {
+
+ // Find the audio collection on the primary external storage device.
+ val collection: Uri by lazy {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ MediaStore.Audio.Media.getContentUri(
+ MediaStore.VOLUME_EXTERNAL_PRIMARY
+ )
+ } else {
+ MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
+ }
+ }
+
+ val albumArtCollection: Uri by lazy {
+ // This path is not well documented
+ // https://android.googlesource.com/platform/packages/providers/
+ // MediaProvider/+/refs/tags/android-platform-11.0.0_r5/
+ // src/com/android/providers/media/MediaProvider.java#7596
+
+ Uri.parse(collection.toString().replaceAfterLast("/", "albumart"))
+ }
+
+ fun saveInMediaStore(downloadFile: DownloadFile) {
+ val song = downloadFile.song
+ val songFile = downloadFile.completeFile
+
+ // Delete existing row in case the song has been downloaded before.
+ deleteFromMediaStore(downloadFile)
+ val contentResolver = context.contentResolver
+ val values = ContentValues()
+ values.put(MediaStore.MediaColumns.TITLE, song.title)
+ values.put(MediaStore.Audio.AudioColumns.ARTIST, song.artist)
+ values.put(MediaStore.Audio.AudioColumns.ALBUM, song.album)
+ values.put(MediaStore.Audio.AudioColumns.TRACK, song.track)
+ values.put(MediaStore.Audio.AudioColumns.YEAR, song.year)
+ values.put(MediaStore.MediaColumns.DATA, songFile.absolutePath)
+ values.put(MediaStore.MediaColumns.MIME_TYPE, song.contentType)
+ values.put(MediaStore.Audio.AudioColumns.IS_MUSIC, 1)
+
+ val uri = contentResolver.insert(collection, values)
+
+ if (uri != null) {
+ // Look up album, and add cover art if found.
+ val cursor = contentResolver.query(
+ uri, arrayOf(MediaStore.Audio.AudioColumns.ALBUM_ID),
+ null, null, null
+ )
+ if (cursor != null && cursor.moveToFirst()) {
+ val albumId = cursor.getInt(0)
+ insertAlbumArt(albumId, downloadFile)
+ cursor.close()
+ }
+ }
+ }
+
+ fun deleteFromMediaStore(downloadFile: DownloadFile) {
+ val contentResolver = context.contentResolver
+ val song = downloadFile.song
+ val file = downloadFile.completeFile
+
+ val selection = MediaStore.Audio.AudioColumns.TITLE_KEY + "=? AND " +
+ MediaStore.MediaColumns.DATA + "=?"
+ val selectionArgs = arrayOf(MediaStore.Audio.keyFor(song.title), file.absolutePath)
+
+ val res = contentResolver.delete(collection, selection, selectionArgs)
+
+ if (res > 0) {
+ Timber.i("Deleting media store row for %s", song)
+ }
+ }
+
+ private fun insertAlbumArt(albumId: Int, downloadFile: DownloadFile) {
+ val contentResolver = context.contentResolver
+ val uri = Uri.withAppendedPath(albumArtCollection, albumId.toString())
+ ?: return
+ val cursor = contentResolver.query(uri, null, null, null, null)
+ if (cursor != null && !cursor.moveToFirst()) {
+ // No album art found, add it.
+ val albumArtFile = FileUtil.getAlbumArtFile(context, downloadFile.song)
+ if (albumArtFile.exists()) {
+ val values = ContentValues()
+ values.put(MediaStore.Audio.AlbumColumns.ALBUM_ID, albumId)
+ // values.put(MediaStore.MediaColumns.DATA, albumArtFile.path)
+ contentResolver.insert(albumArtCollection, values)
+ Timber.i("Added album art: %s", albumArtFile)
+ }
+ cursor.close()
+ }
+ }
+}
diff --git a/ultrasonic/src/main/res/values-cs/strings.xml b/ultrasonic/src/main/res/values-cs/strings.xml
index ccb89929..6c4deb3a 100644
--- a/ultrasonic/src/main/res/values-cs/strings.xml
+++ b/ultrasonic/src/main/res/values-cs/strings.xml
@@ -382,8 +382,6 @@
Zobrazit všechny skladby umělce
Přidat nový zápis v náhledu umělců pro přístup ke všem skladbám umělce
Zobrazit umělce
- Skenovat média po stažení
- Automaticky skenovat médi po jejich stažení
Počet vláken stahování obrázků
1
2
diff --git a/ultrasonic/src/main/res/values-de/strings.xml b/ultrasonic/src/main/res/values-de/strings.xml
index a115cf54..7ad86fe0 100644
--- a/ultrasonic/src/main/res/values-de/strings.xml
+++ b/ultrasonic/src/main/res/values-de/strings.xml
@@ -379,8 +379,6 @@
Alle Titel nach Künstler sortieren
Einen neuen Eintrag in der Künstleransicht hinzufügen, um auf alle Lieder eines Künstlers zuzugreifen
Künstler zeigen
- Medien nach Download durchsuchen
- Medien nach dem Herunterladen automatisch durchsuchen
Paralleles laden von Bildern
1
2
diff --git a/ultrasonic/src/main/res/values-es/strings.xml b/ultrasonic/src/main/res/values-es/strings.xml
index b2f2073d..32f368f1 100644
--- a/ultrasonic/src/main/res/values-es/strings.xml
+++ b/ultrasonic/src/main/res/values-es/strings.xml
@@ -384,8 +384,6 @@
Mostrar todas las canciones por artista
Añadir nueva entrada en la vista de artista para acceder a todas las canciones de un artista
Mostrar artista
- Escanear medio después de descargar
- Escanear automáticamente el medio después de descargar
Concurrencia del cargador de imágenes
1
2
diff --git a/ultrasonic/src/main/res/values-fr/strings.xml b/ultrasonic/src/main/res/values-fr/strings.xml
index 628e3a20..7d5451ab 100644
--- a/ultrasonic/src/main/res/values-fr/strings.xml
+++ b/ultrasonic/src/main/res/values-fr/strings.xml
@@ -384,8 +384,6 @@
Voir toutes les titres par artiste
Ajouter une nouvelle entrée de l\'affichage de l\'artiste pour accéder à toutes les titres pour un artiste
Afficher l\'artiste
- Scan Media After Download
- Balayer automatiquement les médias après téléchargement
Chargements d’images simultanés
1
2
diff --git a/ultrasonic/src/main/res/values-hu/strings.xml b/ultrasonic/src/main/res/values-hu/strings.xml
index 59c63f62..f937486e 100644
--- a/ultrasonic/src/main/res/values-hu/strings.xml
+++ b/ultrasonic/src/main/res/values-hu/strings.xml
@@ -383,8 +383,6 @@
Az előadó összes dalának megjelenítése
Új bejegyzés hozzáadása az előadóhoz, az előadó összes dalának eléréséhez.
Ugrás az előadóhoz
- Scan Media After Download
- Automatically scan media after download
Image Loader Concurrency
1
2
diff --git a/ultrasonic/src/main/res/values-nl/strings.xml b/ultrasonic/src/main/res/values-nl/strings.xml
index ac9180f7..30e2fd6a 100644
--- a/ultrasonic/src/main/res/values-nl/strings.xml
+++ b/ultrasonic/src/main/res/values-nl/strings.xml
@@ -384,8 +384,6 @@
Alle nummers van artiest tonen
Item toevoegen in artiestweergave om alle nummers van een artiest te bekijken
Artiest tonen
- Media scannen na downloaden
- Media automatisch scannen na downloaden
Aantal tegelijkertijd te laden afbeeldingen
1
2
diff --git a/ultrasonic/src/main/res/values-pl/strings.xml b/ultrasonic/src/main/res/values-pl/strings.xml
index 094ed7be..4e0046f3 100644
--- a/ultrasonic/src/main/res/values-pl/strings.xml
+++ b/ultrasonic/src/main/res/values-pl/strings.xml
@@ -379,8 +379,6 @@ ponieważ api Subsonic nie wspiera nowego sposobu autoryzacji dla użytkowników
Wyświetlaj wszystkie utwory artysty
Dodaje nową pozycję w widoku artysty z wszystkimi jego utworami
Wyświetlaj artystę
- Skanuj media po pobraniu
- Automatycznie uruchamia skanowanie mediów po pobraniu
Ilość jednocześnie ładowanych obrazów
1
2
diff --git a/ultrasonic/src/main/res/values-pt-rBR/strings.xml b/ultrasonic/src/main/res/values-pt-rBR/strings.xml
index b2fe9f00..1d58e96c 100644
--- a/ultrasonic/src/main/res/values-pt-rBR/strings.xml
+++ b/ultrasonic/src/main/res/values-pt-rBR/strings.xml
@@ -384,8 +384,6 @@
Mostrar Todas as Músicas por Artista
Adicionar nova entrada em artista para acessar todas as músicas do artista
Mostrar Artista
- Escanear Música no Download
- Automaticamente escaneia música após o download
Concorrência ao Carregar Imagens
1
2
diff --git a/ultrasonic/src/main/res/values-pt/strings.xml b/ultrasonic/src/main/res/values-pt/strings.xml
index 9a6b346e..e23471fb 100644
--- a/ultrasonic/src/main/res/values-pt/strings.xml
+++ b/ultrasonic/src/main/res/values-pt/strings.xml
@@ -379,8 +379,6 @@
Todas as Músicas do Artista
Adicionar nova entrada em artista para ver todas as músicas do artista
Mostrar Artista
- Varrer Música no Download
- Automaticamente varre música após baixar
Concorrência ao Carregar Imagens
1
2
diff --git a/ultrasonic/src/main/res/values-ru/strings.xml b/ultrasonic/src/main/res/values-ru/strings.xml
index 3d756fcf..50d56c88 100644
--- a/ultrasonic/src/main/res/values-ru/strings.xml
+++ b/ultrasonic/src/main/res/values-ru/strings.xml
@@ -371,8 +371,6 @@
Показать все треки исполнителя
Добавить новую запись в представлении исполнителя, чтобы получить доступ ко всем песням для исполнителя
Показать исполнителей
- Сканировать носители после загрузки
- Автомат
Загрузчик совпадающих изображений
1
2
diff --git a/ultrasonic/src/main/res/values/strings.xml b/ultrasonic/src/main/res/values/strings.xml
index 019cc0cd..4da395e3 100644
--- a/ultrasonic/src/main/res/values/strings.xml
+++ b/ultrasonic/src/main/res/values/strings.xml
@@ -386,8 +386,6 @@
Show All Songs By Artist
Add new entry in artist view to access all songs for an artist
Show Artist
- Scan Media After Download
- Automatically scan media after download
Image Loader Concurrency
1
2
diff --git a/ultrasonic/src/main/res/xml/settings.xml b/ultrasonic/src/main/res/xml/settings.xml
index d6edcc0d..716eb2f2 100644
--- a/ultrasonic/src/main/res/xml/settings.xml
+++ b/ultrasonic/src/main/res/xml/settings.xml
@@ -118,12 +118,6 @@
a:summary="@string/settings.clear_bookmark_summary"
a:title="@string/settings.clear_bookmark"
app:iconSpaceReserved="false"/>
-