From e65561687671d07d9366cb4d782605914e277ae4 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 19 Nov 2019 16:52:11 +0100 Subject: [PATCH] Cloud storage UX improvements (#5613) * Overwrite confirmbox order * Restore confirmbox option to read the downloaded book --- frontend/apps/cloudstorage/cloudstorage.lua | 95 ++++++++++++++------- frontend/apps/cloudstorage/dropbox.lua | 7 +- frontend/apps/cloudstorage/ftp.lua | 4 +- frontend/apps/cloudstorage/webdav.lua | 5 +- 4 files changed, 75 insertions(+), 36 deletions(-) diff --git a/frontend/apps/cloudstorage/cloudstorage.lua b/frontend/apps/cloudstorage/cloudstorage.lua index d6fe913c6..828a52208 100644 --- a/frontend/apps/cloudstorage/cloudstorage.lua +++ b/frontend/apps/cloudstorage/cloudstorage.lua @@ -210,21 +210,43 @@ function CloudStorage:downloadFile(item) local cs_settings = self:readSettings() local download_dir = cs_settings:readSetting("download_dir") or lastdir local path = download_dir .. '/' .. item.text - if lfs.attributes(path) then - UIManager:show(ConfirmBox:new{ - text = _("File already exists. Would you like to overwrite it?"), - ok_callback = function() - self:cloudFile(item, path) - end - }) - else - self:cloudFile(item, path) - end + self:cloudFile(item, path) end function CloudStorage:cloudFile(item, path) - local path_dir = path local download_text = _("Downloading. This might take a moment.") + local function dropboxDownloadFile(unit_item, password, path_dir, callback_close) + UIManager:scheduleIn(1, function() + DropBox:downloadFile(unit_item, password, path_dir, callback_close) + end) + UIManager:show(InfoMessage:new{ + text = download_text, + timeout = 1, + }) + end + + local function ftpDownloadFile(unit_item, address, username, password, path_dir, callback_close) + UIManager:scheduleIn(1, function() + Ftp:downloadFile(unit_item, address, username, password, path_dir, callback_close) + end) + UIManager:show(InfoMessage:new{ + text = download_text, + timeout = 1, + }) + end + + local function webdavDownloadFile(unit_item, address, username, password, path_dir, callback_close) + UIManager:scheduleIn(1, function() + WebDav:downloadFile(unit_item, address, username, password, path_dir, callback_close) + end) + UIManager:show(InfoMessage:new{ + text = download_text, + timeout = 1, + }) + end + + local path_dir = path + local overwrite_text = _("File already exists. Would you like to overwrite it?") local buttons = { { { @@ -234,38 +256,47 @@ function CloudStorage:cloudFile(item, path) local callback_close = function() self:onClose() end - UIManager:scheduleIn(1, function() - DropBox:downloadFile(item, self.password, path_dir, callback_close) - end) UIManager:close(self.download_dialog) - UIManager:show(InfoMessage:new{ - text = download_text, - timeout = 1, - }) + if lfs.attributes(path) then + UIManager:show(ConfirmBox:new{ + text = overwrite_text, + ok_callback = function() + dropboxDownloadFile(item, self.password, path_dir, callback_close) + end + }) + else + dropboxDownloadFile(item, self.password, path_dir, callback_close) + end elseif self.type == "ftp" then local callback_close = function() self:onClose() end - UIManager:scheduleIn(1, function() - Ftp:downloadFile(item, self.address, self.username, self.password, path_dir, callback_close) - end) UIManager:close(self.download_dialog) - UIManager:show(InfoMessage:new{ - text = download_text, - timeout = 1, - }) + if lfs.attributes(path) then + UIManager:show(ConfirmBox:new{ + text = overwrite_text, + ok_callback = function() + ftpDownloadFile(item, self.address, self.username, self.password, path_dir, callback_close) + end + }) + else + ftpDownloadFile(item, self.address, self.username, self.password, path_dir, callback_close) + end elseif self.type == "webdav" then local callback_close = function() self:onClose() end - UIManager:scheduleIn(1, function() - WebDav:downloadFile(item, self.address, self.username, self.password, path_dir, callback_close) - end) UIManager:close(self.download_dialog) - UIManager:show(InfoMessage:new{ - text = download_text, - timeout = 1, - }) + if lfs.attributes(path) then + UIManager:show(ConfirmBox:new{ + text = overwrite_text, + ok_callback = function() + webdavDownloadFile(item, self.address, self.username, self.password, path_dir, callback_close) + end + }) + else + webdavDownloadFile(item, self.address, self.username, self.password, path_dir, callback_close) + end end end, }, diff --git a/frontend/apps/cloudstorage/dropbox.lua b/frontend/apps/cloudstorage/dropbox.lua index 2bc304d62..a3756984d 100644 --- a/frontend/apps/cloudstorage/dropbox.lua +++ b/frontend/apps/cloudstorage/dropbox.lua @@ -1,9 +1,11 @@ -local DropBoxApi = require("apps/cloudstorage/dropboxapi") local ConfirmBox = require("ui/widget/confirmbox") +local DocumentRegistry = require("document/documentregistry") +local DropBoxApi = require("apps/cloudstorage/dropboxapi") local InfoMessage = require("ui/widget/infomessage") local MultiInputDialog = require("ui/widget/multiinputdialog") local UIManager = require("ui/uimanager") local ReaderUI = require("apps/reader/readerui") +local util = require("util") local Screen = require("device").screen local T = require("ffi/util").template local _ = require("gettext") @@ -21,7 +23,8 @@ end function DropBox:downloadFile(item, password, path, close) local code_response = DropBoxApi:downloadFile(item.url, password, path) if code_response == 200 then - if G_reader_settings:isTrue("show_unsupported") then + local __, filename = util.splitFilePathName(path) + if G_reader_settings:isTrue("show_unsupported") and not DocumentRegistry:hasProvider(filename) then UIManager:show(InfoMessage:new{ text = T(_("File saved to:\n%1"), path), }) diff --git a/frontend/apps/cloudstorage/ftp.lua b/frontend/apps/cloudstorage/ftp.lua index ad15e6b58..76a356169 100644 --- a/frontend/apps/cloudstorage/ftp.lua +++ b/frontend/apps/cloudstorage/ftp.lua @@ -1,4 +1,5 @@ local ConfirmBox = require("ui/widget/confirmbox") +local DocumentRegistry = require("document/documentregistry") local FtpApi = require("apps/cloudstorage/ftpapi") local InfoMessage = require("ui/widget/infomessage") local MultiInputDialog = require("ui/widget/multiinputdialog") @@ -26,7 +27,8 @@ function Ftp:downloadFile(item, address, user, pass, path, close) local file = io.open(path, "w") file:write(response) file:close() - if G_reader_settings:isTrue("show_unsupported") then + local __, filename = util.splitFilePathName(path) + if G_reader_settings:isTrue("show_unsupported") and not DocumentRegistry:hasProvider(filename) then UIManager:show(InfoMessage:new{ text = T(_("File saved to:\n%1"), path), }) diff --git a/frontend/apps/cloudstorage/webdav.lua b/frontend/apps/cloudstorage/webdav.lua index 29a5d623a..16e4a0b33 100644 --- a/frontend/apps/cloudstorage/webdav.lua +++ b/frontend/apps/cloudstorage/webdav.lua @@ -1,9 +1,11 @@ local ConfirmBox = require("ui/widget/confirmbox") +local DocumentRegistry = require("document/documentregistry") local InfoMessage = require("ui/widget/infomessage") local MultiInputDialog = require("ui/widget/multiinputdialog") local UIManager = require("ui/uimanager") local ReaderUI = require("apps/reader/readerui") local WebDavApi = require("apps/cloudstorage/webdavapi") +local util = require("util") local _ = require("gettext") local Screen = require("device").screen local T = require("ffi/util").template @@ -17,7 +19,8 @@ end function WebDav:downloadFile(item, address, username, password, local_path, close) local code_response = WebDavApi:downloadFile(address .. WebDavApi:urlEncode( item.url ), username, password, local_path) if code_response == 200 then - if G_reader_settings:isTrue("show_unsupported") then + local __, filename = util.splitFilePathName(local_path) + if G_reader_settings:isTrue("show_unsupported") and not DocumentRegistry:hasProvider(filename) then UIManager:show(InfoMessage:new{ text = T(_("File saved to:\n%1"), local_path), })