<commit_before>package com.lenworthrose.music.widget;

import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.RemoteViews;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.AppWidgetTarget;
import com.lenworthrose.music.R;
import com.lenworthrose.music.util.Constants;

/**
 * {@link BroadcastReceiver} used by the {@link WidgetService} to listen for Playback Broadcasts.
 */
class PlaybackBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, Intent intent) {
        final AppWidgetManager appMan = AppWidgetManager.getInstance(context);
        final int[] appWidgetIds = appMan.getAppWidgetIds(new ComponentName(context, WidgetProvider.class));

        switch (intent.getAction()) {
            case Constants.PLAYING_NOW_CHANGED:
                String artist = intent.getStringExtra(Constants.EXTRA_ARTIST);
                String title = intent.getStringExtra(Constants.EXTRA_TITLE);
                if (TextUtils.isEmpty(title)) title = context.getString(R.string.app_name);

                RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_view);
                rv.setTextViewText(R.id.widget_title, title);
                rv.setTextViewText(R.id.widget_subtitle, artist);
                rv.setViewVisibility(R.id.widget_subtitle, TextUtils.isEmpty(artist) ? View.GONE : View.VISIBLE);
                WidgetProvider.setOnClickIntents(context, rv);

                for (int appWidgetId : appWidgetIds)
                    appMan.partiallyUpdateAppWidget(appWidgetId, rv);

                Glide.with(context).load(intent.getStringExtra(Constants.EXTRA_ALBUM_ART_URL)).asBitmap().fallback(R.drawable.logo)
                        .error(R.drawable.logo).into(new AppWidgetTarget(context, rv, R.id.widget_image, appWidgetIds) {
                    @Override
                    public void onLoadFailed(Exception e, Drawable errorDrawable) {
                        super.onLoadFailed(e, errorDrawable); //Currently, super doesn't do anything.

                        if (errorDrawable instanceof BitmapDrawable) {
                            RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_view);
                            rv.setImageViewBitmap(R.id.widget_image, ((BitmapDrawable)errorDrawable).getBitmap());

                            for (int appWidgetId : appWidgetIds)
                                appMan.partiallyUpdateAppWidget(appWidgetId, rv);
                        }
                    }
                });

                break;
            case Constants.PLAYBACK_STATE_CHANGED:
                Constants.PlaybackState state = (Constants.PlaybackState)intent.getSerializableExtra(Constants.EXTRA_STATE);
                RemoteViews rv2 = new RemoteViews(context.getPackageName(), R.layout.widget_view);
                WidgetProvider.setOnClickIntents(context, rv2);

                switch (state) {
                    case PLAYING:
                        rv2.setImageViewResource(R.id.widget_play_pause, R.drawable.pause);
                        break;
                    default:
                        rv2.setImageViewResource(R.id.widget_play_pause, R.drawable.play);
                        break;<commit_msg>Fix: crash if cover art too big for Widget<commit_after>package com.lenworthrose.music.widget;

import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.RemoteViews;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.AppWidgetTarget;
import com.lenworthrose.music.R;
import com.lenworthrose.music.util.Constants;

/**
 * {@link BroadcastReceiver} used by the {@link WidgetService} to listen for Playback Broadcasts.
 */
class PlaybackBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, Intent intent) {
        final AppWidgetManager appMan = AppWidgetManager.getInstance(context);
        final int[] appWidgetIds = appMan.getAppWidgetIds(new ComponentName(context, WidgetProvider.class));

        switch (intent.getAction()) {
            case Constants.PLAYING_NOW_CHANGED:
                String artist = intent.getStringExtra(Constants.EXTRA_ARTIST);
                String title = intent.getStringExtra(Constants.EXTRA_TITLE);
                if (TextUtils.isEmpty(title)) title = context.getString(R.string.app_name);

                RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_view);
                rv.setTextViewText(R.id.widget_title, title);
                rv.setTextViewText(R.id.widget_subtitle, artist);
                rv.setViewVisibility(R.id.widget_subtitle, TextUtils.isEmpty(artist) ? View.GONE : View.VISIBLE);
                WidgetProvider.setOnClickIntents(context, rv);

                for (int appWidgetId : appWidgetIds)
                    appMan.partiallyUpdateAppWidget(appWidgetId, rv);

                Glide.with(context).load(intent.getStringExtra(Constants.EXTRA_ALBUM_ART_URL)).asBitmap().override(500, 500).fallback(R.drawable.logo)
                        .error(R.drawable.logo).into(new AppWidgetTarget(context, rv, R.id.widget_image, appWidgetIds) {
                    @Override
                    public void onLoadFailed(Exception e, Drawable errorDrawable) {
                        super.onLoadFailed(e, errorDrawable); //Currently, super doesn't do anything.

                        if (errorDrawable instanceof BitmapDrawable) {
                            RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_view);
                            rv.setImageViewBitmap(R.id.widget_image, ((BitmapDrawable)errorDrawable).getBitmap());

                            for (int appWidgetId : appWidgetIds)
                                appMan.partiallyUpdateAppWidget(appWidgetId, rv);
                        }
                    }
                });

                break;
            case Constants.PLAYBACK_STATE_CHANGED:
                Constants.PlaybackState state = (Constants.PlaybackState)intent.getSerializableExtra(Constants.EXTRA_STATE);
                RemoteViews rv2 = new RemoteViews(context.getPackageName(), R.layout.widget_view);
                WidgetProvider.setOnClickIntents(context, rv2);

                switch (state) {
                    case PLAYING:
                        rv2.setImageViewResource(R.id.widget_play_pause, R.drawable.pause);
                        break;
                    default:
                        rv2.setImageViewResource(R.id.widget_play_pause, R.drawable.play);
                        break;
{'fraction_non_alphanumeric': 0.0883328725463091, 'fraction_numerical': 0.0019353055017970694, 'mean_word_length': 2.407913330193123, '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': '4267096', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1823, 'n_words': 328}