<commit_before>import 'dart:convert';

import 'package:code_wars_android/code_wars/code_wars.dart';
import 'package:code_wars_android/code_wars/colors.dart';
import 'package:code_wars_android/util/storage.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:code_wars_android/util/util.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';

class SettingsActivity extends MaterialPageRoute<Null> {
  SettingsActivity()
      : super(builder: (BuildContext context) => new SettingsView());
}

class SettingsView extends StatefulWidget {
  static const String _title = "Settings";

  @override
  State<StatefulWidget> createState() => new SettingsState(_title);
}

// ignore: must_be_immutable
class SettingsState extends State<SettingsView> {
  CodeWarsUser _user;
  String _title = "Settings";
  Color textColor = CodeWarsColors.black.shade700;
  TextEditingController _usernameEditingController;

  SettingsState(this._title);

  _performChangeUser(String _json) {
    try {
      Map json = new JsonDecoder(null).convert(_json);
      var reason = json['reason'];
      _user = null != reason ? null : new CodeWarsUser.fromJSON(json);
    } catch (e) {
      _json = CodeWarsAPI.getErrorWithReason("invalid");
    }
    SharedPreferences.getInstance().then((sp) {
      sp.setString(DatabaseKeys.USER, _json);
    });
  }

  _changeUserName() {
    var dialog = new SimpleDialog(
      contentPadding: new EdgeInsets.all(20.0),
      children: [
        new TextFormField(
            decoration: const InputDecoration(
                hintText: "Click OK to submit",
                labelText: "New user name"),
            maxLines: 1,
            controller: _usernameEditingController),
        new FlatButton(onPressed: () {
          Navigator.pop(context);
          showDialog(context: context, child: new RefreshProgressDialog(
              CodeWarsColors.black.shade100, width: 100, height: 100),
              barrierDismissible: false);
          get(CodeWarsAPI.getUser(_usernameEditingController.text))
            ..then((val) {
              setState(() => _performChangeUser(val.body));
              Navigator.pop(context);
            })
            ..timeout(new Duration(seconds: 10))
            ..catchError(() {
              SharedPreferences.getInstance().then((sp) {
                sp.setString(DatabaseKeys.USER,
                    CodeWarsAPI.getErrorWithReason("time out"));
              });
              setState(() {
                _user = null;
                Navigator.pop(context);
              });
            });
        }, child: new Text("OK")),
      ], title: new Text("Reset your username"),);
    showDialog(context: context, child: dialog);
  }


  @override
  void initState() {
    super.initState();
    _usernameEditingController = new TextEditingController();
    SharedPreferences.getInstance().then((sp) {
      _user = new CodeWarsUser.fromJSON(new JsonDecoder(null).convert(
          sp.getString(DatabaseKeys.USER) ??
              CodeWarsAPI.getErrorWithReason("not found")));
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(title: new Text(_title)),
        backgroundColor: CodeWarsColors.black.shade200,
        body: new ListView(primary: false, children: [
          new ListTile(title: new Text("Change user name",
              style: new TextStyle(color: textColor)),
              subtitle: new Text(_user?.username ?? "Unknown",
                  style: new TextStyle(color: textColor)),
              trailing: new IconButton(
                  icon: new Icon(Icons.edit), onPressed: _changeUserName)),
          new ExpansionTile(title: new Text("App info"), children: [
            new ListTile(dense: true, title: new Text("View Source on GitHub"),
                onTap: _viewSource),
            new ListTile(dense: true, title: new Text("License"),
                onTap: () {
                  showDialog(context: context, child: new SimpleDialog(
                      title: new Text("License"),
                      children: [ new Text(GPLv3)]));
                }),
            new ListTile(title: new Text("ass we can"),),
          ])
        ]));
  }

  _viewSource() async {
    const url = 'https://github.com/ice1000/code_wars_android';
    if (await canLaunch(url)) await launch(url);
  }
}<commit_msg>add code wars<commit_after>import 'dart:convert';

import 'package:code_wars_android/code_wars/code_wars.dart';
import 'package:code_wars_android/code_wars/colors.dart';
import 'package:code_wars_android/util/storage.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:code_wars_android/util/util.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';

class SettingsActivity extends MaterialPageRoute<Null> {
  SettingsActivity()
      : super(builder: (BuildContext context) => new SettingsView());
}

class SettingsView extends StatefulWidget {
  static const String _title = "Settings";

