Skip to content

Commit 32f0055

Browse files
committed
refactor: move infowindow into own package
1 parent e7aa641 commit 32f0055

File tree

7 files changed

+122
-104
lines changed

7 files changed

+122
-104
lines changed
Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package ui
1+
// Package infowindow provides a window for displaying information about Eve objects.
2+
package infowindow
23

34
import (
45
"context"
@@ -109,7 +110,8 @@ type Settings interface {
109110
PreferMarketTab() bool
110111
}
111112

112-
// InfoWindow represents a dedicated window for showing information similar to the in-game info windows.
113+
// InfoWindow represents a dedicated window for showing information about Eve objects
114+
// similar to the in-game info window.
113115
type InfoWindow struct {
114116
cs CS
115117
eis EIS
@@ -125,50 +127,64 @@ type InfoWindow struct {
125127
w fyne.Window
126128
}
127129

128-
type InfoWindowParams struct {
129-
cs CS
130-
eis EIS
131-
eus EUS
132-
isMobile bool
133-
js *janiceservice.JaniceService
134-
scs SCS
135-
settings Settings
136-
u UIService
137-
w fyne.Window
130+
type Params struct {
131+
CharacterService CS
132+
EveImageService EIS
133+
EveUniverseService EUS
134+
IsMobile bool
135+
JaniceService *janiceservice.JaniceService
136+
StatusCacheService SCS
137+
Settings Settings
138+
UIService UIService
139+
Window fyne.Window
138140
}
139141

140-
// NewInfoWindow returns a configured InfoWindow.
141-
func NewInfoWindow(arg InfoWindowParams) *InfoWindow {
142+
// New returns a configured InfoWindow.
143+
func New(arg Params) *InfoWindow {
142144
iw := &InfoWindow{
143-
cs: arg.cs,
144-
eis: arg.eis,
145-
eus: arg.eus,
146-
isMobile: arg.isMobile,
147-
js: arg.js,
148-
scs: arg.scs,
149-
settings: arg.settings,
150-
u: arg.u,
151-
w: arg.w,
145+
cs: arg.CharacterService,
146+
eis: arg.EveImageService,
147+
eus: arg.EveUniverseService,
148+
isMobile: arg.IsMobile,
149+
js: arg.JaniceService,
150+
scs: arg.StatusCacheService,
151+
settings: arg.Settings,
152+
u: arg.UIService,
153+
w: arg.Window,
154+
}
155+
if iw.cs == nil ||
156+
iw.eis == nil ||
157+
iw.eus == nil ||
158+
iw.js == nil ||
159+
iw.scs == nil ||
160+
iw.settings == nil ||
161+
iw.u == nil ||
162+
iw.w == nil {
163+
panic(app.ErrInvalid)
152164
}
153165
return iw
154166
}
155167

156168
// ShowEveEntity shows a new info window for an EveEntity.
157169
func (iw *InfoWindow) ShowEveEntity(ee *app.EveEntity) {
158-
iw.show(eveEntity2InfoVariant(ee), int64(ee.ID))
170+
iw.show(eveEntity2InfoVariant(ee), ee.ID)
159171
}
160172

161173
// Show shows a new info window for an EveEntity.
162174
func (iw *InfoWindow) Show(c app.EveEntityCategory, id int64) {
163-
iw.show(eveEntity2InfoVariant(&app.EveEntity{Category: c}), int64(id))
175+
iw.show(eveEntity2InfoVariant(&app.EveEntity{Category: c}), id)
164176
}
165177

166178
func (iw *InfoWindow) ShowLocation(id int64) {
167179
iw.show(infoLocation, id)
168180
}
169181

170182
func (iw *InfoWindow) ShowRace(id int64) {
171-
iw.show(infoRace, int64(id))
183+
iw.show(infoRace, id)
184+
}
185+
186+
func (iw *InfoWindow) ShowTypeWithCharacter(typeID, characterID int64) {
187+
iw.showWithCharacterID(infoInventoryType, typeID, characterID)
172188
}
173189

174190
// infoWidget defines common functionality for all info widgets.
@@ -219,30 +235,30 @@ func (iw *InfoWindow) showWithCharacterID(v infoVariant, entityID int64, charact
219235
switch v {
220236
case infoAlliance:
221237
title = "Alliance"
222-
page = newAllianceInfo(iw, int64(entityID))
238+
page = newAllianceInfo(iw, entityID)
223239
case infoCharacter:
224240
title = "Character"
225-
page = newCharacterInfo(iw, int64(entityID))
241+
page = newCharacterInfo(iw, entityID)
226242
case infoConstellation:
227243
title = "Constellation"
228-
page = newConstellationInfo(iw, int64(entityID))
244+
page = newConstellationInfo(iw, entityID)
229245
case infoCorporation:
230246
title = "Corporation"
231-
page = newCorporationInfo(iw, int64(entityID))
247+
page = newCorporationInfo(iw, entityID)
232248
case infoInventoryType:
233-
x := newInventoryTypeInfo(iw, int64(entityID), characterID)
249+
x := newInventoryTypeInfo(iw, entityID, characterID)
234250
x.setTitle = func(s string) { ab.SetTitle(makeAppBarTitle(s)) }
235251
page = x
236252
title = "Item"
237253
case infoRace:
238254
title = "Race"
239-
page = newRaceInfo(iw, int64(entityID))
255+
page = newRaceInfo(iw, entityID)
240256
case infoRegion:
241257
title = "Region"
242-
page = newRegionInfo(iw, int64(entityID))
258+
page = newRegionInfo(iw, entityID)
243259
case infoSolarSystem:
244260
title = "Solar System"
245-
page = newSolarSystemInfo(iw, int64(entityID))
261+
page = newSolarSystemInfo(iw, entityID)
246262
case infoLocation:
247263
title = "Location"
248264
page = newLocationInfo(iw, entityID)
@@ -295,7 +311,7 @@ func (iw *InfoWindow) showWithCharacterID(v infoVariant, entityID int64, charact
295311
}()
296312
}
297313

298-
func (iw *InfoWindow) showZoomWindow(title string, id int64, load loadFuncAsync, w fyne.Window) {
314+
func (iw *InfoWindow) showZoomWindow(title string, id int64, load func(int64, int, func(fyne.Resource)), w fyne.Window) {
299315
w2, created := iw.u.GetOrCreateWindow(fmt.Sprintf("zoom-window-%d", id), title)
300316
if !created {
301317
w2.Show()
@@ -458,7 +474,7 @@ func eveEntity2InfoVariant(ee *app.EveEntity) infoVariant {
458474

459475
}
460476

461-
func infoWindowSupportedEveEntities() set.Set[app.EveEntityCategory] {
477+
func InfoWindowSupportedEveEntities() set.Set[app.EveEntityCategory] {
462478
return set.Collect(maps.Keys(eveEntityCategory2InfoVariant))
463479

464480
}
@@ -1290,7 +1306,7 @@ func (a *locationInfo) update(ctx context.Context) error {
12901306
if o.Variant() != app.EveLocationStation {
12911307
return nil
12921308
}
1293-
ss, err := a.iw.eus.GetStationServicesESI(ctx, int64(a.id))
1309+
ss, err := a.iw.eus.GetStationServicesESI(ctx, a.id)
12941310
if err != nil {
12951311
return err
12961312
}
@@ -2284,7 +2300,7 @@ func (a *inventoryTypeInfo) makeRequirementsTab(requiredSkills []requiredSkill)
22842300
list.OnSelected = func(id widget.ListItemID) {
22852301
defer list.UnselectAll()
22862302
r := requiredSkills[id]
2287-
a.iw.show(infoInventoryType, int64(r.typeID))
2303+
a.iw.show(infoInventoryType, r.typeID)
22882304
}
22892305
return container.NewTabItem("Requirements", list)
22902306
}
@@ -2453,7 +2469,7 @@ func (w *attributeList) set(items []attributeItem) {
24532469
}
24542470

24552471
func (w *attributeList) CreateRenderer() fyne.WidgetRenderer {
2456-
supportedCategories := infoWindowSupportedEveEntities()
2472+
supportedCategories := InfoWindowSupportedEveEntities()
24572473
l := widget.NewList(
24582474
func() int {
24592475
return len(w.items)
@@ -2609,7 +2625,7 @@ func newEntityItem(id int64, category, text string, v infoVariant) entityItem {
26092625

26102626
func newEntityItemFromEvePlanet(o *app.EvePlanet) entityItem {
26112627
return entityItem{
2612-
id: int64(o.ID),
2628+
id: o.ID,
26132629
category: "Planet",
26142630
text: o.Name,
26152631
infoVariant: infoNotSupported,
@@ -2619,22 +2635,22 @@ func newEntityItemFromEvePlanet(o *app.EvePlanet) entityItem {
26192635
func newEntityItemFromEveSolarSystem(o *app.EveSolarSystem) entityItem {
26202636
ee := o.EveEntity()
26212637
return entityItem{
2622-
id: int64(ee.ID),
2638+
id: ee.ID,
26232639
category: ee.CategoryDisplay(),
26242640
textSegments: o.DisplayRichText(),
26252641
infoVariant: eveEntity2InfoVariant(ee),
26262642
}
26272643
}
26282644

26292645
func newEntityItemFromEveEntity(ee *app.EveEntity) entityItem {
2630-
return newEntityItem(int64(ee.ID), ee.CategoryDisplay(), ee.Name, eveEntity2InfoVariant(ee))
2646+
return newEntityItem(ee.ID, ee.CategoryDisplay(), ee.Name, eveEntity2InfoVariant(ee))
26312647
}
26322648

26332649
func newEntityItemFromEveEntityWithText(ee *app.EveEntity, text string) entityItem {
26342650
if text == "" {
26352651
text = ee.Name
26362652
}
2637-
return newEntityItem(int64(ee.ID), ee.CategoryDisplay(), text, eveEntity2InfoVariant(ee))
2653+
return newEntityItem(ee.ID, ee.CategoryDisplay(), text, eveEntity2InfoVariant(ee))
26382654
}
26392655

26402656
// entityList is a list widget for showing entities.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package infowindow
2+
3+
// import (
4+
// "context"
5+
// "testing"
6+
7+
// "fyne.io/fyne/v2/test"
8+
9+
// "github.com/ErikKalkoken/evebuddy/internal/app/testutil"
10+
// )
11+
12+
// func TestInfoWindow_CanRenderLocationInfo(t *testing.T) {
13+
// test.ApplyTheme(t, test.Theme())
14+
// db, st, factory := testutil.NewDBOnDisk(t)
15+
// defer db.Close()
16+
// u := MakeFakeBaseUI(st, test.NewTempApp(t), true)
17+
// ctx := context.Background()
18+
// makeInfoWindow := func() *InfoWindow {
19+
// return NewInfoWindow(InfoWindowParams{
20+
// cs: u.cs,
21+
// eis: u.eis,
22+
// eus: u.eus,
23+
// isMobile: u.isMobile,
24+
// js: u.js,
25+
// settings: u.settings,
26+
// scs: u.scs,
27+
// u: u,
28+
// w: u.MainWindow(),
29+
// })
30+
// }
31+
// t.Run("can render full location", func(t *testing.T) {
32+
// l := factory.CreateEveLocationStation()
33+
// iw := makeInfoWindow()
34+
// a := newLocationInfo(iw, l.ID)
35+
// a.update(ctx)
36+
// test.RenderObjectToMarkup(a)
37+
// })
38+
// t.Run("can render minimal location", func(t *testing.T) {
39+
// l := factory.CreateEveLocationEmptyStructure()
40+
// iw := makeInfoWindow()
41+
// a := newLocationInfo(iw, l.ID)
42+
// a.update(ctx)
43+
// test.RenderObjectToMarkup(a)
44+
// })
45+
// }

internal/app/ui/typeattributeitem.go renamed to internal/app/infowindow/typeattributeitem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ui
1+
package infowindow
22

33
import (
44
"fyne.io/fyne/v2"

internal/app/ui/assetbrowser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func (a *assetBrowserNavigation) clear() {
342342
a.footer.SetText("")
343343
}
344344

345-
func (a *assetBrowserNavigation) update(ctx context.Context, trees []*asset.Node) {
345+
func (a *assetBrowserNavigation) update(_ context.Context, trees []*asset.Node) {
346346
filteredTrees := make(map[assetFilter]filteredTree)
347347
for _, f := range a.filters {
348348
td := generateTreeData(trees, f, a.ab.forCorporation)

internal/app/ui/gamesearch.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/ErikKalkoken/evebuddy/internal/app"
2020
"github.com/ErikKalkoken/evebuddy/internal/app/icons"
21+
"github.com/ErikKalkoken/evebuddy/internal/app/infowindow"
2122
awidget "github.com/ErikKalkoken/evebuddy/internal/app/widget"
2223
iwidget "github.com/ErikKalkoken/evebuddy/internal/widget"
2324
"github.com/ErikKalkoken/evebuddy/internal/xslices"
@@ -54,7 +55,7 @@ func newGameSearch(u *baseUI) *gameSearch {
5455
entry: widget.NewEntry(),
5556
indicator: widget.NewProgressBarInfinite(),
5657
resultCount: widget.NewLabel(""),
57-
supportedCategories: infoWindowSupportedEveEntities(),
58+
supportedCategories: infowindow.InfoWindowSupportedEveEntities(),
5859
u: u,
5960
w: u.MainWindow(),
6061
}
@@ -265,7 +266,7 @@ func (a *gameSearch) makeRecentSelected() *widget.List {
265266
return len(a.recentItems)
266267
},
267268
func() fyne.CanvasObject {
268-
return newSearchResult(a.u.eis, a.u.eus, infoWindowSupportedEveEntities())
269+
return newSearchResult(a.u.eis, a.u.eus, infowindow.InfoWindowSupportedEveEntities())
269270
},
270271
func(id widget.ListItemID, co fyne.CanvasObject) {
271272
if id >= len(a.recentItems) {

internal/app/ui/infowindow_internal_test.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)