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

Homepage: more accurate navigation #1837

Merged
merged 9 commits into from
May 1, 2022
33 changes: 15 additions & 18 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,8 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {
return_button.clicked.connect (view_return);

homepage.package_selected.connect (package_selected);
homepage.subview_entered.connect (view_opened);
installed_view.package_selected.connect (package_selected);
installed_view.subview_entered.connect (view_opened);
search_view.package_selected.connect (package_selected);
search_view.subview_entered.connect (view_opened);
search_view.home_return_clicked.connect (() => {
stack.visible_child = homepage;
});
Expand Down Expand Up @@ -444,35 +441,35 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {
selected_package = package;
}

private void view_opened (string? return_name, bool allow_search, string? custom_header = null, string? custom_search_placeholder = null) {
public void set_return_name (string? return_name) {
if (return_name != null) {
if (return_button_history.peek_head () != return_name) {
return_button_history.offer_head (return_name);
}

return_button.label = return_name;
return_button.no_show_all = false;
return_button.visible = true;
} else {
return_button.no_show_all = true;
return_button.visible = false;
}

return_button.no_show_all = return_name == null;
return_button.visible = return_name != null;
}

public void configure_search (bool sensitive, string? placeholder_text = _("Search Apps")) {
search_entry.sensitive = sensitive;
search_entry.placeholder_text = placeholder_text;

if (sensitive) {
search_entry.grab_focus_without_selecting ();
}
}

public void set_custom_header (string? custom_header) {
if (custom_header != null) {
homepage_header.label = custom_header;
custom_title_stack.visible_child = homepage_header;
} else {
custom_title_stack.visible_child = view_mode_revealer;
}

if (custom_search_placeholder != null) {
search_entry.placeholder_text = custom_search_placeholder;
} else {
search_entry.placeholder_text = _("Search Apps");
}

search_entry.sensitive = allow_search;
search_entry.grab_focus_without_selecting ();
}

private void view_return () {
Expand Down
13 changes: 11 additions & 2 deletions src/Views/AbstractView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

public abstract class AppCenter.AbstractView : Gtk.Stack {
public signal void subview_entered (string? return_name, bool allow_search, string? custom_header = null, string? custom_search_placeholder = null);
public signal void package_selected (AppCenterCore.Package package);

protected AppCenterCore.Package? previous_package = null;
Expand All @@ -28,6 +27,14 @@ public abstract class AppCenter.AbstractView : Gtk.Stack {
get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW);
expand = true;

notify["visible-child"].connect (() => {
if (visible_child is Views.AppInfoView) {
var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window ();
main_window.set_custom_header ("");
main_window.configure_search (false);
}
});

notify["transition-running"].connect (() => {
// Transition finished
if (!transition_running) {
Expand Down Expand Up @@ -71,7 +78,9 @@ public abstract class AppCenter.AbstractView : Gtk.Stack {
show_package (_package, remember_history);
if (remember_history) {
previous_package = package;
subview_entered (package.get_name (), false, "", null);

var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window ();
main_window.set_return_name (package.get_name ());
}
transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
});
Expand Down
47 changes: 34 additions & 13 deletions src/Views/Homepage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public class AppCenter.Homepage : AbstractView {

public signal void page_loaded ();

public bool viewing_package { get; private set; default = false; }
public bool viewing_package {
get {
return visible_child is Views.AppInfoView;
}
}

public AppStream.Category? currently_viewed_category {
get {
Expand Down Expand Up @@ -189,6 +193,8 @@ public class AppCenter.Homepage : AbstractView {
destroy.connect (() => {
banner_timeout_stop ();
});

notify["visible-child"].connect (update_navigation);
}

private async void load_banners_and_carousels () {
Expand Down Expand Up @@ -265,36 +271,50 @@ public class AppCenter.Homepage : AbstractView {
bool remember_history = true
) {
base.show_package (package, remember_history);
viewing_package = true;
if (remember_history) {
current_category = null;
subview_entered (_("Home"), false, "");

var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window ();
main_window.set_return_name (_("Home"));
}
}

public override void return_clicked () {
var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window ();

if (previous_package != null) {
show_package (previous_package);
if (current_category != null) {
subview_entered (current_category.name, false, "");
main_window.set_return_name (current_category.name);
} else {
subview_entered (_("Home"), false, "");
main_window.set_return_name (_("Home"));
}
} else if (viewing_package && current_category != null) {
visible_child = get_child_by_name (current_category.name);
viewing_package = false;
subview_entered (_("Home"), true, current_category.name, _("Search %s").printf (current_category.name));

main_window.set_return_name (_("Home"));
} else {
set_visible_child (scrolled_window);
viewing_package = false;
}
}

private void update_navigation () {
var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window ();

if (visible_child is CategoryView) {
current_category = ((CategoryView) visible_child).category;
main_window.set_custom_header (current_category.name);
main_window.set_return_name (_("Home"));
main_window.configure_search (true, _("Search %s").printf (current_category.name));
} else if (visible_child == scrolled_window) {
current_category = null;
subview_entered (null, true);
main_window.set_return_name (null);
main_window.set_custom_header (null);
main_window.configure_search (true);
}
}

public void show_app_list_for_category (AppStream.Category category) {
subview_entered (_("Home"), true, category.name, _("Search %s").printf (category.name));
current_category = category;
var child = get_child_by_name (category.name);
if (child != null) {
visible_child = child;
Expand All @@ -307,9 +327,10 @@ public class AppCenter.Homepage : AbstractView {
visible_child = category_view;

category_view.show_app.connect ((package) => {
viewing_package = true;
base.show_package (package);
subview_entered (category.name, false, "");

var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window ();
main_window.set_return_name (category.name);
});
}

Expand Down
10 changes: 7 additions & 3 deletions src/Views/InstalledView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class AppCenter.Views.InstalledView : AbstractView {

app_list_view = new AppListUpdateView ();
app_list_view.show_app.connect ((package) => {
subview_entered (C_("view", "Installed"), false, "");
var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window ();
main_window.set_return_name (C_("view", "Installed"));
show_package (package);
});

Expand All @@ -52,12 +53,15 @@ public class AppCenter.Views.InstalledView : AbstractView {
}

public override void return_clicked () {
var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window ();
if (previous_package != null) {
show_package (previous_package);
subview_entered (C_("view", "Installed"), false, null);
main_window.set_return_name (C_("view", "Installed"));
} else {
set_visible_child (app_list_view);
subview_entered (null, false);
main_window.set_return_name (null);
main_window.set_custom_header (null);
main_window.configure_search (false);
}
}

Expand Down
22 changes: 17 additions & 5 deletions src/Views/SearchView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public class AppCenter.Views.SearchView : AbstractView {
app_list_view = new AppListView ();
add (app_list_view);
app_list_view.show_app.connect ((package) => {
var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window ();
/// TRANSLATORS: the name of the Search view
subview_entered (C_("view", "Search"), false);
main_window.set_return_name (C_("view", "Search"));
viewing_package = true;
show_package (package);
});
Expand All @@ -51,11 +52,17 @@ public class AppCenter.Views.SearchView : AbstractView {
set_visible_child (app_list_view);
viewing_package = false;

var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window ();
if (current_category != null) {
subview_entered (current_category.name, true, current_category.name);
main_window.set_custom_header (current_category.name);
main_window.set_return_name (current_category.name);
} else {
subview_entered (_("Home"), true);
main_window.set_custom_header (null);
main_window.set_return_name (_("Home"));
}

main_window.configure_search (true);

}
} else if (current_category != null) {
category_return_clicked (current_category);
Expand All @@ -82,11 +89,16 @@ public class AppCenter.Views.SearchView : AbstractView {
app_list_view.add_packages (found_apps);
}

var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window ();
if (current_category != null) {
subview_entered (current_category.name, true, current_category.name);
main_window.set_custom_header (current_category.name);
main_window.set_return_name (current_category.name);
} else {
subview_entered (_("Home"), true);
main_window.set_custom_header (null);
main_window.set_return_name (_("Home"));
}

main_window.configure_search (true);
}

public void reset () {
Expand Down