It now be smart enough to redownload history items that went poof

pull/9943/head
Scarlett 1 year ago
parent 273f869622
commit e8ea6cea53

@ -25,7 +25,7 @@ end
function History:add(url, download_path)
-- Add to the history by pushing to the first element of the list.
-- The history stack should only contain one entry of a given ID.
local stack = self.lua_settings:readSetting(History.STACK) or {}
local stack = self:get()
-- Add the new entry to the stack table.
table.insert(stack, {
url = url,
@ -55,11 +55,42 @@ function History:add(url, download_path)
self.lua_settings:flush()
end
-- Remove all instances of the given URL from history.
function History:remove(url)
local stack = self:get()
local new_stack = {}
for i, value in ipairs(stack) do
logger.dbg(value)
if value.url ~= url then
logger.dbg("lol")
table.insert(new_stack, value)
end
end
self.lua_settings:saveSetting(History.STACK, new_stack)
self.lua_settings:flush()
end
function History:get()
local stack = self.lua_settings:readSetting(History.STACK) or {}
return stack
end
function History:find(v)
local stack = self:get()
local maybe_found = nil
for i, value in ipairs(stack) do
if value.url == v or
value.download_path == v then
maybe_found = value
break;
end
end
return maybe_found
end
function History:save()
end

@ -109,12 +109,8 @@ function DownloadToEpub:maybeOpenEpub(file_path)
local ReaderUI = require("apps/reader/readerui")
ReaderUI:showReader(file_path)
else
logger.dbg("DownloadToEpub: Couldn't open EPUB! File has been moved since downloaded to " .. file_path)
UIManager:show(InfoMessage:new{
text = _("Couldn't open! EPUB has been deleted or moved since being downloaded."),
show_icon = false,
timeout = 10,
})
logger.dbg("DownloadToEpub: Couldn't open " .. file_path .. ". It's been moved or deleted.")
self:showRedownloadPrompt(file_path)
end
end
@ -170,6 +166,9 @@ function DownloadToEpub:onDownloadEpubFromUrl(link_url)
else
local history = History:new{}
history:init()
logger.dbg("DownloadToEpub: Maybe deleting from history " .. link_url)
history:remove(link_url) -- link might have already been downloaded. If so, remove the history item.
logger.dbg("DownloadToEpub: Adding to history " .. link_url)
history:add(link_url, file_path)
logger.dbg("DownloadToEpub: Finished downloading epub to " .. file_path)
self:showReadPrompt(_("EPUB downloaded. Would you like to read it now?"), file_path)
@ -191,6 +190,41 @@ function DownloadToEpub:downloadEpubWithUi(link_url, callback)
end)
end
function DownloadToEpub:showRedownloadPrompt(file_path) -- supply this with a directory?
local prompt
local history = History:new{}
history:init()
local history_item = history:find(file_path)
if history_item then
prompt = MultiConfirmBox:new{
text = T(_("Couldn't open EPUB! \n\nFile has been moved since download (%1)\n\nInitially downloaded from (%2)\n\nWhat would you like to do?"),
file_path,
history_item.url),
choice1_text = _("Redownload EPUB"),
choice1_callback = function()
logger.dbg("DownloadToEpub: Redownloading " .. history_item.url)
self:onDownloadEpubFromUrl(history_item.url)
UIManager:close(prompt)
end,
choice2_text = _("Delete from history"),
choice2_callback = function()
logger.dbg("DownloadToEpub: Deleting from history " .. history_item.url)
history:remove(history_item.url)
UIManager:close(prompt)
end,
}
else
prompt = InfoMessage:new{
text = _("Couldn't open EPUB! EPUB has been deleted or moved since being downloaded."),
show_icon = false,
timeout = 10,
}
end
UIManager:show(prompt)
end
function DownloadToEpub:showReadPrompt(message, file_path)
local prompt = MultiConfirmBox:new{
text = message,
@ -245,6 +279,7 @@ function EpubBuilder:buildFromUrl(url)
end
self.Trapper:info("Writing to device...")
logger.dbg("DownloadToEpub: Writing EPUB to " .. epub_path)
local path_to_epub, err = build_director:construct(epub)
if not path_to_epub then
logger.dbg("DownloadToEpub: " .. err)

Loading…
Cancel
Save