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_"
}
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
2 changes: 2 additions & 0 deletions common/resources/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,6 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>

</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-fil/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-hr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-kr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,5 @@
<string name="stop_rpc_toast">모든 서비스가 중지되었습니다</string>
<string name="show_playback_state">재생 상태 표시</string>
<string name="copied_to_clipboard">클립보드에 복사됨</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-mm/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@
<string name="stop_rpc_toast">Все сервисы остановлены</string>
<string name="show_playback_state">Показать статус воспроизведения</string>
<string name="copied_to_clipboard">Скопировано в буфер обмена</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-th/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@
<string name="stop_rpc_toast">services ทั้งหมดหยุดการทำงานแล้ว</string>
<string name="show_playback_state">แสดงสถานะการเล่น</string>
<string name="copied_to_clipboard">ก็อปไปยังคลิปบอร์ดแล้ว</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@
<string name="stop_rpc_toast">Đã dừng hoạt động</string>
<string name="show_playback_state">Hiện trạng thái phát</string>
<string name="copied_to_clipboard">Đã sao chép</string>
<string name="application_id">Application ID</string>
</resources>
1 change: 1 addition & 0 deletions common/resources/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
3 changes: 2 additions & 1 deletion common/resources/src/main/res/values/strings.xml
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 @@ -201,4 +201,5 @@
<string name="stop_rpc_toast">All services stopped</string>
<string name="show_playback_state">Show Playback State</string>
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="application_id">Application ID</string>
</resources>
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 @@ -31,6 +33,7 @@ import androidx.compose.material.icons.filled.HighQuality
import androidx.compose.material.icons.filled.Image
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material.icons.filled.Pin
import androidx.compose.material.icons.filled.SmartButton
import androidx.compose.material.icons.filled.Storage
import androidx.compose.material.icons.filled.Tune
Expand Down Expand Up @@ -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 = "Use Custom Activity Application ID",
description = "Enter ID number to use Rich Presence based on discord Developer Application ID",
icon = Icons.Default.Pin
) {
showApplicationIdDialog = true
}

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

if (showApplicationIdDialog) {
AlertDialog(
onDismissRequest = {
showApplicationIdDialog = false
},
title = { Text("Application ID") },
text = {
Column {
Spacer(modifier = Modifier.height(8.dp))
RpcField(
value = customApplicationId,
label = R.string.application_id,
isError = customApplicationId.length != 18 || !customApplicationId.all { it.isDigit() },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
onValueChange = { newText ->
if (newText.length <= 18 && newText.all { it.isDigit() }) {
customApplicationId = newText
}
}
)
}
},
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.save))
}
},
)
}

}
}
Loading