<commit_before>package com.example.spartahack.spartahack2016.Fragment;


import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.spartahack.spartahack2016.Adapters.CompanyListAdapter;
import com.example.spartahack.spartahack2016.Adapters.SimpleSectionedRecyclerViewAdapter;
import com.example.spartahack.spartahack2016.Model.Company;
import com.example.spartahack.spartahack2016.R;
import com.example.spartahack.spartahack2016.Retrofit.GSONMock;
import com.example.spartahack.spartahack2016.Retrofit.ParseAPIService;

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

import butterknife.Bind;
import butterknife.ButterKnife;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;

/**
 * Fragments that displays the companies that are sponsors of our great event
 */
public class CompanyFragment extends BaseFragment {

    /** Recycler view that displays all objects */
    @Bind(android.R.id.list) RecyclerView recyclerView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_company, container, false);

        ButterKnife.bind(this, view);

        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        ParseAPIService.INSTANCE.getRestAdapter().getCompany()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<GSONMock.Companies>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("CompanyFragment", e.toString());
                    }

                    @Override
                    public void onNext(GSONMock.Companies company) {
                        
                        // get results as array list 
                        ArrayList<Company> companies = company.companies;
                        
                        // TODO: 1/5/16 handle if list of companies returns empty/ null
                        if (companies == null || companies.isEmpty()) 
                            return;
                        Collections.sort(company.companies, new Comparator<Company>() {
                                    @Override
                                    public int compare(Company lhs, Company rhs) {
                                        if (lhs.getLevel() - rhs.getLevel() != 0)
                                            return lhs.getLevel() - rhs.getLevel();
                                        return lhs.getName().compareTo(rhs.getName());
                                    }
                                });

                        CompanyListAdapter simpleCompanyAdapter = new CompanyListAdapter(getActivity(), companies);

                        ArrayList<SimpleSectionedRecyclerViewAdapter.Section> sections = new ArrayList<>();

                        // add section header for first tier that has sponsors
//                        sections.add(new SimpleSectionedRecyclerViewAdapter.Section(0, companies.get(0).getLevelName()));

                        // the level from the last header used to track what level needs to add a header next
                        int companyLevelTemp = -1;

                        // location the header should go at
                        int sectionLoc = 0;
                        for (Company c : companies){
                            if (c.getLevel() != companyLevelTemp){
                                sections.add(new SimpleSectionedRecyclerViewAdapter.Section(sectionLoc, c.getLevelName()));
                                companyLevelTemp = c.getLevel();
                            }
                            sectionLoc++;
                        }<commit_msg>dumb sort error<commit_after>package com.example.spartahack.spartahack2016.Fragment;


import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.spartahack.spartahack2016.Adapters.CompanyListAdapter;
import com.example.spartahack.spartahack2016.Adapters.SimpleSectionedRecyclerViewAdapter;
import com.example.spartahack.spartahack2016.Model.Company;
import com.example.spartahack.spartahack2016.R;
import com.example.spartahack.spartahack2016.Retrofit.GSONMock;
import com.example.spartahack.spartahack2016.Retrofit.ParseAPIService;

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

import butterknife.Bind;
import butterknife.ButterKnife;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;

/**
 * Fragments that displays the companies that are sponsors of our great event
 */
public class CompanyFragment extends BaseFragment {

    /** Recycler view that displays all objects */
    @Bind(android.R.id.list) RecyclerView recyclerView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_company, container, false);

        ButterKnife.bind(this, view);

        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        ParseAPIService.INSTANCE.getRestAdapter().getCompany()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<GSONMock.Companies>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("CompanyFragment", e.toString());
                    }

                    @Override
                    public void onNext(GSONMock.Companies company) {
                        
                        // get results as array list 
                        ArrayList<Company> companies = company.companies;
                        
                        // TODO: 1/5/16 handle if list of companies returns empty/ null
                        if (companies == null || companies.isEmpty()) 
                            return;
                        Collections.sort(companies, new Comparator<Company>() {
                                    @Override
                                    public int compare(Company lhs, Company rhs) {
                                        if (lhs.getLevel() - rhs.getLevel() != 0)
                                            return lhs.getLevel() - rhs.getLevel();
                                        return lhs.getName().compareTo(rhs.getName());
                                    }
                                });

                        CompanyListAdapter simpleCompanyAdapter = new CompanyListAdapter(getActivity(), companies);

                        ArrayList<SimpleSectionedRecyclerViewAdapter.Section> sections = new ArrayList<>();

                        // add section header for first tier that has sponsors
//                        sections.add(new SimpleSectionedRecyclerViewAdapter.Section(0, companies.get(0).getLevelName()));

                        // the level from the last header used to track what level needs to add a header next
                        int companyLevelTemp = -1;

                        // location the header should go at
                        int sectionLoc = 0;
                        for (Company c : companies){
                            if (c.getLevel() != companyLevelTemp){
                                sections.add(new SimpleSectionedRecyclerViewAdapter.Section(sectionLoc, c.getLevelName()));
                                companyLevelTemp = c.getLevel();
                            }
                            sectionLoc++;
                        }
{'fraction_non_alphanumeric': 0.07893468305615811, 'fraction_numerical': 0.009399855386840203, 'mean_word_length': 1.7174197773411919, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5632463', 'n_tokens_mistral': 2068, 'n_tokens_neox': 1870, 'n_words': 436}