Skip to content

Commit cfcc13b

Browse files
authored
✨ - Auto import favorite stations to service updates (#364)
1 parent 4098faa commit cfcc13b

File tree

12 files changed

+91
-58
lines changed

12 files changed

+91
-58
lines changed

android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ android {
120120
applicationId "com.betterrail"
121121
minSdkVersion rootProject.ext.minSdkVersion
122122
targetSdkVersion rootProject.ext.targetSdkVersion
123-
versionCode 81
123+
versionCode 82
124124
versionName "2.3.0"
125125
missingDimensionStrategy "store", "play"
126126
}

app/i18n/ar.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@
176176
"enableNotifications": "تفعيل الإشعارات",
177177

178178
"notificationSetupContent": "سوف يرسل لك Better Rail تحديثات حول الأحداث المتعلقة بالمحطات التي اخترتها",
179+
"stations": "محطات",
179180
"selectStations": "اختر المحطات",
180181
"selectedStations": "المحطات المختارة",
182+
"stationsFromFavorites": "من الطرق المفضلة",
181183

182184
"notificationNote": "يرجى الملاحظة: بينما سيبذل Better Rail قصارى جهده لتوفير تحديثات سريعة وموثوقة، يُنصح دائمًا بالتحقق من المصادر الرسمية لسكك حديد إسرائيل كذلك."
183185
}

app/i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,10 @@
268268
"enableNotifications": "Enable Notifications",
269269

270270
"notificationSetupContent": "Better Rail will send you updates on events related to your selected stations",
271+
"stations": "Stations",
271272
"selectStations": "Select Stations",
272273
"selectedStations": "Selected Stations",
274+
"stationsFromFavorites": "From Favorite Routes",
273275

274276
"notificationNote": "Please note: While Better Rail will do its best to provide fast and reliable updates, it is always advisable to check with the official sources of Israel Railways as well."
275277
}

app/i18n/he.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,10 @@
272272
"enableNotifications": "הפעלת התראות",
273273

274274
"notificationSetupContent": "בטר רייל תשלח התראות רלוונטיות לתחנות המועדפות עליכם",
275+
"stations": "תחנות",
275276
"selectStations": "בחירת תחנות",
276-
"selectedStations": "תחנות",
277+
"selectedStations": "תחנות נוספות",
278+
"stationsFromFavorites": "תחנות ממסלולים מועדפים",
277279

278280
"notificationNote": "בטר רייל תעשה כמיטב יכולתה לספק עדכונים מהירים ואמינים, אך תמיד מומלץ לבדוק גם עם המקורות הרשמיים של רכבת ישראל."
279281
}

app/i18n/ru.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,10 @@
179179
"enableNotifications": "Включить уведомления",
180180

181181
"notificationSetupContent": "Better Rail будет отправлять вам обновления о событиях, связанных с выбранными вами станциями",
182+
"stations": "Станции",
182183
"selectStations": "Выбрать станции",
183184
"selectedStations": "Выбранные станции",
185+
"stationsFromFavorites": "Из любимых маршрутов",
184186

185187
"notificationNote": "Обратите внимание: хотя Better Rail и будет стараться предоставлять быстрые и надежные обновления, всегда рекомендуется проверять информацию у официальных источников Израильских железных дорог."
186188
}

app/screens/notifications/notifications-setup-screen.tsx

Lines changed: 73 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import { useStations } from "../../data/stations"
1212
import analytics from "@react-native-firebase/analytics"
1313
import messaging from "@react-native-firebase/messaging"
1414
import { useAppState } from "../../hooks"
15+
import { chain } from "lodash"
1516

1617
export const NotificationsSetupScreen = observer(function NotificationsSetupScreen({ navigation }: AnnouncementsScreenProps) {
17-
const { settings } = useStores()
18+
const { settings, favoriteRoutes } = useStores()
1819
const stations = useStations()
1920
const appState = useAppState()
2021
const [notificationPermission, setNotificationPermission] = useState(false)
@@ -67,50 +68,84 @@ export const NotificationsSetupScreen = observer(function NotificationsSetupScre
6768
}
6869
}, [notificationPermission])
6970

