Skip to content

Commit

Permalink
Merge branch 'master' of @wooportal/client
Browse files Browse the repository at this point in the history
  • Loading branch information
schlusslicht committed Sep 24, 2019
2 parents 6f97a26 + 970b088 commit 84ed284
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 102 deletions.
4 changes: 2 additions & 2 deletions libs/core/platform/platform.guarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { PlatformProvider } from './platform.provider';
export class PlatformGuarding
implements CanActivate, CanDeactivate<boolean | UrlTree> {

private offline: UrlTree = this.router.createUrlTree(['/', 'offline']);
private netsplit: UrlTree = this.router.createUrlTree(['/', 'netsplit']);

public constructor(
private platformProvider: PlatformProvider,
private router: Router
) { }

public canActivate(): boolean | UrlTree {
return this.platformProvider.connected || this.offline;
return this.platformProvider.connected || this.netsplit;
}

public canDeactivate(): boolean {
Expand Down
6 changes: 6 additions & 0 deletions libs/core/platform/platform.provider.i.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Observable } from 'rxjs';

export interface PlatformProvider {

readonly chromeClient: any;

readonly connected: boolean;

readonly connection: Observable<boolean>;
Expand All @@ -14,4 +16,8 @@ export interface PlatformProvider {

readonly type: 'Native' | 'Online';

readonly viewClient: any;

reload(): void;

}
49 changes: 43 additions & 6 deletions libs/core/platform/platform.provider.tns.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
import { Injectable } from '@angular/core';
import { Injectable, NgZone } from '@angular/core';
import { Router } from '@angular/router';
import { Observable, ReplaySubject } from 'rxjs';
import { filter, multicast, refCount } from 'rxjs/operators';
import { android, ios } from 'tns-core-modules/application';
import { android as androidApp, ios as iosApp } from 'tns-core-modules/application';
import { connectionType, getConnectionType, startMonitoring, stopMonitoring } from 'tns-core-modules/connectivity';
import { device } from 'tns-core-modules/platform';
import { openUrl } from 'tns-core-modules/utils/utils';
import { CoreSettings } from '../utils/settings';
import { PlatformProvider as Compat } from './platform.provider.i';

declare const android: any;

let navigate: (url: string) => Promise<boolean>;

@Injectable({ providedIn: 'root' })
export class PlatformProvider implements Compat {

public readonly chromeClient: any = android.webkit.WebChromeClient.extend({
onGeolocationPermissionsShowPrompt: (url: string, callback: any) => {
if (url.startsWith(this.coreSettings.appUrl)) {
callback.invoke(url, true, false);
}
}
});

public readonly viewClient: any = android.webkit.WebViewClient.extend({
shouldOverrideUrlLoading: (_: any, url: any) => {
url = typeof url === 'string' ? url : url.getUrl().toString();

if (url.startsWith(this.coreSettings.appUrl)) {
navigate(url.replace(this.coreSettings.appUrl, ''));
} else {
openUrl(url);
}

return true;
}
});

public get connected(): boolean {
return this.online(getConnectionType());
}
Expand All @@ -28,8 +55,8 @@ export class PlatformProvider implements Compat {

public get engine(): any {
switch (this.name) {
case 'Android': return android;
case 'iOS': return ios;
case 'Android': return androidApp;
case 'iOS': return iosApp;
}
}

Expand All @@ -47,10 +74,20 @@ export class PlatformProvider implements Compat {

public constructor(
private coreSettings: CoreSettings,
router: Router
router: Router,
zone: NgZone
) {
navigate = (url) => zone.run(() => router.navigateByUrl(url));

this.connection.pipe(filter((state) => !state))
.subscribe(() => router.navigate(['/', 'offline']));
.subscribe(() => router.navigate(['/', 'netsplit']));
}

public reload(): void {
switch (this.name) {
case 'Android': return this.engine.foregroundActivity.finish();
case 'iOS': return;
}
}

private online(type: connectionType): boolean {
Expand Down
10 changes: 9 additions & 1 deletion libs/core/platform/platform.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { PlatformProvider as Compat } from './platform.provider.i';
@Injectable({ providedIn: 'root' })
export class PlatformProvider implements Compat {

public readonly chromeClient: any;

public readonly viewClient: any;

public get connected(): boolean {
switch (this.name) {
case 'Server': return true;
Expand Down Expand Up @@ -68,7 +72,11 @@ export class PlatformProvider implements Compat {
router: Router
) {
this.connection.pipe(filter((state) => !state))
.subscribe(() => router.navigate(['/', 'offline']));
.subscribe(() => router.navigate(['/', 'netsplit']));
}

public reload(): void {
this.document.defaultView.location.reload();
}

}
10 changes: 5 additions & 5 deletions libs/core/session/session.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class SessionProvider {
});
}

public isLiked(id: string): boolean {
return this.session.value.likes.includes(id);
}

public like(id: string): void {
if (!this.isLiked(id)) {
this.session.next(Object.assign(this.session.value, {
Expand All @@ -40,11 +44,7 @@ export class SessionProvider {
}
}

public isLiked(id: string): boolean {
return this.session.value.likes.includes(id);
}

public changeLanguage(language: string): void {
public setLanguage(language: string): void {
this.session.next(Object.assign(this.session.value, { language }));
}

Expand Down
4 changes: 2 additions & 2 deletions res/Android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="__PACKAGE__"
android:versionCode="1"
android:versionName="1.0">
android:versionCode="3"
android:versionName="0.1.0">

<supports-screens
android:smallScreens="true"
Expand Down
5 changes: 0 additions & 5 deletions src/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ layout-component {
@include flex(column);
@include position(fixed, 0, 0, 0, 0);

&.fadeout {
opacity: 0;
transition: opacity $animation-duration;
}

& > header {
height: 10rem;
overflow: hidden;
Expand Down
2 changes: 1 addition & 1 deletion src/client.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const routes: Route[] = [
exports: [RouterModule],
imports: [RouterModule.forRoot([
{
path: 'offline',
path: 'netsplit',
canDeactivate: [PlatformGuarding],
component: ErrorNetsplitComponent
},
Expand Down
2 changes: 1 addition & 1 deletion src/native.router.tns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const routes: Route[] = [
exports: [NativeScriptRouterModule],
imports: [NativeScriptRouterModule.forRoot([
{
path: 'offline',
path: 'netsplit',
canDeactivate: [PlatformGuarding],
component: ErrorNetsplitComponent
},
Expand Down
30 changes: 0 additions & 30 deletions src/utils/clients.ts

This file was deleted.

20 changes: 5 additions & 15 deletions src/views/maps/maps.component.tns.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AfterViewInit, Component, ElementRef, NgZone, OnInit, ViewChild } from '@angular/core';
import { Route, Router } from '@angular/router';
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { Route } from '@angular/router';
import { PlatformProvider, Selfrouter } from '@wooportal/core';
import { WebView } from 'tns-core-modules/ui/web-view';
import { WebChromeClientFactory, WebViewClientFactory } from '../../utils/clients';
import { ClientPackage } from '../../utils/package';
import { geolocation } from '../shared/shared.imports';

Expand All @@ -26,9 +25,7 @@ export class MapsComponent
}

public constructor(
private platformProvider: PlatformProvider,
private router: Router,
private zone: NgZone
private platformProvider: PlatformProvider
) {
super();
}
Expand All @@ -46,18 +43,11 @@ export class MapsComponent

switch (this.platformProvider.name) {
case 'Android':
const WebChromeClient = WebChromeClientFactory();
const WebViewClient = WebViewClientFactory((url) => {
if (!url.startsWith(this.router.url)) {
this.zone.run(() => this.router.navigateByUrl(url));
}
});

wv = wv.android;
wv.getSettings().setGeolocationEnabled(true);
wv.getSettings().setJavaScriptEnabled(true);
wv.setWebChromeClient(new WebChromeClient());
wv.setWebViewClient(new WebViewClient());
wv.setWebChromeClient(new this.platformProvider.chromeClient());
wv.setWebViewClient(new this.platformProvider.viewClient());
return;

case 'iOS':
Expand Down
2 changes: 1 addition & 1 deletion src/views/maps/maps.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class MapsComponent
if (this.connection) {
this.connection.nextRoute(event.url);
} else if (this.native) {
this.document.location.href = event.url;
this.document.defaultView.location.href = event.url;
} else if (this.route.snapshot.queryParamMap.has('embed')) {
this.router.navigate(this.route.snapshot.url);
}
Expand Down
17 changes: 4 additions & 13 deletions src/views/public/objects/activity/activity.object.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Component, ElementRef, NgZone, Optional, Type, ViewChild } from '@angular/core';
import { Component, ElementRef, Optional, Type, ViewChild } from '@angular/core';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { ActivatedRoute, Router } from '@angular/router';
import { I18n } from '@ngx-translate/i18n-polyfill';
import { CrudJoiner, PlatformProvider, Title } from '@wooportal/core';
import { WebView } from 'tns-core-modules/ui/web-view';
import { ActivityModel } from '../../../../realm/models/activity.model';
import { ScheduleModel } from '../../../../realm/models/schedule.model';
import { WebChromeClientFactory, WebViewClientFactory } from '../../../../utils/clients';
import { ClientPackage } from '../../../../utils/package';
import { geolocation } from '../../../shared/shared.imports';
import { BaseObject } from '../base.object';
Expand Down Expand Up @@ -42,7 +41,6 @@ export class ActivityObjectComponent extends BaseObject<ActivityModel> {

public constructor(
@Optional() private sanitizer: DomSanitizer,
private zone: NgZone,
i18n: I18n,
platformProvider: PlatformProvider,
route: ActivatedRoute,
Expand All @@ -57,7 +55,7 @@ export class ActivityObjectComponent extends BaseObject<ActivityModel> {

switch (this.platformProvider.type) {
case 'Native':
geolocation.enableLocationRequest().catch(() => null);
geolocation.enableLocationRequest().catch(() => { });
this.source = ClientPackage.config.defaults.appUrl + url + '&native';
break;

Expand All @@ -77,18 +75,11 @@ export class ActivityObjectComponent extends BaseObject<ActivityModel> {

switch (this.platformProvider.name) {
case 'Android':
const WebChromeClient = WebChromeClientFactory();
const WebViewClient = WebViewClientFactory((url) => {
if (!url.startsWith(this.router.url)) {
this.zone.run(() => this.router.navigateByUrl(url));
}
});

wv = wv.android;
wv.getSettings().setGeolocationEnabled(true);
wv.getSettings().setJavaScriptEnabled(true);
wv.setWebChromeClient(new WebChromeClient());
wv.setWebViewClient(new WebViewClient());
wv.setWebChromeClient(new this.platformProvider.chromeClient());
wv.setWebViewClient(new this.platformProvider.viewClient());
return;

case 'iOS':
Expand Down
4 changes: 3 additions & 1 deletion src/views/shared/compat/calendar/calendar.compat.tns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export class CalendarCompatComponent implements CalendarCompat, AfterViewInit {
}

public get startdate(): Date {
return new Date(this.items[0].startDate);
return this.items.length
? new Date(this.items[0].startDate)
: new Date();
}

public ngAfterViewInit(): void {
Expand Down
4 changes: 3 additions & 1 deletion src/views/shared/compat/calendar/calendar.compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export class CalendarCompatComponent implements CalendarCompat {
public selectable: (date: Date) => boolean = this.scheduled.bind(this);

public get startdate(): Date {
return new Date(this.items[0].startDate);
return this.items.length
? new Date(this.items[0].startDate)
: new Date();
}

public click(event: Event): void {
Expand Down
5 changes: 1 addition & 4 deletions src/views/shared/compat/marked/marked.compat.tns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AfterViewInit, Component, ElementRef, HostBinding, Input, OnInit, ViewC
import { PlatformProvider } from '@wooportal/core';
import * as marked from 'marked';
import { WebView } from 'tns-core-modules/ui/web-view';
import { WebViewClientFactory } from '../../../../utils/clients';
import { MarkedCompat } from './marked.compat.i';

@Component({
Expand Down Expand Up @@ -43,12 +42,10 @@ export class MarkedCompatComponent

switch (this.platformProvider.name) {
case 'Android':
const WebViewClient = WebViewClientFactory();

wv = wv.android;
wv.setBackgroundColor(0x00000000);
wv.getSettings().setSupportZoom(false);
wv.setWebViewClient(new WebViewClient());
wv.setWebViewClient(new this.platformProvider.viewClient());
return;

case 'iOS':
Expand Down
Loading

0 comments on commit 84ed284

Please sign in to comment.