Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 553bb21e authored by Pranav Vashi's avatar Pranav Vashi Committed by Michael Bestas
Browse files

Screenrecord: Save preferences for permission dialog

Change-Id: I98a7b649100fdd3fc791c1031b825c96374da664
parent be1d7684
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.widget.Spinner
import android.widget.Switch
import androidx.annotation.LayoutRes
import androidx.annotation.StyleRes
import com.android.systemui.Prefs
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.mediaprojection.MediaProjectionCaptureTarget
import com.android.systemui.mediaprojection.MediaProjectionMetricsLogger
@@ -221,6 +222,8 @@ class ScreenRecordPermissionDialogDelegate(
                }
            }
        options.isLongClickable = false

        loadPrefs();
    }

    /**
@@ -265,10 +268,33 @@ class ScreenRecordPermissionDialogDelegate(
                RecordingService.getStopIntent(userContext),
                PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
            )
        savePrefs();
        controller.startCountdown(if (skipTimeSwitch.isChecked) NO_DELAY else DELAY_MS,
                INTERVAL_MS, startIntent, stopIntent)
    }

    private fun savePrefs() {
        val userContext = userContextProvider.userContext
        Prefs.putInt(userContext, PREF_TAPS, if (tapsSwitch.isChecked) 1 else 0)
        Prefs.putInt(userContext, PREF_LOW, if (lowQualitySwitch.isChecked) 1 else 0)
        Prefs.putInt(userContext, PREF_LONGER, if (longerDurationSwitch.isChecked) 1 else 0)
        Prefs.putInt(userContext, PREF_AUDIO, if (audioSwitch.isChecked) 1 else 0)
        Prefs.putInt(userContext, PREF_AUDIO_SOURCE, options.selectedItemPosition)
        Prefs.putInt(userContext, PREF_SKIP, if (skipTimeSwitch.isChecked) 1 else 0)
        Prefs.putInt(userContext, PREF_HEVC, if (hevcSwitch.isChecked) 1 else 0)
    }

    private fun loadPrefs() {
        val userContext = userContextProvider.userContext
        tapsSwitch.isChecked = Prefs.getInt(userContext, PREF_TAPS, 0) == 1
        lowQualitySwitch.isChecked = Prefs.getInt(userContext, PREF_LOW, 0) == 1
        longerDurationSwitch.isChecked = Prefs.getInt(userContext, PREF_LONGER, 0) == 1
        audioSwitch.isChecked = Prefs.getInt(userContext, PREF_AUDIO, 0) == 1
        options.setSelection(Prefs.getInt(userContext, PREF_AUDIO_SOURCE, 0))
        skipTimeSwitch.isChecked = Prefs.getInt(userContext, PREF_SKIP, 0) == 1
        hevcSwitch.isChecked = Prefs.getInt(userContext, PREF_HEVC, 1) == 1
    }

    private inner class CaptureTargetResultReceiver :
        ResultReceiver(Handler(Looper.getMainLooper())) {
        override fun onReceiveResult(resultCode: Int, resultData: Bundle) {
@@ -295,5 +321,13 @@ class ScreenRecordPermissionDialogDelegate(
        private const val DELAY_MS: Long = 3000
        private const val NO_DELAY: Long = 100
        private const val INTERVAL_MS: Long = 1000

        private const val PREF_TAPS = "screenrecord_show_taps"
        private const val PREF_LOW = "screenrecord_use_low_quality"
        private const val PREF_LONGER = "screenrecord_use_longer_timeout"
        private const val PREF_AUDIO = "screenrecord_use_audio"
        private const val PREF_AUDIO_SOURCE = "screenrecord_audio_source"
        private const val PREF_SKIP = "screenrecord_skip_timer"
        private const val PREF_HEVC = "screenrecord_use_hevc"
    }
}