diff --git a/plugins/goodreads.koplugin/doublekeyvaluepage.lua b/plugins/goodreads.koplugin/doublekeyvaluepage.lua index 1d920eeae..06647bc12 100644 --- a/plugins/goodreads.koplugin/doublekeyvaluepage.lua +++ b/plugins/goodreads.koplugin/doublekeyvaluepage.lua @@ -16,7 +16,7 @@ local Geom = require("ui/geometry") local Font = require("ui/font") local Device = require("device") local Screen = Device.screen -local GoodReadersApi = require("goodreadsapi") +local GoodreadsApi = require("goodreadsapi") local LuaSettings = require("luasettings") local DataStorage = require("datastorage") local _ = require("gettext") @@ -176,7 +176,7 @@ local DoubleKeyValuePage = InputContainer:new{ show_page = 1, text_input = "", pages = 1, - goodreadersKey = "", + goodreads_key = "", } function DoubleKeyValuePage:readGRSettings() @@ -195,11 +195,11 @@ function DoubleKeyValuePage:init() self.screen_height = Screen:getSize().h local gr_sett = self:readGRSettings().data if gr_sett.goodreads then - self.goodreadersKey = gr_sett.goodreads.key - self.goodreadersSecret = gr_sett.goodreads.secret + self.goodreads_key = gr_sett.goodreads.key + self.goodreads_secret = gr_sett.goodreads.secret end - self.kv_pairs = GoodReadersApi:showData(self.text_input, self.search_type, 1, self.goodreadersKey) - self.total_res = GoodReadersApi:getTotalResults() + self.kv_pairs = GoodReadsApi:showData(self.text_input, self.search_type, 1, self.goodreads_key) + self.total_res = GoodReadsApi:getTotalResults() if self.total_res == nil then self.total_res = 0 end @@ -257,7 +257,7 @@ function DoubleKeyValuePage:nextPage() and #self.kv_pairs < self.total_res then local api_page = math.floor(new_page * self.items_per_page / 20 ) + 1 -- load new portion of data - local new_pair = GoodReadersApi:showData(self.text_input, self.search_type, api_page, self.goodreadersKey ) + local new_pair = GoodReadsApi:showData(self.text_input, self.search_type, api_page, self.goodreads_key ) if new_pair == nil then return end for _, v in pairs(new_pair) do table.insert(self.kv_pairs, v) diff --git a/plugins/goodreads.koplugin/goodreadsapi.lua b/plugins/goodreads.koplugin/goodreadsapi.lua index ffec436e4..431e5650b 100644 --- a/plugins/goodreads.koplugin/goodreadsapi.lua +++ b/plugins/goodreads.koplugin/goodreadsapi.lua @@ -1,5 +1,5 @@ local InputContainer = require("ui/widget/container/inputcontainer") -local GoodReaderBook = require("goodreaderbook") +local GoodreadsBook = require("goodreadsbook") local InfoMessage = require("ui/widget/infomessage") local UIManager = require("ui/uimanager") local url = require('socket.url') @@ -9,13 +9,13 @@ local https = require('ssl.https') local ltn12 = require('ltn12') local _ = require("gettext") -local GoodReadsApi = InputContainer:new { - goodreaders_key = "", - goodreaders_secret = "", +local GoodreadsApi = InputContainer:new { + goodreads_key = "", + goodreads_secret = "", total_result = 0, } -function GoodReadsApi:init() +function GoodreadsApi:init() end local function genSearchURL(text_search, userApi, search_type, npage) @@ -42,7 +42,7 @@ local function genIdUrl(id, userApi) )) end -function GoodReadsApi:fetchXml(s_url) +function GoodreadsApi:fetchXml(s_url) local request, sink = {}, {} local parsed = url.parse(s_url) request['url'] = s_url @@ -61,7 +61,7 @@ function GoodReadsApi:fetchXml(s_url) end end -function GoodReadsApi:showSearchTable(data) +function GoodreadsApi:showSearchTable(data) local books = {} if data == nil then UIManager:show(InfoMessage:new{text =_("Network problem.\nCheck connection.")}) @@ -86,7 +86,7 @@ function GoodReadsApi:showSearchTable(data) return books end -function GoodReadsApi:getTotalResults() +function GoodreadsApi:getTotalResults() return self.total_result end @@ -175,9 +175,9 @@ end -- search_type = all - search all -- search_type = author - serch book by author -- search_type = title - search book by title -function GoodReadsApi:showData(search_text, search_type, page, goodreaders_key) +function GoodreadsApi:showData(search_text, search_type, page, goodreads_key) local stats = {} - local gen_url = genSearchURL(search_text, goodreaders_key, search_type, page) + local gen_url = genSearchURL(search_text, goodreads_key, search_type, page) local gen_xml = self:fetchXml(gen_url) local tbl = self:showSearchTable(gen_xml) if #tbl == 0 then @@ -190,9 +190,9 @@ function GoodReadsApi:showData(search_text, search_type, page, goodreaders_key) table.insert(stats, { author, title, callback = function() - local dates = self:showIdData(id, goodreaders_key) + local dates = self:showIdData(id, goodreads_key) if dates.id ~= nil then - UIManager:show(GoodReaderBook:new{ + UIManager:show(GoodreadsBook:new{ dates = dates, }) end @@ -202,11 +202,11 @@ function GoodReadsApi:showData(search_text, search_type, page, goodreaders_key) return stats end -function GoodReadsApi:showIdData(id, goodreaders_key) - local gen_url = genIdUrl(id, goodreaders_key) +function GoodreadsApi:showIdData(id, goodreads_key) + local gen_url = genIdUrl(id, goodreads_key) local gen_xml = self:fetchXml(gen_url) local tbl = showIdTable(gen_xml) return tbl end -return GoodReadsApi +return GoodreadsApi diff --git a/plugins/goodreads.koplugin/goodreaderbook.lua b/plugins/goodreads.koplugin/goodreadsbook.lua similarity index 95% rename from plugins/goodreads.koplugin/goodreaderbook.lua rename to plugins/goodreads.koplugin/goodreadsbook.lua index 6d2871825..f2cd0291e 100644 --- a/plugins/goodreads.koplugin/goodreaderbook.lua +++ b/plugins/goodreads.koplugin/goodreadsbook.lua @@ -22,11 +22,11 @@ local _ = require("gettext") local T = require("ffi/util").template local Pic = require("ffi/pic") -local GoodReaderBook = InputContainer:new{ +local GoodreadsBook = InputContainer:new{ padding = Screen:scaleBySize(15), } -function GoodReaderBook:init() +function GoodreadsBook:init() self.small_font_face = Font:getFace("ffont", 16) self.medium_font_face = Font:getFace("ffont", 18) self.large_font_face = Font:getFace("ffont", 22) @@ -45,7 +45,7 @@ function GoodReaderBook:init() } end -function GoodReaderBook:getStatusContent(width) +function GoodreadsBook:getStatusContent(width) return VerticalGroup:new{ align = "left", OverlapGroup:new{ @@ -59,7 +59,7 @@ function GoodReaderBook:getStatusContent(width) } end -function GoodReaderBook:genHeader(title) +function GoodreadsBook:genHeader(title) local header_title = TextWidget:new{ text = title, face = self.medium_font_face, @@ -94,7 +94,7 @@ function GoodReaderBook:genHeader(title) } end -function GoodReaderBook:genBookInfoGroup() +function GoodreadsBook:genBookInfoGroup() local split_span_width = self.screen_width * 0.05 local img_width, img_height if Screen:getScreenMode() == "landscape" then @@ -226,7 +226,7 @@ function GoodReaderBook:genBookInfoGroup() } end -function GoodReaderBook:bookReview() +function GoodreadsBook:bookReview() local book_meta_info_group = VerticalGroup:new{ align = "center", padding = 0, @@ -246,14 +246,14 @@ function GoodReaderBook:bookReview() } end -function GoodReaderBook:onAnyKeyPressed() +function GoodreadsBook:onAnyKeyPressed() return self:onClose() end -function GoodReaderBook:onClose() +function GoodreadsBook:onClose() UIManager:setDirty("all") UIManager:close(self) return true end -return GoodReaderBook +return GoodreadsBook diff --git a/plugins/goodreads.koplugin/main.lua b/plugins/goodreads.koplugin/main.lua index ff67a16f0..01ea975ee 100644 --- a/plugins/goodreads.koplugin/main.lua +++ b/plugins/goodreads.koplugin/main.lua @@ -7,61 +7,61 @@ local UIManager = require("ui/uimanager") local Screen = require("device").screen local _ = require("gettext") -local GoodReads = InputContainer:new { - goodreaders_key = "", - goodreaders_secret = "", +local Goodreads = InputContainer:new { + goodreads_key = "", + goodreads_secret = "", } -function GoodReads:init() +function Goodreads:init() local gr_sett = DoubleKeyValuePage:readGRSettings().data if gr_sett.goodreads then - self.goodreaders_key = gr_sett.goodreads.key - self.goodreaders_secret = gr_sett.goodreads.secret + self.goodreads_key = gr_sett.goodreads.key + self.goodreads_secret = gr_sett.goodreads.secret end self.ui.menu:registerToMainMenu(self) end -function GoodReads:addToMainMenu(tab_item_table) +function Goodreads:addToMainMenu(tab_item_table) table.insert(tab_item_table.plugins, { - text = _("GoodReads"), + text = _("Goodreads"), sub_item_table = { { text = _("Settings"), callback = function() self:updateSettings() end, }, { - text = _("Search book all"), + text = _("Search all books"), callback = function() - if self.goodreaders_key ~= "" then + if self.goodreads_key ~= "" then self:search("all") else UIManager:show(InfoMessage:new{ - text = _("Please set up GoodReads key in settings"), + text = _("Please set up your Goodreads key in the settings dialog"), }) end end, }, { - text = _("Search book by title"), + text = _("Search for book by title"), callback = function() - if self.goodreaders_key ~= "" then + if self.goodreads_key ~= "" then self:search("title") else UIManager:show(InfoMessage:new{ - text = _("Please set up GoodReads key in settings"), + text = _("Please set up your Goodreads key in the settings dialog"), }) end end, }, { - text = _("Search book by author"), + text = _("Search for book by author"), callback = function() - if self.goodreaders_key ~= "" then + if self.goodreads_key ~= "" then self:search("author") else UIManager:show(InfoMessage:new{ - text = _("Please set up GoodReads key in settings"), + text = _("Please set up your Goodreads key in the settings dialog"), }) end end, @@ -70,33 +70,33 @@ function GoodReads:addToMainMenu(tab_item_table) }) end -function GoodReads:updateSettings() +function Goodreads:updateSettings() local hint_top local text_top local hint_bottom local text_bottom - local text_info = "How to generate key and secret key:\n".. - "1. Go to https://www.goodreads.com/user/sign_up and create account\n" .. - "2. Register development key on page: https://www.goodreads.com/user/sign_in?rd=true\n" .. - "3. Your key and secret key are on https://www.goodreads.com/api/keys\n" .. - "4. Enter your generated key and secret key in settings (Login to GoodReads window)" - if self.goodreaders_key == "" then - hint_top = _("GoodReaders Key Not Set") + local text_info = "How to generate a key and a secret key:\n".. + "1. Go to https://www.goodreads.com/user/sign_up and create an account\n" .. + "2. Register for a development key on the following page: https://www.goodreads.com/user/sign_in?rd=true\n" .. + "3. Your key and secret key will now be available on https://www.goodreads.com/api/keys\n" .. + "4. Enter your generated key and your secret key in the settings dialog (Login to Goodreads window)" + if self.goodreads_key == "" then + hint_top = _("Goodreads Key Not Set") text_top = "" else hint_top = "" - text_top = self.goodreaders_key + text_top = self.goodreads_key end - if self.goodreaders_secret == "" then - hint_bottom = _("GoodReaders Secret Key Not Set (optional)") + if self.goodreads_secret == "" then + hint_bottom = _("Goodreads Secret Key Not Set (optional)") text_bottom = "" else hint_bottom = "" - text_bottom = self.goodreaders_key + text_bottom = self.goodreads_key end self.settings_dialog = MultiInputDialog:new { - title = _("Login to GoodReads"), + title = _("Login to Goodreads"), fields = { { text = text_top, @@ -142,14 +142,14 @@ function GoodReads:updateSettings() UIManager:show(self.settings_dialog) end -function GoodReads:saveSettings(fields) +function Goodreads:saveSettings(fields) if fields then - self.goodreaders_key = fields[1] - self.goodreaders_secret = fields[2] + self.goodreads_key = fields[1] + self.goodreads_secret = fields[2] end local settings = { - key = self.goodreaders_key, - secret = self.goodreaders_secret, + key = self.goodreads_key, + secret = self.goodreads_secret, } DoubleKeyValuePage:saveGRSettings(settings) end @@ -157,7 +157,7 @@ end -- search_type = all - search all -- search_type = author - serch book by author -- search_type = title - search book by title -function GoodReads:search(search_type) +function Goodreads:search(search_type) local title_header local hint local search_input @@ -165,13 +165,13 @@ function GoodReads:search(search_type) local info local result if search_type == "all" then - title_header = _("Search book all in GoodReads") + title_header = _("Search all books in Goodreads") hint = _("Title, author or ISBN") elseif search_type == "author" then - title_header = _("Search book by author in GoodReads") + title_header = _("Search for book by author in Goodreads") hint = _("Author") elseif search_type == "title" then - title_header = _("Search book by title in GoodReads") + title_header = _("Search for book by title in Goodreads") hint = _("Title") end @@ -209,7 +209,7 @@ function GoodReads:search(search_type) UIManager:close(search_input) else UIManager:show(InfoMessage:new{ - text =_("Please input text"), + text =_("Please enter text"), }) end end, @@ -221,4 +221,4 @@ function GoodReads:search(search_type) UIManager:show(search_input) end -return GoodReads +return Goodreads