Merge branch 'develop' into remove-version
This commit is contained in:
commit
bedbad658f
|
@ -10,7 +10,7 @@ ext.versions = [
|
|||
ktlint : "0.37.1",
|
||||
ktlintGradle : "9.2.1",
|
||||
detekt : "1.16.0",
|
||||
jacoco : "0.8.5",
|
||||
jacoco : "0.8.7",
|
||||
preferences : "1.1.1",
|
||||
media : "1.3.0",
|
||||
|
||||
|
@ -33,13 +33,13 @@ ext.versions = [
|
|||
|
||||
junit4 : "4.12",
|
||||
junit5 : "5.3.1",
|
||||
mockito : "3.5.5",
|
||||
mockito : "3.8.0",
|
||||
mockitoKotlin : "1.5.0",
|
||||
kluent : "1.35",
|
||||
apacheCodecs : "1.10",
|
||||
testRunner : "1.0.1",
|
||||
robolectric : "4.4",
|
||||
dexter : "6.1.2",
|
||||
robolectric : "4.5.1",
|
||||
dexter : "6.2.2",
|
||||
timber : "4.7.1",
|
||||
fastScroll : "2.0.1",
|
||||
]
|
||||
|
|
|
@ -447,6 +447,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||
sharingDefaultExpiration.setSummary(sharingDefaultExpiration.getText());
|
||||
sharingDefaultDescription.setSummary(sharingDefaultDescription.getText());
|
||||
sharingDefaultGreeting.setSummary(sharingDefaultGreeting.getText());
|
||||
cacheLocation.setSummary(settings.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION,
|
||||
FileUtil.getDefaultMusicDirectory(getActivity()).getPath()));
|
||||
|
||||
if (!mediaButtonsEnabled.isChecked()) {
|
||||
lockScreenEnabled.setChecked(false);
|
||||
|
|
|
@ -188,6 +188,7 @@ public class Downloader
|
|||
DownloadFile downloadFile = backgroundDownloadList.get(i);
|
||||
if (downloadFile.isWorkDone() && (!downloadFile.shouldSave() || downloadFile.isSaved()))
|
||||
{
|
||||
Util.scanMedia(context, downloadFile.getCompleteFile());
|
||||
|
||||
// Don't need to keep list like active song list
|
||||
backgroundDownloadList.remove(i);
|
||||
|
|
|
@ -33,6 +33,7 @@ import android.graphics.drawable.BitmapDrawable;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
|
@ -1323,6 +1324,12 @@ public class Util
|
|||
return preferences.getBoolean(Constants.PREFERENCES_KEY_SHOW_ALL_SONGS_BY_ARTIST, 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)
|
||||
{
|
||||
|
|
|
@ -42,7 +42,6 @@ class DownloadFile(
|
|||
val partialFile: File
|
||||
val completeFile: File
|
||||
private val saveFile: File = FileUtil.getSongFile(context, song)
|
||||
private val mediaStoreService: MediaStoreService
|
||||
private var downloadTask: CancellableTask? = null
|
||||
var isFailed = false
|
||||
private var retryCount = MAX_RETRIES
|
||||
|
@ -65,7 +64,6 @@ class DownloadFile(
|
|||
init {
|
||||
partialFile = File(saveFile.parent, FileUtil.getPartialFile(saveFile.name))
|
||||
completeFile = File(saveFile.parent, FileUtil.getCompleteFile(saveFile.name))
|
||||
mediaStoreService = MediaStoreService(context)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,7 +135,8 @@ class DownloadFile(
|
|||
Util.delete(partialFile)
|
||||
Util.delete(completeFile)
|
||||
Util.delete(saveFile)
|
||||
mediaStoreService.deleteFromMediaStore(this)
|
||||
|
||||
Util.scanMedia(context, saveFile)
|
||||
}
|
||||
|
||||
fun unpin() {
|
||||
|
@ -185,7 +184,7 @@ class DownloadFile(
|
|||
} else if (completeWhenDone) {
|
||||
if (save) {
|
||||
Util.renameFile(partialFile, saveFile)
|
||||
mediaStoreService.saveInMediaStore(this@DownloadFile)
|
||||
Util.scanMedia(context, saveFile)
|
||||
} else {
|
||||
Util.renameFile(partialFile, completeFile)
|
||||
}
|
||||
|
@ -282,7 +281,7 @@ class DownloadFile(
|
|||
} else {
|
||||
if (save) {
|
||||
Util.renameFile(partialFile, saveFile)
|
||||
mediaStoreService.saveInMediaStore(this@DownloadFile)
|
||||
Util.scanMedia(context, saveFile)
|
||||
} else {
|
||||
Util.renameFile(partialFile, completeFile)
|
||||
}
|
||||
|
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
* 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()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue