Merge pull request #10925 from nextcloud/fix/nc25-colors

Fix login colors in NC25
This commit is contained in:
Álvaro Brey 2022-10-26 11:31:04 +02:00 committed by GitHub
commit 190f5dbbd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -83,10 +83,12 @@ import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.onboarding.FirstRunActivity;
import com.nextcloud.client.onboarding.OnboardingService;
import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.java.util.Optional;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.databinding.AccountSetupBinding;
import com.owncloud.android.databinding.AccountSetupWebviewBinding;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
@ -103,10 +105,12 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.GetCapabilitiesRemoteOperation;
import com.owncloud.android.lib.resources.status.NextcloudVersion;
import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation;
import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod;
import com.owncloud.android.operations.GetCapabilitiesOperation;
import com.owncloud.android.operations.GetServerInfoOperation;
import com.owncloud.android.providers.DocumentsStorageProvider;
import com.owncloud.android.services.OperationsService;
@ -119,7 +123,6 @@ 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;
@ -127,6 +130,7 @@ import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Executors;
import javax.inject.Inject;
@ -134,6 +138,7 @@ import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
@ -440,8 +445,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
accountSetupWebviewBinding.loginWebviewProgressBar.setVisibility(View.GONE);
accountSetupWebviewBinding.loginWebview.setVisibility(View.VISIBLE);
viewThemeUtils.platform.colorStatusBar(AuthenticatorActivity.this, primaryColor);
getWindow().setNavigationBarColor(primaryColor);
if (mServerInfo.mVersion != null && mServerInfo.mVersion.isOlderThan(NextcloudVersion.nextcloud_25)) {
viewThemeUtils.platform.colorStatusBar(AuthenticatorActivity.this, primaryColor);
getWindow().setNavigationBarColor(primaryColor);
} else {
viewThemeUtils.platform.resetStatusBar(AuthenticatorActivity.this);
getWindow().setNavigationBarColor(ContextCompat.getColor(AuthenticatorActivity.this, R.color.bg_default));
}
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
@ -1132,15 +1142,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
if (success) {
accountManager.setCurrentOwnCloudAccount(mAccount.name);
setupColorCapability();
if (onlyAdd) {
finish();
} else {
Intent i = new Intent(this, FileDisplayActivity.class);
i.setAction(FileDisplayActivity.RESTART);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
getUserCapabilitiesAndFinish();
} else {
// init webView again
if (accountSetupWebviewBinding != null) {
@ -1192,15 +1194,36 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
}
}
/**
* Caches a fake OCCapability with only the server color, so that it is immediately available for drawing the next
* screens
*/
private void setupColorCapability() {
final OCCapability colorCapability = new OCCapability();
colorCapability.setServerColor(colorUtil.colorToHexString(primaryColor));
colorCapability.setAccountName(mAccount.name);
CapabilityUtils.updateCapability(colorCapability);
private void endSuccess() {
if (onlyAdd) {
finish();
} else {
Intent i = new Intent(this, FileDisplayActivity.class);
i.setAction(FileDisplayActivity.RESTART);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
}
private void getUserCapabilitiesAndFinish() {
final Handler handler = new Handler();
final Optional<User> user = accountManager.getUser(mAccount.name);
if (user.isPresent()) {
Executors.newSingleThreadExecutor().execute(() -> {
try {
final FileDataStorageManager storageManager = new FileDataStorageManager(user.get(), getContentResolver());
new GetCapabilitiesOperation(storageManager).execute(MainApp.getAppContext());
handler.post(this::endSuccess);
} catch (Exception e) {
Log_OC.e(TAG, "Failed to fetch capabilities", e);
handler.post(this::endSuccess);
}
});
} else {
Log_OC.w(TAG, "User not present for fetching capabilities");
endSuccess();
}
}
/**