mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-30 06:13:54 +01:00
Upgrade to SDK 34 (#5790)
* change the overridden method signature as per API 34 * add version check condition to compare with API 23 before adding flag * refactor: add final keywords, fix typo, and remove redundant spaces For optimized code only * upgrade: migrate to SDK 34 and upgrade APG Additionally, add Jetpack Compose to the project * AndroidManifest: add new permission for API 34 DescriptionActivity should not be exposed * refactor: permission should not be check on onCreate for some cases * add method to get correct storage permission and check partial access Additionally, add final keywords to reduce compiler warnings * refactor: prevent app from crashing for SDKs >= 34 * add new UI component to allows user to manage partially access photos Implement using composeView * change the overridden method signature as per API 34 * add version check condition to compare with API 23 before adding flag * refactor: add final keywords, fix typo, and remove redundant spaces For optimized code only * upgrade: migrate to SDK 34 and upgrade APG Additionally, add Jetpack Compose to the project * AndroidManifest: add new permission for API 34 DescriptionActivity should not be exposed * refactor: permission should not be check on onCreate for some cases * add method to get correct storage permission and check partial access Additionally, add final keywords to reduce compiler warnings * refactor: prevent app from crashing for SDKs >= 34 * add new UI component to allows user to manage partially access photos Implement using composeView * replace deprecated circular progress bar with material progress bar * remove redundant appcompat dependency * add condition to check for partial access on API >= 34 It prevents invoking photo picker on UploadActivity. * UploadWorker: add foreground service type * fix typos in UploadWorker.kt * add permission to access media location
This commit is contained in:
parent
eb027b74ce
commit
3e915f9848
17 changed files with 433 additions and 200 deletions
|
|
@ -4,16 +4,12 @@ import android.app.NotificationManager;
|
|||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import android.os.Build;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.R;
|
||||
|
||||
import static androidx.core.app.NotificationCompat.DEFAULT_ALL;
|
||||
import static androidx.core.app.NotificationCompat.PRIORITY_HIGH;
|
||||
|
||||
|
|
@ -30,11 +26,11 @@ public class NotificationHelper {
|
|||
public static final int NOTIFICATION_EDIT_DESCRIPTION = 4;
|
||||
public static final int NOTIFICATION_EDIT_DEPICTIONS = 5;
|
||||
|
||||
private NotificationManager notificationManager;
|
||||
private NotificationCompat.Builder notificationBuilder;
|
||||
private final NotificationManager notificationManager;
|
||||
private final NotificationCompat.Builder notificationBuilder;
|
||||
|
||||
@Inject
|
||||
public NotificationHelper(Context context) {
|
||||
public NotificationHelper(final Context context) {
|
||||
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationBuilder = new NotificationCompat
|
||||
.Builder(context, CommonsApplication.NOTIFICATION_CHANNEL_ID_ALL)
|
||||
|
|
@ -49,12 +45,13 @@ public class NotificationHelper {
|
|||
* @param notificationId the notificationID
|
||||
* @param intent the intent to be fired when the notification is clicked
|
||||
*/
|
||||
public void showNotification(Context context,
|
||||
String notificationTitle,
|
||||
String notificationMessage,
|
||||
int notificationId,
|
||||
Intent intent) {
|
||||
|
||||
public void showNotification(
|
||||
final Context context,
|
||||
final String notificationTitle,
|
||||
final String notificationMessage,
|
||||
final int notificationId,
|
||||
final Intent intent
|
||||
) {
|
||||
notificationBuilder.setDefaults(DEFAULT_ALL)
|
||||
.setContentTitle(notificationTitle)
|
||||
.setStyle(new NotificationCompat.BigTextStyle()
|
||||
|
|
@ -65,14 +62,11 @@ public class NotificationHelper {
|
|||
.setPriority(PRIORITY_HIGH);
|
||||
|
||||
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
|
||||
|
||||
// Check if the API level is 31 or higher to modify the flag
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
// For API level 31 or above, PendingIntent requires either FLAG_IMMUTABLE or FLAG_MUTABLE to be set
|
||||
flags |= PendingIntent.FLAG_IMMUTABLE;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
flags |= PendingIntent.FLAG_IMMUTABLE; // This flag was introduced in API 23
|
||||
}
|
||||
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, flags);
|
||||
final PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, flags);
|
||||
notificationBuilder.setContentIntent(pendingIntent);
|
||||
notificationManager.notify(notificationId, notificationBuilder.build());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue