Skip to content

Commit

Permalink
Improve sorting for Library
Browse files Browse the repository at this point in the history
Not perfect--month view is weird. But the year view is perfect!
  • Loading branch information
roygbyte committed May 7, 2023
1 parent 80699e8 commit f579e65
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion library.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local UIManager = require("ui/uimanager")
local util = require("util")
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local sort = require("sort")

local Puzzle = require("puzzle")

Expand Down Expand Up @@ -57,7 +58,6 @@ function Library:getFilesInDirectory(path_to_dir)
end

function Library:processDirectoryCallback(item)
logger.dbg(item)
if item.mode == "directory" then
self:showDirectoryView(("%s/%s"):format(item.path_to_dir, item.filename))
else
Expand All @@ -67,6 +67,11 @@ end

function Library:showDirectoryView(path_to_directory)
local directory_items = self:getFilesInDirectory(path_to_directory)

table.sort(directory_items, function(a, b)
local fn = sort.natsort_cmp()
return fn(a.title, b.title)
end)
local kv_pairs = {}
for key, item in ipairs(directory_items) do
table.insert(kv_pairs, {
Expand Down

0 comments on commit f579e65

Please sign in to comment.