Skip to content

Commit

Permalink
Merge pull request #590 from paper-plane-developers/marhkb/feat/messa…
Browse files Browse the repository at this point in the history
…ge-document/loading-indicator

feat(message-document): Add origami loading indicator
  • Loading branch information
marhkb authored Oct 1, 2023
2 parents dd9463a + a7756b6 commit 7c78bf6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ indexmap = "2"
locale_config = "0.3"
log = "0.4"
once_cell = "1"
ori = { git = "https://github.com/paper-plane-developers/origami.git", package = "origami" }
pretty_env_logger = "0.5"
qrcode-generator = { version = "4", default-features = false }
regex = "1"
Expand Down
4 changes: 4 additions & 0 deletions data/resources/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ messagebubble.document.outgoing .file > overlay > statusindicator {
color: #79c271;
}

statusindicator > loadingindicator {
margin: 2px;
}

messagebubble.document .file:hover > overlay > statusindicator {
opacity: 0.85;
}
Expand Down
15 changes: 7 additions & 8 deletions src/ui/session/content/message_row/document/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,38 +166,37 @@ impl MessageDocument {
) {
let imp = self.imp();
let click = &*imp.click;
let indicator = &*imp.status_indicator;
let file_id = file.id;

imp.status_indicator.set_status(status);
let handler_id = match status {
FileStatus::Downloading(_progress) | FileStatus::Uploading(_progress) => {
FileStatus::Downloading(_) | FileStatus::Uploading(_) => {
return;
// Show loading indicator
}
FileStatus::CanBeDownloaded => {
// Download file
indicator.set_status(FileStatus::CanBeDownloaded);
click.connect_released(clone!(@weak self as obj, @weak session => move |click, _, _, _| {
// TODO: Fix bug mentioned here
// https://github.com/paper-plane-developers/paper-plane/pull/372#discussion_r968841370
session.download_file_with_updates(file_id, clone!(@weak obj, @weak session => move |file| {
obj.update_status(file, session);
}));

obj.imp().status_indicator.set_status(FileStatus::Downloading(0.0));
let imp = obj.imp();

imp.status_indicator.set_status(FileStatus::Downloading(0.0));
let handler_id = click.connect_released(clone!(@weak session => move |_, _, _, _| {
session.cancel_download_file(file_id);
}));
if let Some(handler_id) = obj.imp().status_handler_id.replace(Some(handler_id)) {
if let Some(handler_id) = imp.status_handler_id.replace(Some(handler_id)) {
click.disconnect(handler_id);
}
}))
}
FileStatus::Downloaded => {
// Open file
indicator.set_status(FileStatus::Downloaded);
if imp.file_thumbnail_picture.file().is_some() {
indicator.set_visible(false);
imp.status_indicator.set_visible(false);
}
let gio_file = gio::File::for_path(&file.local.path);
click.connect_released(move |_, _, _, _| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ template $PaplMessageDocumentStatusIndicator {
overflow: hidden;

Image status_image {}

$OriLoadingIndicator loading_indicator {}
}
18 changes: 13 additions & 5 deletions src/ui/session/content/message_row/document/status_indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ mod imp {
pub(super) masked: Cell<bool>,
#[template_child]
pub(super) status_image: TemplateChild<gtk::Image>,
#[template_child]
pub(super) loading_indicator: TemplateChild<ori::LoadingIndicator>,
}

#[glib::object_subclass]
Expand Down Expand Up @@ -103,12 +105,18 @@ glib::wrapper! {

impl StatusIndicator {
pub(crate) fn set_status(&self, status: FileStatus) {
let icon_name = match status {
FileStatus::Downloading(_) | FileStatus::Uploading(_) => "media-playback-stop-symbolic",
FileStatus::CanBeDownloaded => "document-save-symbolic",
FileStatus::Downloaded => "folder-documents-symbolic",
let (loading_is_visible, progress, icon_name) = match status {
FileStatus::Downloading(progress) | FileStatus::Uploading(progress) => {
(true, progress, "media-playback-stop-symbolic")
}
FileStatus::CanBeDownloaded => (false, 0.0, "document-save-symbolic"),
FileStatus::Downloaded => (false, 0.0, "folder-documents-symbolic"),
};

self.imp().status_image.set_icon_name(Some(icon_name));
let imp = self.imp();

imp.loading_indicator.set_visible(loading_is_visible);
imp.loading_indicator.set_progress(progress);
imp.status_image.set_icon_name(Some(icon_name));
}
}

0 comments on commit 7c78bf6

Please sign in to comment.