<commit_before>
import React, { Component } from 'react';
import { 
    View, 
    Text,
    TouchableHighlight,
    ListView,
    Dimensions,
    Image,
    StyleSheet
} from 'react-native';

export default class PageAds extends Component {
    constructor(props) {
        super(props);
        this.ds = new ListView.DataSource({rowHasChanged: (r1,r2) => r1 !== r2});
        this.state = {
            dataSource: this.ds.cloneWithRows([]),
            images: [],
            level: 'top'
        };
    }

    getImagesAsync() {
        return fetch('http://store.wholefoods.coop/api/flyers/')
            .then((response) => response.json())
            .then((responseJSON) => {
                var covers = responseJSON.map((imgs) => imgs[0]);
                this.setState({
                    dataSource: this.ds.cloneWithRows(covers),
                    images: responseJSON,
                    level: 'top'
                });
            })
            .catch((error) => console.log(error));
    }

    componentDidMount() {
        this.getImagesAsync();
    }

    goToTop() {
        var covers = this.state.images.map((i) => i[0]);
        this.setState({
            dataSource: this.ds.cloneWithRows(covers),
            level: 'top'
        });
    }

    goDownLevel(url) {
        var list = ['Go Back'];
        for (var i=0; i<this.state.images.length; i++) {
            if (this.state.images[i][0] == url) {
                for (var j=0; j<this.state.images[i].length; j++) {
                    list.push(this.state.images[i][j]);
                }
            }
        }
        list.push('Go Back');
        this.setState({
            dataSource: this.ds.cloneWithRows(list),
            level: 'sub'
        }); 
    }

    renderImg(url) {
        var {width, height} = Dimensions.get('window');
        var w = width - 50;
        var h = Math.round(w * (11.0/8.5));
        if (this.state.level == 'top') {
            return (
                <TouchableHighlight onPress={() => this.goDownLevel(url)}>
                    <Image
                        style={{width: w, height: h}}
                        source={{uri: url}}
                        resizeMode="contain"
                    />
                </TouchableHighlight>
            );
        } else if (url == 'Go Back') {
            return (
                <TouchableHighlight onPress={this.goToTop.bind(this)}>
                    <Text>{url}</Text>
                </TouchableHighlight>
            );
        } else {
            return (
                <View>
                <Image
                    style={{width: w, height: h, padding: 5}}
                    source={{uri: url}}
                    resizeMode="contain"
                />
                </View>
            );
        }
    }

    render() {
        return (
            <View style={{flex: 1, alignItems: 'center'}}>
                <Text>Current Sales Flyers</Text>
                <ListView
                    dataSource={this.state.dataSource}
                    renderRow={this.renderImg.bind(this)}
                    enableEmptySections={true}
                    automaticallyAdjustContentInsets={false}
                />
            </View>
        );
    }
}

<commit_msg>Resize flyer images on device rotation<commit_after>
import React, { Component } from 'react';
import { 
    View, 
    Text,
    TouchableHighlight,
    ListView,
    Dimensions,
    Image,
    StyleSheet
} from 'react-native';

export default class PageAds extends Component {
    constructor(props) {
        super(props);
        this.ds = new ListView.DataSource({rowHasChanged: (r1,r2) => r1 !== r2});
        this.state = {
            dataSource: this.ds.cloneWithRows([]),
            images: [],
            level: 'top',
            currentList: []
        };
    }

    getImagesAsync() {
        return fetch('http://store.wholefoods.coop/api/flyers/')
            .then((response) => response.json())
            .then((responseJSON) => {
                var covers = responseJSON.map((imgs) => imgs[0]);
                this.setState({
                    dataSource: this.ds.cloneWithRows(covers),
                    images: responseJSON,
                    level: 'top',
                    currentList: covers
                });
            })
            .catch((error) => console.log(error));
    }

    componentDidMount() {
        this.getImagesAsync();
    }

    reOrient() {
        /**
          Hack. State needs to change to trigger
          re-rendering the ListView so swap in an
          empty list then the current list again
        */
        var cur = this.state.currentList;
        this.setState({
            dataSource: this.ds.cloneWithRows([])
        });
        this.setState({
            dataSource: this.ds.cloneWithRows(cur)
        });  
    }

    goToTop() {
        var covers = this.state.images.map((i) => i[0]);
        this.setState({
            dataSource: this.ds.cloneWithRows(covers),
            level: 'top',
            currentList: covers
        });
    }

    goDownLevel(url) {
        var list = ['Go Back'];
        for (var i=0; i<this.state.images.length; i++) {
            if (this.state.images[i][0] == url) {
                for (var j=0; j<this.state.images[i].length; j++) {
                    list.push(this.state.images[i][j]);
                }
            }
        }
        list.push('Go Back');
        this.setState({
            dataSource: this.ds.cloneWithRows(list),
            level: 'sub',
            currentList: list
        }); 
    }

    renderImg(url) {
        var {width, height} = Dimensions.get('window');
        var w = width - 50;
        var h = Math.round(w * (11.0/8.5));
        if (this.state.level == 'top') {
            return (
                <TouchableHighlight onPress={() => this.goDownLevel(url)}>
                    <Image
                        style={{width: w, height: h}}
                        source={{uri: url}}
                        resizeMode="contain"
                    />
                </TouchableHighlight>
            );
        } else if (url == 'Go Back') {
            return (
                <TouchableHighlight onPress={this.goToTop.bind(this)}>
                    <Text>{url}</Text>
                </TouchableHighlight>
            );
        } else {
            return (
                <View>
                <Image
                    style={{width: w, height: h, padding: 5}}
                    source={{uri: url}}
                    resizeMode="contain"
                />
                </View>
            );
        }
    }

    render() {
        return (
            <View style={{flex: 1, alignItems: 'center'}}
                onLayout={this.reOrient.bind(this)}>
                <Text>Current Sales Flyers</Text>
                <ListView
                    dataSource={this.state.dataSource}
                    renderRow={this.renderImg.bind(this)}
                    enableEmptySections={true}
                    automaticallyAdjustContentInsets={false}
                />
            </View>
        );
    }
}


{'fraction_non_alphanumeric': 0.13283103111483185, 'fraction_numerical': 0.0050230221850146506, 'mean_word_length': 1.2697910069664344, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1612758', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1928, 'n_words': 368}