<commit_before>package eu.ydp.empiria.player.client.module.media.button;

import com.google.inject.Inject;
import com.google.inject.Provider;

import eu.ydp.empiria.player.client.util.events.bus.EventsBus;
import eu.ydp.empiria.player.client.util.events.media.AbstractMediaEventHandler;
import eu.ydp.empiria.player.client.util.events.media.MediaEvent;
import eu.ydp.empiria.player.client.util.events.media.MediaEventTypes;
import eu.ydp.empiria.player.client.util.events.scope.CurrentPageScope;

public abstract class AbstractPlayMediaButton<T> extends AbstractMediaButton<T> {

	@Inject
	protected EventsBus eventsBus;

	@Inject
	private Provider<T> provider;

	public AbstractPlayMediaButton(String baseStyleName) {
		super(baseStyleName);
	}

	protected abstract MediaEvent createMediaEvent();

	protected abstract boolean initButtonStyleChangeHandlersCondition();

	@Override
	public void init() {
		super.init();
		if (initButtonStyleChangeHandlersCondition()) {
			initButtonStyleChangeHandlers();
		}
	}

	protected void initButtonStyleChangeHandlers() {
		AbstractMediaEventHandler handler = new AbstractMediaEventHandler() {
			@Override
			public void onMediaEvent(MediaEvent event) {
				if (event.getType() == MediaEventTypes.ON_PLAY) {
					setActive(true);
				} else {
					setActive(false);
				}
				changeStyleForClick();
			}
		};
		CurrentPageScope scope = createCurrentPageScope();
		eventsBus.addHandlerToSource(MediaEvent.getType(MediaEventTypes.ON_PAUSE), getMediaWrapper(), handler, scope);
		eventsBus.addHandlerToSource(MediaEvent.getType(MediaEventTypes.ON_END), getMediaWrapper(), handler, scope);
		eventsBus.addHandlerToSource(MediaEvent.getType(MediaEventTypes.ON_STOP), getMediaWrapper(), handler, scope);
		eventsBus.addHandlerToSource(MediaEvent.getType(MediaEventTypes.ON_PLAY), getMediaWrapper(), handler, scope);
	}

	protected CurrentPageScope createCurrentPageScope() {
		return new CurrentPageScope();
	}

	@Override
	protected void onClick() {
		MediaEvent mediaEvent = createMediaEvent();
		eventsBus.fireEventFromSource(mediaEvent, getMediaWrapper());
	}

	@Override
	public boolean isSupported() {
		return getMediaAvailableOptions().isPlaySupported();
	}

	@Override
	public T getNewInstance() {
		return provider.get();
	}

}<commit_msg>small refactoring - clean code issue YPUB-5075<commit_after>package eu.ydp.empiria.player.client.module.media.button;

import com.google.inject.Inject;
import com.google.inject.Provider;

import eu.ydp.empiria.player.client.util.events.bus.EventsBus;
import eu.ydp.empiria.player.client.util.events.media.AbstractMediaEventHandler;
import eu.ydp.empiria.player.client.util.events.media.MediaEvent;
import eu.ydp.empiria.player.client.util.events.media.MediaEventTypes;
import eu.ydp.empiria.player.client.util.events.scope.CurrentPageScope;

public abstract class AbstractPlayMediaButton<T> extends AbstractMediaButton<T> {

	@Inject
	protected EventsBus eventsBus;

	@Inject
	private Provider<T> provider;

	public AbstractPlayMediaButton(String baseStyleName) {
		super(baseStyleName);
	}

	protected abstract MediaEvent createMediaEvent();

	protected abstract boolean initButtonStyleChangeHandlersCondition();

	@Override
	public void init() {
		super.init();
		if (initButtonStyleChangeHandlersCondition()) {
			initButtonStyleChangeHandlers();
		}
	}

	@Override
	public boolean isSupported() {
		return getMediaAvailableOptions().isPlaySupported();
	}

	@Override
	public T getNewInstance() {
		return provider.get();
	}
	
	protected void initButtonStyleChangeHandlers() {
		AbstractMediaEventHandler handler = createAbstractMediaEventHandler();
		CurrentPageScope scope = createCurrentPageScope();
		addMediaEventHandlers(handler, scope);
	}

	protected CurrentPageScope createCurrentPageScope() {
		return new CurrentPageScope();
	}

	@Override
	protected void onClick() {
		MediaEvent mediaEvent = createMediaEvent();
		eventsBus.fireEventFromSource(mediaEvent, getMediaWrapper());
	}

	private void addMediaEventHandlers(AbstractMediaEventHandler handler, CurrentPageScope scope) {
		eventsBus.addHandlerToSource(MediaEvent.getType(MediaEventTypes.ON_PAUSE), getMediaWrapper(), handler, scope);
		eventsBus.addHandlerToSource(MediaEvent.getType(MediaEventTypes.ON_END), getMediaWrapper(), handler, scope);
		eventsBus.addHandlerToSource(MediaEvent.getType(MediaEventTypes.ON_STOP), getMediaWrapper(), handler, scope);
		eventsBus.addHandlerToSource(MediaEvent.getType(MediaEventTypes.ON_PLAY), getMediaWrapper(), handler, scope);
	}

	private AbstractMediaEventHandler createAbstractMediaEventHandler() {
		return new AbstractMediaEventHandler() {
			@Override
			public void onMediaEvent(MediaEvent event) {
				if (event.getType() == MediaEventTypes.ON_PLAY) {
					setActive(true);
				} else {
					setActive(false);
				}
				changeStyleForClick();
			}
		};
	}	
}
{'fraction_non_alphanumeric': 0.10318602261048304, 'fraction_numerical': 0.0008221993833504625, 'mean_word_length': 6.103649635036496, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6892780', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1425, 'n_words': 248}