diff --git a/android/app/google-services.json b/android/app/google-services.json index b29eab8..c1b6f32 100644 --- a/android/app/google-services.json +++ b/android/app/google-services.json @@ -1,13 +1,13 @@ { "project_info": { - "project_number": "473250290916", - "project_id": "smartstop-7a69d", - "storage_bucket": "smartstop-7a69d.appspot.com" + "project_number": "649637283755", + "project_id": "smartstop-e9b90", + "storage_bucket": "smartstop-e9b90.appspot.com" }, "client": [ { "client_info": { - "mobilesdk_app_id": "1:473250290916:android:6153a7d8264a90b963e0f1", + "mobilesdk_app_id": "1:649637283755:android:02f9b01c4acf051ca174ee", "android_client_info": { "package_name": "com.smartstop" } @@ -15,7 +15,7 @@ "oauth_client": [], "api_key": [ { - "current_key": "AIzaSyAI7Q2y3XOAO8qQfnOZAOfFGqzS4pjbD7k" + "current_key": "AIzaSyCvcskItwpjqoA2wiNv4xwHhNoYsinfU2s" } ], "services": { diff --git a/android/app/google-services.json.olx b/android/app/google-services.json.olx new file mode 100644 index 0000000..b29eab8 --- /dev/null +++ b/android/app/google-services.json.olx @@ -0,0 +1,29 @@ +{ + "project_info": { + "project_number": "473250290916", + "project_id": "smartstop-7a69d", + "storage_bucket": "smartstop-7a69d.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:473250290916:android:6153a7d8264a90b963e0f1", + "android_client_info": { + "package_name": "com.smartstop" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyAI7Q2y3XOAO8qQfnOZAOfFGqzS4pjbD7k" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png index a2f5908..9fbe371 100644 Binary files a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png index 1b52399..9fbe371 100644 Binary files a/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png index ff10afd..49787e6 100644 Binary files a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png index 115a4c7..49787e6 100644 Binary files a/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png index dcd3cd8..fc1ec52 100644 Binary files a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png index 459ca60..fc1ec52 100644 Binary files a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png index 8ca12fe..d3e9673 100644 Binary files a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png index 8e19b41..d3e9673 100644 Binary files a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png index b824ebd..c6a9ab7 100644 Binary files a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png index 4c19a13..c6a9ab7 100644 Binary files a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/package.json b/package.json index a21bdf2..7cb9d93 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "moment": "^2.29.4", "react": "18.2.0", "react-native": "0.72.6", - "react-native-device-info": "^10.11.0", + "react-native-device-info": "^10.13.1", "react-native-vector-icons": "^10.0.2" }, "devDependencies": { diff --git a/src/domain/services/BusStopInfoService.ts b/src/domain/services/BusStopInfoService.ts index 17f0f6e..6688294 100644 --- a/src/domain/services/BusStopInfoService.ts +++ b/src/domain/services/BusStopInfoService.ts @@ -12,8 +12,11 @@ class BusStopInfoService { getLines(): LineDetail[] { return this.lines; + } + + getLinesByNumber(lineNumber: string): LineDetail { const line = this.lines.find(bus => bus.lineNumber === lineNumber); @@ -40,9 +43,9 @@ class BusStopInfoService { compareTime.set('minute', getMinutes(arrival.estimatedGPS)); compareTime.set('second', getSeconds(arrival.estimatedGPS)); - if (compareTime.isAfter(currentTime)) { + //if (compareTime.isAfter(currentTime)) { return arrival; - } + // } }, ); diff --git a/src/infraestructure/api/clients/AuthAPI.ts b/src/infraestructure/api/clients/AuthAPI.ts index 3c7310b..365a4e0 100644 --- a/src/infraestructure/api/clients/AuthAPI.ts +++ b/src/infraestructure/api/clients/AuthAPI.ts @@ -10,7 +10,7 @@ class AuthAPI { this.baseURL = baseURL; } - async auth({username, password}: AuthRequest): Promise { + async auth({username, password,rut}: AuthRequest): Promise { if (!username) { throw new Error('username is required'); } @@ -18,12 +18,15 @@ class AuthAPI { if (!password) { throw new Error('password is required'); } - + if (!rut) { + throw new Error('rut is required'); + } const {data} = await axios.post( `${this.baseURL}${LOGIN_METHOD}`, { username, password, + rut, }, ); diff --git a/src/infraestructure/api/clients/__tests__/AuthAPI.spec.ts b/src/infraestructure/api/clients/__tests__/AuthAPI.spec.ts index 48c76b4..5cb1059 100644 --- a/src/infraestructure/api/clients/__tests__/AuthAPI.spec.ts +++ b/src/infraestructure/api/clients/__tests__/AuthAPI.spec.ts @@ -21,6 +21,7 @@ describe('AuthAPI tests', () => { const token = await authAPI.auth({ username: 'username', password: 'password', + rut:'rut', }); expect(token).toMatchObject({token: 'token'}); @@ -31,6 +32,7 @@ describe('AuthAPI tests', () => { authAPI.auth({ password: 'password', username: '', + rut:'rut', }), ).rejects.toThrow('username is required'); }); @@ -40,6 +42,7 @@ describe('AuthAPI tests', () => { authAPI.auth({ username: 'username', password: '', + rut:'rut', }), ).rejects.toThrow('password is required'); }); @@ -53,6 +56,7 @@ describe('AuthAPI tests', () => { authAPI.auth({ username: 'username', password: 'password', + rut:'rut', }), ).rejects.toThrow('Request failed with status code 400'); }); diff --git a/src/infraestructure/api/models/AuthRequest.ts b/src/infraestructure/api/models/AuthRequest.ts index 7b02f71..2b8d36f 100644 --- a/src/infraestructure/api/models/AuthRequest.ts +++ b/src/infraestructure/api/models/AuthRequest.ts @@ -1,6 +1,7 @@ interface AuthRequest { username: string; password: string; + rut:string; } export default AuthRequest; diff --git a/src/infraestructure/hooks/useDevices.ts b/src/infraestructure/hooks/useDevices.ts index 57e19f0..dea0a98 100644 --- a/src/infraestructure/hooks/useDevices.ts +++ b/src/infraestructure/hooks/useDevices.ts @@ -11,6 +11,7 @@ import RemoteConfigKeys from '../../utils/RemoteConfigKeys'; import {Line} from '../../presentation/components/Table'; import Status from '../../utils/Status'; import {BUSES_BY_PAGE} from '../../domain/const'; +//import DeviceInfo from 'react-native-device-info'; export interface State { status: Status; @@ -20,8 +21,8 @@ export interface State { stopMessage: string; stopName: string; } - -const DEVICE_ID = 'TTM543870hyt'; +//const deviceId = DeviceInfo.getUniqueId(); +const DEVICE_ID ='TTM543870hyt';// String(deviceId); const useDevices = () => { const [state, setState] = useState({ @@ -35,10 +36,12 @@ const useDevices = () => { const baseURL = remoteConfig().getString(RemoteConfigKeys.BASE_URL); const username = remoteConfig().getString(RemoteConfigKeys.USER); - const password = remoteConfig().getString(RemoteConfigKeys.PASS); + const password = remoteConfig().getString(RemoteConfigKeys.PASSWORD); + const rut = remoteConfig().getString(RemoteConfigKeys.RUT); const changePageInterval = remoteConfig().getNumber( RemoteConfigKeys.CHANGE_PAGE_INTERVAL, ); + const updateBusesListInterval = remoteConfig().getNumber( RemoteConfigKeys.UPDATE_BUSES_LIST_INTERVAL, ); @@ -49,6 +52,7 @@ const useDevices = () => { () => new DevicesRepositoryImpl(deviceApi), [deviceApi], ); + const authRepository = useMemo( () => new AuthRepositoryImpl(authApi), [authApi], @@ -56,18 +60,20 @@ const useDevices = () => { const setDisplayedLines = useCallback( (lineDetails: LineDetail[], stopMessage: string, stopName: string) => { + if (!lineDetails || !stopName) { return; } try { let busStopInfoService = new BusStopInfoService(lineDetails); - + const linesWithArrivals = lineDetails .map(line => { try { - busStopInfoService.getNextArraival(line.lineNumber); - + if (line.arrivals && line.arrivals.length > 0) { + busStopInfoService.getNextArraival(line.lineNumber); + } return line; } catch (error) { return undefined; @@ -75,19 +81,29 @@ const useDevices = () => { }) .filter((line): line is LineDetail => line !== undefined); - busStopInfoService = new BusStopInfoService(linesWithArrivals); + + busStopInfoService = new BusStopInfoService(linesWithArrivals); + + var estimatedArrivalTimeInMinutes=""; const linesToDisplay: Line[] = busStopInfoService .pruneBusList(state.currentIndex, BUSES_BY_PAGE) .map(line => { try { - const nextArraival = busStopInfoService.getNextArraival( - line.lineNumber, - ); + - const estimatedArrivalTimeInMinutes = - busStopInfoService.checkArraivalTime(nextArraival); + if (line.arrivals && line.arrivals.length > 0) + { + const nextArraival = busStopInfoService.getNextArraival( + line.lineNumber, + ); + estimatedArrivalTimeInMinutes =busStopInfoService.checkArraivalTime(nextArraival); + } + else + { + estimatedArrivalTimeInMinutes = "Sin información"; + } const lineLetter = busStopInfoService.getLineLetterFromDescription( line.description, @@ -104,7 +120,7 @@ const useDevices = () => { return { backgroundColor: line.backgroundColor, - estimatedArrivalTimeInMinutes, + estimatedArrivalTimeInMinutes, letterColor: line.letterColor, lineLetter, lineNumber, @@ -115,7 +131,7 @@ const useDevices = () => { } }) .filter((line): line is Line => line !== undefined); - + setState(prevState => { const displayedLines = linesToDisplay.length === 0 @@ -150,7 +166,7 @@ const useDevices = () => { status: Status.LOADING, })); - const token = await authRepository.auth({username, password}); + const token = await authRepository.auth({username, password, rut}); const {lineDetails, stopMessage} = await devicesRepository.getDeviceInfo({ @@ -201,6 +217,7 @@ const useDevices = () => { password, updateBusesListInterval, username, + rut, ]); useEffect(() => { diff --git a/src/infraestructure/hooks/useRemoteConfig.ts b/src/infraestructure/hooks/useRemoteConfig.ts index b349ee6..df1bcee 100644 --- a/src/infraestructure/hooks/useRemoteConfig.ts +++ b/src/infraestructure/hooks/useRemoteConfig.ts @@ -6,28 +6,30 @@ const ONE_HOUR = 3600000; const useRemoteConfig = () => { const [status, setStatus] = useState(Status.LOADING); - + useEffect(() => { const init = async () => { try { await remoteConfig().setConfigSettings({ minimumFetchIntervalMillis: ONE_HOUR, }); - + await remoteConfig().setDefaults({ BASE_URL: 'https://transporte.hz.kursor.cl', HEADER_IMAGE_URL: 'https://cdn-icons-png.flaticon.com/512/8371/8371047.png', USER: 'usuario1', - PASS: 'usuario1', + PASSWORD: 'usuario1', + RUT:'11111111-1', CHANGE_PAGE_INTERVAL: 20000, // in miliseconds - UPDATE_BUSES_LIST_INTERVAL: 600000, // in miliseconds + UPDATE_BUSES_LIST_INTERVAL: 60000, // in miliseconds }); - + await remoteConfig().fetchAndActivate(); setStatus(Status.SUCCESS); } catch (error) { + console.log(error ); setStatus(Status.ERROR); } }; diff --git a/src/infraestructure/repositories/__tests__/AuthRepositoryImpl.spec.ts b/src/infraestructure/repositories/__tests__/AuthRepositoryImpl.spec.ts index a47a938..7e36640 100644 --- a/src/infraestructure/repositories/__tests__/AuthRepositoryImpl.spec.ts +++ b/src/infraestructure/repositories/__tests__/AuthRepositoryImpl.spec.ts @@ -17,7 +17,7 @@ describe('AuthRepositoryImpl tests', () => { const repo = new AuthRepositoryImpl(mockedAuthAPI); - const token = await repo.auth({username: 'username', password: 'password'}); + const token = await repo.auth({username: 'username', password: 'password',rut:'rut'}); expect(token).toBe('TOKEN'); }); diff --git a/src/presentation/components/BusList.tsx b/src/presentation/components/BusList.tsx index 1dfb634..f598256 100644 --- a/src/presentation/components/BusList.tsx +++ b/src/presentation/components/BusList.tsx @@ -8,14 +8,28 @@ import { import {ViewStyle} from 'react-native'; import Table, {Line} from './Table'; import Status from '../../utils/Status'; - +//import DeviceInfo from 'react-native-device-info'; +import remoteConfig from '@react-native-firebase/remote-config'; +import RemoteConfigKeys from '../../utils/RemoteConfigKeys'; interface BusListProps { buses: Line[]; status: Status; style?: StyleProp; } -const ERROR_MESSAGE = 'Ha ocurrido un error'; +/* let deviceId = null; +try { + deviceId = DeviceInfo.getUniqueId(); +} catch (error) { + console.error('Error al obtener el ID del dispositivo:', error); +} + +const DEVICE_ID = deviceId ? String(deviceId) : 'No se pudo obtener el ID del dispositivo'; +const ERROR_MESSAGE = 'Ha ocurrido un error. El ID del dispositivo es: ' + DEVICE_ID; + */ + +//const ERROR_MESSAGE = 'Ha ocurrido un error.' ; +const ERROR_MESSAGE = remoteConfig().getString(RemoteConfigKeys.BASE_URL); const EMPTY_MESSAGE = 'No buses available'; const BusList = ({buses, status, style}: BusListProps) => { diff --git a/src/presentation/screens/App.tsx b/src/presentation/screens/App.tsx index 54b0c04..c6bf71d 100644 --- a/src/presentation/screens/App.tsx +++ b/src/presentation/screens/App.tsx @@ -7,7 +7,7 @@ const ERROR_MESSAGE = 'Ha ocurrido un error'; const App = () => { const {status} = useRemoteConfig(); - + console.log(status); if (status === Status.LOADING) { return ( @@ -23,6 +23,8 @@ const App = () => { ); } + + return ( diff --git a/src/presentation/screens/BusStopInfoScreen.tsx b/src/presentation/screens/BusStopInfoScreen.tsx index 09f51fb..5df5a1c 100644 --- a/src/presentation/screens/BusStopInfoScreen.tsx +++ b/src/presentation/screens/BusStopInfoScreen.tsx @@ -34,11 +34,11 @@ const BusStopInfoScreen = () => { style={styles.bodyContainer} status={status} /> - - + {/*footerContainer + /> */} ); @@ -58,7 +58,7 @@ const styles = StyleSheet.create({ }, bannerContainer: { flex: 0.5, - backgroundColor: 'grey', + backgroundColor: 'orange', }, bodyContainer: { flex: 10, diff --git a/src/utils/RemoteConfigKeys.ts b/src/utils/RemoteConfigKeys.ts index d44448d..fd31224 100644 --- a/src/utils/RemoteConfigKeys.ts +++ b/src/utils/RemoteConfigKeys.ts @@ -4,7 +4,8 @@ enum RemoteConfigKeys { CHANGE_PAGE_INTERVAL = 'CHANGE_PAGE_INTERVAL', UPDATE_BUSES_LIST_INTERVAL = 'UPDATE_BUSES_LIST_INTERVAL', USER = 'USER', - PASS = 'PASSWORD', + PASSWORD = 'PASSWORD', + RUT = 'RUT', } export default RemoteConfigKeys; diff --git a/yarn.lock b/yarn.lock index ed6a8d3..abf0c96 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6203,10 +6203,10 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== -react-native-device-info@^10.11.0: - version "10.12.0" - resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-10.12.0.tgz#be4e71cbcc9a05e8643b1a419a4450d4cef9bbcc" - integrity sha512-gnBkjyZNEqRd+5BNrdzuvmlraHTCH/to2x0Gp9rtDt0O9xWWW1MTYohUVWX9A0Ad2HVYcGanDCIvjWp4ngMZFg== +react-native-device-info@^10.13.1: + version "10.13.1" + resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-10.13.1.tgz#f87f44ba7b67933248be10ca302a4f2f6dbbdd4f" + integrity sha512-j/7Z+Yl9Cesjp8vKaVzbuJQKJSVs4ojXATt5WjwipZ0Ss0mBJjqtbc4x5dfZLmQ4y55VVa7c0v8KHca1iqY/TQ== react-native-vector-icons@^10.0.2: version "10.0.3"