Skip to content

Commit

Permalink
✨ - Auto import favorite stations to service updates (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
planecore authored Apr 13, 2024
1 parent 4098faa commit cfcc13b
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 58 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ android {
applicationId "com.betterrail"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 81
versionCode 82
versionName "2.3.0"
missingDimensionStrategy "store", "play"
}
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@
"enableNotifications": "تفعيل الإشعارات",

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

"notificationNote": "يرجى الملاحظة: بينما سيبذل Better Rail قصارى جهده لتوفير تحديثات سريعة وموثوقة، يُنصح دائمًا بالتحقق من المصادر الرسمية لسكك حديد إسرائيل كذلك."
}
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@
"enableNotifications": "Enable Notifications",

"notificationSetupContent": "Better Rail will send you updates on events related to your selected stations",
"stations": "Stations",
"selectStations": "Select Stations",
"selectedStations": "Selected Stations",
"stationsFromFavorites": "From Favorite Routes",

"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."
}
Expand Down
4 changes: 3 additions & 1 deletion app/i18n/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,10 @@
"enableNotifications": "הפעלת התראות",

"notificationSetupContent": "בטר רייל תשלח התראות רלוונטיות לתחנות המועדפות עליכם",
"stations": "תחנות",
"selectStations": "בחירת תחנות",
"selectedStations": "תחנות",
"selectedStations": "תחנות נוספות",
"stationsFromFavorites": "תחנות ממסלולים מועדפים",

"notificationNote": "בטר רייל תעשה כמיטב יכולתה לספק עדכונים מהירים ואמינים, אך תמיד מומלץ לבדוק גם עם המקורות הרשמיים של רכבת ישראל."
}
Expand Down
2 changes: 2 additions & 0 deletions app/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@
"enableNotifications": "Включить уведомления",

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

"notificationNote": "Обратите внимание: хотя Better Rail и будет стараться предоставлять быстрые и надежные обновления, всегда рекомендуется проверять информацию у официальных источников Израильских железных дорог."
}
Expand Down
111 changes: 73 additions & 38 deletions app/screens/notifications/notifications-setup-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { useStations } from "../../data/stations"
import analytics from "@react-native-firebase/analytics"
import messaging from "@react-native-firebase/messaging"
import { useAppState } from "../../hooks"
import { chain } from "lodash"

export const NotificationsSetupScreen = observer(function NotificationsSetupScreen({ navigation }: AnnouncementsScreenProps) {
const { settings } = useStores()
const { settings, favoriteRoutes } = useStores()
const stations = useStations()
const appState = useAppState()
const [notificationPermission, setNotificationPermission] = useState(false)
Expand Down Expand Up @@ -67,50 +68,84 @@ export const NotificationsSetupScreen = observer(function NotificationsSetupScre
}
}, [notificationPermission])

const favoriteStations = chain(favoriteRoutes.routes)
.flatMap((route) => [route.originId, route.destinationId])
.uniq()
.filter((station) => !settings.stationsNotifications.includes(station))
.value()

