<commit_before>package net.x4a42.volksempfaenger.service.playback;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import net.x4a42.volksempfaenger.data.entity.episode.Episode;
import net.x4a42.volksempfaenger.data.playlist.Playlist;

class PlaybackServiceProxy implements PlaybackEventListener, IntentParser.Listener
{
    public static final int                          NotificationId = 0x59d54313;
    private final BackgroundPositionSaver            positionSaver;
    private final Controller                         controller;
    private final IntentParser                       intentParser;
    private final MediaButtonReceiver                mediaButtonReceiver;
    private final MediaSessionManager                mediaSessionManager;
    private final NotificationManager                notificationManager;
    private final PlaybackNotificationBuilder        notificationBuilder;
    private final Playlist                           playlist;

    public PlaybackServiceProxy(BackgroundPositionSaver            positionSaver,
                                Controller                         controller,
                                IntentParser                       intentParser,
                                MediaButtonReceiver                mediaButtonReceiver,
                                MediaSessionManager                mediaSessionManager,
                                NotificationManager                notificationManager,
                                PlaybackNotificationBuilder        notificationBuilder,
                                Playlist                           playlist)
    {
        this.positionSaver              = positionSaver;
        this.controller                 = controller;
        this.intentParser               = intentParser;
        this.mediaButtonReceiver        = mediaButtonReceiver;
        this.mediaSessionManager        = mediaSessionManager;
        this.notificationManager        = notificationManager;
        this.notificationBuilder        = notificationBuilder;
        this.playlist                   = playlist;
    }

    public int onStartCommand(Intent intent)
    {
        // these come from app elements that want to change the state of the player
        // by either playing, pausing, or stopping

        intentParser.parse(intent);

        return Service.START_STICKY;
    }

    public void onDestroy()
    {
        controller.destroy();
        mediaButtonReceiver.destroy();
        if (mediaSessionManager != null)
        {
            mediaSessionManager.destroy();
        }
    }

    public IBinder onBind()
    {
        return new PlaybackServiceBinder(new PlaybackServiceFacade(controller));
    }

    @Override
    public void onPlaybackEvent(PlaybackEvent playbackEvent)
    {
        // these come from our own controller to let us know that it has changed state.
        switch (playbackEvent)
        {
            case PLAYING:
                handlePlaying();
                break;
            case PAUSED:
                handlePaused();
                break;
            case ENDED:
                handleEnded();
                break;
            default:
                // we ignore these
                break;
        }
    }

    @Override
    public void onPlay()
    {
        if (playlist.isEmpty())
        {
            return;
        }

        Episode episode = playlist.getCurrentEpisode();

        if (controller.isPlaybackEpisodeOpen(episode))
        {
            if (!controller.isPlaying())
            {
                controller.play();
            }
            return;
        }

        positionSaver.stop(false);
        controller.open(episode);
    }

    @Override
    public void onPause()
    {
        if (controller.isPlaying())
        {
            controller.pause();
        }
    }

    @Override
    public void onPlayPause()
    {
        if (!controller.isOpen())
        {
            return;
        }

        if (controller.isPlaying())
        {
            controller.pause();
        }
        else
        {
            controller.play();
        }
    }

    @Override
    public void onStop()
    {
        onPause();
        controller.stop();
        notificationManager.cancel(NotificationId);
    }

    @Override
    public void onSeek(int position)
    {
        if (controller.isOpen())
        {
            controller.seekTo(position);
        }
    }

    @Override<commit_msg>fix to play/pause button behavior<commit_after>package net.x4a42.volksempfaenger.service.playback;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import net.x4a42.volksempfaenger.data.entity.episode.Episode;
import net.x4a42.volksempfaenger.data.playlist.Playlist;

class PlaybackServiceProxy implements PlaybackEventListener, IntentParser.Listener
{
    public static final int                          NotificationId = 0x59d54313;
    private final BackgroundPositionSaver            positionSaver;
    private final Controller                         controller;
    private final IntentParser                       intentParser;
    private final MediaButtonReceiver                mediaButtonReceiver;
    private final MediaSessionManager                mediaSessionManager;
    private final NotificationManager                notificationManager;
    private final PlaybackNotificationBuilder        notificationBuilder;
    private final Playlist                           playlist;

    public PlaybackServiceProxy(BackgroundPositionSaver            positionSaver,
                                Controller                         controller,
                                IntentParser                       intentParser,
                                MediaButtonReceiver                mediaButtonReceiver,
                                MediaSessionManager                mediaSessionManager,
                                NotificationManager                notificationManager,
                                PlaybackNotificationBuilder        notificationBuilder,
                                Playlist                           playlist)
    {
        this.positionSaver              = positionSaver;
        this.controller                 = controller;
        this.intentParser               = intentParser;
        this.mediaButtonReceiver        = mediaButtonReceiver;
        this.mediaSessionManager        = mediaSessionManager;
        this.notificationManager        = notificationManager;
        this.notificationBuilder        = notificationBuilder;
        this.playlist                   = playlist;
    }

    public int onStartCommand(Intent intent)
    {
        // these come from app elements that want to change the state of the player
        // by either playing, pausing, or stopping

        intentParser.parse(intent);

        return Service.START_STICKY;
    }

    public void onDestroy()
    {
        controller.destroy();
        mediaButtonReceiver.destroy();
        if (mediaSessionManager != null)
        {
            mediaSessionManager.destroy();
        }
    }

    public IBinder onBind()
    {
        return new PlaybackServiceBinder(new PlaybackServiceFacade(controller));
    }

    @Override
    public void onPlaybackEvent(PlaybackEvent playbackEvent)
    {
        // these come from our own controller to let us know that it has changed state.
        switch (playbackEvent)
        {
            case PLAYING:
                handlePlaying();
                break;
            case PAUSED:
                handlePaused();
                break;
            case ENDED:
                handleEnded();
                break;
            default:
                // we ignore these
                break;
        }
    }

    @Override
    public void onPlay()
    {
        if (playlist.isEmpty())
        {
            return;
        }

        Episode episode = playlist.getCurrentEpisode();

        if (controller.isPlaybackEpisodeOpen(episode))
        {
            if (!controller.isPlaying())
            {
                controller.play();
            }
            return;
        }

        positionSaver.stop(false);
        controller.open(episode);
    }

    @Override
    public void onPause()
    {
        if (controller.isPlaying())
        {
            controller.pause();
        }
    }

    @Override
    public void onPlayPause()
    {
        if (!controller.isOpen())
        {
            return;
        }

        if (controller.isPlaying())
        {
            controller.pause();
        }
        else
        {
            onPlay();
        }
    }

    @Override
    public void onStop()
    {
        onPause();
        controller.stop();
        notificationManager.cancel(NotificationId);
    }

    @Override
    public void onSeek(int position)
    {
        if (controller.isOpen())
        {
            controller.seekTo(position);
        }
    }

    @Override
{'fraction_non_alphanumeric': 0.06268364348677767, 'fraction_numerical': 0.0037000761780389595, 'mean_word_length': 1.447403462050599, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '834342', 'n_tokens_mistral': 2164, 'n_tokens_neox': 2035, 'n_words': 457}