Skip to content

Commit 16af401

Browse files
authored
Merge pull request #4496 from crazyserver/MOBILE-4842
Mobile 4842 - Additional signals
2 parents 32387d2 + 3100a6f commit 16af401

File tree

23 files changed

+269
-181
lines changed

23 files changed

+269
-181
lines changed

local_moodleappbehat/tests/behat/behat_app.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,15 +1179,16 @@ public function i_switch_offline_mode(string $offline) {
11791179
public function i_switch_network_connection(string $mode) {
11801180
switch ($mode) {
11811181
case 'wifi':
1182-
$this->runtime_js("network.setForceConnectionMode('$mode');");
1182+
$this->runtime_js("network.setForceConnectionMode('wifi');");
11831183
break;
11841184
case 'cellular':
1185-
$this->runtime_js("network.setForceConnectionMode('$mode');");
1185+
$this->runtime_js("network.setForceConnectionMode('cellular');");
11861186
break;
11871187
case 'offline':
1188-
$this->runtime_js("network.setForceConnectionMode('none');");
1188+
$this->runtime_js("network.setForceConnectionMode('offline');");
11891189
break;
11901190
default:
1191+
$this->runtime_js("network.setForceConnectionMode('unknown');");
11911192
break;
11921193
}
11931194
}

src/addons/blog/pages/index/index.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events';
4141
import { CoreTime } from '@singletons/time';
4242
import { CorePopovers } from '@services/overlays/popovers';
4343
import { CoreLoadings } from '@services/overlays/loadings';
44-
import { Subscription } from 'rxjs';
4544
import { CoreAlerts } from '@services/overlays/alerts';
4645
import { Translate } from '@singletons';
4746
import { CoreCommentsCommentsComponent } from '@features/comments/components/comments/comments';
@@ -89,10 +88,9 @@ export default class AddonBlogIndexPage implements OnInit, OnDestroy {
8988
contextInstanceId = 0;
9089
entryUpdateObserver: CoreEventObserver;
9190
syncObserver: CoreEventObserver;
92-
onlineObserver: Subscription;
9391
optionsAvailable = false;
9492
readonly hasOfflineDataToSync = signal(false);
95-
readonly isOnline = signal(false);
93+
readonly isOnline = CoreNetwork.onlineSignal();
9694
siteId: string;
9795
syncIcon = CoreConstants.ICON_SYNC;
9896
readonly syncHidden = computed(() => !this.loaded() || !this.isOnline() || !this.hasOfflineDataToSync());
@@ -101,7 +99,6 @@ export default class AddonBlogIndexPage implements OnInit, OnDestroy {
10199
this.currentUserId = CoreSites.getCurrentSiteUserId();
102100
this.siteHomeId = CoreSites.getCurrentSiteHomeId();
103101
this.siteId = CoreSites.getCurrentSiteId();
104-
this.isOnline.set(CoreNetwork.isOnline());
105102

106103
this.logView = CoreTime.once(async () => {
107104
await CorePromiseUtils.ignoreErrors(AddonBlog.logView(this.filter));
@@ -137,11 +134,6 @@ export default class AddonBlogIndexPage implements OnInit, OnDestroy {
137134
await CorePromiseUtils.ignoreErrors(this.refresh(false));
138135
this.loaded.set(true);
139136
});
140-
141-
// Refresh online status when changes.
142-
this.onlineObserver = CoreNetwork.onChange().subscribe(async () => {
143-
this.isOnline.set(CoreNetwork.isOnline());
144-
});
145137
}
146138

147139
/**
@@ -516,7 +508,6 @@ export default class AddonBlogIndexPage implements OnInit, OnDestroy {
516508
ngOnDestroy(): void {
517509
this.entryUpdateObserver.off();
518510
this.syncObserver.off();
519-
this.onlineObserver.unsubscribe();
520511
}
521512

522513
}

src/addons/mod/page/tests/behat/basic_usage.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Feature: Test basic usage of page activity in app
2424
| name | activity | activityname | course |
2525
| \mod_page\event\course_module_viewed | page | Test page title | Course 1 |
2626

27-
Scenario: Prefecth page
27+
Scenario: Prefetch page
2828
Given I entered the course "Course 1" as "student1" in the app
2929
When I press "Course downloads" in the app
3030
And I press "Download" within "Test page title" "ion-item" in the app

src/core/classes/sites/authenticated-site.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ export class CoreAuthenticatedSite extends CoreUnauthenticatedSite {
15921592
let expirationDelay = CoreAuthenticatedSite.UPDATE_FREQUENCIES[updateFrequency] ||
15931593
CoreAuthenticatedSite.UPDATE_FREQUENCIES[CoreCacheUpdateFrequency.USUALLY];
15941594

1595-
if (CoreNetwork.isNetworkAccessLimited()) {
1595+
if (CoreNetwork.isCellular()) {
15961596
// Not WiFi, increase the expiration delay a 50% to decrease the data usage in this case.
15971597
expirationDelay *= 1.5;
15981598
}

src/core/directives/external-content.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O
518518
clickableEl.addEventListener(eventName, () => {
519519
// User played media or opened a downloadable link.
520520
// Download the file if in wifi and it hasn't been downloaded already (for big files).
521-
if (state !== DownloadStatus.DOWNLOADED && state !== DownloadStatus.DOWNLOADING && CoreNetwork.isWifi()) {
521+
if (state !== DownloadStatus.DOWNLOADED && state !== DownloadStatus.DOWNLOADING &&
522+
CoreNetwork.isWifi()) {
522523
// We aren't using the result, so it doesn't matter which of the 2 functions we call.
523524
CoreFilepool.getUrlByUrl(site.getId(), url, this.component, this.componentId, 0, false);
524525
}

src/core/features/comments/pages/viewer/viewer.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { Component, OnDestroy, OnInit, ViewChild, AfterViewInit, inject } from '@angular/core';
15+
import { Component, OnDestroy, OnInit, ViewChild, AfterViewInit, effect, inject } from '@angular/core';
1616
import { CoreEventObserver, CoreEvents } from '@singletons/events';
1717
import { ActivatedRoute } from '@angular/router';
1818
import { CoreSites } from '@services/sites';
@@ -49,6 +49,7 @@ import { CoreDom } from '@singletons/dom';
4949
import { CoreSharedModule } from '@/core/shared.module';
5050
import { ADDON_MOD_ASSIGN_COMMENTS_COMPONENT_NAME } from '@addons/mod/assign/submission/comments/constants';
5151
import { CoreCourses } from '@features/courses/services/courses';
52+
import { CoreKeyboard } from '@singletons/keyboard';
5253

5354
/**
5455
* Page that displays comments.
@@ -93,7 +94,6 @@ export default class CoreCommentsViewerPage implements OnInit, OnDestroy, AfterV
9394
protected addDeleteCommentsAvailable = false;
9495
protected syncObserver?: CoreEventObserver;
9596
protected onlineObserver: Subscription;
96-
protected keyboardObserver: CoreEventObserver;
9797
protected viewDestroyed = false;
9898
protected scrollBottom = true;
9999
protected scrollElement?: HTMLElement;
@@ -128,9 +128,11 @@ export default class CoreCommentsViewerPage implements OnInit, OnDestroy, AfterV
128128
});
129129
});
130130

131-
this.keyboardObserver = CoreEvents.on(CoreEvents.KEYBOARD_CHANGE, (keyboardHeight: number) => {
132-
// Force when opening.
133-
this.scrollToBottom(keyboardHeight > 0);
131+
effect(() => {
132+
const shown = CoreKeyboard.getKeyboardShownSignal();
133+
134+
/// Force when opening.
135+
this.scrollToBottom(shown());
134136
});
135137
}
136138

@@ -700,7 +702,6 @@ export default class CoreCommentsViewerPage implements OnInit, OnDestroy, AfterV
700702
this.syncObserver?.off();
701703
this.onlineObserver.unsubscribe();
702704
this.viewDestroyed = true;
703-
this.keyboardObserver.off();
704705
}
705706

706707
}

src/core/features/course/components/module/core-course-module.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
@if (module.visible === 0 || module.uservisible === false) {
3131
<ion-icon name="fas-lock" [attr.aria-label]="'core.restricted' | translate" />
3232
}
33-
@if (prefetchStatusIcon$ | async; as prefetchStatusIcon) {
34-
<ion-icon [name]="prefetchStatusIcon" color="success"
35-
[attr.aria-label]="((prefetchStatusText$ | async) || '') | translate" />
33+
@if (prefetchStatusIcon()) {
34+
<ion-icon [name]="prefetchStatusIcon()" color="success"
35+
[attr.aria-label]="(prefetchStatusText() || '') | translate" />
3636
}
3737
</p>
3838

src/core/features/course/components/module/module.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { Component, Input, Output, EventEmitter, OnInit, OnDestroy, HostBinding } from '@angular/core';
15+
import { Component, Input, Output, EventEmitter, OnInit, OnDestroy, HostBinding, signal } from '@angular/core';
1616

1717
import { CoreSites } from '@services/sites';
1818
import {
@@ -29,7 +29,6 @@ import {
2929
} from '@features/course/services/module-prefetch-delegate';
3030
import { CoreConstants, DownloadStatus } from '@/core/constants';
3131
import { CoreEventObserver, CoreEvents } from '@singletons/events';
32-
import { BehaviorSubject } from 'rxjs';
3332
import { toBoolean } from '@/core/transforms/boolean';
3433
import { CoreRemindersDateComponent } from '../../../reminders/components/date/date';
3534
import { CoreCourseModuleCompletionComponent } from '../module-completion/module-completion';
@@ -74,9 +73,9 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy {
7473
modNameTranslated = '';
7574
hasCompletion = false; // Whether activity has completion to be shown.
7675
showManualCompletion = false; // Whether to show manual completion when completion conditions are disabled.
77-
prefetchStatusIcon$ = new BehaviorSubject<string>(''); // Module prefetch status icon.
78-
prefetchStatusText$ = new BehaviorSubject<string>(''); // Module prefetch status text.
7976
moduleHasView = true;
77+
readonly prefetchStatusIcon = signal<string>(''); // Module prefetch status icon.
78+
readonly prefetchStatusText = signal<string>(''); // Module prefetch status text.
8079

8180
protected prefetchHandler?: CoreCourseModulePrefetchHandler;
8281

@@ -152,16 +151,16 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy {
152151

153152
switch (prefetchStatus) {
154153
case DownloadStatus.OUTDATED:
155-
this.prefetchStatusIcon$.next(CoreConstants.ICON_OUTDATED);
156-
this.prefetchStatusText$.next('core.outdated');
154+
this.prefetchStatusIcon.set(CoreConstants.ICON_OUTDATED);
155+
this.prefetchStatusText.set('core.outdated');
157156
break;
158157
case DownloadStatus.DOWNLOADED:
159-
this.prefetchStatusIcon$.next(CoreConstants.ICON_DOWNLOADED);
160-
this.prefetchStatusText$.next('core.downloaded');
158+
this.prefetchStatusIcon.set(CoreConstants.ICON_DOWNLOADED);
159+
this.prefetchStatusText.set('core.downloaded');
161160
break;
162161
default:
163-
this.prefetchStatusIcon$.next('');
164-
this.prefetchStatusText$.next('');
162+
this.prefetchStatusIcon.set('');
163+
this.prefetchStatusText.set('');
165164
break;
166165
}
167166

src/core/features/editor/components/rich-text-editor/rich-text-editor.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
Output,
2626
EventEmitter,
2727
inject,
28+
effect,
2829
} from '@angular/core';
2930
import { IonContent } from '@ionic/angular';
3031
import { CoreSharedModule } from '@/core/shared.module';
@@ -50,6 +51,7 @@ import { CoreLoadingComponent } from '@components/loading/loading';
5051
import { CoreToasts } from '@services/overlays/toasts';
5152
import { CorePromiseUtils } from '@singletons/promise-utils';
5253
import { convertTextToHTMLElement } from '@/core/utils/create-html-element';
54+
import { CoreKeyboard } from '@singletons/keyboard';
5355

5456
/**
5557
* Component that displays a rich text editor.
@@ -85,7 +87,6 @@ export class CoreEditorRichTextEditorComponent implements AfterViewInit, OnDestr
8587

8688
@ViewChild(CoreDynamicComponent) dynamicComponent!: CoreDynamicComponent<CoreEditorBaseComponent>;
8789

88-
protected keyboardObserver?: CoreEventObserver;
8990
protected resizeListener?: CoreEventObserver;
9091
protected editorComponentClass?: Type<CoreEditorBaseComponent>;
9192
protected editorComponentData: Record<string, unknown> = {};
@@ -107,6 +108,15 @@ export class CoreEditorRichTextEditorComponent implements AfterViewInit, OnDestr
107108
constructor() {
108109
// Generate a "unique" ID based on timestamp.
109110
this.pageInstance = `app_${Date.now()}`;
111+
112+
effect(() => {
113+
// Signal will be triggered when the keyboard is shown or hidden.
114+
CoreKeyboard.getKeyboardShownSignal();
115+
116+
// Opening or closing the keyboard also calls the resize function, but sometimes the resize is called too soon.
117+
// Check the height again, now the window height should have been updated.
118+
this.maximizeEditorSize();
119+
});
110120
}
111121

112122
/**
@@ -188,20 +198,13 @@ export class CoreEditorRichTextEditorComponent implements AfterViewInit, OnDestr
188198
this.controlSubscription = this.control?.valueChanges.subscribe((newValue) => {
189199
this.onControlValueChange(newValue);
190200
});
191-
192-
// Opening or closing the keyboard also calls the resize function, but sometimes the resize is called too soon.
193-
// Check the height again, now the window height should have been updated.
194-
this.keyboardObserver = CoreEvents.on(CoreEvents.KEYBOARD_CHANGE, () => {
195-
this.maximizeEditorSize();
196-
});
197201
}
198202

199203
/**
200204
* @inheritdoc
201205
*/
202206
ngOnDestroy(): void {
203207
this.resizeListener?.off();
204-
this.keyboardObserver?.off();
205208
this.controlSubscription?.unsubscribe();
206209
this.resetObserver?.off();
207210
this.labelObserver?.disconnect();

src/core/features/fileuploader/services/fileuploader-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class CoreFileUploaderHelperProvider {
140140

141141
if (size < 0) {
142142
return CoreAlerts.confirm(Translate.instant('core.fileuploader.confirmuploadunknownsize'));
143-
} else if (size >= wifiThreshold || (CoreNetwork.isNetworkAccessLimited() && size >= limitedThreshold)) {
143+
} else if (size >= wifiThreshold || (CoreNetwork.isCellular() && size >= limitedThreshold)) {
144144
const readableSize = CoreText.bytesToSize(size, 2);
145145

146146
return CoreAlerts.confirm(Translate.instant('core.fileuploader.confirmuploadfile', { size: readableSize }));

0 commit comments

Comments
 (0)