diff --git a/app/build.gradle b/app/build.gradle
index 018d91fdc4911fef8fe638e8d814616c33e26dfb..e1ec7cf1f328351a27a6b23fbe9a249dc46bdaa9 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -60,6 +60,7 @@ dependencies {
api project(':NextcloudLib')
implementation fileTree(include: ['*.jar'], dir: 'libs')
api 'androidx.annotation:annotation:1.3.0'
+ implementation 'androidx.core:core:1.6.0'
def work_version = "2.7.1"
// (Java only)
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 29b9ba121d55c864aa4496b16dfe80dff8b48ab3..d2d8002ad1efd6a93e64efcdbd7259c904ef9e8f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -17,6 +17,8 @@ http://www.gnu.org/licenses/gpl.html
+
+
datas = new ArrayList<>();
datas.add(syncedState.getSyncedFolderId());
+ datas.add(relativeQuotaBeforeFileUpload);
final RemoteOperationResult finalResult = new RemoteOperationResult(resultCode);
finalResult.setData(datas);
return finalResult;
@@ -194,7 +198,9 @@ public class UploadFileOperation extends RemoteOperation {
return new RemoteOperationResult(ResultCode.QUOTA_EXCEEDED);
} else {
Log.d(TAG, "Quota Okay");
- return new RemoteOperationResult(ResultCode.OK);
+ RemoteOperationResult result = new RemoteOperationResult(ResultCode.OK);
+ result.setSingleData((Double) userInfo.getQuota().getRelative());
+ return result;
}
} else {
Log.w(TAG, "getRemoteUserInfoOperation failed: "+ocsResult.getHttpCode() );
diff --git a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java
index aad4927034c9ef4244deefb11fe0ad1ade18f041..afc77d70aec182aa708f95a36d7d8770011295c2 100644
--- a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java
+++ b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java
@@ -24,6 +24,7 @@ import android.os.Message;
import android.util.Log;
import androidx.annotation.Nullable;
+import androidx.core.app.NotificationCompat;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
@@ -35,6 +36,7 @@ import java.util.Collection;
import java.util.Hashtable;
import java.util.concurrent.ConcurrentLinkedDeque;
+import foundation.e.drive.R;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.models.DownloadRequest;
import foundation.e.drive.models.SyncRequest;
@@ -125,6 +127,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation
Log.v(TAG, " an operation has been poll from queue");
if (CommonUtils.isThisSyncAllowed(account, request.getSyncedFileState().isMediaType())) {
+ CommonUtils.createNotificationChannel(this);
startedOperations.put(operation, threadIndex);
threadPool[threadIndex] = operation.execute(client, this, handler);
threadWorkingState[threadIndex] = true;
@@ -149,6 +152,16 @@ public class SynchronizationService extends Service implements OnRemoteOperation
}
} else {
String operationClassName = callerOperation.getClass().getSimpleName();
+ if (callerOperation instanceof UploadFileOperation) {
+ final Float relativeQuota = (Float) result.getData().get(1);
+ if (relativeQuota >= 99.0) {
+ addNotification(getString(R.string.notif_quota_nearlyReached_title), getString(R.string.notif_quota_99Plus_text));
+ } else if (relativeQuota >= 90.0) {
+ addNotification(getString(R.string.notif_quota_nearlyReached_title), getString(R.string.notif_quota_90Plus_text));
+ } else if (relativeQuota >= 80.0) {
+ addNotification(getString(R.string.notif_quota_nearlyReached_title), getString(R.string.notif_quota_80Plus_text));
+ }
+ }
switch (result.getCode()) {
case OK:
Log.d(TAG, operationClassName + " Succeed");
@@ -187,19 +200,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation
case QUOTA_EXCEEDED:
//Case specific to UploadFileOperation
Log.w(TAG, "Quota_EXCEEDED");
-
- NotificationManager nM = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
-
- Notification notif = new Notification.Builder(this, AppConstants.notificationChannelID)
- .setContentIntent(PendingIntent.getActivity(getApplicationContext(),
- 0,
- new Intent(Intent.ACTION_VIEW, client.getBaseUri()),
- 0))
- .setContentText("Your drive lacks of space. Tap to check " + client.getBaseUri())
- .setSmallIcon(android.R.drawable.stat_sys_warning)
- .build();
-
- nM.notify(1,notif );
+ addNotification(getString(R.string.notif_quota_execeeded_title), getString(R.string.notif_quota_execeeded_text));
break;
case FILE_NOT_FOUND:
//Case specific to DownloadFileOperation
@@ -233,6 +234,25 @@ public class SynchronizationService extends Service implements OnRemoteOperation
return operation;
}
+ /**
+ * send notification to inform user that he lacks space on ecloud
+ * Improvement idea:
+ * - add translatable message & title
+ * - make message & title to be a parameter of the method, so we could reuse the function somewhere
+ * - else with different notification. File conflict for example.
+ **/
+ private void addNotification(String title, String text){
+ final NotificationCompat.Builder builder =
+ new NotificationCompat.Builder(this, AppConstants.notificationChannelID)
+ .setSmallIcon(android.R.drawable.stat_sys_warning)
+ .setContentTitle(title)
+ .setContentText(text+ client.getBaseUri());
+ // Add as notification
+ final NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+ manager.notify(0, builder.build());
+ }
+
+
/**
* Handler for the class
diff --git a/app/src/main/java/foundation/e/drive/utils/AppConstants.java b/app/src/main/java/foundation/e/drive/utils/AppConstants.java
index fec0762dab95493f427f8efe074e6b28e44d73b3..63f00e488e3fc1c0d56650891354aac62757571f 100644
--- a/app/src/main/java/foundation/e/drive/utils/AppConstants.java
+++ b/app/src/main/java/foundation/e/drive/utils/AppConstants.java
@@ -34,8 +34,7 @@ public abstract class AppConstants {
public static final String[] MEDIA_SYNCABLE_CATEGORIES = new String[]{"Images", "Movies", "Music", "Ringtones", "Documents", "Podcasts"};
public static final String[] SETTINGS_SYNCABLE_CATEGORIES = new String[] {"Rom settings"};
- public static final String notificationChannelID ="3310";
- public static final String notificationChannelName="eDrive channel";
+ public static final String notificationChannelID ="foundation.e.drive";
public static final String WORK_GENERIC_TAG="eDrive";
public static final String WORK_INITIALIZATION_TAG="eDrive-init";
public static final String USER_AGENT = "eos("+getBuildTime()+")-eDrive("+ BuildConfig.VERSION_NAME +")";
diff --git a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java
index 2cab9888ee9a184a658b2df0fb307a713d4b45e9..563841fd32463184f9e19c088431767c26959bfa 100644
--- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java
+++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java
@@ -12,6 +12,8 @@ package foundation.e.drive.utils;
import android.accounts.Account;
import android.accounts.AccountManager;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
import android.app.Service;
import android.content.ContentResolver;
import android.content.Context;
@@ -19,6 +21,7 @@ import android.media.MediaScannerConnection;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.Uri;
+import android.os.Build;
import android.util.Log;
import android.webkit.MimeTypeMap;
@@ -35,6 +38,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
+import foundation.e.drive.R;
import foundation.e.drive.models.SyncedFolder;
import foundation.e.drive.work.CreateRemoteFolderWorker;
import foundation.e.drive.work.FirstStartWorker;
@@ -389,4 +393,18 @@ public abstract class CommonUtils {
.putBoolean(DATA_KEY_MEDIATYPE, folder.isMediaType())
.build();
}
+
+ public static void createNotificationChannel(Context context){
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ final CharSequence name = context.getString(R.string.notif_channel_name);
+ final String description = context.getString(R.string.notif_channel_description);
+ int importance = NotificationManager.IMPORTANCE_DEFAULT;
+ final NotificationChannel channel = new NotificationChannel(AppConstants.notificationChannelID, name, importance);
+ channel.setDescription(description);
+ // Register the channel with the system; you can't change the importance
+ // or other notification behaviors after this
+ final NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
+ notificationManager.createNotificationChannel(channel);
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 8f9814a8960fdc198e3c59e0825e47b42749a8a7..4ba1b93508f6ffa0c5fbd3c7f7e36d625d53674c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,4 +1,12 @@
/e/ Drive
e.foundation.webdav.eelo
+ eDrive\'s notification
+ eDrive\'s notification channel
+ /e/ account\'s quota reached
+ /e/ account\'s quota nearly reached
+ eDrive can\'t upload a file that is bigger than remaining quota at:
+ You filled 99% of your /e/\'s account quota. check:
+ You filled 90% of your /e/\'s account quota. check:
+ You filled 80% of your /e/\'s account quota. check: