History: show last read date instead of file size

In classic and list display modes.
reviewable/pr6595/r1
poire-z 4 years ago committed by Martín Fernández
parent bafc52afd1
commit cfa45f8d88

@ -83,6 +83,13 @@ function DocSettings:getNameFromHistory(hist_name)
return string.sub(hist_name, string.len(s)+2, -5) return string.sub(hist_name, string.len(s)+2, -5)
end end
function DocSettings:getLastSaveTime(doc_path)
local attr = lfs.attributes(self:getSidecarFile(doc_path))
if attr and attr.mode == "file" then
return attr.modification
end
end
function DocSettings:ensureSidecar(sidecar) function DocSettings:ensureSidecar(sidecar)
if lfs.attributes(sidecar, "mode") ~= "directory" then if lfs.attributes(sidecar, "mode") ~= "directory" then
lfs.mkdir(sidecar) lfs.mkdir(sidecar)

@ -2,7 +2,7 @@ local DataStorage = require("datastorage")
local DocSettings = require("docsettings") local DocSettings = require("docsettings")
local dump = require("dump") local dump = require("dump")
local ffiutil = require("ffi/util") local ffiutil = require("ffi/util")
local getFriendlySize = require("util").getFriendlySize local util = require("util")
local joinPath = ffiutil.joinPath local joinPath = ffiutil.joinPath
local lfs = require("libs/libkoreader-lfs") local lfs = require("libs/libkoreader-lfs")
local realpath = ffiutil.realpath local realpath = ffiutil.realpath
@ -15,13 +15,30 @@ local ReadHistory = {
} }
local function buildEntry(input_time, input_file) local function buildEntry(input_time, input_file)
local file_exists = lfs.attributes(input_file, "mode") == "file" local file_path = realpath(input_file) or input_file -- keep orig file path of deleted files
local file_exists = lfs.attributes(file_path, "mode") == "file"
return { return {
time = input_time, time = input_time,
text = input_file:gsub(".*/", ""), text = input_file:gsub(".*/", ""),
file = realpath(input_file) or input_file, -- keep orig file path of deleted files file = file_path,
dim = not file_exists, -- "dim", as expected by Menu dim = not file_exists, -- "dim", as expected by Menu
mandatory = file_exists and getFriendlySize(lfs.attributes(input_file, "size") or 0), -- mandatory = file_exists and require("util").getFriendlySize(lfs.attributes(input_file, "size") or 0),
mandatory_func = function() -- Show the last read time (rather than file size)
local readerui_instance = require("apps/reader/readerui"):_getRunningInstance()
local currently_opened_file = readerui_instance and readerui_instance.document.file
local last_read_ts
if file_path == currently_opened_file then
-- Don't use the sidecar file date which is updated regularly while
-- reading: keep showing the opening time for the current document.
last_read_ts = input_time
else
-- For past documents, the last save time of the settings is better
-- as last read time than input_time (its last opening time, that
-- we fallback to it no sidecar file)
last_read_ts = DocSettings:getLastSaveTime(file_path) or input_time
end
return util.secondsToDate(last_read_ts, G_reader_settings:nilOrTrue("twelve_hour_clock"))
end,
callback = function() callback = function()
local ReaderUI = require("apps/reader/readerui") local ReaderUI = require("apps/reader/readerui")
ReaderUI:showReader(input_file) ReaderUI:showReader(input_file)

@ -236,12 +236,13 @@ function MenuItem:init()
-- Padding before mandatory -- Padding before mandatory
local text_mandatory_padding = 0 local text_mandatory_padding = 0
local text_ellipsis_mandatory_padding = 0 local text_ellipsis_mandatory_padding = 0
if self.mandatory then local mandatory = self.mandatory_func and self.mandatory_func() or self.mandatory
if mandatory then
text_mandatory_padding = Size.span.horizontal_default text_mandatory_padding = Size.span.horizontal_default
-- Smaller padding when ellipsis for better visual feeling -- Smaller padding when ellipsis for better visual feeling
text_ellipsis_mandatory_padding = Size.span.horizontal_small text_ellipsis_mandatory_padding = Size.span.horizontal_small
end end
local mandatory = self.mandatory and ""..self.mandatory or "" mandatory = mandatory and ""..mandatory or ""
local mandatory_widget = TextWidget:new{ local mandatory_widget = TextWidget:new{
text = mandatory, text = mandatory,
face = self.info_face, face = self.info_face,
@ -1014,6 +1015,7 @@ function Menu:updateItems(select_number)
text = Menu.getMenuText(self.item_table[i]), text = Menu.getMenuText(self.item_table[i]),
bidi_wrap_func = self.item_table[i].bidi_wrap_func, bidi_wrap_func = self.item_table[i].bidi_wrap_func,
mandatory = self.item_table[i].mandatory, mandatory = self.item_table[i].mandatory,
mandatory_func = self.item_table[i].mandatory_func,
bold = self.item_table.current == i or self.item_table[i].bold == true, bold = self.item_table.current == i or self.item_table[i].bold == true,
dim = self.item_table[i].dim, dim = self.item_table[i].dim,
font = "smallinfofont", font = "smallinfofont",

@ -224,7 +224,7 @@ function ListMenuItem:update()
self.is_directory = true self.is_directory = true
-- nb items on the right, directory name on the left -- nb items on the right, directory name on the left
local wright = TextWidget:new{ local wright = TextWidget:new{
text = self.mandatory, text = self.mandatory_func and self.mandatory_func() or self.mandatory,
face = Font:getFace("infont", math.min(max_fontsize_fileinfo, _fontSize(15))), face = Font:getFace("infont", math.min(max_fontsize_fileinfo, _fontSize(15))),
} }
local pad_width = Screen:scaleBySize(10) -- on the left, in between, and on the right local pad_width = Screen:scaleBySize(10) -- on the left, in between, and on the right
@ -357,15 +357,23 @@ function ListMenuItem:update()
-- pages read / nb of pages (not available for crengine doc not opened) -- pages read / nb of pages (not available for crengine doc not opened)
local directory, filename = util.splitFilePathName(self.filepath) -- luacheck: no unused local directory, filename = util.splitFilePathName(self.filepath) -- luacheck: no unused
local filename_without_suffix, filetype = util.splitFileNameSuffix(filename) local filename_without_suffix, filetype = util.splitFileNameSuffix(filename)
local fileinfo_str = filetype local fileinfo_str
if self.mandatory then if self.mandatory_func then
fileinfo_str = self.mandatory .. " " .. BD.wrap(fileinfo_str) -- Currently only provided by History, giving the last time read.
end -- Just show this date, without the file extension
if bookinfo._no_provider then fileinfo_str = self.mandatory_func()
-- for unspported files: don't show extension on the right, else
-- keep it in filename if self.mandatory then
filename_without_suffix = filename fileinfo_str = BD.wrap(self.mandatory) .. " " .. BD.wrap(filetype)
fileinfo_str = self.mandatory else
fileinfo_str = filetype
end
if bookinfo._no_provider then
-- for unspported files: don't show extension on the right,
-- keep it in filename
filename_without_suffix = filename
fileinfo_str = self.mandatory
end
end end
-- Current page / pages are available or more accurate in .sdr/metadata.lua -- Current page / pages are available or more accurate in .sdr/metadata.lua
-- We use a cache (cleaned at end of this browsing session) to store -- We use a cache (cleaned at end of this browsing session) to store
@ -949,6 +957,7 @@ function ListMenu:_updateItemsBuildUI()
text = getMenuText(entry), text = getMenuText(entry),
show_parent = self.show_parent, show_parent = self.show_parent,
mandatory = entry.mandatory, mandatory = entry.mandatory,
mandatory_func = entry.mandatory_func,
dimen = self.item_dimen:new(), dimen = self.item_dimen:new(),
shortcut = item_shortcut, shortcut = item_shortcut,
shortcut_style = shortcut_style, shortcut_style = shortcut_style,

Loading…
Cancel
Save