Skip to content

Commit

Permalink
ToWatch List improvement & LongPress
Browse files Browse the repository at this point in the history
Long press surprise
Improvement to ToWatch list with more warnings...


Former-commit-id: 7764061
  • Loading branch information
HenryQuan committed Mar 20, 2018
1 parent 94074af commit a2de18d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 16 deletions.
6 changes: 5 additions & 1 deletion AnimeGo/src/component/cell/AnimeCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AnimeCell extends PureComponent {
const { viewStyle, textStyle, titleStyle, episodeStyle } = styles;
return (
<View style={{flex: 1}}>
<SmartTouchable onPress={this.buttonPressed}>
<SmartTouchable onPress={this.buttonPressed} onLongPress={this.showWebpage}>
<View style={viewStyle}>
{ this.renderImage() }
<Text numberOfLines={3} style={[titleStyle, {width: '95%'}]}>{this.data.name}</Text>
Expand All @@ -38,6 +38,10 @@ class AnimeCell extends PureComponent {
}
}

showWebpage = () => {
Linking.openURL(this.data.link);
}

buttonPressed = () => {
if (this.data.link.includes('-episode-')) {
// Only NewRelease redirects you to that new episode
Expand Down
6 changes: 3 additions & 3 deletions AnimeGo/src/component/common/SmartTouchable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { TouchableNativeFeedback, TouchableOpacity, Platform } from 'react-nativ

class SmartTouchable extends Component {
render() {
const { onPress, children, round } = this.props;
const { onPress, onLongPress, children, round } = this.props;
if (Platform.OS == 'android' && Platform.Version > 19) {
return (
<TouchableNativeFeedback onPress={onPress} background={round ? TouchableNativeFeedback.SelectableBackgroundBorderless() : TouchableNativeFeedback.SelectableBackground()}>
<TouchableNativeFeedback onPress={onPress} onLongPress={onLongPress} background={round ? TouchableNativeFeedback.SelectableBackgroundBorderless() : TouchableNativeFeedback.SelectableBackground()}>
{children}
</TouchableNativeFeedback>
)
} else {
return (
<TouchableOpacity onPress={onPress}>
<TouchableOpacity onPress={onPress} onLongPress={onLongPress}>
{children}
</TouchableOpacity>
)
Expand Down
4 changes: 3 additions & 1 deletion AnimeGo/src/helper/core/GithubUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export default class GithubUpdate {
{text: 'OK', onPress: () => Linking.openURL(link)},
],
)
} else {
} else if (code < VERSION){
Alert.alert('はわわです', 'How could you get version ' + VERSION + '\nHave you hacked the version number?');
} else{
Alert.alert(code, 'AnimeGo is up to date');
}
})
Expand Down
54 changes: 47 additions & 7 deletions AnimeGo/src/screen/ToWatch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { View, FlatList, Text, AsyncStorage, Button, ToastAndroid, Platform } from 'react-native';
import { View, FlatList, Text, AsyncStorage, Button, ToastAndroid, Platform, Alert } from 'react-native';
import { SmartTouchable } from '../component';
import { styles } from './ToWatchStyles';
import { Actions } from 'react-native-router-flux';
Expand All @@ -18,16 +18,16 @@ class ToWatch extends Component {
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)}>
<SmartTouchable onPress={() => this.showAnimeDetail(item.link)} onLongPress={() => this.removeFromList(item)}>
<View style={btnViewStyle}>
<Text style={textStyle} numberOfLines={2}>{item.name}</Text>
</View>
</SmartTouchable>
)
}} automaticallyAdjustContentInsets={false}/>
<Button title='Remove all anime' color={RedColour} onPress={this.removeAllAnime}/>
</View>
);
}
Expand All @@ -36,10 +36,50 @@ class ToWatch extends Component {
* 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([]));
if (global.favList.length < 1) {
Alert.alert('No anime', 'Please add some anime before removing any -_-')
} else {
Alert.alert('Warning', 'Do you want to remove all anime?',
[
{text: 'Cancel', onPress: () => console.log('No anime has been removed'), style: 'cancel'},
{text: 'OK', onPress: () => {
this.setState({data: []});
global.favList = [];
if (Platform.OS == 'android') ToastAndroid.show('All anime has been removed', ToastAndroid.SHORT);
AsyncStorage.setItem('@Favourite', JSON.stringify([]));
}},
]
)
}
}

/**
* Remove one entry from ToWatch list
*/
removeFromList(item) {
Alert.alert(item.name, 'Do you want to remove this anime from list?',
[
{text: 'Cancel', onPress: () => console.log('No anime has been removed'), style: 'cancel'},
{text: 'OK', onPress: () => {
if (global.favList.length == 1) {
this.setState({data: []});
global.favList = [];
} else {
for (var i = 0; i < global.favList.length; i++) {
let curr = global.favList[i];
if (curr.name == item.name && curr.link == item.link) {
// Remove this item
global.favList.splice(i, 1);
this.setState({data: global.favList});
break;
}
}
}
if (Platform.OS == 'android') ToastAndroid.show('Anime has been removed', ToastAndroid.SHORT);
AsyncStorage.setItem('@Favourite', JSON.stringify(global.favList));
}},
]
)
}

/**
Expand Down
5 changes: 2 additions & 3 deletions AnimeGo/src/screen/ToWatchStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { StyleSheet } from 'react-native';

export const styles = StyleSheet.create({
mainViewStyle: {
paddingTop: 6,
flex: 1
},
listStyle: {
margin: 4,
marginTop: 8
marginLeft: 8,
marginRight: 8,
},
btnViewStyle: {
marginTop: 4,
Expand Down
2 changes: 1 addition & 1 deletion AnimeGo/src/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const MicrosoftStore = 'https://www.microsoft.com/store/p/anime-go/9mx3qr
export const Email = 'mailto:[email protected]';

export const AD_IS_OPTIONAL = 'This is completely optional.'
export const VERSION = '1.0.7';
export const VERSION = '1.0.747';

export const ScreenIndex = {
NewRelease: 0,
Expand Down

0 comments on commit a2de18d

Please sign in to comment.