diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 2d02cba6..4a8eb485 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -16,6 +16,7 @@ + - + diff --git a/common/preference/src/main/java/com/my/kizzy/preference/Prefs.kt b/common/preference/src/main/java/com/my/kizzy/preference/Prefs.kt index 78b1d3c7..af15ba9e 100644 --- a/common/preference/src/main/java/com/my/kizzy/preference/Prefs.kt +++ b/common/preference/src/main/java/com/my/kizzy/preference/Prefs.kt @@ -122,6 +122,7 @@ object Prefs { const val RPC_BUTTONS_DATA = "saved_rpc_buttons_data" const val RPC_USE_LOW_RES_ICON = "use_low_res_app_icons" const val CONFIGS_DIRECTORY = "configs_directory" + const val USE_IMGUR = "use_imgur" // Saved Image Asset ids const val SAVED_IMAGES = "saved_images" // Saved ArtWork diff --git a/common/resources/src/main/res/values-de/strings.xml b/common/resources/src/main/res/values-de/strings.xml index 39849306..166badea 100644 --- a/common/resources/src/main/res/values-de/strings.xml +++ b/common/resources/src/main/res/values-de/strings.xml @@ -188,4 +188,6 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-es/strings.xml b/common/resources/src/main/res/values-es/strings.xml index 23e356d0..4355d720 100644 --- a/common/resources/src/main/res/values-es/strings.xml +++ b/common/resources/src/main/res/values-es/strings.xml @@ -223,4 +223,6 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-fa/strings.xml b/common/resources/src/main/res/values-fa/strings.xml index a7c01a9a..04f8303b 100644 --- a/common/resources/src/main/res/values-fa/strings.xml +++ b/common/resources/src/main/res/values-fa/strings.xml @@ -188,4 +188,6 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-fil/strings.xml b/common/resources/src/main/res/values-fil/strings.xml index 5b745e67..cd055ab3 100644 --- a/common/resources/src/main/res/values-fil/strings.xml +++ b/common/resources/src/main/res/values-fil/strings.xml @@ -187,4 +187,6 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-fr/strings.xml b/common/resources/src/main/res/values-fr/strings.xml index 2d516f08..0261ed41 100644 --- a/common/resources/src/main/res/values-fr/strings.xml +++ b/common/resources/src/main/res/values-fr/strings.xml @@ -187,4 +187,6 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-hr/strings.xml b/common/resources/src/main/res/values-hr/strings.xml index 2939ee19..5bf94b29 100644 --- a/common/resources/src/main/res/values-hr/strings.xml +++ b/common/resources/src/main/res/values-hr/strings.xml @@ -188,4 +188,6 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-in/strings.xml b/common/resources/src/main/res/values-in/strings.xml index bcaa29a6..46731abe 100644 --- a/common/resources/src/main/res/values-in/strings.xml +++ b/common/resources/src/main/res/values-in/strings.xml @@ -187,6 +187,8 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-it/strings.xml b/common/resources/src/main/res/values-it/strings.xml index 78475b1d..7f1972a6 100644 --- a/common/resources/src/main/res/values-it/strings.xml +++ b/common/resources/src/main/res/values-it/strings.xml @@ -187,4 +187,6 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-ja/strings.xml b/common/resources/src/main/res/values-ja/strings.xml index 9f163915..a7e65753 100644 --- a/common/resources/src/main/res/values-ja/strings.xml +++ b/common/resources/src/main/res/values-ja/strings.xml @@ -187,4 +187,6 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. \ No newline at end of file diff --git a/common/resources/src/main/res/values-kr/strings.xml b/common/resources/src/main/res/values-kr/strings.xml index f10e9efb..77a01183 100644 --- a/common/resources/src/main/res/values-kr/strings.xml +++ b/common/resources/src/main/res/values-kr/strings.xml @@ -188,4 +188,6 @@ 설정 이름은 비워둘 수 없습니다 재시작 사용자 정의 RPC 실행 중 + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-mm/strings.xml b/common/resources/src/main/res/values-mm/strings.xml index 6cfe8f39..6b34a88f 100644 --- a/common/resources/src/main/res/values-mm/strings.xml +++ b/common/resources/src/main/res/values-mm/strings.xml @@ -187,4 +187,6 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-nl/strings.xml b/common/resources/src/main/res/values-nl/strings.xml index 51cc072e..383e26b4 100644 --- a/common/resources/src/main/res/values-nl/strings.xml +++ b/common/resources/src/main/res/values-nl/strings.xml @@ -187,6 +187,8 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. \ No newline at end of file diff --git a/common/resources/src/main/res/values-pl/strings.xml b/common/resources/src/main/res/values-pl/strings.xml index a11b55bf..d42ce52b 100644 --- a/common/resources/src/main/res/values-pl/strings.xml +++ b/common/resources/src/main/res/values-pl/strings.xml @@ -188,4 +188,6 @@ Nazwa konfiguracji nie może być pusta Restartuj Własne RPC jest uruchomiony + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-pt/strings.xml b/common/resources/src/main/res/values-pt/strings.xml index 256c18bc..1d32648e 100644 --- a/common/resources/src/main/res/values-pt/strings.xml +++ b/common/resources/src/main/res/values-pt/strings.xml @@ -187,5 +187,7 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-ru/strings.xml b/common/resources/src/main/res/values-ru/strings.xml index 8b5dd282..1155e656 100644 --- a/common/resources/src/main/res/values-ru/strings.xml +++ b/common/resources/src/main/res/values-ru/strings.xml @@ -187,4 +187,6 @@ Название конфигурации не может быть пустым Перезапустить Свой RPC запущен + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-th/strings.xml b/common/resources/src/main/res/values-th/strings.xml index eb207cfd..9eb9bf13 100644 --- a/common/resources/src/main/res/values-th/strings.xml +++ b/common/resources/src/main/res/values-th/strings.xml @@ -187,4 +187,6 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-tr/strings.xml b/common/resources/src/main/res/values-tr/strings.xml index 7fad7b19..724a6ca3 100644 --- a/common/resources/src/main/res/values-tr/strings.xml +++ b/common/resources/src/main/res/values-tr/strings.xml @@ -187,4 +187,6 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values-vi/strings.xml b/common/resources/src/main/res/values-vi/strings.xml index 56473754..e4aafe45 100644 --- a/common/resources/src/main/res/values-vi/strings.xml +++ b/common/resources/src/main/res/values-vi/strings.xml @@ -187,4 +187,6 @@ Tên cấu hình không được để trống Khởi chạy lại RPC tuỳ chỉnh đang chạy + Lưu trữ hình ảnh trên Imgur + Sử dụng Imgur làm nơi lưu trữ hình ảnh. diff --git a/common/resources/src/main/res/values-zh/strings.xml b/common/resources/src/main/res/values-zh/strings.xml index bc4eb012..5b362f05 100644 --- a/common/resources/src/main/res/values-zh/strings.xml +++ b/common/resources/src/main/res/values-zh/strings.xml @@ -187,4 +187,6 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/common/resources/src/main/res/values/strings.xml b/common/resources/src/main/res/values/strings.xml index 2c2906f5..fbac8236 100644 --- a/common/resources/src/main/res/values/strings.xml +++ b/common/resources/src/main/res/values/strings.xml @@ -38,9 +38,9 @@ Storage permission required for config features to work. Please grant the permission. Grant Permission Use Low Resolution Images - Use a lower resolution app icon for displaying on RPC (turn this on if the RPC is crashing). This setting will also be applied to Apps . + Use a lower resolution app icon for displaying on RPC (turn this on if the RPC is crashing). This setting will also be applied to Apps. Delete Saved Icon Links - Delete app icon URLs saved in local files (Only use this in rare cases as it will send all the images again to discord servers which will consume more data) + Delete app icon URLs saved in local files (Only use this as needed as it will send images to Discord servers again, which will consume more data) App Crashed Please send the Logs in Discord channel with the following stacktrace : SHARE LOGS @@ -188,4 +188,6 @@ Config name cannot be empty Restart Custom RPC is running + Imgur as Image Proxy + Use Imgur as an alternate image proxy. diff --git a/data/build.gradle.kts b/data/build.gradle.kts index bff10126..65f9795b 100644 --- a/data/build.gradle.kts +++ b/data/build.gradle.kts @@ -12,6 +12,7 @@ android { buildConfigFieldFromGradleProperty("BASE_URL","BASE_URL") buildConfigFieldFromGradleProperty("DISCORD_API_BASE_URL","DISCORD_API_URL") buildConfigFieldFromGradleProperty("GITHUB_API_BASE_URL","GITHUB_API_URL") + buildConfigFieldFromGradleProperty("IMGUR_API_BASE_URL", "IMGUR_API_URL") } } diff --git a/data/src/main/java/com/my/kizzy/data/di/AppModule.kt b/data/src/main/java/com/my/kizzy/data/di/AppModule.kt index 5968a9ec..8a8dad93 100644 --- a/data/src/main/java/com/my/kizzy/data/di/AppModule.kt +++ b/data/src/main/java/com/my/kizzy/data/di/AppModule.kt @@ -17,6 +17,8 @@ import com.my.kizzy.data.remote.ApiService import com.my.kizzy.data.remote.Base import com.my.kizzy.data.remote.Discord import com.my.kizzy.data.remote.Github +import com.my.kizzy.data.remote.Imgur +import com.my.kizzy.data.remote.ImgurApiService import com.my.kizzy.data.repository.KizzyRepositoryImpl import com.my.kizzy.domain.repository.KizzyRepository import dagger.Module @@ -53,6 +55,11 @@ object AppModule { @Github fun provideGithubBaseUrl() = BuildConfig.GITHUB_API_BASE_URL + @Provides + @Singleton + @Imgur + fun provideImgurBaseUrl() = BuildConfig.IMGUR_API_BASE_URL + @Provides fun provideJson() = Json { ignoreUnknownKeys = true @@ -88,7 +95,8 @@ object AppModule { @Provides fun providesKizzyRepository( apiService: ApiService, + imgurApiService: ImgurApiService ): KizzyRepository { - return KizzyRepositoryImpl(apiService) + return KizzyRepositoryImpl(apiService, imgurApiService) } } \ No newline at end of file diff --git a/data/src/main/java/com/my/kizzy/data/get_current_data/media/GetCurrentlyPlayingMedia.kt b/data/src/main/java/com/my/kizzy/data/get_current_data/media/GetCurrentlyPlayingMedia.kt index a10e2f30..06253219 100644 --- a/data/src/main/java/com/my/kizzy/data/get_current_data/media/GetCurrentlyPlayingMedia.kt +++ b/data/src/main/java/com/my/kizzy/data/get_current_data/media/GetCurrentlyPlayingMedia.kt @@ -78,7 +78,8 @@ class GetCurrentPlayingMedia @Inject constructor( context = context, bitmap = bitmap, packageName = mediaController.packageName, - title = title + //
| + title = "${metadata.let { metadataResolver.getAlbumArtists(it) }}|${metadata.let { metadataResolver.getAlbum(it) } ?: title}" ) } else smallIcon = null return CommonRpc(name = appName, diff --git a/data/src/main/java/com/my/kizzy/data/get_current_data/media/MetadataResolver.kt b/data/src/main/java/com/my/kizzy/data/get_current_data/media/MetadataResolver.kt index d4dc8cb9..d682e8a0 100644 --- a/data/src/main/java/com/my/kizzy/data/get_current_data/media/MetadataResolver.kt +++ b/data/src/main/java/com/my/kizzy/data/get_current_data/media/MetadataResolver.kt @@ -37,4 +37,10 @@ class MetadataResolver @Inject constructor() { MediaMetadata.METADATA_KEY_ALBUM ) else null } + + fun getAlbumArtists(metadata: MediaMetadata): String? { + return if (!metadata.getString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST).isNullOrEmpty()) metadata.getString( + MediaMetadata.METADATA_KEY_ALBUM_ARTIST + ) else getArtistOrAuthor(metadata) + } } \ No newline at end of file diff --git a/data/src/main/java/com/my/kizzy/data/remote/ApiService.kt b/data/src/main/java/com/my/kizzy/data/remote/ApiService.kt index 4a9a1a7f..0999f745 100644 --- a/data/src/main/java/com/my/kizzy/data/remote/ApiService.kt +++ b/data/src/main/java/com/my/kizzy/data/remote/ApiService.kt @@ -13,6 +13,7 @@ package com.my.kizzy.data.remote import com.my.kizzy.domain.model.samsung_rpc.GalaxyPresence import io.ktor.client.HttpClient +import io.ktor.client.call.body import io.ktor.client.request.forms.MultiPartFormDataContent import io.ktor.client.request.forms.formData import io.ktor.client.request.get @@ -21,9 +22,11 @@ import io.ktor.client.request.parameter import io.ktor.client.request.post import io.ktor.client.request.setBody import io.ktor.client.request.url +import io.ktor.client.statement.HttpResponse import io.ktor.http.ContentType import io.ktor.http.Headers import io.ktor.http.HttpHeaders +import io.ktor.http.HttpStatusCode import io.ktor.http.contentType import java.io.File import javax.inject.Inject @@ -40,6 +43,7 @@ class ApiService @Inject constructor( parameter("url", url) } } + suspend fun uploadImage(file: File) = runCatching { client.post { url("$baseUrl/upload") @@ -84,6 +88,7 @@ class ApiService @Inject constructor( setBody(galaxyPresence) } } + suspend fun checkForUpdate() = runCatching { client.get { url("$githubBaseUrl/repos/dead8309/Kizzy/releases/latest") diff --git a/data/src/main/java/com/my/kizzy/data/remote/ExternalAsset.kt b/data/src/main/java/com/my/kizzy/data/remote/ExternalAsset.kt new file mode 100644 index 00000000..b4ef0eee --- /dev/null +++ b/data/src/main/java/com/my/kizzy/data/remote/ExternalAsset.kt @@ -0,0 +1,24 @@ +/* + * + * ****************************************************************** + * * * Copyright (C) 2022 + * * * ExternalAsset.kt is part of Kizzy + * * * and can not be copied and/or distributed without the express + * * * permission of yzziK(Vaibhav) + * * ***************************************************************** + * + * + */ + +package com.my.kizzy.data.remote + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ExternalAsset( + @SerialName("external_asset_path") + val externalAssetPath: String, + @SerialName("url") + val url: String +) \ No newline at end of file diff --git a/data/src/main/java/com/my/kizzy/data/remote/ImgurApiService.kt b/data/src/main/java/com/my/kizzy/data/remote/ImgurApiService.kt new file mode 100644 index 00000000..3d827496 --- /dev/null +++ b/data/src/main/java/com/my/kizzy/data/remote/ImgurApiService.kt @@ -0,0 +1,66 @@ +/* + * + * ****************************************************************** + * * * Copyright (C) 2022 + * * * ImgurApiService.kt is part of Kizzy + * * * and can not be copied and/or distributed without the express + * * * permission of yzziK(Vaibhav) + * * ***************************************************************** + * + * + */ + +package com.my.kizzy.data.remote + +import com.my.kizzy.data.rpc.Constants.APPLICATION_ID +import io.ktor.client.HttpClient +import io.ktor.client.call.body +import io.ktor.client.request.forms.MultiPartFormDataContent +import io.ktor.client.request.forms.formData +import io.ktor.client.request.headers +import io.ktor.client.request.post +import io.ktor.client.request.setBody +import io.ktor.client.request.url +import io.ktor.client.statement.HttpResponse +import io.ktor.http.ContentType +import io.ktor.http.HttpHeaders +import io.ktor.http.HttpStatusCode +import io.ktor.http.contentType +import java.io.File +import javax.inject.Inject + +class ImgurApiService @Inject constructor( + private val client: HttpClient, + @Discord private val discordBaseUrl: String, + @Imgur private val imgurBaseUrl: String, +) { + suspend fun getImage(url: String, token: String) = runCatching { + client.post { + url("$discordBaseUrl/applications/$APPLICATION_ID/external-assets") + headers { + append(HttpHeaders.Authorization, token) + append(HttpHeaders.ContentType, "application/json") + } + setBody(mapOf("urls" to arrayOf(url))) + } + } + + suspend fun uploadImage(file: File) = runCatching { + client.post { + url("$imgurBaseUrl/image") + headers { + // Imgur web client API key, unchanged for at least >5 years as of 2024 + append(HttpHeaders.Authorization, "Client-ID 546c25a59c58ad7") + } + contentType(ContentType.MultiPart.FormData) + setBody( + MultiPartFormDataContent( + formData { + append("image", file.readBytes()) + append("type", "raw") + } + ) + ) + } + } +} \ No newline at end of file diff --git a/data/src/main/java/com/my/kizzy/data/remote/ImgurResponse.kt b/data/src/main/java/com/my/kizzy/data/remote/ImgurResponse.kt new file mode 100644 index 00000000..e5ce0537 --- /dev/null +++ b/data/src/main/java/com/my/kizzy/data/remote/ImgurResponse.kt @@ -0,0 +1,28 @@ +/* + * + * ****************************************************************** + * * * Copyright (C) 2022 + * * * ImgurResponse.kt is part of Kizzy + * * * and can not be copied and/or distributed without the express + * * * permission of yzziK(Vaibhav) + * * ***************************************************************** + * + * + */ + +package com.my.kizzy.data.remote + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ImgurResponse( + @SerialName("data") + val data: Data +) { + @Serializable + data class Data( + @SerialName("link") + val link: String, + ) +} \ No newline at end of file diff --git a/data/src/main/java/com/my/kizzy/data/remote/Qualifier.kt b/data/src/main/java/com/my/kizzy/data/remote/Qualifier.kt index 2a5aefa2..42e6e4bc 100644 --- a/data/src/main/java/com/my/kizzy/data/remote/Qualifier.kt +++ b/data/src/main/java/com/my/kizzy/data/remote/Qualifier.kt @@ -26,3 +26,6 @@ annotation class Discord @Retention(AnnotationRetention.BINARY) annotation class Github +@Qualifier +@Retention(AnnotationRetention.BINARY) +annotation class Imgur diff --git a/data/src/main/java/com/my/kizzy/data/repository/KizzyRepositoryImpl.kt b/data/src/main/java/com/my/kizzy/data/repository/KizzyRepositoryImpl.kt index 86ef5dbe..a5de948f 100644 --- a/data/src/main/java/com/my/kizzy/data/repository/KizzyRepositoryImpl.kt +++ b/data/src/main/java/com/my/kizzy/data/repository/KizzyRepositoryImpl.kt @@ -14,8 +14,11 @@ package com.my.kizzy.data.repository import com.my.kizzy.data.remote.ApiService import com.my.kizzy.data.remote.GamesResponse +import com.my.kizzy.data.remote.ImgurApiService import com.my.kizzy.data.remote.toGame -import com.my.kizzy.data.utils.toImageAsset +import com.my.kizzy.data.utils.toAttachmentAsset +import com.my.kizzy.data.utils.toExternalAsset +import com.my.kizzy.data.utils.toImageURL import com.my.kizzy.domain.model.Contributor import com.my.kizzy.domain.model.Game import com.my.kizzy.domain.model.release.Release @@ -30,14 +33,23 @@ import javax.inject.Inject class KizzyRepositoryImpl @Inject constructor( private val api: ApiService, + private val imgurApi: ImgurApiService ): KizzyRepository { override suspend fun getImage(url: String): String? { - return api.getImage(url).getOrNull()?.toImageAsset() + return if (Prefs[Prefs.USE_IMGUR, false]) { + imgurApi.getImage(url, Prefs[Prefs.TOKEN]).getOrNull()?.toExternalAsset() + } else { + api.getImage(url).getOrNull()?.toAttachmentAsset() + } } override suspend fun uploadImage(file: File): String? { - return api.uploadImage(file).getOrNull()?.toImageAsset() + return if (Prefs[Prefs.USE_IMGUR, false]) { + imgurApi.uploadImage(file).getOrNull()?.toImageURL()?.let { this.getImage(it) } + } else { + api.uploadImage(file).getOrNull()?.toAttachmentAsset() + } } override suspend fun getGames(): List { diff --git a/data/src/main/java/com/my/kizzy/data/utils/Ext.kt b/data/src/main/java/com/my/kizzy/data/utils/Ext.kt index 6d0a2b39..ccae26fd 100644 --- a/data/src/main/java/com/my/kizzy/data/utils/Ext.kt +++ b/data/src/main/java/com/my/kizzy/data/utils/Ext.kt @@ -28,6 +28,8 @@ import com.blankj.utilcode.util.AppUtils import com.blankj.utilcode.util.FileIOUtils import com.blankj.utilcode.util.FileUtils import com.my.kizzy.data.remote.ApiResponse +import com.my.kizzy.data.remote.ExternalAsset +import com.my.kizzy.data.remote.ImgurResponse import com.my.kizzy.data.rpc.RpcImage import com.my.kizzy.preference.Prefs import io.ktor.client.call.body @@ -36,7 +38,29 @@ import io.ktor.http.HttpStatusCode import java.io.File import java.io.FileOutputStream -suspend fun HttpResponse.toImageAsset(): String? { +suspend fun HttpResponse.toImageURL(): String? { + return try { + if (this.status == HttpStatusCode.OK) + this.body().data.link + else + null + } catch (e: Exception) { + null + } +} + +suspend fun HttpResponse.toExternalAsset(): String? { + return try { + if (this.status == HttpStatusCode.OK) + "mp:" + this.body>().first().externalAssetPath + else + null + } catch (e: Exception) { + null + } +} + +suspend fun HttpResponse.toAttachmentAsset(): String? { return try { if (this.status == HttpStatusCode.OK) this.body().id @@ -96,7 +120,7 @@ fun ApplicationInfo.toBitmap(context: Context): Bitmap? { fun String.toRpcImage(): RpcImage? { return if (this.isBlank()) null - else if (this.startsWith("attachments")) + else if (this.startsWith("attachments") || this.startsWith("external")) RpcImage.DiscordImage(this) else RpcImage.ExternalImage(this) diff --git a/feature_profile/src/main/java/com/my/kizzy/feature_profile/ui/component/ActivityRow.kt b/feature_profile/src/main/java/com/my/kizzy/feature_profile/ui/component/ActivityRow.kt index 488c9eda..790a608b 100644 --- a/feature_profile/src/main/java/com/my/kizzy/feature_profile/ui/component/ActivityRow.kt +++ b/feature_profile/src/main/java/com/my/kizzy/feature_profile/ui/component/ActivityRow.kt @@ -37,9 +37,9 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color +import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import coil.compose.AsyncImage @@ -85,6 +85,8 @@ fun ActivityRow( } } } + + Column( Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(1.dp) @@ -103,11 +105,12 @@ fun ActivityRow( contentAlignment = Alignment.Center ) { AsyncImage( - model = if (rpcConfig?.largeImg?.startsWith("attachments") == true) "https://media.discordapp.net/${rpcConfig.largeImg}" else + model = if (isAsset(rpcConfig?.largeImg)) "https://media.discordapp.net/${rpcConfig?.largeImg}" else rpcConfig?.largeImg, error = painterResource(id = R.drawable.editing_rpc_pencil), placeholder = painterResource(R.drawable.editing_rpc_pencil), contentDescription = null, + contentScale = ContentScale.FillHeight, modifier = if (!rpcConfig?.largeImg.isNullOrEmpty()) Modifier .size(70.dp) @@ -120,13 +123,14 @@ fun ActivityRow( if (!rpcConfig?.smallImg.isNullOrEmpty()) { AsyncImage( model = - if (rpcConfig?.smallImg?.startsWith("attachments") == true) - "https://media.discordapp.net/${rpcConfig.largeImg}" + if (isAsset(rpcConfig?.smallImg)) + "https://media.discordapp.net/${rpcConfig?.smallImg}" else rpcConfig?.smallImg, error = painterResource(id = R.drawable.ic_rpc_placeholder), placeholder = painterResource(R.drawable.ic_rpc_placeholder), contentDescription = null, + contentScale = ContentScale.FillHeight, modifier = Modifier .size(30.dp) .clip(CircleShape) @@ -281,7 +285,11 @@ fun ActivityRow( } } -fun getFormatFromMs(ms: Long): String { +private fun isAsset(url: String?): Boolean { + return url?.startsWith("attachments") == true || url?.startsWith("external") == true +} + +private fun getFormatFromMs(ms: Long): String { var remainingMs = ms val daysDifference = TimeUnit.MILLISECONDS.toDays(remainingMs) @@ -296,7 +304,7 @@ fun getFormatFromMs(ms: Long): String { String.format(Locale.US, "%02d:%02d", minutesDifference, secondsDifference) } -fun formatTime(start: Long?, end: Long? = null): String { +private fun formatTime(start: Long?, end: Long? = null): String { val startTime = end ?: start ?: return "" val endTime = System.currentTimeMillis() diff --git a/feature_settings/src/main/java/com/my/kizzy/feature_settings/rpc_settings/RpcSettings.kt b/feature_settings/src/main/java/com/my/kizzy/feature_settings/rpc_settings/RpcSettings.kt index 70858af7..d70fbf42 100644 --- a/feature_settings/src/main/java/com/my/kizzy/feature_settings/rpc_settings/RpcSettings.kt +++ b/feature_settings/src/main/java/com/my/kizzy/feature_settings/rpc_settings/RpcSettings.kt @@ -28,6 +28,7 @@ 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.Image import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material.icons.filled.KeyboardArrowUp import androidx.compose.material.icons.filled.SmartButton @@ -75,6 +76,7 @@ import kotlinx.serialization.json.Json fun RpcSettings(onBackPressed: () -> Boolean) { val context = LocalContext.current var isLowResIconsEnabled by remember { mutableStateOf(Prefs[Prefs.RPC_USE_LOW_RES_ICON, false]) } + var useImgur by remember { mutableStateOf(Prefs[Prefs.USE_IMGUR, false]) } var configsDir by remember { mutableStateOf(Prefs[Prefs.CONFIGS_DIRECTORY, ""]) } var showDirConfigDialog by remember { mutableStateOf(false) } var useButtonConfigs by remember { mutableStateOf(Prefs[Prefs.USE_RPC_BUTTONS, false]) } @@ -187,6 +189,17 @@ fun RpcSettings(onBackPressed: () -> Boolean) { Prefs[Prefs.SAMSUNG_RPC_ENABLED] = isSamsungRpcEnabled } } + item { + PreferenceSwitch( + title = stringResource(id = R.string.use_imgur), + description = stringResource(id = R.string.use_imgur_desc), + icon = Icons.Default.Image, + isChecked = useImgur + ) { + useImgur = !useImgur + Prefs[Prefs.USE_IMGUR] = useImgur + } + } item { PreferenceSwitch( title = stringResource(id = R.string.use_low_res_icon), diff --git a/gradle.properties b/gradle.properties index 311671e7..84e83c2d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,3 +27,4 @@ android.defaults.buildfeatures.buildconfig=true android.nonFinalResIds=false DISCORD_API_URL="https://discord.com/api/v10" GITHUB_API_URL="https://api.github.com" +IMGUR_API_URL="https://api.imgur.com/3"