package com.nf2m.provider;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import com.nf2m.service.MediaPlayerService;
public class PlayerWidgetLargeProvider extends AppWidgetProvider {
public static final String ACTION_LARGE_WIDGET_PLAY = "action_large_widget_play";
public static final String ACTION_LARGE_WIDGET_NEXT = "action_large_widget_next";
public static final String ACTION_LARGE_WIDGET_PREVIOUS = "action_large_widget_previous";
public static final String ACTION_LARGE_WIDGET_SHUFFLE = "action_large_widget_shuffle";
public static final String ACTION_LARGE_WIDGET_REPEAT = "action_large_widget_repeat";
private Context context;
@Override
public void onEnabled(Context context) {
send(PlayerWidgetSmallProvider.VALUE_PAUSE, MediaPlayerService.ACTION_UPDATE);
}
private void send(String value, String action) {
if (!MediaPlayerService.isServiceStart) {
startMediaPlayerService(value);
} else {
Intent intent = new Intent(action);
context.sendBroadcast(intent);
}
}
private void startMediaPlayerService(String value) {
Intent intent = new Intent(context, MediaPlayerService.class);
intent.putExtra(PlayerWidgetSmallProvider.EXTRA_WIDGET, value);
context.startService(intent);
}
@Override
public void onReceive(Context context, @NonNull Intent intent) {
this.context = context;
if (intent.getAction().equalsIgnoreCase(ACTION_LARGE_WIDGET_PLAY)) {
send(PlayerWidgetSmallProvider.VALUE_PLAY, MediaPlayerService.ACTION_PLAY);
} else if (intent.getAction().equalsIgnoreCase(ACTION_LARGE_WIDGET_NEXT)) {
send(PlayerWidgetSmallProvider.VALUE_NEXT, MediaPlayerService.ACTION_NEXT);
} else if (intent.getAction().equalsIgnoreCase(ACTION_LARGE_WIDGET_PREVIOUS)) {
send(PlayerWidgetSmallProvider.VALUE_PREVIOUS, MediaPlayerService.ACTION_PREVIOUS);
} else if (intent.getAction().equalsIgnoreCase(ACTION_LARGE_WIDGET_REPEAT)) {
send(PlayerWidgetSmallProvider.VALUE_PAUSE, MediaPlayerService.ACTION_REPEAT);
} else if (intent.getAction().equalsIgnoreCase(ACTION_LARGE_WIDGET_SHUFFLE)) {
send(PlayerWidgetSmallProvider.VALUE_PAUSE, MediaPlayerService.ACTION_SHUFFLE);
} else if (intent.getAction().equalsIgnoreCase("android.appwidget.action.APPWIDGET_ENABLED")) {
onEnabled(context);
}
}
}