Skip to content

Commit

Permalink
Frontend.Maui: add BalancesPage
Browse files Browse the repository at this point in the history
Add BalancesPage.

Fixed and simplified layout of BalancesPage.

Fix layout of currency balances on balances page in Maui.

Fix circle chart rendering in Maui.

Use Launcher from Maui.Essentials on Maui instead of one from
Xamarin.Essentials.

Made click event handlers work for Gtk. Had to wrap footer label
in a Frame for this.

LogoImg had wrong size and it had to be resized based on the
layout size. The reason is that Aspect for Image is not working
in Maui/Gtk and should be fixed later (see [1]).

Also added #nowarn 44 and #nowarn 1182 in BalancesPage,
CircleChartView, and FrontendHelpers because of the following
warnings:

```
BalancesPage.xaml.fs(503, 13): [FS1182] The value 'tapper' is unused
BalancesPage.xaml.fs(443, 13): [FS1182] The value 'currentChartView' is unused
BalancesPage.xaml.fs(443, 30): [FS1182] The value 'otherChartView' is unused
BalancesPage.xaml.fs(439, 41): [FS1182] The value 'totalOtherFiatAmountFrame' is unused
BalancesPage.xaml.fs(437, 13): [FS1182] The value 'switchingToReadOnly' is unused
CircleChartView.fs(181, 35): [FS0044] This construct is deprecated. The StackLayout expansion options are deprecated; please use a Grid instead.
BalancesPage.xaml.fs(53, 19): [FS1182] The value 'currencyImages' is unused
CircleChartView.fs(180, 37): [FS0044] This construct is deprecated. The StackLayout expansion options are deprecated; please use a Grid instead.
FrontendHelpers.fs(425, 60): [FS0044] This construct is deprecated. The StackLayout expansion options are deprecated; please use a Grid instead.
```

Co-authored-by: Parham <[email protected]>

[1] jsuarezruiz/maui-linux#69
  • Loading branch information
