<commit_before>package io.mokshjn.cosmo.activities;

import android.Manifest;
import android.app.ActivityOptions;
import android.app.SearchManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnLongClick;
import io.mokshjn.cosmo.R;
import io.mokshjn.cosmo.fragments.AlbumFragment;
import io.mokshjn.cosmo.fragments.SongsFragment;
import io.mokshjn.cosmo.helpers.LogHelper;
import io.mokshjn.cosmo.transitions.FabTransform;
import io.mokshjn.cosmo.utils.SettingsUtils;

public class CosmoActivity extends BaseActivity implements SongsFragment.MediaFragmentListener {

    public static final String EXTRA_START_FULLSCREEN =
            "io.mokshjn.cosmo.EXTRA_START_FULLSCREEN";

    public static final String EXTRA_CURRENT_MEDIA_DESCRIPTION =
            "io.mokshjn.cosmo.CURRENT_MEDIA_DESCRIPTION";

    private static final String TAG = LogHelper.makeLogTag(MainActivity.class);
    private static final String SAVED_MEDIA_ID = "io.mokshjn.cosmo.MEDIA_ID";
    private static final int RC_SEARCH = 0;
    private static final int PERMISSION_REQUEST_CODE = 1;
    @BindView(R.id.fab)
    FloatingActionButton fab;
    @BindView(R.id.main_content)
    ViewPager mViewPager;
    @BindView(R.id.navigation)
    BottomNavigationView navigation;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    private Bundle mVoiceSearchParams;
    private PagerAdapter mPagerAdapter;

