mirror of
https://github.com/koreader/koreader
synced 2024-10-31 21:20:20 +00:00
8a04dc9852
When this feature is enabled on a feed and that feed is synced, all new feed entries will be collected into a new single EPUB file. This is achieved by implementing a feed history feature (downloaded feeds are added as M5D hashes to a LuaSettings file), and by introducing additional methods into epubdownloader.lua that allow for multiple HTML documents to be added into single EPUB file.
230 lines
5.9 KiB
Lua
230 lines
5.9 KiB
Lua
local logger = require("logger")
|
|
local _ = require("gettext")
|
|
|
|
local FeedView = {
|
|
URL = "url",
|
|
LIMIT = "limit",
|
|
DOWNLOAD_FULL_ARTICLE = "download_full_article",
|
|
INCLUDE_IMAGES = "include_images",
|
|
ENABLE_FILTER = "enable_filter",
|
|
FILTER_ELEMENT = "filter_element",
|
|
VOLUMIZE = "volumize",
|
|
ACTION_RESET_HISTORY = "reset_history",
|
|
ACTION_DELETE_FEED = "delete_feed",
|
|
}
|
|
|
|
function FeedView:getList(feed_config, callback, edit_feed_attribute_callback, delete_feed_callback)
|
|
local view_content = {}
|
|
-- Loop through the feed.
|
|
for idx, feed in ipairs(feed_config) do
|
|
local feed_item_content = {}
|
|
|
|
local vc_feed_item = FeedView:getItem(
|
|
idx,
|
|
feed,
|
|
edit_feed_attribute_callback,
|
|
delete_feed_callback
|
|
)
|
|
|
|
if not vc_feed_item then
|
|
logger.warn('NewsDownloader: invalid feed config entry', feed)
|
|
else
|
|
feed_item_content = FeedView:flattenArray(feed_item_content, vc_feed_item)
|
|
local url = feed[1]
|
|
table.insert(
|
|
view_content,
|
|
{
|
|
url,
|
|
"",
|
|
callback = function()
|
|
-- Here is where we trigger the single feed item display
|
|
callback(feed_item_content)
|
|
end
|
|
}
|
|
)
|
|
-- Insert a divider.
|
|
table.insert(
|
|
view_content,
|
|
"---"
|
|
)
|
|
end
|
|
end
|
|
return view_content
|
|
end
|
|
|
|
function FeedView:getItem(id, feed, edit_feed_callback, feed_action_callback)
|
|
|
|
logger.dbg("NewsDownloader:", feed)
|
|
|
|
local url = feed[1]
|
|
local limit = feed.limit
|
|
|
|
-- If there's no URL or limit we don't care about this
|
|
-- because we can't use it.
|
|
if not url and limit then
|
|
return nil
|
|
end
|
|
|
|
-- Collect this stuff for later, with the single view.
|
|
local download_full_article = feed.download_full_article ~= false
|
|
local include_images = feed.include_images ~= false
|
|
local enable_filter = feed.enable_filter ~= false
|
|
local filter_element = feed.filter_element
|
|
local volumize = feed.volumize ~= false
|
|
|
|
local vc = {
|
|
{
|
|
_("URL"),
|
|
url,
|
|
callback = function()
|
|
edit_feed_callback(
|
|
id,
|
|
FeedView.URL,
|
|
url
|
|
)
|
|
end
|
|
},
|
|
{
|
|
_("Limit"),
|
|
limit,
|
|
callback = function()
|
|
edit_feed_callback(
|
|
id,
|
|
FeedView.LIMIT,
|
|
limit
|
|
)
|
|
end
|
|
},
|
|
{
|
|
_("Download full article"),
|
|
download_full_article,
|
|
callback = function()
|
|
edit_feed_callback(
|
|
id,
|
|
FeedView.DOWNLOAD_FULL_ARTICLE,
|
|
download_full_article
|
|
)
|
|
end
|
|
},
|
|
{
|
|
_("Include images"),
|
|
include_images,
|
|
callback = function()
|
|
edit_feed_callback(
|
|
id,
|
|
FeedView.INCLUDE_IMAGES,
|
|
include_images
|
|
)
|
|
end
|
|
},
|
|
{
|
|
_("Enable filter"),
|
|
enable_filter,
|
|
callback = function()
|
|
edit_feed_callback(
|
|
id,
|
|
FeedView.ENABLE_FILTER,
|
|
enable_filter
|
|
)
|
|
end
|
|
|
|
},
|
|
{
|
|
_("Filter element"),
|
|
filter_element,
|
|
callback = function()
|
|
edit_feed_callback(
|
|
id,
|
|
FeedView.FILTER_ELEMENT,
|
|
filter_element
|
|
)
|
|
end
|
|
},
|
|
{
|
|
_("Volumize feed"),
|
|
volumize,
|
|
callback = function()
|
|
edit_feed_callback(
|
|
id,
|
|
FeedView.VOLUMIZE,
|
|
volumize
|
|
)
|
|
end
|
|
},
|
|
}
|
|
|
|
-- These actions only pertain to initiated feeds, so we don't always
|
|
-- display them.
|
|
if feed_action_callback then
|
|
table.insert(
|
|
vc,
|
|
"---"
|
|
)
|
|
table.insert(
|
|
vc,
|
|
{
|
|
_("Delete feed"),
|
|
"",
|
|
callback = function()
|
|
feed_action_callback(
|
|
id,
|
|
FeedView.ACTION_DELETE_FEED
|
|
)
|
|
end
|
|
}
|
|
)
|
|
table.insert(
|
|
vc,
|
|
{
|
|
_("Reset feed history"),
|
|
"",
|
|
callback = function()
|
|
feed_action_callback(
|
|
url,
|
|
FeedView.ACTION_RESET_HISTORY
|
|
)
|
|
end
|
|
}
|
|
)
|
|
end
|
|
|
|
return vc
|
|
end
|
|
|
|
--
|
|
-- KeyValuePage doesn't like to get a table with sub tables.
|
|
-- This function flattens an array, moving all nested tables
|
|
-- up the food chain, so to speak
|
|
--
|
|
function FeedView:flattenArray(base_array, source_array)
|
|
for key, value in pairs(source_array) do
|
|
if value[2] == nil then
|
|
-- If the value is empty, then it's probably supposed to be a line
|
|
table.insert(
|
|
base_array,
|
|
"---"
|
|
)
|
|
else
|
|
if value["callback"] then
|
|
table.insert(
|
|
base_array,
|
|
{
|
|
value[1], value[2], callback = value["callback"]
|
|
}
|
|
)
|
|
else
|
|
table.insert(
|
|
base_array,
|
|
{
|
|
value[1], value[2]
|
|
}
|
|
)
|
|
end
|
|
end
|
|
end
|
|
return base_array
|
|
end
|
|
|
|
|
|
return FeedView
|