mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-22 16:10:31 +00:00
Use AndroidX's PendingIntentCompat class.
This commit is contained in:
parent
74bd28cbd9
commit
acebabd028
@ -6,6 +6,7 @@ import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.app.PendingIntentCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.edit
|
||||
import androidx.core.net.toUri
|
||||
@ -19,7 +20,6 @@ import com.grack.nanojson.JsonParser
|
||||
import com.grack.nanojson.JsonParserException
|
||||
import org.schabi.newpipe.extractor.downloader.Response
|
||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
|
||||
import org.schabi.newpipe.util.PendingIntentCompat
|
||||
import org.schabi.newpipe.util.ReleaseVersionUtil.coerceUpdateCheckExpiry
|
||||
import org.schabi.newpipe.util.ReleaseVersionUtil.isLastUpdateCheckExpired
|
||||
import org.schabi.newpipe.util.ReleaseVersionUtil.isReleaseApk
|
||||
@ -60,7 +60,7 @@ class NewVersionWorker(
|
||||
val intent = Intent(Intent.ACTION_VIEW, apkLocationUrl?.toUri())
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
val pendingIntent = PendingIntentCompat.getActivity(
|
||||
applicationContext, 0, intent, 0
|
||||
applicationContext, 0, intent, 0, false
|
||||
)
|
||||
val channelId = applicationContext.getString(R.string.app_update_notification_channel_id)
|
||||
val notificationBuilder = NotificationCompat.Builder(applicationContext, channelId)
|
||||
|
@ -9,10 +9,10 @@ import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.app.PendingIntentCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import org.schabi.newpipe.R
|
||||
import org.schabi.newpipe.util.PendingIntentCompat
|
||||
|
||||
/**
|
||||
* This class contains all of the methods that should be used to let the user know that an error has
|
||||
@ -118,7 +118,8 @@ class ErrorUtil {
|
||||
context,
|
||||
0,
|
||||
getErrorActivityIntent(context, errorInfo),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
PendingIntent.FLAG_UPDATE_CURRENT,
|
||||
false
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -10,6 +10,7 @@ import android.os.Build
|
||||
import android.provider.Settings
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.app.PendingIntentCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.squareup.picasso.Picasso
|
||||
@ -19,7 +20,6 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
||||
import org.schabi.newpipe.local.feed.service.FeedUpdateInfo
|
||||
import org.schabi.newpipe.util.Localization
|
||||
import org.schabi.newpipe.util.NavigationHelper
|
||||
import org.schabi.newpipe.util.PendingIntentCompat
|
||||
import org.schabi.newpipe.util.PicassoHelper
|
||||
|
||||
/**
|
||||
@ -76,7 +76,8 @@ class NotificationHelper(val context: Context) {
|
||||
NavigationHelper
|
||||
.getChannelIntent(context, data.listInfo.serviceId, data.listInfo.url)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
||||
0
|
||||
0,
|
||||
false
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -29,6 +29,7 @@ import android.os.IBinder
|
||||
import android.util.Log
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.app.PendingIntentCompat
|
||||
import androidx.core.app.ServiceCompat
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.core.Flowable
|
||||
@ -42,7 +43,6 @@ import org.schabi.newpipe.extractor.ListInfo
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
||||
import org.schabi.newpipe.local.feed.service.FeedEventManager.Event.ErrorResultEvent
|
||||
import org.schabi.newpipe.local.feed.service.FeedEventManager.postEvent
|
||||
import org.schabi.newpipe.util.PendingIntentCompat
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class FeedLoadService : Service() {
|
||||
@ -152,8 +152,8 @@ class FeedLoadService : Service() {
|
||||
private lateinit var notificationBuilder: NotificationCompat.Builder
|
||||
|
||||
private fun createNotification(): NotificationCompat.Builder {
|
||||
val cancelActionIntent =
|
||||
PendingIntentCompat.getBroadcast(this, NOTIFICATION_ID, Intent(ACTION_CANCEL), 0)
|
||||
val cancelActionIntent = PendingIntentCompat
|
||||
.getBroadcast(this, NOTIFICATION_ID, Intent(ACTION_CANCEL), 0, false)
|
||||
|
||||
return NotificationCompat.Builder(this, getString(R.string.notification_channel_id))
|
||||
.setOngoing(true)
|
||||
|
@ -13,6 +13,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
import androidx.core.app.PendingIntentCompat;
|
||||
import androidx.core.app.ServiceCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
@ -21,7 +22,6 @@ import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.player.Player;
|
||||
import org.schabi.newpipe.player.mediasession.MediaSessionPlayerUi;
|
||||
import org.schabi.newpipe.util.NavigationHelper;
|
||||
import org.schabi.newpipe.util.PendingIntentCompat;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -134,7 +134,7 @@ public final class NotificationUtil {
|
||||
.setColorized(player.getPrefs().getBoolean(
|
||||
player.getContext().getString(R.string.notification_colorize_key), true))
|
||||
.setDeleteIntent(PendingIntentCompat.getBroadcast(player.getContext(),
|
||||
NOTIFICATION_ID, new Intent(ACTION_CLOSE), FLAG_UPDATE_CURRENT));
|
||||
NOTIFICATION_ID, new Intent(ACTION_CLOSE), FLAG_UPDATE_CURRENT, false));
|
||||
|
||||
// set the initial value for the video thumbnail, updatable with updateNotificationThumbnail
|
||||
setLargeIcon(builder);
|
||||
@ -152,7 +152,7 @@ public final class NotificationUtil {
|
||||
|
||||
// also update content intent, in case the user switched players
|
||||
notificationBuilder.setContentIntent(PendingIntentCompat.getActivity(player.getContext(),
|
||||
NOTIFICATION_ID, getIntentForNotification(), FLAG_UPDATE_CURRENT));
|
||||
NOTIFICATION_ID, getIntentForNotification(), FLAG_UPDATE_CURRENT, false));
|
||||
notificationBuilder.setContentTitle(player.getVideoTitle());
|
||||
notificationBuilder.setContentText(player.getUploaderName());
|
||||
notificationBuilder.setTicker(player.getVideoTitle());
|
||||
@ -335,7 +335,7 @@ public final class NotificationUtil {
|
||||
final String intentAction) {
|
||||
return new NotificationCompat.Action(drawable, player.getContext().getString(title),
|
||||
PendingIntentCompat.getBroadcast(player.getContext(), NOTIFICATION_ID,
|
||||
new Intent(intentAction), FLAG_UPDATE_CURRENT));
|
||||
new Intent(intentAction), FLAG_UPDATE_CURRENT, false));
|
||||
}
|
||||
|
||||
private Intent getIntentForNotification() {
|
||||
|
@ -1,69 +0,0 @@
|
||||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public final class PendingIntentCompat {
|
||||
private PendingIntentCompat() {
|
||||
}
|
||||
|
||||
private static int addImmutableFlag(final int flags) {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
? flags | PendingIntent.FLAG_IMMUTABLE : flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link PendingIntent} to start an activity. It is immutable on API level 23 and
|
||||
* greater.
|
||||
*
|
||||
* @param context The context in which the activity should be started.
|
||||
* @param requestCode The request code
|
||||
* @param intent The Intent of the activity to be launched.
|
||||
* @param flags The flags for the intent.
|
||||
* @return The pending intent.
|
||||
* @see PendingIntent#getActivity(Context, int, Intent, int)
|
||||
*/
|
||||
@NonNull
|
||||
public static PendingIntent getActivity(@NonNull final Context context, final int requestCode,
|
||||
@NonNull final Intent intent, final int flags) {
|
||||
return PendingIntent.getActivity(context, requestCode, intent, addImmutableFlag(flags));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link PendingIntent} to start a service. It is immutable on API level 23 and
|
||||
* greater.
|
||||
*
|
||||
* @param context The context in which the service should be started.
|
||||
* @param requestCode The request code
|
||||
* @param intent The Intent of the service to be launched.
|
||||
* @param flags The flags for the intent.
|
||||
* @return The pending intent.
|
||||
* @see PendingIntent#getService(Context, int, Intent, int)
|
||||
*/
|
||||
@NonNull
|
||||
public static PendingIntent getService(@NonNull final Context context, final int requestCode,
|
||||
@NonNull final Intent intent, final int flags) {
|
||||
return PendingIntent.getService(context, requestCode, intent, addImmutableFlag(flags));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link PendingIntent} to perform a broadcast. It is immutable on API level 23 and
|
||||
* greater.
|
||||
*
|
||||
* @param context The context in which the broadcast should be performed.
|
||||
* @param requestCode The request code
|
||||
* @param intent The Intent to be broadcast.
|
||||
* @param flags The flags for the intent.
|
||||
* @return The pending intent.
|
||||
* @see PendingIntent#getBroadcast(Context, int, Intent, int)
|
||||
*/
|
||||
@NonNull
|
||||
public static PendingIntent getBroadcast(@NonNull final Context context, final int requestCode,
|
||||
@NonNull final Intent intent, final int flags) {
|
||||
return PendingIntent.getBroadcast(context, requestCode, intent, addImmutableFlag(flags));
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ import androidx.annotation.StringRes;
|
||||
import androidx.collection.SparseArrayCompat;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationCompat.Builder;
|
||||
import androidx.core.app.PendingIntentCompat;
|
||||
import androidx.core.app.ServiceCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
@ -43,7 +44,6 @@ import org.schabi.newpipe.player.helper.LockManager;
|
||||
import org.schabi.newpipe.streams.io.StoredDirectoryHelper;
|
||||
import org.schabi.newpipe.streams.io.StoredFileHelper;
|
||||
import org.schabi.newpipe.util.Localization;
|
||||
import org.schabi.newpipe.util.PendingIntentCompat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -146,7 +146,7 @@ public class DownloadManagerService extends Service {
|
||||
|
||||
mOpenDownloadList = PendingIntentCompat.getActivity(this, 0,
|
||||
openDownloadListIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
PendingIntent.FLAG_UPDATE_CURRENT, false);
|
||||
|
||||
icLauncher = BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher);
|
||||
|
||||
@ -487,7 +487,7 @@ public class DownloadManagerService extends Service {
|
||||
private PendingIntent makePendingIntent(String action) {
|
||||
Intent intent = new Intent(this, DownloadManagerService.class).setAction(action);
|
||||
return PendingIntentCompat.getService(this, intent.hashCode(), intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
PendingIntent.FLAG_UPDATE_CURRENT, false);
|
||||
}
|
||||
|
||||
private void manageLock(boolean acquire) {
|
||||
|
Loading…
Reference in New Issue
Block a user