Merge pull request #2119 from crazyserver/MOBILE-3026

Mobile 3026
main
Juan Leyva 2019-10-01 17:31:24 +02:00 committed by GitHub
commit eaee7e5152
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 92 additions and 6 deletions

View File

@ -1962,5 +1962,7 @@
"core.wsfunctionnotavailable": "local_moodlemobileapp",
"core.year": "moodle",
"core.years": "moodle",
"core.yes": "moodle"
"core.yes": "moodle",
"core.youreoffline": "local_moodlemobileapp",
"core.youreonline": "local_moodlemobileapp"
}

View File

@ -14,6 +14,7 @@
import { Component, OnInit, NgZone } from '@angular/core';
import { Platform, IonicApp } from 'ionic-angular';
import { Network } from '@ionic-native/network';
import { CoreAppProvider } from '@providers/app';
import { CoreEventsProvider } from '@providers/events';
import { CoreLangProvider } from '@providers/lang';
@ -42,7 +43,7 @@ export class MoodleMobileApp implements OnInit {
private eventsProvider: CoreEventsProvider, private loginHelper: CoreLoginHelperProvider, private zone: NgZone,
private appProvider: CoreAppProvider, private langProvider: CoreLangProvider, private sitesProvider: CoreSitesProvider,
private screenOrientation: ScreenOrientation, private urlSchemesProvider: CoreCustomURLSchemesProvider,
private utils: CoreUtilsProvider, private urlUtils: CoreUrlUtilsProvider) {
private utils: CoreUtilsProvider, private urlUtils: CoreUrlUtilsProvider, private network: Network) {
this.logger = logger.getInstance('AppComponent');
platform.ready().then(() => {
@ -109,6 +110,22 @@ export class MoodleMobileApp implements OnInit {
this.loginHelper.sitePolicyNotAgreed(data.siteId);
});
// Refresh online status when changes.
this.network.onchange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working.
this.zone.run(() => {
const isOnline = this.appProvider.isOnline();
document.body.classList.toggle('core-offline', !isOnline);
document.body.classList.toggle('core-online', isOnline);
if (isOnline) {
setTimeout(() => {
document.body.classList.remove('core-online');
}, 3000);
}
});
});
// Check URLs loaded in any InAppBrowser.
this.eventsProvider.on(CoreEventsProvider.IAB_LOAD_START, (event) => {
// URLs with a custom scheme can be prefixed with "http://" or "https://", we need to remove this.

View File

@ -1960,5 +1960,7 @@
"core.wsfunctionnotavailable": "The web service function is not available.",
"core.year": "year",
"core.years": "years",
"core.yes": "Yes"
"core.yes": "Yes",
"core.youreoffline": "You are offline",
"core.youreonline": "You are back online"
}

View File

@ -1,5 +1,13 @@
<core-ion-tabs #mainTabs [hidden]="!showTabs" [loaded]="loaded" tabsLayout="title-hide" [attr.tabsPlacement]="tabsPlacement">
<core-ion-tab [enabled]="false" [show]="false" [root]="redirectPage" [rootParams]="redirectParams"></core-ion-tab>
<core-ion-tab *ngFor="let tab of tabs" [root]="tab.page" [rootParams]="tab.pageParams" [tabTitle]="tab.title | translate" [tabIcon]="tab.icon" [tabBadge]="tab.badge" class="{{tab.class}}" [enabled]="!tab.hide" [show]="!tab.hide"></core-ion-tab>
<core-ion-tab root="CoreMainMenuMorePage" [tabTitle]="'core.more' | translate" tabIcon="more"></core-ion-tab>
<core-ion-tab root="CoreMainMenuMorePage" [tabTitle]="'core.more' | translate" tabIcon="menu"></core-ion-tab>
</core-ion-tabs>
<div class="core-network-message" [hidden]="!showTabs">
<div class="core-online-message">
{{ "core.youreonline" | translate }}
</div>
<div class="core-offline-message">
{{ "core.youreoffline" | translate }}
</div>
</div>

View File

@ -1,8 +1,9 @@
ion-app.app-root page-core-mainmenu {
ion-icon {
ion-icon.tab-button-icon {
text-overflow: unset;
overflow: visible;
text-align: center;
transition: margin 500ms ease-in-out, transform 300ms ease-in-out;
}
.ion-md-fa-graduation-cap,
@ -40,4 +41,56 @@ ion-app.app-root page-core-mainmenu {
font-size: 23px;
height: 23px;
}
.core-network-message {
position: absolute;
bottom: 0;
left: 0;
right: 0;
padding-left: 10px;
padding-right: 10px;
text-align: center;
color: white;
visibility: hidden;
height: 0;
transition: all 500ms ease-in-out;
opacity: .8;
}
.core-online-message,
.core-offline-message {
display: none;
}
}
.core-online ion-app.app-root page-core-mainmenu,
.core-offline ion-app.app-root page-core-mainmenu {
core-ion-tabs[tabsplacement="bottom"] ion-icon.tab-button-icon {
margin-bottom: $core-network-message-height / 2;
&.icon-ios {
margin-bottom: 14px;
}
}
.core-network-message {
visibility: visible;
height: $core-network-message-height;
pointer-events: none;
}
}
.core-offline ion-app.app-root page-core-mainmenu .core-offline-message,
.core-online ion-app.app-root page-core-mainmenu .core-online-message {
display: block;
}
.core-online ion-app.app-root page-core-mainmenu .core-network-message {
background: $green;
}
.core-offline ion-app.app-root page-core-mainmenu .core-network-message {
background: $red;
}

View File

@ -293,5 +293,7 @@
"wsfunctionnotavailable": "The web service function is not available.",
"year": "year",
"years": "years",
"yes": "Yes"
"yes": "Yes",
"youreoffline": "You are offline",
"youreonline": "You are back online"
}

View File

@ -188,6 +188,8 @@ $core-loading-spinner-color: $core-color !default;
$core-spinner-color: $core-color !default;
$core-button-outline-background-color: $white !default;
$core-network-message-height: 16px !default;
// Login.
$core-login-page-background-color: radial-gradient(white, $gray-light) !default;
$core-login-box-background-color: $white !default;