Skip to content

Commit

Permalink
Merge pull request #12 from TriPSs/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
TriPSs authored Oct 13, 2018
2 parents bd233c9 + f5b2a7b commit 5637b15
Show file tree
Hide file tree
Showing 29 changed files with 495 additions and 122 deletions.
Binary file added .github/home-bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/movies.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/my-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/show.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/shows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ Please see the [contributing guide](https://github.com/tripss/popcorn-native/blo

## Screenshots

Home Screen | Movies Screen
Home Screen | Home Screen
:-------------------------:|:-------------------------:
![Home Screen](./.github/home.png) | ![Movies Screen](./.github/movies.png)
![Home Screen](./.github/home.png) | ![Home Screen](./.github/home-bottom.png)

My List Screen | Movies Screen
:-------------------------:|:-------------------------:
![My List Screen](./.github/my-list.png) |![Show Screen](./.github/movies.png)

Shows Screen | Show Screen
:-------------------------:|:-------------------------:
Expand Down
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ android {
applicationId "com.popcorn"
minSdkVersion 16
targetSdkVersion 26
versionCode 9
versionName "v0.6.3"
versionCode 10
versionName "v0.7.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
Expand Down
81 changes: 52 additions & 29 deletions app/components/Card/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const styles = StyleSheet.create({

root: {
height : 190,
width : 120,
width : 121,
marginLeft : 8,
marginRight: 8,
alignSelf : 'stretch',
Expand All @@ -24,33 +24,56 @@ const styles = StyleSheet.create({

})

export const Card = ({ item, empty, ...rest }) => (
<BaseButton
// onLongPress={() => console.warn(item.title)}
// onPress={() => this.openItem(item)}
{...rest}>
<View style={styles.root}>
<Image
style={styles.image}
defaultSource={posterHolder}
source={
!empty
? { uri: item.images.poster.thumb }
: posterHolder
}
/>
</View>
</BaseButton>
)

Card.propTypes = {
item : PropTypes.object,
empty: PropTypes.bool,
}
export default class Card extends React.Component {

Card.defaultProps = {
item : null,
empty: false,
}
static propTypes = {
item : PropTypes.object,
empty: PropTypes.bool,
}

static defaultProps = {
item : null,
empty: false,
}

constructor(props) {
super(props)

const { item, empty } = props

export default Card
this.state = {
showPlaceholder: empty || !item.images.poster.thumb,
}
}

handleImageError = () => {
this.setState({
showPlaceholder: true,
})
}

render() {
const { item, empty, ...rest } = this.props
const { showPlaceholder } = this.state

return (
<BaseButton
// onLongPress={() => console.warn(item.title)}
// onPress={() => this.openItem(item)}
{...rest}>
<View style={styles.root}>
<Image
style={styles.image}
defaultSource={posterHolder}
onError={this.handleImageError}
source={
!showPlaceholder
? { uri: item.images.poster.thumb }
: posterHolder
}
/>
</View>
</BaseButton>
)
}
}
14 changes: 8 additions & 6 deletions app/components/Disclaimer/Disclaimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,19 @@ export default class CheckForUpdates extends React.Component {
children: PropTypes.node.isRequired,
}

state = {
accepted : false,
animating: false,
loading : true,
constructor(props, context) {
super(props, context)

this.state = {
accepted : false,
animating: false,
}
}

componentWillMount() {
Settings.getItem(Settings.DISCLAIMER_ACCEPTED).then((accepted) => {
this.setState({
accepted: accepted && accepted === 'y',
loading : false,
}, () => {
if (!accepted) {
SplashScreen.hide()
Expand Down Expand Up @@ -122,7 +124,7 @@ export default class CheckForUpdates extends React.Component {

render() {
const { children } = this.props
const { animating, accepted, loading } = this.state
const { animating, accepted } = this.state

return (
<React.Fragment>
Expand Down
31 changes: 31 additions & 0 deletions app/modules/BookmarkAdapter/BookmarkAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import DefaultBookmarkAdapter from 'popcorn-sdk/BookmarkAdapter'

import Bookmarks from '../db/Bookmarks'

export default new (class BookmarkAdapter extends DefaultBookmarkAdapter {

getAll = Bookmarks.getAll

checkMovie = movie => new Promise(async(resolve) => {
const bookmarks = await Bookmarks.getAllMovies()

resolve({
...movie,
bookmarked: bookmarks.filter(bookmark => bookmark.id === movie.id).length === 1,
})
})

checkShow = show => new Promise(async(resolve) => {
const bookmarks = await Bookmarks.getAllShows()

resolve({
...show,
bookmarked: bookmarks.filter(bookmark => bookmark.id === show.id).length === 1,
})
})

addItem = Bookmarks.addItem

removeItem = Bookmarks.removeItem

})()
1 change: 1 addition & 0 deletions app/modules/BookmarkAdapter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './BookmarkAdapter'
8 changes: 8 additions & 0 deletions app/modules/PopcornSDK.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Popcorn from 'popcorn-sdk'

import BookmarkAdapter from './BookmarkAdapter'

const SDK = Popcorn
SDK.setBookmarkAdapter(BookmarkAdapter)

export default SDK
55 changes: 55 additions & 0 deletions app/modules/db/Bookmarks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Constants } from 'popcorn-sdk'
import Base from './Base'

export default new (class BookmarksDB extends Base {

KEY_BOOKMARKS = '@Popcorn:Bookmarks'

bookmarks = []

getAll = async() => {
if (this.bookmarks.length > 0) {
return this.bookmarks
}

const bookmarks = await this.getItem(this.KEY_BOOKMARKS)

if (bookmarks) {
this.bookmarks = JSON.parse(bookmarks)
console.log('this.bookmarks', this.bookmarks)
return this.bookmarks
}

return this.bookmarks
}

getAllMovies = async() => {
await this.getAll()

return this.bookmarks.filter(bookmark => bookmark.type === Constants.TYPE_MOVIE)
}

getAllShows = async() => {
await this.getAll()

return this.bookmarks.filter(bookmark => bookmark.type === Constants.TYPE_SHOW)
}

addItem = ({ id, title, type, images }) => {
this.bookmarks.push({
id,
title,
type,
images,
})

this.setItem(this.KEY_BOOKMARKS, JSON.stringify(this.bookmarks))
}

removeItem = ({ id }) => {
this.bookmarks = this.bookmarks.filter(bookmark => bookmark.id !== id)

this.setItem(this.KEY_BOOKMARKS, JSON.stringify(this.bookmarks))
}

})()
2 changes: 1 addition & 1 deletion app/modules/db/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import Base from './Base'

export default new (class SettingsDB extends Base {

DISCLAIMER_ACCEPTED = 'Settings.DISCLAIMER_ACCEPTED'
DISCLAIMER_ACCEPTED = '@Popcorn:Settings:DISCLAIMER_ACCEPTED'

})()
1 change: 1 addition & 0 deletions app/modules/i18n/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"Home": "Home",
"My List": "My List",
"Movies": "Movies",
"Shows": "Shows",
"Season {{number}}": "Season {{number}}",
Expand Down
1 change: 1 addition & 0 deletions app/modules/i18n/translations/nl.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"Home": "Home",
"My List": "Mijn Lijst",
"Movies": "Films",
"Shows": "Series",
"Season {{number}}": "Seizoen {{number}}",
Expand Down
26 changes: 25 additions & 1 deletion app/screens/Home/HomeActions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Popcorn, { Constants } from 'popcorn-sdk'
import { Constants } from 'popcorn-sdk'
import Popcorn from 'modules/PopcornSDK'

import * as HomeConstants from './HomeConstants'
import * as HomeSelectors from './HomeSelectors'
Expand Down Expand Up @@ -42,9 +43,32 @@ export const getItems = (mode, page = 1, givenFilters = {}) => (dispatch, getSta
case Constants.TYPE_MOVIE:
return Popcorn.getMovies(page, filters).then(movies => dispatch(fetchedItems(movies, mode))).catch(catchNoCon)

case 'movieSearch':
// Clear the items
dispatch(clearItems(mode))

return Popcorn.getMovies(page, filters).then(movies => dispatch(fetchedItems(movies, mode))).catch(catchNoCon)

case Constants.TYPE_SHOW:
return Popcorn.getShows(page, filters).then(shows => dispatch(fetchedItems(shows, mode))).catch(catchNoCon)

case 'showSearch':
// Clear the items
dispatch(clearItems(mode))

return Popcorn.getShows(page, filters).then(shows => dispatch(fetchedItems(shows, mode))).catch(catchNoCon)

case Constants.TYPE_BOOKMARK:
return Popcorn.bookmarks.getAll().then(bookmarks => dispatch(fetchedItems(bookmarks, mode)))

case 'bookmarkSearch':
return Popcorn.bookmarks.getAll().then(bookmarks => dispatch(
fetchedItems(
bookmarks.filter(bookmark => bookmark.title.toLowerCase().indexOf(filters.keywords.toLowerCase()) > -1),
mode,
),
))

default:
return null
}
Expand Down
12 changes: 8 additions & 4 deletions app/screens/Home/HomeConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ export const INITIAL_STATE = {
isLoading : true,
hasInternet: true,
modes : {
bookmark: { page: 1, items: [], filters: {} },
movie : { page: 1, items: [], filters: { limit: 50, sort: 'trending' } },
show : { page: 1, items: [], filters: { limit: 50, sort: 'trending' } },
search : { page: 1, items: [], filters: {} },
bookmark : { items: [] },
bookmarkSearch: { items: [] },

movie : { page: 1, items: [], filters: { limit: 50, sort: 'trending' } },
movieSearch : { page: 1, items: [], filters: {} },

show : { page: 1, items: [], filters: { limit: 50, sort: 'trending' } },
showSearch : { page: 1, items: [], filters: {} },
},
}

Expand Down
28 changes: 28 additions & 0 deletions app/screens/Home/HomeReducer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as HomeConstants from './HomeConstants'
import * as ItemConstants from '../Item/ItemConstants'

export default (state = HomeConstants.INITIAL_STATE, action) => {
switch (action.type) {
Expand Down Expand Up @@ -40,6 +41,33 @@ export default (state = HomeConstants.INITIAL_STATE, action) => {
},
}

case ItemConstants.ADD_TO_BOOKMARKS:
return {
...state,
modes: {
...state.modes,
bookmark: {
...state.modes.bookmark,
items: [
...state.modes.bookmark.items,
action.payload,
],
},
},
}

case ItemConstants.REMOVE_FROM_BOOKMARKS:
return {
...state,
modes: {
...state.modes,
bookmark: {
...state.modes.bookmark,
items: state.modes.bookmark.items.filter(bookmark => bookmark.id !== action.payload.id),
},
},
}

default:
return state
}
Expand Down
Loading

0 comments on commit 5637b15

Please sign in to comment.