-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
21 changed files
with
335 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* @author: Est <codeest.dev@gmail.com> | ||
* @date: 2017/6/5 | ||
* @description: | ||
*/ | ||
|
||
import React, {Component} from 'react' | ||
import { connect } from 'react-redux' | ||
import { | ||
Image, | ||
} from 'react-native' | ||
import realm from '../util/realm' | ||
import CustomButton from '../component/CustomButton' | ||
|
||
class DownloadButton extends Component { | ||
|
||
getLocalIcon(isLoved) { | ||
return isLoved? require('../images/ic_downloaded.png'): require('../images/ic_download.png'); | ||
} | ||
|
||
handleLocal() { | ||
if (this.props.currentSong) { | ||
if (this.props.currentSong.isLocaled) { | ||
realm.deleteLocaledSong(this.props.currentSong.id); | ||
} else { | ||
realm.insertLocaledSong(this.props.currentSong); | ||
//Download | ||
} | ||
} | ||
if (this.props.onDownload) { | ||
this.props.onDownload(); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<CustomButton onPress={() => this.handleLocal()}> | ||
<Image style={this.props.innerStyle} source={this.getLocalIcon(this.props.currentSong.isLocaled)}/> | ||
</CustomButton> | ||
) | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => { | ||
return { | ||
currentSong: state.songs.currentSong, | ||
} | ||
}; | ||
|
||
const mapDispatchToProps = (dispatch) => { | ||
return { | ||
onDownload: () => { | ||
dispatch({type: 'LOCAL'}) | ||
} | ||
} | ||
}; | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(DownloadButton) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* @author: Est <codeest.dev@gmail.com> | ||
* @date: 2017/6/5 | ||
* @description: | ||
*/ | ||
|
||
import React, {Component} from 'react' | ||
import { connect } from 'react-redux' | ||
import { | ||
Image, | ||
} from 'react-native' | ||
import realm from '../util/realm' | ||
import CustomButton from '../component/CustomButton' | ||
|
||
class LoveButton extends Component { | ||
|
||
getLoveIcon(isLoved) { | ||
return isLoved? require('../images/ic_loved.png'): require('../images/ic_love.png'); | ||
} | ||
|
||
handleLove() { | ||
if (this.props.currentSong) { | ||
if (this.props.currentSong.isLoved) { | ||
realm.deleteLovedSong(this.props.currentSong.id); | ||
} else { | ||
realm.insertLovedSong(this.props.currentSong); | ||
} | ||
} | ||
if (this.props.onLove) { | ||
this.props.onLove(); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<CustomButton onPress={() => this.handleLove()}> | ||
<Image style={this.props.innerStyle} source={this.getLoveIcon(this.props.currentSong.isLoved)}/> | ||
</CustomButton> | ||
) | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => { | ||
return { | ||
currentSong: state.songs.currentSong, | ||
} | ||
}; | ||
|
||
const mapDispatchToProps = (dispatch) => { | ||
return { | ||
onLove: () => { | ||
dispatch({type: 'LOVE'}) | ||
} | ||
} | ||
}; | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(LoveButton) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @author: Est <codeest.dev@gmail.com> | ||
* @date: 2017/6/5 | ||
* @description: | ||
*/ | ||
|
||
import Realm from 'realm'; | ||
|
||
class LovedSong extends Realm.Object {} | ||
class LocalSong extends Realm.Object {} | ||
|
||
LovedSong.schema = { | ||
name:'LovedSong', | ||
primaryKey: 'id', | ||
properties: { | ||
index: {type: 'int'}, | ||
id: {type: 'int'}, | ||
title: {type: 'string'}, | ||
date: {type: 'int'}, | ||
cover: {type: 'string'}, | ||
url: {type: 'string', optional: true}, | ||
quality: {type: 'string', optional: true}, | ||
time: {type: 'string', optional: true}, | ||
size: {type: 'int', optional: true}, | ||
isLoved: {type: 'bool'}, | ||
isLocaled: {type: 'bool'}, | ||
} | ||
}; | ||
|
||
LocalSong.schema = { | ||
name:'LocalSong', | ||
primaryKey: 'id', | ||
properties: { | ||
index: {type: 'int'}, | ||
id: {type: 'int'}, | ||
title: {type: 'string'}, | ||
date: {type: 'int'}, | ||
cover: {type: 'string'}, | ||
url: {type: 'string', optional: true}, | ||
quality: {type: 'string', optional: true}, | ||
time: {type: 'string', optional: true}, | ||
size: {type: 'int', optional: true}, | ||
isLoved: {type: 'bool'}, | ||
isLocaled: {type: 'bool'}, | ||
} | ||
}; | ||
|
||
export default new Realm({schema: [LovedSong, LocalSong]}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* @author: Est <codeest.dev@gmail.com> | ||
* @date: 2017/6/5 | ||
* @description: | ||
*/ | ||
|
||
import realm from '../model/db/Schema'; | ||
|
||
export default class Realm { | ||
|
||
static insertLovedSong(song) { | ||
console.log(song); | ||
realm.write(()=>{ | ||
realm.create('LovedSong',{ | ||
index: song.index, | ||
id: song.id, | ||
title: song.title, | ||
date: song.date, | ||
cover: song.cover, | ||
url: song.url, | ||
quality: song.quality, | ||
time: song.time, | ||
size: song.size, | ||
isLoved: song.isLoved, | ||
isLocaled: song.isLocaled | ||
}); | ||
}); | ||
} | ||
|
||
static deleteLovedSong(id) { | ||
realm.write(() => { | ||
// let target = realm.create('LovedSong', {id: id}); | ||
const target = realm.objects('LovedSong').filtered('id = ' + id); | ||
realm.delete(target); | ||
}); | ||
} | ||
|
||
static queryLovedSong(id) { | ||
const target = realm.objects('LovedSong').filtered('id = ' + id); | ||
return target !== null && target.length > 0; | ||
} | ||
|
||
static insertLocaledSong(song) { | ||
realm.write(()=>{ | ||
realm.create('LocalSong',{ | ||
index: song.index, | ||
id: song.id, | ||
title: song.title, | ||
date: song.date, | ||
cover: song.cover, | ||
url: song.url, | ||
quality: song.quality, | ||
time: song.time, | ||
size: song.size, | ||
isLoved: song.isLoved, | ||
isLocaled: song.isLocaled | ||
}); | ||
}); | ||
} | ||
|
||
static deleteLocaledSong(id) { | ||
const target = realm.objects('LocalSong').filtered('id = ' + id); | ||
realm.delete(target); | ||
} | ||
|
||
static queryLocaledSong(id) { | ||
const target = realm.objects('LocalSong').filtered('id = ' + id); | ||
return target !== null && target.length > 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters