From 67a5ac06f07278efede523960bf6da66c842aa06 Mon Sep 17 00:00:00 2001 From: bleakgrey Date: Wed, 25 Apr 2018 17:30:44 +0300 Subject: [PATCH] Stub account view --- data/Application.css | 5 ++++ src/API/Account.vala | 9 ++++++++ src/NetManager.vala | 4 ++-- src/Utils.vala | 1 + src/Views/AccountView.vala | 47 ++++++++++++++++++++++++++++++++------ 5 files changed, 57 insertions(+), 9 deletions(-) diff --git a/data/Application.css b/data/Application.css index 9664d7e..6b2240f 100644 --- a/data/Application.css +++ b/data/Application.css @@ -18,3 +18,8 @@ .toot-text{ background: none; } + +.header{ + background-size: cover; + opacity: 0.1; +} diff --git a/src/API/Account.vala b/src/API/Account.vala index 00030f2..75f7e65 100644 --- a/src/API/Account.vala +++ b/src/API/Account.vala @@ -5,8 +5,12 @@ public class Tootle.Account{ public string acct; public string display_name; public string note; + public string header; public string avatar; public string url; + public int64 followers_count; + public int64 following_count; + public int64 statuses_count; public Account(int64 id){ this.id = id; @@ -23,7 +27,12 @@ public class Tootle.Account{ account.display_name = account.username; account.note = obj.get_string_member ("note"); account.avatar = obj.get_string_member ("avatar"); + account.header = obj.get_string_member ("header"); account.url = obj.get_string_member ("url"); + + account.followers_count = obj.get_int_member ("followers_count"); + account.following_count = obj.get_int_member ("following_count"); + account.statuses_count = obj.get_int_member ("statuses_count"); return account; } diff --git a/src/NetManager.vala b/src/NetManager.vala index ec86f9c..4e5b4ed 100644 --- a/src/NetManager.vala +++ b/src/NetManager.vala @@ -47,7 +47,7 @@ public class Tootle.NetManager : GLib.Object{ public static Json.Object parse(Soup.Message msg) throws GLib.Error{ // stdout.printf ("Status Code: %u\n", msg.status_code); // stdout.printf ("Message length: %lld\n", msg.response_body.length); - //stdout.printf ("Data: \n%s\n", (string) msg.response_body.data); + // stdout.printf ("Object: \n%s\n", (string) msg.response_body.data); var parser = new Json.Parser (); parser.load_from_data ((string) msg.response_body.flatten ().data, -1); @@ -57,7 +57,7 @@ public class Tootle.NetManager : GLib.Object{ public static Json.Array parse_array(Soup.Message msg) throws GLib.Error{ // stdout.printf ("Status Code: %u\n", msg.status_code); // stdout.printf ("Message length: %lld\n", msg.response_body.length); - //stdout.printf ("Data: \n%s\n", (string) msg.response_body.data); + // stdout.printf ("Array: \n%s\n", (string) msg.response_body.data); var parser = new Json.Parser (); parser.load_from_data ((string) msg.response_body.flatten ().data, -1); diff --git a/src/Utils.vala b/src/Utils.vala index 992c226..a0d4ecf 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -8,6 +8,7 @@ public class Tootle.Utils{ .replace("rel=\"tag\"", "") .replace("rel=\"nofollow noopener\"", "") .replace("class=\"mention hashtag\"", "") + .replace("class=\"mention\"", "") .replace("class=\"h-card\"", "") .replace("class=\"invisible\"", "") .replace("class=\"ellipsis\"", "") diff --git a/src/Views/AccountView.vala b/src/Views/AccountView.vala index 111388f..6695129 100644 --- a/src/Views/AccountView.vala +++ b/src/Views/AccountView.vala @@ -5,31 +5,48 @@ public class Tootle.AccountView : Tootle.AbstractView { Account account; - Gtk.Box header; + Gtk.Grid header; + Gtk.Grid header_image; Granite.Widgets.Avatar avatar; Gtk.Label display_name; Gtk.Label username; Gtk.Label note; + Gtk.Grid counters; construct { - header = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); - header.margin = 16; + header = new Gtk.Grid (); avatar = new Granite.Widgets.Avatar.with_default_icon (128); - header.pack_start (avatar, false, false, 0); + avatar.hexpand = true; + avatar.margin_top = 16; + avatar.margin_bottom = 16; + header.attach (avatar, 0, 1, 1, 1); display_name = new Gtk.Label (""); display_name.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL); - header.pack_start (display_name, false, false, 0); + header.attach (display_name, 0, 2, 1, 1); + username = new Gtk.Label (""); username.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL); - header.pack_start (username, false, false, 0); + header.attach (username, 0, 3, 1, 1); + note = new Gtk.Label (""); note.set_use_markup (true); note.set_line_wrap (true); note.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL); note.justify = Gtk.Justification.CENTER; - header.pack_start (note, false, false, 0); + note.margin_start = 16; + note.margin_end = 16; + header.attach (note, 0, 4, 1, 1); + + counters = new Gtk.Grid (); + counters.margin_top = 16; + counters.column_homogeneous = true; + header.attach (counters, 0, 5, 1, 1); + + header_image = new Gtk.Grid (); + header_image.get_style_context ().add_class ("header"); + header.attach (header_image, 0, 1, 1, 5); view.pack_start (header, false, false, 0); } @@ -42,6 +59,22 @@ public class Tootle.AccountView : Tootle.AbstractView { username.label = "@" + account.acct; note.label = Utils.escape_html (account.note); CacheManager.instance.load_avatar (account.avatar, avatar, 128); + + add_counter (_("Toots"), 1, account.statuses_count); + add_counter (_("Follows"), 2, account.following_count); + add_counter (_("Followers"), 3, account.followers_count); + show_all (); + + var stylesheet = ".header{background-image: url(\"%s\")}".printf (account.header); + var css_provider = Granite.Widgets.Utils.get_css_provider (stylesheet); + header_image.get_style_context ().add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } + + private void add_counter (string name, int i, int64 val){ + var label_name = new Gtk.Label (name); + var label_val = new Gtk.Label (val.to_string ()); + counters.attach (label_name, i, 1, 1, 1); + counters.attach (label_val, i, 2, 1, 1); } }