Showing posts with label NP1 days of MvvmCross. Show all posts
Showing posts with label NP1 days of MvvmCross. Show all posts

Thursday, November 07, 2013

N=42 - Is my ViewModel visible? Can I kill it?

Today's N+1 is all about whether or not your ViewModel is Visible - and about how to kill it when it gets removed from the screen.


This is a fairly FAQ topic - see questions like http://stackoverflow.com/questions/15961664/viewmodel-lifecycle-when-does-it-get-disposed and http://stackoverflow.com/questions/19816819/how-are-views-and-viewmodels-freed-up-in-mvvmcross


MvvmCross doesn't provide any built-in event notification - but it is easy to add it for your app.


In this video, I show how to add and invoke interfaces like these to some view models which are shown by a standard MvvmCross presenter:




If you have custom presentation, then you'll need to adapt this technique to suit your needs - but, since it is your custom presentation, then you should hopefully be in the best place to do this.


The source for today's video is in https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/tree/master/N-42-Lifecycles


The video itself is:




The audio skips in the first few seconds - making me sound even odder than normal ;)


For a full N+1 index, please see Aboo's fabulous work on http://mvvmcross.wordpress.com

Thursday, October 03, 2013

N=41 - More Android maps - more advanced - N+1

Today we carry on to a finalé in our trip through data-bound maps on Android.

 
This maps tutorial follows on from:


For demos in the video, I use a real device - sorry for the bad camera work!


I also mess up a few times - sorry :)


I also try some really advanced stuff with making a bindable fragment - for which I make no apologies :)


For really working out how to use Google Maps - see https://developers.google.com/maps/documentation/android/views - it's actually very good documentation!




The source code for today is on: https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/tree/master/N-41-Maps



The video:




For a full and wonderful N+1 index, see: http://mvvmcross.wordpress.com/

Wednesday, October 02, 2013

N=40 First Part of Maps on Android - N+1

Today we move on to maps on Android.

 
This maps tutorial follows on from:


To get maps working we use the Google Play Services component - see https://components.xamarin.com/gettingstarted/googleplayservices for how get started on this.



For demos in the video, I use a real device - sorry for the bad camera work!



If you want to try to get maps working on an emulator, then I recommend you take a look at http://www.genymotion.com/ - although I don't think this plays nicely with the WP8 emulator or with the Intel HAXM driver either :(



The source code for today is on: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-40-Maps



The video:







Sorry again about the demos by hand rather than in a simulator - and for the pauses while I gather my thoughts each time :)


For a full and wonderful N+1 index, see: http://mvvmcross.wordpress.com/

Wednesday, September 25, 2013

N=39 - CrossLight on Xamarin.iOS/MonoTouch (aka Project Chimp)

This video is a follow on from http://slodge.blogspot.co.uk/2013/06/n30-crosslight-aka-project-chimp-n1.html where I showed how to use the MvvmCross binding layer in Android without using the higher layers (the navigation service, the plugin loader, the thread dispatcher, etc).


In this video I quickly do the same thing for Xamarin.iOS.


The process is pretty simple:


1. Add references to the CrossCore and Binding assemblies for MvvmCross (in the video I use nuget CrossCore package - https://www.nuget.org/packages/MvvmCross.HotTuna.CrossCore/)

2. Add a small setup class and call it from your appdelegate start code



3. Add you ViewModel - and INotifyPropertyChanged will do

4. Adjust your ViewController so that it can do data-binding to an instance of your ViewModel



5. Run :)


The code for today is at: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-39-CrossLight-Touch


The video is:




For a full index of N+1 videos, see http://mvvmcross.wordpress.com

N=38 - More maps and more zombies

Today, I tried to extend the N=37 Maps Xamarin.iOS sample into 4 new directions:

  1. A draggable annotation that updates it's location in the ViewModel
  2. An ObservableCollection of annotations.
  3. A mechanism to update the map center from the ViewModel
  4. A mechanism to update the ViewModel from map panning



The code for this is on: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-38-Maps


The video is:



Disclaimer: I only tested on iOS6 - and there were a few animation details there that needed a little smoothing... I've not tested them on iOS5 or iOS7 yet - expect more there too!


For a full index of N+1 videos, see http://mvvmcross.wordpress.com

Thursday, September 19, 2013

N=37 - Maps and Zombies part 1 - N+1 Days of MvvmCross

After a slightly longer than planned summer break, I'm finally returning to these recordings. Sorry about the elongated break, but I'm back now, and hoping to cover some more advanced topics :)


To start with, I thought I'd try some mapping. This is going to take a few videos to get completed.... just easing back into this process.


First up:

  • we create just a PCL and an iOS project
  • we add an MKMapView view
  • we databind some annotations to the ViewModel

The video for this is:


I'm afraid I did get interrupted during the recording, so you might hear someone asking if I wanted a beer - but I didn't - I don't drink and screencast ;)


The code for this is in: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-37-Maps


The index of N+1's is on http://mvvmcross.wordpress.com, but we also have a copy on the wiki - https://github.com/slodge/MvvmCross/wiki

Wednesday, July 17, 2013

N=36 - A Rio Binding Carnival :)

