Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/microfone permission #375

Merged
merged 57 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
243c622
implement observation sharing
CDFN May 10, 2024
f0d826c
change share text based on attachements amount
CDFN May 10, 2024
cd50715
lang
CDFN May 10, 2024
7ecaed4
Merge branch 'main' into feat/observation-sharing
CDFN May 10, 2024
44ee88c
add query to fetch attachments in base64 format
CDFN May 14, 2024
4aa4c00
ignore promise rejection when user closes sheet
CDFN May 14, 2024
5bdff97
extract url to base64 function to utils
CDFN May 14, 2024
22df49e
adjust urls in share modal to new types
CDFN May 14, 2024
5552226
fix url type
CDFN May 14, 2024
23976a2
lang, use utm format for coordinates while sharing
CDFN May 14, 2024
aa93a33
fix typing, cleanup code
CDFN May 16, 2024
79d5bb7
Add loading state
CDFN May 16, 2024
aba1388
remvoe unused import
CDFN May 16, 2024
8de7da5
Merge branch 'main' into feat/observation-sharing
CDFN May 16, 2024
1a5d1bc
don't use base64 to display images
CDFN May 18, 2024
4660f25
redisign observation edit screen
bohdanprog May 20, 2024
7fba1c1
change translations
bohdanprog May 20, 2024
30f7321
óMerge branch 'main' of github.com:digidem/CoMapeo-mobile into feat/r…
bohdanprog May 20, 2024
5094abd
update icons, create separate components for ActionTab
bohdanprog May 20, 2024
5f6dc4a
update translates
bohdanprog May 20, 2024
5aad33c
Update ActionTab component
bohdanprog May 20, 2024
356995d
change translations in audio button
bohdanprog May 20, 2024
bd46914
update description field edit observation screen
bohdanprog May 20, 2024
e140762
Merge branch 'main' of github.com:digidem/CoMapeo-mobile into feat/re…
bohdanprog May 20, 2024
b966352
lazy fetch base64 urls, minor nitpicks
CDFN May 20, 2024
7972cee
change styles
bohdanprog May 20, 2024
9ac3aad
remove import
bohdanprog May 20, 2024
719c2b4
feat: display photos in observations (#344)
CDFN May 20, 2024
07662a7
remove base64 query as it's not used anymore
CDFN May 20, 2024
9ce0d10
Merge branch 'main' into feat/observation-sharing
CDFN May 20, 2024
bdeb988
fixed problem with Item Button, create custom hook KeyboardListener, …
bohdanprog May 21, 2024
fab435b
Merge branch 'main' into feat/redesign-edit-observation
bohdanprog May 21, 2024
f36ee7c
fixed problem with feature flag
bohdanprog May 21, 2024
50b1a44
Merge branch 'feat/redesign-edit-observation' of github.com:digidem/C…
bohdanprog May 21, 2024
324d17a
Merge branch 'feat/redesign-edit-observation' of github.com:digidem/C…
bohdanprog May 21, 2024
04f3608
resolve conflict
bohdanprog May 21, 2024
935bbe3
Merge remote-tracking branch 'origin/feat/observation-sharing' into f…
bohdanprog May 21, 2024
c39937c
update thubnail components
bohdanprog May 21, 2024
c0259ba
update imports
bohdanprog May 21, 2024
0cf9453
update imports and rename folder with icons
bohdanprog May 21, 2024
c5c6047
Merge branch 'feat/redesign-edit-observation' of github.com:digidem/C…
bohdanprog May 21, 2024
cf03d5f
change structure files, add play icon
bohdanprog May 21, 2024
82abe01
change type of AudioThumbnail
bohdanprog May 21, 2024
86ab823
add color style to audio svg
bohdanprog May 21, 2024
abea494
Merge branch 'main' of github.com:digidem/CoMapeo-mobile into feat/ne…
bohdanprog May 22, 2024
05b9899
Merge branch 'feat/new-ui-edit-observation-atachment' of github.com:d…
bohdanprog May 22, 2024
9b4bcad
add audio permission check, add translations, add new microphone icon…
bohdanprog May 22, 2024
d29a96f
generate translations
bohdanprog May 22, 2024
93c2b7c
Merge branch 'main' into feat/microfone-permission
CDFN May 24, 2024
0c1e731
Merge branch 'main' into feat/new-ui-edit-observation-atachment
CDFN May 24, 2024
d9ab6ab
Merge branch 'feat/new-ui-edit-observation-atachment' into feat/micro…
CDFN May 24, 2024
62ea44b
add changes after review, rename files
bohdanprog May 27, 2024
0c6b81f
Merge branch 'main' of github.com:digidem/CoMapeo-mobile into feat/ne…
bohdanprog May 27, 2024
30b22cf
change another color variable in audioThumbnail
bohdanprog May 27, 2024
0c70804
add changes after review
bohdanprog May 27, 2024
146c475
Merge branch 'feat/new-ui-edit-observation-atachment' of github.com:d…
bohdanprog May 27, 2024
7cfe40b
update package-lock.json
bohdanprog May 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,26 @@
"screens.AppPasscode.TurnOffPasscode.usePasscode": {
"message": "Use App Passcode"
},
"screens.AudioPermission.Button.allow": {
"description": "Screen button text for allow the audio permission",
"message": "Allow"
},
"screens.AudioPermission.Button.goToSettings": {
"description": "Screen button text for navigate user to settings when audio permission was denied",
"message": "Go to Settings"
},
"screens.AudioPermission.Button.notNow": {
"description": "Screen button text for not allowed audio permission",
"message": "Not Now"
},
"screens.AudioPermission.description": {
"description": "Screen description for audio permission screen",
"message": "To record audio while using the app and in the background CoMapeo needs to access your microphone."
},
"screens.AudioPermission.title": {
"description": "Screen title for audio permission screen",
"message": "Recording Audio with CoMapeo"
},
"screens.CameraScreen.goToSettings": {
"message": "Go to Settings"
},
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"uint8array-extras": "^0.5.0",
"utm": "^1.1.1",
"validate-color": "^2.2.4",
"zustand": "^4.4.6"
"zustand": "^4.4.6",
"expo-av": "^13.10.6"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const emptyObservation: ClientGeneratedObservation = {

export type DraftObservationSlice = {
photos: Photo[];
audioRecordings: [];
value: Observation | null | ClientGeneratedObservation;
observationId?: string;
actions: {
Expand All @@ -47,6 +48,7 @@ const draftObservationSlice: StateCreator<DraftObservationSlice> = (
get,
) => ({
photos: [],
audioRecordings: [],
value: null,
actions: {
deletePhoto: id => deletePhoto(set, get, id),
Expand All @@ -57,6 +59,7 @@ const draftObservationSlice: StateCreator<DraftObservationSlice> = (
clearDraft: () => {
set({
photos: [],
audioRecordings: [],
value: null,
observationId: undefined,
});
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/images/observationEdit/AudioPermission.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/frontend/images/observationEdit/Play.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/frontend/screens/Observation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {InsetMapView} from './InsetMapView';
import {ButtonFields} from './Buttons';
import {NativeNavigationComponent} from '../../sharedTypes/navigation';
import {ObservationHeaderRight} from './ObservationHeaderRight';
import {ThumbnailScrollView} from '../../sharedComponents/ThumbnailScrollView.tsx';
import {MediaScrollView} from '../../sharedComponents/Thumbnail/MediaScrollView';
import {useAttachmentUrlQueries} from '../../hooks/server/media.ts';

const m = defineMessages({
Expand Down Expand Up @@ -94,7 +94,7 @@ export const ObservationScreen: NativeNavigationComponent<'Observation'> = ({
</View>
) : null}
{attachmentUrls.length > 0 && (
<ThumbnailScrollView
<MediaScrollView
photos={attachmentUrls.map(attachmentData => {
return !attachmentData
? undefined
Expand All @@ -103,6 +103,7 @@ export const ObservationScreen: NativeNavigationComponent<'Observation'> = ({
id: attachmentData.driveDiscoveryId,
};
})}
audioRecordings={[]}
/>
)}
</View>
Expand Down
120 changes: 120 additions & 0 deletions src/frontend/screens/ObservationEdit/ThumbnailAndActionTab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import React, {FC, useCallback} from 'react';
import {View} from 'react-native';
import {defineMessages, useIntl} from 'react-intl';
import {MediaScrollView} from '../../sharedComponents/Thumbnail/MediaScrollView';
import {ActionTab} from '../../sharedComponents/ActionTab';
import PhotoIcon from '../../images/observationEdit/Photo.svg';
import AudioIcon from '../../images/observationEdit/Audio.svg';
import DetailsIcon from '../../images/observationEdit/Details.svg';
import {usePersistedDraftObservation} from '../../hooks/persistedState/usePersistedDraftObservation';
import {useDraftObservation} from '../../hooks/useDraftObservation';
import {NativeStackNavigationProp} from '@react-navigation/native-stack';
import {AppStackParamsList} from '../../sharedTypes/navigation';
import {useBottomSheetModal} from '../../sharedComponents/BottomSheetModal';
import {PermissionAudio} from '../../sharedComponents/PermissionAudio';
import {Audio} from 'expo-av';

const m = defineMessages({
audioButton: {
id: 'screens.ObservationEdit.ObservationEditView.audioButton',
defaultMessage: 'Audio',
description: 'Button label for adding audio',
},
photoButton: {
id: 'screens.ObservationEdit.ObservationEditView.photoButton',
defaultMessage: 'Photo',
description: 'Button label for adding photo',
},
detailsButton: {
id: 'screens.ObservationEdit.ObservationEditView.detailsButton',
defaultMessage: 'Details',
description: 'Button label to add details',
},
});

interface ThumbnailAndActionTab {
navigation: NativeStackNavigationProp<
AppStackParamsList,
'ObservationEdit',
undefined
>;
}

export const ThumbnailAndActionTab: FC<ThumbnailAndActionTab> = ({
navigation,
}) => {
const {formatMessage: t} = useIntl();
const {usePreset} = useDraftObservation();
const preset = usePreset();
const {photos, audioRecordings, observationId} = usePersistedDraftObservation(
store => store,
);
const {
openSheet: openAudioPermissionSheet,
sheetRef: audioPermissionSheetRef,
isOpen: isAudioPermissionSheetOpen,
closeSheet: closeAudioPermissionSheet,
} = useBottomSheetModal({
openOnMount: false,
});
const [permissionResponse] = Audio.usePermissions({request: false});

const handleCameraPress = () => {
navigation.navigate('AddPhoto');
};

const handleDetailsPress = () => {
navigation.navigate('ObservationFields', {question: 1});
};

const handleAudioPress = useCallback(() => {
if (permissionResponse?.granted) {
navigation.navigate('Home', {screen: 'Map'});
} else {
openAudioPermissionSheet();
}
}, [navigation, openAudioPermissionSheet, permissionResponse?.granted]);

const bottomSheetItems = [
{
icon: <PhotoIcon width={30} height={30} />,
label: t(m.photoButton),
onPress: handleCameraPress,
},
];

if (process.env.EXPO_PUBLIC_FEATURE_AUDIO) {
bottomSheetItems.unshift({
icon: <AudioIcon width={30} height={30} />,
label: t(m.audioButton),
onPress: handleAudioPress,
});
}

if (preset?.fieldIds.length) {
// Only show the option to add details if preset fields are defined.
bottomSheetItems.push({
icon: <DetailsIcon width={30} height={30} />,
label: t(m.detailsButton),
onPress: handleDetailsPress,
});
}

return (
<>
<View>
<MediaScrollView
photos={photos}
audioRecordings={audioRecordings}
observationId={observationId}
/>
<ActionTab items={bottomSheetItems} />
</View>
<PermissionAudio
closeSheet={closeAudioPermissionSheet}
isOpen={isAudioPermissionSheetOpen}
sheetRef={audioPermissionSheetRef}
/>
</>
);
};
71 changes: 5 additions & 66 deletions src/frontend/screens/ObservationEdit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import React, {useCallback} from 'react';
import {MessageDescriptor, defineMessages, useIntl} from 'react-intl';

import React from 'react';
import {MessageDescriptor, defineMessages} from 'react-intl';
import {NativeNavigationComponent} from '../../sharedTypes/navigation';
import {usePersistedDraftObservation} from '../../hooks/persistedState/usePersistedDraftObservation';
import {View, ScrollView, StyleSheet} from 'react-native';
import {DescriptionField} from './DescriptionField';
import {ThumbnailScrollView} from '../../sharedComponents/ThumbnailScrollView';
import {ErrorBottomSheet} from '../../sharedComponents/ErrorBottomSheet';
import {SaveButton} from './SaveButton';
import {PresetAndLocationHeader} from './PresetAndLocationHeader';
import {WHITE} from '../../lib/styles';
import Photo from '../../images/observationEdit/Photo.svg';
import Audio from '../../images/observationEdit/Audio.svg';
import Details from '../../images/observationEdit/Details.svg';
import {ActionTab} from '../../sharedComponents/ActionTab';
import {useDraftObservation} from '../../hooks/useDraftObservation';
import {ThumbnailAndActionTab} from './ThumbnailAndActionTab';

const m = defineMessages({
editTitle: {
Expand All @@ -27,35 +21,14 @@ const m = defineMessages({
defaultMessage: 'New Observation',
description: 'screen title for new observation screen',
},
audioButton: {
id: 'screens.ObservationEdit.ObservationEditView.audioButton',
defaultMessage: 'Audio',
description: 'Button label for adding audio',
},
photoButton: {
id: 'screens.ObservationEdit.ObservationEditView.photoButton',
defaultMessage: 'Photo',
description: 'Button label for adding photo',
},
detailsButton: {
id: 'screens.ObservationEdit.ObservationEditView.detailsButton',
defaultMessage: 'Details',
description: 'Button label to add details',
},
});

export const ObservationEdit: NativeNavigationComponent<'ObservationEdit'> & {
editTitle: MessageDescriptor;
} = ({navigation}) => {
const [error, setError] = React.useState<Error | null>(null);
const observationId = usePersistedDraftObservation(
store => store.observationId,
);
const {usePreset} = useDraftObservation();
const preset = usePreset();
const {observationId} = usePersistedDraftObservation(store => store);
const isNew = !observationId;
const {formatMessage: t} = useIntl();
const photos = usePersistedDraftObservation(store => store.photos);

React.useEffect(() => {
navigation.setOptions({
Expand All @@ -65,47 +38,13 @@ export const ObservationEdit: NativeNavigationComponent<'ObservationEdit'> & {
});
}, [navigation, observationId]);

const handleCameraPress = useCallback(() => {
navigation.navigate('AddPhoto');
}, [navigation]);

const handleDetailsPress = useCallback(() => {
navigation.navigate('ObservationFields', {question: 1});
}, [navigation]);

const bottomSheetItems = [
{
icon: <Photo width={30} height={30} />,
label: t(m.photoButton),
onPress: handleCameraPress,
},
];

if (process.env.EXPO_PUBLIC_FEATURE_AUDIO) {
bottomSheetItems.unshift({
icon: <Audio width={30} height={30} />,
label: t(m.audioButton),
onPress: () => {},
});
}

if (preset?.fieldIds.length) {
// Only show the option to add details if preset fields are defined.
bottomSheetItems.push({
icon: <Details width={30} height={30} />,
label: t(m.detailsButton),
onPress: handleDetailsPress,
});
}

return (
<View style={styles.container}>
<ScrollView contentContainerStyle={styles.scrollViewContent}>
<PresetAndLocationHeader isNew={isNew} />
<DescriptionField />
<ThumbnailScrollView photos={photos} />
</ScrollView>
<ActionTab items={bottomSheetItems} />
<ThumbnailAndActionTab navigation={navigation} />
<ErrorBottomSheet error={error} clearError={() => setError(null)} />
</View>
);
Expand Down
Loading
Loading