<commit_before>/*
 * Copyright 2017 <NAME>
 *
 * 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 com.matthewtamlin.mixtape.example.activities;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;

import com.matthewtamlin.mixtape.example.R;
import com.matthewtamlin.mixtape.example.data.HeaderDataSource;
import com.matthewtamlin.mixtape.example.data.Mp3Song;
import com.matthewtamlin.mixtape.example.data.Mp3SongDataSource;
import com.matthewtamlin.mixtape.library.base_mvp.BaseDataSource;
import com.matthewtamlin.mixtape.library.caching.LibraryItemCache;
import com.matthewtamlin.mixtape.library.caching.LruLibraryItemCache;
import com.matthewtamlin.mixtape.library.data.DisplayableDefaults;
import com.matthewtamlin.mixtape.library.data.ImmutableDisplayableDefaults;
import com.matthewtamlin.mixtape.library.data.LibraryItem;
import com.matthewtamlin.mixtape.library.data.LibraryReadException;
import com.matthewtamlin.mixtape.library.databinders.ArtworkBinder;
import com.matthewtamlin.mixtape.library.databinders.SubtitleBinder;
import com.matthewtamlin.mixtape.library.databinders.TitleBinder;
import com.matthewtamlin.mixtape.library.mixtape_body.BodyContract;
import com.matthewtamlin.mixtape.library.mixtape_body.ListBody;
import com.matthewtamlin.mixtape.library.mixtape_body.RecyclerViewBodyPresenter;
import com.matthewtamlin.mixtape.library.mixtape_coordinator.CoordinatedMixtapeContainer;
import com.matthewtamlin.mixtape.library.mixtape_header.HeaderContract;
import com.matthewtamlin.mixtape.library.mixtape_header.SmallHeader;
import com.matthewtamlin.mixtape.library.mixtape_header.SmallHeaderPresenter;

import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class PlaylistActivity extends AppCompatActivity {
	private CoordinatedMixtapeContainer rootView;

	private SmallHeader header;

	private ListBody body;

	private HeaderDataSource headerDataSource;

	private Mp3SongDataSource bodyDataSource;

	private SmallHeaderPresenter<HeaderDataSource> headerPresenter;

	private RecyclerViewBodyPresenter<Mp3Song, Mp3SongDataSource> bodyPresenter;

	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.example_layout);

		setupHeaderView();
		setupBodyView();
		setupContainerView();

		setupDataSources();

		setupHeaderPresenter();
		setupBodyPresenter();

		precacheText();
	}

	private void setupHeaderView() {
		header = new SmallHeader(this);

		header.setOverflowMenuResource(R.menu.header_menu);

		header.setExtraButtons(new Bitmap[]{
				BitmapFactory.decodeResource(getResources(), R.drawable.ic_play),
				BitmapFactory.decodeResource(getResources(), R.drawable.ic_share),
				BitmapFactory.decodeResource(getResources(), R.drawable.ic_shuffle)
		});
	}

	private void setupBodyView() {
		body = new ListBody(this);
		body.setContextualMenuResource(R.menu.song_menu);
	}

	private void setupContainerView() {
		rootView = (CoordinatedMixtapeContainer) findViewById(R.id.example_layout_coordinator);

		rootView.setBody(body);
		rootView.setHeader(header);
		rootView.showHeaderAtStartOnly();
	}

	private void setupDataSources() {
		bodyDataSource = new Mp3SongDataSource();

		final Bitmap headerArtwork = BitmapFactory.decodeResource(getResources(),
				R.raw.header_artwork);
		headerDataSource = new HeaderDataSource("All Songs",
				"Various artists",
				new BitmapDrawable(getResources(), headerArtwork));
	}

	private void setupHeaderPresenter() {
		final Bitmap defaultArtwork = BitmapFactory.decodeResource(getResources(), R.raw
				.default_artwork);
		final DisplayableDefaults defaults = new ImmutableDisplayableDefaults("Playlist",
				"Unknown artists",
				new BitmapDrawable(getResources(), defaultArtwork));

		final LibraryItemCache cache = new LruLibraryItemCache(10000, 10000, 100000);
		final TitleBinder titleBinder = new TitleBinder(cache, defaults);
		final SubtitleBinder subtitleBinder = new SubtitleBinder(cache, defaults);
		final ArtworkBinder artworkBinder = new ArtworkBinder(cache, defaults);

		headerPresenter = new SmallHeaderPresenter<HeaderDataSource>
				(titleBinder, subtitleBinder, artworkBinder) {
			@Override
			public void onExtraButtonClicked(final HeaderContract.View headerView, final int index) {
				handleHeaderExtraButtonClicked(index);
			}
<commit_msg>Added support for changes to Mp3SongDataSource<commit_after>/*
 * Copyright 2017 <NAME>
 *
 * 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 com.matthewtamlin.mixtape.example.activities;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;

import com.matthewtamlin.mixtape.example.R;
import com.matthewtamlin.mixtape.example.data.HeaderDataSource;
import com.matthewtamlin.mixtape.example.data.Mp3Song;
import com.matthewtamlin.mixtape.example.data.Mp3SongDataSource;
import com.matthewtamlin.mixtape.library.base_mvp.BaseDataSource;
import com.matthewtamlin.mixtape.library.caching.LibraryItemCache;
import com.matthewtamlin.mixtape.library.caching.LruLibraryItemCache;
import com.matthewtamlin.mixtape.library.data.DisplayableDefaults;
import com.matthewtamlin.mixtape.library.data.ImmutableDisplayableDefaults;
import com.matthewtamlin.mixtape.library.data.LibraryItem;
import com.matthewtamlin.mixtape.library.data.LibraryReadException;
import com.matthewtamlin.mixtape.library.databinders.ArtworkBinder;
import com.matthewtamlin.mixtape.library.databinders.SubtitleBinder;
import com.matthewtamlin.mixtape.library.databinders.TitleBinder;
import com.matthewtamlin.mixtape.library.mixtape_body.BodyContract;
import com.matthewtamlin.mixtape.library.mixtape_body.ListBody;
import com.matthewtamlin.mixtape.library.mixtape_body.RecyclerViewBodyPresenter;
import com.matthewtamlin.mixtape.library.mixtape_coordinator.CoordinatedMixtapeContainer;
import com.matthewtamlin.mixtape.library.mixtape_header.HeaderContract;
import com.matthewtamlin.mixtape.library.mixtape_header.SmallHeader;
import com.matthewtamlin.mixtape.library.mixtape_header.SmallHeaderPresenter;

import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class PlaylistActivity extends AppCompatActivity {
	private CoordinatedMixtapeContainer rootView;

	private SmallHeader header;

	private ListBody body;

	private HeaderDataSource headerDataSource;

	private Mp3SongDataSource bodyDataSource;

	private SmallHeaderPresenter<HeaderDataSource> headerPresenter;

	private RecyclerViewBodyPresenter<Mp3Song, Mp3SongDataSource> bodyPresenter;

	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.example_layout);

		setupHeaderView();
		setupBodyView();
		setupContainerView();

		setupDataSources();

		setupHeaderPresenter();
		setupBodyPresenter();

		precacheText();
	}

	private void setupHeaderView() {
		header = new SmallHeader(this);

		header.setOverflowMenuResource(R.menu.header_menu);

		header.setExtraButtons(new Bitmap[]{
				BitmapFactory.decodeResource(getResources(), R.drawable.ic_play),
				BitmapFactory.decodeResource(getResources(), R.drawable.ic_share),
				BitmapFactory.decodeResource(getResources(), R.drawable.ic_shuffle)
		});
	}

	private void setupBodyView() {
		body = new ListBody(this);
		body.setContextualMenuResource(R.menu.song_menu);
	}

	private void setupContainerView() {
		rootView = (CoordinatedMixtapeContainer) findViewById(R.id.example_layout_coordinator);

		rootView.setBody(body);
		rootView.setHeader(header);
		rootView.showHeaderAtStartOnly();
	}

	private void setupDataSources() {
		bodyDataSource = new Mp3SongDataSource(getResources());

		final Bitmap headerArtwork = BitmapFactory.decodeResource(getResources(),
				R.raw.header_artwork);
		headerDataSource = new HeaderDataSource("All Songs",
				"Various artists",
				new BitmapDrawable(getResources(), headerArtwork));
	}

	private void setupHeaderPresenter() {
		final Bitmap defaultArtwork = BitmapFactory.decodeResource(getResources(), R.raw
				.default_artwork);
		final DisplayableDefaults defaults = new ImmutableDisplayableDefaults("Playlist",
				"Unknown artists",
				new BitmapDrawable(getResources(), defaultArtwork));

		final LibraryItemCache cache = new LruLibraryItemCache(10000, 10000, 100000);
		final TitleBinder titleBinder = new TitleBinder(cache, defaults);
		final SubtitleBinder subtitleBinder = new SubtitleBinder(cache, defaults);
		final ArtworkBinder artworkBinder = new ArtworkBinder(cache, defaults);

		headerPresenter = new SmallHeaderPresenter<HeaderDataSource>
				(titleBinder, subtitleBinder, artworkBinder) {
			@Override
			public void onExtraButtonClicked(final HeaderContract.View headerView, final int index) {
				handleHeaderExtraButtonClicked(index);
			}

{'fraction_non_alphanumeric': 0.0873438559116878, 'fraction_numerical': 0.006100513217778638, 'mean_word_length': 6.3352272727272725, 'pattern_counts': {'":': 0, '<': 11, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '263644', 'n_tokens_mistral': 3364, 'n_tokens_neox': 3030, 'n_words': 607}