aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-08-04 18:55:45 -0700
committerScott Jackson <daneren2005@gmail.com>2012-08-04 18:55:45 -0700
commitb0d38681e05a6fea987b7fe30290cc574b235a67 (patch)
tree7149f8ee6d5bbabb39337eba89472f1ddd25689c /subsonic-android/src/github
parentb59dde7ba0e2d975c59d88b8616ccad8f21a9790 (diff)
downloaddsub-b0d38681e05a6fea987b7fe30290cc574b235a67.tar.gz
dsub-b0d38681e05a6fea987b7fe30290cc574b235a67.tar.bz2
dsub-b0d38681e05a6fea987b7fe30290cc574b235a67.zip
Added offline search
Diffstat (limited to 'subsonic-android/src/github')
-rw-r--r--subsonic-android/src/github/daneren2005/subphonic/service/OfflineMusicService.java49
1 files changed, 48 insertions, 1 deletions
diff --git a/subsonic-android/src/github/daneren2005/subphonic/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/subphonic/service/OfflineMusicService.java
index 0b79e02d..52955ca4 100644
--- a/subsonic-android/src/github/daneren2005/subphonic/service/OfflineMusicService.java
+++ b/subsonic-android/src/github/daneren2005/subphonic/service/OfflineMusicService.java
@@ -148,8 +148,55 @@ public class OfflineMusicService extends RESTMusicService {
@Override
public SearchResult search(SearchCritera criteria, Context context, ProgressListener progressListener) throws Exception {
- throw new OfflineException("Search not available in offline mode");
+ List<Artist> artists = new ArrayList<Artist>();
+ List<MusicDirectory.Entry> albums = new ArrayList<MusicDirectory.Entry>();
+ List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>();
+ File root = FileUtil.getMusicDirectory(context);
+ for (File artistFile : FileUtil.listFiles(root)) {
+ String artistName = artistFile.getName();
+ if (artistFile.isDirectory()) {
+ if(matchCriteria(criteria, artistName)) {
+ Artist artist = new Artist();
+ artist.setId(artistFile.getPath());
+ artist.setIndex(artistFile.getName().substring(0, 1));
+ artist.setName(artistFile.getName());
+ artists.add(artist);
+ }
+
+ for(File albumFile : FileUtil.listMusicFiles(artistFile)) {
+ if(albumFile.isDirectory()) {
+ String albumName = getName(albumFile);
+ if(matchCriteria(criteria, albumName)) {
+ albums.add(createEntry(context, albumFile, albumName));
+ }
+
+ for(File songFile : FileUtil.listMusicFiles(albumFile)) {
+ String songName = getName(songFile);
+ if(matchCriteria(criteria, songName)) {
+ songs.add(createEntry(context, albumFile, songName));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return new SearchResult(artists, albums, songs);
}
+
+ private boolean matchCriteria(SearchCritera criteria, String name) {
+ String query = criteria.getQuery().toLowerCase();
+ String[] parts = query.split(" ");
+ name = name.toLowerCase();
+
+ for(String part : parts) {
+ if(name.indexOf(part) != -1) {
+ return true;
+ }
+ }
+
+ return false;
+ }
@Override
public List<Playlist> getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception {