Skip to content

Commit

Permalink
Fix wallet tables for mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikKalkoken committed Jan 28, 2025
1 parent f0f7f20 commit 029ff2e
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 218 deletions.
16 changes: 10 additions & 6 deletions internal/app/ui/assetsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ const (

// AssetSearchArea is the UI area that shows the skillqueue
type AssetSearchArea struct {
assets []*assetSearchRow
Content *fyne.Container

assetCollection assetcollection.AssetCollection
assetTable *widget.Table
assets []*assetSearchRow
assetsFiltered []*assetSearchRow
colSort []assetSortDir
assetTable *widget.Table
characterNames map[int32]string
Content *fyne.Container
colSearch []string
colSort []assetSortDir
found *widget.Label
iconSortAsc fyne.Resource
iconSortDesc fyne.Resource
iconSortOff fyne.Resource
found *widget.Label
colSearch []string
searchBoxes []*widget.Entry
total *widget.Label
u *BaseUI
Expand Down Expand Up @@ -320,6 +321,9 @@ func (a *AssetSearchArea) resetSearch() {
}

func (a *AssetSearchArea) Refresh() {
if !a.u.IsDesktop() {
return // TODO: Temporary until mobile friendly version is available
}
var t string
var i widget.Importance
characterCount := a.characterCount()
Expand Down
4 changes: 2 additions & 2 deletions internal/app/ui/colonies.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func (u *BaseUI) NewColoniesArea() *ColoniesArea {
return text, align, importance
}
if a.u.IsDesktop() {
a.body = makeDataTableForDesktop(headers, &a.rows, makeDataLabel)
a.body = makeDataTableForDesktop(headers, &a.rows, makeDataLabel, nil)
} else {
a.body = makeDataTableForMobile(headers, &a.rows, makeDataLabel)
a.body = makeDataTableForMobile(headers, &a.rows, makeDataLabel, nil)
}
top := container.NewVBox(a.top, widget.NewSeparator())
a.Content = container.NewBorder(top, nil, nil, nil, a.body)
Expand Down
15 changes: 8 additions & 7 deletions internal/app/ui/mobile/mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,14 @@ func NewMobileUI(fyneApp fyne.App) *MobileUI {
crossNav.Push(NewAppBar("Overview", u.OverviewArea.Content))
},
),
NewNavListItemWithIcon(
theme.NewThemedResource(ui.IconInventory2Svg),
"Asset Search",
func() {
crossNav.Push(NewAppBar("Asset Search", u.AssetSearchArea.Content))
},
),
// TODO: Enable once mobile friendly version is available
// NewNavListItemWithIcon(
// theme.NewThemedResource(ui.IconInventory2Svg),
// "Asset Search",
// func() {
// crossNav.Push(NewAppBar("Asset Search", u.AssetSearchArea.Content))
// },
// ),
NewNavListItemWithIcon(
theme.NewThemedResource(ui.IconMapMarkerSvg),
"Locations",
Expand Down
24 changes: 12 additions & 12 deletions internal/app/ui/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ type overviewCharacter struct {
type OverviewArea struct {
Content fyne.CanvasObject

characters []overviewCharacter
body fyne.CanvasObject
top *widget.Label
u *BaseUI
rows []overviewCharacter
body fyne.CanvasObject
top *widget.Label
u *BaseUI
}

func (u *BaseUI) NewOverviewArea() *OverviewArea {
a := OverviewArea{
characters: make([]overviewCharacter, 0),
top: makeTopLabel(),
u: u,
rows: make([]overviewCharacter, 0),
top: makeTopLabel(),
u: u,
}
top := container.NewVBox(a.top, widget.NewSeparator())
headers := []headerDef{
Expand Down Expand Up @@ -99,9 +99,9 @@ func (u *BaseUI) NewOverviewArea() *OverviewArea {
return text, align, importance
}
if a.u.IsDesktop() {
a.body = makeDataTableForDesktop(headers, &a.characters, makeDataLabel)
a.body = makeDataTableForDesktop(headers, &a.rows, makeDataLabel, nil)
} else {
a.body = makeDataTableForMobile(headers, &a.characters, makeDataLabel)
a.body = makeDataTableForMobile(headers, &a.rows, makeDataLabel, nil)
}
a.Content = container.NewBorder(top, nil, nil, nil, a.body)
return &a
Expand All @@ -113,15 +113,15 @@ func (a *OverviewArea) Refresh() {
if err != nil {
return "", 0, err
}
if len(a.characters) == 0 {
if len(a.rows) == 0 {
return "No characters", widget.LowImportance, nil
}
walletText := ihumanize.OptionalFloat(totals.wallet, 1, "?")
assetsText := ihumanize.OptionalFloat(totals.assets, 1, "?")
unreadText := ihumanize.Optional(totals.unread, "?")
s := fmt.Sprintf(
"%d characters • %s ISK wallet • %s ISK assets • %s unread",
len(a.characters),
len(a.rows),
walletText,
assetsText,
unreadText,
Expand Down Expand Up @@ -199,7 +199,7 @@ func (a *OverviewArea) updateCharacters() (overviewTotals, error) {
totals.assets.Set(totals.assets.ValueOrZero() + c.assetValue.ValueOrZero())
}
}
a.characters = cc
a.rows = cc

// FIXME
// var hasUnread bool
Expand Down
4 changes: 2 additions & 2 deletions internal/app/ui/overview_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestOverviewUpdateCharacters(t *testing.T) {
_, err := a.updateCharacters()
// then
if assert.NoError(t, err) {
assert.Len(t, a.characters, 1)
assert.Len(t, a.rows, 1)
}
})
t.Run("can handle empty location", func(t *testing.T) {
Expand All @@ -52,7 +52,7 @@ func TestOverviewUpdateCharacters(t *testing.T) {
_, err := a.updateCharacters()
// then
if assert.NoError(t, err) {
assert.Len(t, a.characters, 1)
assert.Len(t, a.rows, 1)
}
})
}
Expand Down
30 changes: 23 additions & 7 deletions internal/app/ui/tableHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func makeDataTableForDesktop[S ~[]E, E any](
headers []headerDef,
data *S,
makeLabel func(int, E) (string, fyne.TextAlign, widget.Importance),
onSelected func(E),
) *widget.Table {
t := widget.NewTable(
func() (rows int, cols int) {
Expand All @@ -49,8 +50,8 @@ func makeDataTableForDesktop[S ~[]E, E any](
if tci.Row >= len(*data) || tci.Row < 0 {
return
}
c := (*data)[tci.Row]
cell.Text, cell.Alignment, cell.Importance = makeLabel(tci.Col, c)
r := (*data)[tci.Row]
cell.Text, cell.Alignment, cell.Importance = makeLabel(tci.Col, r)
cell.Truncation = fyne.TextTruncateClip
cell.Refresh()
},
Expand All @@ -61,12 +62,19 @@ func makeDataTableForDesktop[S ~[]E, E any](
return widget.NewLabel("Template")
}
t.UpdateHeader = func(tci widget.TableCellID, co fyne.CanvasObject) {
s := headers[tci.Col]
h := headers[tci.Col]
label := co.(*widget.Label)
label.SetText(s.text)
label.SetText(h.text)
}
t.OnSelected = func(tci widget.TableCellID) {
defer t.UnselectAll()
if onSelected != nil {
if tci.Row >= len(*data) || tci.Row < 0 {
return
}
r := (*data)[tci.Row]
onSelected(r)
}
}
for i, h := range headers {
t.SetColumnWidth(i, h.width)
Expand All @@ -78,6 +86,7 @@ func makeDataTableForMobile[S ~[]E, E any](
headers []headerDef,
data *S,
makeLabel func(int, E) (string, fyne.TextAlign, widget.Importance),
onSelected func(E),
) *widget.List {
l := widget.NewList(
func() int {
Expand All @@ -101,11 +110,11 @@ func makeDataTableForMobile[S ~[]E, E any](
if id >= len(*data) || id < 0 {
return
}
c := (*data)[id]
r := (*data)[id]
for col := range len(headers) {
row := f[col*2].(*fyne.Container).Objects[1].(*fyne.Container).Objects
data := row[1].(*widget.Label)
data.Text, _, data.Importance = makeLabel(col, c)
data.Text, _, data.Importance = makeLabel(col, r)
data.Truncation = fyne.TextTruncateEllipsis
bg := f[col*2].(*fyne.Container).Objects[0]
if col == 0 {
Expand All @@ -128,7 +137,14 @@ func makeDataTableForMobile[S ~[]E, E any](
},
)
l.OnSelected = func(id widget.ListItemID) {
l.UnselectAll()
defer l.UnselectAll()
if onSelected != nil {
if id >= len(*data) || id < 0 {
return
}
r := (*data)[id]
onSelected(r)
}
}
return l
}
24 changes: 12 additions & 12 deletions internal/app/ui/training.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ type trainingCharacter struct {
type TrainingArea struct {
Content *fyne.Container

body fyne.CanvasObject
characters []trainingCharacter
top *widget.Label
u *BaseUI
body fyne.CanvasObject
rows []trainingCharacter
top *widget.Label
u *BaseUI
}

func (u *BaseUI) NewTrainingArea() *TrainingArea {
a := TrainingArea{
characters: make([]trainingCharacter, 0),
top: makeTopLabel(),
u: u,
rows: make([]trainingCharacter, 0),
top: makeTopLabel(),
u: u,
}
headers := []headerDef{
{"Name", 250},
Expand Down Expand Up @@ -68,9 +68,9 @@ func (u *BaseUI) NewTrainingArea() *TrainingArea {
return text, align, importance
}
if a.u.IsDesktop() {
a.body = makeDataTableForDesktop(headers, &a.characters, makeDataLabel)
a.body = makeDataTableForDesktop(headers, &a.rows, makeDataLabel, nil)
} else {
a.body = makeDataTableForMobile(headers, &a.characters, makeDataLabel)
a.body = makeDataTableForMobile(headers, &a.rows, makeDataLabel, nil)
}
top2 := container.NewVBox(a.top, widget.NewSeparator())
a.Content = container.NewBorder(top2, nil, nil, nil, a.body)
Expand All @@ -83,11 +83,11 @@ func (a *TrainingArea) Refresh() {
if err != nil {
return "", 0, err
}
if len(a.characters) == 0 {
if len(a.rows) == 0 {
return "No characters", widget.LowImportance, nil
}
spText := ihumanize.Optional(totalSP, "?")
s := fmt.Sprintf("%d characters • %s Total SP", len(a.characters), spText)
s := fmt.Sprintf("%d characters • %s Total SP", len(a.rows), spText)
return s, widget.MediumImportance, nil
}()
if err != nil {
Expand Down Expand Up @@ -130,6 +130,6 @@ func (a *TrainingArea) updateCharacters() (optional.Optional[int], error) {
totalSP.Set(totalSP.ValueOrZero() + c.totalSP.ValueOrZero())
}
}
a.characters = cc
a.rows = cc
return totalSP, nil
}
Loading

0 comments on commit 029ff2e

Please sign in to comment.