Skip to content

Commit

Permalink
feat: add Android Nearby toggle in front
Browse files Browse the repository at this point in the history
Signed-off-by: D4ryl00 <d4ryl00@gmail.com>
  • Loading branch information
D4ryl00 committed Mar 26, 2021
1 parent ba8fca0 commit a37d814
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
3 changes: 3 additions & 0 deletions js/packages/berty-i18n/locale/en-US/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@
"mc": {
"activate-button": "Activate Multipeer Connectivity"
},
"nearby": {
"activate-button": "Activate Android Nearby"
},
"services-auth": {
"title": "External services",
"operated-services-button": "Use Berty operated services",
Expand Down
5 changes: 4 additions & 1 deletion js/packages/berty-i18n/locale/fr-FR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@
"tag-positive": ""
},
"mc": {
"activate-button": "Activer la connectivité multi-pair"
"activate-button": "Activer Apple Multipeer Connectivity"
},
"nearby": {
"activate-button": "Activer Android Nearby"
},
"services-auth": {
"title": "Services externes",
Expand Down
6 changes: 6 additions & 0 deletions js/packages/components/onboarding/SetupFinished.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ const SetupFinishedBody = () => {
enable: hasBluetoothPermission,
},
})
await setPersistentOption({
type: PersistentOptionsKeys.Nearby,
payload: {
enable: hasBluetoothPermission,
},
})
}

return () => {
Expand Down
22 changes: 21 additions & 1 deletion js/packages/components/settings/Bluetooth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const BodyBluetooth: React.FC<BluetoothProps> = ({ isBluetooth }) => {
const ctx = useMsgrContext()
const [bleEnabled, setBleEnabled] = useState(ctx.persistentOptions?.ble.enable)
const [mcEnabled, setMcEnabled] = useState(ctx.persistentOptions?.mc.enable)
const [nearbyEnabled, setNearbyEnabled] = useState(ctx.persistentOptions?.nearby.enable)

return (
<Translation>
Expand Down Expand Up @@ -241,7 +242,7 @@ const BodyBluetooth: React.FC<BluetoothProps> = ({ isBluetooth }) => {
iconColor={color.blue}
toggled
disabled={Platform.OS === 'android' || !isBluetooth ? true : false}
varToggle={mcEnabled}
varToggle={Platform.OS === 'ios' && mcEnabled}
actionToggle={async () => {
setMcEnabled(!ctx.persistentOptions?.mc.enable)
await ctx.setPersistentOption({
Expand All @@ -252,6 +253,25 @@ const BodyBluetooth: React.FC<BluetoothProps> = ({ isBluetooth }) => {
})
}}
/>

<ButtonSetting
name={t('settings.nearby.activate-button')}
icon='wifi-outline'
iconSize={30}
iconColor={color.blue}
toggled
disabled={Platform.OS === 'ios' || !isBluetooth ? true : false}
varToggle={Platform.OS === 'android' && nearbyEnabled}
actionToggle={async () => {
setNearbyEnabled(!ctx.persistentOptions?.nearby.enable)
await ctx.setPersistentOption({
type: PersistentOptionsKeys.Nearby,
payload: {
enable: !ctx.persistentOptions?.nearby.enable,
},
})
}}
/>
</View>
)}
</Translation>
Expand Down
13 changes: 13 additions & 0 deletions js/packages/store/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export enum PersistentOptionsKeys {
Suggestions = 'suggestions',
BLE = 'ble',
MC = 'mc',
Nearby = 'nearby',
Debug = 'debug',
Tor = 'tor',
Log = 'log',
Expand Down Expand Up @@ -172,6 +173,10 @@ export type PersistentOptionsMC = {
enable: boolean
}

export type PersistentOptionsNearby = {
enable: boolean
}

export type PersistentOptionsDebug = {
enable: boolean
}
Expand Down Expand Up @@ -223,6 +228,10 @@ export type PersistentOptionsUpdate =
type: typeof PersistentOptionsKeys.MC
payload: Partial<PersistentOptionsMC>
}
| {
type: typeof PersistentOptionsKeys.Nearby
payload: Partial<PersistentOptionsNearby>
}
| {
type: typeof PersistentOptionsKeys.Debug
payload: Partial<PersistentOptionsDebug>
Expand Down Expand Up @@ -254,6 +263,7 @@ export type PersistentOptions = {
[PersistentOptionsKeys.Suggestions]: PersistentOptionsSuggestions
[PersistentOptionsKeys.BLE]: PersistentOptionsBLE
[PersistentOptionsKeys.MC]: PersistentOptionsMC
[PersistentOptionsKeys.Nearby]: PersistentOptionsNearby
[PersistentOptionsKeys.Debug]: PersistentOptionsDebug
[PersistentOptionsKeys.Tor]: PersistentOptionsTor
[PersistentOptionsKeys.Log]: PersistentOptionsLog
Expand Down Expand Up @@ -292,6 +302,9 @@ export const defaultPersistentOptions = (): PersistentOptions => {
[PersistentOptionsKeys.MC]: {
enable: true,
},
[PersistentOptionsKeys.Nearby]: {
enable: true,
},
[PersistentOptionsKeys.Debug]: {
enable: false,
},
Expand Down

0 comments on commit a37d814

Please sign in to comment.