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

android-tv #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<package android:name="com.spotify.lite"/>
<package android:name="com.pandora.android"/>
<package android:name="com.slacker.radio"/>
<package android:name="com.spotify.tv.android"/>
</queries>
<application
android:allowBackup="true"
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/bluepie/ad_silence/AdSilenceActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class AdSilenceActivity : Activity() {
val isSpotifyLiteInstalled = utils.isSpotifyLiteInstalled(applicationContext)
val isPandoraInstalled = utils.isPandoraInstalled(applicationContext)
val isLiveOneInstalled = utils.isLiveOneInstalled(applicationContext)
val isSpotifyTvInstalled = utils.isSpotifyTVInstalled(applicationContext)

findViewById<Button>(R.id.about_btn)?.setOnClickListener {
layoutInflater.inflate(R.layout.about, null)?.run {
Expand Down Expand Up @@ -256,6 +257,22 @@ class AdSilenceActivity : Activity() {
}
}

appSelectionView.findViewById<Switch>(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()
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/bluepie/ad_silence/NotificationParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fun AppNotification.getApp(): SupportedApps {
fun AppNotification.adString(): List<String> {
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)
)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/bluepie/ad_silence/Preference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand All @@ -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() }
}
}

Expand All @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/bluepie/ad_silence/SupportedApps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ enum class SupportedApps {
SPOTIFY_LITE,
PANDORA,
LiveOne,
SPOTIFY_TV,
INVALID
}
3 changes: 3 additions & 0 deletions app/src/main/java/bluepie/ad_silence/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/app_selection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@
android:minHeight="48dp"
android:text="@string/liveone" />

<Switch
android:id="@+id/spotify_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:text="@string/spotify_tv" />

</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@
<string name="liveOne_ad_string_2">60 Minutes Uninterrupted Listening</string>
<string name="liveone">LiveOne</string>
<string name="beta">(Beta)</string>
<string name="spotify_tv_package_name">com.spotify.tv.android</string>
<string name="spotify_tv">Spotify tv</string>
</resources>