-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PokeMob notifications #149
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3bb963b
PokeMob notifications
75a96d6
Merge remote-tracking branch 'origin/develop' into notifications
4d3cd31
Scheduling notifications only on native Android (but not in the browser)
a65a054
Change notification text
29ae5ba
Merge remote-tracking branch 'origin/develop' into notifications
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
import { Component } from '@angular/core'; | ||
import { Platform } from 'ionic-angular'; | ||
import { Component, ViewChild } from '@angular/core'; | ||
import { Platform, Nav } from 'ionic-angular'; | ||
import { StatusBar, Splashscreen } from 'ionic-native'; | ||
import 'rxjs/add/operator/map'; | ||
|
||
import { MapPage } from '../pages/map/map.page'; | ||
import { NotificationService } from '../services/notification.service'; | ||
|
||
@Component({ | ||
templateUrl: './app.html' | ||
}) | ||
export class App { | ||
rootPage = MapPage; | ||
|
||
constructor(private platform: Platform) { | ||
@ViewChild('content') nav: Nav; | ||
|
||
constructor(private platform: Platform, private notificationService: NotificationService) { | ||
platform.ready().then(() => { | ||
// Okay, so the platform is ready and our plugins are available. | ||
// Here you can do any higher level native things you might need. | ||
StatusBar.styleDefault(); | ||
Splashscreen.hide(); | ||
if (platform.is('cordova')) { | ||
StatusBar.styleDefault(); | ||
Splashscreen.hide(); | ||
} | ||
|
||
if (platform.is('android') && !platform.is('mobileweb')) { | ||
notificationService.setNav(this.nav); | ||
notificationService.scheduleNotifications(); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Nav } from 'ionic-angular'; | ||
import { LocalNotifications } from 'ionic-native'; | ||
|
||
import { Mob } from '../models/mob'; | ||
import { MapPage } from '../pages/map/map.page'; | ||
import { ApiService } from './api.service'; | ||
|
||
@Injectable() | ||
export class NotificationService { | ||
|
||
private MOB_NOTIFICATION_ID = 1; | ||
private MOB_ZOOM_LEVEL = 15; | ||
|
||
private nav: Nav; | ||
|
||
constructor(private apiService: ApiService) {} | ||
|
||
setNav(nav: Nav) { | ||
this.nav = nav; | ||
} | ||
|
||
scheduleNotifications() { | ||
this.apiService.subscribeToMobs(this.showMobNotification.bind(this)); | ||
|
||
LocalNotifications.on('click', notification => { | ||
switch(notification.id) { | ||
case this.MOB_NOTIFICATION_ID: | ||
this.onMobNotificationClick(JSON.parse(notification.data)); | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
showMobNotification(mob: Mob) { | ||
// https://github.com/katzer/cordova-plugin-local-notifications/wiki/04.-Scheduling | ||
LocalNotifications.schedule({ | ||
id: this.MOB_NOTIFICATION_ID, | ||
title: 'PredictEmAll - PokeMob detected', | ||
text: mob.tweets.length + ' tweets about Pokémon were posted in your area', | ||
icon: 'res://icon.png', | ||
smallIcon: 'res://icon.png', | ||
data: mob | ||
}); | ||
} | ||
|
||
onMobNotificationClick(mob: Mob) { | ||
let parameters: any = {}; | ||
parameters.position = { | ||
coordinates: { | ||
latitude: mob.coordinates[1], | ||
longitude: mob.coordinates[0] | ||
}, | ||
zoomLevel: this.MOB_ZOOM_LEVEL | ||
}; | ||
|
||
this.nav.setRoot(MapPage, parameters); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as io from 'socket.io-client'; | ||
import { Injectable } from '@angular/core'; | ||
import { ConfigService } from './config.service'; | ||
|
||
@Injectable() | ||
export class WebsocketService { | ||
|
||
private connected: Promise<any>; | ||
|
||
constructor(config: ConfigService) { | ||
let socket: any = io.connect(config.websocketEndpoint); | ||
|
||
this.connected = new Promise((resolve, reject) => { | ||
socket.on('connect', () => resolve(socket)); | ||
}); | ||
} | ||
|
||
on(key: string, callback: ((any) => any)) { | ||
this.connected.then(socket => { | ||
socket.on(key, callback); | ||
}); | ||
} | ||
|
||
emit(key: string, data: any) { | ||
this.connected.then(socket => { | ||
socket.emit(key, data); | ||
}) | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason to add this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well this is just how the mob object looks like PokemonGoers/PokeMap-2#32 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok 😆 I'll just accept it the way it is.