Skip to content

Commit

Permalink
Added GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Release-Candidate committed Apr 6, 2021
1 parent f1fc308 commit 6e5bd4c
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 62 deletions.
10 changes: 5 additions & 5 deletions src/Tzolkin.Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" />
<application android:label="Tzolkin.Android"></application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.RC.Tzolkin" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" />
<application android:label="Tzolkin.Android"></application>
</manifest>
5 changes: 4 additions & 1 deletion src/Tzolkin.Android/Tzolkin.Android.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<MandroidI18n />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugSymbols>false</DebugSymbols>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
Expand All @@ -59,6 +59,9 @@
<EnableLLVM>false</EnableLLVM>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<BundleAssemblies>false</BundleAssemblies>
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
<AndroidLinkMode>Full</AndroidLinkMode>
<MandroidI18n />
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.FSharp.targets" />
<Import Project="..\packages\Xamarin.AndroidX.MultiDex.2.0.1.1\build\monoandroid90\Xamarin.AndroidX.MultiDex.targets" Condition="Exists('..\packages\Xamarin.AndroidX.MultiDex.2.0.1.1\build\monoandroid90\Xamarin.AndroidX.MultiDex.targets')" />
Expand Down
193 changes: 137 additions & 56 deletions src/Tzolkin/Tzolkin.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,109 @@
/// The namespace of the IOS and Android Tzolkin app.
namespace TzolkinApp

open System
open System.Diagnostics
open Fabulous
open Fabulous.XamarinForms
open Fabulous.XamarinForms.LiveUpdate
open Xamarin.Forms

open RC.Maya.TzolkinDate
open RC.Maya

/// The module holds the IOS and Android app.
module App =

/// The MVU model.
type Model =
{ Count: int
Step: int
TimerOn: bool }
{ Date: System.DateTime
ListTzolkinDate: TzolkinDate.T
FilterTzolkinDate: TzolkinDate.T
FilterString: string }

/// MVU messages.
type Msg =
| Increment
| Decrement
| Reset
| SetStep of int
| TimerToggled of bool
| TimedTick
| SetDate of System.DateTime
| SetListNumber of int
| SetListGlyph of int
| SetFilterNumber of int
| SetFilterGlyph of int
| SetFilterString of string


/// Initial state of the MVU model.
let initModel = { Count = 0; Step = 1; TimerOn = false }
let initModel =
{ Date = System.DateTime.Today
ListTzolkinDate =
{ number = TzolkinNumber.T.TzolkinNumber 8
glyph = TzolkinGlyph.T.TzolkinGlyph 5 }
FilterTzolkinDate =
{ number = TzolkinNumber.T.TzolkinNumber 6
glyph = TzolkinGlyph.T.TzolkinGlyph 15 }
FilterString = "" }

/// Initialize the model and commands.
let init () = initModel, Cmd.none

let timerCmd =
async {
do! Async.Sleep 200
return TimedTick
}
|> Cmd.ofAsyncMsg

/// The update function of MVU.
let update msg model =
match msg with
| Increment ->
| SetDate date -> { model with Date = date }, Cmd.none
| SetListNumber newNum ->
{ model with
ListTzolkinDate =
{ model.ListTzolkinDate with
number = (TzolkinNumber.T.TzolkinNumber newNum) } },
Cmd.none
| SetListGlyph newGlyph ->
{ model with
Count = model.Count + model.Step },
ListTzolkinDate =
{ model.ListTzolkinDate with
glyph = (TzolkinGlyph.T.TzolkinGlyph newGlyph) } },
Cmd.none
| Decrement ->
| SetFilterNumber newNum ->
{ model with
Count = model.Count - model.Step },
FilterTzolkinDate =
{ model.FilterTzolkinDate with
number = (TzolkinNumber.T.TzolkinNumber newNum) } },
Cmd.none
| Reset -> init ()
| SetStep n -> { model with Step = n }, Cmd.none
| TimerToggled on -> { model with TimerOn = on }, (if on then timerCmd else Cmd.none)
| TimedTick ->
if model.TimerOn then
{ model with
Count = model.Count + model.Step },
timerCmd
else
model, Cmd.none
| SetFilterGlyph newGlyph ->
{ model with
FilterTzolkinDate =
{ model.FilterTzolkinDate with
glyph = (TzolkinGlyph.T.TzolkinGlyph newGlyph) } },
Cmd.none
| SetFilterString newStr -> { model with FilterString = newStr }, Cmd.none

/// Fills the list view with 21 dates that have the same Tzolk’in date.
let fillListView model =
let lastList =
TzolkinDate.getLastList 10 model.FilterTzolkinDate DateTime.Today
|> List.map (fun t -> t.ToShortDateString())
|> List.rev

