Skip to content

Commit

Permalink
keep display on for entire duration of the mixing (#553)
Browse files Browse the repository at this point in the history
* keep display on for entire duration of the mixing

* check mixer status on the HomeActivity, and keep dispay on if mixer is still active
  • Loading branch information
dreacot committed May 12, 2021
1 parent 126f5fb commit 96cee47
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
34 changes: 33 additions & 1 deletion app/src/main/java/com/dcrandroid/HomeActivity.kt
Expand Up @@ -21,6 +21,7 @@ import android.os.Handler
import android.util.DisplayMetrics
import android.view.MotionEvent
import android.view.View
import android.view.WindowManager
import android.view.animation.AnimationUtils
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
Expand Down Expand Up @@ -48,6 +49,7 @@ import com.dcrandroid.util.WalletData
import com.google.gson.Gson
import dcrlibwallet.*
import kotlinx.android.synthetic.main.activity_tabs.*
import kotlinx.android.synthetic.main.overview_mixer_status_card.*
import kotlinx.coroutines.*
import java.lang.Runnable
import java.text.DecimalFormat
Expand All @@ -56,7 +58,7 @@ import kotlin.system.exitProcess

const val TAG = "HomeActivity"

class HomeActivity : BaseActivity(), SyncProgressListener, TxAndBlockNotificationListener, ProposalNotificationListener {
class HomeActivity : BaseActivity(), SyncProgressListener, TxAndBlockNotificationListener, ProposalNotificationListener, AccountMixerNotificationListener {

private var deviceWidth: Int = 0
private var blockNotificationSound: Int = 0
Expand Down Expand Up @@ -152,6 +154,8 @@ class HomeActivity : BaseActivity(), SyncProgressListener, TxAndBlockNotificatio
e.printStackTrace()
}
}

checkMixerStatus()
}

private val bottomSheetDismissed = DialogInterface.OnDismissListener {
Expand All @@ -173,6 +177,34 @@ class HomeActivity : BaseActivity(), SyncProgressListener, TxAndBlockNotificatio
}
}

private fun checkMixerStatus() = GlobalScope.launch(Dispatchers.Main) {
var activeMixers = 0
for (wallet in multiWallet!!.openedWalletsList()) {
if (wallet.isAccountMixerActive) {
activeMixers++
}
}

if (activeMixers > 0) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}

override fun onAccountMixerEnded(walletID: Long) {
checkMixerStatus()
}

override fun onAccountMixerStarted(walletID: Long) {
checkMixerStatus()
}

override fun onResume() {
super.onResume()
checkMixerStatus()
}

override fun onDestroy() {
super.onDestroy()

Expand Down
Expand Up @@ -9,6 +9,7 @@ package com.dcrandroid.activities.privacy
import android.content.DialogInterface
import android.os.Bundle
import android.text.Html
import android.view.WindowManager
import com.dcrandroid.BuildConfig
import com.dcrandroid.R
import com.dcrandroid.activities.BaseActivity
Expand Down Expand Up @@ -172,6 +173,10 @@ class AccountMixerActivity : BaseActivity(), AccountMixerNotificationListener, T

private fun stopAccountMixer() = GlobalScope.launch(Dispatchers.Default) {
multiWallet?.stopAccountMixer(wallet.id)
// Allow display to timeout after mixer is stopped
GlobalScope.launch(Dispatchers.Main) {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}

override fun onAccountMixerEnded(walletID: Long) {
Expand All @@ -180,6 +185,8 @@ class AccountMixerActivity : BaseActivity(), AccountMixerNotificationListener, T
setMixerStatus()
GlobalScope.launch(Dispatchers.Main) {
mixer_toggle_switch.isChecked = false
// Allow display to timeout after mixer completes
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
}
Expand All @@ -189,6 +196,8 @@ class AccountMixerActivity : BaseActivity(), AccountMixerNotificationListener, T
setMixerStatus()
GlobalScope.launch(Dispatchers.Main) {
mixer_toggle_switch.isChecked = true
// Prevent display from timing out after mixer starts
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Expand Up @@ -569,7 +569,7 @@
<string name="mix_tx_change">Mix transaction change</string>
<string name="mix_tx_change_summary">Change from transactions will be sent to unmixed account if enabled.</string>
<string name="change_sent_to_unmixed"><![CDATA[Change will be sent to <b>%1$s</b>.]]></string>
<string name="start_mixer_warning">Your wallet will be unlocked until mixing completes.</string>
<string name="start_mixer_warning">Your wallet will be unlocked and your display would remain on until mixing completes.</string>
<string name="mixer_has_stopped_running">cspp mixer has stopped running</string>
<string name="no_mixable_output">Unmixed account has no mixable output</string>
<string name="new_caps">NEW</string>
Expand All @@ -596,7 +596,7 @@
<string name="mix_server">Mix server</string>
<string name="keep_app_opened">Keep this app opened</string>
<string name="mixer_help_title">How to use the mixer?</string>
<string name="mixer_help_desc"><![CDATA[When you turn on the mixer, your unmixed DCRs in this wallet (unmixed balance) will be gradually mixed.<br/><br/><b><font color="#091440">Important: keep this app opened while mixer is running.</font></b><br/><br/>Mixer will automatically stop when unmixed balance are fully mixed.]]></string>
<string name="mixer_help_desc"><![CDATA[When you turn on the mixer, your unmixed DCRs in this wallet (unmixed balance) will be gradually mixed.<br/><br/><b><font color="#091440">Important: keep this app opened while mixer is running. Your display would not timeout until the mixer completes, this may impact your battery life.</font></b><br/><br/>Mixer will automatically stop when unmixed balance are fully mixed.]]></string>
<string name="mixer_is_running">Mixer is running…</string>
<string name="keep_this_app_opened">Keep this app opened</string>
<string name="mixer_status_info">Mixer will automatically stop when unmixed balance are fully mixed.</string>
Expand Down

0 comments on commit 96cee47

Please sign in to comment.