Remove wake-lock permission

This commit is contained in:
Lucas Lima 2020-05-24 13:41:30 -03:00
parent d216cef8d5
commit 315ae34def
No known key found for this signature in database
GPG key ID: C828A958035D9C34
2 changed files with 12 additions and 2 deletions

View file

@ -14,8 +14,6 @@
<uses-permission
android:name="android.permission.VIBRATE" />
<uses-permission
android:name="android.permission.WAKE_LOCK" />
<uses-feature
android:name="android.hardware.touchscreen"

View file

@ -9,6 +9,7 @@ import android.text.format.DateUtils
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.WindowManager
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AlertDialog
import androidx.core.os.HandlerCompat.postDelayed
@ -443,6 +444,7 @@ class GameActivity : DaggerAppCompatActivity() {
status = Status.Running
viewModel.runClock()
invalidateOptionsMenu()
keepScreenOn(true)
}
Event.Victory -> {
val score = Score(
@ -455,6 +457,7 @@ class GameActivity : DaggerAppCompatActivity() {
viewModel.revealAllEmptyAreas()
viewModel.victory()
invalidateOptionsMenu()
keepScreenOn(false)
waitAndShowEndGameDialog(
victory = true,
await = false
@ -468,6 +471,7 @@ class GameActivity : DaggerAppCompatActivity() {
)
status = Status.Over(currentTime, score)
invalidateOptionsMenu()
keepScreenOn(false)
viewModel.stopClock()
GlobalScope.launch(context = Dispatchers.Main) {
@ -567,6 +571,14 @@ class GameActivity : DaggerAppCompatActivity() {
preferencesRepository.putBoolean(PREFERENCE_REQUEST_RATING, false)
}
private fun keepScreenOn(enabled: Boolean) {
if (enabled) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
companion object {
const val PREFERENCE_FIRST_USE = "preference_first_use"
const val PREFERENCE_USE_COUNT = "preference_use_count"