Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit c416c88

Browse files
committed
save data for display order
1 parent fdff17f commit c416c88

File tree

6 files changed

+80
-17
lines changed

6 files changed

+80
-17
lines changed

js/actions/actionTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ export const UNSTAR_DATA_SUCCESS = 'UNSTAR_DATA_SUCCESS';
2727
export const UPDATE_STAR_STATE = 'UPDATE_STAR_STATE';
2828

2929
export const CHANGE_COLOR = 'CHANGE_COLOR';
30-
30+
export const CHANGE_DISPLAY_ORDER = 'CHANGE_DISPLAY_ORDER';
3131
export const OPEN_SHOW_THUMBNAIL = 'OPEN_SHOW_THUMBNAIL';
3232
export const CLOSE_SHOW_THUMBNAIL = 'CLOSE_SHOW_THUMBNAIL';

js/actions/modifySettings.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export function changeColor(color, flag=true) {
1212
dao.saveThemeColor(color);
1313
}
1414

15-
console.log(color);
1615
return {
1716
type: TYPES.CHANGE_COLOR,
1817
color: color
@@ -36,6 +35,18 @@ export function changeShowThumbnail(value, flag=true) {
3635
}
3736
}
3837

38+
export function changeDisplayOrder(order, flag=true) {
39+
if(flag) {
40+
let dao = new SettingsDataDAO();
41+
dao.saveDisplayOrder(order);
42+
}
43+
44+
return {
45+
type: TYPES.CHANGE_DISPLAY_ORDER,
46+
displayOrder: order
47+
};
48+
}
49+
3950
function fetchShowThumbnailValue() {
4051
return (dispatch) => {
4152
let dao = new SettingsDataDAO();
@@ -51,18 +62,28 @@ function fetchThemeColorValue() {
5162
return (dispatch) => {
5263
let dao = new SettingsDataDAO();
5364
dao.getThemeColorValue().then((result)=>{
54-
console.log('right');
5565
dispatch(changeColor(result, false));
5666
}, (error)=>{
57-
console.log('wrong');
5867
dispatch(changeColor(error));
5968
});
6069
};
6170
}
6271

72+
function fetchDisplayOrderValue() {
73+
return (dispatch) => {
74+
let dao = new SettingsDataDAO();
75+
dao.getDisplayOrderValue().then((result)=>{
76+
dispatch(changeDisplayOrder(result, false));
77+
}, (error)=>{
78+
dispatch(changeDisplayOrder(error));
79+
});
80+
};
81+
}
82+
6383
export function initialSettingsStateFacade() {
6484
return (dispatch)=>{
6585
dispatch(fetchShowThumbnailValue());
6686
dispatch(fetchThemeColorValue());
87+
dispatch(fetchDisplayOrderValue());
6788
}
6889
}

js/containers/HomeTab/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class HomeFragment extends Component{
5353
labelTime={this.props.dataTime}/>
5454
</View>
5555
<View style={styles.scrollContents}>
56-
{Info.getCategoryList(dataSource).map((item, i) => {
56+
{this.props.displayOrder.map((item, i) => {
5757
if(item !== '福利' && Info.getTargetList(dataSource, item) != null)
5858
return(
5959
<ListViewForHome
@@ -187,7 +187,8 @@ const mapStateToProps = (state) => {
187187
hasData: state.homeData.hasData,
188188
dataSource: state.homeData.dataSource,
189189
dataTime: state.homeData.dataTime,
190-
mainThemeColor: state.settingState.mainThemeColor
190+
mainThemeColor: state.settingState.mainThemeColor,
191+
displayOrder: state.settingState.displayOrder
191192
};
192193
};
193194

js/containers/MoreTab/OrderContentPage.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,34 @@ import BackPageComponent from '../BackPageComponent';
1010
import NavigationBar from '../../components/NavigationBar';
1111
import px2dp from '../../utils/px2dp';
1212
import theme from '../../constants/theme';
13+
import {changeDisplayOrder} from '../../actions/modifySettings';
14+
import {connect} from 'react-redux';
15+
import {store} from '../../store/index';
1316

14-
export default class OrderContentPage extends BackPageComponent{
17+
class OrderContentPage extends BackPageComponent{
1518
constructor(props){
1619
super(props);
17-
this.names = ['Android','iOS','前端','拓展资源','休息视频','App'];
1820
this.items = [];
1921
this.order = [];
2022
}
2123

24+
_okBtnPressCallback(){
25+
store.dispatch(changeDisplayOrder(this.order));
26+
this.order = [];
27+
this._handleBack();
28+
}
29+
2230
render(){
2331
return(
2432
<View style={styles.container}>
2533
<NavigationBar
2634
title="首页内容展示顺序"
27-
leftBtnIcon="arrow-back"
35+
leftBtnText="取消"
2836
leftBtnPress={this._handleBack.bind(this)}
37+
rightBtnText="确定"
38+
rightBtnPress={this._okBtnPressCallback.bind(this)}
2939
/>
30-
{this.names.map((item, i)=>{
40+
{this.props.displayOrder.map((item, i)=>{
3141
this.order.push(item);
3242
return (
3343
<View
@@ -129,11 +139,7 @@ export default class OrderContentPage extends BackPageComponent{
129139

130140
_getTopValueYById(id){
131141
const height = px2dp(49);
132-
return (id + 1) * height + ((Platform.OS === 'android') ? px2dp(20) : px2dp(7));
133-
}
134-
135-
_storeOrder(){
136-
142+
return (id + 1) * height + ((Platform.OS === 'android') ? px2dp(18) : px2dp(7));
137143
}
138144
}
139145

@@ -159,4 +165,12 @@ const styles = StyleSheet.create({
159165
color: '#000',
160166
marginLeft: px2dp(20)
161167
}
162-
});
168+
});
169+
170+
const mapStateToProps = (state) => {
171+
return {
172+
displayOrder: state.settingState.displayOrder
173+
}
174+
}
175+
176+
export default connect(mapStateToProps)(OrderContentPage);

js/dao/SettingsDataDAO.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
const SHOW_THUMBNAIL = 'showThumbnail';
77
const THEME_COLOR = 'themeColor';
8+
const DISPLAY_ORDER = 'displayOrder';
89

910
import {AsyncStorage} from 'react-native';
1011

@@ -45,4 +46,23 @@ export default class SettingsDataDAO{
4546
});
4647
}
4748

49+
saveDisplayOrder(order){
50+
AsyncStorage.setItem(DISPLAY_ORDER, JSON.stringify({order: order}));
51+
}
52+
53+
getDisplayOrderValue(){
54+
return new Promise((resolve, reject) => {
55+
AsyncStorage.getItem(DISPLAY_ORDER, (error, result) => {
56+
if(!error){
57+
const data = JSON.parse(result);
58+
if(data)
59+
resolve(data.order);
60+
else
61+
reject(['Android','iOS','前端','拓展资源','休息视频','App']);
62+
}else
63+
reject(['Android','iOS','前端','拓展资源','休息视频','App']);
64+
});
65+
});
66+
}
67+
4868
}

js/reducers/settingState.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import * as TYPES from '../actions/actionTypes';
88

99
const initialState = {
1010
mainThemeColor: colors.dodgerBlue,
11-
isOpenThumbnail: false
11+
isOpenThumbnail: false,
12+
displayOrder: ['Android','iOS','前端','拓展资源','休息视频','App']
1213
}
1314

1415
export default function settingState(state=initialState, action) {
@@ -31,6 +32,12 @@ export default function settingState(state=initialState, action) {
3132
isOpenThumbnail: false
3233
});
3334

35+
case TYPES.CHANGE_DISPLAY_ORDER:
36+
return Object.assign({}, state, {
37+
...state,
38+
displayOrder: action.displayOrder
39+
});
40+
3441
default:
3542
return state;
3643
}

0 commit comments

Comments
 (0)