Browse Source
ADD: Android notifications ADD: Switches for push type FIX: Removed unused var FIX: Remove unused proppushn
Marcos Rodriguez
5 years ago
17 changed files with 344 additions and 15 deletions
@ -0,0 +1,40 @@ |
|||
{ |
|||
"project_info": { |
|||
"project_number": "541972087747", |
|||
"firebase_url": "https://bluewallet-a33f1.firebaseio.com", |
|||
"project_id": "bluewallet-a33f1", |
|||
"storage_bucket": "bluewallet-a33f1.appspot.com" |
|||
}, |
|||
"client": [ |
|||
{ |
|||
"client_info": { |
|||
"mobilesdk_app_id": "1:541972087747:android:ee6cc9c4a1be5b37df3376", |
|||
"android_client_info": { |
|||
"package_name": "io.bluewallet.bluewallet" |
|||
} |
|||
}, |
|||
"oauth_client": [ |
|||
{ |
|||
"client_id": "541972087747-20h4jb8vovckcdr56skfigcf3odocg64.apps.googleusercontent.com", |
|||
"client_type": 3 |
|||
} |
|||
], |
|||
"api_key": [ |
|||
{ |
|||
"current_key": "AIzaSyDLYHQwXTcvPlSgT7bIEoCxqdRSqMNMuac" |
|||
} |
|||
], |
|||
"services": { |
|||
"appinvite_service": { |
|||
"other_platform_oauth_client": [ |
|||
{ |
|||
"client_id": "541972087747-20h4jb8vovckcdr56skfigcf3odocg64.apps.googleusercontent.com", |
|||
"client_type": 3 |
|||
} |
|||
] |
|||
} |
|||
} |
|||
} |
|||
], |
|||
"configuration_version": "1" |
|||
} |
@ -1,3 +1,4 @@ |
|||
{ |
|||
"app_secret": "7a010505-cccc-4e40-aa6b-fbbe0624c8d9" |
|||
"app_secret": "7a010505-cccc-4e40-aa6b-fbbe0624c8d9", |
|||
"enable_push_in_javascript": true |
|||
} |
@ -0,0 +1,71 @@ |
|||
import Push from 'appcenter-push'; |
|||
import { AppState, Alert } from 'react-native'; |
|||
import AsyncStorage from '@react-native-community/async-storage'; |
|||
|
|||
export default class BlueNotifications { |
|||
static PRICE_FLUCTUATION = 'NOTIFICATION_PRICE_FLUCTUATION'; |
|||
static NEWS = 'NOTIFICATION_NEWS'; |
|||
|
|||
static async setEnabled(value) { |
|||
let setListener = !(await Push.isEnabled()); |
|||
await Push.setEnabled(value); |
|||
if (setListener) { |
|||
await BlueNotifications.setListener(); |
|||
} |
|||
await BlueNotifications.setNotificationTypeEnabled(BlueNotifications.NEWS, value); |
|||
await BlueNotifications.setNotificationTypeEnabled(BlueNotifications.PRICE_FLUCTUATION, values); |
|||
} |
|||
|
|||
static async isEnabled() { |
|||
return Push.isEnabled(); |
|||
} |
|||
|
|||
static async isNotificationTypeEnabled(notificatonType) { |
|||
try { |
|||
const notificationEnabled = await AsyncStorage.getItem(notificatonType); |
|||
return !!notificationEnabled; |
|||
} catch { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
static async setNotificationTypeEnabled(notificatonType, isEnabled) { |
|||
return AsyncStorage.setItem(notificatonType, isEnabled ? '1' : ''); |
|||
} |
|||
|
|||
static async setListener() { |
|||
if (await Push.isEnabled()) { |
|||
Push.setListener({ |
|||
onPushNotificationReceived: async function(pushNotification) { |
|||
let message = pushNotification.message; |
|||
let title = pushNotification.title; |
|||
console.log(pushNotification); |
|||
if (message === null) { |
|||
// Android messages received in the background don't include a message. On Android, that fact can be used to
|
|||
// check if the message was received in the background or foreground. For iOS the message is always present.
|
|||
title = 'Android background'; |
|||
message = '<empty>'; |
|||
} |
|||
|
|||
// Custom name/value pairs set in the App Center web portal are in customProperties
|
|||
if (pushNotification.customProperties && Object.keys(pushNotification.customProperties).length > 0) { |
|||
if (!(await BlueNotifications.isNotificationTypeEnabled(pushNotification.customProperties.type))) { |
|||
return; |
|||
} |
|||
} |
|||
|
|||
if (AppState.currentState === 'active') { |
|||
Alert.alert(title, message); |
|||
} else { |
|||
// Sometimes the push callback is received shortly before the app is fully active in the foreground.
|
|||
// In this case you'll want to save off the notification info and wait until the app is fully shown
|
|||
// in the foreground before displaying any UI. You could use AppState.addEventListener to be notified
|
|||
// when the app is fully in the foreground.
|
|||
} |
|||
}, |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
|
|||
BlueNotifications.setListener(); |
@ -1,8 +1,10 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
|||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
|||
<plist version="1.0"> |
|||
<dict> |
|||
<key>AppSecret</key> |
|||
<string>e83710b1-61c2-497b-b0f7-c3b6ab79f2d8</string> |
|||
</dict> |
|||
</plist> |
|||
<dict> |
|||
<key>EnablePushInJavascript</key> |
|||
<true/> |
|||
<key>AppSecret</key> |
|||
<string>e83710b1-61c2-497b-b0f7-c3b6ab79f2d8</string> |
|||
</dict> |
|||
</plist> |
|||
|
@ -0,0 +1,8 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
|||
<plist version="1.0"> |
|||
<dict> |
|||
<key>aps-environment</key> |
|||
<string>development</string> |
|||
</dict> |
|||
</plist> |
@ -0,0 +1,73 @@ |
|||
import React, { Component } from 'react'; |
|||
import { View } from 'react-native'; |
|||
import { SafeBlueArea, BlueNavigationStyle, BlueListItem, BlueText, BlueCard } from '../../BlueComponents'; |
|||
import BlueNotifications from '../../class/BlueNotifications'; |
|||
|
|||
export default class SettingsNotifications extends Component { |
|||
static navigationOptions = () => ({ |
|||
...BlueNavigationStyle(), |
|||
title: 'Notifications', |
|||
}); |
|||
|
|||
constructor(props) { |
|||
super(props); |
|||
this.state = { notificationsEnabled: false, blueWalletNewsNotificationEnabled: false, bitcoinPriceNotificationEnabled: false }; |
|||
} |
|||
|
|||
notificationSwitchValueChanged = async value => { |
|||
await BlueNotifications.setEnabled(value); |
|||
this.setState({ notificationsEnabled: value, bitcoinPriceNotificationEnabled: value, blueWalletNewsNotificationEnabled: value }); |
|||
}; |
|||
|
|||
bitcoinPriceNotificationSwitchValueChanged = async value => { |
|||
await BlueNotifications.setNotificationTypeEnabled(BlueNotifications.PRICE_FLUCTUATION, value); |
|||
this.setState({ bitcoinPriceNotificationEnabled: value }); |
|||
}; |
|||
|
|||
blueWalletNewsNotificationSwitchValueChanged = async value => { |
|||
await BlueNotifications.setNotificationTypeEnabled(BlueNotifications.NEWS, value); |
|||
this.setState({ blueWalletNewsNotificationEnabled: value }); |
|||
}; |
|||
|
|||
async componentDidMount() { |
|||
const notificationsEnabled = await BlueNotifications.isEnabled(); |
|||
const blueWalletNewsNotificationEnabled = await BlueNotifications.isNotificationTypeEnabled(BlueNotifications.NEWS); |
|||
const bitcoinPriceNotificationEnabled = await BlueNotifications.isNotificationTypeEnabled(BlueNotifications.PRICE_FLUCTUATION); |
|||
this.setState({ notificationsEnabled, blueWalletNewsNotificationEnabled, bitcoinPriceNotificationEnabled }); |
|||
} |
|||
|
|||
render() { |
|||
return ( |
|||
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}> |
|||
<View style={{ flex: 1 }}> |
|||
<BlueListItem |
|||
hideChevron |
|||
switchButton |
|||
switched={this.state.notificationsEnabled} |
|||
onSwitch={this.notificationSwitchValueChanged} |
|||
title="Notifications" |
|||
/> |
|||
<BlueCard> |
|||
<BlueText>By enabling, you will receive notifications related to:</BlueText> |
|||
</BlueCard> |
|||
<BlueListItem |
|||
hideChevron |
|||
switchButton |
|||
switchDisabled={!this.state.notificationsEnabled} |
|||
switched={this.state.blueWalletNewsNotificationEnabled} |
|||
onSwitch={this.blueWalletNewsNotificationSwitchValueChanged} |
|||
title="BlueWallet News" |
|||
/> |
|||
<BlueListItem |
|||
hideChevron |
|||
switchButton |
|||
switchDisabled={!this.state.notificationsEnabled} |
|||
switched={this.state.bitcoinPriceNotificationEnabled} |
|||
onSwitch={this.bitcoinPriceNotificationSwitchValueChanged} |
|||
title="Bitcoin Price Fluctuation" |
|||
/> |
|||
</View> |
|||
</SafeBlueArea> |
|||
); |
|||
} |
|||
} |
Loading…
Reference in new issue