Skip to content

Commit

Permalink
Next & Prev episode
Browse files Browse the repository at this point in the history
Life is so much easier with this


Former-commit-id: bd6bc20
  • Loading branch information
HenryQuan committed Mar 20, 2018
1 parent a2de18d commit d7706da
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 39 deletions.
4 changes: 2 additions & 2 deletions AnimeGo/src/component/cell/AnimeCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class AnimeCell extends PureComponent {
buttonPressed = () => {
if (this.data.link.includes('-episode-')) {
// Only NewRelease redirects you to that new episode
Actions.WatchAnime({title: this.title, link: this.data.link, fromInfo: false, headerTintColor: 'white'});
Actions.WatchAnime({title: this.title, link: this.data.link, fromInfo: false});
} else if (this.data.link == 'Error') {
// No anime found go back
Linking.openURL('https://www.google.com/search?q=' + this.data.name + ' gogoanime');
} else {
// AnimeDetail will be shown here
Actions.AnimeDetail({title: 'Loading...', link: this.data.link, headerTintColor: 'white'})
Actions.AnimeDetail({title: 'Loading...', link: this.data.link})
}
}
}
Expand Down
39 changes: 33 additions & 6 deletions AnimeGo/src/component/list/SourceList.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { Component } from 'react';
import { View, Text, Button, FlatList, Dimensions } from 'react-native';
import { View, Text, Button, FlatList, Dimensions, Alert } from 'react-native';
import AnimeSourceLoader from '../../helper/core/AnimeSourceLoader';
import SourceCell from '../cell/SourceCell';
import { LoadingIndicator } from '../../component';
import { Actions } from 'react-native-router-flux';
import { SecondaryColour, RedColour, GreenColour } from '../../value';
import { SecondaryColour, RedColour, GreenColour, AnimeGoColour } from '../../value';
import { styles } from './SourceListStyles';

