<commit_before>package com.sqli.blockchain.rhchain.survey;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.sqli.blockchain.rhchain.R;
import com.sqli.blockchain.rhchain.RHChainAbstractActivity;
import com.sqli.blockchain.rhchain.Utils;
import com.sqli.blockchain.rhchain.model.Question;
import com.sqli.blockchain.rhchain.results.ResultActivity;

import java.util.Arrays;
import java.util.List;

import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;

/**
 * Created by gunicolas on 19/04/17.
 */

public class SurveyActivity extends RHChainAbstractActivity implements View.OnClickListener {

    ListView surveyListView;
    Button surveyButton;
    ProgressDialog progressDialog;

    SurveyAdapter adapter;
    boolean canSubmit;

    Subscription overSubscription;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.survey_activity);

        List<Question> questions = application.questions;

        int[] submission = application.blockchainAPI.getSubmission(questions.size());

        surveyListView = (ListView) findViewById(R.id.survey_listview);
        surveyButton = (Button) findViewById(R.id.survey_button);
        adapter = new SurveyAdapter(this,questions,submission);

        setCanSubmit(application.blockchainAPI.canSubmit(submission));

        surveyListView.setAdapter(adapter);

        surveyButton.setOnClickListener(this);

        progressDialog = new ProgressDialog(this);
        progressDialog.setTitle("Vote en cours");
        progressDialog.setMessage("Votre vote est en attente de prise en compte");
        progressDialog.setIndeterminate(true);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.setCancelable(false);
        progressDialog.setProgressNumberFormat(null);
        progressDialog.setProgressPercentFormat(null);

        overSubscription = application.blockchainAPI.registerOverEvent()
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(results -> showResultsActivity());
    }

    void showResultsActivity() {
        Intent intent = new Intent(this, ResultActivity.class);
        startActivity(intent);
    }

    void updateView(){
        surveyButton.setVisibility( canSubmit ? View.VISIBLE : View.GONE);
        adapter.lockUpdate(!canSubmit);
    }

    public void setCanSubmit(boolean canSubmit) {
        this.canSubmit = canSubmit;
        updateView();
    }

    @Override
    public void onClick(View v) {
        if( v.equals(surveyButton) ){
            progressDialog.show();
            int[] submission = adapter.submission;
            application.blockchainAPI.submit(submission)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe( tx -> {
                                progressDialog.dismiss();
                                setCanSubmit(false);
                            },
                            error -> {
                                progressDialog.dismiss();
                                Utils.showAlertDialog(this,error.getMessage());
                            });
        }
    }

    @Override
    protected void onStop() {
        overSubscription.unsubscribe();
        super.onStop();
    }
}
<commit_msg>fix issue with lambda context crashing the app<commit_after>package com.sqli.blockchain.rhchain.survey;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.sqli.blockchain.rhchain.R;
import com.sqli.blockchain.rhchain.RHChainAbstractActivity;
import com.sqli.blockchain.rhchain.Utils;
import com.sqli.blockchain.rhchain.model.Question;
import com.sqli.blockchain.rhchain.results.ResultActivity;

import java.util.Arrays;
import java.util.List;

import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;

/**
 * Created by gunicolas on 19/04/17.
 */

public class SurveyActivity extends RHChainAbstractActivity implements View.OnClickListener {

    ListView surveyListView;
    Button surveyButton;
    ProgressDialog progressDialog;

    SurveyAdapter adapter;
    boolean canSubmit;

    Subscription overSubscription;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.survey_activity);

        List<Question> questions = application.questions;

        int[] submission = application.blockchainAPI.getSubmission(questions.size());

        surveyListView = (ListView) findViewById(R.id.survey_listview);
        surveyButton = (Button) findViewById(R.id.survey_button);
        adapter = new SurveyAdapter(this,questions,submission);

        setCanSubmit(application.blockchainAPI.canSubmit(submission));

        surveyListView.setAdapter(adapter);

        surveyButton.setOnClickListener(this);

        progressDialog = new ProgressDialog(this);
        progressDialog.setTitle("Vote en cours");
        progressDialog.setMessage("Votre vote est en attente de prise en compte");
        progressDialog.setIndeterminate(true);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.setCancelable(false);
        progressDialog.setProgressNumberFormat(null);
        progressDialog.setProgressPercentFormat(null);

        overSubscription = application.blockchainAPI.registerOverEvent()
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(results -> showResultsActivity());
    }

    void showResultsActivity() {
        Intent intent = new Intent(this, ResultActivity.class);
        startActivity(intent);
    }

    void updateView(){
        surveyButton.setVisibility( canSubmit ? View.VISIBLE : View.GONE);
        adapter.lockUpdate(!canSubmit);
    }

    public void setCanSubmit(boolean canSubmit) {
        this.canSubmit = canSubmit;
        updateView();
    }

    @Override
    public void onClick(View v) {
        if( v.equals(surveyButton) ){
            progressDialog.show();
            int[] submission = adapter.submission;
            application.blockchainAPI.submit(submission)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe( tx -> {
                                SurveyActivity.this.progressDialog.dismiss();
                                SurveyActivity.this.setCanSubmit(false);
                            },
                            error -> {
                                SurveyActivity.this.progressDialog.dismiss();
                                Utils.showAlertDialog(SurveyActivity.this,error.getMessage());
                            });
        }
    }

    @Override
    protected void onStop() {
        overSubscription.unsubscribe();
        super.onStop();
    }
}

{'fraction_non_alphanumeric': 0.09191780821917808, 'fraction_numerical': 0.0016438356164383563, 'mean_word_length': 2.8045857217300676, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '7251388', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1849, 'n_words': 329}