show outdated warning also on very old servers

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2023-09-08 13:59:33 +02:00
parent cb21ef01a0
commit 623590ba6c
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
4 changed files with 77 additions and 10 deletions

View file

@ -0,0 +1,52 @@
/*
*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2023 Tobias Kaminsky
* Copyright (C) 2023 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.owncloud.android.utils.theme
import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.resources.status.NextcloudVersion
import com.owncloud.android.lib.resources.status.OwnCloudVersion
import junit.framework.TestCase.assertFalse
import junit.framework.TestCase.assertTrue
import org.junit.Test
class CapabilityUtilsIT : AbstractIT() {
@Test
fun checkOutdatedWarning() {
assertFalse(test(NextcloudVersion.nextcloud_27))
assertFalse(test(NextcloudVersion.nextcloud_26))
assertFalse(test(NextcloudVersion.nextcloud_25))
assertFalse(test(NextcloudVersion.nextcloud_24))
assertTrue(test(NextcloudVersion.nextcloud_23))
assertTrue(test(NextcloudVersion.nextcloud_22))
assertTrue(test(NextcloudVersion.nextcloud_21))
assertTrue(test(OwnCloudVersion.nextcloud_20))
assertTrue(test(OwnCloudVersion.nextcloud_19))
assertTrue(test(OwnCloudVersion.nextcloud_18))
assertTrue(test(OwnCloudVersion.nextcloud_17))
assertTrue(test(OwnCloudVersion.nextcloud_16))
}
private fun test(version: OwnCloudVersion): Boolean {
return CapabilityUtils.checkOutdatedWarning(targetContext.resources, version, false)
}
}

View file

@ -125,6 +125,7 @@ import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertL
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.ErrorMessageAdapter;
import com.owncloud.android.utils.PermissionUtil;
import com.owncloud.android.utils.theme.CapabilityUtils;
import com.owncloud.android.utils.theme.ViewThemeUtils;
import java.io.InputStream;
@ -900,9 +901,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
mServerInfo = (GetServerInfoOperation.ServerInfo) (result.getData().get(0));
// show outdated warning
if (getResources().getBoolean(R.bool.show_outdated_server_warning) &&
MainApp.OUTDATED_SERVER_VERSION.isSameMajorVersion(mServerInfo.mVersion) &&
!mServerInfo.hasExtendedSupport) {
if (CapabilityUtils.checkOutdatedWarning(getResources(),
mServerInfo.mVersion,
mServerInfo.hasExtendedSupport)) {
DisplayUtils.showServerOutdatedSnackbar(this, Snackbar.LENGTH_INDEFINITE);
}

View file

@ -135,6 +135,7 @@ import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.PermissionUtil;
import com.owncloud.android.utils.PushUtils;
import com.owncloud.android.utils.StringUtils;
import com.owncloud.android.utils.theme.CapabilityUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@ -436,14 +437,14 @@ public class FileDisplayActivity extends FileActivity
private void checkOutdatedServer() {
Optional<User> user = getUser();
OwnCloudVersion serverVersion = user.get().getServer().getVersion();
if (getResources().getBoolean(R.bool.show_outdated_server_warning) && user.isPresent()) {
OwnCloudVersion serverVersion = user.get().getServer().getVersion();
// show outdated warning
if (MainApp.OUTDATED_SERVER_VERSION.isSameMajorVersion(serverVersion) &&
getCapabilities().getExtendedSupport().isFalse()) {
DisplayUtils.showServerOutdatedSnackbar(this, Snackbar.LENGTH_LONG);
}
// show outdated warning
if (user.isPresent() &&
CapabilityUtils.checkOutdatedWarning(getResources(),
serverVersion,
getCapabilities().getExtendedSupport().isTrue())) {
DisplayUtils.showServerOutdatedSnackbar(this, Snackbar.LENGTH_LONG);
}
}

View file

@ -24,12 +24,16 @@ package com.owncloud.android.utils.theme;
import android.accounts.Account;
import android.content.Context;
import android.content.res.Resources;
import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManagerImpl;
import com.nextcloud.java.util.Optional;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import java.util.HashMap;
import java.util.Map;
@ -88,4 +92,13 @@ public final class CapabilityUtils {
public static void updateCapability(OCCapability capability) {
cachedCapabilities.put(capability.getAccountName(), capability);
}
public static boolean checkOutdatedWarning(Resources resources,
OwnCloudVersion version,
boolean hasExtendedSupport) {
return resources.getBoolean(R.bool.show_outdated_server_warning) &&
(MainApp.OUTDATED_SERVER_VERSION.isSameMajorVersion(version) ||
version.isOlderThan(MainApp.OUTDATED_SERVER_VERSION))
&& !hasExtendedSupport;
}
}