Skip to content

Commit

Permalink
#78 Manually set location in AdvancedSettings screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonononoki committed Jan 1, 2025
1 parent b68346f commit 9034ec8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Global.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const STORAGE_SETTINGS_UNIT = "settings.unit"
export const STORAGE_SETTINGS_COLOR_PRIMARY = "settings.color.primary"
export const STORAGE_SETTINGS_COLOR_SECONDARY = "settings.color.secondary"

export const STORAGE_ADV_SEARCH_GPSTIMEOPUT = "adv-search.gps-timeout";

export const SCREEN_YOURPROFILE = "YourProfile"
export const SCREEN_CHAT = "Chat"
export const SCREEN_SEARCH = "Search"
Expand All @@ -61,6 +63,7 @@ export const EMPTY_STRING = "...";
export const MAX_INTERESTS = 10;
export const MAX_MESSAGE_LENGTH = 255;
export const MAX_DESCRIPTION_LENGTH = 255;
export const DEFAULT_GPS_TIMEOUT = 6000;

const IMG_SIZE_MAX = 600;

Expand Down
2 changes: 1 addition & 1 deletion i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
},
"search": {
"settings": {
"min-gps-timeout": "Standort Timeout",
"min-gps-timeout": "GPS Timeout (ms)",
"location": {
"latitude": "Latitude",
"longitude": "Longitude"
Expand Down
2 changes: 1 addition & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
},
"search": {
"settings": {
"min-gps-timeout": "Location timeout",
"min-gps-timeout": "GPS timeout (ms)",
"location": {
"latitude": "Latitude",
"longitude": "Longitude"
Expand Down
10 changes: 7 additions & 3 deletions screens/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ const Search = ({ route, navigation }) => {

const { height, width } = useWindowDimensions();

const LOCATION_TIMEOUT_SHORT = 6000;
const LOCATION_TIMEOUT_LONG = 10000;
const LOCATION_TIMEOUT_SHORT = Global.DEFAULT_GPS_TIMEOUT;
const LOCATION_TIMEOUT_LONG = LOCATION_TIMEOUT_SHORT * 2;

const promiseWithTimeout = (timeoutMs: number, promise: Promise<any>) => {
return Promise.race([
Expand Down Expand Up @@ -151,7 +151,11 @@ const Search = ({ route, navigation }) => {
if (status == 'granted') {
hasLocationPermission = true;
try {
location = await promiseWithTimeout(hasLocation ? LOCATION_TIMEOUT_SHORT : LOCATION_TIMEOUT_LONG, Location.getCurrentPositionAsync({}));
let storedGpsTimeout = await Global.GetStorage(Global.STORAGE_ADV_SEARCH_GPSTIMEOPUT);
let gpsTimeout = storedGpsTimeout ?
hasLocation ? Math.max(LOCATION_TIMEOUT_SHORT, Number(storedGpsTimeout)) : Math.max(LOCATION_TIMEOUT_LONG, Number(storedGpsTimeout)) :
hasLocation ? LOCATION_TIMEOUT_SHORT : LOCATION_TIMEOUT_LONG;
location = await promiseWithTimeout(gpsTimeout, Location.getCurrentPositionAsync({}));
hasGpsEnabled = true;
lat = location?.coords.latitude;
lon = location?.coords.longitude;
Expand Down
37 changes: 37 additions & 0 deletions screens/profile/AdvancedSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ const AdvancedSettings = ({ route, navigation }) => {
var user: UserDto = route.params.user;
const { colors } = useTheme();
const { height, width } = useWindowDimensions();
const defaultTimeoutString = String(Global.DEFAULT_GPS_TIMEOUT);

React.useEffect(() => {
load();
}, []);

const [latitude, setLatitude] = React.useState("0.00");
const [longitude, setLongitude] = React.useState("0.00");
const [gpsTimeout, setGpsTimeout] = React.useState(defaultTimeoutString);


async function load() {
setLatitude(String(user.locationLatitude));
setLongitude(String(user.locationLongitude));
let timeoutStorage = await Global.GetStorage(Global.STORAGE_ADV_SEARCH_GPSTIMEOPUT);
setGpsTimeout(timeoutStorage ? timeoutStorage : defaultTimeoutString);
}

async function uploadLocation() {
Expand All @@ -39,6 +43,14 @@ const AdvancedSettings = ({ route, navigation }) => {
}
}

async function saveGpsTimeout(value?: number) {
if(value) {
Global.SetStorage(Global.STORAGE_ADV_SEARCH_GPSTIMEOPUT, String(value));
} else if(!isNaN(Number(gpsTimeout))) {
Global.SetStorage(Global.STORAGE_ADV_SEARCH_GPSTIMEOPUT, gpsTimeout);
}
}

return (
<View style={{ height: height, width: '100%' }}>
<VerticalView onRefresh={load} style={{ padding: 0 }}>
Expand Down Expand Up @@ -66,6 +78,31 @@ const AdvancedSettings = ({ route, navigation }) => {
onPress={uploadLocation}
/>
</View>
<View style={[styles.containerProfileItem, { marginTop: 32, flexDirection: 'row', gap: 4, alignItems: 'center' }]}>
<TextInput
style={{ backgroundColor: colors.background }}
label={i18n.t('profile.search.settings.min-gps-timeout')}
value={gpsTimeout}
onChangeText={setGpsTimeout}
onSubmitEditing={() => saveGpsTimeout}
keyboardType="decimal-pad"
/>
<IconButton
icon="check"
size={20}
mode="contained"
onPress={() => saveGpsTimeout}
/>
<IconButton
icon="undo-variant"
size={20}
mode="contained"
onPress={() => {
setGpsTimeout(defaultTimeoutString);
saveGpsTimeout(Global.DEFAULT_GPS_TIMEOUT)
}}
/>
</View>
</VerticalView>
</View>
);
Expand Down

0 comments on commit 9034ec8

Please sign in to comment.