Skip to content

Commit 76b1538

Browse files
committed
Implement wifi no-download alert
1 parent 645bfc4 commit 76b1538

File tree

10 files changed

+129
-77
lines changed

10 files changed

+129
-77
lines changed

android/app/src/main/java/org/languagetransfer/MainApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import androidx.multidex.MultiDexApplication;
66
import com.facebook.react.PackageList;
77
import com.facebook.react.ReactApplication;
8+
import com.reactnativecommunity.netinfo.NetInfoPackage;
9+
import com.reactnativecommunity.netinfo.NetInfoPackage;
810
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
911
import com.facebook.react.ReactInstanceManager;
1012
import com.facebook.react.ReactNativeHost;

android/settings.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
rootProject.name = 'LanguageTransfer'
2+
include ':@react-native-community_netinfo'
3+
project(':@react-native-community_netinfo').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/netinfo/android')
4+
include ':@react-native-community_netinfo'
5+
project(':@react-native-community_netinfo').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/netinfo/android')
26
include ':react-native-gesture-handler'
37
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
48
include ':react-native-navigation-bar-color'

ios/LanguageTransfer.xcodeproj/project.pbxproj

Lines changed: 74 additions & 74 deletions
Large diffs are not rendered by default.

ios/Podfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ target 'LanguageTransfer' do
88

99
pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler'
1010

11+
pod 'react-native-netinfo', :path => '../node_modules/@react-native-community/netinfo'
12+
1113
target 'LanguageTransferTests' do
1214
inherit! :complete
1315
# Pods for testing

ios/Podfile.lock

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ PODS:
288288
- React-Core
289289
- react-native-get-random-values (1.8.0):
290290
- React-Core
291+
- react-native-netinfo (8.3.0):
292+
- React-Core
291293
- react-native-safe-area-context (3.4.1):
292294
- React-Core
293295
- react-native-track-player (2.1.3):
@@ -428,6 +430,7 @@ DEPENDENCIES:
428430
- react-native-background-downloader (from `../node_modules/react-native-background-downloader`)
429431
- react-native-background-timer (from `../node_modules/react-native-background-timer`)
430432
- react-native-get-random-values (from `../node_modules/react-native-get-random-values`)
433+
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
431434
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
432435
- react-native-track-player (from `../node_modules/react-native-track-player`)
433436
- react-native-webview (from `../node_modules/react-native-webview`)
@@ -515,6 +518,8 @@ EXTERNAL SOURCES:
515518
:path: "../node_modules/react-native-background-timer"
516519
react-native-get-random-values:
517520
:path: "../node_modules/react-native-get-random-values"
521+
react-native-netinfo:
522+
:path: "../node_modules/@react-native-community/netinfo"
518523
react-native-safe-area-context:
519524
:path: "../node_modules/react-native-safe-area-context"
520525
react-native-track-player:
@@ -599,6 +604,7 @@ SPEC CHECKSUMS:
599604
react-native-background-downloader: 4a034cf39a3b00fac57364984e360a4f180a5efb
600605
react-native-background-timer: 17ea5e06803401a379ebf1f20505b793ac44d0fe
601606
react-native-get-random-values: a6ea6a8a65dc93e96e24a11105b1a9c8cfe1d72a
607+
react-native-netinfo: 3671b091c4843fda5e153612866ef4024b8f5d62
602608
react-native-safe-area-context: 9e40fb181dac02619414ba1294d6c2a807056ab9
603609
react-native-track-player: c4147afddd29de936caa06561f78a32d6502eb12
604610
react-native-webview: 8ec7ddf9eb4ddcd92b32cee7907efec19a9ec7cb
@@ -627,6 +633,6 @@ SPEC CHECKSUMS:
627633
Yoga: 99652481fcd320aefa4a7ef90095b95acd181952
628634
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
629635

630-
PODFILE CHECKSUM: bfa19de3e345f445377fed12260434b0ce04f43d
636+
PODFILE CHECKSUM: dc120fbf419dbc6f06e12a63498f07affa535eb5
631637

632638
COCOAPODS: 1.11.3

js/components/AllLessons/AllLessons.react.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import CourseData from '../../course-data';
1515
import DownloadManager from '../../download-manager';
1616
import prettyBytes from 'pretty-bytes';
1717
import {usePreference} from '../../persistence';
18+
import genConditionallyShowErrorOnNoWifi from '../../download-on-wifi-error';
19+
1820
import {Icon} from 'react-native-elements';
1921

2022
import {throttle} from 'lodash';
@@ -64,7 +66,9 @@ const AllLessons = ({route}: {route: any}) => {
6466
},
6567
{
6668
text: 'OK',
67-
onPress: () => {
69+
onPress: async() => {
70+
await genConditionallyShowErrorOnNoWifi();
71+
6872
indices
6973
.filter((lesson) => !downloadedMask[lesson])
7074
.forEach((lesson) => DownloadManager.startDownload(course, lesson));

js/components/AllLessons/LessonRow.react.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {useState, useEffect} from 'react';
2-
import {View, Text, StyleSheet, TouchableNativeFeedback} from 'react-native';
2+
import {Alert, View, Text, StyleSheet, TouchableNativeFeedback} from 'react-native';
33
import ProgressCircle from 'react-native-progress-circle';
44

55
import {Icon} from 'react-native-elements';
@@ -12,6 +12,7 @@ import {usePreference} from '../../persistence';
1212
import {log} from '../../metrics';
1313
import { useNavigation } from '@react-navigation/core';
1414
import { MainNavigationProp } from '../App.react';
15+
import genConditionallyShowErrorOnNoWifi from '../../download-on-wifi-error';
1516

1617
export const LESSON_ROW_HEIGHT = 72;
1718

@@ -98,6 +99,8 @@ const handleDownloadClick = async (
9899
});
99100
DownloadManager.stopDownload(DownloadManager.getDownloadId(course, lesson));
100101
} else if (!downloaded) {
102+
await genConditionallyShowErrorOnNoWifi();
103+
101104
log({
102105
action: 'download_lesson',
103106
surface: 'all_lessons',

js/download-on-wifi-error.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import NetInfo from '@react-native-community/netinfo';
2+
import {genPreferenceDownloadOnlyOnWifi} from './persistence';
3+
import { Alert } from 'react-native';
4+
5+
export default async function downloadOnWifiError(){
6+
const [wifiOnly, network] = await Promise.all([
7+
genPreferenceDownloadOnlyOnWifi(),
8+
NetInfo.fetch(),
9+
]);
10+
11+
if (wifiOnly && network.type !== 'wifi') {
12+
Alert.alert(`Waiting for wi-fi to start download.\n
13+
To download now, uncheck Settings > Download only on wi-fi.`);
14+
}
15+
}

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"dependencies": {
1414
"@react-native-async-storage/async-storage": "^1.14.1",
1515
"@react-native-community/masked-view": "^0.1.10",
16+
"@react-native-community/netinfo": "^8.3.0",
1617
"@react-navigation/drawer": "^5.8.5",
1718
"@react-navigation/native": "^5.7.0",
1819
"@react-navigation/stack": "^5.7.0",

0 commit comments

Comments
 (0)