<commit_before>package org.sugr.gearshift;

import java.io.File;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import android.content.Context;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.content.Loader;
import android.text.Html;
import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;

/**
 * A fragment representing a single Torrent detail screen.
 * This fragment is either contained in a {@link TorrentListActivity}
 * in two-pane mode (on tablets) or a {@link TorrentDetailActivity}
 * on handsets.
 */
/* TODO: Use this class to hold the view pager. Place the options menu and loader here.
 * Create a new TorrentDetailPagerFragment class for the individual pages */
public class TorrentDetailPageFragment extends Fragment {
    private Torrent mTorrent;
    private List<String> mPriorityNames;
    private List<String> mPriorityValues;
    private List<String> mSeedRatioModeValues;

    private Object[] mTextValues = {
        "", "", "", "", ""
    };
    private static final int QUEUE_POSITION = 0;
    private static final int DOWNLOAD_LIMIT = 1;
    private static final int UPLOAD_LIMIT = 2;
    private static final int SEED_RATIO_LIMIT = 3;
    private static final int PEER_LIMIT = 4;

    private static final String STATE_EXPANDED = "expanded_states";
    private static final String STATE_SCROLL_POSITION = "scroll_position_state";

    private static class Expanders {
        public static final int TOTAL_EXPANDERS = 3;

        public static final int OVERVIEW = 0;
        public static final int FILES = 1;
        public static final int LIMITS = 2;
    }

    private boolean[] mExpandedStates = new boolean[Expanders.TOTAL_EXPANDERS];

    private View.OnClickListener mExpanderListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            View image;
            View content;
            int index;
            switch(v.getId()) {
                case R.id.torrent_detail_overview_expander:
                    image = v.findViewById(R.id.torrent_detail_overview_expander_image);
                    content = getView().findViewById(R.id.torrent_detail_overview_content);
                    index = Expanders.OVERVIEW;
                    break;
                case R.id.torrent_detail_files_expander:
                    image = v.findViewById(R.id.torrent_detail_files_expander_image);
                    content = getView().findViewById(R.id.torrent_detail_files_content);
                    index = Expanders.FILES;
                    break;
                case R.id.torrent_detail_limits_expander:
                    image = v.findViewById(R.id.torrent_detail_limits_expander_image);
                    content = getView().findViewById(R.id.torrent_detail_limits_content);
                    index = Expanders.LIMITS;
                    break;
                default:
                    return;
            }

