From 560a52fee78112af8ebcf69d98df9b0971de4023 Mon Sep 17 00:00:00 2001 From: Mike Nsubuga Date: Thu, 6 Aug 2020 16:40:34 +0300 Subject: [PATCH 1/6] added firebase sdk --- maths-club-app/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/maths-club-app/package.json b/maths-club-app/package.json index f151cd86..c01d466e 100644 --- a/maths-club-app/package.json +++ b/maths-club-app/package.json @@ -26,6 +26,7 @@ "@capacitor/android": "2.2.1", "@capacitor/cli": "^2.2.1", "@capacitor/core": "^2.2.1", + "firebase": "^7.17.1", "material-design-icons": "^3.0.1", "ngx-markdown": "^9.1.1", "rxjs": "~6.5.4", From ae790d31cfae7a02f61f6d508371d00fd788087b Mon Sep 17 00:00:00 2001 From: Mike Nsubuga Date: Tue, 27 Oct 2020 22:09:02 +0300 Subject: [PATCH 2/6] added share button --- .../io/c2dev/samimathsclub/MainActivity.java | 21 +++++++++++++++++++ .../problem-detail.component.html | 3 +++ .../problem-detail.component.ts | 12 +++++++++++ 3 files changed, 36 insertions(+) create mode 100644 maths-club-app/android/app/src/main/java/io/c2dev/samimathsclub/MainActivity.java diff --git a/maths-club-app/android/app/src/main/java/io/c2dev/samimathsclub/MainActivity.java b/maths-club-app/android/app/src/main/java/io/c2dev/samimathsclub/MainActivity.java new file mode 100644 index 00000000..22c66610 --- /dev/null +++ b/maths-club-app/android/app/src/main/java/io/c2dev/samimathsclub/MainActivity.java @@ -0,0 +1,21 @@ +package io.c2dev.samimathsclub; + +import android.os.Bundle; + +import com.getcapacitor.BridgeActivity; +import com.getcapacitor.Plugin; + +import java.util.ArrayList; + +public class MainActivity extends BridgeActivity { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Initializes the Bridge + this.init(savedInstanceState, new ArrayList>() {{ + // Additional plugins you've installed go here + // Ex: add(TotallyAwesomePlugin.class); + }}); + } +} diff --git a/maths-club-app/src/app/components/problem-detail/problem-detail.component.html b/maths-club-app/src/app/components/problem-detail/problem-detail.component.html index f9fc7b80..84a690a2 100644 --- a/maths-club-app/src/app/components/problem-detail/problem-detail.component.html +++ b/maths-club-app/src/app/components/problem-detail/problem-detail.component.html @@ -16,6 +16,9 @@ + diff --git a/maths-club-app/src/app/components/problem-detail/problem-detail.component.ts b/maths-club-app/src/app/components/problem-detail/problem-detail.component.ts index 5e129288..8330ff8c 100644 --- a/maths-club-app/src/app/components/problem-detail/problem-detail.component.ts +++ b/maths-club-app/src/app/components/problem-detail/problem-detail.component.ts @@ -1,6 +1,8 @@ import { Component, ViewEncapsulation, ChangeDetectorRef } from "@angular/core"; import { ProblemService } from "src/app/services/problem.service"; import { fadeInOut } from "src/app/animations"; +import { Plugins } from '@capacitor/core'; +const { Share } = Plugins; @Component({ selector: "app-problem-detail", @@ -13,6 +15,7 @@ export class ProblemDetailComponent { markdownReady = false; constructor( public problemService: ProblemService, + //private socialSharing: SocialSharing, private cdr: ChangeDetectorRef ) {} @@ -22,4 +25,13 @@ export class ProblemDetailComponent { // change detection to avoid change detection errors this.cdr.detectChanges(); } + + async share(){ + await Share.share({ + title: '15 numbers', + text: 'Real', + url: 'https://mathsclub.samicharity.co.uk/en/15-game', + dialogTitle: 'Share with buddies' + }); + } } From 089b37c7122d41905650ed4a009f8f2bc9defb78 Mon Sep 17 00:00:00 2001 From: Mike Nsubuga Date: Tue, 27 Oct 2020 23:00:05 +0300 Subject: [PATCH 3/6] added problem deep link urls to share button --- .../problem-detail.component.ts | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/maths-club-app/src/app/components/problem-detail/problem-detail.component.ts b/maths-club-app/src/app/components/problem-detail/problem-detail.component.ts index 8330ff8c..6583d2cc 100644 --- a/maths-club-app/src/app/components/problem-detail/problem-detail.component.ts +++ b/maths-club-app/src/app/components/problem-detail/problem-detail.component.ts @@ -1,4 +1,4 @@ -import { Component, ViewEncapsulation, ChangeDetectorRef } from "@angular/core"; +import { Component, ViewEncapsulation, ChangeDetectorRef, OnInit } from "@angular/core"; import { ProblemService } from "src/app/services/problem.service"; import { fadeInOut } from "src/app/animations"; import { Plugins } from '@capacitor/core'; @@ -11,27 +11,37 @@ const { Share } = Plugins; encapsulation: ViewEncapsulation.None, animations: [fadeInOut], }) -export class ProblemDetailComponent { +export class ProblemDetailComponent implements OnInit { markdownReady = false; constructor( public problemService: ProblemService, - //private socialSharing: SocialSharing, private cdr: ChangeDetectorRef ) {} + ngOnInit(){ + console.log("on init", this.problemService); + } + onMarkdownReady() { this.markdownReady = true; + //console.log("on md ready", this.problemService.activeProblem$.value); + // as markdown can be ready before page fully initialised complete manually trigger // change detection to avoid change detection errors this.cdr.detectChanges(); } + async share(){ await Share.share({ - title: '15 numbers', - text: 'Real', - url: 'https://mathsclub.samicharity.co.uk/en/15-game', + title: this.problemService.activeProblem$.value.title, + text: this.problemService.activeProblem$.value.title, + url: `https://mathsclub.samicharity.co.uk/en/${this.problemService.activeProblem$.value.slug}`, dialogTitle: 'Share with buddies' - }); + }).then((success)=>{ + console.log("shared") + }).catch((err)=>{ + console.log("an error occureed") + }) } } From 1b2eda36970048aa2b73e2c3f37ea58b8f698fb5 Mon Sep 17 00:00:00 2001 From: Mike Nsubuga Date: Sun, 1 Nov 2020 10:58:55 +0300 Subject: [PATCH 4/6] check if onMobile to show share button --- .../problem-detail.component.html | 2 +- .../problem-detail.component.ts | 27 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/maths-club-app/src/app/components/problem-detail/problem-detail.component.html b/maths-club-app/src/app/components/problem-detail/problem-detail.component.html index 84a690a2..019559e1 100644 --- a/maths-club-app/src/app/components/problem-detail/problem-detail.component.html +++ b/maths-club-app/src/app/components/problem-detail/problem-detail.component.html @@ -16,7 +16,7 @@ - diff --git a/maths-club-app/src/app/components/problem-detail/problem-detail.component.ts b/maths-club-app/src/app/components/problem-detail/problem-detail.component.ts index 6583d2cc..ecf05358 100644 --- a/maths-club-app/src/app/components/problem-detail/problem-detail.component.ts +++ b/maths-club-app/src/app/components/problem-detail/problem-detail.component.ts @@ -1,7 +1,7 @@ import { Component, ViewEncapsulation, ChangeDetectorRef, OnInit } from "@angular/core"; import { ProblemService } from "src/app/services/problem.service"; import { fadeInOut } from "src/app/animations"; -import { Plugins } from '@capacitor/core'; +import { Capacitor, Plugins } from '@capacitor/core'; const { Share } = Plugins; @Component({ @@ -13,6 +13,8 @@ const { Share } = Plugins; }) export class ProblemDetailComponent implements OnInit { markdownReady = false; + isNative = Capacitor.isNative; + constructor( public problemService: ProblemService, private cdr: ChangeDetectorRef @@ -31,17 +33,20 @@ export class ProblemDetailComponent implements OnInit { this.cdr.detectChanges(); } + async share(){ - await Share.share({ - title: this.problemService.activeProblem$.value.title, - text: this.problemService.activeProblem$.value.title, - url: `https://mathsclub.samicharity.co.uk/en/${this.problemService.activeProblem$.value.slug}`, - dialogTitle: 'Share with buddies' - }).then((success)=>{ - console.log("shared") - }).catch((err)=>{ - console.log("an error occureed") - }) + if(Capacitor.isNative){ + await Share.share({ + title: this.problemService.activeProblem$.value.title, + text: "Here's a problem for you to try! If you get stuck there are also notes for facilitators included", + url: `https://mathsclub.samicharity.co.uk/en/${this.problemService.activeProblem$.value.slug}`, + dialogTitle: 'Share' + }).then((success)=>{ + console.log("shared") + }).catch((err)=>{ + console.log("an error occureed") + }) + } } } From a62e3e5de5bb84744802d6c9e5ae044c87d90953 Mon Sep 17 00:00:00 2001 From: Mike Nsubuga Date: Sun, 1 Nov 2020 12:48:30 +0300 Subject: [PATCH 5/6] removed duplicate main class --- .../io/c2dev/samimathsclub/MainActivity.java | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 maths-club-app/android/app/src/main/java/io/c2dev/samimathsclub/MainActivity.java diff --git a/maths-club-app/android/app/src/main/java/io/c2dev/samimathsclub/MainActivity.java b/maths-club-app/android/app/src/main/java/io/c2dev/samimathsclub/MainActivity.java deleted file mode 100644 index 22c66610..00000000 --- a/maths-club-app/android/app/src/main/java/io/c2dev/samimathsclub/MainActivity.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.c2dev.samimathsclub; - -import android.os.Bundle; - -import com.getcapacitor.BridgeActivity; -import com.getcapacitor.Plugin; - -import java.util.ArrayList; - -public class MainActivity extends BridgeActivity { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // Initializes the Bridge - this.init(savedInstanceState, new ArrayList>() {{ - // Additional plugins you've installed go here - // Ex: add(TotallyAwesomePlugin.class); - }}); - } -} From 896940a3143e8ebc5151d903d0870db7f766dec9 Mon Sep 17 00:00:00 2001 From: Mike Nsubuga Date: Fri, 6 Nov 2020 09:51:49 +0300 Subject: [PATCH 6/6] added exitOnBack in ProblemList component --- maths-club-app/android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 4 ++-- maths-club-app/src/app/app.component.ts | 16 ++++------------ .../problems-list/problems-list.component.ts | 18 ++++++++++++++++-- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/maths-club-app/android/build.gradle b/maths-club-app/android/build.gradle index 48f76bf6..db432bb2 100644 --- a/maths-club-app/android/build.gradle +++ b/maths-club-app/android/build.gradle @@ -8,7 +8,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.1' + classpath 'com.android.tools.build:gradle:4.1.0' classpath 'com.google.gms:google-services:4.3.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" diff --git a/maths-club-app/android/gradle/wrapper/gradle-wrapper.properties b/maths-club-app/android/gradle/wrapper/gradle-wrapper.properties index 2148d5ed..4c85a5f2 100644 --- a/maths-club-app/android/gradle/wrapper/gradle-wrapper.properties +++ b/maths-club-app/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Aug 05 09:58:33 EAT 2020 +#Sun Nov 01 13:50:01 EAT 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip diff --git a/maths-club-app/src/app/app.component.ts b/maths-club-app/src/app/app.component.ts index d1797e10..aea3f3c1 100644 --- a/maths-club-app/src/app/app.component.ts +++ b/maths-club-app/src/app/app.component.ts @@ -1,6 +1,6 @@ -import { Component, NgZone, ViewEncapsulation } from "@angular/core"; +import { Component, NgZone, ViewEncapsulation} from "@angular/core"; import { AppService } from "./services/app.service"; -import { Router, RouterOutlet } from "@angular/router"; +import { Router, RouterOutlet} from "@angular/router"; import { slideTransition } from "./animations"; import { environment } from "src/environments/environment"; @@ -10,7 +10,6 @@ import { Plugins, Capacitor, StatusBarStyle } from "@capacitor/core"; import { AnalyticsService } from "./services/analytics.service"; import { SeoService } from "./services/seo.service"; const { StatusBar, App } = Plugins; - @Component({ selector: "app-root", templateUrl: "./app.component.html", @@ -26,7 +25,7 @@ export class AppComponent { analytics: AnalyticsService, seo: SeoService, private zone: NgZone, - private router: Router + private router: Router, ) { // this.notifications.init() analytics.init(); @@ -37,9 +36,7 @@ export class AppComponent { } else { // SEO only relevant whe not native seo.init(); - } - //exit on back - this.exitOnBack(); + } } getRouteAnimationState(outlet: RouterOutlet) { return ( @@ -63,9 +60,4 @@ export class AppComponent { }); }); } - exitOnBack(){ - if(Capacitor.isNative){ - App.addListener('backButton', App.exitApp) - } - } } diff --git a/maths-club-app/src/app/components/problems-list/problems-list.component.ts b/maths-club-app/src/app/components/problems-list/problems-list.component.ts index faeb60cc..57591035 100644 --- a/maths-club-app/src/app/components/problems-list/problems-list.component.ts +++ b/maths-club-app/src/app/components/problems-list/problems-list.component.ts @@ -1,7 +1,9 @@ -import { Component } from "@angular/core"; +import { Component, OnDestroy, OnInit } from "@angular/core"; import { ProblemService } from "../../services/problem.service"; import { fadeChildren } from "src/app/animations"; import * as Sentry from "@sentry/angular"; +import { Plugins, Capacitor } from "@capacitor/core"; +const { StatusBar, App } = Plugins; @Component({ selector: "app-problems", @@ -9,7 +11,7 @@ import * as Sentry from "@sentry/angular"; styleUrls: ["./problems-list.component.scss"], animations: [fadeChildren], }) -export class ProblemsListComponent { +export class ProblemsListComponent implements OnInit, OnDestroy{ constructor(public problemService: ProblemService) {} /** @@ -18,4 +20,16 @@ export class ProblemsListComponent { testClick(identifier: string) { Sentry.captureMessage(`[${identifier}] UI Test Interaction Recorded`); } + + ngOnInit(){ + if(Capacitor.isNative){ + App.addListener('backButton', App.exitApp); + } + } + + ngOnDestroy(){ + if(Capacitor.isNative){ + App.removeAllListeners(); + } + } }