Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VLC-Android
Manage
Activity
Members
Labels
Plan
Issues
534
Issue boards
Milestones
Wiki
Code
Merge requests
15
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
Merge requests
!155
ViewModels: Delegate medialibrary callbacks
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
ViewModels: Delegate medialibrary callbacks
Dekans/vlc-android:medialibrary_cb_delegation
into
master
Overview
0
Commits
1
Pipelines
0
Changes
11
Merged
Geoffrey Métais
requested to merge
Dekans/vlc-android:medialibrary_cb_delegation
into
master
5 years ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
Make a delegate to remove Medialibrary callbacks management from viewmodels
0
0
Merge request reports
Compare
version 1
version 2
d27714f7
5 years ago
version 1
fdad196f
5 years ago
master (base)
and
version 2
latest version
61408a67
1 commit,
5 years ago
version 2
d27714f7
1 commit,
5 years ago
version 1
fdad196f
1 commit,
5 years ago
Show latest version
1 file
+
2
−
2
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
vlc-android/src/org/videolan/vlc/viewmodels/CallBackDelegate.kt
0 → 100644
+
156
−
0
Options
/*
*****************************************************************************
* CallBackDelegate.kt
*****************************************************************************
* Copyright © 2019 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package
org.videolan.vlc.viewmodels
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.channels.SendChannel
import
org.videolan.medialibrary.interfaces.AbstractMedialibrary
import
org.videolan.tools.conflatedActor
interface
ICallBackHandler
:
AbstractMedialibrary
.
OnMedialibraryReadyListener
,
AbstractMedialibrary
.
OnDeviceChangeListener
,
AbstractMedialibrary
.
MediaCb
,
AbstractMedialibrary
.
ArtistsCb
,
AbstractMedialibrary
.
AlbumsCb
,
AbstractMedialibrary
.
GenresCb
,
AbstractMedialibrary
.
PlaylistsCb
{
val
medialibrary
:
AbstractMedialibrary
fun
CoroutineScope
.
registerCallBacks
(
refresh
:
()
->
Unit
)
fun
releaseCallbacks
()
fun
watchMedia
()
fun
watchArtists
()
fun
watchAlbums
()
fun
watchGenres
()
fun
watchPlaylists
()
override
fun
onMedialibraryReady
()
override
fun
onMedialibraryIdle
()
override
fun
onDeviceChange
()
override
fun
onMediaAdded
()
override
fun
onMediaModified
()
override
fun
onMediaDeleted
()
override
fun
onArtistsAdded
()
override
fun
onArtistsModified
()
override
fun
onArtistsDeleted
()
override
fun
onAlbumsAdded
()
override
fun
onAlbumsModified
()
override
fun
onAlbumsDeleted
()
override
fun
onGenresAdded
()
override
fun
onGenresModified
()
override
fun
onGenresDeleted
()
override
fun
onPlaylistsAdded
()
override
fun
onPlaylistsModified
()
override
fun
onPlaylistsDeleted
()
}
class
CallBackDelegate
:
ICallBackHandler
{
override
val
medialibrary
=
AbstractMedialibrary
.
getInstance
()
private
lateinit
var
refreshActor
:
SendChannel
<
Unit
>
private
var
mediaCb
=
false
private
var
artistsCb
=
false
private
var
albumsCb
=
false
private
var
genresCb
=
false
private
var
playlistsCb
=
false
override
fun
CoroutineScope
.
registerCallBacks
(
refresh
:
()
->
Unit
)
{
refreshActor
=
conflatedActor
{
refresh
()
}
medialibrary
.
addOnMedialibraryReadyListener
(
this
@CallBackDelegate
)
medialibrary
.
addOnDeviceChangeListener
(
this
@CallBackDelegate
)
}
override
fun
watchMedia
()
{
medialibrary
.
addMediaCb
(
this
)
mediaCb
=
true
}
override
fun
watchArtists
()
{
medialibrary
.
addArtistsCb
(
this
)
artistsCb
=
true
}
override
fun
watchAlbums
()
{
medialibrary
.
addAlbumsCb
(
this
)
albumsCb
=
true
}
override
fun
watchGenres
()
{
medialibrary
.
addGenreCb
(
this
)
genresCb
=
true
}
override
fun
watchPlaylists
()
{
medialibrary
.
addPlaylistCb
(
this
)
playlistsCb
=
true
}
override
fun
releaseCallbacks
()
{
medialibrary
.
removeOnMedialibraryReadyListener
(
this
)
medialibrary
.
removeOnDeviceChangeListener
(
this
)
if
(
mediaCb
)
medialibrary
.
removeMediaCb
(
this
)
if
(
artistsCb
)
medialibrary
.
removeArtistsCb
(
this
)
if
(
albumsCb
)
medialibrary
.
removeAlbumsCb
(
this
)
if
(
genresCb
)
medialibrary
.
removeGenreCb
(
this
)
if
(
playlistsCb
)
medialibrary
.
removePlaylistCb
(
this
)
refreshActor
.
close
()
}
override
fun
onMedialibraryReady
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onMedialibraryIdle
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onDeviceChange
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onMediaAdded
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onMediaModified
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onMediaDeleted
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onArtistsAdded
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onArtistsModified
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onArtistsDeleted
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onAlbumsAdded
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onAlbumsModified
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onAlbumsDeleted
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onGenresAdded
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onGenresModified
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onGenresDeleted
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onPlaylistsAdded
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onPlaylistsModified
()
{
refreshActor
.
offer
(
Unit
)
}
override
fun
onPlaylistsDeleted
()
{
refreshActor
.
offer
(
Unit
)
}
}
Loading