Today's N+1 follows on from the previous Tibet video - N=35 - which was all about Views and multibinding.


Rio Binding today is all about ViewModels.


Rio is an attempt to experiment with different types of ViewModel. In particular to:

  • use 
    • fields
    • methods 

  • instead of
    • properties
    • commands.


Using the FieldBinding and MethodBinding plugins from Rio, a view model can look like:





instead of an old-skool-INotifyPropertyChanged ViewModel like:





Rio is an attempt to start a conversation.:

  • Which ViewModel style do you prefer? 
  • Why? 
  • What else could be tried?
  • How could anyone do better?


Please note that no-one is saying that Rio field- and method-binding is better than the established property and command binding. All it does for now is to offer some new alternatives. Always think about your code and always choose the tools and techniques which suit you, your team and your app best - the app is king!





The source for today's video is at: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-36-Rio


A full N+1 index is available on:

Tuesday, July 16, 2013

N=35 - MultiBinding with Tibet - N+1 Videos of MvvmCross

Fresh from the heat and Summer-sunshine of London, today's N+1 introduces the new 'Tibet' binding engine.


This binding engine is built on top of the old 'Swiss' engine - so should be fully backwards compatible.


In addition to all the awesome syntax you had in Swiss, you can now take advantage of:
  • Multi-binding
  • Simple combination operators
  • The `Format` combination operator
  • The `If` combination operator
  • Recursive nesting of combinations and of value conversions
  • Function-style invocation of value converters

There's some good documentation on Tibet binding being authored over on https://github.com/slodge/MvvmCross/wiki/Databinding#tibet


This includes examples like:

   Value Format('Hello {1} - today is {0:ddd MMM yyyy}', TheDate, Name)

and

   Text Length(Trim(FirstName + ' ' + LastName))



Tibet has proven quite a hard topic for me to introduce... but I've had a go in this intro video:





The code for the video is at: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-35-Tibet


For a full N+1 index, see:
http://mvvmcross.wordpress.com

Monday, July 08, 2013

N=34 - Showing a Progress 'IsBusy' display - N+1 days of MvvmCross

Today we show how to quickly add a 'progress dialog' display to Xamarin.Android, Xamarin.iOS and to Windows Phone.


This should have been quite a quick demo today... but unfortunately some gremlins in the Xamarin Component Store this much slower. Sorry about that. The component I eventually downloaded was http://components.xamarin.com/view/mbprogresshud/


The video for N=34 is:


The code is at:



For a complete N+1 index, see:

N=33 - Animating Data-Bound Text Changes - N+1 Videos of MvvmCross

Today I just show how to change your UI controls so that they can animate when their values change.

The animations I use are pretty basic:

  • On Android:


  • On iOS:


  • On Windows:



The video:



The source is available on: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-33-AnimateTextChanges


For a full and lovely index of N+1, see:

Friday, June 28, 2013

N=32 - The Truth about ViewModels... starring MvxView on the iPad - N+1 days of MvvmCross

Triggered by a stackoverflow question I thought I'd try to explain that a ViewModel is just a Model for a View.


I'm not sure if I succeeded or not... but at least I got a chance to demo an iPad app - and I got a chance to talk about the very lovely but underused MvxView





The code is at: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-32-ViewModels


The excellent N+1 index is at:

Tuesday, June 25, 2013

N=31 - Injection of Platform Specific Services - N+1 Days of MvvmCross

One of the common questions I get asked is how to consume non-portable functionality into portable class library functionality.


My answer to this is to use dependency injection where possible.


This N+1 covers two ways of doing that:

  1. firstly by defining interfaces in the core project, and manually registering implementations in each UI project
  2. secondly by using testable, reusable plugins

In my 'real-world' projects I generally:

  • start with the first approach - it's quick and very easy to do
  • migrate to plugins where I find I have functionality I need to test, or if I think that I might want to reuse that functionality across projects
  • sometimes, rarely, I do also switch back to non-portable code (to file-linking) for cases where the native API which needs consuming is too large to wrap with an interface - but I try to avoid this wherever possible.


The video for today is at:




At one point, you see that I have an assembly version mismatch - sorry about this - it's due to me talking from a development rather than production setup, and it was easily solved using the nuget `Update-Package` command to update all my projects to the same MvvmCross NuGet version.


The code is at: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-31-Injection


For more info on this, please also see:


For more on N+1, see:

Monday, June 24, 2013

N=30 - CrossLight (aka Project Chimp) - N+1 Days of MvvmCross

This is a very technical topic today.



It's aimed mainly at people who want to use the MvvmCross plugins or the MvvmCross binding layer in non-MvvmCross applications. This may sound isn't something MvvmCross should want... but I would personally love to see lots of small cross-platform application frameworks pushing away at different ideas/areas. Innovation breeds off of invention, and innovation is fun and profitable :)


Today's video is:



The code is at: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-30-ChimpCrossLight


The existing CrossLight demos are in: https://github.com/slodge/MvvmCross-Tutorials/tree/master/CrossLight


The original idea for Project Chimp was discussed in http://slodge.blogspot.co.uk/2013/03/a-chimp-is-born-mvvm-on-monodroid.html


