Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

searching for tracks considers the search pattern in filenames too #818

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,43 @@ protected void asyncUpdate() {
final String finalSearch = mSearchKeywords.toLowerCase();

List<Music> arrayMusic = null;
List<Music> arrayMusicFiles = null;

try {
arrayMusic = mApp.oMPDAsyncHelper.oMPD.search("any", finalSearch);
} catch (final IOException | MPDException e) {
Log.e(TAG, "MPD search failure.", e);

}

if (arrayMusic == null) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it returns here you don't get the chance to match the filename ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats right, but i thought arrayMusic is only null if an error occured (exception catched) and i don't wanted to do another search in that case. arrayMusic should be an empty list if nothing was found.

}

try {
arrayMusicFiles = mApp.oMPDAsyncHelper.oMPD.search("filename", finalSearch);
} catch (final IOException | MPDException e) {
Log.e(TAG, "MPD search failure.", e);
}
if (arrayMusicFiles == null) {
arrayMusicFiles = new ArrayList();
}

mArtistResults.clear();
mAlbumResults.clear();
mSongResults.clear();

String tmpValue;
boolean valueFound;
for (final Music music : arrayMusic) {
for (final Music fMusic : arrayMusicFiles) {
final String fMusicFullPath = fMusic.getFullPath();
if (fMusicFullPath != null &&
fMusicFullPath.equals(music.getFullPath())) {
arrayMusicFiles.remove(fMusic);
break;
}
}

if (music.getTitle() != null && music.getTitle().toLowerCase().contains(finalSearch)) {
mSongResults.add(music);
}
Expand Down Expand Up @@ -255,6 +273,10 @@ protected void asyncUpdate() {
}
}

for (final Music music : arrayMusicFiles) {
mSongResults.add(music);
}

Collections.sort(mArtistResults);
Collections.sort(mAlbumResults);
Collections.sort(mSongResults, Music.COMPARE_WITHOUT_TRACK_NUMBER);
Expand Down