return (
<Screen style={{ paddingHorizontal: spacing[4], flex: 1, paddingBottom: spacing[5] }} unsafe>
<Screen style={{ paddingHorizontal: spacing[4], flex: 1 }} unsafe>
<ScrollView showsVerticalScrollIndicator={false}>
<View style={{ marginVertical: spacing[2], gap: spacing[2] }}>
<Text style={{ textAlign: "center", fontSize: 56 }}>🔔</Text>
<Text
tx="announcements.notifications.notificationSetupContent"
style={{ textAlign: "center", paddingHorizontal: spacing[3], marginBottom: spacing[2] }}
/>
</View>

{notificationPermission ? (
<View style={{ flex: 1, gap: 12 }}>
<Button
title={translate("announcements.notifications.selectStations")}
onPress={() => navigation.navigate("notificationsPickStations")}
<View style={{ paddingBottom: spacing[6] }}>
<View style={{ marginVertical: spacing[2], gap: spacing[2] }}>
<Text style={{ textAlign: "center", fontSize: 56 }}>🔔</Text>
<Text
tx="announcements.notifications.notificationSetupContent"
style={{ textAlign: "center", paddingHorizontal: spacing[3], marginBottom: spacing[2] }}
/>
</View>

{settings.stationsNotifications.length > 0 && (
<View
style={{ borderBottomWidth: 1, borderColor: Platform.select({ ios: color.separator, android: "lightgrey" }) }}
>
<Text tx="announcements.notifications.selectedStations" style={{ fontWeight: "500" }} />
</View>
)}
{notificationPermission ? (
<View style={{ flex: 1, gap: 12 }}>
{favoriteStations.length > 0 && (
<View
style={{ borderBottomWidth: 1, borderColor: Platform.select({ ios: color.separator, android: "lightgrey" }) }}
>
<Text tx="announcements.notifications.stationsFromFavorites" style={{ fontWeight: "500" }} />
</View>
)}

{settings.stationsNotifications.map((stationId) => {
const station = stations.find((s) => s.id === stationId)
return <StationListItem key={stationId} title={station.name} image={station.image} />
})}
{favoriteStations.map((stationId) => {
const station = stations.find((s) => s.id === stationId)
return <StationListItem key={stationId} title={station.name} image={station.image} />
})}

<Text
tx="announcements.notifications.notificationNote"
style={{ textAlign: "center", opacity: 0.8 }}
preset="small"
/>
</View>
) : (
<View style={{ gap: 16 }}>
<Text tx="announcements.notifications.requestPermissionContent" style={{ textAlign: "center" }} />
{settings.stationsNotifications.length > 0 && (
<View
style={{
flex: 1,
flexDirection: "row",
borderBottomWidth: 1,
justifyContent: "space-between",
borderColor: Platform.select({ ios: color.separator, android: "lightgrey" }),
}}
>
<Text
tx={
favoriteStations.length > 0
? "announcements.notifications.selectedStations"
: "announcements.notifications.stations"
}
style={{ fontWeight: "500" }}
/>
</View>
)}

<Button title={translate("announcements.notifications.enableNotifications")} onPress={requestPermission} />
</View>
)}
{settings.stationsNotifications.map((stationId) => {
const station = stations.find((s) => s.id === stationId)
return <StationListItem key={stationId} title={station.name} image={station.image} />
})}

<Button
title={translate("announcements.notifications.selectStations")}
onPress={() => navigation.navigate("notificationsPickStations")}
/>

<Text
tx="announcements.notifications.notificationNote"
style={{ textAlign: "center", opacity: 0.8 }}
preset="small"
/>
</View>
) : (
<View style={{ gap: 16 }}>
<Text tx="announcements.notifications.requestPermissionContent" style={{ textAlign: "center" }} />

<Button title={translate("announcements.notifications.enableNotifications")} onPress={requestPermission} />
</View>
)}
</View>
</ScrollView>
</Screen>
)
Expand Down
6 changes: 4 additions & 2 deletions app/utils/notification-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@ const handleServiceUpdateNotification = async (message: FirebaseMessagingTypes.R
const rootStoreString = await AsyncStorage.getItem("root")
const rootStore = JSON.parse(rootStoreString)

const stationsNotifications = rootStore.settings.stationsNotifications
const stationsNotifications: string[] = rootStore.settings.stationsNotifications
const favoriteRoutes: string[] = rootStore.favoriteRoutes.routes.flatMap((route) => [route.originId, route.destinationId])
const stationsToCheck = [...stationsNotifications, ...favoriteRoutes]

parsedStations.find((station) => {
if (stationsNotifications.includes(station)) {
if (stationsToCheck.includes(station)) {
displayNotification = true
return true
}
Expand Down
2 changes: 1 addition & 1 deletion ios/BetterRail/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>16</string>
<string>17</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationQueriesSchemes</key>
Expand Down
2 changes: 1 addition & 1 deletion ios/BetterRailWidget/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>16</string>
<string>17</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>NSExtension</key>
Expand Down
2 changes: 1 addition & 1 deletion ios/BetterRailWidget/WatchInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>16</string>
<string>17</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
Expand Down
12 changes: 0 additions & 12 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -816,12 +816,6 @@ PODS:
- Libuv-gRPC/Implementation (0.0.10):
- Libuv-gRPC/Interface (= 0.0.10)
- Libuv-gRPC/Interface (0.0.10)
- Mixpanel-swift (4.2.0):
- Mixpanel-swift/Complete (= 4.2.0)
- Mixpanel-swift/Complete (4.2.0)
- MixpanelReactNative (3.0.0-beta.2):
- Mixpanel-swift (= 4.2.0)
- React-Core
- nanopb (2.30909.0):
- nanopb/decode (= 2.30909.0)
- nanopb/encode (= 2.30909.0)
Expand Down Expand Up @@ -1309,7 +1303,6 @@ DEPENDENCIES:
- GoogleUtilities
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
- libevent (~> 2.1.12)
- MixpanelReactNative (from `../node_modules/mixpanel-react-native`)
- nanopb
- RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
- RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`)
Expand Down Expand Up @@ -1401,7 +1394,6 @@ SPEC REPOS:
- leveldb-library
- libevent
- Libuv-gRPC
- Mixpanel-swift
- nanopb
- PromisesObjC
- PromisesSwift
Expand Down Expand Up @@ -1431,8 +1423,6 @@ EXTERNAL SOURCES:
:podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec"
hermes-engine:
:podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
MixpanelReactNative:
:path: "../node_modules/mixpanel-react-native"
RCT-Folly:
:podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec"
RCTRequired:
Expand Down Expand Up @@ -1595,8 +1585,6 @@ SPEC CHECKSUMS:
leveldb-library: f03246171cce0484482ec291f88b6d563699ee06
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
Libuv-gRPC: 55e51798e14ef436ad9bc45d12d43b77b49df378
Mixpanel-swift: e5dd85295923e6a875acf17ccbab8d2ecb10ea65
MixpanelReactNative: 07c91e9adc7a2c722398108c10409d9ea789dc39
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef
PromisesSwift: cf9eb58666a43bbe007302226e510b16c1e10959
Expand Down
2 changes: 1 addition & 1 deletion ios/StationIntent/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>16</string>
<string>17</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
Expand Down

0 comments on commit cfcc13b

Please sign in to comment.