Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show outdated warning also on very old servers #11954

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
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;
Expand Down Expand Up @@ -900,9 +901,9 @@ private void onGetServerInfoFinish(RemoteOperationResult result) {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
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;
Expand Down Expand Up @@ -436,14 +437,14 @@ public void onClick(DialogInterface dialog, int which) {

private void checkOutdatedServer() {
Optional<User> user = getUser();

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);
}
OwnCloudVersion serverVersion = user.get().getServer().getVersion();

// show outdated warning
if (user.isPresent() &&
CapabilityUtils.checkOutdatedWarning(getResources(),
serverVersion,
getCapabilities().getExtendedSupport().isTrue())) {
DisplayUtils.showServerOutdatedSnackbar(this, Snackbar.LENGTH_LONG);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@

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;
Expand Down Expand Up @@ -88,4 +92,13 @@ public static OCCapability getCapability(User user, Context context) {
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;
}
}
Loading