Add support for background notification download when power save mode is enabled.
Fixes #408.
This commit is contained in:
parent
41abd55f43
commit
284ad36927
|
@ -14,9 +14,12 @@
|
|||
<uses-permission android:name="android.permission.USE_CREDENTIALS" android:maxSdkVersion="22" />
|
||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.touchscreen"
|
||||
|
@ -49,7 +52,6 @@
|
|||
<activity
|
||||
android:name="es.ugr.swad.swadroid.SWADMain"
|
||||
android:icon="@drawable/ic_launcher_swadroid"
|
||||
android:label="@string/app_name"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
@ -366,6 +368,26 @@
|
|||
android:resource="@xml/sync_notifications" />
|
||||
</service>
|
||||
|
||||
<receiver
|
||||
android:name="es.ugr.swad.swadroid.modules.notifications.RestarterNotificationsReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.REBOOT" />
|
||||
<action android:name="android.intent.action.SCREEN_ON" />
|
||||
<action android:name="android.intent.action.SCREEN_OFF" />
|
||||
<action android:name="android.intent.action.USER_PRESENT" />
|
||||
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED" />
|
||||
<action android:name="android.intent.action.PACKAGE_REPLACED" />
|
||||
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
|
||||
<action android:name="android.intent.action.MY_PACKAGE_SUSPENDED" />
|
||||
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
|
||||
<action android:name="android.intent.action.PACKAGE_REMOVED" />
|
||||
<action android:name="android.intent.action.MY_PACKAGE_SUSPENDED" />
|
||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="es.ugr.swad.swadroid.fileprovider"
|
||||
|
|
|
@ -267,6 +267,10 @@ public class Constants {
|
|||
* Request code for PERMISSION_MULTIPLE permissions
|
||||
*/
|
||||
public static final int PERMISSION_MULTIPLE = 102;
|
||||
/**
|
||||
* Request code for POST_NOTIFICATIONS permission
|
||||
*/
|
||||
public static final int PERMISSIONS_REQUEST_POST_NOTIFICATIONS = 103;
|
||||
/**
|
||||
* Prefix tag name for Logcat
|
||||
*/
|
||||
|
|
|
@ -19,11 +19,14 @@
|
|||
|
||||
package es.ugr.swad.swadroid;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
@ -43,6 +46,10 @@ import android.widget.Spinner;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -59,8 +66,8 @@ import es.ugr.swad.swadroid.model.Model;
|
|||
import es.ugr.swad.swadroid.modules.courses.Courses;
|
||||
import es.ugr.swad.swadroid.modules.downloads.DownloadsManager;
|
||||
import es.ugr.swad.swadroid.modules.groups.MyGroupsManager;
|
||||
import es.ugr.swad.swadroid.modules.information.Information;
|
||||
import es.ugr.swad.swadroid.modules.indoorlocation.IndoorLocation;
|
||||
import es.ugr.swad.swadroid.modules.information.Information;
|
||||
import es.ugr.swad.swadroid.modules.login.Login;
|
||||
import es.ugr.swad.swadroid.modules.login.LoginActivity;
|
||||
import es.ugr.swad.swadroid.modules.messages.Messages;
|
||||
|
@ -191,6 +198,20 @@ public class SWADMain extends MenuExpandableListActivity {
|
|||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
// Check Android 13 permission
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this,
|
||||
new String[]{Manifest.permission.POST_NOTIFICATIONS},
|
||||
Constants.PERMISSIONS_REQUEST_POST_NOTIFICATIONS);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see android.app.Activity#onResume()
|
||||
|
|
|
@ -19,118 +19,144 @@
|
|||
|
||||
package es.ugr.swad.swadroid.gui;
|
||||
|
||||
import static es.ugr.swad.swadroid.utils.NotificationUtils.SWADROID_CHANNEL_ID;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import es.ugr.swad.swadroid.utils.NotificationUtils;
|
||||
|
||||
import static es.ugr.swad.swadroid.utils.NotificationUtils.SWADROID_CHANNEL_ID;
|
||||
|
||||
/**
|
||||
* Class for create notification alerts.
|
||||
*
|
||||
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||
*/
|
||||
public class AlertNotificationFactory {
|
||||
public static NotificationCompat.Builder createAlertNotificationBuilder(Context context, String contentTitle, String contentText,
|
||||
String ticker, PendingIntent pendingIntent, int smallIcon, int largeIcon,
|
||||
boolean autocancel, boolean ongoing, boolean onlyAlertOnce) {
|
||||
|
||||
int flags = 0;
|
||||
public static NotificationCompat.Builder createAlertNotificationBuilder(Context context, String contentTitle, String contentText,
|
||||
String ticker, PendingIntent pendingIntent, int smallIcon, int largeIcon,
|
||||
boolean autocancel, boolean ongoing, boolean onlyAlertOnce) {
|
||||
|
||||
NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context, SWADROID_CHANNEL_ID)
|
||||
.setAutoCancel(autocancel)
|
||||
.setSmallIcon(smallIcon)
|
||||
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), largeIcon))
|
||||
.setContentTitle(contentTitle)
|
||||
.setContentText(contentText)
|
||||
.setTicker(ticker)
|
||||
.setOngoing(ongoing)
|
||||
.setOnlyAlertOnce(onlyAlertOnce)
|
||||
.setWhen(System.currentTimeMillis());
|
||||
//.setLights(Color.GREEN, 500, 500);
|
||||
int flags = 0;
|
||||
|
||||
NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context, SWADROID_CHANNEL_ID)
|
||||
.setAutoCancel(autocancel)
|
||||
.setSmallIcon(smallIcon)
|
||||
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), largeIcon))
|
||||
.setContentTitle(contentTitle)
|
||||
.setContentText(contentText)
|
||||
.setTicker(ticker)
|
||||
.setOngoing(ongoing)
|
||||
.setOnlyAlertOnce(onlyAlertOnce)
|
||||
.setWhen(System.currentTimeMillis());
|
||||
//.setLights(Color.GREEN, 500, 500);
|
||||
|
||||
//Launch activity on alert click
|
||||
if(pendingIntent != null) {
|
||||
if (pendingIntent != null) {
|
||||
notifBuilder.setContentIntent(pendingIntent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Add sound, vibration and lights
|
||||
flags |= Notification.DEFAULT_SOUND;
|
||||
flags |= Notification.DEFAULT_VIBRATE;
|
||||
flags |= Notification.DEFAULT_LIGHTS;
|
||||
|
||||
notifBuilder.setDefaults(flags);
|
||||
|
||||
return notifBuilder;
|
||||
}
|
||||
|
||||
public static NotificationCompat.Builder createProgressNotificationBuilder(Context context, String contentTitle, String contentText,
|
||||
String ticker, PendingIntent pendingIntent, int smallIcon, int largeIcon,
|
||||
boolean autocancel, boolean ongoing, boolean onlyAlertOnce, int maxProgress, int progress, boolean indeterminate) {
|
||||
|
||||
NotificationCompat.Builder notifBuilder = createAlertNotificationBuilder(context,
|
||||
contentTitle,
|
||||
contentText,
|
||||
ticker,
|
||||
pendingIntent,
|
||||
smallIcon,
|
||||
largeIcon,
|
||||
autocancel,
|
||||
ongoing,
|
||||
onlyAlertOnce);
|
||||
|
||||
notifBuilder.setProgress(maxProgress, progress, indeterminate);
|
||||
|
||||
return notifBuilder;
|
||||
}
|
||||
|
||||
public static Notification createAlertNotification(Context context, String contentTitle, String contentText,
|
||||
String ticker, PendingIntent pendingIntent, int smallIcon, int largeIcon,
|
||||
boolean autocancel, boolean ongoing, boolean onlyAlertOnce) {
|
||||
|
||||
NotificationCompat.Builder notifBuilder = createAlertNotificationBuilder(context,
|
||||
contentTitle,
|
||||
contentText,
|
||||
ticker,
|
||||
pendingIntent,
|
||||
smallIcon,
|
||||
largeIcon,
|
||||
autocancel,
|
||||
ongoing,
|
||||
onlyAlertOnce);
|
||||
|
||||
notifBuilder.setDefaults(flags);
|
||||
|
||||
return notifBuilder;
|
||||
}
|
||||
|
||||
public static NotificationCompat.Builder createProgressNotificationBuilder(Context context, String contentTitle, String contentText,
|
||||
String ticker, PendingIntent pendingIntent, int smallIcon, int largeIcon,
|
||||
boolean autocancel, boolean ongoing, boolean onlyAlertOnce, int maxProgress, int progress, boolean indeterminate) {
|
||||
|
||||
NotificationCompat.Builder notifBuilder = createAlertNotificationBuilder(context,
|
||||
contentTitle,
|
||||
contentText,
|
||||
ticker,
|
||||
pendingIntent,
|
||||
smallIcon,
|
||||
largeIcon,
|
||||
autocancel,
|
||||
ongoing,
|
||||
onlyAlertOnce);
|
||||
|
||||
notifBuilder.setProgress(maxProgress, progress, indeterminate);
|
||||
|
||||
return notifBuilder;
|
||||
}
|
||||
|
||||
public static Notification createAlertNotification(Context context, String contentTitle, String contentText,
|
||||
String ticker, PendingIntent pendingIntent, int smallIcon, int largeIcon,
|
||||
boolean autocancel, boolean ongoing, boolean onlyAlertOnce) {
|
||||
|
||||
NotificationCompat.Builder notifBuilder = createAlertNotificationBuilder(context,
|
||||
contentTitle,
|
||||
contentText,
|
||||
ticker,
|
||||
pendingIntent,
|
||||
smallIcon,
|
||||
largeIcon,
|
||||
autocancel,
|
||||
ongoing,
|
||||
onlyAlertOnce);
|
||||
|
||||
//Create alert
|
||||
return notifBuilder.build();
|
||||
}
|
||||
|
||||
public static Notification createProgressNotification(Context context, String contentTitle, String contentText,
|
||||
String ticker, PendingIntent pendingIntent, int smallIcon, int largeIcon,
|
||||
boolean autocancel, boolean ongoing, boolean onlyAlertOnce, int maxProgress, int progress, boolean indeterminate) {
|
||||
|
||||
NotificationCompat.Builder notifBuilder = createProgressNotificationBuilder(context,
|
||||
contentTitle,
|
||||
contentText,
|
||||
ticker,
|
||||
pendingIntent,
|
||||
smallIcon,
|
||||
largeIcon,
|
||||
autocancel,
|
||||
ongoing,
|
||||
onlyAlertOnce,
|
||||
maxProgress,
|
||||
progress,
|
||||
indeterminate);
|
||||
|
||||
public static Notification createProgressNotification(Context context, String contentTitle, String contentText,
|
||||
String ticker, PendingIntent pendingIntent, int smallIcon, int largeIcon,
|
||||
boolean autocancel, boolean ongoing, boolean onlyAlertOnce, int maxProgress, int progress, boolean indeterminate) {
|
||||
|
||||
NotificationCompat.Builder notifBuilder = createProgressNotificationBuilder(context,
|
||||
contentTitle,
|
||||
contentText,
|
||||
ticker,
|
||||
pendingIntent,
|
||||
smallIcon,
|
||||
largeIcon,
|
||||
autocancel,
|
||||
ongoing,
|
||||
onlyAlertOnce,
|
||||
maxProgress,
|
||||
progress,
|
||||
indeterminate);
|
||||
|
||||
//Create alert
|
||||
return notifBuilder.build();
|
||||
}
|
||||
|
||||
public static void showAlertNotification(Context context, Notification notif, int notifId) {
|
||||
|
||||
public static Notification createBackgroundNotification(Context context, String contentTitle, int smallIcon, int largeIcon) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
String channelName = "Background Service";
|
||||
NotificationChannel channel = new NotificationChannel(SWADROID_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
|
||||
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
assert manager != null;
|
||||
channel.setLightColor(Color.BLUE);
|
||||
manager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context, SWADROID_CHANNEL_ID)
|
||||
.setOngoing(true)
|
||||
.setSmallIcon(smallIcon)
|
||||
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), largeIcon))
|
||||
.setContentTitle(contentTitle)
|
||||
.setPriority(NotificationManager.IMPORTANCE_HIGH)
|
||||
.setCategory(Notification.CATEGORY_SERVICE);
|
||||
|
||||
//Create alert
|
||||
return notifBuilder.build();
|
||||
}
|
||||
|
||||
public static void showAlertNotification(Context context, Notification notif, int notifId) {
|
||||
NotificationManager notifManager;
|
||||
|
||||
//Obtain a reference to the notification service
|
||||
|
@ -144,5 +170,5 @@ public class AlertNotificationFactory {
|
|||
|
||||
//Send alert
|
||||
notifManager.notify(notifId, notif);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package es.ugr.swad.swadroid.modules.notifications;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
|
@ -28,9 +27,7 @@ import android.content.ContentResolver;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -42,6 +39,8 @@ import android.widget.LinearLayout;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import org.ksoap2.serialization.SoapObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -142,48 +141,44 @@ public class Notifications extends Module implements
|
|||
/**
|
||||
* Id for the not seen notifications group
|
||||
*/
|
||||
private int NOT_SEEN_GROUP_ID = 0;
|
||||
private final int NOT_SEEN_GROUP_ID = 0;
|
||||
/**
|
||||
* Id for the seen notifications group
|
||||
*/
|
||||
private int SEEN_GROUP_ID = 1;
|
||||
private final int SEEN_GROUP_ID = 1;
|
||||
/**
|
||||
* ListView click listener
|
||||
*/
|
||||
private OnChildClickListener clickListener = new OnChildClickListener() {
|
||||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v,
|
||||
int groupPosition, int childPosition, long id) {
|
||||
|
||||
TextView notifCode = (TextView) v.findViewById(R.id.notifCode);
|
||||
TextView code = (TextView) v.findViewById(R.id.eventCode);
|
||||
TextView type = (TextView) v.findViewById(R.id.eventType);
|
||||
TextView userPhoto = (TextView) v.findViewById(R.id.eventUserPhoto);
|
||||
TextView sender = (TextView) v.findViewById(R.id.eventSender);
|
||||
TextView course = (TextView) v.findViewById(R.id.eventLocation);
|
||||
TextView summary = (TextView) v.findViewById(R.id.eventSummary);
|
||||
TextView content = (TextView) v.findViewById(R.id.eventText);
|
||||
TextView date = (TextView) v.findViewById(R.id.eventDate);
|
||||
TextView time = (TextView) v.findViewById(R.id.eventTime);
|
||||
TextView seenLocalText = (TextView) v.findViewById(R.id.seenLocal);
|
||||
private final OnChildClickListener clickListener = (parent, v, groupPosition, childPosition, id) -> {
|
||||
|
||||
TextView notifCode = v.findViewById(R.id.notifCode);
|
||||
TextView code = v.findViewById(R.id.eventCode);
|
||||
TextView type = v.findViewById(R.id.eventType);
|
||||
TextView userPhoto = v.findViewById(R.id.eventUserPhoto);
|
||||
TextView sender = v.findViewById(R.id.eventSender);
|
||||
TextView course = v.findViewById(R.id.eventLocation);
|
||||
TextView summary = v.findViewById(R.id.eventSummary);
|
||||
TextView content = v.findViewById(R.id.eventText);
|
||||
TextView date = v.findViewById(R.id.eventDate);
|
||||
TextView time = v.findViewById(R.id.eventTime);
|
||||
TextView seenLocalText = v.findViewById(R.id.seenLocal);
|
||||
|
||||
Intent activity = new Intent(getApplicationContext(),
|
||||
NotificationItem.class);
|
||||
activity.putExtra("notifCode", notifCode.getText().toString());
|
||||
activity.putExtra("eventCode", code.getText().toString());
|
||||
activity.putExtra("notificationType", type.getText().toString());
|
||||
activity.putExtra("userPhoto", userPhoto.getText().toString());
|
||||
activity.putExtra("sender", sender.getText().toString());
|
||||
activity.putExtra("course", course.getText().toString());
|
||||
activity.putExtra("summary", summary.getText().toString());
|
||||
activity.putExtra("content", content.getText().toString());
|
||||
activity.putExtra("date", date.getText().toString());
|
||||
activity.putExtra("time", time.getText().toString());
|
||||
activity.putExtra("seenLocal", seenLocalText.getText().toString());
|
||||
startActivity(activity);
|
||||
|
||||
return true;
|
||||
}
|
||||
Intent activity = new Intent(getApplicationContext(),
|
||||
NotificationItem.class);
|
||||
activity.putExtra("notifCode", notifCode.getText().toString());
|
||||
activity.putExtra("eventCode", code.getText().toString());
|
||||
activity.putExtra("notificationType", type.getText().toString());
|
||||
activity.putExtra("userPhoto", userPhoto.getText().toString());
|
||||
activity.putExtra("sender", sender.getText().toString());
|
||||
activity.putExtra("course", course.getText().toString());
|
||||
activity.putExtra("summary", summary.getText().toString());
|
||||
activity.putExtra("content", content.getText().toString());
|
||||
activity.putExtra("date", date.getText().toString());
|
||||
activity.putExtra("time", time.getText().toString());
|
||||
activity.putExtra("seenLocal", seenLocalText.getText().toString());
|
||||
startActivity(activity);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -280,9 +275,9 @@ public class Notifications extends Module implements
|
|||
|
||||
refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container_expandablelist);
|
||||
list = (ExpandableListView) findViewById(R.id.expandablelist_pulltorefresh);
|
||||
emptyNotifTextView = (TextView) findViewById(R.id.list_item_title);
|
||||
emptyNotifTextView = findViewById(R.id.list_item_title);
|
||||
mBirthdayLayout = (LinearLayout) findViewById(R.id.notify_layout);
|
||||
mBirthdayTextView = (TextView) findViewById(R.id.notifyTextView);
|
||||
mBirthdayTextView = findViewById(R.id.notifyTextView);
|
||||
|
||||
groupItem = new ArrayList<>();
|
||||
childItem = new ArrayList<>();
|
||||
|
@ -331,7 +326,7 @@ public class Notifications extends Module implements
|
|||
|
||||
refreshScreen();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
@ -406,12 +401,12 @@ public class Notifications extends Module implements
|
|||
notifCount = 0;
|
||||
for (int i = 0; i < numNotif; i++) {
|
||||
SoapObject pii = (SoapObject) soap.getProperty(i);
|
||||
Long notifCode = Long.valueOf(pii.getProperty("notifCode")
|
||||
long notifCode = Long.parseLong(pii.getProperty("notifCode")
|
||||
.toString());
|
||||
Long eventCode = Long.valueOf(pii.getProperty(
|
||||
long eventCode = Long.parseLong(pii.getProperty(
|
||||
"eventCode").toString());
|
||||
String eventType = pii.getProperty("eventType").toString();
|
||||
Long eventTime = Long.valueOf(pii.getProperty("eventTime")
|
||||
long eventTime = Long.parseLong(pii.getProperty("eventTime")
|
||||
.toString());
|
||||
String userNickname = pii.getProperty("userNickname")
|
||||
.toString();
|
||||
|
@ -424,7 +419,7 @@ public class Notifications extends Module implements
|
|||
String userPhoto = pii.getProperty("userPhoto").toString();
|
||||
String location = pii.getProperty("location").toString();
|
||||
String summary = pii.getProperty("summary").toString();
|
||||
Integer status = Integer.valueOf(pii.getProperty("status")
|
||||
int status = Integer.parseInt(pii.getProperty("status")
|
||||
.toString());
|
||||
String content = pii.getProperty("content").toString();
|
||||
boolean notifReadSWAD = (status >= 4);
|
||||
|
@ -587,17 +582,14 @@ public class Notifications extends Module implements
|
|||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_markAllRead:
|
||||
if (item.getItemId() == R.id.action_markAllRead) {
|
||||
dbHelper.updateAllNotifications("seenLocal",
|
||||
Utils.parseBoolString(true));
|
||||
sendReadNotifications();
|
||||
refreshScreen();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -638,76 +630,8 @@ public class Notifications extends Module implements
|
|||
refreshLayout.setEnabled(enable);
|
||||
}
|
||||
});
|
||||
/*
|
||||
* Create a ListView-specific touch listener. ListViews are given special treatment because
|
||||
* by default they handle touches for their list items... i.e. they're in charge of drawing
|
||||
* the pressed state (the list selector), handling list item clicks, etc.
|
||||
*
|
||||
* Requires Android 3.1 (HONEYCOMB_MR1) or newer
|
||||
*/
|
||||
/*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
|
||||
SwipeListViewTouchListener touchListener =
|
||||
new SwipeListViewTouchListener(
|
||||
list,
|
||||
new SwipeListViewTouchListener.OnSwipeCallback() {
|
||||
@Override
|
||||
public void onSwipeLeft(ListView listView, int [] reverseSortedPositions) {
|
||||
if(reverseSortedPositions.length > 0) {
|
||||
swipeItem(reverseSortedPositions[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwipeRight(ListView listView, int [] reverseSortedPositions) {
|
||||
if(reverseSortedPositions.length > 0) {
|
||||
swipeItem(reverseSortedPositions[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartSwipe() {
|
||||
disableSwipe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopSwipe() {
|
||||
enableSwipe();
|
||||
}
|
||||
},
|
||||
true,
|
||||
true);
|
||||
|
||||
list.setOnTouchListener(touchListener);
|
||||
// Setting this scroll listener is required to ensure that during ListView scrolling,
|
||||
// we don't look for swipes.
|
||||
list.setOnScrollListener(touchListener.makeScrollListener(refreshLayout));
|
||||
} else {
|
||||
Log.w(TAG, "SwipeListViewTouchListener requires Android 3.1 (HONEYCOMB_MR1) or newer");
|
||||
list.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView absListView, int scrollState) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScroll(AbsListView absListView, int firstVisibleItem,
|
||||
int visibleItemCount, int totalItemCount) {
|
||||
|
||||
boolean enable = false;
|
||||
if(list != null && list.getChildCount() > 0){
|
||||
// check if the first item of the list is visible
|
||||
boolean firstItemVisible = list.getFirstVisiblePosition() == 0;
|
||||
// check if the top of the first item is visible
|
||||
boolean topOfFirstItemVisible = list.getChildAt(0).getTop() == 0;
|
||||
// enabling or disabling the refresh layout
|
||||
enable = firstItemVisible && topOfFirstItemVisible;
|
||||
}
|
||||
refreshLayout.setEnabled(enable);
|
||||
}
|
||||
});
|
||||
}*/
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||
private void setAppearance() {
|
||||
refreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
|
||||
android.R.color.holo_green_light,
|
||||
|
|
|
@ -59,7 +59,6 @@ import es.ugr.swad.swadroid.model.SWADNotification;
|
|||
import es.ugr.swad.swadroid.model.User;
|
||||
import es.ugr.swad.swadroid.modules.login.Login;
|
||||
import es.ugr.swad.swadroid.preferences.Preferences;
|
||||
import es.ugr.swad.swadroid.ssl.SecureConnection;
|
||||
import es.ugr.swad.swadroid.utils.Utils;
|
||||
import es.ugr.swad.swadroid.webservices.IWebserviceClient;
|
||||
import es.ugr.swad.swadroid.webservices.SOAPClient;
|
||||
|
@ -72,8 +71,6 @@ import es.ugr.swad.swadroid.webservices.SOAPClient;
|
|||
*/
|
||||
public class NotificationsSyncAdapterService extends Service {
|
||||
private static final String TAG = "NotificationsSyncAdapterService";
|
||||
private static Preferences prefs;
|
||||
private static SecureConnection conn;
|
||||
private static SyncAdapterImpl sSyncAdapter = null;
|
||||
private static int notifCount;
|
||||
private static DataBaseHelper dbHelper;
|
||||
|
@ -81,14 +78,9 @@ public class NotificationsSyncAdapterService extends Service {
|
|||
private static String METHOD_NAME = "";
|
||||
private static Object result;
|
||||
private static String errorMessage = "";
|
||||
private static boolean isConnected;
|
||||
private static boolean isDebuggable;
|
||||
public static final String START_SYNC = "es.ugr.swad.swadroid.sync.start";
|
||||
public static final String STOP_SYNC = "es.ugr.swad.swadroid.sync.stop";
|
||||
/**
|
||||
* Application context
|
||||
*/
|
||||
private static Context mCtx;
|
||||
|
||||
public NotificationsSyncAdapterService() {
|
||||
super();
|
||||
|
@ -100,7 +92,6 @@ public class NotificationsSyncAdapterService extends Service {
|
|||
public SyncAdapterImpl(Context context) {
|
||||
super(context, true);
|
||||
mContext = context;
|
||||
mCtx = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -187,7 +178,6 @@ public class NotificationsSyncAdapterService extends Service {
|
|||
*/
|
||||
@Override
|
||||
public void onCreate() {
|
||||
isConnected = Utils.connectionAvailable(this);
|
||||
// Check if debug mode is enabled
|
||||
try {
|
||||
getPackageManager().getApplicationInfo(
|
||||
|
@ -198,7 +188,6 @@ public class NotificationsSyncAdapterService extends Service {
|
|||
}
|
||||
|
||||
try {
|
||||
prefs = new Preferences(this);
|
||||
dbHelper = new DataBaseHelper(this);
|
||||
//Initialize webservices client
|
||||
webserviceClient = null;
|
||||
|
@ -206,19 +195,44 @@ public class NotificationsSyncAdapterService extends Service {
|
|||
Log.e(TAG, "Error initializing database and preferences", e);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
||||
Log.i(TAG, "Starting persistent notification in custom foreground mode");
|
||||
startCustomForeground();
|
||||
} else {
|
||||
Log.i(TAG, "Starting persistent notification in standard foreground mode");
|
||||
startForeground(1, new Notification());
|
||||
}
|
||||
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
Intent broadcastIntent = new Intent();
|
||||
broadcastIntent.setAction("restartNotificationsService");
|
||||
broadcastIntent.setClass(this, RestarterNotificationsReceiver.class);
|
||||
this.sendBroadcast(broadcastIntent);
|
||||
}
|
||||
|
||||
private void startCustomForeground() {
|
||||
Notification notification = AlertNotificationFactory.createBackgroundNotification(
|
||||
this,
|
||||
getString(R.string.appRunningBackground),
|
||||
R.drawable.ic_launcher_swadroid_notif,
|
||||
R.drawable.ic_launcher_swadroid);
|
||||
|
||||
startForeground(2, notification);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.app.Service#onStartCommand(android.content.Intent, int, int)
|
||||
*/
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
super.onStartCommand(intent, flags, startId);
|
||||
// return START_NOT_STICKY - we want this Service to be left running
|
||||
// unless explicitly stopped, and it's process is killed, we want it to
|
||||
// be restarted
|
||||
return START_STICKY;
|
||||
return START_REDELIVER_INTENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -342,10 +356,10 @@ public class NotificationsSyncAdapterService extends Service {
|
|||
notifCount = 0;
|
||||
for (int i = 0; i < numNotif; i++) {
|
||||
SoapObject pii = (SoapObject) soap.getProperty(i);
|
||||
Long notifCode = Long.valueOf(pii.getProperty("notifCode").toString());
|
||||
Long eventCode = Long.valueOf(pii.getProperty("eventCode").toString());
|
||||
long notifCode = Long.parseLong(pii.getProperty("notifCode").toString());
|
||||
long eventCode = Long.parseLong(pii.getProperty("eventCode").toString());
|
||||
String eventType = pii.getProperty("eventType").toString();
|
||||
Long eventTime = Long.valueOf(pii.getProperty("eventTime").toString());
|
||||
long eventTime = Long.parseLong(pii.getProperty("eventTime").toString());
|
||||
String userNickname = pii.getProperty("userNickname").toString();
|
||||
String userSurname1 = pii.getProperty("userSurname1").toString();
|
||||
String userSurname2 = pii.getProperty("userSurname2").toString();
|
||||
|
@ -353,7 +367,7 @@ public class NotificationsSyncAdapterService extends Service {
|
|||
String userPhoto = pii.getProperty("userPhoto").toString();
|
||||
String location = pii.getProperty("location").toString();
|
||||
String summary = pii.getProperty("summary").toString();
|
||||
Integer status = Integer.valueOf(pii.getProperty("status").toString());
|
||||
int status = Integer.parseInt(pii.getProperty("status").toString());
|
||||
String content = pii.getProperty("content").toString();
|
||||
boolean notifReadSWAD = (status >= 4);
|
||||
boolean notifCancelled = (status >= 8);
|
||||
|
|
|
@ -18,11 +18,9 @@
|
|||
*/
|
||||
package es.ugr.swad.swadroid.preferences;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
|
@ -177,7 +175,6 @@ public class Preferences {
|
|||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public Preferences(Context ctx) {
|
||||
getPreferences(ctx);
|
||||
|
||||
|
|
|
@ -23,6 +23,11 @@
|
|||
<li type="disc">Añadido módulo para localización en interiores</li>
|
||||
</ul>-->
|
||||
|
||||
<h4>1.5.9 (upcoming)</h4>
|
||||
<ul>
|
||||
<li type="disc">Añadido soporte para la descarga de notificaciones en segundo plano cuando la optimización de batería está habilitada</li>
|
||||
</ul>
|
||||
|
||||
<h4>1.5.8 (2022-05-23)</h4>
|
||||
<ul>
|
||||
<li type="disc">Corregida descarga de notificaciones en Android 12 (S)</li>
|
||||
|
|
|
@ -23,6 +23,11 @@
|
|||
<li type="disc">Added indoor location module</li>
|
||||
</ul>-->
|
||||
|
||||
<h4>1.5.9 (upcoming)</h4>
|
||||
<ul>
|
||||
<li type="disc">Added support for background notification download when power save mode is enabled</li>
|
||||
</ul>
|
||||
|
||||
<h4>1.5.8 (2022-05-23)</h4>
|
||||
<ul>
|
||||
<li type="disc">Fixed notifications downloads on Android 12 (S)</li>
|
||||
|
|
|
@ -356,4 +356,5 @@
|
|||
<string name="checkIn">Hora</string>
|
||||
<string name="lostLocation">Ubicación no encontrada</string>
|
||||
<string name="nearestLocation">Punto de acceso inalámbrico más cercano</string>
|
||||
<string name="appRunningBackground">SWADroid se está ejecutando</string>
|
||||
</resources>
|
||||
|
|
|
@ -372,4 +372,5 @@
|
|||
<string name="checkIn">Time</string>
|
||||
<string name="lostLocation">Location not found</string>
|
||||
<string name="nearestLocation">Nearest wireless access point</string>
|
||||
<string name="appRunningBackground">SWADroid is running</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue
Block a user