Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VLC-Android
Manage
Activity
Members
Labels
Plan
Issues
531
Issue boards
Milestones
Wiki
Code
Merge requests
14
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VideoLAN
VLC-Android
Commits
773b5a17
Commit
773b5a17
authored
6 years ago
by
Geoffrey Métais
Browse files
Options
Downloads
Patches
Plain Diff
CoroutineScope helper for LifecycleOwner classes
parent
fe9a5792
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tools/build.gradle
+3
-0
3 additions, 0 deletions
tools/build.gradle
tools/src/main/java/org/videolan/tools/KotlinExtensions.kt
+29
-0
29 additions, 0 deletions
tools/src/main/java/org/videolan/tools/KotlinExtensions.kt
with
32 additions
and
0 deletions
tools/build.gradle
+
3
−
0
View file @
773b5a17
...
...
@@ -30,6 +30,9 @@ dependencies {
api
"com.android.support:appcompat-v7:$rootProject.ext.appCompatVersion"
api
"com.android.support:support-tv-provider:$rootProject.ext.appCompatVersion"
implementation
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
implementation
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation
"org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.ext.kotlinx_version"
implementation
"org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.ext.kotlinx_version"
testImplementation
"junit:junit:$rootProject.ext.junitVersion"
androidTestImplementation
"com.android.support.test:runner:$rootProject.ext.supportTest"
...
...
This diff is collapsed.
Click to expand it.
tools/src/main/java/org/videolan/tools/KotlinExtensions.kt
0 → 100644
+
29
−
0
View file @
773b5a17
package
org.videolan.tools
import
android.arch.lifecycle.GenericLifecycleObserver
import
android.arch.lifecycle.Lifecycle
import
android.arch.lifecycle.LifecycleOwner
import
kotlinx.coroutines.experimental.CoroutineScope
import
kotlinx.coroutines.experimental.Dispatchers
import
kotlinx.coroutines.experimental.Job
import
kotlinx.coroutines.experimental.android.Main
fun
LifecycleOwner
.
createJob
(
cancelEvent
:
Lifecycle
.
Event
=
Lifecycle
.
Event
.
ON_STOP
):
Job
=
Job
().
also
{
job
->
lifecycle
.
addObserver
(
object
:
GenericLifecycleObserver
{
override
fun
onStateChanged
(
source
:
LifecycleOwner
?,
event
:
Lifecycle
.
Event
)
{
if
(
event
==
cancelEvent
)
{
lifecycle
.
removeObserver
(
this
)
job
.
cancel
()
}
}
})
}
private
val
lifecycleCoroutineScopes
=
mutableMapOf
<
Lifecycle
,
CoroutineScope
>()
val
LifecycleOwner
.
coroutineScope
:
CoroutineScope
get
()
=
lifecycleCoroutineScopes
[
lifecycle
]
?:
createJob
().
let
{
val
newScope
=
CoroutineScope
(
it
+
Dispatchers
.
Main
.
immediate
)
lifecycleCoroutineScopes
[
lifecycle
]
=
newScope
it
.
invokeOnCompletion
{
_
->
lifecycleCoroutineScopes
-=
lifecycle
}
newScope
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment