This repository was archived by the owner on Nov 12, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +58
-2
lines changed
Expand file tree Collapse file tree 4 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -27,5 +27,6 @@ export const UNSTAR_DATA_SUCCESS = 'UNSTAR_DATA_SUCCESS';
2727export const UPDATE_STAR_STATE = 'UPDATE_STAR_STATE' ;
2828
2929export const CHANGE_COLOR = 'CHANGE_COLOR' ;
30+
3031export const OPEN_SHOW_THUMBNAIL = 'OPEN_SHOW_THUMBNAIL' ;
3132export const CLOSE_SHOW_THUMBNAIL = 'CLOSE_SHOW_THUMBNAIL' ;
Original file line number Diff line number Diff line change 44'use strict' ;
55
66import * as TYPES from './actionTypes' ;
7+ import SettingsDataDAO from '../dao/SettingsDataDAO' ;
78
89export 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}
Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ import theme from '../constants/theme';
1515import px2dp from '../utils/px2dp' ;
1616import { connect } from 'react-redux' ;
1717import { store } from '../store/index' ;
18- import { fetchStarList } from '../actions/handleCollectionData'
18+ import { fetchStarList } from '../actions/handleCollectionData' ;
19+ import { initialSettingsStateFacade , getShowThumbnailValue } from '../actions/modifySettings' ;
1920
2021class 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments