<commit_before>package com.example.alexeyglushkov.wordteacher;

import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.alexeyglushkov.quizletservice.entities.QuizletSet;
import com.example.alexeyglushkov.quizletservice.entities.QuizletTerm;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * A placeholder fragment containing a simple view.
 */
public class QuizletCardsFragment extends Fragment {

    enum ViewType {
        Sets,
        Cards
    }

    private QuizletSet parentSet;
    private RecyclerView recyclerView;
    private RecyclerView.Adapter adapter;
    private LinearLayoutManager layoutManager;
    private ViewType viewType = ViewType.Sets;
    private Listener listener;

    public QuizletCardsFragment() {
    }

    public void setListener(Listener listener) {
        this.listener = listener;
    }

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

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        recyclerView = (RecyclerView)view.findViewById(R.id.recyclerView);

        layoutManager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(layoutManager);

        if (savedInstanceState != null) {
            restore(savedInstanceState);
        }

        if (adapter == null) {
            recreateAdapter();
        }

        if (recyclerView.getAdapter() == null) {
            applyAdapter();
        }
    }

    private void restore(@Nullable Bundle savedInstanceState) {
        int intViewType = savedInstanceState.getInt("viewType");
        viewType = ViewType.values()[intViewType];
        recreateAdapter();
        restoreAdapter(savedInstanceState);
    }

    private void restoreAdapter(@Nullable Bundle savedInstanceState) {
        Parcelable parcelable = savedInstanceState.getParcelable("adapter");
        if (viewType == ViewType.Sets) {
            getSetAdapter().onRestoreInstanceState(parcelable);
        } else {
            getWordAdapter().onRestoreInstanceState(parcelable);
        }
    }<commit_msg>fixed restoration for quizlet fragments<commit_after>package com.example.alexeyglushkov.wordteacher;

import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.alexeyglushkov.quizletservice.entities.QuizletSet;
import com.example.alexeyglushkov.quizletservice.entities.QuizletTerm;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * A placeholder fragment containing a simple view.
 */
public class QuizletCardsFragment extends Fragment {

    enum ViewType {
        Sets,
        Cards
    }

    private QuizletSet parentSet;
    private RecyclerView recyclerView;
    private RecyclerView.Adapter adapter;
    private LinearLayoutManager layoutManager;
    private ViewType viewType = ViewType.Sets;
    private Listener listener;

    public QuizletCardsFragment() {
    }

    public void setListener(Listener listener) {
        this.listener = listener;
    }

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

        if (savedInstanceState != null) {
            restore(savedInstanceState);
        }
    }

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

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        recyclerView = (RecyclerView)view.findViewById(R.id.recyclerView);

        layoutManager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(layoutManager);

        if (adapter == null) {
            recreateAdapter();
        }

        if (recyclerView.getAdapter() == null) {
            applyAdapter();
        }
    }

    private void restore(@Nullable Bundle savedInstanceState) {
        int intViewType = savedInstanceState.getInt("viewType");
        viewType = ViewType.values()[intViewType];
        recreateAdapter();
        restoreAdapter(savedInstanceState);
    }

    private void restoreAdapter(@Nullable Bundle savedInstanceState) {
        Parcelable parcelable = savedInstanceState.getParcelable("adapter");
        if (viewType == ViewType.Sets) {
            getSetAdapter().onRestoreInstanceState(parcelable);
        } else {
            getWordAdapter().onRestoreInstanceState(parcelable);
        }
    }
{'fraction_non_alphanumeric': 0.08590751233778103, 'fraction_numerical': 0.0010966916468652897, 'mean_word_length': 3.295133437990581, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2897766', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1425, 'n_words': 295}