webwarrior-ws committed May 23, 2024
1 parent 3275199 commit c9a2e8c
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 69 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ fabric.properties
src/GWallet.Frontend.Maui/WelcomePage.xaml
src/GWallet.Frontend.Maui/WelcomePage2.xaml
src/GWallet.Frontend.Maui/LoadingPage.xaml
src/GWallet.Frontend.Maui/BalancesPage.xaml
2 changes: 1 addition & 1 deletion scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ let BuildSolutionOrProject
// TODO: we have to change this function to be the other way around (i.e. copy from Maui to XF) once we
// have a finished version of Maui and we consider XF as legacy.
let CopyXamlFiles() =
let files = [| "WelcomePage.xaml"; "WelcomePage2.xaml"; "LoadingPage.xaml" |]
let files = [| "WelcomePage.xaml"; "WelcomePage2.xaml"; "LoadingPage.xaml"; "BalancesPage.xaml" |]
for file in files do
let sourcePath = Path.Combine("src", "GWallet.Frontend.XF", file)
let destPath = Path.Combine("src", "GWallet.Frontend.Maui", file)
Expand Down
83 changes: 83 additions & 0 deletions src/GWallet.Frontend.Maui/GWallet.Frontend.Maui.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,94 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="..\..\img\btc_grey_60x60.png">
<Link>img\btc_grey_60x60.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\btc_red_60x60.png">
<Link>img\btc_red_60x60.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\btc_red_120x120.png">
<Link>img\btc_red_120x120.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\btc_grey_120x120.png">
<Link>img\btc_grey_120x120.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\dai_grey_60x60.png">
<Link>img\dai_grey_60x60.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\dai_grey_120x120.png">
<Link>img\dai_grey_120x120.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\dai_red_60x60.png">
<Link>img\dai_red_60x60.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\dai_red_120x120.png">
<Link>img\dai_red_120x120.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\sai_grey_60x60.png">
<Link>img\sai_grey_60x60.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\sai_grey_120x120.png">
<Link>img\sai_grey_120x120.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\sai_red_60x60.png">
<Link>img\sai_red_60x60.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\sai_red_120x120.png">
<Link>img\sai_red_120x120.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\etc_grey_60x60.png">
<Link>img\etc_grey_60x60.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\etc_grey_120x120.png">
<Link>img\etc_grey_120x120.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\etc_red_60x60.png">
<Link>img\etc_red_60x60.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\etc_red_120x120.png">
<Link>img\etc_red_120x120.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\eth_grey_60x60.png">
<Link>img\eth_grey_60x60.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\eth_grey_120x120.png">
<Link>img\eth_grey_120x120.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\eth_red_60x60.png">
<Link>img\eth_red_60x60.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\eth_red_120x120.png">
<Link>img\eth_red_120x120.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\ltc_grey_60x60.png">
<Link>img\ltc_grey_60x60.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\ltc_grey_120x120.png">
<Link>img\ltc_grey_120x120.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\ltc_red_60x60.png">
<Link>img\ltc_red_60x60.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\ltc_red_120x120.png">
<Link>img\ltc_red_120x120.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\img\logo_512x512.png">
<Link>img\logo_512x512.png</Link>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="BalancesPage.xaml" />
<EmbeddedResource Include="LoadingPage.xaml" />
<EmbeddedResource Include="WelcomePage.xaml" />
<EmbeddedResource Include="WelcomePage2.xaml" />
<Compile Include="..\GWallet.Frontend.XF\Controls\CircleChartView.fs" />
<Compile Include="..\GWallet.Frontend.XF\FrontendHelpers.fs" />
<Compile Include="..\GWallet.Frontend.XF\GlobalState.fs" />
<Compile Include="..\GWallet.Frontend.XF\BalancesPage.xaml.fs">
<DependentUpon>BalancesPage.xaml</DependentUpon>
</Compile>
<Compile Include="..\GWallet.Frontend.XF\LoadingPage.xaml.fs">
<DependentUpon>LoadingPage.xaml</DependentUpon>
</Compile>
Expand Down
59 changes: 51 additions & 8 deletions src/GWallet.Frontend.XF/BalancesPage.xaml.fs
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
namespace GWallet.Frontend.XF
#if XAMARIN
namespace GWallet.Frontend.XF
#else
namespace GWallet.Frontend.Maui
// We have unused variables because they are in the #XAMARIN sections.
// this should be removed once we fully integrate this code.
#nowarn "1182"
#endif

open System
open System.Linq
open System.Threading
open System.Threading.Tasks

#if !XAMARIN
open Microsoft.Maui
open Microsoft.Maui.Controls
open Microsoft.Maui.Controls.Xaml
open Microsoft.Maui.ApplicationModel
open Microsoft.Maui.Networking
#else
open Xamarin.Forms
open Xamarin.Forms.Xaml
open Xamarin.Essentials
#endif

open Fsdk

#if XAMARIN
open GWallet.Frontend.XF.Controls
#else
open GWallet.Frontend.Maui.Controls
#endif
open GWallet.Backend
open GWallet.Backend.FSharpUtil.UwpHacks

Expand Down Expand Up @@ -217,7 +237,12 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState,
let activeCurrencyClassId,inactiveCurrencyClassId =
FrontendHelpers.GetActiveAndInactiveCurrencyClassIds readOnly

let contentLayoutChildrenList = (contentLayout.Children |> List.ofSeq)
let contentLayoutChildrenList =
#if XAMARIN
(contentLayout.Children |> List.ofSeq)
#else
contentLayout.Children |> Seq.choose (function :? View as view -> Some view | _ -> None) |> List.ofSeq
#endif

