diff --git a/app/screenshots/gplay/debug/com.nextcloud.client.SyncedFoldersActivityIT_showPowerCheckDialog.png b/app/screenshots/gplay/debug/com.nextcloud.client.SyncedFoldersActivityIT_showPowerCheckDialog.png new file mode 100644 index 0000000000..f7a9b2a92d Binary files /dev/null and b/app/screenshots/gplay/debug/com.nextcloud.client.SyncedFoldersActivityIT_showPowerCheckDialog.png differ diff --git a/app/src/androidTest/java/com/nextcloud/client/SyncedFoldersActivityIT.java b/app/src/androidTest/java/com/nextcloud/client/SyncedFoldersActivityIT.java index e1770a1d38..4bc1377a7f 100644 --- a/app/src/androidTest/java/com/nextcloud/client/SyncedFoldersActivityIT.java +++ b/app/src/androidTest/java/com/nextcloud/client/SyncedFoldersActivityIT.java @@ -7,8 +7,8 @@ */ package com.nextcloud.client; -import android.app.Activity; import android.content.Intent; +import android.os.Looper; import com.nextcloud.client.preferences.SubFolderRule; import com.owncloud.android.AbstractIT; @@ -25,6 +25,7 @@ import org.junit.Test; import java.util.Objects; +import androidx.appcompat.app.AlertDialog; import androidx.test.espresso.intent.rule.IntentsTestRule; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; @@ -78,4 +79,24 @@ public class SyncedFoldersActivityIT extends AbstractIT { screenshot(Objects.requireNonNull(sut.requireDialog().getWindow()).getDecorView()); } + + @Test + @ScreenshotTest + public void showPowerCheckDialog() { + if (Looper.myLooper() == null) { + Looper.prepare(); + } + + Intent intent = new Intent(targetContext, SyncedFoldersActivity.class); + SyncedFoldersActivity activity = activityRule.launchActivity(intent); + + AlertDialog sut = activity.buildPowerCheckDialog(); + + activity.runOnUiThread(sut::show); + + getInstrumentation().waitForIdleSync(); + shortSleep(); + + screenshot(Objects.requireNonNull(sut.getWindow()).getDecorView()); + } } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.kt b/app/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.kt index 23486394a2..9ce6684472 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.kt @@ -20,6 +20,7 @@ import android.text.TextUtils import android.view.Menu import android.view.MenuItem import android.view.View +import androidx.annotation.VisibleForTesting import androidx.appcompat.app.AlertDialog import androidx.drawerlayout.widget.DrawerLayout import androidx.lifecycle.Lifecycle @@ -31,7 +32,6 @@ import com.nextcloud.client.di.Injectable import com.nextcloud.client.jobs.MediaFoldersDetectionWork import com.nextcloud.client.jobs.NotificationWork import com.nextcloud.client.jobs.upload.FileUploadWorker -import com.nextcloud.client.preferences.AppPreferences import com.nextcloud.client.preferences.SubFolderRule import com.nextcloud.utils.extensions.getParcelableArgument import com.nextcloud.utils.extensions.isDialogFragmentReady @@ -56,7 +56,6 @@ import com.owncloud.android.ui.dialog.SyncedFolderPreferencesDialogFragment.OnSy import com.owncloud.android.ui.dialog.parcel.SyncedFolderParcelable import com.owncloud.android.utils.PermissionUtil import com.owncloud.android.utils.SyncedFolderUtils -import com.owncloud.android.utils.theme.ViewThemeUtils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -135,18 +134,12 @@ class SyncedFoldersActivity : } } - @Inject - lateinit var preferences: AppPreferences - @Inject lateinit var powerManagementService: PowerManagementService @Inject lateinit var clock: Clock - @Inject - lateinit var viewThemeUtils: ViewThemeUtils - @Inject lateinit var syncedFolderProvider: SyncedFolderProvider @@ -220,17 +213,23 @@ class SyncedFoldersActivity : powerCheck.isChecked = !powerCheck.isChecked return true } - - private fun showPowerCheckDialog() { + + fun buildPowerCheckDialog(): AlertDialog { val builder = MaterialAlertDialogBuilder(this) - .setView(R.id.root_layout) .setPositiveButton(R.string.common_ok) { dialog, _ -> dialog.dismiss() } .setTitle(R.string.autoupload_disable_power_save_check) .setMessage(getString(R.string.power_save_check_dialog_message)) viewThemeUtils.dialog.colorMaterialAlertDialogBackground(this, builder) - builder.create().show() + return builder.create() + } + + @VisibleForTesting + fun showPowerCheckDialog() { + buildPowerCheckDialog().show() + + } /** @@ -636,6 +635,7 @@ class SyncedFoldersActivity : binding.emptyList.emptyListIcon.visibility = View.VISIBLE } + @Deprecated("Deprecated in Java") override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_REMOTE_FOLDER && resultCode == RESULT_OK && dialogFragment != null