Merge pull request #4197 from ByteHamster/unique-intents

Unique intents
This commit is contained in:
H. Lehmann 2020-05-29 09:25:11 +02:00 committed by GitHub
commit 77b69340a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 71 additions and 66 deletions

View File

@ -91,7 +91,7 @@ public class MainActivity extends CastEnabledActivity {
super.onCreate(savedInstanceState);
StorageUtils.checkStorageAvailability(this);
setContentView(R.layout.main);
recycledViewPool.setMaxRecycledViews(R.id.episode_item_view_holder, 25);
recycledViewPool.setMaxRecycledViews(R.id.view_type_episode_item, 25);
drawerLayout = findViewById(R.id.drawer_layout);
navDrawer = findViewById(R.id.navDrawerFragment);

View File

@ -44,7 +44,7 @@ public class EpisodeItemListAdapter extends RecyclerView.Adapter<EpisodeItemView
@Override
public final int getItemViewType(int position) {
return R.id.episode_item_view_holder;
return R.id.view_type_episode_item;
}
@NonNull

View File

@ -5,11 +5,10 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.DownloadAuthenticationActivity;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.adapter.NavListAdapter;
import de.danoeh.antennapod.core.DownloadServiceCallbacks;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.service.download.DownloadRequest;
import de.danoeh.antennapod.fragment.DownloadsFragment;
import de.danoeh.antennapod.fragment.QueueFragment;
@ -24,7 +23,8 @@ public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks {
Bundle args = new Bundle();
args.putInt(DownloadsFragment.ARG_SELECTED_TAB, DownloadsFragment.POS_RUNNING);
intent.putExtra(MainActivity.EXTRA_FRAGMENT_ARGS, args);
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
return PendingIntent.getActivity(context,
R.id.pending_intent_download_service_notification, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
@Override
@ -32,7 +32,8 @@ public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks {
final Intent activityIntent = new Intent(context.getApplicationContext(), DownloadAuthenticationActivity.class);
activityIntent.putExtra(DownloadAuthenticationActivity.ARG_DOWNLOAD_REQUEST, request);
activityIntent.putExtra(DownloadAuthenticationActivity.ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL, true);
return PendingIntent.getActivity(context.getApplicationContext(), 0, activityIntent, PendingIntent.FLAG_ONE_SHOT);
return PendingIntent.getActivity(context.getApplicationContext(),
R.id.pending_intent_download_service_auth, activityIntent, PendingIntent.FLAG_ONE_SHOT);
}
@Override
@ -42,14 +43,16 @@ public class DownloadServiceCallbacksImpl implements DownloadServiceCallbacks {
Bundle args = new Bundle();
args.putInt(DownloadsFragment.ARG_SELECTED_TAB, DownloadsFragment.POS_LOG);
intent.putExtra(MainActivity.EXTRA_FRAGMENT_ARGS, args);
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
return PendingIntent.getActivity(context, R.id.pending_intent_download_service_report,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
@Override
public PendingIntent getAutoDownloadReportNotificationContentIntent(Context context) {
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra(MainActivity.EXTRA_FRAGMENT_TAG, QueueFragment.TAG);
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
return PendingIntent.getActivity(context, R.id.pending_intent_download_service_autodownload_report,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
@Override

View File

@ -103,12 +103,8 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
AppWidgetManager manager = AppWidgetManager.getInstance(this);
int[] widgetIds = manager.getAppWidgetIds(playerWidget);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.player_widget);
PendingIntent startMediaplayer = PendingIntent.getActivity(this, 0,
PlaybackService.getPlayerActivityIntent(this), 0);
final PendingIntent startAppPending = PendingIntent.getActivity(this, 0,
PlaybackService.getPlayerActivityIntent(this),
PendingIntent.FLAG_UPDATE_CURRENT);
final PendingIntent startMediaPlayer = PendingIntent.getActivity(this, R.id.pending_intent_player_activity,
PlaybackService.getPlayerActivityIntent(this), PendingIntent.FLAG_UPDATE_CURRENT);
boolean nothingPlaying = false;
Playable media;
@ -122,7 +118,7 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
}
if (media != null) {
views.setOnClickPendingIntent(R.id.layout_left, startMediaplayer);
views.setOnClickPendingIntent(R.id.layout_left, startMediaPlayer);
try {
Bitmap icon = null;
@ -170,8 +166,8 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
if (nothingPlaying) {
// start the app if they click anything
views.setOnClickPendingIntent(R.id.layout_left, startAppPending);
views.setOnClickPendingIntent(R.id.butPlay, startAppPending);
views.setOnClickPendingIntent(R.id.layout_left, startMediaPlayer);
views.setOnClickPendingIntent(R.id.butPlay, startMediaPlayer);
views.setViewVisibility(R.id.txtvProgress, View.GONE);
views.setViewVisibility(R.id.txtvTitle, View.GONE);
views.setViewVisibility(R.id.txtNoPlaying, View.VISIBLE);

View File

@ -17,6 +17,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.sync.SyncService;
import org.apache.commons.io.FileUtils;
import org.greenrobot.eventbus.EventBus;
@ -87,8 +88,6 @@ public class DownloadService extends Service {
public static final String EXTRA_CLEANUP_MEDIA = "cleanupMedia";
public static final int NOTIFICATION_ID = 2;
/**
* Contains all completed downloads that have not been included in the report yet.
*/
@ -165,7 +164,7 @@ public class DownloadService extends Service {
if (intent != null && intent.getParcelableArrayListExtra(EXTRA_REQUESTS) != null) {
Notification notification = notificationManager.updateNotifications(
requester.getNumberOfDownloads(), downloads);
startForeground(NOTIFICATION_ID, notification);
startForeground(R.id.notification_downloading, notification);
syncExecutor.execute(() -> onDownloadQueued(intent));
} else if (numberOfDownloads.get() == 0) {
stopSelf();
@ -191,7 +190,7 @@ public class DownloadService extends Service {
Notification notification = notificationManager.updateNotifications(
requester.getNumberOfDownloads(), downloads);
startForeground(NOTIFICATION_ID, notification);
startForeground(R.id.notification_downloading, notification);
}
@Override
@ -229,7 +228,7 @@ public class DownloadService extends Service {
stopForeground(true);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.cancel(NOTIFICATION_ID);
nm.cancel(R.id.notification_downloading);
// if this was the initial gpodder sync, i.e. we just synced the feeds successfully,
// it is now time to sync the episode actions
@ -566,7 +565,7 @@ public class DownloadService extends Service {
setupNotificationUpdater();
Notification notification = notificationManager.updateNotifications(
requester.getNumberOfDownloads(), downloads);
startForeground(NOTIFICATION_ID, notification);
startForeground(R.id.notification_downloading, notification);
}
}
@ -642,7 +641,7 @@ public class DownloadService extends Service {
Notification n = notificationManager.updateNotifications(requester.getNumberOfDownloads(), downloads);
if (n != null) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NOTIFICATION_ID, n);
nm.notify(R.id.notification_downloading, n);
}
}
}

View File

@ -17,8 +17,6 @@ import java.util.List;
public class DownloadServiceNotification {
private static final String TAG = "DownloadSvcNotification";
private static final int REPORT_ID = 3;
private static final int AUTO_REPORT_ID = 4;
private final Context context;
private NotificationCompat.Builder notificationCompatBuilder;
@ -147,14 +145,14 @@ public class DownloadServiceNotification {
titleId = R.string.auto_download_report_title;
iconId = R.drawable.ic_notification_auto_download_complete;
intent = ClientConfig.downloadServiceCallbacks.getAutoDownloadReportNotificationContentIntent(context);
id = AUTO_REPORT_ID;
id = R.id.notification_auto_download_report;
content = createAutoDownloadNotificationContent(reportQueue);
} else {
channelId = NotificationUtils.CHANNEL_ID_ERROR;
titleId = R.string.download_report_title;
iconId = R.drawable.ic_notification_sync_error;
intent = ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context);
id = REPORT_ID;
id = R.id.notification_download_report;
content = String.format(context.getString(R.string.download_report_content), successfulDownloads, failedDownloads);
}

View File

@ -204,9 +204,6 @@ public class PlaybackService extends MediaBrowserServiceCompat {
*/
private static volatile boolean isCasting = false;
private static final int NOTIFICATION_ID = 1;
private static final int NOTIFICATION_ID_STREAMING = 2;
private PlaybackServiceMediaPlayer mediaPlayer;
private PlaybackServiceTaskManager taskManager;
private PlaybackServiceFlavorHelper flavorHelper;
@ -271,7 +268,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
stateManager = new PlaybackServiceStateManager(this);
notificationBuilder = new PlaybackServiceNotificationBuilder(this);
stateManager.startForeground(NOTIFICATION_ID, notificationBuilder.build());
stateManager.startForeground(R.id.notification_playing, notificationBuilder.build());
registerReceiver(autoStateUpdated, new IntentFilter("com.google.android.gms.car.media.STATUS"));
registerReceiver(headsetDisconnected, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
@ -334,7 +331,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
if (notificationBuilder.getPlayerStatus() == PlayerStatus.PLAYING) {
notificationBuilder.setPlayerStatus(PlayerStatus.STOPPED);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
notificationManager.notify(R.id.notification_playing, notificationBuilder.build());
}
stateManager.stopForeground(!UserPreferences.isPersistNotify());
isRunning = false;
@ -450,9 +447,9 @@ public class PlaybackService extends MediaBrowserServiceCompat {
super.onStartCommand(intent, flags, startId);
Log.d(TAG, "OnStartCommand called");
stateManager.startForeground(NOTIFICATION_ID, notificationBuilder.build());
stateManager.startForeground(R.id.notification_playing, notificationBuilder.build());
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.cancel(NOTIFICATION_ID_STREAMING);
notificationManager.cancel(R.id.notification_streaming_confirmation);
final int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1);
final boolean castDisconnect = intent.getBooleanExtra(EXTRA_CAST_DISCONNECT, false);
@ -542,9 +539,11 @@ public class PlaybackService extends MediaBrowserServiceCompat {
intentAllowThisTime.putExtra(EXTRA_ALLOW_STREAM_THIS_TIME, true);
PendingIntent pendingIntentAllowThisTime;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
pendingIntentAllowThisTime = PendingIntent.getForegroundService(this, 0, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntentAllowThisTime = PendingIntent.getForegroundService(this,
R.id.pending_intent_allow_stream_this_time, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT);
} else {
pendingIntentAllowThisTime = PendingIntent.getService(this, 0, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntentAllowThisTime = PendingIntent.getService(this,
R.id.pending_intent_allow_stream_this_time, intentAllowThisTime, PendingIntent.FLAG_UPDATE_CURRENT);
}
Intent intentAlwaysAllow = new Intent(intentAllowThisTime);
@ -552,12 +551,15 @@ public class PlaybackService extends MediaBrowserServiceCompat {
intentAlwaysAllow.putExtra(EXTRA_ALLOW_STREAM_ALWAYS, true);
PendingIntent pendingIntentAlwaysAllow;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
pendingIntentAlwaysAllow = PendingIntent.getForegroundService(this, 0, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntentAlwaysAllow = PendingIntent.getForegroundService(this,
R.id.pending_intent_allow_stream_always, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT);
} else {
pendingIntentAlwaysAllow = PendingIntent.getService(this, 0, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntentAlwaysAllow = PendingIntent.getService(this,
R.id.pending_intent_allow_stream_always, intentAlwaysAllow, PendingIntent.FLAG_UPDATE_CURRENT);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_USER_ACTION)
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,
NotificationUtils.CHANNEL_ID_USER_ACTION)
.setSmallIcon(R.drawable.ic_stream_white)
.setContentTitle(getString(R.string.confirm_mobile_streaming_notification_title))
.setContentText(getString(R.string.confirm_mobile_streaming_notification_message))
@ -573,7 +575,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
pendingIntentAlwaysAllow)
.setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(NOTIFICATION_ID_STREAMING, builder.build());
notificationManager.notify(R.id.notification_streaming_confirmation, builder.build());
}
/**
@ -1238,9 +1240,8 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
}
if (!Thread.currentThread().isInterrupted() && stateManager.hasReceivedValidStartCommand()) {
mediaSession.setSessionActivity(PendingIntent.getActivity(this, 0,
PlaybackService.getPlayerActivityIntent(this),
PendingIntent.FLAG_UPDATE_CURRENT));
mediaSession.setSessionActivity(PendingIntent.getActivity(this, R.id.pending_intent_player_activity,
PlaybackService.getPlayerActivityIntent(this), PendingIntent.FLAG_UPDATE_CURRENT));
try {
mediaSession.setMetadata(builder.build());
} catch (OutOfMemoryError e) {
@ -1289,7 +1290,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
notificationBuilder.updatePosition(getCurrentPosition(), getCurrentPlaybackSpeed());
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
notificationManager.notify(R.id.notification_playing, notificationBuilder.build());
startForegroundIfPlaying(playerStatus);
if (!notificationBuilder.isIconCached()) {
@ -1297,7 +1298,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
Log.d(TAG, "Loading notification icon");
notificationBuilder.loadIcon();
if (!Thread.currentThread().isInterrupted()) {
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
notificationManager.notify(R.id.notification_playing, notificationBuilder.build());
}
});
notificationSetupThread.start();
@ -1309,12 +1310,12 @@ public class PlaybackService extends MediaBrowserServiceCompat {
if (stateManager.hasReceivedValidStartCommand()) {
if (isCasting || status == PlayerStatus.PLAYING || status == PlayerStatus.PREPARING
|| status == PlayerStatus.SEEKING) {
stateManager.startForeground(NOTIFICATION_ID, notificationBuilder.build());
stateManager.startForeground(R.id.notification_playing, notificationBuilder.build());
Log.d(TAG, "foreground");
} else {
stateManager.stopForeground(false);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
notificationManager.notify(R.id.notification_playing, notificationBuilder.build());
}
}
}
@ -1717,7 +1718,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
notificationBuilder.updatePosition(getCurrentPosition(), getCurrentPlaybackSpeed());
NotificationManager notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
notificationManager.notify(R.id.notification_playing, notificationBuilder.build());
}
skipEndingIfNecessary();
});

View File

@ -146,8 +146,8 @@ public class PlaybackServiceNotificationBuilder {
}
private PendingIntent getPlayerActivityPendingIntent() {
return PendingIntent.getActivity(context, 0, PlaybackService.getPlayerActivityIntent(context),
PendingIntent.FLAG_UPDATE_CURRENT);
return PendingIntent.getActivity(context, R.id.pending_intent_player_activity,
PlaybackService.getPlayerActivityIntent(context), PendingIntent.FLAG_UPDATE_CURRENT);
}
private void addActions(NotificationCompat.Builder notification, MediaSessionCompat.Token mediaSessionToken,

View File

@ -488,8 +488,8 @@ public class SyncService extends Worker {
Intent intent = getApplicationContext().getPackageManager().getLaunchIntentForPackage(
getApplicationContext().getPackageName());
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),
R.id.pending_intent_sync_error, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new NotificationCompat.Builder(getApplicationContext(),
NotificationUtils.CHANNEL_ID_ERROR)
.setContentTitle(getApplicationContext().getString(R.string.gpodnetsync_error_title))

View File

@ -1,28 +1,36 @@
<resources>
<item name="action_bar_refresh" type="id"/>
<item name="action_bar_add" type="id"/>
<item name="clear_queue_item" type="id"/>
<!-- Menu items -->
<item name="select_all_item" type="id"/>
<item name="deselect_all_item" type="id"/>
<item name="search_item" type="id"/>
<item name="enqueue_all_item" type="id"/>
<item name="download_all_item" type="id"/>
<item name="clear_history_item" type="id"/>
<item name="open_in_browser_item" type="id"/>
<item name="copy_url_item" type="id"/>
<item name="share_url_item" type="id"/>
<item name="go_to_position_item" type="id"/>
<item name="organize_queue_item" type="id"/>
<item name="drag_handle" type="id"/>
<item name="skip_episode_item" type="id"/>
<item name="move_to_top_item" type="id"/>
<item name="move_to_bottom_item" type="id"/>
<item name="image_disk_cache_key" type="id"/>
<item name="imageloader_key" type="id"/>
<!-- View types -->
<item name="view_type_episode_item" type="id"/>
<!-- Notifications need unique IDs to update/cancel them -->
<item name="notification_gpodnet_sync_error" type="id"/>
<item name="notification_gpodnet_sync_autherror" type="id"/>
<item name="undobar_button" type="id"/>
<item name="undobar_message" type="id"/>
<item name="episode_item_view_holder" type="id"/>
<item name="notification_downloading" type="id"/>
<item name="notification_download_report" type="id"/>
<item name="notification_auto_download_report" type="id"/>
<item name="notification_playing" type="id"/>
<item name="notification_streaming_confirmation" type="id"/>
<!-- PendingIntent objects that use the same action but different extras need to use a unique request code -->
<item name="pending_intent_download_service_notification" type="id"/>
<item name="pending_intent_download_service_auth" type="id"/>
<item name="pending_intent_download_service_report" type="id"/>
<item name="pending_intent_download_service_autodownload_report" type="id"/>
<item name="pending_intent_allow_stream_always" type="id"/>
<item name="pending_intent_allow_stream_this_time" type="id"/>
<item name="pending_intent_player_activity" type="id"/>
<item name="pending_intent_sync_error" type="id"/>
</resources>