Skip to content

Commit

Permalink
feat(feature_settings): add option for setting custom activity status
Browse files Browse the repository at this point in the history
 for apps,media,experimental rpc
  • Loading branch information
dead8309 committed Jul 9, 2023
1 parent 2466763 commit 92569a3
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,5 @@ object Prefs {
const val PALETTE_STYLE = "palette_style"

const val APPLY_FIELDS_FROM_LAST_RUN_RPC = "enable_setting_from_last_config"
const val CUSTOM_ACTIVITY_STATUS = "custom_activity_status"
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class AppDetectionService : Service() {
kizzyRPC.apply {
setName(AppUtils.getAppName(packageName))
setStartTimestamps(System.currentTimeMillis())
setStatus("dnd")
setStatus(Prefs[Prefs.CUSTOM_ACTIVITY_STATUS,"dnd"])
setLargeImage(RpcImage.ApplicationIcon(packageName, this@AppDetectionService))
if (Prefs[Prefs.USE_RPC_BUTTONS, false]) {
with(rpcButtons) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

package com.my.kizzy.feature_rpc_base.services

import android.app.*
import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.Service
import android.content.Intent
import android.os.IBinder
import com.my.kizzy.data.get_current_data.AppTracker
Expand Down Expand Up @@ -74,7 +77,7 @@ class ExperimentalRpc : Service() {
} else kizzyRPC.apply {
setName(collectedData.name)
setStartTimestamps(System.currentTimeMillis())
setStatus("dnd")
setStatus(Prefs[Prefs.CUSTOM_ACTIVITY_STATUS,"dnd"])
setLargeImage(collectedData.largeImage)
setSmallImage(collectedData.smallImage)
if (Prefs[Prefs.USE_RPC_BUTTONS, false]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class MediaRpcService : Service() {
kizzyRPC.apply {
setName(playingMedia.name.ifEmpty { "YouTube" })
setDetails(playingMedia.details)
setStatus("dnd")
setStatus(Prefs[Prefs.CUSTOM_ACTIVITY_STATUS,"dnd"])
if (Prefs[Prefs.USE_RPC_BUTTONS, false]) {
with(rpcButtons) {
setButton1(button1.takeIf { it.isNotEmpty() })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,42 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.material.icons.filled.Cached
import androidx.compose.material.icons.filled.Code
import androidx.compose.material.icons.filled.DeleteForever
import androidx.compose.material.icons.filled.DoNotDisturbOn
import androidx.compose.material.icons.filled.HighQuality
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material.icons.filled.SmartButton
import androidx.compose.material.icons.filled.Storage
import androidx.compose.material.icons.filled.Tune
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.LargeTopAppBar
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties
import com.my.kizzy.resources.R
import com.my.kizzy.preference.Prefs
import com.my.kizzy.data.rpc.Constants
import com.my.kizzy.data.rpc.Constants.MAX_ALLOWED_CHARACTER_LENGTH
import com.my.kizzy.domain.model.rpc.RpcButtons
import com.my.kizzy.preference.Prefs
import com.my.kizzy.resources.R
import com.my.kizzy.ui.components.BackButton
import com.my.kizzy.ui.components.RpcField
import com.my.kizzy.ui.components.SettingItem
Expand All @@ -59,12 +81,18 @@ fun RpcSettings(onBackPressed: () -> Boolean) {
var rpcButtons by remember {
mutableStateOf(Json.decodeFromString<RpcButtons>(Prefs[Prefs.RPC_BUTTONS_DATA, "{}"]))
}
var customActivityStatus by remember {
mutableStateOf(Prefs[Prefs.CUSTOM_ACTIVITY_STATUS, "dnd"])
}
var customActivityType by remember {
mutableStateOf(Prefs[Prefs.CUSTOM_ACTIVITY_TYPE, 0].toString())
}
var showActivityTypeDialog by remember {
mutableStateOf(false)
}
var showActivityStatusDialog by remember {
mutableStateOf(false)
}
var setLastRunRpcConfigOption by remember {
mutableStateOf(Prefs[Prefs.APPLY_FIELDS_FROM_LAST_RUN_RPC, false])
}
Expand Down Expand Up @@ -121,6 +149,16 @@ fun RpcSettings(onBackPressed: () -> Boolean) {
) {
showActivityTypeDialog = true
}

}
item {
SettingItem(
title = "Custom Activity Status",
description = "Overrides the default activity status",
icon = Icons.Default.DoNotDisturbOn
) {
showActivityStatusDialog = true
}
}
item {
PreferenceSwitch(
Expand Down Expand Up @@ -313,5 +351,35 @@ fun RpcSettings(onBackPressed: () -> Boolean) {
}
)
}

if (showActivityStatusDialog) {
AlertDialog(
onDismissRequest = {
showActivityStatusDialog = false
},
confirmButton = {},
text = {
val statusMap = mapOf(
"Online" to "online",
"AFK" to "idle",
"Do Not Disturb" to "dnd",
"Offline" to "offline",
"Invisible and shown as offline" to "invisible"
)
Column {
statusMap.forEach { (key, value) ->
SingleChoiceItem(
text = key,
selected = value == customActivityStatus
) {
customActivityStatus = value
Prefs[Prefs.CUSTOM_ACTIVITY_STATUS] = value
showActivityStatusDialog = false
}
}
}
}
)
}
}
}
}

0 comments on commit 92569a3

Please sign in to comment.