71+
const favoriteStations = chain(favoriteRoutes.routes)
72+
.flatMap((route) => [route.originId, route.destinationId])
73+
.uniq()
74+
.filter((station) => !settings.stationsNotifications.includes(station))
75+
.value()
76+
7077
return (
71-
<Screen style={{ paddingHorizontal: spacing[4], flex: 1, paddingBottom: spacing[5] }} unsafe>
78+
<Screen style={{ paddingHorizontal: spacing[4], flex: 1 }} unsafe>
7279
<ScrollView showsVerticalScrollIndicator={false}>
73-
<View style={{ marginVertical: spacing[2], gap: spacing[2] }}>
74-
<Text style={{ textAlign: "center", fontSize: 56 }}>🔔</Text>
75-
<Text
76-
tx="announcements.notifications.notificationSetupContent"
77-
style={{ textAlign: "center", paddingHorizontal: spacing[3], marginBottom: spacing[2] }}
78-
/>
79-
</View>
80-
81-
{notificationPermission ? (
82-
<View style={{ flex: 1, gap: 12 }}>
83-
<Button
84-
title={translate("announcements.notifications.selectStations")}
85-
onPress={() => navigation.navigate("notificationsPickStations")}
80+
<View style={{ paddingBottom: spacing[6] }}>
81+
<View style={{ marginVertical: spacing[2], gap: spacing[2] }}>
82+
<Text style={{ textAlign: "center", fontSize: 56 }}>🔔</Text>
83+
<Text
84+
tx="announcements.notifications.notificationSetupContent"
85+
style={{ textAlign: "center", paddingHorizontal: spacing[3], marginBottom: spacing[2] }}
8686
/>
87+
</View>
8788

88-
{settings.stationsNotifications.length > 0 && (
89-
<View
90-
style={{ borderBottomWidth: 1, borderColor: Platform.select({ ios: color.separator, android: "lightgrey" }) }}
91-
>
92-
<Text tx="announcements.notifications.selectedStations" style={{ fontWeight: "500" }} />
93-
</View>
94-
)}
89+
{notificationPermission ? (
90+
<View style={{ flex: 1, gap: 12 }}>
91+
{favoriteStations.length > 0 && (
92+
<View
93+
style={{ borderBottomWidth: 1, borderColor: Platform.select({ ios: color.separator, android: "lightgrey" }) }}
94+
>
95+
<Text tx="announcements.notifications.stationsFromFavorites" style={{ fontWeight: "500" }} />
96+
</View>
97+
)}
9598

96-
{settings.stationsNotifications.map((stationId) => {
97-
const station = stations.find((s) => s.id === stationId)
98-
return <StationListItem key={stationId} title={station.name} image={station.image} />
99-
})}
99+
{favoriteStations.map((stationId) => {
100+
const station = stations.find((s) => s.id === stationId)
101+
return <StationListItem key={stationId} title={station.name} image={station.image} />
102+
})}
100103

101-
<Text
102-
tx="announcements.notifications.notificationNote"
103-
style={{ textAlign: "center", opacity: 0.8 }}
104-
preset="small"
105-
/>
106-
</View>
107-
) : (
108-
<View style={{ gap: 16 }}>
109-
<Text tx="announcements.notifications.requestPermissionContent" style={{ textAlign: "center" }} />
104+
{settings.stationsNotifications.length > 0 && (
105+
<View
106+
style={{
107+
flex: 1,
108+
flexDirection: "row",
109+
borderBottomWidth: 1,
110+
justifyContent: "space-between",
111+
borderColor: Platform.select({ ios: color.separator, android: "lightgrey" }),
112+
}}
113+
>
114+
<Text
115+
tx={
116+
favoriteStations.length > 0
117+
? "announcements.notifications.selectedStations"
118+
: "announcements.notifications.stations"
119+
}
120+
style={{ fontWeight: "500" }}
121+
/>
122+
</View>
123+
)}
110124

111-
<Button title={translate("announcements.notifications.enableNotifications")} onPress={requestPermission} />
112-
</View>
113-
)}
125+
{settings.stationsNotifications.map((stationId) => {
126+
const station = stations.find((s) => s.id === stationId)
127+
return <StationListItem key={stationId} title={station.name} image={station.image} />
128+
})}
129+
130+
<Button
131+
title={translate("announcements.notifications.selectStations")}
132+
onPress={() => navigation.navigate("notificationsPickStations")}
133+
/>
134+
135+
<Text
136+
tx="announcements.notifications.notificationNote"
137+
style={{ textAlign: "center", opacity: 0.8 }}
138+
preset="small"
139+
/>
140+
</View>
141+
) : (
142+
<View style={{ gap: 16 }}>
143+
<Text tx="announcements.notifications.requestPermissionContent" style={{ textAlign: "center" }} />
144+
145+
<Button title={translate("announcements.notifications.enableNotifications")} onPress={requestPermission} />
146+
</View>
147+
)}
148+
</View>
114149
</ScrollView>
115150
</Screen>
116151
)

