diff --git a/ReactNativeClient/lib/components/item-list.js b/ReactNativeClient/lib/components/item-list.js index 2438ebce7..ddf72501d 100644 --- a/ReactNativeClient/lib/components/item-list.js +++ b/ReactNativeClient/lib/components/item-list.js @@ -7,6 +7,7 @@ import { Checkbox } from 'lib/components/checkbox.js'; import { NoteItem } from 'lib/components/note-item.js'; import { reg } from 'lib/registry.js'; import { Note } from 'lib/models/note.js'; +import { Setting } from 'lib/models/setting.js'; import { time } from 'lib/time-utils.js'; import { globalStyle } from 'lib/components/global-style.js'; @@ -33,15 +34,35 @@ class ItemListComponent extends Component { }; } + filterNotes(notes) { + const todoFilter = Setting.value('todoFilter'); + if (todoFilter == 'all') return notes; + + const now = time.unixMs(); + const maxInterval = 1000 * 60 * 60 * 24 * 2; + const notRecentTime = now - maxInterval; + + let output = []; + for (let i = 0; i < notes.length; i++) { + const note = notes[i]; + if (note.is_todo) { + if (todoFilter == 'recent' && note.updated_time < notRecentTime) continue; + if (todoFilter == 'nonCompleted' && !!note.todo_completed) continue; + } + output.push(note); + } + return output; + } + componentWillMount() { - const newDataSource = this.state.dataSource.cloneWithRows(this.props.items); + const newDataSource = this.state.dataSource.cloneWithRows(this.filterNotes(this.props.items)); this.state = { dataSource: newDataSource }; } componentWillReceiveProps(newProps) { // https://stackoverflow.com/questions/38186114/react-native-redux-and-listview this.setState({ - dataSource: this.state.dataSource.cloneWithRows(newProps.items), + dataSource: this.state.dataSource.cloneWithRows(this.filterNotes(newProps.items)), }); } @@ -49,7 +70,6 @@ class ItemListComponent extends Component { let note = await Note.load(itemId); await Note.save({ id: note.id, todo_completed: checked ? time.unixMs() : 0 }); reg.scheduleSync(); - } listView_itemLongPress(itemId) {} diff --git a/ReactNativeClient/lib/components/note-item.js b/ReactNativeClient/lib/components/note-item.js index 6961448d0..dabae2987 100644 --- a/ReactNativeClient/lib/components/note-item.js +++ b/ReactNativeClient/lib/components/note-item.js @@ -9,7 +9,7 @@ import { Note } from 'lib/models/note.js'; import { time } from 'lib/time-utils.js'; import { globalStyle } from 'lib/components/global-style.js'; -const styleObject = { +let styles = { listItem: { flexDirection: 'row', height: 40, @@ -24,7 +24,10 @@ const styleObject = { }, }; -const styles = StyleSheet.create(styleObject); +styles.listItemFadded = Object.assign({}, styles.listItem); +styles.listItemFadded.opacity = 0.4; + +styles = StyleSheet.create(styles); class NoteItemComponent extends Component { @@ -45,9 +48,11 @@ class NoteItemComponent extends Component { const checkboxStyle = !Number(note.is_todo) ? { display: 'none' } : { color: globalStyle.color }; const checkboxChecked = !!Number(note.todo_completed); + const listItemStyle = !!Number(note.is_todo) && checkboxChecked ? styles.listItemFadded : styles.listItem; + return ( onPress ? onPress(note) : this.noteItem_press(note.id)} onLongPress={() => onLongPress(note)} underlayColor="#0066FF"> - + { onCheckboxChange(note, checked) }}/>{note.title} diff --git a/ReactNativeClient/lib/components/screen-header.js b/ReactNativeClient/lib/components/screen-header.js index d12abb744..d15efb6c7 100644 --- a/ReactNativeClient/lib/components/screen-header.js +++ b/ReactNativeClient/lib/components/screen-header.js @@ -144,6 +144,13 @@ class ScreenHeaderComponent extends Component { }); } + config_press() { + this.props.dispatch({ + type: 'Navigation/NAVIGATE', + routeName: 'Config', + }); + } + render() { function sideMenuButton(styles, onPress) { @@ -213,6 +220,15 @@ class ScreenHeaderComponent extends Component { {_('Status')} ); + if (menuOptionComponents.length) { + menuOptionComponents.push(); + } + + menuOptionComponents.push( + this.config_press()} key={'menuOption_' + key++} style={styles.contextMenuItem}> + {_('Configuration')} + ); + const createTitleComponent = () => { const p = this.props.titlePicker; if (p) { diff --git a/ReactNativeClient/lib/components/screens/config.js b/ReactNativeClient/lib/components/screens/config.js new file mode 100644 index 000000000..f6eb1c84d --- /dev/null +++ b/ReactNativeClient/lib/components/screens/config.js @@ -0,0 +1,114 @@ +import React, { Component } from 'react'; +import { View, StyleSheet, Picker, Text, Button } from 'react-native'; +import { connect } from 'react-redux' +import { ScreenHeader } from 'lib/components/screen-header.js'; +import { _ } from 'lib/locale.js'; +import { BaseScreenComponent } from 'lib/components/base-screen.js'; +import { globalStyle } from 'lib/components/global-style.js'; +import { Setting } from 'lib/models/setting.js'; + +let styles = { + body: {} +} + +styles = StyleSheet.create(styles); + +class ConfigScreenComponent extends BaseScreenComponent { + + static navigationOptions(options) { + return { header: null }; + } + + constructor() { + super(); + this.state = { + values: {}, + }; + } + + componentWillMount() { + const settings = Setting.publicSettings(Setting.value('appType')); + + let values = {}; + for (let key in settings) { + if (!settings.hasOwnProperty(key)) continue; + values[key] = settings[key].value; + } + + this.setState({ values: values }); + } + + settingToComponent(key, setting) { + let output = null; + + const updateSettingValue = (key, value) => { + let values = this.state.values; + values[key] = value; + this.setState({ values: values }); + } + + const value = this.state.values[key]; + + if (setting.type == 'enum') { + let items = []; + const settingOptions = setting.options(); + for (let k in settingOptions) { + if (!settingOptions.hasOwnProperty(k)) continue; + items.push(); + } + + return ( + + {setting.label()} + updateSettingValue(key, itemValue)} > + { items } + + + ); + } else { + //throw new Error('Unsupported setting type: ' + setting.type); + } + + return output; + } + + saveButton_press() { + const values = this.state.values; + for (let key in values) { + if (!values.hasOwnProperty(key)) continue; + Setting.setValue(key, values[key]); + } + Setting.saveAll(); + } + + render() { + const settings = Setting.publicSettings(Setting.value('appType')); + + let settingComps = []; + for (let key in settings) { + if (!settings.hasOwnProperty(key)) continue; + const comp = this.settingToComponent(key, settings[key]); + if (!comp) continue; + settingComps.push(comp); + } + + return ( + + + + { settingComps } + +