<commit_before>/*
 * Copyright (c) 2011 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package uk.org.ngo.squeezer.itemlist;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.MenuItem;
import android.view.View;
import android.widget.ExpandableListView;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import uk.org.ngo.squeezer.R;
import uk.org.ngo.squeezer.framework.ItemListActivity;
import uk.org.ngo.squeezer.itemlist.dialog.PlayerSyncDialog;
import uk.org.ngo.squeezer.model.Player;
import uk.org.ngo.squeezer.model.PlayerState;
import uk.org.ngo.squeezer.service.ISqueezeService;
import uk.org.ngo.squeezer.service.event.HandshakeComplete;
import uk.org.ngo.squeezer.service.event.PlayerStateChanged;
import uk.org.ngo.squeezer.service.event.PlayerVolume;


public class PlayerListActivity extends ItemListActivity implements
        PlayerSyncDialog.PlayerSyncDialogHost {
    private static final String CURRENT_PLAYER = "currentPlayer";

    private ExpandableListView mResultsExpandableListView;

    private PlayerListAdapter mResultsAdapter;

    private Player currentPlayer;
    private boolean mTrackingTouch;

    /** An update arrived while tracking touches. UI should be re-synced. */
    private boolean mUpdateWhileTracking = false;

    /** Map from player IDs to Players synced to that player ID. */
    private final Multimap<String, Player> mPlayerSyncGroups = HashMultimap.create();

    /**
     * Updates the adapter with the current players, and ensures that the list view is
     * expanded.
     */
    private void updateAndExpandPlayerList() {
        // Can't do anything if the adapter hasn't been set (pre-handshake).
        if (mResultsExpandableListView.getAdapter() == null) {
            return;
        }

        updateSyncGroups(getService().getPlayers(), getService().getActivePlayer());
        mResultsAdapter.setSyncGroups(mPlayerSyncGroups);

        for (int i = 0; i < mResultsAdapter.getGroupCount(); i++) {
            mResultsExpandableListView.expandGroup(i);
        }
    }

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

        setContentView(R.layout.item_list_players);
        if (savedInstanceState != null)
            currentPlayer = savedInstanceState.getParcelable(CURRENT_PLAYER);

        mResultsAdapter = new PlayerListAdapter(this);
        mResultsExpandableListView = (ExpandableListView) findViewById(R.id.expandable_list);

        mResultsExpandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
                                        int childPosition, long id) {
                mResultsAdapter.onChildClick(groupPosition, childPosition);
                return true;
            }
        });

        // Disable collapsing the list.
        mResultsExpandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition,
                    long id) {
                return true;
            }
        });

        mResultsExpandableListView.setOnCreateContextMenuListener(mResultsAdapter);
        mResultsExpandableListView.setOnScrollListener(new ItemListActivity.ScrollListener());

        setIgnoreVolumeChange(true);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putParcelable(CURRENT_PLAYER, currentPlayer);
        super.onSaveInstanceState(outState);
    }<commit_msg>add the navigationdrawer to the playerlistactivity<commit_after>/*
 * Copyright (c) 2011 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package uk.org.ngo.squeezer.itemlist;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.MenuItem;
import android.view.View;
import android.widget.ExpandableListView;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import uk.org.ngo.squeezer.R;
import uk.org.ngo.squeezer.framework.ItemListActivity;
import uk.org.ngo.squeezer.itemlist.dialog.PlayerSyncDialog;
import uk.org.ngo.squeezer.model.Player;
import uk.org.ngo.squeezer.model.PlayerState;
import uk.org.ngo.squeezer.service.ISqueezeService;
import uk.org.ngo.squeezer.service.event.HandshakeComplete;
import uk.org.ngo.squeezer.service.event.PlayerStateChanged;
import uk.org.ngo.squeezer.service.event.PlayerVolume;


public class PlayerListActivity extends ItemListActivity implements
        PlayerSyncDialog.PlayerSyncDialogHost {
    private static final String CURRENT_PLAYER = "currentPlayer";

    private ExpandableListView mResultsExpandableListView;

    private PlayerListAdapter mResultsAdapter;

    private Player currentPlayer;
    private boolean mTrackingTouch;

    /** An update arrived while tracking touches. UI should be re-synced. */
    private boolean mUpdateWhileTracking = false;

    /** Map from player IDs to Players synced to that player ID. */
    private final Multimap<String, Player> mPlayerSyncGroups = HashMultimap.create();

    /**
     * Updates the adapter with the current players, and ensures that the list view is
     * expanded.
     */
    private void updateAndExpandPlayerList() {
        // Can't do anything if the adapter hasn't been set (pre-handshake).
        if (mResultsExpandableListView.getAdapter() == null) {
            return;
        }

        updateSyncGroups(getService().getPlayers(), getService().getActivePlayer());
        mResultsAdapter.setSyncGroups(mPlayerSyncGroups);

        for (int i = 0; i < mResultsAdapter.getGroupCount(); i++) {
            mResultsExpandableListView.expandGroup(i);
        }
    }

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

        setContentView(R.layout.item_list_players);
        if (savedInstanceState != null)
            currentPlayer = savedInstanceState.getParcelable(CURRENT_PLAYER);

        mResultsAdapter = new PlayerListAdapter(this);
        mResultsExpandableListView = (ExpandableListView) findViewById(R.id.expandable_list);

        mResultsExpandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
                                        int childPosition, long id) {
                mResultsAdapter.onChildClick(groupPosition, childPosition);
                return true;
            }
        });

        // Disable collapsing the list.
        mResultsExpandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition,
                    long id) {
                return true;
            }
        });

        mResultsExpandableListView.setOnCreateContextMenuListener(mResultsAdapter);
        mResultsExpandableListView.setOnScrollListener(new ItemListActivity.ScrollListener());

        setIgnoreVolumeChange(true);

        NavigationDrawer(savedInstanceState);
        navigationDrawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle(R.string.home_item_songs);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putParcelable(CURRENT_PLAYER, currentPlayer);
        super.onSaveInstanceState(outState);
    }
{'fraction_non_alphanumeric': 0.08217377013257368, 'fraction_numerical': 0.0019721704831817686, 'mean_word_length': 3.399036144578313, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6818557', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2356, 'n_words': 599}