<commit_before>/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, {
  AppRegistry,
  ActivityIndicatorIOS,
  Component,
  StyleSheet,
  Text,
  View
} from 'react-native';
import Randomath from './randomath.js';
import Swiper from 'react-native-swiper';

const NUM_WALLPAPERS = 5;

class wallgrabber extends Component {
  constructor(props) {
    super(props);

    this.state = {
      wallsJSON: [],
      isLoading: true
    };
  }

  fetchWallsJSON() {
    // console.log('Wallpapers are being fetched.');
    let url = 'http://unsplash.it/list';
    fetch(url)
      .then ( response => response.json() )
      .then ( jsonData => {
        // console.log(jsonData);
        let randomIds = Randomath.uniqueRandomNumbers(NUM_WALLPAPERS, 0, jsonData.length)
        let walls = [];
        randomIds.forEach(randomId => {
          walls.push(jsonData[randomId]);
        });
        this.setState({
          isLoading: false,
          wallsJSON: [].concat(walls)
        });
      })
      .catch ( error => console.log('Fetch error: ' + error) );
  }

  renderLoadingMessage() {
    return (
      <View style={styles.loadingContainer}>
        <ActivityIndicatorIOS
          animating={true}
          color={'#fff'}
          size={'small'}
          style={{margin: 15}} />
          <Text style={{color: '#fff'}}>Contacting Unsplash.it</Text>
      </View>
    );
  }

  renderResults() {
    let {wallsJSON, isLoading} = this.state;
    console.log(wallsJSON);
    if (!isLoading) {
      return (
        // <View style={styles.dataContainer}>
        <Swiper

        dot={<View style={{backgroundColor: 'rgba(25,25,25,0.4)', width: 10, height: 10, borderRadius: 10, marginLeft: 4, marginRight: 4, marginTop: 4, marginBottom: 4}} />}

        activeDot={<View style={{backgroundColor: '#000', width: 10, height: 10, borderRadius: 10, marginLeft: 4, marginRight: 4}} />}

        onMomentumScrollEnd={this.onMomentumScrollEnd}
        >
          {wallsJSON.map((wallpaper, index) => {
            return (
              <Text style={styles.data} key={index}>
                {wallpaper.id + '\n' + wallpaper.author}
              </Text>
            );
          })}
        </Swiper>
      );
    };
  }

  componentDidMount() {
    this.fetchWallsJSON();
  }

  render() {
    let {isLoading} = this.state;
    if (isLoading) {
      return this.renderLoadingMessage();
    } else {
      return this.renderResults();
    }
    // return (
    //   <View style={styles.container}>
    //     <Text style={styles.welcome}>
    //       Welcome to React Native!
    //     </Text>
    //     <Text style={styles.instructions}>
    //       To get started, edit index.ios.js
    //     </Text>
    //     <Text style={styles.instructions}>
    //       Press Cmd+R to reload,{'\n'}
    //       Cmd+D or shake for dev menu
    //     </Text>
    //   </View>
    // );
  }
}

