-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attach/detach YouTubeSessionService based on app lifecycle
- Loading branch information
Showing
5 changed files
with
36 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,41 @@ | ||
package com.livetl.android | ||
|
||
import android.app.Application | ||
import androidx.lifecycle.DefaultLifecycleObserver | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.ProcessLifecycleOwner | ||
import com.livetl.android.data.media.YouTubeSessionService | ||
import dagger.hilt.android.HiltAndroidApp | ||
import logcat.AndroidLogcatLogger | ||
import logcat.LogPriority | ||
import logcat.LogcatLogger | ||
import javax.inject.Inject | ||
|
||
@HiltAndroidApp | ||
class App : Application() { | ||
class App : | ||
Application(), | ||
DefaultLifecycleObserver { | ||
|
||
@Inject | ||
lateinit var youTubeSessionService: YouTubeSessionService | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
super<Application>.onCreate() | ||
|
||
if (!LogcatLogger.isInstalled) { | ||
LogcatLogger.install(AndroidLogcatLogger(if (BuildConfig.DEBUG) LogPriority.VERBOSE else LogPriority.ERROR)) | ||
} | ||
|
||
ProcessLifecycleOwner.get().lifecycle.addObserver(this) | ||
} | ||
|
||
override fun onStart(owner: LifecycleOwner) { | ||
// TODO: attach when notification permissions granted? | ||
youTubeSessionService.attach() | ||
} | ||
|
||
override fun onStop(owner: LifecycleOwner) { | ||
// TODO: stop ChatService too? | ||
youTubeSessionService.detach() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters