Merge lp:~karni/ubuntuone-android-music/fix-mediastore-conflict into lp:ubuntuone-android-music

Proposed by Michał Karnicki on 2012-04-17
Status: Merged
Approved by: Chad Miller on 2012-04-17
Approved revision: 564
Merged at revision: 564
Proposed branch: lp:~karni/ubuntuone-android-music/fix-mediastore-conflict
Merge into: lp:ubuntuone-android-music
Diff against target: 82 lines (+20/-10)
2 files modified
src/net/sourceforge/subsonic/androidapp/service/MediaStoreService.java (+20/-9)
src/net/sourceforge/subsonic/androidapp/util/Util.java (+0/-1)
To merge this branch: bzr merge lp:~karni/ubuntuone-android-music/fix-mediastore-conflict
Reviewer Review Type Date Requested Status
Chad Miller (community) 2012-04-17 Approve on 2012-04-17
Review via email: mp+102315@code.launchpad.net

Description of the change

This branch defaults song year to 1 if it's equal to zero and adds a little safer code around cursor handling.

To post a comment you must log in.
564. By Michał Karnicki on 2012-04-17

Don't include YEAR rather than bogus value 1.

Chad Miller (cmiller) wrote :

Nice.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/net/sourceforge/subsonic/androidapp/service/MediaStoreService.java'
--- src/net/sourceforge/subsonic/androidapp/service/MediaStoreService.java 2010-11-30 13:36:58 +0000
+++ src/net/sourceforge/subsonic/androidapp/service/MediaStoreService.java 2012-04-17 14:46:18 +0000
@@ -20,6 +20,8 @@
2020
21import java.io.File;21import java.io.File;
2222
23import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
24import net.sourceforge.subsonic.androidapp.util.FileUtil;
23import android.content.ContentResolver;25import android.content.ContentResolver;
24import android.content.ContentValues;26import android.content.ContentValues;
25import android.content.Context;27import android.content.Context;
@@ -27,8 +29,6 @@
27import android.net.Uri;29import android.net.Uri;
28import android.provider.MediaStore;30import android.provider.MediaStore;
29import android.util.Log;31import android.util.Log;
30import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
31import net.sourceforge.subsonic.androidapp.util.FileUtil;
3232
33/**33/**
34 * @author Sindre Mehus34 * @author Sindre Mehus
@@ -57,20 +57,32 @@
57 values.put(MediaStore.Audio.AudioColumns.ARTIST, song.getArtist());57 values.put(MediaStore.Audio.AudioColumns.ARTIST, song.getArtist());
58 values.put(MediaStore.Audio.AudioColumns.ALBUM, song.getAlbum());58 values.put(MediaStore.Audio.AudioColumns.ALBUM, song.getAlbum());
59 values.put(MediaStore.Audio.AudioColumns.TRACK, song.getTrack());59 values.put(MediaStore.Audio.AudioColumns.TRACK, song.getTrack());
60 values.put(MediaStore.Audio.AudioColumns.YEAR, song.getYear());60 // Protect from failed SQLite constraint.
61 if (song.getYear() != 0) {
62 values.put(MediaStore.Audio.AudioColumns.YEAR, song.getYear());
63 }
61 values.put(MediaStore.MediaColumns.DATA, songFile.getAbsolutePath());64 values.put(MediaStore.MediaColumns.DATA, songFile.getAbsolutePath());
62 values.put(MediaStore.MediaColumns.MIME_TYPE, song.getContentType());65 values.put(MediaStore.MediaColumns.MIME_TYPE, song.getContentType());
63 values.put(MediaStore.Audio.AudioColumns.IS_MUSIC, 1);66 values.put(MediaStore.Audio.AudioColumns.IS_MUSIC, 1);
6467
65 Uri uri = contentResolver.insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values);68 Uri uri = contentResolver.insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values);
6669
70 if (uri == null) {
71 Log.w(TAG, "Audio MediaStore insert failed.");
72 return;
73 }
74
67 // Look up album, and add cover art if found.75 // Look up album, and add cover art if found.
68 Cursor cursor = contentResolver.query(uri, new String[]{MediaStore.Audio.AudioColumns.ALBUM_ID}, null, null, null);76 Cursor cursor = contentResolver.query(uri, new String[]{MediaStore.Audio.AudioColumns.ALBUM_ID}, null, null, null);
69 if (cursor.moveToFirst()) {77 try {
70 int albumId = cursor.getInt(0);78 if (cursor != null && cursor.moveToFirst()) {
71 insertAlbumArt(albumId, downloadFile);79 int albumId = cursor.getInt(0);
80 insertAlbumArt(albumId, downloadFile);
81 }
82 } finally {
83 if (cursor != null)
84 cursor.close();
72 }85 }
73 cursor.close();
74 }86 }
7587
76 public void deleteFromMediaStore(DownloadFile downloadFile) {88 public void deleteFromMediaStore(DownloadFile downloadFile) {
@@ -79,9 +91,8 @@
79 File file = downloadFile.getCompleteFile();91 File file = downloadFile.getCompleteFile();
8092
81 int n = contentResolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,93 int n = contentResolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
82 MediaStore.Audio.AudioColumns.TITLE_KEY + "=? AND " +
83 MediaStore.MediaColumns.DATA + "=?",94 MediaStore.MediaColumns.DATA + "=?",
84 new String[]{MediaStore.Audio.keyFor(song.getTitle()), file.getAbsolutePath()});95 new String[]{file.getAbsolutePath()});
85 if (n > 0) {96 if (n > 0) {
86 Log.i(TAG, "Deleting media store row for " + song);97 Log.i(TAG, "Deleting media store row for " + song);
87 }98 }
8899
=== modified file 'src/net/sourceforge/subsonic/androidapp/util/Util.java'
--- src/net/sourceforge/subsonic/androidapp/util/Util.java 2011-11-04 00:07:03 +0000
+++ src/net/sourceforge/subsonic/androidapp/util/Util.java 2012-04-17 14:46:18 +0000
@@ -56,7 +56,6 @@
56import android.content.DialogInterface;56import android.content.DialogInterface;
57import android.content.Intent;57import android.content.Intent;
58import android.content.SharedPreferences;58import android.content.SharedPreferences;
59import android.content.SharedPreferences.Editor;
60import android.content.pm.PackageInfo;59import android.content.pm.PackageInfo;
61import android.content.pm.PackageManager;60import android.content.pm.PackageManager;
62import android.content.res.Resources;61import android.content.res.Resources;

Subscribers

People subscribed via source and target branches

to status/vote changes: