Skip to content

Commit

Permalink
Merge pull request #14002 from nextcloud/powerSavingCrash
Browse files Browse the repository at this point in the history
Power saving crash
  • Loading branch information
tobiasKaminsky authored Nov 25, 2024
2 parents a0c5a9e + 8512212 commit 287203e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +25,7 @@

import java.util.Objects;

import androidx.appcompat.app.AlertDialog;
import androidx.test.espresso.intent.rule.IntentsTestRule;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
Expand Down Expand Up @@ -78,4 +79,24 @@ public void testSyncedFolderDialog() {

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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -221,16 +214,20 @@ class SyncedFoldersActivity :
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()
}

/**
Expand Down Expand Up @@ -636,6 +633,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
Expand Down

0 comments on commit 287203e

Please sign in to comment.