Skip to content

Commit

Permalink
Homepage: build AppCenter banner manually (#2137)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Mar 19, 2024
1 parent 72d8a45 commit 01cb4b9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 25 deletions.
12 changes: 7 additions & 5 deletions src/Views/Homepage.vala
Expand Up @@ -218,20 +218,22 @@ public class AppCenter.Homepage : Adw.NavigationPage {

var local_package = App.local_package;
if (local_package != null) {
var banner = new Widgets.Banner (local_package);
var banner = new Widgets.Banner.from_package (local_package);

banner_carousel.prepend (banner);

banner.clicked.connect (() => {
show_package (local_package);
});
} else {
#if PACKAGEKIT_BACKEND
appcenter_banner = new Widgets.Banner (
AppCenterCore.PackageKitBackend.get_default ().lookup_package_by_id ("appcenter")
_("AppCenter"),
_("Browse and manage apps"),
_("The open source, pay-what-you-want app store from elementary. Reviewed and curated by elementary to ensure a native, privacy-respecting, and secure experience. Browse by categories or search and discover new apps. AppCenter is also used for updating your system to the latest and greatest version for new features and fixes."),
new ThemedIcon ("io.elementary.appcenter"),
"#7239b3"
);
banner_carousel.append (appcenter_banner);
#endif

banner_carousel.page_changed.connect (page_changed_handler );
}
Expand Down Expand Up @@ -295,7 +297,7 @@ public class AppCenter.Homepage : Adw.NavigationPage {
if (!installed) {
packages_in_banner.add (package);

var banner = new Widgets.Banner (package);
var banner = new Widgets.Banner.from_package (package);
banner.clicked.connect (() => {
show_package (package);
});
Expand Down
54 changes: 34 additions & 20 deletions src/Widgets/Banner.vala
Expand Up @@ -27,33 +27,53 @@ const string DEFAULT_BANNER_COLOR_PRIMARY_TEXT = "mix(@accent_color, @text_color
const int MILLISECONDS_BETWEEN_BANNER_ITEMS = 5000;

public class AppCenter.Widgets.Banner : Gtk.Button {
public AppCenterCore.Package package { get; construct; }
public Icon icon { get; construct; }
public string brand_color { get; construct; }
public string description { get; construct; }
public string name { get; construct; }
public string summary { get; construct; }

public Banner (string name, string summary, string description, Icon icon, string brand_color) {
Object (
brand_color: brand_color,
description: description,
icon: icon,
name: name,
summary: summary
);
}

public Banner (AppCenterCore.Package package) {
Object (package: package);
public Banner.from_package (AppCenterCore.Package package) {
Object (
name: package.get_name (),
summary: package.get_summary (),
description: package.get_description (),
icon: package.get_icon (128, get_scale_factor ()),
brand_color: package.get_color_primary ()
);
}


construct {
var name_label = new Gtk.Label (package.get_name ()) {
var name_label = new Gtk.Label (name) {
max_width_chars = 50,
use_markup = true,
wrap = true,
xalign = 0
};
name_label.add_css_class ("name");

var summary_label = new Gtk.Label (package.get_summary ()) {
var summary_label = new Gtk.Label (summary) {
max_width_chars = 50,
use_markup = true,
wrap = true,
xalign = 0
};
summary_label.add_css_class ("summary");

string description = "";
if (package.get_description () != null) {
if (description != null && description != "") {
// We only want the first line/paragraph
description = package.get_description ().split ("\n")[0];
description = description.split ("\n")[0];
}

var description_label = new Gtk.Label (description) {
Expand All @@ -66,9 +86,7 @@ public class AppCenter.Widgets.Banner : Gtk.Button {
};
description_label.add_css_class ("description");

var icon_image = new Gtk.Image.from_gicon (
package.get_icon (128, get_scale_factor ())
);
var icon_image = new Gtk.Image.from_gicon (icon);

var inner_box = new Gtk.Box (VERTICAL, 0) {
valign = CENTER
Expand All @@ -95,16 +113,12 @@ public class AppCenter.Widgets.Banner : Gtk.Button {
string bg_color = DEFAULT_BANNER_COLOR_PRIMARY;
string text_color = DEFAULT_BANNER_COLOR_PRIMARY_TEXT;

if (package != null) {
var primary_color = package.get_color_primary ();

if (primary_color != null) {
var bg_rgba = Gdk.RGBA ();
bg_rgba.parse (primary_color);
if (brand_color != null) {
var bg_rgba = Gdk.RGBA ();
bg_rgba.parse (brand_color);

bg_color = primary_color;
text_color = Granite.contrasting_foreground_color (bg_rgba).to_string ();
}
bg_color = brand_color;
text_color = Granite.contrasting_foreground_color (bg_rgba).to_string ();
}

var colored_css = BANNER_STYLE_CSS.printf (bg_color, text_color);
Expand Down

0 comments on commit 01cb4b9

Please sign in to comment.