let activeCryptoBalances = FindCryptoBalances activeCurrencyClassId
contentLayout
Expand Down Expand Up @@ -247,19 +272,23 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState,
balances |> Seq.iteri (fun balanceIndex balanceState ->
let balanceSet = balanceState.BalanceSet
let tapGestureRecognizer = TapGestureRecognizer()
#if XAMARIN
tapGestureRecognizer.Tapped.Subscribe(fun _ ->
let receivePage () =
ReceivePage(balanceSet.Account, readOnly, balanceState.UsdRate, self, balanceSet.Widgets)
:> Page
FrontendHelpers.SwitchToNewPage self receivePage true
) |> ignore
#endif
let frame = balanceSet.Widgets.Frame
frame.GestureRecognizers.Add tapGestureRecognizer
contentLayout.Children.Add frame

#if XAMARIN
Grid.SetRow(frame, balanceIndex)
#else
contentLayout.SetRow(frame, balanceIndex)
#endif
)

contentLayout.BatchCommit()

member __.UpdateGlobalFiatBalanceSum (fiatBalancesList: List<MaybeCached<decimal>>) totalFiatAmountLabel =
Expand Down Expand Up @@ -370,7 +399,7 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState,
//Avoid cases when user changes timezone in device settings
TimeSpan.Zero

Device.StartTimer(timerInterval + timerStartDelay, fun _ ->
FrontendHelpers.StartTimer(timerInterval + timerStartDelay, fun _ ->
if not cancellationToken.IsCancellationRequested then
async {
try
Expand Down Expand Up @@ -418,6 +447,7 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState,
mainLayout.FindByName<CircleChartView> otherChartViewName

let tapGestureRecognizer = TapGestureRecognizer()
#if XAMARIN
tapGestureRecognizer.Tapped.Add(fun _ ->

let shouldNotOpenNewPage =
Expand Down Expand Up @@ -467,6 +497,7 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState,
FrontendHelpers.SwitchToNewPage self page true

)
#endif
totalCurrentFiatAmountFrame.GestureRecognizers.Add tapGestureRecognizer
tapGestureRecognizer

Expand All @@ -479,7 +510,11 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState,
RedrawCircleView false normalBalanceStates

if startWithReadOnlyAccounts then
#if XAMARIN
tapper.SendTapped null
#else
() // No tapper.SendTapped in MAUI
#endif

member private __.AssignColorLabels (readOnly: bool) =
let labels,color =
Expand All @@ -506,23 +541,31 @@ type BalancesPage(state: FrontendHelpers.IGlobalAppState,
self.BalanceRefreshCancelSources <- Seq.empty

member private self.Init () =
#if XAMARIN
if Device.RuntimePlatform = Device.GTK then
// workaround layout issues in Xamarin.Forms/GTK
mainLayout.RowDefinitions.[1] <- RowDefinition(
Height = GridLength 550.0
)
#endif

normalChartView.DefaultImageSource <- FrontendHelpers.GetSizedImageSource "logo" 512
readonlyChartView.DefaultImageSource <- FrontendHelpers.GetSizedImageSource "logo" 512

let tapGestureRecognizer = TapGestureRecognizer()
tapGestureRecognizer.Tapped.Subscribe(fun _ ->
tapGestureRecognizer.Tapped.Add(fun _ ->
Uri "http://www.geewallet.com"
|> Xamarin.Essentials.Launcher.OpenAsync
|> Launcher.OpenAsync
|> FrontendHelpers.DoubleCheckCompletionNonGeneric
) |> ignore
)
// On GTK, adding gesture recognizer directly to label doesn't work, so we add it to encompassing frame.
#if !XAMARIN
let footerLabelFrame = mainLayout.FindByName<Frame> "footerLabelFrame"
footerLabelFrame.GestureRecognizers.Add tapGestureRecognizer
#else
let footerLabel = mainLayout.FindByName<Label> "footerLabel"
footerLabel.GestureRecognizers.Add tapGestureRecognizer
#endif

let allNormalAccountFiatBalances =
normalBalanceStates.Select(fun balanceState -> balanceState.FiatAmount) |> List.ofSeq
Expand Down
Loading

0 comments on commit c9a2e8c

Please sign in to comment.