mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-06-17 11:58:30 +00:00
Introducing Loading and Exit View for Widget
This commit is contained in:
@ -100,14 +100,9 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
System.println("HomeAssistantApp fetchMenuConfig(): No Internet connection, skipping API call.");
|
||||
}
|
||||
return [new ErrorView(strNoInternet + "."), new ErrorDelegate()] as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>;
|
||||
}else if (mHaMenu != null ){
|
||||
// App.getApp().launchInitialView();
|
||||
return [mHaMenu, new WatchUi.BehaviorDelegate()] as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>;
|
||||
// return mHaMenu.View;
|
||||
// WatchUi.pushView(mHaMenu, new HomeAssistantViewDelegate(), WatchUi.SLIDE_IMMEDIATE);
|
||||
} else {
|
||||
fetchMenuConfig();
|
||||
return [new WatchUi.View(), new WatchUi.BehaviorDelegate()] as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>;
|
||||
return [new RootView(self), new RootViewDelegate(self)] as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>;
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +139,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
} else if (responseCode == 200) {
|
||||
mHaMenu = new HomeAssistantView(data, null);
|
||||
quitTimer.begin();
|
||||
WatchUi.pushView(mHaMenu, new HomeAssistantViewDelegate(), WatchUi.SLIDE_IMMEDIATE);
|
||||
pushHomeAssistantMenuView();
|
||||
mItemsToUpdate = mHaMenu.getItemsToUpdate();
|
||||
// Start the continuous update process that continues for as long as the application is running.
|
||||
// The chain of functions from 'updateNextMenuItem()' calls 'updateNextMenuItem()' on completion.
|
||||
@ -177,6 +172,14 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
);
|
||||
}
|
||||
|
||||
function homeAssistantMenuIsLoaded() as Lang.Boolean{
|
||||
return mHaMenu!=null;
|
||||
}
|
||||
|
||||
function pushHomeAssistantMenuView(){
|
||||
WatchUi.pushView(mHaMenu, new HomeAssistantViewDelegate(), WatchUi.SLIDE_IMMEDIATE);
|
||||
}
|
||||
|
||||
// We need to spread out the API calls so as not to overload the results queue and cause Communications.BLE_QUEUE_FULL (-101) error.
|
||||
// This function is called by a timer every Globals.menuItemUpdateInterval ms.
|
||||
function updateNextMenuItem() as Void {
|
||||
|
60
source/RootView.mc
Normal file
60
source/RootView.mc
Normal file
@ -0,0 +1,60 @@
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
import Toybox.WatchUi;
|
||||
|
||||
class RootView extends WatchUi.View {
|
||||
|
||||
var width,height;
|
||||
var mApp as HomeAssistantApp;
|
||||
|
||||
function initialize(app as HomeAssistantApp) {
|
||||
View.initialize();
|
||||
mApp=app;
|
||||
}
|
||||
|
||||
function onLayout(dc as Dc) as Void {
|
||||
width=dc.getWidth();
|
||||
height=dc.getHeight();
|
||||
}
|
||||
|
||||
function onUpdate(dc as Dc) as Void {
|
||||
dc.setColor(Graphics.COLOR_BLACK,Graphics.COLOR_BLACK);
|
||||
dc.clear();
|
||||
dc.setColor(Graphics.COLOR_BLUE,Graphics.COLOR_TRANSPARENT);
|
||||
if(mApp.homeAssistantMenuIsLoaded()) {
|
||||
dc.drawText(width/2,height/2,Graphics.FONT_SMALL,"Hit Back to Exit\nTap to stay",Graphics.TEXT_JUSTIFY_CENTER|Graphics.TEXT_JUSTIFY_VCENTER);
|
||||
} else {
|
||||
dc.drawText(width/2,height/2,Graphics.FONT_SMALL,"Loading...",Graphics.TEXT_JUSTIFY_CENTER|Graphics.TEXT_JUSTIFY_VCENTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RootViewDelegate extends WatchUi.BehaviorDelegate {
|
||||
|
||||
var mApp as HomeAssistantApp;
|
||||
|
||||
function initialize(app as HomeAssistantApp ) {
|
||||
BehaviorDelegate.initialize();
|
||||
mApp=app;
|
||||
}
|
||||
|
||||
public function onTap(evt as ClickEvent) as Boolean {
|
||||
return backToMainMenu();
|
||||
}
|
||||
|
||||
public function onSelect() as Boolean {
|
||||
return backToMainMenu();
|
||||
}
|
||||
|
||||
function onMenu(){
|
||||
return backToMainMenu();
|
||||
}
|
||||
|
||||
private function backToMainMenu() as Lang.Boolean{
|
||||
if(mApp.homeAssistantMenuIsLoaded()){
|
||||
mApp.pushHomeAssistantMenuView();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user