Modificacion para que tome todas las lineas y cambio de remote config

master
unknown 2024-03-13 22:20:45 -03:00
parent a5a57f8110
commit 79097a07c8
25 changed files with 119 additions and 43 deletions

View File

@ -1,13 +1,13 @@
{ {
"project_info": { "project_info": {
"project_number": "473250290916", "project_number": "649637283755",
"project_id": "smartstop-7a69d", "project_id": "smartstop-e9b90",
"storage_bucket": "smartstop-7a69d.appspot.com" "storage_bucket": "smartstop-e9b90.appspot.com"
}, },
"client": [ "client": [
{ {
"client_info": { "client_info": {
"mobilesdk_app_id": "1:473250290916:android:6153a7d8264a90b963e0f1", "mobilesdk_app_id": "1:649637283755:android:02f9b01c4acf051ca174ee",
"android_client_info": { "android_client_info": {
"package_name": "com.smartstop" "package_name": "com.smartstop"
} }
@ -15,7 +15,7 @@
"oauth_client": [], "oauth_client": [],
"api_key": [ "api_key": [
{ {
"current_key": "AIzaSyAI7Q2y3XOAO8qQfnOZAOfFGqzS4pjbD7k" "current_key": "AIzaSyCvcskItwpjqoA2wiNv4xwHhNoYsinfU2s"
} }
], ],
"services": { "services": {

View File

@ -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"
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -18,7 +18,7 @@
"moment": "^2.29.4", "moment": "^2.29.4",
"react": "18.2.0", "react": "18.2.0",
"react-native": "0.72.6", "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" "react-native-vector-icons": "^10.0.2"
}, },
"devDependencies": { "devDependencies": {

View File

@ -12,8 +12,11 @@ class BusStopInfoService {
getLines(): LineDetail[] { getLines(): LineDetail[] {
return this.lines; return this.lines;
} }
getLinesByNumber(lineNumber: string): LineDetail { getLinesByNumber(lineNumber: string): LineDetail {
const line = this.lines.find(bus => bus.lineNumber === lineNumber); const line = this.lines.find(bus => bus.lineNumber === lineNumber);
@ -40,9 +43,9 @@ class BusStopInfoService {
compareTime.set('minute', getMinutes(arrival.estimatedGPS)); compareTime.set('minute', getMinutes(arrival.estimatedGPS));
compareTime.set('second', getSeconds(arrival.estimatedGPS)); compareTime.set('second', getSeconds(arrival.estimatedGPS));
if (compareTime.isAfter(currentTime)) { //if (compareTime.isAfter(currentTime)) {
return arrival; return arrival;
} // }
}, },
); );

View File

@ -10,7 +10,7 @@ class AuthAPI {
this.baseURL = baseURL; this.baseURL = baseURL;
} }
async auth({username, password}: AuthRequest): Promise<AuthResponse> { async auth({username, password,rut}: AuthRequest): Promise<AuthResponse> {
if (!username) { if (!username) {
throw new Error('username is required'); throw new Error('username is required');
} }
@ -18,12 +18,15 @@ class AuthAPI {
if (!password) { if (!password) {
throw new Error('password is required'); throw new Error('password is required');
} }
if (!rut) {
throw new Error('rut is required');
}
const {data} = await axios.post<AuthResponse>( const {data} = await axios.post<AuthResponse>(
`${this.baseURL}${LOGIN_METHOD}`, `${this.baseURL}${LOGIN_METHOD}`,
{ {
username, username,
password, password,
rut,
}, },
); );

View File

@ -21,6 +21,7 @@ describe('AuthAPI tests', () => {
const token = await authAPI.auth({ const token = await authAPI.auth({
username: 'username', username: 'username',
password: 'password', password: 'password',
rut:'rut',
}); });
expect(token).toMatchObject({token: 'token'}); expect(token).toMatchObject({token: 'token'});
@ -31,6 +32,7 @@ describe('AuthAPI tests', () => {
authAPI.auth({ authAPI.auth({
password: 'password', password: 'password',
username: '', username: '',
rut:'rut',
}), }),
).rejects.toThrow('username is required'); ).rejects.toThrow('username is required');
}); });
@ -40,6 +42,7 @@ describe('AuthAPI tests', () => {
authAPI.auth({ authAPI.auth({
username: 'username', username: 'username',
password: '', password: '',
rut:'rut',
}), }),
).rejects.toThrow('password is required'); ).rejects.toThrow('password is required');
}); });
@ -53,6 +56,7 @@ describe('AuthAPI tests', () => {
authAPI.auth({ authAPI.auth({
username: 'username', username: 'username',
password: 'password', password: 'password',
rut:'rut',
}), }),
).rejects.toThrow('Request failed with status code 400'); ).rejects.toThrow('Request failed with status code 400');
}); });

View File

@ -1,6 +1,7 @@
interface AuthRequest { interface AuthRequest {
username: string; username: string;
password: string; password: string;
rut:string;
} }
export default AuthRequest; export default AuthRequest;

View File

@ -11,6 +11,7 @@ import RemoteConfigKeys from '../../utils/RemoteConfigKeys';
import {Line} from '../../presentation/components/Table'; import {Line} from '../../presentation/components/Table';
import Status from '../../utils/Status'; import Status from '../../utils/Status';
import {BUSES_BY_PAGE} from '../../domain/const'; import {BUSES_BY_PAGE} from '../../domain/const';
//import DeviceInfo from 'react-native-device-info';
export interface State { export interface State {
status: Status; status: Status;
@ -20,8 +21,8 @@ export interface State {
stopMessage: string; stopMessage: string;
stopName: string; stopName: string;
} }
//const deviceId = DeviceInfo.getUniqueId();
const DEVICE_ID = 'TTM543870hyt'; const DEVICE_ID ='TTM543870hyt';// String(deviceId);
const useDevices = () => { const useDevices = () => {
const [state, setState] = useState<State>({ const [state, setState] = useState<State>({
@ -35,10 +36,12 @@ const useDevices = () => {
const baseURL = remoteConfig().getString(RemoteConfigKeys.BASE_URL); const baseURL = remoteConfig().getString(RemoteConfigKeys.BASE_URL);
const username = remoteConfig().getString(RemoteConfigKeys.USER); 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( const changePageInterval = remoteConfig().getNumber(
RemoteConfigKeys.CHANGE_PAGE_INTERVAL, RemoteConfigKeys.CHANGE_PAGE_INTERVAL,
); );
const updateBusesListInterval = remoteConfig().getNumber( const updateBusesListInterval = remoteConfig().getNumber(
RemoteConfigKeys.UPDATE_BUSES_LIST_INTERVAL, RemoteConfigKeys.UPDATE_BUSES_LIST_INTERVAL,
); );
@ -49,6 +52,7 @@ const useDevices = () => {
() => new DevicesRepositoryImpl(deviceApi), () => new DevicesRepositoryImpl(deviceApi),
[deviceApi], [deviceApi],
); );
const authRepository = useMemo( const authRepository = useMemo(
() => new AuthRepositoryImpl(authApi), () => new AuthRepositoryImpl(authApi),
[authApi], [authApi],
@ -56,6 +60,7 @@ const useDevices = () => {
const setDisplayedLines = useCallback( const setDisplayedLines = useCallback(
(lineDetails: LineDetail[], stopMessage: string, stopName: string) => { (lineDetails: LineDetail[], stopMessage: string, stopName: string) => {
if (!lineDetails || !stopName) { if (!lineDetails || !stopName) {
return; return;
} }
@ -66,8 +71,9 @@ const useDevices = () => {
const linesWithArrivals = lineDetails const linesWithArrivals = lineDetails
.map(line => { .map(line => {
try { try {
if (line.arrivals && line.arrivals.length > 0) {
busStopInfoService.getNextArraival(line.lineNumber); busStopInfoService.getNextArraival(line.lineNumber);
}
return line; return line;
} catch (error) { } catch (error) {
return undefined; return undefined;
@ -75,19 +81,29 @@ const useDevices = () => {
}) })
.filter((line): line is LineDetail => line !== undefined); .filter((line): line is LineDetail => line !== undefined);
busStopInfoService = new BusStopInfoService(linesWithArrivals); busStopInfoService = new BusStopInfoService(linesWithArrivals);
var estimatedArrivalTimeInMinutes="";
const linesToDisplay: Line[] = busStopInfoService const linesToDisplay: Line[] = busStopInfoService
.pruneBusList(state.currentIndex, BUSES_BY_PAGE) .pruneBusList(state.currentIndex, BUSES_BY_PAGE)
.map(line => { .map(line => {
try { try {
if (line.arrivals && line.arrivals.length > 0)
{
const nextArraival = busStopInfoService.getNextArraival( const nextArraival = busStopInfoService.getNextArraival(
line.lineNumber, line.lineNumber,
); );
const estimatedArrivalTimeInMinutes = estimatedArrivalTimeInMinutes =busStopInfoService.checkArraivalTime(nextArraival);
busStopInfoService.checkArraivalTime(nextArraival); }
else
{
estimatedArrivalTimeInMinutes = "Sin información";
}
const lineLetter = const lineLetter =
busStopInfoService.getLineLetterFromDescription( busStopInfoService.getLineLetterFromDescription(
line.description, line.description,
@ -150,7 +166,7 @@ const useDevices = () => {
status: Status.LOADING, status: Status.LOADING,
})); }));
const token = await authRepository.auth({username, password}); const token = await authRepository.auth({username, password, rut});
const {lineDetails, stopMessage} = const {lineDetails, stopMessage} =
await devicesRepository.getDeviceInfo({ await devicesRepository.getDeviceInfo({
@ -201,6 +217,7 @@ const useDevices = () => {
password, password,
updateBusesListInterval, updateBusesListInterval,
username, username,
rut,
]); ]);
useEffect(() => { useEffect(() => {

View File

@ -19,15 +19,17 @@ const useRemoteConfig = () => {
HEADER_IMAGE_URL: HEADER_IMAGE_URL:
'https://cdn-icons-png.flaticon.com/512/8371/8371047.png', 'https://cdn-icons-png.flaticon.com/512/8371/8371047.png',
USER: 'usuario1', USER: 'usuario1',
PASS: 'usuario1', PASSWORD: 'usuario1',
RUT:'11111111-1',
CHANGE_PAGE_INTERVAL: 20000, // in miliseconds CHANGE_PAGE_INTERVAL: 20000, // in miliseconds
UPDATE_BUSES_LIST_INTERVAL: 600000, // in miliseconds UPDATE_BUSES_LIST_INTERVAL: 60000, // in miliseconds
}); });
await remoteConfig().fetchAndActivate(); await remoteConfig().fetchAndActivate();
setStatus(Status.SUCCESS); setStatus(Status.SUCCESS);
} catch (error) { } catch (error) {
console.log(error );
setStatus(Status.ERROR); setStatus(Status.ERROR);
} }
}; };

View File

@ -17,7 +17,7 @@ describe('AuthRepositoryImpl tests', () => {
const repo = new AuthRepositoryImpl(mockedAuthAPI); 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'); expect(token).toBe('TOKEN');
}); });

View File

@ -8,14 +8,28 @@ import {
import {ViewStyle} from 'react-native'; import {ViewStyle} from 'react-native';
import Table, {Line} from './Table'; import Table, {Line} from './Table';
import Status from '../../utils/Status'; 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 { interface BusListProps {
buses: Line[]; buses: Line[];
status: Status; status: Status;
style?: StyleProp<ViewStyle>; style?: StyleProp<ViewStyle>;
} }
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 EMPTY_MESSAGE = 'No buses available';
const BusList = ({buses, status, style}: BusListProps) => { const BusList = ({buses, status, style}: BusListProps) => {

View File

@ -7,7 +7,7 @@ const ERROR_MESSAGE = 'Ha ocurrido un error';
const App = () => { const App = () => {
const {status} = useRemoteConfig(); const {status} = useRemoteConfig();
console.log(status);
if (status === Status.LOADING) { if (status === Status.LOADING) {
return ( return (
<SafeAreaView style={styles.centeredContainer}> <SafeAreaView style={styles.centeredContainer}>
@ -23,6 +23,8 @@ const App = () => {
</SafeAreaView> </SafeAreaView>
); );
} }
return ( return (
<SafeAreaView style={styles.container}> <SafeAreaView style={styles.container}>
<BusStopInfoScreen /> <BusStopInfoScreen />

View File

@ -34,11 +34,11 @@ const BusStopInfoScreen = () => {
style={styles.bodyContainer} style={styles.bodyContainer}
status={status} status={status}
/> />
<View style={styles.footerContainer}> <View style={styles.headerContainer}>
<Image {/*footerContainer <Image
source={require('../../../resources/images/footer.jpg')} source={require('../../../resources/images/footer.jpg')}
style={styles.image} style={styles.image}
/> /> */}
</View> </View>
</Container> </Container>
); );
@ -58,7 +58,7 @@ const styles = StyleSheet.create({
}, },
bannerContainer: { bannerContainer: {
flex: 0.5, flex: 0.5,
backgroundColor: 'grey', backgroundColor: 'orange',
}, },
bodyContainer: { bodyContainer: {
flex: 10, flex: 10,

View File

@ -4,7 +4,8 @@ enum RemoteConfigKeys {
CHANGE_PAGE_INTERVAL = 'CHANGE_PAGE_INTERVAL', CHANGE_PAGE_INTERVAL = 'CHANGE_PAGE_INTERVAL',
UPDATE_BUSES_LIST_INTERVAL = 'UPDATE_BUSES_LIST_INTERVAL', UPDATE_BUSES_LIST_INTERVAL = 'UPDATE_BUSES_LIST_INTERVAL',
USER = 'USER', USER = 'USER',
PASS = 'PASSWORD', PASSWORD = 'PASSWORD',
RUT = 'RUT',
} }
export default RemoteConfigKeys; export default RemoteConfigKeys;

View File

@ -6203,10 +6203,10 @@ react-is@^17.0.1:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
react-native-device-info@^10.11.0: react-native-device-info@^10.13.1:
version "10.12.0" version "10.13.1"
resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-10.12.0.tgz#be4e71cbcc9a05e8643b1a419a4450d4cef9bbcc" resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-10.13.1.tgz#f87f44ba7b67933248be10ca302a4f2f6dbbdd4f"
integrity sha512-gnBkjyZNEqRd+5BNrdzuvmlraHTCH/to2x0Gp9rtDt0O9xWWW1MTYohUVWX9A0Ad2HVYcGanDCIvjWp4ngMZFg== integrity sha512-j/7Z+Yl9Cesjp8vKaVzbuJQKJSVs4ojXATt5WjwipZ0Ss0mBJjqtbc4x5dfZLmQ4y55VVa7c0v8KHca1iqY/TQ==
react-native-vector-icons@^10.0.2: react-native-vector-icons@^10.0.2:
version "10.0.3" version "10.0.3"