Skip to content

Commit

Permalink
ToWatch, NewSeason & Fix animelist
Browse files Browse the repository at this point in the history
New ToWatch list
NewSeason will be correct
AnimeList could work with hide DUB mode on


Former-commit-id: 420a3aa
  • Loading branch information
HenryQuan committed Mar 14, 2018
1 parent c159ee0 commit fde0e28
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 20 deletions.
6 changes: 5 additions & 1 deletion AnimeGo/src/app/App.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Router, Scene, Actions } from 'react-native-router-flux';
import { DrawerCell, SmartTouchable } from '../component';
import { Divider, Button, Icon } from 'react-native-elements';
import { AdMobInterstitial } from 'react-native-admob';
import { NewRelease, NewSeason, Movie, Popular, Genre, Setting, GenreInfo, WatchAnime, AnimeDetail, SearchAnime, SubCategory } from '../screen';
import { NewRelease, NewSeason, Movie, Popular, Genre, Setting, GenreInfo, WatchAnime, AnimeDetail, SearchAnime, SubCategory, ToWatch } from '../screen';
import { AnimeGoColour, StatusBarColour, ScreenIndex } from '../value';
import { styles } from './AppStyle';
import { DataManager } from '../helper/';
Expand Down Expand Up @@ -46,6 +46,7 @@ export default class App extends Component {
<Scene key='SearchAnime' component={SearchAnime}/>
<Scene key='SubCategory' component={SubCategory}/>

<Scene key='ToWatch' component={ToWatch} title='ToWatch'/>
<Scene key='Setting' component={Setting} title='Settings'/>
</Scene>
</Router>
Expand All @@ -67,6 +68,7 @@ export default class App extends Component {
<DrawerCell text='Popular' onPress={() => this.onChangingScreen(ScreenIndex.Popular)}/>
<DrawerCell text='Genre' onPress={() => this.onChangingScreen(ScreenIndex.Genre)}/>
<Divider style={dividerStyle}/>
<DrawerCell text='ToWatch list' onPress={() => this.onChangingScreen(ScreenIndex.ToWatch)}/>
<DrawerCell text='Settings' onPress={() => this.onChangingScreen(ScreenIndex.Setting)}/>
<DrawerCell text='Support this app (Ad)' onPress={() => this.showAd()}/>
</ScrollView>
Expand Down Expand Up @@ -119,6 +121,8 @@ export default class App extends Component {
Actions.Genre(); break;
case ScreenIndex.Setting:
Actions.Setting(); break;
case ScreenIndex.ToWatch:
Actions.ToWatch(); break;
}
this.refs['Drawer'].closeDrawer();
}
Expand Down
7 changes: 4 additions & 3 deletions AnimeGo/src/component/list/AnimeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ class AnimeList extends PureComponent {
const { hasMorePage, isRefreshing, url, page, data } = this.state;
if (!hasMorePage && !isRefreshing) return;
let loader = new AnimeLoader(url, page);
loader.loadAnime().then((animeData) => {
if (animeData.length == 0) {
loader.loadAnime().then(([animeData, count]) => {
console.log(count);
if (count == 0) {
// No more pages
this.setState({
hasMorePage: false,
isRefreshing: false,
})
} else if (animeData.length < 20 && !global.hideDub) {
} else if (count < 20) {
// Append data
this.setState({
data: data.concat(animeData),
Expand Down
50 changes: 47 additions & 3 deletions AnimeGo/src/component/list/EpisodeList.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { Component } from 'react';
import { View, Text, FlatList, Image, Linking, Button } from 'react-native';
import { View, Text, FlatList, Image, Linking, Button, AsyncStorage, ToastAndroid, Platform, Alert } from 'react-native';
import EpisodeLoader from '../../helper/core/EpisodeLoader';
import EpisodeCell from '../cell/EpisodeCell';
import { LoadingIndicator } from '../../component';
import { Actions } from 'react-native-router-flux';
import { isPortrait } from '../../helper/DeviceDimensions';
import { styles } from './EpisodeListStyles'
import { BlueColour, GreenColour } from '../../value';
import { BlueColour, GreenColour, RedColour } from '../../value';

class EpisodeList extends React.PureComponent {
constructor(props) {
Expand Down Expand Up @@ -44,23 +44,52 @@ class EpisodeList extends React.PureComponent {

renderHeader = () => {
const { name, image, plot } = this.state;
const { mainViewStyle, titleStyle, basicTextStyle, plotStyle} = styles;
const { mainViewStyle, titleStyle, basicTextStyle, plotStyle } = styles;
return (
<View style={mainViewStyle}>
<Text numberOfLines={3} style={titleStyle}>{name}</Text>
{ this.renderInfo() }
<Text style={plotStyle}>{plot}</Text>
<Button title='Google it' color={BlueColour} onPress={this.searchGoogle}/>
<Text style={basicTextStyle}>* Please consider buying its DVD</Text>
<Button title='To-Watch' color={RedColour} onPress={this.addToList}/>
</View>
)
}

/**
* Add this name to To-Watch list. No duplicate
*/
addToList = () => {
const { data, link } = this.props;
let animeInfo = {link: link, name: data.name};
if (global.favList.length == 0) global.favList = [animeInfo];
else {
var hasAnime = false;
for (var i = 0; i < global.favList.length; i++) {
let anime = global.favList[i];
if (anime.name == animeInfo.name) {
if (Platform.OS == 'android') ToastAndroid.show('Anime has already been added', ToastAndroid.SHORT);
else Alert.alert('Warning', 'Anime has already been added');
hasAnime = true; break;
}
}
if (!hasAnime) global.favList = global.favList.concat([animeInfo]);
}
AsyncStorage.setItem('@Favourite', JSON.stringify(global.favList));
}

/**
* Google this anime name
*/
searchGoogle = () => {
let google = 'https://www.google.com/search?q=' + this.state.name.split(' ').join('%20');
Linking.openURL(google).catch(err => console.error('An error occurred', err));
}

/**
* Render anime information depending on DataSaver mode
*/
renderInfo = () => {
const { genre, release, episode, type, image } = this.state;
const { imageViewStyle, imageStyle, infoViewStyle, basicTextStyle } = styles;
Expand Down Expand Up @@ -94,11 +123,17 @@ class EpisodeList extends React.PureComponent {
}
}

/**
* Render footer for EpisodeList. It is either an indicator or nothing
*/
renderFooter = () => {
if (this.state.hasMorePage) return <LoadingIndicator />
else return null;
}

/**
* Visit this anime's category
*/
goSubCategory = () => {
const { type, typeLink } = this.state;
// To prevent infinite loop
Expand All @@ -109,10 +144,16 @@ class EpisodeList extends React.PureComponent {
}
}

/**
* Update column number depending on orientation
*/
updateColumn = () => {
this.setState({column: isPortrait() ? 4 : 8});
}

/**
* Loading anime first 99 episodes
*/
loadEpisode = () => {
const { ep_start, ep_end, id, episode, data, hasMorePage } = this.state;
if (!hasMorePage) return;
Expand All @@ -131,6 +172,9 @@ class EpisodeList extends React.PureComponent {
});
}

/**
* Loading next 99 episodes
*/
loadMoreEpisode = () => {
const { episode, ep_start, ep_end } = this.state;
var new_start = ep_start + 100;
Expand Down
3 changes: 2 additions & 1 deletion AnimeGo/src/global.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
global.dataSaver = false;
global.hideDub = false;
global.currSubCategory = '';
global.currSubCategory = '';
global.favList = [];
11 changes: 7 additions & 4 deletions AnimeGo/src/helper/DataManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class DataManager {
static async setupData() {
// Setup data here when app is launched
try {
const value = await AsyncStorage.getItem('@FIRST');
const value = await AsyncStorage.getItem('@FIRST');
if (value != 'false') {
// First launch
await AsyncStorage.setItem('@FIRST', 'false');
await AsyncStorage.setItem('@dataSaver', 'false');
await AsyncStorage.setItem('@DUB', 'false');
await AsyncStorage.setItem('@Favourite', JSON.stringify({}));
await AsyncStorage.setItem('@Favourite', JSON.stringify([]));
await AsyncStorage.setItem('@Version', VERSION);
global.dataSaver = false;
} else {
Expand All @@ -25,7 +25,9 @@ class DataManager {
}
const dataSaver = await AsyncStorage.getItem('@dataSaver');
const DUB = await AsyncStorage.getItem('@DUB');
const favList = await AsyncStorage.getItem('@Favourite');
const favList = await AsyncStorage.getItem('@Favourite');
global.favList = JSON.parse(favList);
console.log(global.favList);
global.dataSaver = JSON.parse(dataSaver);
global.hideDub = JSON.parse(DUB);
}
Expand All @@ -35,7 +37,8 @@ class DataManager {
}

static async addMoreEntry() {
await AsyncStorage.setItem('@Favourite', JSON.stringify({}));
if (await AsyncStorage.getItem('@Favourite') == null)
await AsyncStorage.setItem('@Favourite', JSON.stringify([]));
}
}

Expand Down
9 changes: 6 additions & 3 deletions AnimeGo/src/helper/core/AnimeLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export default class AnimeLoader {
var items = root.childNodes;
// For search when no reult has been found
if (items["0"].rawText.includes('Sorry')) {
success([{name: this.url.replace(MajorLink.Search, '').replace('&page=', ''), info: 'Google', link: 'Error'}]);
success([{name: this.url.replace(MajorLink.Search, '').replace('&page=', ''), info: 'Google', link: 'Error'}, 1]);
}

var animeData = [];
var entryCount = 0;
var length = items.length;
// This is only for new release
if (length == 0) success([]);
Expand All @@ -38,15 +39,17 @@ export default class AnimeLoader {
var animeImage = anime.querySelector('.img');
var animeLink = MajorLink.MainURL + animeImage.childNodes[1].attributes.href;
var animeName = anime.querySelector('.name').text;
// To keep original entry numbers
entryCount++;
if (global.hideDub && animeName.includes('(Dub)')) continue;
// Only for NewRelease, it is displaying episode.
var extraInformation = this.url == MajorLink.NewRelease ? anime.querySelector('.episode').text : anime.querySelector('.released').removeWhitespace().text;
if (extraInformation == '') extraInformation = '??';
var animeThumbnail = animeImage.childNodes[1].childNodes[1].attributes.src;
animeData.push({name: animeName, info: extraInformation, link: animeLink, thumbnail: animeThumbnail});
}
// console.log(animeData);
success(animeData);
// console.log(entryCount);
success([animeData, entryCount]);
})
.catch((error) => {
// console.error(error);
Expand Down
2 changes: 1 addition & 1 deletion AnimeGo/src/screen/AnimeDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AnimeDetail extends Component {
if (data == '') {
return <LoadingIndicator />
} else {
return <EpisodeList data={data}/>
return <EpisodeList data={data} link={this.link}/>
}
}

Expand Down
28 changes: 27 additions & 1 deletion AnimeGo/src/screen/NewSeason.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,35 @@ import { MajorLink } from '../value';
class NewSeason extends Component {
render() {
return (
<AnimeList AnimeUrl={MajorLink.NewSeason}/>
<AnimeList AnimeUrl={this.getNewSeason()}/>
)
}

/**
* Getting new season url depending on month
*/
getNewSeason() {
let now = new Date();
var season = '';
// Month starts from 0
switch (now.getMonth() + 1) {
case 1:
case 2:
case 3: season = 'winter'; break;
case 4:
case 5:
case 6: season = 'spring'; break;
case 7:
case 8:
case 9: season = 'summer'; break;
case 10:
case 11:
case 12: season = 'fall'; break;
}
let url = MajorLink.NewSeason + season + '-' + now.getFullYear() + '-anime&page=';
console.log(url);
return url;
}
}

export {NewSeason};
54 changes: 54 additions & 0 deletions AnimeGo/src/screen/ToWatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { Component } from 'react';
import { View, FlatList, Text, AsyncStorage, Button, ToastAndroid, Platform } from 'react-native';
import { SmartTouchable } from '../component';
import { styles } from './ToWatchStyles';
import { Actions } from 'react-native-router-flux';
import { RedColour } from '../value';

class ToWatch extends Component {
constructor() {
super()
this.state = {
data: Object.assign(global.favList)
}
}

listKey = (item) => item.name;
render() {
const { btnViewStyle, mainViewStyle, listStyle, textStyle } = styles;
return (
<View style={mainViewStyle}>
<Button title='Remove all anime' color={RedColour} onPress={this.removeAllAnime}/>
<FlatList style={listStyle} data={this.state.data} keyExtractor={this.listKey} renderItem={({item}) => {
return (
<SmartTouchable onPress={() => this.showAnimeDetail(item.link)}>
<View style={btnViewStyle}>
<Text style={textStyle} numberOfLines={2}>{item.name}</Text>
</View>
</SmartTouchable>
)
}} automaticallyAdjustContentInsets={false}/>
</View>
);
}

/**
* Remove all anime from ToWatch list
*/
removeAllAnime = () => {
this.setState({data: []});
global.favList = [];
if (Platform.OS == 'android') ToastAndroid.show('All anime has been removed', ToastAndroid.SHORT);
AsyncStorage.setItem('@Favourite', JSON.stringify([]));
}

/**
* Visit AnimeDetail page
*/
showAnimeDetail(link) {
Actions.AnimeDetail({title: 'Loading...', link: link});
}

}

export {ToWatch};
21 changes: 21 additions & 0 deletions AnimeGo/src/screen/ToWatchStyles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { StyleSheet } from 'react-native';

export const styles = StyleSheet.create({
mainViewStyle: {
paddingTop: 6,
flex: 1
},
listStyle: {
margin: 4,
marginTop: 8
},
btnViewStyle: {
marginTop: 4,
height: 44,
justifyContent: 'center'
},
textStyle: {
fontWeight: 'bold',
color: 'black'
}
})
3 changes: 2 additions & 1 deletion AnimeGo/src/screen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export * from './GenreInfo';
export * from './AnimeDetail';
export * from './WatchAnime';
export * from './SearchAnime';
export * from './SubCategory';
export * from './SubCategory';
export * from './ToWatch';
5 changes: 3 additions & 2 deletions AnimeGo/src/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ export const ScreenIndex = {
Movie: 2,
Popular: 3,
Genre: 4,
Setting: 5
Setting: 5,
ToWatch: 6
}

export const MajorLink = {
MainURL: 'https://ww5.gogoanime.io',
NewRelease: 'https://ww5.gogoanime.io/page-recent-release.html?page=',
NewSeason: 'https://ww5.gogoanime.io/new-season.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=',
Expand Down

0 comments on commit fde0e28

Please sign in to comment.