<commit_before>package io.github.scarletsky.bangumi.ui.fragments;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.otto.Subscribe;

import java.util.ArrayList;
import java.util.List;

import io.github.scarletsky.bangumi.R;
import io.github.scarletsky.bangumi.adapters.CardRecyclerAdapter;
import io.github.scarletsky.bangumi.api.models.Calendar;
import io.github.scarletsky.bangumi.api.models.Subject;
import io.github.scarletsky.bangumi.events.LoadCalendarEvent;
import io.github.scarletsky.bangumi.ui.widget.MarginDecoration;
import io.github.scarletsky.bangumi.utils.BusProvider;

/**
 * Created by scarlex on 15-7-3.
 */
public class SubjectsRecyclerFragment extends Fragment {

    private Activity ctx;
    private List<Subject> data = new ArrayList<>();
    private int position;
    private CardRecyclerAdapter adapter;

    public static SubjectsRecyclerFragment newInstance(int position) {

        SubjectsRecyclerFragment mSubjectsRecyclerFragment = new SubjectsRecyclerFragment();

        Bundle args = new Bundle();
        args.putInt("ARG_POSITION", position);
        mSubjectsRecyclerFragment.setArguments(args);

        return mSubjectsRecyclerFragment;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.ctx = activity;
        this.position = getArguments().getInt("ARG_POSITION");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_recycler, container, false);

        adapter = new CardRecyclerAdapter(ctx, data);

        RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler);
        mRecyclerView.addItemDecoration(new MarginDecoration(getActivity()));
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setAdapter(adapter);

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        BusProvider.getInstance().register(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        BusProvider.getInstance().unregister(this);
    }

    @Subscribe
    public void onLoadCalendarEvent(LoadCalendarEvent event) {
        Calendar mCalendar = event.getCalendars().get(position);
        this.data.clear();
        this.data.addAll(mCalendar.getItems());
        adapter.notifyDataSetChanged();
    }
}
<commit_msg>feat: add swipe refresh for calendars<commit_after>package io.github.scarletsky.bangumi.ui.fragments;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.otto.Subscribe;

import java.util.ArrayList;
import java.util.List;

import io.github.scarletsky.bangumi.R;
import io.github.scarletsky.bangumi.adapters.CardRecyclerAdapter;
import io.github.scarletsky.bangumi.api.models.Calendar;
import io.github.scarletsky.bangumi.api.models.Subject;
import io.github.scarletsky.bangumi.events.LoadCalendarEvent;
import io.github.scarletsky.bangumi.ui.widget.MarginDecoration;
import io.github.scarletsky.bangumi.utils.BusProvider;

/**
 * Created by scarlex on 15-7-3.
 */
public class SubjectsRecyclerFragment extends Fragment {

    private Activity ctx;
    private List<Subject> data = new ArrayList<>();
    private int position;
    private CardRecyclerAdapter adapter;
    private SwipeRefreshLayout mSwipeRefresh;

    public static SubjectsRecyclerFragment newInstance(int position) {

        SubjectsRecyclerFragment mSubjectsRecyclerFragment = new SubjectsRecyclerFragment();

        Bundle args = new Bundle();
        args.putInt("ARG_POSITION", position);
        mSubjectsRecyclerFragment.setArguments(args);

        return mSubjectsRecyclerFragment;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.ctx = activity;
        this.position = getArguments().getInt("ARG_POSITION");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_recycler, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        adapter = new CardRecyclerAdapter(ctx, data);

        RecyclerView mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler);
        mRecyclerView.addItemDecoration(new MarginDecoration(getActivity()));
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setAdapter(adapter);

        mSwipeRefresh = (SwipeRefreshLayout) getView().findViewById(R.id.swipe_refresh);
        mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mSwipeRefresh.setRefreshing(false);
            }
        });

        mSwipeRefresh.post(new Runnable() {
            @Override
            public void run() {
                mSwipeRefresh.setRefreshing(true);
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        BusProvider.getInstance().register(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        BusProvider.getInstance().unregister(this);
    }

    @Subscribe
    public void onLoadCalendarEvent(LoadCalendarEvent event) {
        Calendar mCalendar = event.getCalendars().get(position);
        this.data.clear();
        this.data.addAll(mCalendar.getItems());
        adapter.notifyDataSetChanged();
        mSwipeRefresh.setRefreshing(false);
    }
}

{'fraction_non_alphanumeric': 0.09802652863151083, 'fraction_numerical': 0.0024263992235522484, 'mean_word_length': 3.5936106983655276, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2409501', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1747, 'n_words': 313}