The v3 changes that enabled Chimp were also discussed in the slide deck at: http://slodge.blogspot.co.uk/2013/03/hot-tuna-mvvmcross-v3-progress.html


For an excellent index of N+1 try:

N=29 - Testing! - N+1 Days of MvvmCross

Today we cover testing of your core services and view models.


For this we use:





For today's code, see https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-29-TipCalcTest


For @gshackles excellent Evolve session on testing see http://xamarin.com/evolve/2013#session-7wb0etd3r8


For an index of all the N+1 videos, please see:

Friday, June 21, 2013

N=28 - Custom Bindings - N+1 Days of MvvmCross

Today, I thought I'd try something Deeply Technical


Custom Bindings


Actually it's not that technical... but it's a topic that people might feel a bit nervous about.

There's no need to worry - custom bindings are actually pretty simple.

For most UI controls/widgets in Android and iOS, MvvmCross binding "just works"

It does this using Reflection.
  • Wherever Mvx sees a property - e.g. public int Count {get;set;} - then it knows it can do one-way binding to it using Reflection.
  • Further, when it sees that there is also an event with a name ~Changed - e.g. public event EventHandler CountChanged; - then it also guesses that the event can be used for TwoWay binding too.

This works brilliantly well for many (most!) controls.

Problems only arise when whoever has written the control hasn't followed this convention - e.g.
  • if they've just provided arbitrary get/set methods instead of a public C# property
  • or if they've decided to signal their changes using a delegate or watcher pattern instead of a C# event.

In these cases, you can work around the challenge by using a Custom Binding.



The code for today is in: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-28-CustomBinding


For an excellent index of all the N+1 videos, check out:

Thursday, June 20, 2013

N=27 - Ninja for MvvmCross (N+1 Days of MvvmCross)

Last week I saw this tweet



And immediately I knew what my calling was.


My destiny was that I would become a Ninja....







What an awesome plugin from @asudbury 




The code generated today is on: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-27-Ninja



For the amazing index of N+1 videos, see:

Monday, June 10, 2013

N=26 - Down at Android Fragments Rock (N+1 Days of MvvmCross)

Today N+1 is back!


Sorry about the short break... and sorry about before another short break that's coming up - I'm going to NDC Oslo in Norway this week :)



Today, we're talking about Fragments!







Fragments are an Android-only thing. They're a type of User Control and they were invented by Jim Henson*


In this N+1 we talk through:

  • how to data-bind static fragments
  • how to data-bind dynamic fragments
  • briefly how to data-bind fragments in:
  • tabs
  • dialogs
  • the little-known MvxFrameControl


For more on fragments:





The video is:














Today's source code is available on: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-26-Fraggle



A full and wonderful index for N+1 is available on





---

* ok, not really :) For more on Fraggle Rock... http://muppet.wikia.com/wiki/Fraggle_Rock - which is where the images above come from (under CC). Also for the full Fraggle Rock theme song, try http://www.youtube.com/watch?v=l_zsz_MlVvI

Monday, June 03, 2013

N=25 - Tabs - N+1 Days of MvvmCross

Following on from splitview presenters, this talk gives an introduction into using tabs on Xamarin.Android, Xamarin.iOS and WindowsPhone.


For WindowsPhone, we use a Panorama as the local equivalent of Tabs - and we also mention Pivots.


For iOS, we show how to use a custom presenter to perform navigation within a tab child.


For Android, we hint at a future discussion of Fragments, but for now we discuss only Activities.


The video is:






The code is at https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-25-Tabbed


For more on the N+1 series, check out this excellent index - http://mvvmcross.wordpress.com/ - thanks Aboo!

Wednesday, May 29, 2013

N=24 - a SplitViewPresenter - N+1 Days of MvvmCross

As a first step in talking about custom presenters, I created N=24 - a splitview sample.


This sample shows how to create a presenter which allows the same Views and ViewModels to be used in different ways on the iPhone and iPad:






The video is at:




A slide deck for custom presenters is:




The code is on: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-24-Split



If you want to see more N+1 videos, then please see the full and fabulous index on http://mvvmcross.wordpress.com/

Tuesday, May 28, 2013

N=23 - Dialogs - N+1 Days of MvvmCross

Sorry for the lack of new videos...


Just a bit busy right now - including with some time off :)


Today's video covers the MonoDroid and MonoTouch Dialogs in the 3.0.7 nuget MvvmCross packages


I may have been a little bla in my intoduction today - I may have assumed that everyone knows what dialogs are already....


If the mention of Dialog makes you think 'what's a Dialog?' then it might be best to start with an introduction to Dialogs... so maybe start with Nic Wise's slides at:

- http://fastchicken.co.nz/2013/04/20/xamarin-evolve-talk-fast-ui-creation-with-monotouch-dot-dialog/

(video of his talk is also coming soon on http://xamarin.com/evolve/2013)



If, however, you are already familiar with Dialogs, then here's the MvvmCross action:






And the code is on: https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-23-Dlg




A full and fabulous index for N+1 is on http://mvvmcross.wordpress.com/


Previously in N+1: