Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding custom application id feature #325

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package com.my.kizzy.preference
import com.my.kizzy.domain.model.release.Release
import com.my.kizzy.domain.model.user.User
import com.tencent.mmkv.MMKV
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlin.time.Duration.Companion.hours
Expand Down Expand Up @@ -151,4 +150,6 @@ object Prefs {
const val LAST_DELETED = "last_deleted"

const val SAMSUNG_RPC_ENABLED = "samsung_rpc_enabled"

const val CUSTOM_ACTIVITY_APPLICATION_ID = "custom_activity_application_id_"
}
7 changes: 6 additions & 1 deletion common/resources/src/main/res/values/strings.xml
dead8309 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="app_name">Kizzy</string>
<string name="qs_tile_label" translatable="false">Kizzy Quickie</string>

Expand Down Expand Up @@ -65,6 +65,8 @@
<string name="rpc_settings_button_configs">Button configuration for Media and AppDetection RPC</string>
<string name="use_custom_buttons">Use Custom Buttons</string>
<string name="use_custom_buttons_desc">Use Predefined buttons to show on Media and AppDetection RPC</string>
<string name="use_custom_activity_application_id" tools:ignore="MissingTranslation">Use Custom Activity Application ID </string>
<string name="use_custom_activity_application_id_desc" tools:ignore="MissingTranslation"> Enter Custom Activity Application ID </string>
<string name="follow_system">Follow System</string>
<string name="advance_settings">Advanced Settings</string>
<string name="amoled">AMOLED Theme</string>
Expand Down Expand Up @@ -137,6 +139,9 @@
<string name="custom_rpc_directory">Directory to store Custom RPC configs</string>
<string name="select_directory">Select directory</string>
<string name="enter_details">Enter details</string>
<string name="enter_your_developer_activity_application_id" tools:ignore="MissingTranslation">Enter your Developer Activity Application ID</string>
<string name="ok" tools:ignore="MissingTranslation">OK</string>
<string name="application_id" tools:ignore="MissingTranslation">Application ID</string>
<string name="status_online">Online</string>
<string name="status_idle">Idle</string>
<string name="status_dnd">Do Not Disturb</string>
Expand Down
8 changes: 6 additions & 2 deletions data/src/main/java/com/my/kizzy/data/rpc/KizzyRPC.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class KizzyRPC(
) {
private lateinit var presence: Presence
private var activityName: String? = null
private var applicationIdNumber = Prefs[Prefs.CUSTOM_ACTIVITY_APPLICATION_ID, Constants.APPLICATION_ID]
private var details: String? = null
private var state: String? = null
private var party: Party? = null
Expand All @@ -48,6 +49,8 @@ class KizzyRPC(
private var buttonUrl = ArrayList<String>()
private var url: String? = null



fun closeRPC() {
discordWebSocket.close()
}
Expand Down Expand Up @@ -268,7 +271,7 @@ class KizzyRPC(
).takeIf { largeImage != null || smallImage != null },
buttons = buttons.takeIf { buttons.size > 0 },
metadata = Metadata(buttonUrls = buttonUrl).takeIf { buttonUrl.size > 0 },
applicationId = Constants.APPLICATION_ID,
applicationId = applicationIdNumber.takeIf { it.isNotEmpty() } ?: Constants.APPLICATION_ID,
url = url
)
),
Expand Down Expand Up @@ -313,7 +316,8 @@ class KizzyRPC(
party = party.takeIf { party != null },
buttons = buttons.takeIf { buttons.size > 0 },
metadata = Metadata(buttonUrls = buttonUrl).takeIf { buttonUrl.size > 0 },
applicationId = Constants.APPLICATION_ID
applicationId = applicationIdNumber.takeIf { it.isNotEmpty() } ?: Constants.APPLICATION_ID

)
),
afk = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import android.widget.Toast
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.text.KeyboardOptions
Expand All @@ -45,6 +47,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -67,7 +70,6 @@ import com.my.kizzy.ui.components.SettingItem
import com.my.kizzy.ui.components.Subtitle
import com.my.kizzy.ui.components.dialog.SingleChoiceItem
import com.my.kizzy.ui.components.preference.PreferenceSwitch
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

Expand Down Expand Up @@ -96,10 +98,16 @@ fun RpcSettings(onBackPressed: () -> Boolean) {
var showActivityStatusDialog by remember {
mutableStateOf(false)
}
var showApplicationIdDialog by remember {
mutableStateOf(false)
}
var setLastRunRpcConfigOption by remember {
mutableStateOf(Prefs[Prefs.APPLY_FIELDS_FROM_LAST_RUN_RPC, false])
}
var isSamsungRpcEnabled by remember { mutableStateOf(Prefs[Prefs.SAMSUNG_RPC_ENABLED, false]) }

var customApplicationId by remember { mutableStateOf(Prefs[Prefs.CUSTOM_ACTIVITY_APPLICATION_ID, ""]) }

Scaffold(modifier = Modifier.fillMaxSize(), topBar = {
LargeTopAppBar(title = {
Text(
Expand Down Expand Up @@ -175,6 +183,16 @@ fun RpcSettings(onBackPressed: () -> Boolean) {
Prefs[Prefs.APPLY_FIELDS_FROM_LAST_RUN_RPC] = setLastRunRpcConfigOption
}
}
item {
SettingItem(
title = stringResource(id = R.string.use_custom_activity_application_id),
description = stringResource(id = R.string.use_custom_activity_application_id_desc),
icon = Icons.Default.Code
dead8309 marked this conversation as resolved.
Show resolved Hide resolved
) {
showApplicationIdDialog = true
}

}
item {
Subtitle(text = stringResource(id = R.string.advance_settings))
}
Expand Down Expand Up @@ -407,5 +425,50 @@ fun RpcSettings(onBackPressed: () -> Boolean) {
}
)
}

if (showApplicationIdDialog) {
AlertDialog(
onDismissRequest = {
showApplicationIdDialog = false
},
text = {
Column {
Text(text = stringResource(R.string.application_id))
dead8309 marked this conversation as resolved.
Show resolved Hide resolved
Spacer(modifier = Modifier.height(8.dp))
TextField(
dead8309 marked this conversation as resolved.
Show resolved Hide resolved
value = customApplicationId,
onValueChange = { newText ->
// Ensure the text only contains digits and is no longer than 18 characters
if (newText.length <= 18 && newText.all { it.isDigit() }) {
customApplicationId = newText}
},
singleLine = true
)
}
},
confirmButton = {
TextButton(
onClick = {
if (customApplicationId.length != 18 || !customApplicationId.all { it.isDigit() }) {
Toast.makeText(context, "Please enter a valid Application ID", Toast.LENGTH_SHORT).show()
} else {
Prefs[Prefs.CUSTOM_ACTIVITY_APPLICATION_ID] = customApplicationId
showApplicationIdDialog = false
}
}
) {
Text(stringResource(R.string.ok))
dead8309 marked this conversation as resolved.
Show resolved Hide resolved
}
},
dismissButton = {
TextButton(
onClick = { showApplicationIdDialog = false }
) {
Text("Cancel")
}
}
)
}

}
}