2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2013-10-22 15:11:31 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2014-01-22 18:03:44 +00:00
|
|
|
local ButtonDialog = require("ui/widget/buttondialog")
|
2014-08-14 11:49:42 +00:00
|
|
|
local lfs = require("libs/libkoreader-lfs")
|
2015-10-03 06:18:47 +00:00
|
|
|
local DataStorage = require("datastorage")
|
2013-10-18 20:38:07 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local DocSettings = require("docsettings")
|
2014-08-14 11:49:42 +00:00
|
|
|
local Menu = require("ui/widget/menu")
|
2016-02-14 21:47:36 +00:00
|
|
|
local joinPath = require("ffi/util").joinPath
|
2014-10-30 18:42:18 +00:00
|
|
|
local Screen = require("device").screen
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
|
|
|
|
2016-02-14 21:47:36 +00:00
|
|
|
local history_dir = DataStorage:getHistoryDir()
|
2014-01-22 18:03:44 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local FileManagerHistory = InputContainer:extend{
|
2014-03-13 13:52:43 +00:00
|
|
|
hist_menu_title = _("History"),
|
2013-08-14 09:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function FileManagerHistory:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
2013-08-14 09:29:05 +00:00
|
|
|
end
|
|
|
|
|
2016-02-17 07:10:23 +00:00
|
|
|
function FileManagerHistory:addToMainMenu(tab_item_table)
|
|
|
|
-- insert table to info tab of filemanager menu
|
|
|
|
table.insert(tab_item_table.info, {
|
|
|
|
text = self.hist_menu_title,
|
|
|
|
callback = function()
|
|
|
|
self:onShowHist()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:updateItemTable()
|
|
|
|
local ReaderUI = require("apps/reader/readerui")
|
|
|
|
self.hist = {}
|
|
|
|
|
|
|
|
for f in lfs.dir(history_dir) do
|
|
|
|
local path = joinPath(history_dir, f)
|
|
|
|
if lfs.attributes(path, "mode") == "file" then
|
|
|
|
local name = DocSettings:getNameFromHistory(f)
|
|
|
|
table.insert(self.hist, {
|
|
|
|
date = lfs.attributes(path, "modification"),
|
|
|
|
text = name,
|
|
|
|
histfile = f,
|
|
|
|
callback = function()
|
|
|
|
ReaderUI:showReader(
|
|
|
|
DocSettings:getPathFromHistory(f).. "/" .. name)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.sort(self.hist, function(v1, v2) return v1.date > v2.date end)
|
|
|
|
|
|
|
|
self.hist_menu:swithItemTable(self.hist_menu_title, self.hist)
|
|
|
|
end
|
|
|
|
|
2013-08-14 09:29:05 +00:00
|
|
|
function FileManagerHistory:onSetDimensions(dimen)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dimen = dimen
|
2013-08-14 09:29:05 +00:00
|
|
|
end
|
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
function FileManagerHistory:onMenuHold(item)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.histfile_dialog = ButtonDialog:new{
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
2014-11-16 14:54:47 +00:00
|
|
|
text = _("Remove this item from history"),
|
2014-03-13 13:52:43 +00:00
|
|
|
callback = function()
|
2016-02-14 21:47:36 +00:00
|
|
|
os.remove(joinPath(history_dir, item.histfile))
|
2014-03-13 13:52:43 +00:00
|
|
|
self._manager:updateItemTable()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
UIManager:show(self.histfile_dialog)
|
|
|
|
return true
|
2014-01-22 18:03:44 +00:00
|
|
|
end
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
function FileManagerHistory:onShowHist()
|
2014-03-13 13:52:43 +00:00
|
|
|
local menu_container = CenterContainer:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
}
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.hist_menu = Menu:new{
|
|
|
|
ui = self.ui,
|
|
|
|
width = Screen:getWidth()-50,
|
|
|
|
height = Screen:getHeight()-50,
|
|
|
|
show_parent = menu_container,
|
|
|
|
onMenuHold = self.onMenuHold,
|
|
|
|
_manager = self,
|
|
|
|
}
|
|
|
|
self:updateItemTable()
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
table.insert(menu_container, self.hist_menu)
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.hist_menu.close_callback = function()
|
|
|
|
UIManager:close(menu_container)
|
|
|
|
end
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:show(menu_container)
|
|
|
|
return true
|
2013-08-14 09:29:05 +00:00
|
|
|
end
|
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
return FileManagerHistory
|