Friday, January 17, 2014

From concept to reality in 6 weeks - part 37

In many ways today is a sad day is it is the last day I have to work on the Windows Store app. To start the day off in the correct musical mood I am going to listen to "North Mississippi Allstars". Next week I am going to write a couple of summary blog entries to recap all of the things I learned from a couple of views.

For now I just need to wrap up and test as many of the features as I can. The beauty of working on my laptop is that it is not a simulator or emulator as the machine is also a touch device that is the target of this app. I don't expect to try any new C# stuff today but you never know...

The very first thing I encountered was numerous 500 and 502 server errors. I have ignored these long enough as I need to add some retry logic as they always seem to work when I try them in Safari on my Mac. When in the debugger I see an odd HResult code but that is not going to help me as I tried to look that up in the Microsoft error codes and it was not a match. The real ticket was looking up the HttpResponseCodes as that is very easy to retrieve. I set a a maximum number of times to retry so I never get into an infinite look when the server is not working at all or the internet connection fails. When that happens I make sure the progress dialog is closed and a MessageDialog is shown so the user sees the actual error message. That is my first error I have shown in the this app so I feel pretty good about that.

I have been testing the live updates for a while and found several issues that have to be fixed. When part of the data is filtered and new data arrives then the data is not stored correctly. That was pretty easy to fix. I was a bit worried at first as it seemed like a major problem.

Then I switched to changing the way search worked as it was only partially implemented. I need to match the iPad functionality but at the same time make it look better and act better. It is kind of late to do this but I am confident that it can be done. The first thing I want to do it make the search popup on the right hand side of the app (kind of like the Settings). It turns out that is way harder than it should be. I first tried to change the placement location as documented. When that did not work I tried looking for other answers but some were so complicated that it just did not seem like the right thing to do. In the end the solution was to set the HorizontalAlignment to be on the right side, but that pushed the whole popup off the screen. Then I set the HorizontalOffset to be the negative of the popup width and bingo all was resolved.

After trying a couple of different things using multiple StackedPanel and then a Grid to display the custom search results, I tried wrapping them both in a ScrollView but that was not a good idea. It was a good guess but totally the wrong thing to do. I abandoned everything I have done so far and looked up the GridView or ListView to learn about how they are different and which would be better for me. I decided ListView was better so I was off to explore a brand new part of a Windows Store app on my final day - sounds dangerous but it was just what I needed or so it seems. Thankfully the ListView quick start guide was perfect and I was up and running quickly. I created a new model class to hold the search results to be displayed in the ListView, which was a small subset of the observations data model. Perfectly simple and made perfect sense. As a first pass I just added a ToString method in my new model class and the data displayed correctly the first time! I guess I am getting the hang of this now.

I need to make it look stylish so I need to find the style template names. ListView has been around so that was too easy as they are all documented. I read up on the ListView guidelines to make sure I was not doing something odd. The only tricky thing was I needed to apply the style programmatically, which is not something I even know how to do. A quick search on the MSDN blog and solution was found and worked the first time. Then I switched as it seemed like my code was getting too complicated. I found an explanation of styling using a ListView.ItemTemplate. That is amazing how easy that is in XAML, so I deleted all of my C# code related to ListViewItems.

Now that my search results look beautiful, I need to figure out how to allow multiple selection, since the scrolling automatically works with the ListView as I don't have to deal with that nastiness. The only tricky part was figuring out how to deal with multiple selections in the SelectionChange handler.  The ListView has a SelectedItems property which is a collection of IList. I got into the debugger and found that these are actually a List of my SearchResult objects. This is going to just too easy. I add a button in the search to clear all selections just there can be many matches and I already know how to clear a list by calling SelectedItems.Clear()! I went back and read up on multiple selections to make sure I understood how they work. Some of these posts are pretty worthless but I found this gem talking about the ListView selections in just the right amount of detail. I went back into the original search auto-complete as that needs to change to just update the SelectedItems and I am sure it will just all work correctly. The real question is what happens if I try to add an item that is already selected a second time. And the answer is nothing - just as it should be - so perfect.

I had time to look a one last filter bug and squished that with some effort. I have been neglecting that one for a long time. That leaves one final bug that will just have to sit there so a while as I have run out of time and money to work on this project so I have to make one final tag in the GitHub repo and then make one final release build to give to the customer next week in my last visit.

Happy ending to a Friday!

No comments: