<commit_before>package org.sugr.gearshift;

import java.util.ArrayList;
import java.util.Arrays;

import org.sugr.gearshift.TransmissionSessionManager.TransmissionExclusionStrategy;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;
import android.support.v4.view.ViewPager;
import android.view.MenuItem;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;


/**
 * An activity representing a single Torrent detail screen. This
 * activity is only used on handset devices. On tablet-size devices,
 * item details are presented side-by-side with a list of items
 * in a {@link TorrentListActivity}.
 * <p>
 * This activity is mostly just a 'shell' activity containing nothing
 * more than a {@link TorrentDetailFragment}.
 */
public class TorrentDetailActivity extends FragmentActivity implements TransmissionSessionInterface {
    public static final String ARG_TORRENT_ID = "torrent_id";
    public static final String ARG_JSON_TORRENTS = "json_torrents";

	private ViewPager mPager;
	
    private ArrayList<Torrent> mTorrents = new ArrayList<Torrent>();
    
    /* TODO: create transmissionsessionloader and callback */
		
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_torrent_detail);

        // Show the Up button in the action bar.
        getActionBar().setDisplayHomeAsUpEnabled(true);
        
        Gson gson = new GsonBuilder().setExclusionStrategies(new TransmissionExclusionStrategy()).create();
        mTorrents = new ArrayList<Torrent>(Arrays.asList(
                gson.fromJson(getIntent().getStringExtra(ARG_JSON_TORRENTS), Torrent[].class)));
        
        mPager = (ViewPager) findViewById(R.id.torrent_detail_pager);
        mPager.setAdapter(new TorrentDetailPagerAdapter(this));

        // savedInstanceState is non-null when there is fragment state
        // saved from previous configurations of this activity
        // (e.g. when rotating the screen from portrait to landscape).
        // In this case, the fragment will automatically be re-added
        // to its container so we don't need to manually add it.
        // For more information, see the Fragments API guide at:
        //
        // http://developer.android.com/guide/components/fragments.html
        //
                
        if (savedInstanceState == null) {
            int id = getIntent().getIntExtra(ARG_TORRENT_ID, 0);
            for (int i = 0; i < mTorrents.size(); ++i) {
                Torrent t = mTorrents.get(i);
                if (t.getId() == id) {
                    mPager.setCurrentItem(i);
                    break;
                }<commit_msg>generate the torrent list before calling the support, or the fragment will not have access to that list<commit_after>package org.sugr.gearshift;

import java.util.ArrayList;
import java.util.Arrays;

import org.sugr.gearshift.TransmissionSessionManager.TransmissionExclusionStrategy;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;
import android.support.v4.view.ViewPager;
import android.view.MenuItem;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;


/**
 * An activity representing a single Torrent detail screen. This
 * activity is only used on handset devices. On tablet-size devices,
 * item details are presented side-by-side with a list of items
 * in a {@link TorrentListActivity}.
 * <p>
 * This activity is mostly just a 'shell' activity containing nothing
 * more than a {@link TorrentDetailFragment}.
 */
public class TorrentDetailActivity extends FragmentActivity implements TransmissionSessionInterface {
    public static final String ARG_TORRENT_ID = "torrent_id";
    public static final String ARG_JSON_TORRENTS = "json_torrents";

	private ViewPager mPager;
	
    private ArrayList<Torrent> mTorrents = new ArrayList<Torrent>();
    
    /* TODO: create transmissionsessionloader and callback */
		
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Gson gson = new GsonBuilder().setExclusionStrategies(new TransmissionExclusionStrategy()).create();
        mTorrents = new ArrayList<Torrent>(Arrays.asList(
                gson.fromJson(getIntent().getStringExtra(ARG_JSON_TORRENTS), Torrent[].class)));

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_torrent_detail);

        // Show the Up button in the action bar.
        getActionBar().setDisplayHomeAsUpEnabled(true);
        
        mPager = (ViewPager) findViewById(R.id.torrent_detail_pager);
        mPager.setAdapter(new TorrentDetailPagerAdapter(this));

        // savedInstanceState is non-null when there is fragment state
        // saved from previous configurations of this activity
        // (e.g. when rotating the screen from portrait to landscape).
        // In this case, the fragment will automatically be re-added
        // to its container so we don't need to manually add it.
        // For more information, see the Fragments API guide at:
        //
        // http://developer.android.com/guide/components/fragments.html
        //
                
        if (savedInstanceState == null) {
            int id = getIntent().getIntExtra(ARG_TORRENT_ID, 0);
            for (int i = 0; i < mTorrents.size(); ++i) {
                Torrent t = mTorrents.get(i);
                if (t.getId() == id) {
                    mPager.setCurrentItem(i);
                    break;
                }
{'fraction_non_alphanumeric': 0.08973906911142454, 'fraction_numerical': 0.001763046544428773, 'mean_word_length': 2.9894514767932487, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '5824807', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1519, 'n_words': 441}