File view fixes (#379)

* Sort file lists by path and show filename/foldername in details
* rewrite diplay of file lists using java.io.File for platform independence. It also makes the code clearer by avoiding string acrobatics
* fix enqueue order of action_play_from_this_item
* remove java.io.File dependency again
instead add method getFilenameFromPath
* move playMediaFile to end of block
This commit is contained in:
Sebastian 2017-05-03 10:28:12 +02:00 committed by Synced Synapse
parent 1cb77876be
commit b42f6f8119
1 changed files with 33 additions and 5 deletions

View File

@ -323,7 +323,7 @@ public class MediaFileListFragment extends AbstractListFragment {
Files.GetDirectory action = new Files.GetDirectory(dir.file,
mediaType,
new ListType.Sort(ListType.Sort.SORT_METHOD_LABEL, true, true),
new ListType.Sort(ListType.Sort.SORT_METHOD_PATH, true, true),
properties);
action.execute(hostManager.getConnection(), new ApiCallback<List<ListType.ItemFile>>() {
@Override
@ -474,6 +474,27 @@ public class MediaFileListFragment extends AbstractListFragment {
return p;
}
/**
* return the filename of a given path, if path is a directory, return directory name
* @param path of the current file
* @return filename or directory name
*/
public static String getFilenameFromPath(final String path) {
String p = path;
String pathSymbol = "/"; // unix style
if (path.contains("\\")) {
pathSymbol = "\\"; // windows style
}
// if path ends with /, remove it
if (path.endsWith(pathSymbol)) {
p = path.substring(0, path.length() - 1);
}
if (p.lastIndexOf(pathSymbol) != -1) {
p = p.substring(p.lastIndexOf(pathSymbol)+1);
}
return p;
}
@Override
public void onRefresh() {
@ -511,15 +532,14 @@ public class MediaFileListFragment extends AbstractListFragment {
case R.id.action_play_from_this_item:
mediaQueueFileLocation.clear();
FileLocation fl;
// start playing the selected one, then queue the rest
mediaQueueFileLocation.add(loc);
for (int i = position + 1; i < fileLocationItems.size(); i++) {
fl = fileLocationItems.get(i);
if (!fl.isDirectory) {
mediaQueueFileLocation.add(fl);
}
}
// start playing the selected one, then queue the rest make sure to queue
// the selected on last so the it does not lose its place in the queue
mediaQueueFileLocation.add(loc);
playMediaFile(loc.file);
return true;
}
@ -717,9 +737,17 @@ public class MediaFileListFragment extends AbstractListFragment {
artUrl = itemFile.thumbnail;
break;
case ListType.ItemBase.TYPE_ALBUM:
title = itemFile.displayartist + " | " + itemFile.album;
details = getFilenameFromPath(itemFile.file);
artUrl = itemFile.thumbnail;
sizeDuration = (itemFile.size > 0) && (itemFile.duration > 0) ?
UIUtils.formatFileSize(itemFile.size) + " | " + UIUtils.formatTime(itemFile.duration) :
(itemFile.size > 0) ? UIUtils.formatFileSize(itemFile.size) :
(itemFile.duration > 0)? UIUtils.formatTime(itemFile.duration) : null;
break;
case ListType.ItemBase.TYPE_SONG:
title = itemFile.label;
details = itemFile.displayartist + " | " + itemFile.album;
details = getFilenameFromPath(itemFile.file);
artUrl = itemFile.thumbnail;
sizeDuration = (itemFile.size > 0) && (itemFile.duration > 0) ?
UIUtils.formatFileSize(itemFile.size) + " | " + UIUtils.formatTime(itemFile.duration) :