class SourceList extends Component {
Expand All @@ -16,18 +16,19 @@ class SourceList extends Component {
this.state = {
data: [],
name: '', link: '',
prev: '', next: ''
}
}

componentWillMount() {
let source = new AnimeSourceLoader(this.props.link);
source.loadSource().then((animeSource) => {
// console.log(animeSource);
source.loadSource().then(([animeSource, prev, next]) => {
if (animeSource.length == 0) return;
this.setState({
data: animeSource,
name: animeSource[1].animeName,
link: animeSource[1].infoLink,
prev: prev, next: next
})
})
.catch((error) => {
Expand All @@ -42,7 +43,7 @@ class SourceList extends Component {
return (
<View>
<FlatList keyExtractor={this.keyExtractor} ListHeaderComponent={this.renderHeader} ListFooterComponent={this.renderFooter}
data={data} renderItem={({item}) => <SourceCell data={item}/>} />
data={data} renderItem={({item}) => <SourceCell data={item}/>}/>
</View>
)
}
Expand All @@ -53,14 +54,40 @@ class SourceList extends Component {
}

renderHeader = () => {
const { headerViewStyle, textStyle } = styles;
const { headerViewStyle, textStyle, buttonGroupStyle, buttonStyle } = styles;
return (
<View style={headerViewStyle}>
<Text style={textStyle}>Anime Detail</Text>
<Button title={this.state.name} onPress={this.infoBtnPressed} color={GreenColour}/>
<View style={buttonGroupStyle}>
<View style={buttonStyle}>
<Button title='<< Previous' onPress={this.prevEpisode} color={AnimeGoColour}/>
</View>
<View style={buttonStyle}>
<Button title='Next >>' onPress={this.nextEpisode} color={AnimeGoColour}/>
</View>
</View>
</View>
)
}

prevEpisode = () => {
const { prev } = this.state;
if (prev == '') Alert.alert('First Episode', 'this is the first episode of this anime');
else {
Actions.pop();
Actions.WatchAnime({title: 'Episode ' + prev.split('-').pop(), link: prev, fromInfo: false});
}
}

nextEpisode = () => {
const { next } = this.state;
if (next == '') Alert.alert('Last Episode', 'this is currently the last episode of this anime');
else {
Actions.pop();
Actions.WatchAnime({title: 'Episode ' + next.split('-').pop(), link: next, fromInfo: false});
}
}

infoBtnPressed = () => {
// In case user wants infinite loop
Expand Down
18 changes: 0 additions & 18 deletions AnimeGo/src/component/list/SourceListStyles.ios.js

This file was deleted.

11 changes: 10 additions & 1 deletion AnimeGo/src/component/list/SourceListStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ export const styles = StyleSheet.create({
padding: 4
},
adStyle: {
padding: 8, fontSize: 12
padding: 8, fontSize: 12,
textAlign: 'center'
},
buttonGroupStyle: {
flexDirection: 'row', justifyContent: 'space-around',
flex: 1, paddingTop: 4
},
buttonStyle: {
flex: 1,
padding: 1
}
})
22 changes: 18 additions & 4 deletions AnimeGo/src/helper/core/AnimeSourceLoader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MajorLink } from '../../value';
import { Alert } from 'react-native';
import { MajorLink } from '../../value';

export default class AnimeSourceLoader {

Expand All @@ -15,18 +15,20 @@ export default class AnimeSourceLoader {
.then((html) => html.text())
.then((htmlText) => {
var HTMLParser = require('fast-html-parser');
var prev = ''; var next = '';

var root = HTMLParser.parse(htmlText);
var animeSources = root.querySelector('.anime_muti_link');
// Somwhow it does not exist
if (animeSources == null) success([]);
if (animeSources == null) success([[], prev, next]);

var items = animeSources.childNodes[0].childNodes;
// console.log(items);
var animeData = [];
var length = items.length;

// Somwhow it does not have any sources
if (length == 0) success([]);
if (length == 0) success([[], prev, next]);

// Getting anime information
animeInfoLink = '';
Expand Down Expand Up @@ -55,7 +57,19 @@ export default class AnimeSourceLoader {
animeData.push({source: animeSource, name: sourceName, animeName: animeName, infoLink: animeInfoLink});
}
// console.log(animeData);
success(animeData);

// Getting next and prev info
var nextPrev = root.querySelector('.anime_video_body_episodes');
if (nextPrev != null) {
prev = nextPrev.childNodes[0].childNodes[1];
next = nextPrev.childNodes[2].childNodes[1];
if (prev != null) prev = MajorLink.MainURL + prev.attributes.href;
else prev = '';
if (next != null) next = MajorLink.MainURL + next.attributes.href;
else next = '';
}

success([animeData, prev, next]);
})
.catch((error) => {
// console.error(error);
Expand Down
16 changes: 8 additions & 8 deletions AnimeGo/src/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export const ScreenIndex = {
}

export const MajorLink = {
MainURL: 'https://ww5.gogoanime.io',
NewRelease: 'https://ww5.gogoanime.io/page-recent-release.html?page=',
NewSeason: 'https://ww5.gogoanime.io/sub-category/',
Movie: 'https://ww5.gogoanime.io/anime-movies.html?page=',
Genre: 'https://ww5.gogoanime.io/genre/',
Search: 'https://ww5.gogoanime.io/search.html?keyword=',
Episode: 'https://ww5.gogoanime.io/load-list-episode?ep_start=',
Popular: 'https://ww5.gogoanime.io/popular.html?page=',
MainURL: 'https://gogoanime.se',
NewRelease: 'https://gogoanime.se/page-recent-release.html?page=',
NewSeason: 'https://gogoanime.se/sub-category/',
Movie: 'https://gogoanime.se/anime-movies.html?page=',
Genre: 'https://gogoanime.se/genre/',
Search: 'https://gogoanime.se/search.html?keyword=',
Episode: 'https://gogoanime.se/load-list-episode?ep_start=',
Popular: 'https://gogoanime.se/popular.html?page=',
}

0 comments on commit d7706da

Please sign in to comment.