mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 11:05:59 +00:00
Optimize code
New Privilege object, which follows Application lifecycle. Add Privilege.DPM and Privilege.DAR variable, instead of creating DPM and DAR instance every time.
This commit is contained in:
@@ -7,25 +7,21 @@ import android.os.Bundle
|
||||
import androidx.core.content.pm.ShortcutInfoCompat
|
||||
import androidx.core.content.pm.ShortcutManagerCompat
|
||||
import androidx.core.graphics.drawable.IconCompat
|
||||
import com.bintianqi.owndroid.dpm.getDPM
|
||||
import com.bintianqi.owndroid.dpm.getReceiver
|
||||
|
||||
class ShortcutsReceiverActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
try {
|
||||
val action = intent.action?.removePrefix("com.bintianqi.owndroid.action.")
|
||||
if (action != null && SharedPrefs(this).shortcuts) {
|
||||
val dpm = getDPM()
|
||||
val receiver = getReceiver()
|
||||
if (action != null && SP.shortcuts) {
|
||||
when (action) {
|
||||
"LOCK" -> dpm.lockNow()
|
||||
"LOCK" -> Privilege.DPM.lockNow()
|
||||
"DISABLE_CAMERA" -> {
|
||||
dpm.setCameraDisabled(receiver, !dpm.getCameraDisabled(receiver))
|
||||
Privilege.DPM.setCameraDisabled(Privilege.DAR, !Privilege.DPM.getCameraDisabled(Privilege.DAR))
|
||||
createShortcuts(this)
|
||||
}
|
||||
"MUTE" -> {
|
||||
dpm.setMasterVolumeMuted(receiver, !dpm.isMasterVolumeMuted(receiver))
|
||||
Privilege.DPM.setMasterVolumeMuted(Privilege.DAR, !Privilege.DPM.isMasterVolumeMuted(Privilege.DAR))
|
||||
createShortcuts(this)
|
||||
}
|
||||
}
|
||||
@@ -37,13 +33,11 @@ class ShortcutsReceiverActivity : Activity() {
|
||||
}
|
||||
|
||||
fun createShortcuts(context: Context) {
|
||||
if (!SharedPrefs(context).shortcuts) return
|
||||
if (!SP.shortcuts) return
|
||||
val action = "com.bintianqi.owndroid.action"
|
||||
val baseIntent = Intent(context, ShortcutsReceiverActivity::class.java)
|
||||
val dpm = context.getDPM()
|
||||
val receiver = context.getReceiver()
|
||||
val cameraDisabled = dpm.getCameraDisabled(receiver)
|
||||
val muted = dpm.isMasterVolumeMuted(receiver)
|
||||
val cameraDisabled = Privilege.DPM.getCameraDisabled(Privilege.DAR)
|
||||
val muted = Privilege.DPM.isMasterVolumeMuted(Privilege.DAR)
|
||||
val list = listOf(
|
||||
ShortcutInfoCompat.Builder(context, "LOCK")
|
||||
.setIcon(IconCompat.createWithResource(context, R.drawable.screen_lock_portrait_fill0))
|
||||
|
||||
Reference in New Issue
Block a user