2017-11-03 02:09:34 +02:00
|
|
|
const React = require('react'); const Component = React.Component;
|
|
|
|
const { connect } = require('react-redux');
|
2017-11-19 02:03:42 +02:00
|
|
|
const { Platform, View, Text, Button, StyleSheet, TouchableOpacity, Image } = require('react-native');
|
2017-11-03 02:09:34 +02:00
|
|
|
const Icon = require('react-native-vector-icons/Ionicons').default;
|
|
|
|
const { Log } = require('lib/log.js');
|
|
|
|
const { BackButtonService } = require('lib/services/back-button.js');
|
2017-11-21 20:48:50 +02:00
|
|
|
const { ReportService } = require('lib/services/report.js');
|
2017-11-03 02:09:34 +02:00
|
|
|
const { Menu, MenuOptions, MenuOption, MenuTrigger } = require('react-native-popup-menu');
|
|
|
|
const { _ } = require('lib/locale.js');
|
|
|
|
const { Setting } = require('lib/models/setting.js');
|
|
|
|
const { FileApi } = require('lib/file-api.js');
|
|
|
|
const { FileApiDriverOneDrive } = require('lib/file-api-driver-onedrive.js');
|
|
|
|
const { reg } = require('lib/registry.js');
|
|
|
|
const { themeStyle } = require('lib/components/global-style.js');
|
2017-11-19 01:59:07 +02:00
|
|
|
const { ItemList } = require('lib/components/ItemList.js');
|
|
|
|
const { Dropdown } = require('lib/components/Dropdown.js');
|
2017-11-21 20:48:50 +02:00
|
|
|
const { time } = require('lib/time-utils');
|
|
|
|
const RNFS = require('react-native-fs');
|
2017-05-16 21:57:09 +02:00
|
|
|
|
2017-07-31 20:19:58 +02:00
|
|
|
// Rather than applying a padding to the whole bar, it is applied to each
|
|
|
|
// individual component (button, picker, etc.) so that the touchable areas
|
|
|
|
// are widder and to give more room to the picker component which has a larger
|
|
|
|
// default height.
|
|
|
|
const PADDING_V = 10;
|
|
|
|
|
2017-08-01 19:59:01 +02:00
|
|
|
class ScreenHeaderComponent extends Component {
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.styles_ = {};
|
2017-07-21 23:40:02 +02:00
|
|
|
}
|
2017-07-16 01:30:54 +02:00
|
|
|
|
2017-08-01 19:59:01 +02:00
|
|
|
styles() {
|
|
|
|
const themeId = Setting.value('theme');
|
|
|
|
if (this.styles_[themeId]) return this.styles_[themeId];
|
|
|
|
this.styles_ = {};
|
|
|
|
|
|
|
|
const theme = themeStyle(themeId);
|
|
|
|
|
|
|
|
let styleObject = {
|
|
|
|
container: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
backgroundColor: theme.raisedBackgroundColor,
|
|
|
|
alignItems: 'center',
|
|
|
|
shadowColor: '#000000',
|
|
|
|
elevation: 5,
|
2017-11-19 17:19:36 +02:00
|
|
|
paddingTop: Platform.OS === 'ios' ? 15 : 0, // Extra padding for iOS because the top icons are there
|
2017-08-01 19:59:01 +02:00
|
|
|
},
|
|
|
|
divider: {
|
|
|
|
borderBottomWidth: 1,
|
|
|
|
borderColor: theme.dividerColor,
|
|
|
|
backgroundColor: "#0000ff"
|
|
|
|
},
|
|
|
|
sideMenuButton: {
|
|
|
|
flex: 1,
|
|
|
|
alignItems: 'center',
|
|
|
|
backgroundColor: theme.raisedBackgroundColor,
|
|
|
|
paddingLeft: theme.marginLeft,
|
|
|
|
paddingRight: 5,
|
|
|
|
marginRight: 2,
|
|
|
|
paddingTop: PADDING_V,
|
|
|
|
paddingBottom: PADDING_V,
|
|
|
|
},
|
|
|
|
iconButton: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: theme.raisedBackgroundColor,
|
|
|
|
paddingLeft: 15,
|
|
|
|
paddingRight: 15,
|
|
|
|
paddingTop: PADDING_V,
|
|
|
|
paddingBottom: PADDING_V,
|
|
|
|
},
|
|
|
|
saveButton: {
|
|
|
|
flex: 0,
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
padding: 10,
|
|
|
|
borderWidth: 1,
|
|
|
|
borderColor: theme.raisedHighlightedColor,
|
|
|
|
borderRadius: 4,
|
|
|
|
marginRight: 8,
|
|
|
|
},
|
|
|
|
saveButtonText: {
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
color: theme.raisedHighlightedColor,
|
|
|
|
fontWeight: 'bold',
|
|
|
|
},
|
|
|
|
savedButtonIcon: {
|
|
|
|
fontSize: 20,
|
|
|
|
color: theme.raisedHighlightedColor,
|
|
|
|
width: 18,
|
|
|
|
height: 18,
|
|
|
|
},
|
|
|
|
saveButtonIcon: {
|
|
|
|
width: 18,
|
|
|
|
height: 18,
|
|
|
|
},
|
|
|
|
contextMenuTrigger: {
|
|
|
|
fontSize: 25,
|
|
|
|
paddingRight: theme.marginRight,
|
|
|
|
color: theme.raisedColor,
|
|
|
|
fontWeight: 'bold',
|
|
|
|
},
|
|
|
|
contextMenu: {
|
|
|
|
backgroundColor: theme.raisedBackgroundColor,
|
|
|
|
},
|
|
|
|
contextMenuItem: {
|
|
|
|
backgroundColor: theme.backgroundColor,
|
|
|
|
},
|
|
|
|
contextMenuItemText: {
|
|
|
|
flex: 1,
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
paddingLeft: theme.marginLeft,
|
|
|
|
paddingRight: theme.marginRight,
|
|
|
|
paddingTop: theme.itemMarginTop,
|
|
|
|
paddingBottom: theme.itemMarginBottom,
|
|
|
|
color: theme.color,
|
|
|
|
backgroundColor: theme.backgroundColor,
|
|
|
|
fontSize: theme.fontSize,
|
|
|
|
},
|
|
|
|
titleText: {
|
|
|
|
flex: 1,
|
|
|
|
marginLeft: 0,
|
|
|
|
color: theme.raisedHighlightedColor,
|
|
|
|
fontWeight: 'bold',
|
|
|
|
fontSize: theme.fontSize,
|
|
|
|
}
|
|
|
|
};
|
2017-07-22 18:36:55 +02:00
|
|
|
|
2017-08-01 19:59:01 +02:00
|
|
|
styleObject.topIcon = Object.assign({}, theme.icon);
|
|
|
|
styleObject.topIcon.flex = 1;
|
|
|
|
styleObject.topIcon.textAlignVertical = 'center';
|
|
|
|
styleObject.topIcon.color = theme.raisedColor;
|
2017-07-23 00:52:24 +02:00
|
|
|
|
2017-08-01 19:59:01 +02:00
|
|
|
styleObject.backButton = Object.assign({}, styleObject.iconButton);
|
|
|
|
styleObject.backButton.marginRight = 1;
|
2017-07-16 01:30:54 +02:00
|
|
|
|
2017-08-01 19:59:01 +02:00
|
|
|
styleObject.backButtonDisabled = Object.assign({}, styleObject.backButton, { opacity: theme.disabledOpacity });
|
|
|
|
styleObject.saveButtonDisabled = Object.assign({}, styleObject.saveButton, { opacity: theme.disabledOpacity });
|
2017-05-16 22:25:19 +02:00
|
|
|
|
2017-08-01 19:59:01 +02:00
|
|
|
this.styles_[themeId] = StyleSheet.create(styleObject);
|
|
|
|
return this.styles_[themeId];
|
|
|
|
}
|
2017-05-16 21:57:09 +02:00
|
|
|
|
2017-06-06 22:01:43 +02:00
|
|
|
sideMenuButton_press() {
|
2017-05-24 21:27:13 +02:00
|
|
|
this.props.dispatch({ type: 'SIDE_MENU_TOGGLE' });
|
|
|
|
}
|
|
|
|
|
2017-08-24 20:10:03 +02:00
|
|
|
async backButton_press() {
|
|
|
|
await BackButtonService.back();
|
|
|
|
//this.props.dispatch({ type: 'NAV_BACK' });
|
2017-05-16 21:57:09 +02:00
|
|
|
}
|
|
|
|
|
2017-07-23 00:52:24 +02:00
|
|
|
searchButton_press() {
|
|
|
|
this.props.dispatch({
|
2017-07-25 20:41:53 +02:00
|
|
|
type: 'NAV_GO',
|
2017-07-23 00:52:24 +02:00
|
|
|
routeName: 'Search',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-06 22:01:43 +02:00
|
|
|
menu_select(value) {
|
2017-05-16 22:25:19 +02:00
|
|
|
if (typeof(value) == 'function') {
|
|
|
|
value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-07 19:19:24 +02:00
|
|
|
log_press() {
|
|
|
|
this.props.dispatch({
|
2017-07-25 20:41:53 +02:00
|
|
|
type: 'NAV_GO',
|
2017-07-07 19:19:24 +02:00
|
|
|
routeName: 'Log',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-10 21:16:59 +02:00
|
|
|
status_press() {
|
|
|
|
this.props.dispatch({
|
2017-07-25 20:41:53 +02:00
|
|
|
type: 'NAV_GO',
|
2017-07-10 21:16:59 +02:00
|
|
|
routeName: 'Status',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-23 20:26:50 +02:00
|
|
|
config_press() {
|
|
|
|
this.props.dispatch({
|
2017-07-25 20:41:53 +02:00
|
|
|
type: 'NAV_GO',
|
2017-07-23 20:26:50 +02:00
|
|
|
routeName: 'Config',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-21 20:48:50 +02:00
|
|
|
async debugReport_press() {
|
|
|
|
const service = new ReportService();
|
|
|
|
|
|
|
|
const logItems = await reg.logger().lastEntries(null);
|
|
|
|
const logItemRows = [
|
|
|
|
['Date','Level','Message']
|
|
|
|
];
|
|
|
|
for (let i = 0; i < logItems.length; i++) {
|
|
|
|
const item = logItems[i];
|
|
|
|
logItemRows.push([
|
|
|
|
time.formatMsToLocal(item.timestamp, 'MM-DDTHH:mm:ss'),
|
|
|
|
item.level,
|
|
|
|
item.message
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
const logItemCsv = service.csvCreate(logItemRows);
|
|
|
|
|
|
|
|
const itemListCsv = await service.basicItemList({ format: 'csv' });
|
|
|
|
const filePath = RNFS.ExternalDirectoryPath + '/syncReport-' + (new Date()).getTime() + '.txt';
|
|
|
|
|
|
|
|
const finalText = [logItemCsv, itemListCsv].join("\n--------------------------------------------------------------------------------");
|
|
|
|
|
|
|
|
await RNFS.writeFile(filePath, finalText);
|
|
|
|
alert('Debug report exported to ' + filePath);
|
|
|
|
}
|
|
|
|
|
2017-05-16 21:57:09 +02:00
|
|
|
render() {
|
2017-07-16 01:30:54 +02:00
|
|
|
|
|
|
|
function sideMenuButton(styles, onPress) {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={onPress}>
|
|
|
|
<View style={styles.sideMenuButton}>
|
2017-08-01 19:59:01 +02:00
|
|
|
<Icon name='md-menu' style={styles.topIcon} />
|
2017-07-16 01:30:54 +02:00
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function backButton(styles, onPress, disabled) {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={onPress} disabled={disabled}>
|
|
|
|
<View style={disabled ? styles.backButtonDisabled : styles.backButton}>
|
2017-07-22 18:36:55 +02:00
|
|
|
<Icon name='md-arrow-back' style={styles.topIcon} />
|
2017-07-16 01:30:54 +02:00
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-07-16 12:17:40 +02:00
|
|
|
function saveButton(styles, onPress, disabled, show) {
|
|
|
|
if (!show) return null;
|
|
|
|
|
2017-07-31 20:19:58 +02:00
|
|
|
const icon = disabled ? <Icon name='md-checkmark' style={styles.savedButtonIcon} /> : <Image style={styles.saveButtonIcon} source={require('./SaveIcon.png')} />;
|
2017-07-30 23:33:54 +02:00
|
|
|
|
2017-07-16 12:17:40 +02:00
|
|
|
return (
|
2017-07-31 20:19:58 +02:00
|
|
|
<TouchableOpacity onPress={onPress} disabled={disabled} style={{ padding:0 }}>
|
2017-07-16 12:17:40 +02:00
|
|
|
<View style={disabled ? styles.saveButtonDisabled : styles.saveButton}>
|
2017-07-31 20:19:58 +02:00
|
|
|
{ icon }
|
2017-07-16 12:17:40 +02:00
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-07-23 00:52:24 +02:00
|
|
|
function searchButton(styles, onPress) {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={onPress}>
|
|
|
|
<View style={styles.iconButton}>
|
|
|
|
<Icon name='md-search' style={styles.topIcon} />
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-05-16 23:46:21 +02:00
|
|
|
let key = 0;
|
2017-05-16 22:25:19 +02:00
|
|
|
let menuOptionComponents = [];
|
|
|
|
for (let i = 0; i < this.props.menuOptions.length; i++) {
|
|
|
|
let o = this.props.menuOptions[i];
|
|
|
|
menuOptionComponents.push(
|
2017-08-01 19:59:01 +02:00
|
|
|
<MenuOption value={o.onPress} key={'menuOption_' + key++} style={this.styles().contextMenuItem}>
|
|
|
|
<Text style={this.styles().contextMenuItemText}>{o.title}</Text>
|
2017-05-16 23:46:21 +02:00
|
|
|
</MenuOption>);
|
|
|
|
}
|
|
|
|
|
2017-09-24 16:48:23 +02:00
|
|
|
if (this.props.showAdvancedOptions) {
|
|
|
|
if (menuOptionComponents.length) {
|
|
|
|
menuOptionComponents.push(<View key={'menuOption_' + key++} style={this.styles().divider}/>);
|
|
|
|
}
|
2017-05-16 22:25:19 +02:00
|
|
|
|
2017-09-24 16:48:23 +02:00
|
|
|
menuOptionComponents.push(
|
2017-11-21 20:48:50 +02:00
|
|
|
<MenuOption value={() => this.log_press()} key={'menuOption_log'} style={this.styles().contextMenuItem}>
|
2017-09-24 16:48:23 +02:00
|
|
|
<Text style={this.styles().contextMenuItemText}>{_('Log')}</Text>
|
|
|
|
</MenuOption>);
|
2017-05-16 23:46:21 +02:00
|
|
|
|
2017-09-24 16:48:23 +02:00
|
|
|
menuOptionComponents.push(
|
2017-11-21 20:48:50 +02:00
|
|
|
<MenuOption value={() => this.status_press()} key={'menuOption_status'} style={this.styles().contextMenuItem}>
|
2017-09-24 16:48:23 +02:00
|
|
|
<Text style={this.styles().contextMenuItemText}>{_('Status')}</Text>
|
|
|
|
</MenuOption>);
|
2017-11-21 20:48:50 +02:00
|
|
|
|
|
|
|
if (Platform.OS === 'android') {
|
|
|
|
menuOptionComponents.push(
|
|
|
|
<MenuOption value={() => this.debugReport_press()} key={'menuOption_debugReport'} style={this.styles().contextMenuItem}>
|
|
|
|
<Text style={this.styles().contextMenuItemText}>{_('Export Debug Report')}</Text>
|
|
|
|
</MenuOption>);
|
|
|
|
}
|
2017-09-24 16:48:23 +02:00
|
|
|
}
|
2017-07-10 21:16:59 +02:00
|
|
|
|
2017-07-23 20:26:50 +02:00
|
|
|
if (menuOptionComponents.length) {
|
2017-08-01 19:59:01 +02:00
|
|
|
menuOptionComponents.push(<View key={'menuOption_' + key++} style={this.styles().divider}/>);
|
2017-07-23 20:26:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
menuOptionComponents.push(
|
2017-08-01 19:59:01 +02:00
|
|
|
<MenuOption value={() => this.config_press()} key={'menuOption_' + key++} style={this.styles().contextMenuItem}>
|
|
|
|
<Text style={this.styles().contextMenuItemText}>{_('Configuration')}</Text>
|
2017-07-23 20:26:50 +02:00
|
|
|
</MenuOption>);
|
|
|
|
|
2017-07-16 18:06:05 +02:00
|
|
|
const createTitleComponent = () => {
|
2017-11-19 01:59:07 +02:00
|
|
|
const themeId = Setting.value('theme');
|
|
|
|
const theme = themeStyle(themeId);
|
|
|
|
|
2017-07-16 18:06:05 +02:00
|
|
|
const p = this.props.titlePicker;
|
|
|
|
if (p) {
|
|
|
|
return (
|
2017-11-19 01:59:07 +02:00
|
|
|
<Dropdown
|
|
|
|
items={p.items}
|
|
|
|
itemHeight={35}
|
|
|
|
selectedValue={p.selectedValue}
|
|
|
|
itemListStyle={{
|
|
|
|
backgroundColor: theme.backgroundColor,
|
|
|
|
}}
|
|
|
|
headerStyle={{
|
2017-11-19 02:23:18 +02:00
|
|
|
color: theme.raisedHighlightedColor,
|
2017-11-19 01:59:07 +02:00
|
|
|
fontSize: theme.fontSize,
|
|
|
|
}}
|
|
|
|
itemStyle={{
|
|
|
|
color: theme.color,
|
|
|
|
fontSize: theme.fontSize,
|
|
|
|
}}
|
|
|
|
onValueChange={(itemValue, itemIndex) => { if (p.onValueChange) p.onValueChange(itemValue, itemIndex); }}
|
|
|
|
/>
|
2017-07-16 18:06:05 +02:00
|
|
|
);
|
|
|
|
} else {
|
2017-07-24 23:52:30 +02:00
|
|
|
let title = 'title' in this.props && this.props.title !== null ? this.props.title : '';
|
2017-08-01 19:59:01 +02:00
|
|
|
return <Text style={this.styles().titleText}>{title}</Text>
|
2017-07-16 18:06:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const titleComp = createTitleComponent();
|
2017-05-16 22:25:19 +02:00
|
|
|
|
2017-05-16 21:57:09 +02:00
|
|
|
return (
|
2017-08-01 19:59:01 +02:00
|
|
|
<View style={this.styles().container} >
|
|
|
|
{ sideMenuButton(this.styles(), () => this.sideMenuButton_press()) }
|
|
|
|
{ backButton(this.styles(), () => this.backButton_press(), !this.props.historyCanGoBack) }
|
|
|
|
{ saveButton(this.styles(), () => { if (this.props.onSaveButtonPress) this.props.onSaveButtonPress() }, this.props.saveButtonDisabled === true, this.props.showSaveButton === true) }
|
2017-07-23 00:52:24 +02:00
|
|
|
{ titleComp }
|
2017-08-01 19:59:01 +02:00
|
|
|
{ searchButton(this.styles(), () => this.searchButton_press()) }
|
2017-11-19 01:59:07 +02:00
|
|
|
<Menu onSelect={(value) => this.menu_select(value)} style={this.styles().contextMenu}>
|
2017-07-31 20:19:58 +02:00
|
|
|
<MenuTrigger style={{ paddingTop: PADDING_V, paddingBottom: PADDING_V }}>
|
2017-08-01 19:59:01 +02:00
|
|
|
<Text style={this.styles().contextMenuTrigger}> ⋮</Text>
|
2017-05-16 22:25:19 +02:00
|
|
|
</MenuTrigger>
|
|
|
|
<MenuOptions>
|
|
|
|
{ menuOptionComponents }
|
|
|
|
</MenuOptions>
|
|
|
|
</Menu>
|
2017-05-16 21:57:09 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-06-11 23:11:14 +02:00
|
|
|
ScreenHeaderComponent.defaultProps = {
|
|
|
|
menuOptions: [],
|
|
|
|
};
|
|
|
|
|
2017-05-16 21:57:09 +02:00
|
|
|
const ScreenHeader = connect(
|
2017-07-09 01:57:30 +02:00
|
|
|
(state) => {
|
|
|
|
return {
|
|
|
|
historyCanGoBack: state.historyCanGoBack,
|
2017-07-26 19:49:01 +02:00
|
|
|
locale: state.settings.locale,
|
2017-08-01 19:59:01 +02:00
|
|
|
theme: state.settings.theme,
|
2017-09-24 16:48:23 +02:00
|
|
|
showAdvancedOptions: state.settings.showAdvancedOptions,
|
2017-07-09 01:57:30 +02:00
|
|
|
};
|
|
|
|
}
|
2017-05-16 21:57:09 +02:00
|
|
|
)(ScreenHeaderComponent)
|
|
|
|
|
2017-11-03 02:13:17 +02:00
|
|
|
module.exports = { ScreenHeader };
|