Skip to content

Commit

Permalink
restructured settings and introduced update check
Browse files Browse the repository at this point in the history
  • Loading branch information
repolevedavaj committed Apr 25, 2021
1 parent d788f33 commit f4768f5
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 42 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"react-native-web": "^0.15.5",
"sentry-expo": "^3.1.3",
"expo-document-picker": "~8.4.1",
"expo-updates": "~0.4.1"
"expo-updates": "~0.4.1",
"expo-constants": "~9.3.3"
},
"devDependencies": {
"@babel/core": "^7.9.0",
Expand Down
1 change: 1 addition & 0 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ i18n.translations = {
ALL_PLANTS: 'Alle Pflanzen',
SETTINGS: 'Einstellungen',
BACKUPS: 'Sicherungskopien',
DEVELOPER: 'Entwickler',
NEW: 'Neu',
SEARCH: 'Suchen',
SOURCES: 'Quellen',
Expand Down
16 changes: 8 additions & 8 deletions src/stacks/default/tabs/plants/screens/PlantEditScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ import {KeyboardAvoidingView, Platform, ScrollView, StyleSheet, View} from "reac
import {StackActions, useNavigation, useRoute} from "@react-navigation/native";
import {PlantsStackNavigationProp, PlantsStackRouteProp, PlantsTabRoute} from "../PlantsTabRoute";
import {Plant} from "../../../../../model/Plant";
import PlantRepository from "../../../../../repositories/PlantRepository";
import {PreferredLocation} from "../../../../../model/PreferredLocation";
import {WaterDemand} from "../../../../../model/WaterDemand";
import i18n, {translateEnumValue} from "../../../../../i18n";
import * as ImagePicker from 'expo-image-picker';
import {ImagePickerOptions, ImagePickerResult, MediaTypeOptions} from 'expo-image-picker';
import PlantAvatar from "../../../../../common/components/PlantAvatar";
import ImageDataUriHelper from "../../../../../common/ImageDataUriHelper";
import IndexPathHelper from "../../../../../common/IndexPathHelper";
import {WinterProof} from "../../../../../model/WinterProof";
import ObjectUtils from "../../../../../common/ObjectUtils";
import renderTopNavigationTitle from "../../../../../common/components/renderTopNavigationTitle";
import PlantService from "../../../../../services/PlantService";
import renderCardHeader from "../../../../../common/components/renderCardHeader";

const IMAGE_PICKER_OPTIONS: ImagePickerOptions = {
mediaTypes: MediaTypeOptions.Images
Expand Down Expand Up @@ -231,11 +230,13 @@ export default () => {
</Card>

{plant.id !== undefined &&
<Button onPress={deletePlant}
appearance="outline"
status="danger">
Löschen
</Button>
<Card status="basic">
<Button onPress={deletePlant}
appearance="outline"
status="danger">
Löschen
</Button>
</Card>
}
</View>
</ScrollView>
Expand All @@ -247,7 +248,6 @@ export default () => {

}


const styles = StyleSheet.create({
layout: {
flex: 1
Expand Down
2 changes: 2 additions & 0 deletions src/stacks/default/tabs/settings/SettingsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SettingsOverview from "./screens/SettingsOverview";
import {SettingsTabRoute} from "./SettingsTabRoute";
import BackupOverviewScreen from "./screens/BackupOverviewScreen";
import BackupDetailScreen from "./screens/BackupDetailScreen";
import DeveloperScreen from "./screens/DeveloperScreen";

const Stack = createStackNavigator();

Expand All @@ -14,6 +15,7 @@ export default function SettingsTab() {
<Stack.Screen name={SettingsTabRoute.SETTINGS_OVERVIEW} component={SettingsOverview}/>
<Stack.Screen name={SettingsTabRoute.SETTINGS_BACKUP_OVERVIEW} component={BackupOverviewScreen}/>
<Stack.Screen name={SettingsTabRoute.SETTINGS_BACKUP_DETAIL} component={BackupDetailScreen}/>
<Stack.Screen name={SettingsTabRoute.SETTINGS_DEVELOPER} component={DeveloperScreen}/>
</Stack.Navigator>
);

Expand Down
7 changes: 4 additions & 3 deletions src/stacks/default/tabs/settings/SettingsTabRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ export enum SettingsTabRoute {
SETTINGS = 'settings',
SETTINGS_OVERVIEW = 'settings-overview',
SETTINGS_BACKUP_OVERVIEW = 'settings-backup-overview',
SETTINGS_BACKUP_DETAIL = 'settings-backup-detail'

SETTINGS_BACKUP_DETAIL = 'settings-backup-detail',
SETTINGS_DEVELOPER = 'settings-developer'
}

export type SettingsTabRouteParams = {
"settings-overview": any;
"settings-backup-overview": any;
"settings-backup-detail": {
backup: Backup
}
},
"settings-developer": any;
}

export type SettingsTabRouteProp<RouteName extends keyof SettingsTabRouteParams> = RouteProp<SettingsTabRouteParams, RouteName>;
Expand Down
10 changes: 6 additions & 4 deletions src/stacks/default/tabs/settings/screens/BackupDetailScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Button, Divider, Icon, Layout, TopNavigation, TopNavigationAction} from "@ui-kitten/components";
import {Button, Card, Divider, Icon, Layout, TopNavigation, TopNavigationAction} from "@ui-kitten/components";
import React, {useState} from "react";
import {StyleSheet} from "react-native";
import {useNavigation, useRoute} from "@react-navigation/native";
Expand Down Expand Up @@ -49,9 +49,11 @@ export default () => {
accessoryLeft={BackAction}/>
<Divider/>
<Layout style={styles.layout} level="2">
<Button onPress={shareBackup}>Teilen</Button>
<Button status="danger" style={styles.button} onPress={applyBackup}>Übernehmen</Button>
<Button status="danger" style={styles.button} onPress={deleteBackup}>Löschen</Button>
<Card status="basic">
<Button onPress={shareBackup}>Teilen</Button>
<Button status="danger" style={styles.button} onPress={applyBackup}>Übernehmen</Button>
<Button status="danger" style={styles.button} onPress={deleteBackup}>Löschen</Button>
</Card>
</Layout>
<Divider/>
</React.Fragment>
Expand Down
127 changes: 127 additions & 0 deletions src/stacks/default/tabs/settings/screens/DeveloperScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import {
Button,
Card,
Divider,
Icon,
Layout,
List,
ListItem,
TopNavigation,
TopNavigationAction
} from "@ui-kitten/components";
import React, {useState} from "react";
import {Alert, ListRenderItemInfo, StyleSheet, View} from "react-native";
import {useNavigation, useRoute} from "@react-navigation/native";
import renderTopNavigationTitle from "../../../../../common/components/renderTopNavigationTitle";
import {SettingsTabNavigationProp, SettingsTabRoute, SettingsTabRouteProp} from "../SettingsTabRoute";
import i18n from "../../../../../i18n";
import renderCardHeader from "../../../../../common/components/renderCardHeader";
import Constants from 'expo-constants';
import CardListContainer from "../../../../../common/components/CardListContainer";
import GrowBuddyDatabaseService from "../../../../../services/database/GrowBuddyDatabaseService";
import * as Updates from 'expo-updates';

export default () => {

const navigation = useNavigation<SettingsTabNavigationProp<SettingsTabRoute.SETTINGS_BACKUP_DETAIL>>();
const route = useRoute<SettingsTabRouteProp<SettingsTabRoute.SETTINGS_BACKUP_DETAIL>>();

const back = () => {
navigation.goBack();
}

const checkForOTAUpdate = () => {
Updates.checkForUpdateAsync().then((result) => {
if (result.isAvailable) {
Alert.alert(
'OTA Aktualisierung',
`Version ${result.manifest.version} ist verfügbar`,
[
{
text: 'Jetzt übernehmen',
onPress: () => {
Updates.fetchUpdateAsync().then(() => {
Updates.reloadAsync();
});
}
},
{text: 'Ignorieren'}
]
);
} else {
Alert.alert(
'OTA Aktualisierung',
`Version ${Constants.manifest.version} ist die aktuellste Version`,
[{text: 'OK'}]
);
}
});
}

const versions = [
{
key: 'App Version',
value: Constants.manifest.version
},
{
key: 'Native App Version',
value: Constants.nativeAppVersion
}
]

const BackIcon = (props: any) => (
<Icon {...props} name='arrow-back'/>
);

const BackAction = () => (
<TopNavigationAction icon={BackIcon} onPress={back}/>
);

const renderVersionItem = ({item}: ListRenderItemInfo<any>) => {
return (
<ListItem title={item.value} description={item.key} disabled={true}/>
)
}

const Footer = (props: any) => (
<View {...props}>
<Button onPress={checkForOTAUpdate}>
Auf OTA Aktualisierungen prüfen
</Button>
</View>
)

return (
<React.Fragment>
<TopNavigation title={renderTopNavigationTitle(i18n.t('DEVELOPER'))}
alignment="center"
accessoryLeft={BackAction}/>
<Divider/>
<Layout style={styles.layout} level="2">
<Card header={renderCardHeader('App Version')} style={styles.card} footer={Footer}>
<CardListContainer>
<List data={versions} renderItem={renderVersionItem}
ItemSeparatorComponent={Divider}/>
</CardListContainer>
</Card>
<Card header={renderCardHeader('Danger zone')}>
<Button onPress={() => GrowBuddyDatabaseService.resetDatabase()} status="danger">
Datenbank zurücksetzen
</Button>
</Card>
</Layout>
<Divider/>
</React.Fragment>
)

}

const styles = StyleSheet.create({
layout: {
flex: 1,
padding: 15
},
card: {
marginBottom: 15
},
});
48 changes: 22 additions & 26 deletions src/stacks/default/tabs/settings/screens/SettingsOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import {Divider, Layout, List, ListItem, TopNavigation} from "@ui-kitten/components";
import {ListRenderItemInfo} from "react-native";
import {Divider, Icon, Layout, Menu, MenuItem, TopNavigation} from "@ui-kitten/components";
import GrowBuddyDatabaseService from "../../../../../services/database/GrowBuddyDatabaseService";
import renderTopNavigationTitle from "../../../../../common/components/renderTopNavigationTitle";
import {useNavigation, useRoute} from "@react-navigation/native";
Expand All @@ -12,36 +11,33 @@ export default () => {
const navigation = useNavigation<SettingsTabNavigationProp<SettingsTabRoute.SETTINGS_OVERVIEW>>();
const route = useRoute<SettingsTabRouteProp<SettingsTabRoute.SETTINGS_OVERVIEW>>();

const settings = [
{
title: i18n.t('BACKUPS'),
onPress: async () => {
navigation.navigate({name: SettingsTabRoute.SETTINGS_BACKUP_OVERVIEW, params: {}});
}
}, {
title: 'Datenbank zurücksetzen',
onPress: async () => {
await GrowBuddyDatabaseService.resetDatabase();
}
}
]

const renderItem = ({item}: ListRenderItemInfo<any>) => {
return (
<ListItem title={item.title} description={item.description} onPress={item.onPress}/>
)
}
const ForwardIcon = (props: any) => (
<Icon {...props} name='arrow-ios-forward'/>
);

return (
<React.Fragment>
<TopNavigation title={renderTopNavigationTitle("Settings")} alignment="center"/>
<Divider/>
<Layout style={{flex: 1}}>
<List
data={settings}
renderItem={renderItem}
ItemSeparatorComponent={Divider}
/>
<Menu>
<MenuItem
title={i18n.t('BACKUPS')}
onPress={() => navigation.navigate({
name: SettingsTabRoute.SETTINGS_BACKUP_OVERVIEW,
params: {}
})}
accessoryRight={ForwardIcon}
/>
<MenuItem
title={i18n.t('DEVELOPER')}
onPress={() => navigation.navigate({
name: SettingsTabRoute.SETTINGS_DEVELOPER,
params: {}
})}
accessoryRight={ForwardIcon}
/>
</Menu>
</Layout>
<Divider/>
</React.Fragment>
Expand Down

0 comments on commit f4768f5

Please sign in to comment.