mirror of
https://github.com/koreader/koreader
synced 2024-11-11 19:11:14 +00:00
Annotation list: sort by date (#12020)
This commit is contained in:
parent
a03195d524
commit
fb88e8db28
@ -138,7 +138,8 @@ function ReaderBookmark:addToMainMenu(menu_items)
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
text_func = function()
|
text_func = function()
|
||||||
local curr_perpage = G_reader_settings:readSetting("bookmarks_items_per_page")
|
local curr_perpage = self.items_max_lines and _("flexible")
|
||||||
|
or G_reader_settings:readSetting("bookmarks_items_per_page")
|
||||||
return T(_("Bookmarks per page: %1"), curr_perpage)
|
return T(_("Bookmarks per page: %1"), curr_perpage)
|
||||||
end,
|
end,
|
||||||
enabled_func = function()
|
enabled_func = function()
|
||||||
@ -193,7 +194,7 @@ function ReaderBookmark:addToMainMenu(menu_items)
|
|||||||
return not self.items_max_lines
|
return not self.items_max_lines
|
||||||
end,
|
end,
|
||||||
checked_func = function()
|
checked_func = function()
|
||||||
return G_reader_settings:isTrue("bookmarks_items_multilines_show_more_text")
|
return not self.items_max_lines and G_reader_settings:isTrue("bookmarks_items_multilines_show_more_text")
|
||||||
end,
|
end,
|
||||||
callback = function()
|
callback = function()
|
||||||
G_reader_settings:flipNilOrFalse("bookmarks_items_multilines_show_more_text")
|
G_reader_settings:flipNilOrFalse("bookmarks_items_multilines_show_more_text")
|
||||||
@ -221,15 +222,25 @@ function ReaderBookmark:addToMainMenu(menu_items)
|
|||||||
separator = true,
|
separator = true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text = _("Sort by largest page number"),
|
text_func = function()
|
||||||
|
return T(_("Sort by: %1"), self:genSortByMenuItems())
|
||||||
|
end,
|
||||||
|
sub_item_table = {
|
||||||
|
self:genSortByMenuItems("page"),
|
||||||
|
self:genSortByMenuItems("date", true),
|
||||||
|
-- separator
|
||||||
|
{
|
||||||
|
text = _("Reverse sorting"),
|
||||||
checked_func = function()
|
checked_func = function()
|
||||||
return G_reader_settings:nilOrTrue("bookmarks_items_reverse_sorting")
|
return G_reader_settings:isTrue("bookmarks_items_reverse_sorting")
|
||||||
end,
|
end,
|
||||||
callback = function()
|
callback = function()
|
||||||
G_reader_settings:flipNilOrTrue("bookmarks_items_reverse_sorting")
|
G_reader_settings:flipNilOrFalse("bookmarks_items_reverse_sorting")
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
menu_items.bookmark_search = {
|
menu_items.bookmark_search = {
|
||||||
text = _("Bookmark search"),
|
text = _("Bookmark search"),
|
||||||
@ -257,6 +268,7 @@ function ReaderBookmark:genShowInItemsMenuItems(value)
|
|||||||
checked_func = function()
|
checked_func = function()
|
||||||
return self.items_text == value
|
return self.items_text == value
|
||||||
end,
|
end,
|
||||||
|
radio = true,
|
||||||
callback = function()
|
callback = function()
|
||||||
self.items_text = value
|
self.items_text = value
|
||||||
G_reader_settings:saveSetting("bookmarks_items_text_type", value)
|
G_reader_settings:saveSetting("bookmarks_items_text_type", value)
|
||||||
@ -264,6 +276,36 @@ function ReaderBookmark:genShowInItemsMenuItems(value)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReaderBookmark:genSortByMenuItems(value, separator)
|
||||||
|
local strings = {
|
||||||
|
page = _("page number"),
|
||||||
|
date = _("date"),
|
||||||
|
}
|
||||||
|
local strings_reverse = {
|
||||||
|
page = _("page number, reverse"),
|
||||||
|
date = _("date, reverse"),
|
||||||
|
}
|
||||||
|
if value == nil then
|
||||||
|
local curr_value = G_reader_settings:readSetting("bookmarks_items_sorting") or "page"
|
||||||
|
if G_reader_settings:isTrue("bookmarks_items_reverse_sorting") then
|
||||||
|
return strings_reverse[curr_value]
|
||||||
|
else
|
||||||
|
return strings[curr_value]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return {
|
||||||
|
text = strings[value],
|
||||||
|
checked_func = function()
|
||||||
|
return value == (G_reader_settings:readSetting("bookmarks_items_sorting") or "page")
|
||||||
|
end,
|
||||||
|
radio = true,
|
||||||
|
callback = function()
|
||||||
|
G_reader_settings:saveSetting("bookmarks_items_sorting", value ~= "page" and value or nil)
|
||||||
|
end,
|
||||||
|
separator = separator,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
-- page bookmarks, dogear
|
-- page bookmarks, dogear
|
||||||
|
|
||||||
function ReaderBookmark:onToggleBookmark()
|
function ReaderBookmark:onToggleBookmark()
|
||||||
@ -566,7 +608,8 @@ end
|
|||||||
-- bookmark list, dialogs
|
-- bookmark list, dialogs
|
||||||
|
|
||||||
function ReaderBookmark:onShowBookmark()
|
function ReaderBookmark:onShowBookmark()
|
||||||
self.is_reverse_sorting = G_reader_settings:nilOrTrue("bookmarks_items_reverse_sorting") -- page numbers descending
|
self.sorting_mode = G_reader_settings:readSetting("bookmarks_items_sorting") or "page"
|
||||||
|
self.is_reverse_sorting = G_reader_settings:isTrue("bookmarks_items_reverse_sorting")
|
||||||
|
|
||||||
-- build up item_table
|
-- build up item_table
|
||||||
local item_table = {}
|
local item_table = {}
|
||||||
@ -598,6 +641,13 @@ function ReaderBookmark:onShowBookmark()
|
|||||||
curr_page_index_filtered = curr_page_index_filtered - 1
|
curr_page_index_filtered = curr_page_index_filtered - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local curr_page_datetime
|
||||||
|
if self.sorting_mode == "date" then
|
||||||
|
curr_page_datetime = item_table[curr_page_index_filtered].datetime
|
||||||
|
local sort_func = self.is_reverse_sorting and function(a, b) return a.datetime > b.datetime end
|
||||||
|
or function(a, b) return a.datetime < b.datetime end
|
||||||
|
table.sort(item_table, sort_func)
|
||||||
|
end
|
||||||
|
|
||||||
local items_per_page = G_reader_settings:readSetting("bookmarks_items_per_page")
|
local items_per_page = G_reader_settings:readSetting("bookmarks_items_per_page")
|
||||||
local items_font_size = G_reader_settings:readSetting("bookmarks_items_font_size", Menu.getItemFontSize(items_per_page))
|
local items_font_size = G_reader_settings:readSetting("bookmarks_items_font_size", Menu.getItemFontSize(items_per_page))
|
||||||
@ -638,7 +688,7 @@ function ReaderBookmark:onShowBookmark()
|
|||||||
local bookmark = self
|
local bookmark = self
|
||||||
|
|
||||||
function bm_menu:onMenuSelect(item)
|
function bm_menu:onMenuSelect(item)
|
||||||
if self.select_mode then
|
if self.select_count then
|
||||||
if item.dim then
|
if item.dim then
|
||||||
item.dim = nil
|
item.dim = nil
|
||||||
if item.after_curr_page then
|
if item.after_curr_page then
|
||||||
@ -663,11 +713,8 @@ function ReaderBookmark:onShowBookmark()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function bm_menu:toggleSelectMode()
|
function bm_menu:toggleSelectMode()
|
||||||
self.select_mode = not self.select_mode
|
if self.select_count then
|
||||||
if self.select_mode then
|
self.select_count = nil
|
||||||
self.select_count = 0
|
|
||||||
self:setTitleBarLeftIcon("check")
|
|
||||||
else
|
|
||||||
for _, v in ipairs(item_table) do
|
for _, v in ipairs(item_table) do
|
||||||
v.dim = nil
|
v.dim = nil
|
||||||
if v.after_curr_page then
|
if v.after_curr_page then
|
||||||
@ -675,6 +722,9 @@ function ReaderBookmark:onShowBookmark()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
self:setTitleBarLeftIcon("appbar.menu")
|
self:setTitleBarLeftIcon("appbar.menu")
|
||||||
|
else
|
||||||
|
self.select_count = 0
|
||||||
|
self:setTitleBarLeftIcon("check")
|
||||||
end
|
end
|
||||||
bookmark:updateBookmarkList(nil, -1)
|
bookmark:updateBookmarkList(nil, -1)
|
||||||
end
|
end
|
||||||
@ -682,7 +732,7 @@ function ReaderBookmark:onShowBookmark()
|
|||||||
function bm_menu:onLeftButtonTap()
|
function bm_menu:onLeftButtonTap()
|
||||||
local bm_dialog, dialog_title
|
local bm_dialog, dialog_title
|
||||||
local buttons = {}
|
local buttons = {}
|
||||||
if self.select_mode then
|
if self.select_count then
|
||||||
local actions_enabled = self.select_count > 0
|
local actions_enabled = self.select_count > 0
|
||||||
local more_selections_enabled = self.select_count < #item_table
|
local more_selections_enabled = self.select_count < #item_table
|
||||||
if actions_enabled then
|
if actions_enabled then
|
||||||
@ -781,7 +831,7 @@ function ReaderBookmark:onShowBookmark()
|
|||||||
table.remove(item_table, i)
|
table.remove(item_table, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.select_mode = false
|
self.select_count = nil
|
||||||
self:setTitleBarLeftIcon("appbar.menu")
|
self:setTitleBarLeftIcon("appbar.menu")
|
||||||
bookmark:updateBookmarkList(item_table, -1)
|
bookmark:updateBookmarkList(item_table, -1)
|
||||||
end,
|
end,
|
||||||
@ -849,7 +899,18 @@ function ReaderBookmark:onShowBookmark()
|
|||||||
text = _("Current page"),
|
text = _("Current page"),
|
||||||
callback = function()
|
callback = function()
|
||||||
UIManager:close(bm_dialog)
|
UIManager:close(bm_dialog)
|
||||||
bookmark:updateBookmarkList(nil, curr_page_index_filtered)
|
local idx
|
||||||
|
if bookmark.sorting_mode == "date" then
|
||||||
|
for i, v in ipairs(item_table) do
|
||||||
|
if v.datetime == curr_page_datetime then
|
||||||
|
idx = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else -- "page"
|
||||||
|
idx = curr_page_index_filtered
|
||||||
|
end
|
||||||
|
bookmark:updateBookmarkList(nil, idx)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -858,8 +919,13 @@ function ReaderBookmark:onShowBookmark()
|
|||||||
and not (bookmark.match_table or bookmark.show_edited_only or bookmark.show_drawer_only),
|
and not (bookmark.match_table or bookmark.show_edited_only or bookmark.show_drawer_only),
|
||||||
callback = function()
|
callback = function()
|
||||||
UIManager:close(bm_dialog)
|
UIManager:close(bm_dialog)
|
||||||
local _, idx = bookmark:getLatestBookmark()
|
local idx
|
||||||
idx = self.is_reverse_sorting and #item_table - idx + 1 or idx
|
if bookmark.sorting_mode == "date" then
|
||||||
|
idx = bookmark.is_reverse_sorting and 1 or #item_table
|
||||||
|
else -- "page"
|
||||||
|
idx = select(2, bookmark:getLatestBookmark())
|
||||||
|
idx = bookmark.is_reverse_sorting and #item_table - idx + 1 or idx
|
||||||
|
end
|
||||||
bookmark:updateBookmarkList(nil, idx)
|
bookmark:updateBookmarkList(nil, idx)
|
||||||
bookmark:showBookmarkDetails(item_table[idx])
|
bookmark:showBookmarkDetails(item_table[idx])
|
||||||
end,
|
end,
|
||||||
@ -905,7 +971,13 @@ function ReaderBookmark:onShowBookmark()
|
|||||||
self.show_drawer_only = nil
|
self.show_drawer_only = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
self:updateBookmarkList(nil, curr_page_index_filtered)
|
local idx
|
||||||
|
if bookmark.sorting_mode == "date" then -- show the most recent bookmark
|
||||||
|
idx = bookmark.is_reverse_sorting and 1 or #item_table
|
||||||
|
else -- "page", show bookmark in the current book page
|
||||||
|
idx = curr_page_index_filtered
|
||||||
|
end
|
||||||
|
self:updateBookmarkList(nil, idx)
|
||||||
UIManager:show(self.bookmark_menu)
|
UIManager:show(self.bookmark_menu)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -919,7 +991,7 @@ function ReaderBookmark:updateBookmarkList(item_table, item_number)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local subtitle
|
local subtitle
|
||||||
if bm_menu.select_mode then
|
if bm_menu.select_count then
|
||||||
subtitle = T(_("Selected: %1"), bm_menu.select_count)
|
subtitle = T(_("Selected: %1"), bm_menu.select_count)
|
||||||
else
|
else
|
||||||
if self.show_edited_only then
|
if self.show_edited_only then
|
||||||
@ -948,19 +1020,24 @@ function ReaderBookmark:updateBookmarkList(item_table, item_number)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ReaderBookmark:getBookmarkItemIndex(item)
|
function ReaderBookmark:getBookmarkItemIndex(item)
|
||||||
return (self.match_table or self.show_edited_only or self.show_drawer_only)
|
if self.match_table or self.show_edited_only or self.show_drawer_only -- filtered
|
||||||
and self.ui.annotation:getItemIndex(item) -- item table is filtered, cannot use item.idx
|
or self.sorting_mode ~= "page" then -- or item_table order does not match with annotations
|
||||||
or (self.is_reverse_sorting and #self.ui.annotation.annotations - item.idx + 1 or item.idx)
|
return self.ui.annotation:getItemIndex(item)
|
||||||
|
end
|
||||||
|
if self.is_reverse_sorting then
|
||||||
|
return #self.ui.annotation.annotations - item.idx + 1
|
||||||
|
end
|
||||||
|
return item.idx
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReaderBookmark:getBookmarkItemText(item)
|
function ReaderBookmark:getBookmarkItemText(item)
|
||||||
if item.type == "highlight" or self.items_text == "text" then
|
|
||||||
return self.display_prefix[item.type] .. item.text_orig
|
|
||||||
end
|
|
||||||
if item.type == "note" and self.items_text == "note" then
|
|
||||||
return self.display_prefix["note"] .. item.note
|
|
||||||
end
|
|
||||||
local text
|
local text
|
||||||
|
if item.type == "highlight" or self.items_text == "text" then
|
||||||
|
text = self.display_prefix[item.type] .. item.text_orig
|
||||||
|
else
|
||||||
|
if item.type == "note" and self.items_text == "note" then
|
||||||
|
text = self.display_prefix["note"] .. item.note
|
||||||
|
else
|
||||||
if item.type == "bookmark" then
|
if item.type == "bookmark" then
|
||||||
text = self.display_prefix["bookmark"]
|
text = self.display_prefix["bookmark"]
|
||||||
else -- it is a note, but we show the "highlight" prefix before the highlighted text
|
else -- it is a note, but we show the "highlight" prefix before the highlighted text
|
||||||
@ -972,6 +1049,11 @@ function ReaderBookmark:getBookmarkItemText(item)
|
|||||||
if item.note then
|
if item.note then
|
||||||
text = text .. "\u{2002}" .. self.display_prefix["note"] .. item.note
|
text = text .. "\u{2002}" .. self.display_prefix["note"] .. item.note
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if self.sorting_mode == "date" then
|
||||||
|
text = item.datetime .. "\u{2002}" .. text
|
||||||
|
end
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -989,7 +1071,7 @@ function ReaderBookmark:showBookmarkDetails(item)
|
|||||||
if item.note then
|
if item.note then
|
||||||
text = text .. "\n\n" .. self.display_prefix["note"] .. item.note
|
text = text .. "\n\n" .. self.display_prefix["note"] .. item.note
|
||||||
end
|
end
|
||||||
local not_select_mode = not bm_menu.select_mode and not self.ui.highlight.select_mode
|
local not_select_mode = not bm_menu.select_count and not self.ui.highlight.select_mode
|
||||||
|
|
||||||
local textviewer
|
local textviewer
|
||||||
local edit_details_callback = function()
|
local edit_details_callback = function()
|
||||||
@ -1043,7 +1125,7 @@ function ReaderBookmark:showBookmarkDetails(item)
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
text = item.note and _("Edit note") or _("Add note"),
|
text = item.note and _("Edit note") or _("Add note"),
|
||||||
enabled = not bm_menu.select_mode,
|
enabled = not bm_menu.select_count,
|
||||||
callback = function()
|
callback = function()
|
||||||
self:setBookmarkNote(item, nil, nil, edit_details_callback)
|
self:setBookmarkNote(item, nil, nil, edit_details_callback)
|
||||||
end,
|
end,
|
||||||
@ -1069,7 +1151,7 @@ function ReaderBookmark:showBookmarkDetails(item)
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
text = _("Go to bookmark"),
|
text = _("Go to bookmark"),
|
||||||
enabled = not bm_menu.select_mode,
|
enabled = not bm_menu.select_count,
|
||||||
callback = function()
|
callback = function()
|
||||||
UIManager:close(textviewer)
|
UIManager:close(textviewer)
|
||||||
self.ui.link:addCurrentLocationToStack()
|
self.ui.link:addCurrentLocationToStack()
|
||||||
|
Loading…
Reference in New Issue
Block a user