Catch an exception from the app widget.
This commit is contained in:
parent
eda384c260
commit
fc8c55b218
1 changed files with 13 additions and 9 deletions
|
|
@ -31,6 +31,8 @@ import com.kabouzeid.gramophone.ui.activities.MainActivity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
// TODO rewrite the whole class
|
||||||
|
@Deprecated
|
||||||
public class WidgetMedium extends AppWidgetProvider {
|
public class WidgetMedium extends AppWidgetProvider {
|
||||||
public static final String TAG = WidgetMedium.class.getSimpleName();
|
public static final String TAG = WidgetMedium.class.getSimpleName();
|
||||||
private static RemoteViews widgetLayout;
|
private static RemoteViews widgetLayout;
|
||||||
|
|
@ -40,7 +42,7 @@ public class WidgetMedium extends AppWidgetProvider {
|
||||||
widgetLayout = new RemoteViews(context.getPackageName(), R.layout.widget_medium);
|
widgetLayout = new RemoteViews(context.getPackageName(), R.layout.widget_medium);
|
||||||
}
|
}
|
||||||
if (song.id == -1) {
|
if (song.id == -1) {
|
||||||
Log.d(TAG, "Had to download the current song from the SQL database.");
|
Log.d(TAG, "Had to load the current song from the SQL database.");
|
||||||
ArrayList<Song> restoredQueue = MusicPlaybackQueueStore.getInstance(context).getSavedPlayingQueue();
|
ArrayList<Song> restoredQueue = MusicPlaybackQueueStore.getInstance(context).getSavedPlayingQueue();
|
||||||
int restoredPosition = PreferenceManager.getDefaultSharedPreferences(context).getInt(MusicService.SAVED_POSITION, -1);
|
int restoredPosition = PreferenceManager.getDefaultSharedPreferences(context).getInt(MusicService.SAVED_POSITION, -1);
|
||||||
if (!restoredQueue.isEmpty() && restoredPosition >= 0 && restoredPosition < restoredQueue.size()) {
|
if (!restoredQueue.isEmpty() && restoredPosition >= 0 && restoredPosition < restoredQueue.size()) {
|
||||||
|
|
@ -65,12 +67,17 @@ public class WidgetMedium extends AppWidgetProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateWidgets(@NonNull final Context context) {
|
private static void updateWidgets(@NonNull final Context context) {
|
||||||
|
// this is only a temporary solution until we rewrote this whole class.
|
||||||
|
try {
|
||||||
AppWidgetManager man = AppWidgetManager.getInstance(context);
|
AppWidgetManager man = AppWidgetManager.getInstance(context);
|
||||||
int[] ids = man.getAppWidgetIds(
|
int[] ids = man.getAppWidgetIds(
|
||||||
new ComponentName(context, WidgetMedium.class));
|
new ComponentName(context, WidgetMedium.class));
|
||||||
for (int widgetId : ids) {
|
for (int widgetId : ids) {
|
||||||
man.updateAppWidget(widgetId, widgetLayout);
|
man.updateAppWidget(widgetId, widgetLayout);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Handler uiThreadHandler;
|
private static Handler uiThreadHandler;
|
||||||
|
|
@ -152,9 +159,6 @@ public class WidgetMedium extends AppWidgetProvider {
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, @NonNull int[] appWidgetIds) {
|
public void onUpdate(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, @NonNull int[] appWidgetIds) {
|
||||||
updateWidgets(context, MusicPlayerRemote.getCurrentSong(), MusicPlayerRemote.isPlaying());
|
updateWidgets(context, MusicPlayerRemote.getCurrentSong(), MusicPlayerRemote.isPlaying());
|
||||||
for (int widgetId : appWidgetIds) {
|
|
||||||
appWidgetManager.updateAppWidget(widgetId, widgetLayout);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue