Inceptum/launcher-gtk/src/main/java/io/gitlab/jfronny/inceptum/gtk/window/settings/launcher/AccountsTab.java

59 lines
2.2 KiB
Java

package io.gitlab.jfronny.inceptum.gtk.window.settings.launcher;
import io.gitlab.jfronny.inceptum.gtk.GtkMenubar;
import io.gitlab.jfronny.inceptum.gtk.control.ILabel;
import io.gitlab.jfronny.inceptum.gtk.control.settings.SettingsTab;
import io.gitlab.jfronny.inceptum.gtk.window.dialog.MicrosoftLoginDialog;
import io.gitlab.jfronny.inceptum.launcher.api.account.AccountManager;
import io.gitlab.jfronny.inceptum.launcher.api.account.MicrosoftAccount;
import org.gnome.gtk.*;
public class AccountsTab extends SettingsTab implements SettingsTab.SectionBuilder {
public AccountsTab(Window window) {
super(window);
section(null, this);
}
@Override
public void build(Section section) {
generateRows(section);
Button row = Button.newFromIconName("list-add-symbolic");
section.row(row);
row.onClicked(() -> new MicrosoftLoginDialog(window, () -> {
section.clear();
build(section);
GtkMenubar.generateAccountsMenu(window.application);
}).show());
}
private void generateRows(SectionBuilder.Section section) {
for (MicrosoftAccount account : AccountManager.getAccounts()) {
Box row = new Box(Orientation.HORIZONTAL, 40);
var ref = section.row(row);
row.margin = 8;
//TODO profile icon
Box head = new Box(Orientation.VERTICAL, 0);
head.hexpand = true;
head.halign = Align.START;
head.valign = Align.CENTER;
Label title = new Label(account.minecraftUsername);
title.halign = Align.START;
head.append(title);
Label subtitle = new Label(account.uuid);
ILabel.theme(subtitle, ILabel.Mode.SUBTITLE);
subtitle.halign = Align.START;
head.append(subtitle);
row.append(head);
Button remove = Button.newFromIconName("window-close-symbolic");
remove.valign = Align.CENTER;
remove.halign = Align.END;
remove.onClicked(() -> {
AccountManager.removeAccount(account);
section.remove(ref);
GtkMenubar.generateAccountsMenu(window.application);
});
row.append(remove);
}
}
}