From 2afbf1802bfcd3fb489aa82799ec9796299a6671 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Thu, 8 Jun 2023 14:49:42 +0600 Subject: [PATCH] Remove nc-sso-glide library issue: https://gitlab.e.foundation/e/backlog/-/issues/6839 Upstream uses `com.github.stefan-niedermann.nextcloud-commons:sso-glide` lib to load avatar image like other nc requests through nc app (in our case accountManager by default). But accountManager failed to deseriealize nc request perfectly then log out error message, although image loaded perfectly. As for now, only avatar images are being loaded & they are public by default, so we can remove this library & load the avatar directly via glide, so no unwanted exception is thrown. P.S: if in the future, the private image loading support added, we might need to revert this commit. --- app/build.gradle | 3 --- .../notes/accountswitcher/AccountSwitcherDialog.java | 3 ++- .../notes/accountswitcher/AccountSwitcherViewHolder.java | 4 ++-- .../it/niedermann/owncloud/notes/main/MainActivity.java | 3 ++- .../notes/manageaccounts/ManageAccountViewHolder.java | 4 ++-- .../notes/shared/account/AccountChooserViewHolder.java | 4 ++-- .../owncloud/notes/shared/util/DisplayUtils.java | 7 +++++++ 7 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1c308d3f0..786286d7c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -60,9 +60,6 @@ dependencies { implementation ('com.github.stefan-niedermann:android-commons:0.2.7') { exclude group: 'com.github.nextcloud', module: 'Android-SingleSignOn' } - implementation ('com.github.stefan-niedermann.nextcloud-commons:sso-glide:1.6.4') { - exclude group: 'com.github.nextcloud', module: 'Android-SingleSignOn' - } implementation ('com.github.stefan-niedermann.nextcloud-commons:exception:1.6.4') { exclude group: 'com.github.nextcloud', module: 'Android-SingleSignOn' } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java index 7d088afea..20c1eed4f 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java @@ -22,6 +22,7 @@ import it.niedermann.owncloud.notes.databinding.DialogAccountSwitcherBinding; import it.niedermann.owncloud.notes.manageaccounts.ManageAccountsActivity; import it.niedermann.owncloud.notes.persistence.NotesRepository; import it.niedermann.owncloud.notes.persistence.entity.Account; +import it.niedermann.owncloud.notes.shared.util.DisplayUtils; /** * Displays all available {@link Account} entries and provides basic operations for them, like adding or switching @@ -67,7 +68,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment { binding.accountName.setText(currentLocalAccount.getDisplayName()); binding.accountHost.setText(Uri.parse(currentLocalAccount.getUrl()).getHost()); Glide.with(requireContext()) - .load(currentLocalAccount.getUrl() + "/index.php/avatar/" + Uri.encode(currentLocalAccount.getUserName()) + "/64") + .load(DisplayUtils.getAvatarUrl(currentLocalAccount)) .error(R.drawable.ic_account_circle_grey_24dp) .apply(RequestOptions.circleCropTransform()) .into(binding.currentAccountItemAvatar); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherViewHolder.java b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherViewHolder.java index 1f096c96e..512c9a9c2 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherViewHolder.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherViewHolder.java @@ -10,10 +10,10 @@ import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; -import it.niedermann.nextcloud.sso.glide.SingleSignOnUrl; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ItemAccountChooseBinding; import it.niedermann.owncloud.notes.persistence.entity.Account; +import it.niedermann.owncloud.notes.shared.util.DisplayUtils; public class AccountSwitcherViewHolder extends RecyclerView.ViewHolder { @@ -28,7 +28,7 @@ public class AccountSwitcherViewHolder extends RecyclerView.ViewHolder { binding.accountName.setText(localAccount.getDisplayName()); binding.accountHost.setText(Uri.parse(localAccount.getUrl()).getHost()); Glide.with(itemView.getContext()) - .load(new SingleSignOnUrl(localAccount.getAccountName(), localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUserName()) + "/64")) + .load(DisplayUtils.getAvatarUrl(localAccount)) .placeholder(R.drawable.ic_account_circle_grey_24dp) .error(R.drawable.ic_account_circle_grey_24dp) .apply(RequestOptions.circleCropTransform()) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java index 9843e4cab..fce42c0ba 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java @@ -92,6 +92,7 @@ import it.niedermann.owncloud.notes.shared.model.IResponseCallback; import it.niedermann.owncloud.notes.shared.model.NavigationCategory; import it.niedermann.owncloud.notes.shared.model.NoteClickListener; import it.niedermann.owncloud.notes.shared.util.CustomAppGlideModule; +import it.niedermann.owncloud.notes.shared.util.DisplayUtils; import it.niedermann.owncloud.notes.shared.util.NoteUtil; import it.niedermann.owncloud.notes.shared.util.ShareUtil; import trikita.log.Log; @@ -307,7 +308,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A fabCreate.hide(); Glide .with(this) - .load(nextAccount.getUrl() + "/index.php/avatar/" + Uri.encode(nextAccount.getUserName()) + "/64") + .load(DisplayUtils.getAvatarUrl(nextAccount)) .placeholder(R.drawable.ic_account_circle_grey_24dp) .error(R.drawable.ic_account_circle_grey_24dp) .apply(RequestOptions.circleCropTransform()) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountViewHolder.java b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountViewHolder.java index 26b1e785c..32687e66c 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountViewHolder.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountViewHolder.java @@ -16,10 +16,10 @@ import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; -import it.niedermann.nextcloud.sso.glide.SingleSignOnUrl; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ItemAccountChooseBinding; import it.niedermann.owncloud.notes.persistence.entity.Account; +import it.niedermann.owncloud.notes.shared.util.DisplayUtils; public class ManageAccountViewHolder extends RecyclerView.ViewHolder { @@ -38,7 +38,7 @@ public class ManageAccountViewHolder extends RecyclerView.ViewHolder { binding.accountName.setText(localAccount.getUserName()); binding.accountHost.setText(Uri.parse(localAccount.getUrl()).getHost()); Glide.with(itemView.getContext()) - .load(new SingleSignOnUrl(localAccount.getAccountName(), localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUserName()) + "/64")) + .load(DisplayUtils.getAvatarUrl(localAccount)) .error(R.drawable.ic_account_circle_grey_24dp) .apply(RequestOptions.circleCropTransform()) .into(binding.accountItemAvatar); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserViewHolder.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserViewHolder.java index 5d3d29632..494f92917 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserViewHolder.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserViewHolder.java @@ -8,10 +8,10 @@ import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; -import it.niedermann.nextcloud.sso.glide.SingleSignOnUrl; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ItemAccountChooseBinding; import it.niedermann.owncloud.notes.persistence.entity.Account; +import it.niedermann.owncloud.notes.shared.util.DisplayUtils; public class AccountChooserViewHolder extends RecyclerView.ViewHolder { private final ItemAccountChooseBinding binding; @@ -24,7 +24,7 @@ public class AccountChooserViewHolder extends RecyclerView.ViewHolder { public void bind(Account localAccount, Consumer targetAccountConsumer) { Glide .with(binding.accountItemAvatar.getContext()) - .load(new SingleSignOnUrl(localAccount.getAccountName(), localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUserName()) + "/64")) + .load(DisplayUtils.getAvatarUrl(localAccount)) .placeholder(R.drawable.ic_account_circle_grey_24dp) .error(R.drawable.ic_account_circle_grey_24dp) .apply(RequestOptions.circleCropTransform()) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java index abba8e002..0aeb1bf49 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java @@ -8,6 +8,7 @@ import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Rect; +import android.net.Uri; import android.os.Build; import android.util.TypedValue; import android.view.View; @@ -26,6 +27,7 @@ import java.util.stream.Stream; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.main.navigation.NavigationAdapter; import it.niedermann.owncloud.notes.main.navigation.NavigationItem; +import it.niedermann.owncloud.notes.persistence.entity.Account; import it.niedermann.owncloud.notes.persistence.entity.CategoryWithNotesCount; public class DisplayUtils { @@ -102,4 +104,9 @@ public class DisplayUtils { final int heightDiff = parentView.getRootView().getHeight() - (rect.bottom - rect.top); return heightDiff >= estimatedKeyboardHeight; } + + @NonNull + public static String getAvatarUrl(@NonNull Account account) { + return account.getUrl() + "/index.php/avatar/" + Uri.encode(account.getUserName()) + "/64"; + } } -- GitLab