app/utils/notification-helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,12 @@ const handleServiceUpdateNotification = async (message: FirebaseMessagingTypes.R
131131
const rootStoreString = await AsyncStorage.getItem("root")
132132
const rootStore = JSON.parse(rootStoreString)
133133

134-
const stationsNotifications = rootStore.settings.stationsNotifications
134+
const stationsNotifications: string[] = rootStore.settings.stationsNotifications
135+
const favoriteRoutes: string[] = rootStore.favoriteRoutes.routes.flatMap((route) => [route.originId, route.destinationId])
136+
const stationsToCheck = [...stationsNotifications, ...favoriteRoutes]
135137

136138
parsedStations.find((station) => {
137-
if (stationsNotifications.includes(station)) {
139+
if (stationsToCheck.includes(station)) {
138140
displayNotification = true
139141
return true
140142
}

ios/BetterRail/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<key>CFBundleSignature</key>
2424
<string>????</string>
2525
<key>CFBundleVersion</key>
26-
<string>16</string>
26+
<string>17</string>
2727
<key>ITSAppUsesNonExemptEncryption</key>
2828
<false/>
2929
<key>LSApplicationQueriesSchemes</key>

ios/BetterRailWidget/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>$(MARKETING_VERSION)</string>
2121
<key>CFBundleVersion</key>
22-
<string>16</string>
22+
<string>17</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string></string>
2525
<key>NSExtension</key>

ios/BetterRailWidget/WatchInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>$(MARKETING_VERSION)</string>
2121
<key>CFBundleVersion</key>
22-
<string>16</string>
22+
<string>17</string>
2323
<key>NSExtension</key>
2424
<dict>
2525
<key>NSExtensionPointIdentifier</key>

ios/Podfile.lock

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,6 @@ PODS:
816816
- Libuv-gRPC/Implementation (0.0.10):
817817
- Libuv-gRPC/Interface (= 0.0.10)
818818
- Libuv-gRPC/Interface (0.0.10)
819-
- Mixpanel-swift (4.2.0):
820-
- Mixpanel-swift/Complete (= 4.2.0)
821-
- Mixpanel-swift/Complete (4.2.0)
822-
- MixpanelReactNative (3.0.0-beta.2):
823-
- Mixpanel-swift (= 4.2.0)
824-
- React-Core
825819
- nanopb (2.30909.0):
826820
- nanopb/decode (= 2.30909.0)
827821
- nanopb/encode (= 2.30909.0)
@@ -1309,7 +1303,6 @@ DEPENDENCIES:
13091303
- GoogleUtilities
13101304
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
13111305
- libevent (~> 2.1.12)
1312-
- MixpanelReactNative (from `../node_modules/mixpanel-react-native`)
13131306
- nanopb
13141307
- RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
13151308
- RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`)
@@ -1401,7 +1394,6 @@ SPEC REPOS:
14011394
- leveldb-library
14021395
- libevent
14031396
- Libuv-gRPC
1404-
- Mixpanel-swift
14051397
- nanopb
14061398
- PromisesObjC
14071399
- PromisesSwift
@@ -1431,8 +1423,6 @@ EXTERNAL SOURCES:
14311423
:podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec"
14321424
hermes-engine:
14331425
:podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
1434-
MixpanelReactNative:
1435-
:path: "../node_modules/mixpanel-react-native"
14361426
RCT-Folly:
14371427
:podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec"
14381428
RCTRequired:
@@ -1595,8 +1585,6 @@ SPEC CHECKSUMS:
15951585
leveldb-library: f03246171cce0484482ec291f88b6d563699ee06
15961586
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
15971587
Libuv-gRPC: 55e51798e14ef436ad9bc45d12d43b77b49df378
1598-
Mixpanel-swift: e5dd85295923e6a875acf17ccbab8d2ecb10ea65
1599-
MixpanelReactNative: 07c91e9adc7a2c722398108c10409d9ea789dc39
16001588
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
16011589
PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef
16021590
PromisesSwift: cf9eb58666a43bbe007302226e510b16c1e10959

ios/StationIntent/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>$(MARKETING_VERSION)</string>
2121
<key>CFBundleVersion</key>
22-
<string>16</string>
22+
<string>17</string>
2323
<key>NSExtension</key>
2424
<dict>
2525
<key>NSExtensionAttributes</key>

0 commit comments

Comments
 (0)