From 0dd7039c0539b2d2286b0b500c23809110f6b89c Mon Sep 17 00:00:00 2001 From: bluepie Date: Sat, 26 Mar 2022 15:04:56 +0530 Subject: [PATCH] spotify-tv --- app/build.gradle | 4 ++-- app/src/main/AndroidManifest.xml | 1 + .../bluepie/ad_silence/AdSilenceActivity.kt | 17 +++++++++++++++++ .../bluepie/ad_silence/NotificationParser.kt | 2 +- .../main/java/bluepie/ad_silence/Preference.kt | 4 ++++ .../java/bluepie/ad_silence/SupportedApps.kt | 1 + app/src/main/java/bluepie/ad_silence/Utils.kt | 3 +++ app/src/main/res/layout/app_selection.xml | 7 +++++++ app/src/main/res/values/strings.xml | 2 ++ 9 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7cc54ed..ff427a4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "bluepie.ad_silence" minSdk 21 targetSdk 31 - versionCode 25 - versionName "0.5.3" + versionCode 28 + versionName "0.5.4-android-tv" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0ad58a4..706bfd0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,6 +10,7 @@ + (R.id.about_btn)?.setOnClickListener { layoutInflater.inflate(R.layout.about, null)?.run { @@ -256,6 +257,22 @@ class AdSilenceActivity : Activity() { } } + appSelectionView.findViewById(R.id.spotify_tv)?.run { + this.isEnabled = isSpotifyTvInstalled + this.isChecked = preference.isAppConfigured(SupportedApps.SPOTIFY_TV) + "${context.getString(R.string.spotify_tv)} ${ + if (isSpotifyTvInstalled) applicationContext.getString(R.string.beta) else context.getString(R.string.not_installed) + }".also { + this.text = it + } + this.setOnClickListener{ + preference.setAppConfigured( + SupportedApps.SPOTIFY_TV, + !preference.isAppConfigured(SupportedApps.SPOTIFY_TV) + ) + } + } + AlertDialog.Builder(this).setView(appSelectionView).show() } } diff --git a/app/src/main/java/bluepie/ad_silence/NotificationParser.kt b/app/src/main/java/bluepie/ad_silence/NotificationParser.kt index 90f3e49..7e6c9d5 100644 --- a/app/src/main/java/bluepie/ad_silence/NotificationParser.kt +++ b/app/src/main/java/bluepie/ad_silence/NotificationParser.kt @@ -26,7 +26,7 @@ fun AppNotification.getApp(): SupportedApps { fun AppNotification.adString(): List { return when (getApp()) { SupportedApps.ACCURADIO -> listOf(context.getString(R.string.accuradio_ad_text)) - SupportedApps.SPOTIFY, SupportedApps.SPOTIFY_LITE -> listOf( + SupportedApps.SPOTIFY, SupportedApps.SPOTIFY_LITE, SupportedApps.SPOTIFY_TV -> listOf( context.getString(R.string.spotify_ad_string), context.getString(R.string.spotify_ad2) ) diff --git a/app/src/main/java/bluepie/ad_silence/Preference.kt b/app/src/main/java/bluepie/ad_silence/Preference.kt index 9a7ccde..c29291a 100644 --- a/app/src/main/java/bluepie/ad_silence/Preference.kt +++ b/app/src/main/java/bluepie/ad_silence/Preference.kt @@ -30,6 +30,8 @@ class Preference(private val context: Context) { private val PANDORA_DEFAULT = true val LIVEONE = "Liveone" private val LIVEONE_DEFAULT = true + val SPOTIFY_TV = "SpotifyTV"; + private val SPOTIFY_TV_DEFAULT = true @@ -51,6 +53,7 @@ class Preference(private val context: Context) { SupportedApps.SPOTIFY_LITE-> preference.edit { putBoolean(SPOTIFY_LITE, status).commit() } SupportedApps.PANDORA-> preference.edit { putBoolean(PANDORA, status).commit() } SupportedApps.LiveOne-> preference.edit { putBoolean(LIVEONE, status).commit() } + SupportedApps.SPOTIFY_TV-> preference.edit { putBoolean(SPOTIFY_TV, status).commit() } } } @@ -62,6 +65,7 @@ class Preference(private val context: Context) { SupportedApps.SPOTIFY_LITE-> preference.getBoolean(SPOTIFY_LITE, SPOTIFY_LITE_DEFAULT) SupportedApps.PANDORA-> preference.getBoolean(PANDORA, PANDORA_DEFAULT) SupportedApps.LiveOne-> preference.getBoolean(LIVEONE, LIVEONE_DEFAULT) + SupportedApps.SPOTIFY_TV-> preference.getBoolean(SPOTIFY_TV, SPOTIFY_TV_DEFAULT) else -> false } diff --git a/app/src/main/java/bluepie/ad_silence/SupportedApps.kt b/app/src/main/java/bluepie/ad_silence/SupportedApps.kt index 18402c2..ca95243 100644 --- a/app/src/main/java/bluepie/ad_silence/SupportedApps.kt +++ b/app/src/main/java/bluepie/ad_silence/SupportedApps.kt @@ -7,5 +7,6 @@ enum class SupportedApps { SPOTIFY_LITE, PANDORA, LiveOne, + SPOTIFY_TV, INVALID } diff --git a/app/src/main/java/bluepie/ad_silence/Utils.kt b/app/src/main/java/bluepie/ad_silence/Utils.kt index 2fc32b1..9e042b3 100644 --- a/app/src/main/java/bluepie/ad_silence/Utils.kt +++ b/app/src/main/java/bluepie/ad_silence/Utils.kt @@ -51,6 +51,9 @@ class Utils { fun isLiveOneInstalled(context: Context) = isPackageInstalled(context, context.getString(R.string.liveOne_package_name)) + fun isSpotifyTVInstalled(context: Context) = + isPackageInstalled(context, context.getString(R.string.spotify_tv_package_name)) + fun isMusicMuted(audoManager: AudioManager): Boolean { if (Build.VERSION.SDK_INT >= 23) { return audoManager.isStreamMute(AudioManager.STREAM_MUSIC) diff --git a/app/src/main/res/layout/app_selection.xml b/app/src/main/res/layout/app_selection.xml index ba22260..2bdea5b 100644 --- a/app/src/main/res/layout/app_selection.xml +++ b/app/src/main/res/layout/app_selection.xml @@ -48,4 +48,11 @@ android:minHeight="48dp" android:text="@string/liveone" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index efd5e58..6da251e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -51,4 +51,6 @@ 60 Minutes Uninterrupted Listening LiveOne (Beta) + com.spotify.tv.android + Spotify tv \ No newline at end of file