diff --git a/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java b/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java index 79ec543711..df40d3f611 100644 --- a/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java +++ b/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java @@ -67,6 +67,9 @@ public class ArbitraryDataProvider { ); } + public void storeOrUpdateKeyValue(String accountName, String key, long newValue) { + storeOrUpdateKeyValue(accountName, key, String.valueOf(newValue)); + } public void storeOrUpdateKeyValue(String accountName, String key, String newValue) { ArbitraryDataSet data = getArbitraryDataSet(accountName, key); @@ -106,9 +109,8 @@ public class ArbitraryDataProvider { } } - - public Long getLongValue(Account account, String key) { - String value = getValue(account, key); + public Long getLongValue(String accountName, String key) { + String value = getValue(accountName, key); if (value.isEmpty()) { return -1l; @@ -117,6 +119,11 @@ public class ArbitraryDataProvider { } } + + public Long getLongValue(Account account, String key) { + return getLongValue(account.name, key); + } + public boolean getBooleanValue(String accountName, String key) { return TRUE.equalsIgnoreCase(getValue(accountName, key)); } diff --git a/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java b/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index 09d2b1617e..f97eaab231 100644 --- a/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@ -89,6 +89,7 @@ public final class ThumbnailsCacheManager { private static final String PNG_MIMETYPE = "image/png"; private static final String CACHE_FOLDER = "thumbnailCache"; public static final String AVATAR = "avatar"; + private static final String AVATAR_TIMESTAMP = "avatarTimestamp"; private static final String ETAG = "ETag"; private static final Object mThumbnailsDiskCacheLock = new Object(); @@ -868,28 +869,29 @@ public final class ThumbnailsCacheManager { private @NotNull Drawable doAvatarInBackground() { - Bitmap avatar = null; + Bitmap avatar; String accountName = mUserId + "@" + mServerName; ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(mContext.getContentResolver()); String eTag = arbitraryDataProvider.getValue(accountName, ThumbnailsCacheManager.AVATAR); + long timestamp = arbitraryDataProvider.getLongValue(accountName, ThumbnailsCacheManager.AVATAR_TIMESTAMP); String avatarKey = "a_" + mUserId + "_" + mServerName + "_" + eTag; + avatar = getBitmapFromDiskCache(avatarKey); - int px = getAvatarDimension(); - - // Download avatar from server - if (mClient != null) { + // Download avatar from server, only if older than 60 min or avatar does not exist + if ((System.currentTimeMillis() - timestamp >= 60 * 60 * 1000 || avatar == null) && mClient != null) { GetMethod get = null; try { + int px = getAvatarDimension(); String uri = mClient.getBaseUri() + "/index.php/avatar/" + Uri.encode(mUserId) + "/" + px; Log_OC.d("Avatar", "URI: " + uri); get = new GetMethod(uri); // only use eTag if available and corresponding avatar is still there // (might be deleted from cache) - if (!eTag.isEmpty() && getBitmapFromDiskCache(avatarKey) != null) { + if (!eTag.isEmpty() && avatar != null) { get.setRequestHeader("If-None-Match", eTag); } @@ -916,6 +918,9 @@ public final class ThumbnailsCacheManager { avatar = handlePNG(avatar, px, px); String newImageKey = "a_" + mUserId + "_" + mServerName + "_" + newETag; addBitmapToCache(newImageKey, avatar); + arbitraryDataProvider.storeOrUpdateKeyValue(accountName, + ThumbnailsCacheManager.AVATAR_TIMESTAMP, + System.currentTimeMillis()); } else { return TextDrawable.createAvatar(mAccount, mAvatarRadius); } @@ -923,10 +928,11 @@ public final class ThumbnailsCacheManager { case HttpStatus.SC_NOT_MODIFIED: // old avatar - avatar = getBitmapFromDiskCache(avatarKey); mClient.exhaustResponse(get.getResponseBodyAsStream()); + arbitraryDataProvider.storeOrUpdateKeyValue(accountName, + ThumbnailsCacheManager.AVATAR_TIMESTAMP, + System.currentTimeMillis()); break; - default: // everything else mClient.exhaustResponse(get.getResponseBodyAsStream()); diff --git a/src/main/java/com/owncloud/android/jobs/ContactsBackupJob.java b/src/main/java/com/owncloud/android/jobs/ContactsBackupJob.java index 5ef97e3009..6453c3eeae 100644 --- a/src/main/java/com/owncloud/android/jobs/ContactsBackupJob.java +++ b/src/main/java/com/owncloud/android/jobs/ContactsBackupJob.java @@ -42,7 +42,6 @@ import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.operations.UploadFileOperation; import com.owncloud.android.services.OperationsService; -import com.owncloud.android.ui.activity.ContactsPreferenceActivity; import java.io.File; import java.io.FileWriter; @@ -55,6 +54,8 @@ import java.util.List; import androidx.annotation.NonNull; +import static com.owncloud.android.ui.activity.ContactsPreferenceActivity.PREFERENCE_CONTACTS_LAST_BACKUP; + /** * Job that backup contacts to /Contacts-Backup and deletes files older than x days */ @@ -81,9 +82,13 @@ public class ContactsBackupJob extends Job { final Account account = accountManager.getAccountByName(bundle.getString(ACCOUNT, "")); + if (account == null) { + return Result.FAILURE; + } + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver()); Long lastExecution = arbitraryDataProvider.getLongValue(account, - ContactsPreferenceActivity.PREFERENCE_CONTACTS_LAST_BACKUP); + PREFERENCE_CONTACTS_LAST_BACKUP); if (force || (lastExecution + 24 * 60 * 60 * 1000) < Calendar.getInstance().getTimeInMillis()) { Log_OC.d(TAG, "start contacts backup job"); @@ -102,8 +107,8 @@ public class ContactsBackupJob extends Job { // store execution date arbitraryDataProvider.storeOrUpdateKeyValue(account.name, - ContactsPreferenceActivity.PREFERENCE_CONTACTS_LAST_BACKUP, - String.valueOf(Calendar.getInstance().getTimeInMillis())); + PREFERENCE_CONTACTS_LAST_BACKUP, + Calendar.getInstance().getTimeInMillis()); } else { Log_OC.d(TAG, "last execution less than 24h ago"); } diff --git a/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.java b/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.java index 5d25752cae..a5e8772e57 100644 --- a/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.java +++ b/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.java @@ -411,7 +411,7 @@ public class PreviewImageActivity extends FileActivity implements } // Call to reset image zoom to initial state - ((PreviewImagePagerAdapter) mViewPager.getAdapter()).resetZoom(); + // ((PreviewImagePagerAdapter) mViewPager.getAdapter()).resetZoom(); } } diff --git a/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java b/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java index 9b70d440de..d88cebcfbc 100644 --- a/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -97,6 +97,7 @@ import pl.droidsonroids.gif.GifDrawable; public class PreviewImageFragment extends FileFragment implements Injectable { private static final String EXTRA_FILE = "FILE"; + private static final String EXTRA_ZOOM = "ZOOM"; private static final String ARG_FILE = "FILE"; private static final String ARG_IGNORE_FIRST = "IGNORE_FIRST"; @@ -219,8 +220,9 @@ public class PreviewImageFragment extends FileFragment implements Injectable { super.onActivityCreated(savedInstanceState); if (savedInstanceState != null) { if (!mIgnoreFirstSavedState) { - OCFile file = savedInstanceState.getParcelable(PreviewImageFragment.EXTRA_FILE); + OCFile file = savedInstanceState.getParcelable(EXTRA_FILE); setFile(file); + mImageView.setScale(savedInstanceState.getFloat(EXTRA_ZOOM)); } else { mIgnoreFirstSavedState = false; } @@ -230,7 +232,9 @@ public class PreviewImageFragment extends FileFragment implements Injectable { @Override public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); - outState.putParcelable(PreviewImageFragment.EXTRA_FILE, getFile()); + + outState.putFloat(EXTRA_ZOOM, mImageView.getScale()); + outState.putParcelable(EXTRA_FILE, getFile()); } @Override