Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
480bb50b
authored
Dec 08, 2018
by
eguven
Committed by
Andrew Lewis
Dec 10, 2018
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add DownloadActionUtil class
PiperOrigin-RevId: 224647076
parent
22948f2e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
0 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadActionUtil.java
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadActionUtilTest.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadActionUtil.java
0 → 100644
View file @
480bb50b
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer2
.
offline
;
import
com.google.android.exoplayer2.util.Assertions
;
import
java.util.ArrayDeque
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
/** {@link DownloadAction} related utility methods. */
public
class
DownloadActionUtil
{
private
DownloadActionUtil
()
{}
/**
* Merge {@link DownloadAction}s in {@code actionQueue} to minimum number of actions.
*
* <p>All actions must have the same type and must be for the same media.
*
* @param actionQueue Queue of actions. Must not be empty.
* @return The first action in the queue.
*/
public
static
DownloadAction
mergeActions
(
ArrayDeque
<
DownloadAction
>
actionQueue
)
{
DownloadAction
removeAction
=
null
;
DownloadAction
downloadAction
=
null
;
HashSet
<
StreamKey
>
keys
=
new
HashSet
<>();
boolean
downloadAllTracks
=
false
;
DownloadAction
firstAction
=
Assertions
.
checkNotNull
(
actionQueue
.
peek
());
while
(!
actionQueue
.
isEmpty
())
{
DownloadAction
action
=
actionQueue
.
remove
();
Assertions
.
checkState
(
action
.
type
.
equals
(
firstAction
.
type
));
Assertions
.
checkState
(
action
.
isSameMedia
(
firstAction
));
if
(
action
.
isRemoveAction
)
{
removeAction
=
action
;
downloadAction
=
null
;
keys
.
clear
();
downloadAllTracks
=
false
;
}
else
{
if
(!
downloadAllTracks
)
{
if
(
action
.
keys
.
isEmpty
())
{
downloadAllTracks
=
true
;
keys
.
clear
();
}
else
{
keys
.
addAll
(
action
.
keys
);
}
}
downloadAction
=
action
;
}
}
if
(
removeAction
!=
null
)
{
actionQueue
.
add
(
removeAction
);
}
if
(
downloadAction
!=
null
)
{
actionQueue
.
add
(
DownloadAction
.
createDownloadAction
(
downloadAction
.
type
,
downloadAction
.
uri
,
new
ArrayList
<>(
keys
),
downloadAction
.
customCacheKey
,
downloadAction
.
data
));
}
return
Assertions
.
checkNotNull
(
actionQueue
.
peek
());
}
}
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadActionUtilTest.java
0 → 100644
View file @
480bb50b
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment