<commit_before>package io.github.droidkaigi.confsched.activity;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.crashlytics.android.Crashlytics;

import java.util.List;

import javax.inject.Inject;

import io.github.droidkaigi.confsched.MainApplication;
import io.github.droidkaigi.confsched.R;
import io.github.droidkaigi.confsched.api.DroidKaigiClient;
import io.github.droidkaigi.confsched.dao.ContributorDao;
import io.github.droidkaigi.confsched.databinding.ActivityContributorsBinding;
import io.github.droidkaigi.confsched.databinding.ItemContributorBinding;
import io.github.droidkaigi.confsched.model.Contributor;
import io.github.droidkaigi.confsched.util.AnalyticsTracker;
import io.github.droidkaigi.confsched.util.AppUtil;
import io.github.droidkaigi.confsched.widget.ArrayRecyclerAdapter;
import io.github.droidkaigi.confsched.widget.BindingHolder;
import io.github.droidkaigi.confsched.widget.itemdecoration.DividerItemDecoration;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.subscriptions.CompositeSubscription;

public class ContributorsActivity extends AppCompatActivity {

    public static final String TAG = ContributorsActivity.class.getSimpleName();

    @Inject
    AnalyticsTracker analyticsTracker;

    @Inject
    DroidKaigiClient client;

    @Inject
    ContributorDao dao;

    @Inject
    CompositeSubscription compositeSubscription;

    private ActivityContributorsBinding binding;

    public static Intent createIntent(@NonNull Context context) {
        return new Intent(context, ContributorsActivity.class);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_contributors);
        MainApplication.getComponent(this).inject(this);
        initToolbar();
        binding.recyclerView.addItemDecoration(new DividerItemDecoration(getApplicationContext(), R.drawable.border_small));
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        compositeSubscription.add(fetchContributors());
    }

    private Subscription fetchContributors() {
        return client.getContributors()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnSubscribe(() -> binding.progressBar.setVisibility(View.VISIBLE))
                .doOnCompleted(() -> binding.progressBar.setVisibility(View.GONE))
                .subscribe(
                        this::renderContributors,
                        this::renderSavedContributors
                );
    }

    private void renderContributors(List<Contributor> contributors) {
        bindContributors(contributors);
        dao.upserterAll(contributors);
    }

    // renderSavedContributors is called when error
    private void renderSavedContributors(Throwable throwable) {
        Log.e(TAG, "Failed to fetchContributors.", throwable);
        Crashlytics.logException(throwable);<commit_msg>Fix progress should be gone when error<commit_after>package io.github.droidkaigi.confsched.activity;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.crashlytics.android.Crashlytics;

import java.util.List;

import javax.inject.Inject;

import io.github.droidkaigi.confsched.MainApplication;
import io.github.droidkaigi.confsched.R;
import io.github.droidkaigi.confsched.api.DroidKaigiClient;
import io.github.droidkaigi.confsched.dao.ContributorDao;
import io.github.droidkaigi.confsched.databinding.ActivityContributorsBinding;
import io.github.droidkaigi.confsched.databinding.ItemContributorBinding;
import io.github.droidkaigi.confsched.model.Contributor;
import io.github.droidkaigi.confsched.util.AnalyticsTracker;
import io.github.droidkaigi.confsched.util.AppUtil;
import io.github.droidkaigi.confsched.widget.ArrayRecyclerAdapter;
import io.github.droidkaigi.confsched.widget.BindingHolder;
import io.github.droidkaigi.confsched.widget.itemdecoration.DividerItemDecoration;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.subscriptions.CompositeSubscription;

public class ContributorsActivity extends AppCompatActivity {

    public static final String TAG = ContributorsActivity.class.getSimpleName();

    @Inject
    AnalyticsTracker analyticsTracker;

    @Inject
    DroidKaigiClient client;

    @Inject
    ContributorDao dao;

    @Inject
    CompositeSubscription compositeSubscription;

    private ActivityContributorsBinding binding;

    public static Intent createIntent(@NonNull Context context) {
        return new Intent(context, ContributorsActivity.class);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_contributors);
        MainApplication.getComponent(this).inject(this);
        initToolbar();
        binding.recyclerView.addItemDecoration(new DividerItemDecoration(getApplicationContext(), R.drawable.border_small));
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        compositeSubscription.add(fetchContributors());
    }

    private Subscription fetchContributors() {
        return client.getContributors()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnSubscribe(() -> binding.progressBar.setVisibility(View.VISIBLE))
                .doOnCompleted(() -> binding.progressBar.setVisibility(View.GONE))
                .doOnError((throwable) -> binding.progressBar.setVisibility(View.GONE))
                .subscribe(
                        this::renderContributors,
                        this::renderSavedContributors
                );
    }

    private void renderContributors(List<Contributor> contributors) {
        bindContributors(contributors);
        dao.upserterAll(contributors);
    }

    // renderSavedContributors is called when error
    private void renderSavedContributors(Throwable throwable) {
        Log.e(TAG, "Failed to fetchContributors.", throwable);
        Crashlytics.logException(throwable);
{'fraction_non_alphanumeric': 0.08818194502581275, 'fraction_numerical': 0.0008371703641691084, 'mean_word_length': 4.235938641344047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '3024454', 'n_tokens_mistral': 2066, 'n_tokens_neox': 1962, 'n_words': 315}