<commit_before>package com.myhoard.app.element;

import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.android.gms.maps.model.LatLng;
import com.myhoard.app.R;
import com.myhoard.app.model.Item;
import com.myhoard.app.model.ItemLocation;
import com.myhoard.app.provider.DataProvider;
import com.myhoard.app.provider.DataStorage;
import com.myhoard.app.views.ElementFragmentPager;

/**
 * Created by <NAME> on 28.04.14.
 */
public class ElementReadFragment extends Fragment {

    private ElementFragmentPager pagerAdapter;
    private ViewPager pager;
    private long elementId;
    private TextView elementName, elementPosition, elementCollection, elementDescription;

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

        elementId = getArguments().getLong("elementId");
        getLoaderManager().initLoader(1, null, new LoaderImagesCallbacks());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        final View v = inflater.inflate(R.layout.fragment_element_read, container,
                false);

        elementName = (TextView) v.findViewById(R.id.tvElementName);
        elementCollection = (TextView) v.findViewById(R.id.tvElementCategory);
        elementDescription = (TextView) v.findViewById(R.id.tvElementDescription);
        elementPosition = (TextView) v.findViewById(R.id.tvElementLocalisation);
        elementPosition.setOnClickListener(listener);

        new AsyncElementRead().execute();

        pager = (ViewPager) v.findViewById(R.id.pager);

        return v;
    }

    private View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            pager.setCurrentItem(pagerAdapter.getCount(), true);
        }
    };

    private class LoaderImagesCallbacks implements
            LoaderManager.LoaderCallbacks<Cursor> {
        @Override
        public Loader<Cursor> onCreateLoader(int id, Bundle args) {
            String[] projection = {DataStorage.Media.FILE_NAME,
                    DataStorage.Media.CREATED_DATE, DataStorage.Media._ID,
                    DataStorage.Media.ID_ITEM};
            CursorLoader cursorLoader = new CursorLoader(getActivity(),
                    DataStorage.Media.CONTENT_URI, projection,
                    DataStorage.Media.ID_ITEM + " =? ",
                    new String[]{String.valueOf(elementId)},
                    DataStorage.Media.CREATED_DATE + " ASC");
            return cursorLoader;
        }

        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
            if(pagerAdapter == null) {
                pagerAdapter = new ElementFragmentPager(getChildFragmentManager(), data, null);
            }
            pagerAdapter.swapCursor(data);
        }

        @Override
        public void onLoaderReset(Loader<Cursor> loader) {
            pagerAdapter.swapCursor(null);
        }
    }

    private class AsyncElementRead extends AsyncTask<Void, Integer, Item> {<commit_msg>[FIX] NullPointerException in ElementReadFragment<commit_after>package com.myhoard.app.element;

import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.android.gms.maps.model.LatLng;
import com.myhoard.app.R;
import com.myhoard.app.model.Item;
import com.myhoard.app.model.ItemLocation;
import com.myhoard.app.provider.DataProvider;
import com.myhoard.app.provider.DataStorage;
import com.myhoard.app.views.ElementFragmentPager;

/**
 * Created by <NAME> on 28.04.14.
 */
public class ElementReadFragment extends Fragment {

    private ElementFragmentPager pagerAdapter;
    private ViewPager pager;
    private long elementId;
    private TextView elementName, elementPosition, elementCollection, elementDescription;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        elementId = getArguments().getLong("elementId");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        final View v = inflater.inflate(R.layout.fragment_element_read, container,
                false);

        elementName = (TextView) v.findViewById(R.id.tvElementName);
        elementCollection = (TextView) v.findViewById(R.id.tvElementCategory);
        elementDescription = (TextView) v.findViewById(R.id.tvElementDescription);
        elementPosition = (TextView) v.findViewById(R.id.tvElementLocalisation);
        elementPosition.setOnClickListener(listener);
        pager = (ViewPager) v.findViewById(R.id.pager);
        getLoaderManager().initLoader(1, null, new LoaderImagesCallbacks());
        return v;
    }

    private View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            pager.setCurrentItem(pagerAdapter.getCount(), true);
        }
    };

    private class LoaderImagesCallbacks implements
            LoaderManager.LoaderCallbacks<Cursor> {
        @Override
        public Loader<Cursor> onCreateLoader(int id, Bundle args) {
            String[] projection = {DataStorage.Media.FILE_NAME,
                    DataStorage.Media.CREATED_DATE, DataStorage.Media._ID,
                    DataStorage.Media.ID_ITEM};
            CursorLoader cursorLoader = new CursorLoader(getActivity(),
                    DataStorage.Media.CONTENT_URI, projection,
                    DataStorage.Media.ID_ITEM + " =? ",
                    new String[]{String.valueOf(elementId)},
                    DataStorage.Media.CREATED_DATE + " ASC");
            return cursorLoader;
        }

        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
            if(pagerAdapter == null) {
                pagerAdapter = new ElementFragmentPager(getChildFragmentManager(), data, null);
            }
            pagerAdapter.swapCursor(data);
            new AsyncElementRead().execute();
        }

        @Override
        public void onLoaderReset(Loader<Cursor> loader) {
            pagerAdapter.swapCursor(null);
        }
    }

    private class AsyncElementRead extends AsyncTask<Void, Integer, Item> {
{'fraction_non_alphanumeric': 0.09449259155717081, 'fraction_numerical': 0.0033547665641599105, 'mean_word_length': 2.953038674033149, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '376610', 'n_tokens_mistral': 1970, 'n_tokens_neox': 1874, 'n_words': 373}