            if (content.getVisibility() == View.GONE) {
                content.setVisibility(View.VISIBLE);
                image.setBackgroundResource(R.drawable.ic_section_collapse);
                mExpandedStates[index] = true;
                updateFields(getView());
            } else {
                content.setVisibility(View.GONE);
                image.setBackgroundResource(R.drawable.ic_section_expand);
                mExpandedStates[index] = false;
            }

        }
    };

    private FilesAdapter mFilesAdapter;
    private FilesDataSetObserver mFilesObserver;

    private ActionMode mActionMode;
    Set<View> mSelectedFiles = new HashSet<View>();

    private ActionMode.Callback mActionModeFiles = new ActionMode.Callback() {

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            mActionMode = null;
            for (View v : mSelectedFiles) {
                v.setActivated(false);
            }
            mSelectedFiles.clear();
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.getMenuInflater().inflate(R.menu.torrent_detail_file_multiselect, menu);
            return true;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            String priorityKey;
            int priority;
            switch (item.getItemId()) {
                case R.id.select_all:
                    List<View> files = mFilesAdapter.getViews();

                    for (View v : files) {
                        if (v != null) {
                            if (!v.isActivated()) {
                                v.setActivated(true);
                                mSelectedFiles.add(v);
                            }
                        }
                    }

                    return true;
                case R.id.priority_low:
                    priorityKey = Torrent.SetterFields.FILES_LOW;
                    priority = Torrent.Priority.LOW;
                    break;
                case R.id.priority_normal:
                    priorityKey = Torrent.SetterFields.FILES_NORMAL;
                    priority = Torrent.Priority.NORMAL;
                    break;
                case R.id.priority_high:
                    priorityKey = Torrent.SetterFields.FILES_HIGH;
                    priority = Torrent.Priority.HIGH;
                    break;
                default:
                    return false;
            }
            List<View> allViews = mFilesAdapter.getViews();
            List<Integer> indexes = new ArrayList<Integer>();
            for (View v : mSelectedFiles) {
                indexes.add(mFilesAdapter.getItem(allViews.indexOf(v)).index);
            }
            mFilesAdapter.notifyDataSetChanged();
            setTorrentProperty(priorityKey, indexes);
            return true;
        }
    };

    /**
     * Mandatory empty constructor for the fragment manager to instantiate the
     * fragment (e.g. upon screen orientation changes).
     */
    public TorrentDetailPageFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mExpandedStates[Expanders.OVERVIEW] = true;

        if (getArguments().containsKey(TorrentDetailFragment.ARG_PAGE_POSITION)) {
            int position = getArguments().getInt(TorrentDetailFragment.ARG_PAGE_POSITION);
            ArrayList<Torrent> torrents = ((TransmissionSessionInterface) getActivity()).getTorrents();
<commit_msg>remove unused<commit_after>package org.sugr.gearshift;

import java.io.File;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import android.content.Context;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.content.Loader;
import android.text.Html;
import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;

/**
 * A fragment representing a single Torrent detail screen.
 * This fragment is either contained in a {@link TorrentListActivity}
 * in two-pane mode (on tablets) or a {@link TorrentDetailActivity}
 * on handsets.
 */
/* TODO: Use this class to hold the view pager. Place the options menu and loader here.
 * Create a new TorrentDetailPagerFragment class for the individual pages */
public class TorrentDetailPageFragment extends Fragment {
    private Torrent mTorrent;
    private List<String> mPriorityNames;
    private List<String> mPriorityValues;
    private List<String> mSeedRatioModeValues;

    private Object[] mTextValues = {
        "", "", "", "", ""
    };
    private static final int QUEUE_POSITION = 0;
    private static final int DOWNLOAD_LIMIT = 1;
    private static final int UPLOAD_LIMIT = 2;
    private static final int SEED_RATIO_LIMIT = 3;
    private static final int PEER_LIMIT = 4;

    private static final String STATE_EXPANDED = "expanded_states";
    private static final String STATE_SCROLL_POSITION = "scroll_position_state";

    private static class Expanders {
        public static final int TOTAL_EXPANDERS = 3;

        public static final int OVERVIEW = 0;
        public static final int FILES = 1;
        public static final int LIMITS = 2;
    }

    private boolean[] mExpandedStates = new boolean[Expanders.TOTAL_EXPANDERS];

    private View.OnClickListener mExpanderListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            View image;
            View content;
            int index;
            switch(v.getId()) {
                case R.id.torrent_detail_overview_expander:
                    image = v.findViewById(R.id.torrent_detail_overview_expander_image);
                    content = getView().findViewById(R.id.torrent_detail_overview_content);
                    index = Expanders.OVERVIEW;
                    break;
                case R.id.torrent_detail_files_expander:
                    image = v.findViewById(R.id.torrent_detail_files_expander_image);
                    content = getView().findViewById(R.id.torrent_detail_files_content);
                    index = Expanders.FILES;
                    break;
                case R.id.torrent_detail_limits_expander:
                    image = v.findViewById(R.id.torrent_detail_limits_expander_image);
                    content = getView().findViewById(R.id.torrent_detail_limits_content);
                    index = Expanders.LIMITS;
                    break;
                default:
                    return;
            }

            if (content.getVisibility() == View.GONE) {
                content.setVisibility(View.VISIBLE);
                image.setBackgroundResource(R.drawable.ic_section_collapse);
                mExpandedStates[index] = true;
                updateFields(getView());
            } else {
                content.setVisibility(View.GONE);
                image.setBackgroundResource(R.drawable.ic_section_expand);
                mExpandedStates[index] = false;
            }

        }
    };

    private FilesAdapter mFilesAdapter;
    private FilesDataSetObserver mFilesObserver;

    private ActionMode mActionMode;
    Set<View> mSelectedFiles = new HashSet<View>();

    private ActionMode.Callback mActionModeFiles = new ActionMode.Callback() {

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            mActionMode = null;
            for (View v : mSelectedFiles) {
                v.setActivated(false);
            }
            mSelectedFiles.clear();
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.getMenuInflater().inflate(R.menu.torrent_detail_file_multiselect, menu);
            return true;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            String priorityKey;
            switch (item.getItemId()) {
                case R.id.select_all:
                    List<View> files = mFilesAdapter.getViews();

                    for (View v : files) {
                        if (v != null) {
                            if (!v.isActivated()) {
                                v.setActivated(true);
                                mSelectedFiles.add(v);
                            }
                        }
                    }

                    return true;
                case R.id.priority_low:
                    priorityKey = Torrent.SetterFields.FILES_LOW;
                    break;
                case R.id.priority_normal:
                    priorityKey = Torrent.SetterFields.FILES_NORMAL;
                    break;
                case R.id.priority_high:
                    priorityKey = Torrent.SetterFields.FILES_HIGH;
                    break;
                default:
                    return false;
            }
            List<View> allViews = mFilesAdapter.getViews();
            List<Integer> indexes = new ArrayList<Integer>();
            for (View v : mSelectedFiles) {
                indexes.add(mFilesAdapter.getItem(allViews.indexOf(v)).index);
            }
            mFilesAdapter.notifyDataSetChanged();
            setTorrentProperty(priorityKey, indexes);
            return true;
        }
    };

    /**
     * Mandatory empty constructor for the fragment manager to instantiate the
     * fragment (e.g. upon screen orientation changes).
     */
    public TorrentDetailPageFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mExpandedStates[Expanders.OVERVIEW] = true;

        if (getArguments().containsKey(TorrentDetailFragment.ARG_PAGE_POSITION)) {
            int position = getArguments().getInt(TorrentDetailFragment.ARG_PAGE_POSITION);
            ArrayList<Torrent> torrents = ((TransmissionSessionInterface) getActivity()).getTorrents();

{'fraction_non_alphanumeric': 0.08111043236272314, 'fraction_numerical': 0.0014932464535396728, 'mean_word_length': 2.1302315700021244, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '6642655', 'n_tokens_mistral': 3935, 'n_tokens_neox': 3727, 'n_words': 867}