Newbie Question - Passing data from 'delegate' to view and adding more screens

Hi guys,

Apologies for the newbie questions here -  I feel like a bit of an idiot, but I've now looked at this so much, I'm now utterly lost and need someone to lead me back out of the woods. I'm not a trained coder, definitely an enthusiastic amateur that knows enough to get myself into trouble, so my question is actually a 2 part question. 

1. How can I move information and data back and forth between 'screens' or classes? 

2. How can I add more 'screens'? 

Example

I have used the 'WebRequest' example to pull JSON information from a website and display it on screen which is working fine. However - all of the 'data' wrangling is contained in the 'View' which, I suspect, probably better belongs in the delegate, however all of my attempts to move this information from the Delegate to the View have failed. I'm aiming to have something similar to the following.

AppDelegate: 

_AppView.updateValues(_location, _coords, _date, _tides);

AppView:

function updateValues(_location as String, _coords as String, _date as String, _tides as Float) {

        _locationElement.setText(_location);
        _coordsElement.setText(_coords);
        _tidesElement.setText(_tides);
        _dateElement.setText(_date);

}

Seems such a straightforward task that I have completed before in another app, albeit rote typing some code (which I apparently don't understand) but I cant quite crack it? I guess I am also getting oddly hung-up on this method:onReceive in a few places of the sample as well. If anyone can tell me what is going on here and give me a detailed but basic explanation - or push me in the right direction of some doco, I'd be very appreciative.

Question 2:
I'd like to make a configuration screen for my app to allow people to enter in new locations etc. Is it best to make another .mc and go from there? How does one call a new screen from a menu item?  

Cheers,
Matt

  • I actually got this fixed!! I had to add some stuff in the main class. Will update a little later - but I essentially followed this guide: www.youtube.com/watch

  • OK This still did not go well for me and I am struggling. I have resolved the view issues but now having issues with calling a function from the menu. 

    The function makeRequest() lives inside MyAppDelegate.mc and is working as expected. What I am now trying to do is call that function from Item1 in the menu delegate, MyAppMenuDelegate.mc using Application.getApp().makeRequest(); but I wind up with an error: Error: Symbol Not Found Error Details: Could not find symbol 'makeRequest'

    Would appreciate if someone could put me out of my misery.

  • OK I GOT IT!

    Needed to put this in my menu delegate in the logic for that menu item.

    var view = new $.MyAppView();
    var app = new MyAppDelegate(view.method(:onReceive));
    var func = app.method(:makeRequest);
    func.invoke();

  • I am back again however - after spending multiple days on this I am at a loss - how does one make extra screens or pages that can be called from a menu? Such as an about page? 

  • Create an mc file, call it say for example View2.mc or something, obviously you’ll need to add the code yourself but to open it from a menu you would use:

    WatchUi.pushView(view2,transition_animation)

    WatchUi.requestUpdate;

    you should be able to see this in the menu samples.

  • Thanks ScareCrow. That is deceptively simple. I dont know how I missed that in the sample. I think I am at the point now where I looked at so much stuff and couldnt see the wood for the trees.

    Can you advise if there is an example for setting up multiple layouts? I am trying to make another layout based on the instinct screens, but struggling also

  • I haven’t/have barely worked with layouts yet sorry, my intended plan for a navigation app is to have an instinct and a non instinct edition. Perhaps I shall look into them though.

  • Scarecrow - I can help you out with that one after nutting it out through several forum posts.

    Firstly - you can use the has :getSubscreen to tell you if it is an instinct 2 or not (or a watch with a subscreen).

    if (WatchUi has :getSubscreen) {
        setLayout(Rez.Layouts.Instinct2Layout(dc));
        } else {
        setLayout(Rez.Layouts.MainLayout(dc));
    }
    Then you can have multiple layouts in the layout.xml like this:
    <layouts>
        <layout id="MainLayout">
             <-- Your main layout stuff here -->
        </layout>
        <layout id="Instinct2Layout">
            <-- Your Instinct 2 layout stuff here -->
        </layout>
    </layouts>
    Hope that makes things easier for you mate. The doco isn't bad and we all get there eventually, but there could be a better job done explaining things in the doco to make it a little easier. I spent an inordinate amount of time hunting for that info.
  • Brilliant, thanks. I may use that get subscreen for things other than layouts.

    Also I completely agree about the documentation, it’s a bit lacking in explanations, what I’d quite like to see is for more complex subjects explained through video like an animation or a walkthrough tutorial.