let nextList =
TzolkinDate.getNextList 10 model.FilterTzolkinDate DateTime.Today
|> List.map (fun t -> t.ToShortDateString())

let strList = lastList @ nextList

List.map (fun elem -> View.TextCell elem) strList

let fillListViewFilter model =
let lastList =
TzolkinDate.filterDateList
model.FilterString
(TzolkinDate.getLastList 500 model.ListTzolkinDate DateTime.Today)
|> List.rev

let nextList =
TzolkinDate.filterDateList
model.FilterString
(TzolkinDate.getNextList 500 model.ListTzolkinDate DateTime.Today)

let strList = lastList @ nextList

List.map (fun elem -> View.TextCell elem) strList

/// The view of MVU.
let view (model: Model) dispatch =
Expand All @@ -80,43 +122,82 @@ module App =
verticalOptions = LayoutOptions.Center,
children =
[ View.Label(
text = sprintf "%d" model.Count,
text = sprintf "Tzolk’in date: %s" ((TzolkinDate.fromDate model.Date).ToString()),
horizontalOptions = LayoutOptions.Center,
width = 200.0,
horizontalTextAlignment = TextAlignment.Center
)
View.Button(
text = "Increment",
command = (fun () -> dispatch Increment),
View.DatePicker(
minimumDate = DateTime.MinValue,
maximumDate = DateTime.MaxValue,
date = DateTime.Today,
format = "dd-MM-yyyy",
dateSelected = (fun args -> SetDate args.NewDate |> dispatch),
horizontalOptions = LayoutOptions.Center
)
View.Button(
text = "Decrement",
command = (fun () -> dispatch Decrement),
horizontalOptions = LayoutOptions.Center
View.Label(
text = sprintf "Tzolk’in date: %s" (model.ListTzolkinDate.ToString()),
horizontalOptions = LayoutOptions.Center,
width = 200.0,
horizontalTextAlignment = TextAlignment.Center
)
View.Label(text = "Timer", horizontalOptions = LayoutOptions.Center)
View.Switch(
isToggled = model.TimerOn,
toggled = (fun on -> dispatch (TimerToggled on.Value)),
horizontalOptions = LayoutOptions.Center
View.Slider(
minimumMaximum = (1.0, 13.0),
minimumTrackColor = Color.Fuchsia,
thumbColor = Color.Fuchsia,
value = double (int model.ListTzolkinDate.number),
valueChanged =
(fun args ->
SetListNumber(int (args.NewValue + 0.5))
|> dispatch),
horizontalOptions = LayoutOptions.FillAndExpand
)
View.Slider(
minimumMaximum = (0.0, 10.0),
value = double model.Step,
valueChanged = (fun args -> dispatch (SetStep(int (args.NewValue + 0.5)))),
minimumMaximum = (1.0, 20.0),
minimumTrackColor = Color.Aqua,
thumbColor = Color.Aqua,
value = double (int model.ListTzolkinDate.glyph),
valueChanged =
(fun args ->
SetListGlyph(int (args.NewValue + 0.5))
|> dispatch),
horizontalOptions = LayoutOptions.FillAndExpand
)
View.ListView(items = fillListView model)
View.Label(
text = sprintf "Step size: %d" model.Step,
horizontalOptions = LayoutOptions.Center
)
View.Button(
text = "Reset",
text = sprintf "Tzolk’in date: %s" (model.FilterTzolkinDate.ToString()),
horizontalOptions = LayoutOptions.Center,
command = (fun () -> dispatch Reset),
commandCanExecute = (model <> initModel)
) ]
width = 200.0,
horizontalTextAlignment = TextAlignment.Center
)
View.Slider(
minimumMaximum = (1.0, 13.0),
minimumTrackColor = Color.Fuchsia,
thumbColor = Color.Fuchsia,
value = double (int model.FilterTzolkinDate.number),
valueChanged =
(fun args ->
SetFilterNumber(int (args.NewValue + 0.5))
|> dispatch),
horizontalOptions = LayoutOptions.FillAndExpand
)
View.Slider(
minimumMaximum = (1.0, 20.0),
minimumTrackColor = Color.Aqua,
thumbColor = Color.Aqua,
value = double (int model.FilterTzolkinDate.glyph),
valueChanged =
(fun args ->
SetFilterGlyph(int (args.NewValue + 0.5))
|> dispatch),
horizontalOptions = LayoutOptions.FillAndExpand
)
View.Entry(
text = model.FilterString,
textChanged = (fun args -> dispatch (SetFilterString args.NewTextValue)),
completed = (fun text -> dispatch (SetFilterString text))
)
View.ListView(items = fillListViewFilter model) ]
)
)

Expand Down

0 comments on commit 6e5bd4c

Please sign in to comment.