const styles = StyleSheet.create({
  loadingContainer: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#000',
  },
  dataContainer: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fff',
  },
  data: {
    fontSize: 16,
    marginTop: 150,
    textAlign: 'center',
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('wallgrabber', () => wallgrabber);<commit_msg>Added code to display wallpapers now, yayayayayay! Progress indicators and errrything.<commit_after>/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, {
  AppRegistry,
  ActivityIndicatorIOS,
  Component,
  Dimensions,
  StyleSheet,
  Text,
  View
} from 'react-native';
import NetworkImage from 'react-native-image-progress';
import Progress from 'react-native-progress';
import Randomath from './randomath.js';
import Swiper from 'react-native-swiper';

const NUM_WALLPAPERS = 5;
const {height, width} = Dimensions.get('window');

class wallgrabber extends Component {
  constructor(props) {
    super(props);

    this.state = {
      wallsJSON: [],
      isLoading: true
    };
  }

  fetchWallsJSON() {
    // console.log('Wallpapers are being fetched.');
    let url = 'http://unsplash.it/list';
    fetch(url)
      .then ( response => response.json() )
      .then ( jsonData => {
        // console.log(jsonData);
        let randomIds = Randomath.uniqueRandomNumbers(NUM_WALLPAPERS, 0, jsonData.length)
        let walls = [];
        randomIds.forEach(randomId => {
          walls.push(jsonData[randomId]);
        });
        this.setState({
          isLoading: false,
          wallsJSON: [].concat(walls)
        });
      })
      .catch ( error => console.log('Fetch error: ' + error) );
  }

  renderLoadingMessage() {
    return (
      <View style={styles.loadingContainer}>
        <ActivityIndicatorIOS
          animating={true}
          color={'#fff'}
          size={'small'}
          style={{margin: 15}} />
          <Text style={{color: '#fff'}}>Contacting Unsplash.it</Text>
      </View>
    );
  }

  renderResults() {
    let {wallsJSON, isLoading} = this.state;
    console.log(wallsJSON);
    if (!isLoading) {
      return (
        // <View style={styles.dataContainer}>
        <Swiper
          dot={<View style={{backgroundColor: 'rgba(200,200,200,0.4)', width: 10, height: 10, borderRadius: 10, marginLeft: 4, marginRight: 4, marginTop: 4, marginBottom: 4}} />}
          activeDot={<View style={{backgroundColor: '#fff', width: 10, height: 10, borderRadius: 10, marginLeft: 4, marginRight: 4}} />}
          onMomentumScrollEnd={this.onMomentumScrollEnd}
        >
          {wallsJSON.map((wallpaper, index) => {
            console.log(`https://unsplash.it/${wallpaper.width}/${wallpaper.height}?image=${wallpaper.id}`);
            return (
              // <Text style={styles.data} key={index}>
              //   {wallpaper.id + '\n' + wallpaper.author}
              // </Text>
              <View key={index}>
                <NetworkImage
                  source={{ uri: `https://unsplash.it/${wallpaper.width}/${wallpaper.height}?image=${wallpaper.id}` }}
                  indicator={Progress.Circle}
                  style={styles.wallpaperImage}
                  indicatorProps={{
                    color: 'rgba(255,255,255)',
                    size: 60,
                    thickness: 7
                  }}>
                </NetworkImage>
              </View>
            );
          })}
        </Swiper>
      );
    };
  }

  componentDidMount() {
    this.fetchWallsJSON();
  }

  render() {
    let {isLoading} = this.state;
    if (isLoading) {
      return this.renderLoadingMessage();
    } else {
      return this.renderResults();
    }
    // return (
    //   <View style={styles.container}>
    //     <Text style={styles.welcome}>
    //       Welcome to React Native!
    //     </Text>
    //     <Text style={styles.instructions}>
    //       To get started, edit index.ios.js
    //     </Text>
    //     <Text style={styles.instructions}>
    //       Press Cmd+R to reload,{'\n'}
    //       Cmd+D or shake for dev menu
    //     </Text>
    //   </View>
    // );
  }
}

const styles = StyleSheet.create({
  loadingContainer: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#000',
  },
  // dataContainer: {
  //   flex: 1,
  //   justifyContent: 'center',
  //   alignItems: 'center',
  //   backgroundColor: '#fff',
  // },
  // data: {
  //   fontSize: 16,
  //   marginTop: 150,
  //   textAlign: 'center',
  // },
  wallpaperImage: {
    flex: 1,
    width: width,
    height: height,
    backgroundColor: '#000',
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('wallgrabber', () => wallgrabber);
{'fraction_non_alphanumeric': 0.15635220125786164, 'fraction_numerical': 0.01459119496855346, 'mean_word_length': 2.124165029469548, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 59, 'https://': 4, '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': '2583249', 'n_tokens_mistral': 2577, 'n_tokens_neox': 2460, 'n_words': 495}