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
13
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
4944e7e1
Commit
4944e7e1
authored
5 years ago
by
Geoffrey Métais
Browse files
Options
Downloads
Patches
Plain Diff
ModelsHelper: cosmetic changes
parent
0468fea1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#9581
passed with stage
in 28 minutes and 3 seconds
Changes
1
Pipelines
5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
+32
-33
32 additions, 33 deletions
vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
with
32 additions
and
33 deletions
vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
+
32
−
33
View file @
4944e7e1
...
...
@@ -43,7 +43,7 @@ object ModelsHelper {
for
(
item
in
items
)
{
if
(
item
.
itemType
==
MediaLibraryItem
.
TYPE_DUMMY
)
continue
val
title
=
item
.
title
val
letter
=
if
(
title
.
isEmpty
()
||
!
Character
.
isLetter
(
title
[
0
])
||
ModelsHelper
.
isSpecialItem
(
item
))
"#"
else
title
.
substring
(
0
,
1
).
toUpperCase
()
val
letter
=
if
(
title
.
isEmpty
()
||
!
Character
.
isLetter
(
title
[
0
])
||
item
.
isSpecialItem
())
"#"
else
title
.
substring
(
0
,
1
).
toUpperCase
()
if
(
currentLetter
===
null
||
!
TextUtils
.
equals
(
currentLetter
,
letter
))
{
currentLetter
=
letter
if
(
array
[
letter
].
isNullOrEmpty
())
array
[
letter
]
=
mutableListOf
()
...
...
@@ -55,8 +55,7 @@ object ModelsHelper {
var
currentLengthCategory
:
String
?
=
null
for
(
item
in
items
)
{
if
(
item
.
itemType
==
MediaLibraryItem
.
TYPE_DUMMY
)
continue
val
length
=
ModelsHelper
.
getLength
(
item
)
val
lengthCategory
=
ModelsHelper
.
lengthToCategory
(
length
)
val
lengthCategory
=
item
.
getLength
().
lengthToCategory
()
if
(
currentLengthCategory
==
null
||
!
TextUtils
.
equals
(
currentLengthCategory
,
lengthCategory
))
{
currentLengthCategory
=
lengthCategory
if
(
array
[
currentLengthCategory
].
isNullOrEmpty
())
array
[
currentLengthCategory
]
=
mutableListOf
()
...
...
@@ -68,7 +67,7 @@ object ModelsHelper {
var
currentYear
:
String
?
=
null
for
(
item
in
items
)
{
if
(
item
.
itemType
==
MediaLibraryItem
.
TYPE_DUMMY
)
continue
val
year
=
ModelsHelper
.
getYear
(
item
)
val
year
=
item
.
getYear
()
if
(
currentYear
===
null
||
!
TextUtils
.
equals
(
currentYear
,
year
))
{
currentYear
=
year
if
(
array
[
currentYear
].
isNullOrEmpty
())
array
[
currentYear
]
=
mutableListOf
()
...
...
@@ -106,35 +105,35 @@ object ModelsHelper {
else
array
}
fun
getFirstLetter
(
item
:
MediaLibraryItem
):
String
{
return
if
(
item
.
title
.
isEmpty
()
||
!
Character
.
isLetter
(
item
.
title
[
0
])
||
isSpecialItem
(
item
))
"#"
else
item
.
title
.
substring
(
0
,
1
).
toUpperCase
()
fun
MediaLibraryItem
.
getFirstLetter
(
):
String
{
return
if
(
title
.
isEmpty
()
||
!
Character
.
isLetter
(
title
[
0
])
||
isSpecialItem
())
"#"
else
title
.
substring
(
0
,
1
).
toUpperCase
()
}
fun
getHeader
(
context
:
Context
?,
sort
:
Int
,
item
:
MediaLibraryItem
?,
aboveItem
:
MediaLibraryItem
?)
=
if
(
context
!==
null
&&
item
!=
null
)
when
(
sort
)
{
SORT_DEFAULT
,
SORT_FILENAME
,
SORT_ALPHA
->
{
val
letter
=
if
(
item
.
title
.
isEmpty
()
||
!
Character
.
isLetter
(
item
.
title
[
0
])
||
ModelsHelper
.
isSpecialItem
(
item
))
"#"
else
item
.
title
.
substring
(
0
,
1
).
toUpperCase
()
val
letter
=
if
(
item
.
title
.
isEmpty
()
||
!
Character
.
isLetter
(
item
.
title
[
0
])
||
item
.
isSpecialItem
())
"#"
else
item
.
title
.
substring
(
0
,
1
).
toUpperCase
()
if
(
aboveItem
==
null
)
letter
else
{
val
previous
=
if
(
aboveItem
.
title
.
isEmpty
()
||
!
Character
.
isLetter
(
aboveItem
.
title
[
0
])
||
ModelsHelper
.
isSpecialItem
(
aboveItem
))
"#"
else
aboveItem
.
title
.
substring
(
0
,
1
).
toUpperCase
()
val
previous
=
if
(
aboveItem
.
title
.
isEmpty
()
||
!
Character
.
isLetter
(
aboveItem
.
title
[
0
])
||
aboveItem
.
isSpecialItem
())
"#"
else
aboveItem
.
title
.
substring
(
0
,
1
).
toUpperCase
()
letter
.
takeIf
{
it
!=
previous
}
}
}
SORT_DURATION
->
{
val
length
=
getLength
(
item
)
val
lengthCategory
=
lengthToCategory
(
length
)
val
length
=
item
.
getLength
()
val
lengthCategory
=
length
.
toLong
().
lengthToCategory
()
if
(
aboveItem
==
null
)
lengthCategory
else
{
val
previous
=
lengthToCategory
(
getLength
(
aboveItem
)
)
val
previous
=
aboveItem
.
getLength
().
lengthToCategory
(
)
lengthCategory
.
takeIf
{
it
!=
previous
}
}
}
SORT_RELEASEDATE
->
{
val
year
=
getYear
(
item
)
val
year
=
item
.
getYear
()
if
(
aboveItem
==
null
)
year
else
{
val
previous
=
getYear
(
aboveItem
)
val
previous
=
aboveItem
.
getYear
(
)
year
.
takeIf
{
it
!=
previous
}
}
}
...
...
@@ -185,42 +184,42 @@ object ModelsHelper {
else
->
context
.
getString
(
R
.
string
.
time_category_older
)
}
private
fun
isSpecialItem
(
item
:
MediaLibraryItem
)
=
item
.
itemType
==
MediaLibraryItem
.
TYPE_ARTIST
&&
(
item
.
id
==
1L
||
item
.
id
==
2L
)
||
item
.
itemType
==
MediaLibraryItem
.
TYPE_ALBUM
&&
item
.
title
==
AbstractAlbum
.
SpecialRes
.
UNKNOWN_ALBUM
private
fun
MediaLibraryItem
.
isSpecialItem
()
=
itemType
==
MediaLibraryItem
.
TYPE_ARTIST
&&
(
id
==
1L
||
id
==
2L
)
||
itemType
==
MediaLibraryItem
.
TYPE_ALBUM
&&
title
==
AbstractAlbum
.
SpecialRes
.
UNKNOWN_ALBUM
private
fun
getLength
(
media
:
MediaLibraryItem
)
=
when
{
media
.
itemType
==
MediaLibraryItem
.
TYPE_ALBUM
->
(
media
as
AbstractAlbum
).
duration
media
.
itemType
==
MediaLibraryItem
.
TYPE_MEDIA
->
(
media
as
AbstractMediaWrapper
).
length
private
fun
MediaLibraryItem
.
getLength
(
)
=
when
{
itemType
==
MediaLibraryItem
.
TYPE_ALBUM
->
(
this
as
AbstractAlbum
).
duration
itemType
==
MediaLibraryItem
.
TYPE_MEDIA
->
(
this
as
AbstractMediaWrapper
).
length
else
->
0L
}
private
fun
lengthToCategory
(
length
:
Long
):
String
{
private
fun
Long
.
lengthToCategory
():
String
{
val
value
:
Int
if
(
leng
th
==
0L
)
return
"-"
if
(
leng
th
<
60000
)
return
"< 1 min"
if
(
leng
th
<
600000
)
{
value
=
floor
((
leng
th
/
60000
).
toDouble
()).
toInt
()
if
(
th
is
==
0L
)
return
"-"
if
(
th
is
<
60000
)
return
"< 1 min"
if
(
th
is
<
600000
)
{
value
=
floor
((
th
is
/
60000
).
toDouble
()).
toInt
()
return
"$value - ${(value + 1)} min"
}
return
if
(
leng
th
<
3600000
)
{
value
=
(
10
*
floor
((
leng
th
/
600000
).
toDouble
())).
toInt
()
return
if
(
th
is
<
3600000
)
{
value
=
(
10
*
floor
((
th
is
/
600000
).
toDouble
())).
toInt
()
"$value - ${(value + 10)} min"
}
else
{
value
=
floor
((
leng
th
/
3600000
).
toDouble
()).
toInt
()
value
=
floor
((
th
is
/
3600000
).
toDouble
()).
toInt
()
"$value - ${(value + 1)} h"
}
}
private
fun
getYear
(
media
:
MediaLibraryItem
)
=
when
(
media
.
itemType
)
{
MediaLibraryItem
.
TYPE_ALBUM
->
if
((
media
as
AbstractAlbum
).
releaseYear
==
0
)
"-"
else
media
.
releaseYear
.
toString
()
MediaLibraryItem
.
TYPE_MEDIA
->
if
((
media
as
AbstractMediaWrapper
).
date
==
null
)
"-"
else
media
.
date
private
fun
MediaLibraryItem
.
getYear
(
)
=
when
(
itemType
)
{
MediaLibraryItem
.
TYPE_ALBUM
->
if
((
this
as
AbstractAlbum
).
releaseYear
==
0
)
"-"
else
releaseYear
.
toString
()
MediaLibraryItem
.
TYPE_MEDIA
->
if
((
this
as
AbstractMediaWrapper
).
date
==
null
)
"-"
else
date
else
->
"-"
}
fun
getTracksCount
(
media
:
MediaLibraryItem
)
=
when
(
media
.
itemType
)
{
MediaLibraryItem
.
TYPE_ALBUM
->
(
media
as
AbstractAlbum
).
tracksCount
MediaLibraryItem
.
TYPE_PLAYLIST
->
(
media
as
AbstractPlaylist
).
tracksCount
fun
MediaLibraryItem
.
getTracksCount
(
)
=
when
(
itemType
)
{
MediaLibraryItem
.
TYPE_ALBUM
->
(
this
as
AbstractAlbum
).
tracksCount
MediaLibraryItem
.
TYPE_PLAYLIST
->
(
this
as
AbstractPlaylist
).
tracksCount
else
->
0
}
}
...
...
This diff is collapsed.
Click to expand it.
Geoffrey Métais
@Dekans
mentioned in commit
12b49ba0
·
5 years ago
mentioned in commit
12b49ba0
mentioned in commit 12b49ba09d11ed96879a515fdcd72582f8f841f0
Toggle commit list
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