From c80700443df8a831de0986eee70677668768d6ca Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 15 Jun 2018 10:47:44 +0200 Subject: [PATCH] MOBILE-2428 splash: Don't hide splash until init is done --- config.xml | 2 +- .../index/addon-mod-lesson-index.html | 2 +- .../pages/password-modal/password-modal.html | 2 +- src/app/app.component.ts | 5 +-- .../forgotten-password.html | 2 +- src/core/login/pages/init/init.ts | 33 ++++++++++++++----- src/core/login/pages/reconnect/reconnect.html | 2 +- src/core/login/pages/site/site.html | 2 +- src/core/login/pages/site/site.ts | 8 +++-- src/core/login/pages/sites/sites.ts | 4 +-- src/core/login/providers/helper.ts | 6 +++- 11 files changed, 44 insertions(+), 24 deletions(-) diff --git a/config.xml b/config.xml index 9948044e3..0946d1ed6 100644 --- a/config.xml +++ b/config.xml @@ -33,7 +33,7 @@ - + diff --git a/src/addon/mod/lesson/components/index/addon-mod-lesson-index.html b/src/addon/mod/lesson/components/index/addon-mod-lesson-index.html index 2bb0a5f6f..50c203f31 100644 --- a/src/addon/mod/lesson/components/index/addon-mod-lesson-index.html +++ b/src/addon/mod/lesson/components/index/addon-mod-lesson-index.html @@ -37,7 +37,7 @@ {{ 'addon.mod_lesson.enterpassword' | translate }} - + diff --git a/src/addon/mod/lesson/pages/password-modal/password-modal.html b/src/addon/mod/lesson/pages/password-modal/password-modal.html index dd55a244a..bde436b31 100644 --- a/src/addon/mod/lesson/pages/password-modal/password-modal.html +++ b/src/addon/mod/lesson/pages/password-modal/password-modal.html @@ -13,7 +13,7 @@ {{ 'addon.mod_lesson.enterpassword' | translate }} - + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 5af93f0fe..d93ed1754 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -15,7 +15,6 @@ import { Component, OnInit } from '@angular/core'; import { Platform } from 'ionic-angular'; import { StatusBar } from '@ionic-native/status-bar'; -import { SplashScreen } from '@ionic-native/splash-screen'; import { CoreAppProvider } from '@providers/app'; import { CoreEventsProvider } from '@providers/events'; import { CoreLangProvider } from '@providers/lang'; @@ -33,7 +32,7 @@ export class MoodleMobileApp implements OnInit { protected logger; protected lastUrls = {}; - constructor(private platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, logger: CoreLoggerProvider, + constructor(private platform: Platform, statusBar: StatusBar, logger: CoreLoggerProvider, private eventsProvider: CoreEventsProvider, private loginHelper: CoreLoginHelperProvider, private appProvider: CoreAppProvider, private langProvider: CoreLangProvider, private sitesProvider: CoreSitesProvider) { this.logger = logger.getInstance('AppComponent'); @@ -46,8 +45,6 @@ export class MoodleMobileApp implements OnInit { } else { statusBar.styleDefault(); } - - splashScreen.hide(); }); } diff --git a/src/core/login/pages/forgotten-password/forgotten-password.html b/src/core/login/pages/forgotten-password/forgotten-password.html index 26cf02d2b..23b78cc15 100644 --- a/src/core/login/pages/forgotten-password/forgotten-password.html +++ b/src/core/login/pages/forgotten-password/forgotten-password.html @@ -25,7 +25,7 @@ - + diff --git a/src/core/login/pages/init/init.ts b/src/core/login/pages/init/init.ts index 2770bcf4e..9d58eb521 100644 --- a/src/core/login/pages/init/init.ts +++ b/src/core/login/pages/init/init.ts @@ -14,6 +14,7 @@ import { Component } from '@angular/core'; import { IonicPage, NavController } from 'ionic-angular'; +import { SplashScreen } from '@ionic-native/splash-screen'; import { CoreAppProvider } from '@providers/app'; import { CoreInitDelegate } from '@providers/init'; import { CoreSitesProvider } from '@providers/sites'; @@ -31,7 +32,8 @@ import { CoreLoginHelperProvider } from '../../providers/helper'; export class CoreLoginInitPage { constructor(private navCtrl: NavController, private appProvider: CoreAppProvider, private initDelegate: CoreInitDelegate, - private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider) { } + private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider, + private splashScreen: SplashScreen) { } /** * View loaded. @@ -51,11 +53,11 @@ export class CoreLoginInitPage { // The redirect is pointing to a site, load it. return this.sitesProvider.loadSite(redirectData.siteId).then(() => { if (!this.loginHelper.isSiteLoggedOut(redirectData.page, redirectData.params)) { - this.navCtrl.setRoot(redirectData.page, redirectData.params, { animate: false }); + return this.navCtrl.setRoot(redirectData.page, redirectData.params, { animate: false }); } }).catch(() => { // Site doesn't exist. - this.loadPage(); + return this.loadPage(); }); } else { // No site to load, just open the state. @@ -64,24 +66,37 @@ export class CoreLoginInitPage { } } - this.loadPage(); + return this.loadPage(); + }).then(() => { + // If we hide the splash screen now, the init view is still seen for an instant. Wait a bit to make sure it isn't seen. + setTimeout(() => { + this.splashScreen.hide(); + }, 100); }); } /** * Load the right page. + * + * @return {Promise} Promise resolved when done. */ - protected loadPage(): void { + protected loadPage(): Promise { if (this.sitesProvider.isLoggedIn()) { if (!this.loginHelper.isSiteLoggedOut()) { - this.loginHelper.goToSiteInitialPage(); + // User is logged in, go to site initial page. + return this.loginHelper.goToSiteInitialPage(); + } else { + // The site is marked as logged out. Logout and try again. + return this.sitesProvider.logout().then(() => { + return this.loadPage(); + }); } } else { - this.sitesProvider.hasSites().then((hasSites) => { + return this.sitesProvider.hasSites().then((hasSites) => { if (hasSites) { - this.navCtrl.setRoot('CoreLoginSitesPage'); + return this.navCtrl.setRoot('CoreLoginSitesPage'); } else { - this.loginHelper.goToAddSite(true); + return this.loginHelper.goToAddSite(true); } }); } diff --git a/src/core/login/pages/reconnect/reconnect.html b/src/core/login/pages/reconnect/reconnect.html index f2b454762..47bfdf501 100644 --- a/src/core/login/pages/reconnect/reconnect.html +++ b/src/core/login/pages/reconnect/reconnect.html @@ -33,7 +33,7 @@
- + diff --git a/src/core/login/pages/site/site.html b/src/core/login/pages/site/site.html index a23e975ff..3b13f0698 100644 --- a/src/core/login/pages/site/site.html +++ b/src/core/login/pages/site/site.html @@ -19,7 +19,7 @@

{{ 'core.login.newsitedescription' | translate }}

- +
diff --git a/src/core/login/pages/site/site.ts b/src/core/login/pages/site/site.ts index 77bb3eb2c..dcd6752fb 100644 --- a/src/core/login/pages/site/site.ts +++ b/src/core/login/pages/site/site.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Component } from '@angular/core'; -import { IonicPage, NavController, ModalController } from 'ionic-angular'; +import { IonicPage, NavController, ModalController, NavParams } from 'ionic-angular'; import { CoreAppProvider } from '@providers/app'; import { CoreSitesProvider } from '@providers/sites'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; @@ -33,10 +33,14 @@ export class CoreLoginSitePage { siteForm: FormGroup; fixedSites: any[]; displayAsButtons = false; + showKeyboard = false; - constructor(private navCtrl: NavController, fb: FormBuilder, private appProvider: CoreAppProvider, + constructor(navParams: NavParams, private navCtrl: NavController, fb: FormBuilder, private appProvider: CoreAppProvider, private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider, private modalCtrl: ModalController, private domUtils: CoreDomUtilsProvider) { + + this.showKeyboard = !!navParams.get('showKeyboard'); + let url = ''; // Load fixed sites if they're set. diff --git a/src/core/login/pages/sites/sites.ts b/src/core/login/pages/sites/sites.ts index 7e659e9c6..a1706e522 100644 --- a/src/core/login/pages/sites/sites.ts +++ b/src/core/login/pages/sites/sites.ts @@ -67,7 +67,7 @@ export class CoreLoginSitesPage { * Go to the page to add a site. */ add(): void { - this.loginHelper.goToAddSite(false); + this.loginHelper.goToAddSite(false, true); } /** @@ -91,7 +91,7 @@ export class CoreLoginSitesPage { // If there are no sites left, go to add site. this.sitesProvider.hasSites().then((hasSites) => { if (!hasSites) { - this.loginHelper.goToAddSite(true); + this.loginHelper.goToAddSite(true, true); } }); }).catch((error) => { diff --git a/src/core/login/providers/helper.ts b/src/core/login/providers/helper.ts index 15db817c6..942fb37da 100644 --- a/src/core/login/providers/helper.ts +++ b/src/core/login/providers/helper.ts @@ -380,9 +380,10 @@ export class CoreLoginHelperProvider { * If a fixed URL is configured, go to credentials instead. * * @param {boolean} [setRoot] True to set the new page as root, false to add it to the stack. + * @param {boolean} [showKeyboard] Whether to show keyboard in the new page. Only if no fixed URL set. * @return {Promise} Promise resolved when done. */ - goToAddSite(setRoot?: boolean): Promise { + goToAddSite(setRoot?: boolean, showKeyboard?: boolean): Promise { let pageName, params; @@ -395,6 +396,9 @@ export class CoreLoginHelperProvider { params = { siteUrl: url }; } else { pageName = 'CoreLoginSitePage'; + params = { + showKeyboard: showKeyboard + }; } if (setRoot) {