  @override
  State<StatefulWidget> createState() => new SettingsState(_title);
}

// ignore: must_be_immutable
class SettingsState extends State<SettingsView> {
  CodeWarsUser _user;
  String _title = "Settings";
  Color textColor = CodeWarsColors.black.shade700;
  TextEditingController _usernameEditingController;

  SettingsState(this._title);

  _performChangeUser(String _json) {
    try {
      Map json = new JsonDecoder(null).convert(_json);
      var reason = json['reason'];
      _user = null != reason ? null : new CodeWarsUser.fromJSON(json);
    } catch (e) {
      _json = CodeWarsAPI.getErrorWithReason("invalid");
    }
    SharedPreferences.getInstance().then((sp) {
      sp.setString(DatabaseKeys.USER, _json);
    });
  }

  _changeUserName() {
    var dialog = new SimpleDialog(
      contentPadding: new EdgeInsets.all(20.0),
      children: [
        new TextFormField(
            decoration: const InputDecoration(
                hintText: "Click OK to submit",
                labelText: "New user name"),
            maxLines: 1,
            controller: _usernameEditingController),
        new FlatButton(onPressed: () {
          Navigator.pop(context);
          showDialog(context: context, child: new RefreshProgressDialog(
              CodeWarsColors.black.shade100, width: 100, height: 100),
              barrierDismissible: false);
          get(CodeWarsAPI.getUser(_usernameEditingController.text))
            ..then((val) {
              setState(() => _performChangeUser(val.body));
              Navigator.pop(context);
            })
            ..timeout(new Duration(seconds: 10))
            ..catchError(() {
              SharedPreferences.getInstance().then((sp) {
                sp.setString(DatabaseKeys.USER,
                    CodeWarsAPI.getErrorWithReason("time out"));
              });
              setState(() {
                _user = null;
                Navigator.pop(context);
              });
            });
        }, child: new Text("OK")),
      ], title: new Text("Reset your username"),);
    showDialog(context: context, child: dialog);
  }


  @override
  void initState() {
    super.initState();
    _usernameEditingController = new TextEditingController();
    SharedPreferences.getInstance().then((sp) {
      _user = new CodeWarsUser.fromJSON(new JsonDecoder(null).convert(
          sp.getString(DatabaseKeys.USER) ??
              CodeWarsAPI.getErrorWithReason("not found")));
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(title: new Text(_title)),
        backgroundColor: CodeWarsColors.black.shade200,
        body: new ListView(primary: false, children: [
          new ListTile(title: new Text("Change user name",
              style: new TextStyle(color: textColor)),
              subtitle: new Text(_user?.username ?? "Unknown",
                  style: new TextStyle(color: textColor)),
              trailing: new IconButton(
                  icon: new Icon(Icons.edit), onPressed: _changeUserName)),
          new ExpansionTile(title: new Text("App info"), children: [
            new ListTile(dense: true, title: new Text("Source on GitHub"),
                onTap: () =>
                    _viewWeb('https://github.com/ice1000/code_wars_android')),
            new ListTile(dense: true, title: new Text("License"),
                onTap: () {
                  showDialog(context: context, child: new SimpleDialog(
                      title: new Text("License"),
                      contentPadding: new EdgeInsets.all(8.0),
                      children: [ new Text(GPLv3)]));
                }),
            new ListTile(dense: true, title: new Text("Open CodeWars"),
                onTap: () => _viewWeb('https://www.codewars.com/'))
          ])
        ]));
  }

  _viewWeb(String url) async {
    if (await canLaunch(url)) await launch(url);
  }
}
{'fraction_non_alphanumeric': 0.11865524060646011, 'fraction_numerical': 0.005932762030323006, 'mean_word_length': 2.5642129992169145, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, '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': '7112577', 'n_tokens_mistral': 2615, 'n_tokens_neox': 2519, 'n_words': 533}