Skip to content

Commit bf6f9ed

Browse files
committed
refactor: split infowindow package files
1 parent 32f0055 commit bf6f9ed

File tree

11 files changed

+2253
-2038
lines changed

11 files changed

+2253
-2038
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package infowindow
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"fyne.io/fyne/v2"
8+
"fyne.io/fyne/v2/canvas"
9+
"fyne.io/fyne/v2/container"
10+
"fyne.io/fyne/v2/layout"
11+
"fyne.io/fyne/v2/theme"
12+
"fyne.io/fyne/v2/widget"
13+
"golang.org/x/sync/errgroup"
14+
15+
"github.com/ErikKalkoken/evebuddy/internal/app"
16+
)
17+
18+
// allianceInfo shows public information about a character.
19+
type allianceInfo struct {
20+
widget.BaseWidget
21+
baseInfo
22+
23+
attributes *attributeList
24+
hq *widget.Hyperlink
25+
id int64
26+
logo *canvas.Image
27+
members *entityList
28+
tabs *container.AppTabs
29+
}
30+
31+
func newAllianceInfo(iw *InfoWindow, id int64) *allianceInfo {
32+
hq := widget.NewHyperlink("", nil)
33+
hq.Wrapping = fyne.TextWrapWord
34+
a := &allianceInfo{
35+
id: id,
36+
logo: makeInfoLogo(),
37+
hq: hq,
38+
}
39+
a.initBase(iw)
40+
a.ExtendBaseWidget(a)
41+
a.attributes = newAttributeList(a.iw)
42+
a.members = newEntityList(a.iw.show)
43+
a.tabs = container.NewAppTabs(
44+
container.NewTabItem("Attributes", a.attributes),
45+
container.NewTabItem("Members", a.members),
46+
)
47+
return a
48+
}
49+
50+
func (a *allianceInfo) CreateRenderer() fyne.WidgetRenderer {
51+
p := theme.Padding()
52+
top := container.NewBorder(
53+
nil,
54+
nil,
55+
container.New(
56+
layout.NewCustomPaddedVBoxLayout(2*p),
57+
container.NewPadded(a.logo),
58+
container.New(
59+
layout.NewCustomPaddedHBoxLayout(3*p),
60+
layout.NewSpacer(),
61+
a.iw.makeZKillboardIcon(a.id, infoAlliance),
62+
a.iw.makeDotlanIcon(a.id, infoAlliance),
63+
a.iw.makeEveWhoIcon(a.id, infoAlliance),
64+
layout.NewSpacer(),
65+
),
66+
),
67+
nil,
68+
a.name,
69+
)
70+
c := container.NewBorder(top, nil, nil, nil, a.tabs)
71+
return widget.NewSimpleRenderer(c)
72+
}
73+
74+
func (a *allianceInfo) update(ctx context.Context) error {
75+
fyne.Do(func() {
76+
a.iw.eis.AllianceLogoAsync(a.id, app.IconPixelSize, func(r fyne.Resource) {
77+
a.logo.Resource = r
78+
a.logo.Refresh()
79+
})
80+
})
81+
g := new(errgroup.Group)
82+
g.Go(func() error {
83+
o, err := a.iw.eus.FetchAlliance(ctx, a.id)
84+
if err != nil {
85+
return err
86+
}
87+
// Attributes
88+
var attributes []attributeItem
89+
if v, ok := o.ExecutorCorporation.Value(); ok {
90+
attributes = append(attributes, newAttributeItem("Executor", v))
91+
}
92+
if o.Ticker != "" {
93+
attributes = append(attributes, newAttributeItem("Short Name", o.Ticker))
94+
}
95+
if o.CreatorCorporation != nil {
96+
attributes = append(attributes, newAttributeItem("Created By Corporation", o.CreatorCorporation))
97+
}
98+
if o.Creator != nil {
99+
attributes = append(attributes, newAttributeItem("Created By", o.Creator))
100+
}
101+
if !o.DateFounded.IsZero() {
102+
attributes = append(attributes, newAttributeItem("Start Date", o.DateFounded))
103+
}
104+
if v, ok := o.Faction.Value(); ok {
105+
attributes = append(attributes, newAttributeItem("Faction", v))
106+
}
107+
if a.iw.u.IsDeveloperMode() {
108+
x := newAttributeItem("EVE ID", o.ID)
109+
x.Action = func(_ any) {
110+
fyne.CurrentApp().Clipboard().SetContent(fmt.Sprint(o.ID))
111+
}
112+
attributes = append(attributes, x)
113+
}
114+
fyne.Do(func() {
115+
a.name.SetText(o.Name)
116+
a.attributes.set(attributes)
117+
a.tabs.Refresh()
118+
})
119+
return nil
120+
})
121+
g.Go(func() error {
122+
members, err := a.iw.eus.FetchAllianceCorporations(ctx, a.id)
123+
if err != nil {
124+
return err
125+
}
126+
if len(members) == 0 {
127+
return nil
128+
}
129+
fyne.Do(func() {
130+
a.members.set(entityItemsFromEveEntities(members)...)
131+
a.tabs.Refresh()
132+
})
133+
return nil
134+
})
135+
return g.Wait()
136+
}

0 commit comments

Comments
 (0)