mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-29 05:15:13 +02:00
Improved quota handling
This commit is contained in:
@@ -218,10 +218,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
account.backoff_until == null ? "-" : DTF.format(account.backoff_until)));
|
||||
tvBackoff.setVisibility(account.backoff_until == null || !settings ? View.GONE : View.VISIBLE);
|
||||
|
||||
Integer percent = null;
|
||||
if (!settings && account.quota_usage != null && account.quota_limit != null)
|
||||
percent = Math.round(account.quota_usage * 100f / account.quota_limit);
|
||||
|
||||
Integer percent = (settings ? null : account.getQuotaPercentage());
|
||||
tvUsage.setText(percent == null ? null : NF.format(percent) + "%");
|
||||
tvUsage.setVisibility(percent == null ? View.GONE : View.VISIBLE);
|
||||
tvQuota.setText(context.getString(R.string.title_storage_quota,
|
||||
|
||||
@@ -121,16 +121,13 @@ public class AdapterNavAccount extends RecyclerView.Adapter<AdapterNavAccount.Vi
|
||||
|
||||
ivExternal.setVisibility(View.GONE);
|
||||
|
||||
int percent;
|
||||
if (account.quota_usage == null || account.quota_limit == null)
|
||||
percent = 0;
|
||||
else
|
||||
percent = Math.round(account.quota_usage * 100f / account.quota_limit);
|
||||
Integer percent = account.getQuotaPercentage();
|
||||
|
||||
if (account.error != null) {
|
||||
ivWarning.setEnabled(false);
|
||||
ivWarning.setImageResource(R.drawable.twotone_warning_24);
|
||||
ivWarning.setVisibility(View.VISIBLE);
|
||||
} else if (percent > QUOTA_WARNING) {
|
||||
} else if (percent != null && percent > QUOTA_WARNING) {
|
||||
ivWarning.setEnabled(true);
|
||||
ivWarning.setImageResource(R.drawable.twotone_disc_full_24);
|
||||
ivWarning.setVisibility(View.VISIBLE);
|
||||
|
||||
@@ -205,6 +205,14 @@ public class EntityAccount extends EntityOrder implements Serializable {
|
||||
return id;
|
||||
}
|
||||
|
||||
Integer getQuotaPercentage() {
|
||||
if (quota_usage == null || quota_limit == null)
|
||||
return null;
|
||||
|
||||
int percent = Math.round(quota_usage * 100f / quota_limit);
|
||||
return (percent > 100 ? null : percent);
|
||||
}
|
||||
|
||||
@Override
|
||||
String[] getSortTitle(Context context) {
|
||||
return new String[]{name, null};
|
||||
|
||||
@@ -303,12 +303,16 @@ public class FragmentFolders extends FragmentBase {
|
||||
public void onChanged(@Nullable EntityAccount account) {
|
||||
imap = (account != null && account.protocol == EntityAccount.TYPE_IMAP);
|
||||
|
||||
if (account != null && account.quota_usage != null && account.quota_limit != null) {
|
||||
int percent = Math.round(account.quota_usage * 100f / account.quota_limit);
|
||||
setSubtitle(getString(R.string.title_name_count,
|
||||
account.name, NF.format(percent) + "%"));
|
||||
} else
|
||||
setSubtitle(account == null ? null : account.name);
|
||||
if (account == null)
|
||||
setSubtitle(null);
|
||||
else {
|
||||
Integer percent = account.getQuotaPercentage();
|
||||
if (percent == null)
|
||||
setSubtitle(account.name);
|
||||
else
|
||||
setSubtitle(getString(R.string.title_name_count,
|
||||
account.name, NF.format(percent) + "%"));
|
||||
}
|
||||
|
||||
if (account != null && account.error != null)
|
||||
fabError.show();
|
||||
|
||||
@@ -1311,7 +1311,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
|
||||
db.account().setAccountMaxSize(account.id, iservice.getMaxSize());
|
||||
if (istore instanceof IMAPStore)
|
||||
updateQuota(((IMAPStore) iservice.getStore()), account);
|
||||
updateQuota(this, ((IMAPStore) iservice.getStore()), account);
|
||||
|
||||
// Listen for folder events
|
||||
iservice.getStore().addFolderListener(new FolderAdapter() {
|
||||
@@ -2183,22 +2183,24 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
}
|
||||
}
|
||||
|
||||
private void updateQuota(IMAPStore istore, EntityAccount account) {
|
||||
private void updateQuota(Context context, IMAPStore istore, EntityAccount account) {
|
||||
DB db = DB.getInstance(this);
|
||||
try {
|
||||
if (istore.hasCapability("QUOTA")) {
|
||||
// https://tools.ietf.org/id/draft-melnikov-extra-quota-00.html
|
||||
// https://datatracker.ietf.org/doc/html/rfc2087
|
||||
Quota[] quotas = istore.getQuota("INBOX");
|
||||
if (quotas != null) {
|
||||
long usage = 0;
|
||||
long limit = 0;
|
||||
Long usage = null;
|
||||
Long limit = null;
|
||||
for (Quota quota : quotas)
|
||||
if (quota.resources != null)
|
||||
for (Quota.Resource resource : quota.resources) {
|
||||
Log.i("Quota " + resource.name + " " + resource.usage + "/" + resource.limit);
|
||||
EntityLog.log(context, "Quota " + resource.name + " " + resource.usage + "/" + resource.limit);
|
||||
if ("STORAGE".equalsIgnoreCase(resource.name)) {
|
||||
usage += resource.usage * 1024;
|
||||
limit = Math.max(limit, resource.limit * 1024);
|
||||
if (resource.usage >= 0)
|
||||
usage = (usage == null ? 0L : usage) + resource.usage * 1024;
|
||||
if (resource.limit > 0)
|
||||
limit = Math.max(limit == null ? 0L : limit, resource.limit * 1024);
|
||||
}
|
||||
}
|
||||
db.account().setAccountQuota(account.id, usage, limit);
|
||||
|
||||
Reference in New Issue
Block a user