Skip to content

Instantly share code, notes, and snippets.

@jmgomez
Last active December 19, 2015 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmgomez/5127e434e83cf2c97c4e to your computer and use it in GitHub Desktop.
Save jmgomez/5127e434e83cf2c97c4e to your computer and use it in GitHub Desktop.
module View =
type MoviePage (movie:Model.Movie) as this =
inherit ContentPage()
do
let title = Label(Text = movie.Title, FontSize = 18., FontAttributes = FontAttributes.Bold, TextColor = Color.Accent)
this.Title <- movie.Title
let img = Image(Source=ImageSource.FromUri(Uri(movie.ImagePath)))
let overview = Label(Text = movie.Overview)
let layout = RelativeLayout()
let m = 10.
let margin = Constraint.Constant m
layout.Children.Add(img, margin, margin)
layout.Children.Add(title,
Constraint.RelativeToView(img, Func<_,_,_>(fun p v -> v.Width + m*2.)),
Constraint.RelativeToView(img, Func<_,_,_>(fun p v -> v.Height / 2.)),
Constraint.RelativeToView(img, Func<_,_,_>(fun p v -> p.Width - v.Width - m*2. )))
layout.Children.Add(overview,
margin,
Constraint.RelativeToView(img, Func<_,_,_>(fun p v -> v.Height + m*3.)),
Constraint.RelativeToParent(Func<_,_>(fun p -> p.Width - m*3.)),
Constraint.RelativeToParent(Func<_,_>(fun p -> p.Width - overview.Y)))
this.Content <- layout
type MovieCell () =
inherit ImageCell()
do
base.SetBinding(TextCell.DetailProperty, "Overview")
base.SetBinding(TextCell.TextProperty, "Title")
base.SetBinding(ImageCell.ImageSourceProperty, "ImagePath")
type MoviesPage () as this =
inherit ContentPage()
let movies = ObservableCollection<Model.Movie>()
let mutable currentPage = 1
let times = 3
let loadMovies() =
if not this.IsBusy then
Device.BeginInvokeOnMainThread(fun _ ->
this.IsBusy <- true
TheMovieDB.getMovies (currentPage, times)
|> Array.iter (movies.Add)
currentPage <- currentPage + times
this.IsBusy <- false)
do
this.Title <- "Movies"
loadMovies()
let lv = ListView(ItemsSource=movies, SeparatorVisibility=SeparatorVisibility.None, RowHeight=100)
lv.ItemAppearing.Add(fun(cell)-> if((cell.Item:?>Model.Movie) = movies.Last()) then loadMovies())
lv.ItemTemplate <- DataTemplate(typeof<MovieCell>)
lv.ItemSelected.Add(fun(item)->this.Navigation.PushAsync(MoviePage(lv.SelectedItem:?>Model.Movie)) |> ignore)
base.Content <- lv
type TheMovieDB () =
inherit Application()
member x.Start() =
base.MainPage <- NavigationPage(MoviesPage())
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment