Skip to content

Commit

Permalink
Merge pull request #4718 from Bnyro/master
Browse files Browse the repository at this point in the history
fix: properly kill offline player notification
  • Loading branch information
Bnyro authored Sep 8, 2023
2 parents 1d7fce9 + 5989523 commit 1f96e88
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 41 deletions.
5 changes: 0 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,6 @@
android:enabled="true"
android:exported="false" />

<service
android:name=".services.ClosingService"
android:enabled="true"
android:exported="false" />

<service
android:name=".services.OnlinePlayerService"
android:enabled="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ object BackgroundHelper {
/**
* Stop the [OnlinePlayerService] service if it is running.
*/
fun stopBackgroundPlay(context: Context) {
if (isBackgroundServiceRunning(context)) {
fun stopBackgroundPlay(context: Context, serviceClass: Class<*> = OnlinePlayerService::class.java) {
if (isBackgroundServiceRunning(context, serviceClass)) {
// Intent to stop background mode service
val intent = Intent(context, OnlinePlayerService::class.java)
val intent = Intent(context, serviceClass)
context.stopService(intent)
}
}

/**
* Check if the [OnlinePlayerService] service is currently running.
*/
fun isBackgroundServiceRunning(context: Context): Boolean {
fun isBackgroundServiceRunning(context: Context, serviceClass: Class<*> = OnlinePlayerService::class.java): Boolean {
@Suppress("DEPRECATION")
return context.getSystemService<ActivityManager>()!!.getRunningServices(Int.MAX_VALUE)
.any { OnlinePlayerService::class.java.name == it.service.className }
.any { serviceClass.name == it.service.className }
}
}
23 changes: 0 additions & 23 deletions app/src/main/java/com/github/libretube/services/ClosingService.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,12 @@ class OfflinePlayerService : LifecycleService() {
super.onBind(intent)
return null
}

/**
* Stop the service when app is removed from the task manager.
*/
override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent)
onDestroy()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import com.github.libretube.helpers.NetworkHelper
import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.helpers.ThemeHelper
import com.github.libretube.helpers.WindowHelper
import com.github.libretube.services.ClosingService
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.dialogs.ErrorDialog
import com.github.libretube.ui.fragments.AudioPlayerFragment
Expand Down Expand Up @@ -65,13 +64,6 @@ class MainActivity : BaseActivity() {
// enable auto rotation if turned on
requestOrientationChange()

// start service that gets called on closure
try {
startService(Intent(this, ClosingService::class.java))
} catch (e: Exception) {
e.printStackTrace()
}

// show noInternet Activity if no internet available on app startup
if (!NetworkHelper.isNetworkAvailable(this)) {
val noInternetIntent = Intent(this, NoInternetActivity::class.java)
Expand Down

0 comments on commit 1f96e88

Please sign in to comment.