<commit_before>package org.commcare.android.framework;

import org.commcare.android.adapters.EntityDetailAdapter;
import org.commcare.android.models.AndroidSessionWrapper;
import org.commcare.android.models.Entity;
import org.commcare.android.models.NodeEntityFactory;
import org.commcare.android.util.DetailCalloutListener;
import org.commcare.android.util.SerializationUtil;
import org.commcare.dalvik.R;
import org.commcare.dalvik.application.CommCareApplication;
import org.commcare.suite.model.Detail;
import org.javarosa.core.model.instance.TreeReference;
import org.odk.collect.android.views.media.AudioController;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

/**
 * Fragment to display Detail content. Not meant for handling nested Detail objects.
 * @author jschweers
 *
 */
public class EntityDetailFragment extends Fragment {
    public static final String CHILD_DETAIL_INDEX = "edf_child_detail_index";
    public static final String DETAIL_ID = "edf_detail_id";
    public static final String DETAIL_INDEX = "edf_detail_index";
    public static final String CHILD_REFERENCE = "edf_detail_reference";
    
    private AndroidSessionWrapper asw;
    private NodeEntityFactory factory;
    private EntityDetailAdapter adapter;
    private EntityDetailAdapter.EntityDetailViewModifier modifier;

    public EntityDetailFragment() {
        super();
        this.asw = CommCareApplication._().getCurrentSessionWrapper();
    }

    public void setEntityDetailModifier(EntityDetailAdapter.EntityDetailViewModifier edvm){
        this.modifier = edvm;
        if(adapter != null) {
            adapter.setModifier(edvm);
        }
    }
    
    /*
     * (non-Javadoc)
     * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Note that some of this setup could be moved into onAttach if it would help performance
        Bundle args = getArguments();

        Detail detail = asw.getSession().getDetail(args.getString(DETAIL_ID));
        Detail childDetail = detail;
        if (args.getInt(CHILD_DETAIL_INDEX, -1) != -1) {
            childDetail = detail.getDetails()[args.getInt(CHILD_DETAIL_INDEX)];
        }

        factory = new NodeEntityFactory(childDetail, asw.getEvaluationContext());
        Entity entity = factory.getEntity(SerializationUtil.deserializeFromBundle(
            args, CHILD_REFERENCE, TreeReference.class)
        );

        View rootView = inflater.inflate(R.layout.entity_detail_list, container, false);
        Activity thisActivity = getActivity();
        AudioController audioController  = null;
        DetailCalloutListener detailCalloutListener = null;
        if(thisActivity instanceof AudioController) {
            audioController = (AudioController)thisActivity;
        } 
        if(thisActivity instanceof DetailCalloutListener) {
            detailCalloutListener = (DetailCalloutListener)thisActivity;
        } 

        
        adapter = new EntityDetailAdapter(
            thisActivity, asw.getSession(), childDetail, entity, 
            detailCalloutListener, audioController, args.getInt(DETAIL_INDEX)
        );
        adapter.setModifier(modifier);
        final TextView header = (TextView) inflater.inflate(R.layout.entity_detail_header, null);
        final ListView listView = ((ListView) rootView.findViewById(R.id.screen_entity_detail_list));
        header.setText(detail.getTitle().getText().evaluate());
        listView.addHeaderView(header);
        listView.setAdapter(adapter);
        return rootView;
    }

}<commit_msg>Color for header row in drawer pulldown<commit_after>package org.commcare.android.framework;

import org.commcare.android.adapters.EntityDetailAdapter;
import org.commcare.android.models.AndroidSessionWrapper;
import org.commcare.android.models.Entity;
import org.commcare.android.models.NodeEntityFactory;
import org.commcare.android.util.AndroidUtil;
import org.commcare.android.util.DetailCalloutListener;
import org.commcare.android.util.SerializationUtil;
import org.commcare.dalvik.R;
import org.commcare.dalvik.application.CommCareApplication;
import org.commcare.suite.model.Detail;
import org.javarosa.core.model.instance.TreeReference;
import org.odk.collect.android.views.media.AudioController;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

/**
 * Fragment to display Detail content. Not meant for handling nested Detail objects.
 * @author jschweers
 *
 */
public class EntityDetailFragment extends Fragment {
    public static final String CHILD_DETAIL_INDEX = "edf_child_detail_index";
    public static final String DETAIL_ID = "edf_detail_id";
    public static final String DETAIL_INDEX = "edf_detail_index";
    public static final String CHILD_REFERENCE = "edf_detail_reference";
    
    private AndroidSessionWrapper asw;
    private NodeEntityFactory factory;
    private EntityDetailAdapter adapter;
    private EntityDetailAdapter.EntityDetailViewModifier modifier;

    public EntityDetailFragment() {
        super();
        this.asw = CommCareApplication._().getCurrentSessionWrapper();
    }

    public void setEntityDetailModifier(EntityDetailAdapter.EntityDetailViewModifier edvm){
        this.modifier = edvm;
        if(adapter != null) {
            adapter.setModifier(edvm);
        }
    }
    
    /*
     * (non-Javadoc)
     * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Note that some of this setup could be moved into onAttach if it would help performance
        Bundle args = getArguments();

        Detail detail = asw.getSession().getDetail(args.getString(DETAIL_ID));
        Detail childDetail = detail;
        if (args.getInt(CHILD_DETAIL_INDEX, -1) != -1) {
            childDetail = detail.getDetails()[args.getInt(CHILD_DETAIL_INDEX)];
        }

        factory = new NodeEntityFactory(childDetail, asw.getEvaluationContext());
        Entity entity = factory.getEntity(SerializationUtil.deserializeFromBundle(
            args, CHILD_REFERENCE, TreeReference.class)
        );

        View rootView = inflater.inflate(R.layout.entity_detail_list, container, false);
        Activity thisActivity = getActivity();
        AudioController audioController  = null;
        DetailCalloutListener detailCalloutListener = null;
        if(thisActivity instanceof AudioController) {
            audioController = (AudioController)thisActivity;
        } 
        if(thisActivity instanceof DetailCalloutListener) {
            detailCalloutListener = (DetailCalloutListener)thisActivity;
        } 

        
        adapter = new EntityDetailAdapter(
            thisActivity, asw.getSession(), childDetail, entity, 
            detailCalloutListener, audioController, args.getInt(DETAIL_INDEX)
        );
        adapter.setModifier(modifier);
        final TextView header = (TextView) inflater.inflate(R.layout.entity_detail_header, null);
        final ListView listView = ((ListView) rootView.findViewById(R.id.screen_entity_detail_list));
        header.setText(detail.getTitle().getText().evaluate());
        int[] color = AndroidUtil.getThemeColorIDs(this.getActivity(), new int[]{ R.attr.drawer_pulldown_even_row_color});
        header.setBackgroundColor(color[0]);
        listView.addHeaderView(header);
        listView.setAdapter(adapter);
        return rootView;
    }

}
{'fraction_non_alphanumeric': 0.08902077151335312, 'fraction_numerical': 0.001112759643916914, 'mean_word_length': 3.7248831775700935, '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': '4153288', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2165, 'n_words': 445}