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

Commit 0e01a56

Browse files
committed
settingState for open thumbnail
1 parent d5580cc commit 0e01a56

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

js/actions/actionTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +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+
3031
export const OPEN_SHOW_THUMBNAIL = 'OPEN_SHOW_THUMBNAIL';
3132
export const CLOSE_SHOW_THUMBNAIL = 'CLOSE_SHOW_THUMBNAIL';

js/actions/modifySettings.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
'use strict';
55

66
import * as TYPES from './actionTypes';
7+
import SettingsDataDAO from '../dao/SettingsDataDAO';
78

89
export function changeColor(color) {
910
return {
@@ -12,7 +13,12 @@ export function changeColor(color) {
1213
};
1314
}
1415

15-
export function changeShowThumbnail(value) {
16+
export function changeShowThumbnail(value, flag=true) {
17+
if(flag) {
18+
let dao = new SettingsDataDAO();
19+
dao.saveShowThumbnail(value);
20+
}
21+
1622
if(value) {
1723
return {
1824
type: TYPES.OPEN_SHOW_THUMBNAIL
@@ -22,4 +28,21 @@ export function changeShowThumbnail(value) {
2228
type: TYPES.CLOSE_SHOW_THUMBNAIL
2329
};
2430
}
31+
}
32+
33+
function getShowThumbnailValue() {
34+
return (dispatch) => {
35+
let dao = new SettingsDataDAO();
36+
dao.getShowThumbnailValue().then((result)=>{
37+
dispatch(changeShowThumbnail(result, false));
38+
}, (error)=>{
39+
dispatch(changeShowThumbnail(error));
40+
});
41+
};
42+
}
43+
44+
export function initialSettingsStateFacade() {
45+
return (dispatch)=>{
46+
dispatch(getShowThumbnailValue());
47+
}
2548
}

js/containers/MainPage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import theme from '../constants/theme';
1515
import px2dp from '../utils/px2dp';
1616
import {connect} from 'react-redux';
1717
import {store} from '../store/index';
18-
import {fetchStarList} from '../actions/handleCollectionData'
18+
import {fetchStarList} from '../actions/handleCollectionData';
19+
import {initialSettingsStateFacade, getShowThumbnailValue} from '../actions/modifySettings';
1920

2021
class MainPage extends Component{
2122

@@ -90,6 +91,7 @@ class BottomTabBar extends Component{
9091

9192
componentDidMount(){
9293
store.dispatch(fetchStarList());
94+
store.dispatch(initialSettingsStateFacade());
9395
}
9496
}
9597

js/dao/SettingsDataDAO.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
11
/**
22
* Created by wangdi on 4/12/16.
33
*/
4+
'use strict';
5+
6+
const SHOW_THUMBNAIL = 'showThumbnail';
7+
8+
9+
import {AsyncStorage} from 'react-native';
10+
11+
export default class SettingsDataDAO{
12+
13+
saveShowThumbnail(value){
14+
AsyncStorage.setItem(SHOW_THUMBNAIL, value+'');
15+
}
16+
17+
getShowThumbnailValue() {
18+
return new Promise((resolve, reject) => {
19+
AsyncStorage.getItem(SHOW_THUMBNAIL, (error, result) => {
20+
if(!error){
21+
if(result === 'true')
22+
resolve(true);
23+
else
24+
resolve(false);
25+
}else{
26+
reject(true);
27+
}
28+
});
29+
});
30+
}
31+
32+
33+
}

0 commit comments

Comments
 (0)