Add HTML widget in GoodReads review (#3929)

pull/3930/head
Robert 6 years ago committed by Frans de Jonge
parent 9e67c5a614
commit 4bf4578d17

@ -88,28 +88,6 @@ function GoodreadsApi:getTotalResults()
return self.total_result return self.total_result
end end
local function cleanHTMLTags(str_html)
local cleaner = {
{ "&", "&" },
{ "—", "-" },
{ "’", "'" },
{ " ", " " },
{ "<!%[CDATA%[(.*)%]%]>", "%1" },
{ "<br%s/>", "\n" },
{ "%-%-", "%-" },
{ "</p>", "\n" },
{ "(%b<>)", "" },
{ "\n\n*", "\n" },
{ "\n*$", "" },
{ "^\n*", "" },
}
for i=1, #cleaner do
local cleans = cleaner[i]
str_html = string.gsub(str_html, cleans[1], cleans[2])
end
return str_html
end
local function showIdTable(data) local function showIdTable(data)
if data == nil then if data == nil then
UIManager:show(InfoMessage:new{text =_("Network problem.\nCheck connection.")}) UIManager:show(InfoMessage:new{text =_("Network problem.\nCheck connection.")})
@ -132,7 +110,8 @@ local function showIdTable(data)
local id = data1:match("<id>([^<]+)</id>"):gsub("<![[]CDATA[[]", ""):gsub("]]>$", "") local id = data1:match("<id>([^<]+)</id>"):gsub("<![[]CDATA[[]", ""):gsub("]]>$", "")
local author = data1:match("<name>([^<]+)</name>") local author = data1:match("<name>([^<]+)</name>")
local description = data1:match("<description>(.*)</description>") local description = data1:match("<description>(.*)</description>")
description = cleanHTMLTags(description) description = string.gsub(description, "<!%[CDATA%[(.*)%]%]>", "%1")
description = string.gsub(description, "%-%-", "%—")
--change format from medium to large --change format from medium to large
local image = data1:match("<image_url>([^<]+)</image_url>"):gsub("([0-9]+)m/", "%1l/") local image = data1:match("<image_url>([^<]+)</image_url>"):gsub("([0-9]+)m/", "%1l/")
local day = data1:match("<original_publication_day[^>]+>([^<]+)</original_publication_day>") local day = data1:match("<original_publication_day[^>]+>([^<]+)</original_publication_day>")

@ -17,7 +17,7 @@ local TextWidget = require("ui/widget/textwidget")
local VerticalGroup = require("ui/widget/verticalgroup") local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan") local VerticalSpan = require("ui/widget/verticalspan")
local Screen = require("device").screen local Screen = require("device").screen
local ScrollTextWidget = require("ui/widget/scrolltextwidget") local ScrollHtmlWidget = require("ui/widget/scrollhtmlwidget")
local TextBoxWidget = require("ui/widget/textboxwidget") local TextBoxWidget = require("ui/widget/textboxwidget")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local https = require('ssl.https') local https = require('ssl.https')
@ -227,18 +227,29 @@ function GoodreadsBook:genBookInfoGroup()
end end
function GoodreadsBook:bookReview() function GoodreadsBook:bookReview()
local css = [[
@page {
margin: 0;
font-family: 'Noto Sans';
}
body {
margin: 0;
line-height: 1.3;
text-align: justify;
}
]]
local book_meta_info_group = VerticalGroup:new{ local book_meta_info_group = VerticalGroup:new{
align = "center", align = "center",
padding = 0, padding = 0,
bordersize = 0, bordersize = 0,
ScrollTextWidget:new{ ScrollHtmlWidget:new{
text = self.dates.description, html_body = self.dates.description,
face = self.medium_font_face, css = css,
padding = 0,
width = self.screen_width * 0.9, width = self.screen_width * 0.9,
height = self.screen_height * 0.48, height = self.screen_height * 0.48,
dialog = self, dialog = self,
justified = true,
} }
} }
return CenterContainer:new{ return CenterContainer:new{

Loading…
Cancel
Save