diff --git a/screenshots/com.owncloud.android.ui.activity.ManageAccountsActivityIT_open.png b/screenshots/com.owncloud.android.ui.activity.ManageAccountsActivityIT_open.png new file mode 100644 index 0000000000..b0e8f2ea21 Binary files /dev/null and b/screenshots/com.owncloud.android.ui.activity.ManageAccountsActivityIT_open.png differ diff --git a/screenshots/com.owncloud.android.ui.activity.ManageAccountsActivityIT_userInfoDetail.png b/screenshots/com.owncloud.android.ui.activity.ManageAccountsActivityIT_userInfoDetail.png new file mode 100644 index 0000000000..fbee87382d Binary files /dev/null and b/screenshots/com.owncloud.android.ui.activity.ManageAccountsActivityIT_userInfoDetail.png differ diff --git a/src/androidTest/java/com/owncloud/android/AbstractIT.java b/src/androidTest/java/com/owncloud/android/AbstractIT.java index c47da86dd1..55dd978061 100644 --- a/src/androidTest/java/com/owncloud/android/AbstractIT.java +++ b/src/androidTest/java/com/owncloud/android/AbstractIT.java @@ -30,11 +30,14 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.util.Collection; import androidx.test.espresso.contrib.DrawerActions; import androidx.test.espresso.intent.rule.IntentsTestRule; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; +import androidx.test.runner.lifecycle.Stage; import static androidx.test.InstrumentationRegistry.getInstrumentation; import static androidx.test.espresso.Espresso.onView; @@ -52,6 +55,8 @@ public abstract class AbstractIT { protected static Account account; protected static Context targetContext; + private Activity currentActivity; + @BeforeClass public static void beforeAll() { try { @@ -167,4 +172,18 @@ public abstract class AbstractIT { Screenshot.snapActivity(sut).record(); } + + protected Activity getCurrentActivity() { + InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { + Collection resumedActivities = ActivityLifecycleMonitorRegistry + .getInstance() + .getActivitiesInStage(Stage.RESUMED); + + if (resumedActivities.iterator().hasNext()) { + currentActivity = resumedActivities.iterator().next(); + } + }); + + return currentActivity; + } } diff --git a/src/androidTest/java/com/owncloud/android/ui/activity/ManageAccountsActivityIT.java b/src/androidTest/java/com/owncloud/android/ui/activity/ManageAccountsActivityIT.java new file mode 100644 index 0000000000..e0de88c845 --- /dev/null +++ b/src/androidTest/java/com/owncloud/android/ui/activity/ManageAccountsActivityIT.java @@ -0,0 +1,62 @@ +/* + * + * Nextcloud Android client application + * + * @author Tobias Kaminsky + * Copyright (C) 2020 Tobias Kaminsky + * Copyright (C) 2020 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 . + */ + +package com.owncloud.android.ui.activity; + +import android.app.Activity; + +import com.facebook.testing.screenshot.Screenshot; +import com.nextcloud.client.account.User; +import com.owncloud.android.AbstractIT; + +import org.junit.Rule; +import org.junit.Test; + +import androidx.test.espresso.intent.rule.IntentsTestRule; + +public class ManageAccountsActivityIT extends AbstractIT { + @Rule + public IntentsTestRule activityRule = new IntentsTestRule<>(ManageAccountsActivity.class, + true, + false); + + @Test + public void open() throws InterruptedException { + Activity sut = activityRule.launchActivity(null); + + Thread.sleep(2000); + + Screenshot.snapActivity(sut).record(); + } + + @Test + public void userInfoDetail() throws InterruptedException { + ManageAccountsActivity sut = activityRule.launchActivity(null); + + User user = sut.accountManager.getUser(); + sut.onClick(user); + + Thread.sleep(2000); + + Screenshot.snapActivity(getCurrentActivity()).record(); + } +} diff --git a/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java b/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index 8bd377cba7..5e231c4000 100644 --- a/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@ -824,9 +824,14 @@ public final class ThumbnailsCacheManager { private Context mContext; - public AvatarGenerationTask(AvatarGenerationListener avatarGenerationListener, Object callContext, - Account account, Resources resources, float avatarRadius, String userId, - String serverName, Context context) { + public AvatarGenerationTask(AvatarGenerationListener avatarGenerationListener, + Object callContext, + Account account, + Resources resources, + float avatarRadius, + String userId, + String serverName, + Context context) { mAvatarGenerationListener = new WeakReference<>(avatarGenerationListener); mCallContext = callContext; mAccount = account; @@ -865,7 +870,8 @@ public final class ThumbnailsCacheManager { AvatarGenerationListener listener = mAvatarGenerationListener.get(); if (listener != null) { AvatarGenerationTask avatarWorkerTask = getAvatarWorkerTask(mCallContext); - if (this == avatarWorkerTask && listener.shouldCallGeneratedCallback(mUserId, mCallContext)) { + String accountName = mUserId + "@" + mServerName; + if (this == avatarWorkerTask && listener.shouldCallGeneratedCallback(accountName, mCallContext)) { listener.avatarGenerated(drawable, mCallContext); } } diff --git a/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java b/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java index 14773b45f4..df43891a5f 100644 --- a/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java @@ -460,7 +460,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap @Override public void onClick(User user) { final Intent intent = new Intent(this, UserInfoActivity.class); - intent.putExtra(UserInfoActivity.KEY_ACCOUNT, Parcels.wrap(user)); + intent.putExtra(UserInfoActivity.KEY_ACCOUNT, user); OwnCloudAccount oca = user.toOwnCloudAccount(); intent.putExtra(KEY_DISPLAY_NAME, oca.getDisplayName()); startActivityForResult(intent, KEY_USER_INFO_REQUEST_CODE); diff --git a/src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java b/src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java index defb32efba..83a45440a2 100644 --- a/src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java @@ -53,7 +53,6 @@ import com.evernote.android.job.util.support.PersistableBundleCompat; import com.nextcloud.client.account.User; import com.nextcloud.client.di.Injectable; import com.nextcloud.client.preferences.AppPreferences; -import com.nextcloud.java.util.Optional; import com.owncloud.android.R; import com.owncloud.android.jobs.AccountRemovalJob; import com.owncloud.android.lib.common.UserInfo; @@ -126,13 +125,15 @@ public class UserInfoActivity extends FileActivity implements Injectable { super.onCreate(savedInstanceState); Bundle bundle = getIntent().getExtras(); - final Account account = Parcels.unwrap(bundle.getParcelable(KEY_ACCOUNT)); - Optional optionalUser = accountManager.getUser(account != null ? account.name : ""); - if(!optionalUser.isPresent()) { + if (bundle == null) { + finish(); + return; + } + + user = bundle.getParcelable(KEY_ACCOUNT); + if(user == null) { finish(); return; - } else { - user = optionalUser.get(); } if (savedInstanceState != null && savedInstanceState.containsKey(KEY_USER_DATA)) { @@ -145,7 +146,7 @@ public class UserInfoActivity extends FileActivity implements Injectable { unbinder = ButterKnife.bind(this); boolean useBackgroundImage = URLUtil.isValidUrl( - getStorageManager().getCapability(account.name).getServerBackground()); + getStorageManager().getCapability(user.getAccountName()).getServerBackground()); setupToolbar(useBackgroundImage); updateActionBarTitleAndHomeButtonByString("");