From e3b878e69b56abafefff9518bcdd373bcc994566 Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Mon, 22 Oct 2018 20:34:32 +0200 Subject: [PATCH] fix loading of unindexed files via dispatch. This is so brittle but the best thing we have - thanks to this patch, it even starts to work (again). --- .../android/vanilla/SongTimeline.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/SongTimeline.java b/app/src/main/java/ch/blinkenlights/android/vanilla/SongTimeline.java index 918f114a..0cb28a85 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/SongTimeline.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/SongTimeline.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2012 Christopher Eby - * Copyright (C) 2015-2017 Adrian Ulrich + * Copyright (C) 2015-2018 Adrian Ulrich * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -750,13 +750,19 @@ public final class SongTimeline { if (count == 0 && type == MediaUtils.TYPE_FILE && query.selectionArgs.length == 1) { // This seems to be a simple file query which lead to no results. - // Assume that this was a LIKE query for an unindexed file, so drop the '%' char - // at the end and return a fileCursor for it. + // The file might just be unindexed, so try to return a file cursor: String pathQuery = query.selectionArgs[0]; - pathQuery = pathQuery.substring(0,pathQuery.length()-1); - cursor.close(); // close old version - cursor = MediaUtils.getCursorForFileQuery(pathQuery); - count = cursor.getCount(); + int len = pathQuery.length(); + if (len > 0) { + String lastchar = pathQuery.substring(len-1); + if (lastchar.equals("%")) { + pathQuery = pathQuery.substring(0, len-1); + } + + cursor.close(); // close old version + cursor = MediaUtils.getCursorForFileQuery(pathQuery); + count = cursor.getCount(); + } } if (count == 0) {