    private ViewPager.OnPageChangeListener pageChangeListener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    };

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.navigation_songs:
                    return true;
                case R.id.navigation_albums:
                    return true;
            }
            return false;
        }

    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cosmo);
        ButterKnife.bind(this);

        if (!checkPermission()) {
            askPermission();
        } else {
            initializeMediaBrowser();
            setupViews();
        }
        initializeFromParams(savedInstanceState, getIntent());
        if (savedInstanceState == null) {
            startFullScreenActivityIfNeeded(getIntent());
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        LogHelper.d(TAG, "onNewIntent, intent=" + intent);
        initializeFromParams(null, intent);
        startFullScreenActivityIfNeeded(intent);
    }

    private void askPermission() {
        if (ActivityCompat.shouldShowRequestPermissionRationale(CosmoActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
            Toast.makeText(CosmoActivity.this, "Write External Storage permission allows us to read songs. Please allow this permission in App Settings.", Toast.LENGTH_LONG).show();
        } else {
            ActivityCompat.requestPermissions(CosmoActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
        }
    }

    private boolean checkPermission() {
        int result = ContextCompat.checkSelfPermission(CosmoActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE);
        return result == PackageManager.PERMISSION_GRANTED;
    }

    private void setupViews() {
        mPagerAdapter = new PagerAdapter(getSupportFragmentManager());

        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
        mViewPager.setAdapter(mPagerAdapter);
        setSupportActionBar(toolbar);
        initializeToolbar();
        setTitle("Cosmo");
    }

    protected void initializeFromParams(Bundle savedInstanceState, Intent intent) {
        // check if we were started from a "Play XYZ" voice search. If so, we save the extras
        // (which contain the query details) in a parameter, so we can reuse it later, when the
        // MediaSession is connected.
        if (intent.getAction() != null
                && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) {
            mVoiceSearchParams = intent.getExtras();
            LogHelper.d(TAG, "Starting from voice search query=",
                    mVoiceSearchParams.getString(SearchManager.QUERY));
        }
    }<commit_msg>implement bottom navbar<commit_after>package io.mokshjn.cosmo.activities;

import android.Manifest;
import android.app.ActivityOptions;
import android.app.SearchManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnLongClick;
import io.mokshjn.cosmo.R;
import io.mokshjn.cosmo.fragments.AlbumFragment;
import io.mokshjn.cosmo.fragments.SongsFragment;
import io.mokshjn.cosmo.helpers.LogHelper;
import io.mokshjn.cosmo.transitions.FabTransform;
import io.mokshjn.cosmo.utils.SettingsUtils;

public class CosmoActivity extends BaseActivity implements SongsFragment.MediaFragmentListener {

    public static final String EXTRA_START_FULLSCREEN =
            "io.mokshjn.cosmo.EXTRA_START_FULLSCREEN";

    public static final String EXTRA_CURRENT_MEDIA_DESCRIPTION =
            "io.mokshjn.cosmo.CURRENT_MEDIA_DESCRIPTION";

    private static final String TAG = LogHelper.makeLogTag(MainActivity.class);
    private static final String SAVED_MEDIA_ID = "io.mokshjn.cosmo.MEDIA_ID";
    private static final int RC_SEARCH = 0;
    private static final int PERMISSION_REQUEST_CODE = 1;
    @BindView(R.id.fab)
    FloatingActionButton fab;
    @BindView(R.id.main_content)
    ViewPager mViewPager;
    @BindView(R.id.navigation)
    BottomNavigationView navigation;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    private Bundle mVoiceSearchParams;
    private PagerAdapter mPagerAdapter;

    private ViewPager.OnPageChangeListener pageChangeListener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }
        @Override
        public void onPageScrollStateChanged(int state) {
        }
        @Override
        public void onPageSelected(int position) {
            switch (position) {
                case 0:
                    navigation.setSelectedItemId(R.id.navigation_songs);
                    break;
                case 1:
                    navigation.setSelectedItemId(R.id.navigation_albums);
                    break;
            }
        }
    };

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.navigation_songs:
                    mViewPager.setCurrentItem(0, true);
                    return true;
                case R.id.navigation_albums:
                    mViewPager.setCurrentItem(1, true);
                    return true;
            }
            return false;
        }

    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cosmo);
        ButterKnife.bind(this);

        if (!checkPermission()) {
            askPermission();
        } else {
            initializeMediaBrowser();
            setupViews();
        }
        initializeFromParams(savedInstanceState, getIntent());
        if (savedInstanceState == null) {
            startFullScreenActivityIfNeeded(getIntent());
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        LogHelper.d(TAG, "onNewIntent, intent=" + intent);
        initializeFromParams(null, intent);
        startFullScreenActivityIfNeeded(intent);
    }

    private void askPermission() {
        if (ActivityCompat.shouldShowRequestPermissionRationale(CosmoActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
            Toast.makeText(CosmoActivity.this, "Write External Storage permission allows us to read songs. Please allow this permission in App Settings.", Toast.LENGTH_LONG).show();
        } else {
            ActivityCompat.requestPermissions(CosmoActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
        }
    }

    private boolean checkPermission() {
        int result = ContextCompat.checkSelfPermission(CosmoActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE);
        return result == PackageManager.PERMISSION_GRANTED;
    }

    private void setupViews() {
        mPagerAdapter = new PagerAdapter(getSupportFragmentManager());

        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
        mViewPager.setAdapter(mPagerAdapter);
        mViewPager.setOnPageChangeListener(pageChangeListener);

        setSupportActionBar(toolbar);
        initializeToolbar();
        setTitle("Cosmo");
    }

    protected void initializeFromParams(Bundle savedInstanceState, Intent intent) {
        // check if we were started from a "Play XYZ" voice search. If so, we save the extras
        // (which contain the query details) in a parameter, so we can reuse it later, when the
        // MediaSession is connected.
        if (intent.getAction() != null
                && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) {
            mVoiceSearchParams = intent.getExtras();
            LogHelper.d(TAG, "Starting from voice search query=",
                    mVoiceSearchParams.getString(SearchManager.QUERY));
        }
    }
{'fraction_non_alphanumeric': 0.08225144484462685, 'fraction_numerical': 0.0021777368288801407, 'mean_word_length': 3.25972172672137, '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': '1791763', 'n_tokens_mistral': 3333, 'n_tokens_neox': 3220, 'n_words': 643}