Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(composer): show weekly use on tag #332

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/API/Tag.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ public class Tuba.API.Tag : Entity, Widgetizable {
public override void open () {
}

public string weekly_use () {
int used_times = 0;

if (history != null && history.size >= 7) {
for (var i = 0; i < 7; i++) {
used_times += int.parse (history.get (i).uses);
}
}

return _("%d per week").printf (used_times);
}

public override Widget to_widget () {
var w = new Adw.ActionRow () {
title = @"#$name",
Expand Down
5 changes: 4 additions & 1 deletion src/Dialogs/Composer/Completion/HashtagProvider.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ public class Tuba.HashtagProvider: Tuba.CompletionProvider {
}

public override void display (GtkSource.CompletionContext context, GtkSource.CompletionProposal proposal, GtkSource.CompletionCell cell) {
var tag = (proposal as Proposal)?.tag;
return_if_fail (tag != null);

switch (cell.get_column ()) {
case GtkSource.CompletionColumn.ICON:
cell.set_icon_name ("tuba-hashtag-symbolic");
break;
case GtkSource.CompletionColumn.TYPED_TEXT:
cell.set_text (proposal.get_typed_text ());
cell.set_markup (@"<b>$(tag.name)</b>\n<span alpha='50%'>$(tag.weekly_use ())</span>");
break;
default:
cell.text = null;
Expand Down