diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/activity/SelectAlbumActivity.java b/ultrasonic/src/main/java/org/moire/ultrasonic/activity/SelectAlbumActivity.java
index 0958aabe..d975160e 100644
--- a/ultrasonic/src/main/java/org/moire/ultrasonic/activity/SelectAlbumActivity.java
+++ b/ultrasonic/src/main/java/org/moire/ultrasonic/activity/SelectAlbumActivity.java
@@ -35,6 +35,7 @@ import android.widget.TextView;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
+
import org.moire.ultrasonic.R;
import org.moire.ultrasonic.domain.MusicDirectory;
import org.moire.ultrasonic.domain.Share;
@@ -594,7 +595,7 @@ public class SelectAlbumActivity extends SubsonicTabActivity
{
MusicDirectory.Entry allSongs = new MusicDirectory.Entry();
- allSongs.setIsDirectory(true);
+ allSongs.setDirectory(true);
allSongs.setArtist(name);
allSongs.setParent(id);
allSongs.setId(allSongsId);
@@ -663,7 +664,7 @@ public class SelectAlbumActivity extends SubsonicTabActivity
{
MusicDirectory.Entry allSongs = new MusicDirectory.Entry();
- allSongs.setIsDirectory(true);
+ allSongs.setDirectory(true);
allSongs.setArtist(name);
allSongs.setParent(id);
allSongs.setId(allSongsId);
diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/domain/MusicDirectory.java b/ultrasonic/src/main/java/org/moire/ultrasonic/domain/MusicDirectory.java
deleted file mode 100644
index e0a72f6a..00000000
--- a/ultrasonic/src/main/java/org/moire/ultrasonic/domain/MusicDirectory.java
+++ /dev/null
@@ -1,474 +0,0 @@
-/*
- This file is part of Subsonic.
-
- Subsonic 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 3 of the License, or
- (at your option) any later version.
-
- Subsonic 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 Subsonic. If not, see .
-
- Copyright 2009 (C) Sindre Mehus
- */
-package org.moire.ultrasonic.domain;
-
-import android.support.annotation.NonNull;
-
-import java.io.Serializable;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-
-/**
- * @author Sindre Mehus
- */
-public class MusicDirectory
-{
-
- private String name;
- private final List children = new ArrayList();
-
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- public void addAll(Collection entries)
- {
- children.addAll(entries);
- }
-
- public void addFirst(Entry child)
- {
- children.add(0, child);
- }
-
- public void addChild(Entry child)
- {
- children.add(child);
- }
-
- public List getChildren()
- {
- return getChildren(true, true);
- }
-
- public Entry findChild(String id)
- {
- Entry entry = null;
-
- for (Entry song : getChildren())
- {
- if (song.getId().equals(id))
- {
- entry = song;
- }
- }
-
- return entry;
- }
-
- public List getChildren(boolean includeDirs, boolean includeFiles)
- {
- if (includeDirs && includeFiles)
- {
- return children;
- }
-
- List result = new ArrayList(children.size());
- for (Entry child : children)
- {
- if (child.isDirectory() && includeDirs || !child.isDirectory() && includeFiles)
- {
- result.add(child);
- }
- }
- return result;
- }
-
- public static class Entry implements Serializable
- {
- /**
- *
- */
- private static final long serialVersionUID = -3339106650010798108L;
- /**
- *
- */
- private String id;
- private String parent;
- private boolean isDirectory;
- private String title;
- private String album;
- private String albumId;
- private String artist;
- private String artistId;
- private Integer track;
- private Integer year;
- private String genre;
- private String contentType;
- private String suffix;
- private String transcodedContentType;
- private String transcodedSuffix;
- private String coverArt;
- private Long size;
- private Long songCount;
- private Integer duration;
- private Integer bitRate;
- private String path;
- private boolean isVideo;
- private boolean isStarred;
- private Integer discNumber;
- private String type;
- private Date created;
- private int closeness;
- private int bookmarkPosition;
-
- public Integer getDiscNumber()
- {
- return discNumber;
- }
-
- public void setDiscNumber(Integer discNumber)
- {
- this.discNumber = discNumber;
- }
-
- public boolean getStarred()
- {
- return isStarred;
- }
-
- public void setStarred(boolean starred)
- {
- this.isStarred = starred;
- }
-
- public String getId()
- {
- return id;
- }
-
- public void setId(String id)
- {
- this.id = id;
- }
-
- public String getParent()
- {
- return parent;
- }
-
- public void setParent(String parent)
- {
- this.parent = parent;
- }
-
- public boolean isDirectory()
- {
- return isDirectory;
- }
-
- public void setIsDirectory(boolean directory)
- {
- this.isDirectory = directory;
- }
-
- public String getTitle()
- {
- return title;
- }
-
- public void setTitle(String title)
- {
- this.title = title;
- }
-
- public String getAlbum()
- {
- return album;
- }
-
- public void setAlbum(String album)
- {
- this.album = album;
- }
-
- public String getAlbumId()
- {
- return albumId;
- }
-
- public void setAlbumId(String albumId)
- {
- this.albumId = albumId;
- }
-
- public String getArtist()
- {
- return artist;
- }
-
- public void setArtist(String artist)
- {
- this.artist = artist;
- }
-
- public String getArtistId()
- {
- return artistId;
- }
-
- public void setArtistId(String artistId)
- {
- this.artistId = artistId;
- }
-
- public Integer getTrack()
- {
- return track == null ? 0 : track;
- }
-
- public void setTrack(Integer track)
- {
- this.track = track;
- }
-
- public Long getSongCount()
- {
- return songCount;
- }
-
- public void setSongCount(Long songCount)
- {
- this.songCount = songCount;
- }
-
- public Integer getYear()
- {
- return year == null ? 0 : year;
- }
-
- public void setYear(Integer year)
- {
- this.year = year;
- }
-
- public String getGenre()
- {
- return genre;
- }
-
- public void setGenre(String genre)
- {
- this.genre = genre;
- }
-
- public String getContentType()
- {
- return contentType;
- }
-
- public void setContentType(String contentType)
- {
- this.contentType = contentType;
- }
-
- public String getSuffix()
- {
- return suffix;
- }
-
- public void setSuffix(String suffix)
- {
- this.suffix = suffix;
- }
-
- public String getTranscodedContentType()
- {
- return transcodedContentType;
- }
-
- public void setTranscodedContentType(String transcodedContentType)
- {
- this.transcodedContentType = transcodedContentType;
- }
-
- public String getTranscodedSuffix()
- {
- return transcodedSuffix;
- }
-
- public void setTranscodedSuffix(String transcodedSuffix)
- {
- this.transcodedSuffix = transcodedSuffix;
- }
-
- public Long getSize()
- {
- return size;
- }
-
- public void setSize(Long size)
- {
- this.size = size;
- }
-
- public Integer getDuration()
- {
- return duration;
- }
-
- public void setDuration(Integer duration)
- {
- this.duration = duration;
- }
-
- public void setDuration(long duration)
- {
- this.duration = (int) duration;
- }
-
- public Integer getBitRate()
- {
- return bitRate;
- }
-
- public void setBitRate(Integer bitRate)
- {
- this.bitRate = bitRate;
- }
-
- @NonNull
- public String getCoverArt()
- {
- return coverArt;
- }
-
- public void setCoverArt(String coverArt)
- {
- this.coverArt = coverArt;
- }
-
- public String getPath()
- {
- return path;
- }
-
- public void setPath(String path)
- {
- this.path = path;
- }
-
- public boolean isVideo()
- {
- return isVideo;
- }
-
- public void setIsVideo(boolean video)
- {
- this.isVideo = video;
- }
-
- public String getType()
- {
- return type;
- }
-
- public void setType(String type)
- {
- this.type = type;
- }
-
- public Date getCreated()
- {
- return created;
- }
-
- public void setCreated(String created)
- {
- if (created != null)
- {
- try
- {
- this.created = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH).parse(created);
- }
- catch (ParseException e)
- {
- this.created = null;
- }
- }
- else
- {
- this.created = null;
- }
- }
-
- public void setCreated(Date created) {
- this.created = created;
- }
-
- public int getCloseness()
- {
- return closeness;
- }
-
- public void setCloseness(int closeness)
- {
- this.closeness = closeness;
- }
-
- public int getBookmarkPosition()
- {
- return bookmarkPosition;
- }
-
- public void setBookmarkPosition(int bookmarkPosition)
- {
- this.bookmarkPosition = bookmarkPosition;
- }
-
- @Override
- public boolean equals(Object o)
- {
- if (this == o)
- {
- return true;
- }
- if (o == null || getClass() != o.getClass())
- {
- return false;
- }
-
- Entry entry = (Entry) o;
- return id.equals(entry.id);
- }
-
- @Override
- public int hashCode()
- {
- return id.hashCode();
- }
-
- @Override
- public String toString()
- {
- return title;
- }
- }
-}
\ No newline at end of file
diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/service/OfflineMusicService.java b/ultrasonic/src/main/java/org/moire/ultrasonic/service/OfflineMusicService.java
index d3be03cc..b3dac806 100644
--- a/ultrasonic/src/main/java/org/moire/ultrasonic/service/OfflineMusicService.java
+++ b/ultrasonic/src/main/java/org/moire/ultrasonic/service/OfflineMusicService.java
@@ -185,7 +185,7 @@ public class OfflineMusicService extends RESTMusicService
private static MusicDirectory.Entry createEntry(Context context, File file, String name)
{
MusicDirectory.Entry entry = new MusicDirectory.Entry();
- entry.setIsDirectory(file.isDirectory());
+ entry.setDirectory(file.isDirectory());
entry.setId(file.getPath());
entry.setParent(file.getParent());
entry.setSize(file.length());
@@ -232,7 +232,7 @@ public class OfflineMusicService extends RESTMusicService
entry.setTitle(title);
}
- entry.setIsVideo(hasVideo != null);
+ entry.setVideo(hasVideo != null);
Log.i("OfflineMusicService", String.format("Offline Stuff: %s", track));
diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIAlbumConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIAlbumConverter.kt
index f5f6c4ac..efcebe2e 100644
--- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIAlbumConverter.kt
+++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIAlbumConverter.kt
@@ -5,19 +5,19 @@ package org.moire.ultrasonic.domain
import org.moire.ultrasonic.api.subsonic.models.Album
-fun Album.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.Entry().apply {
- id = this@toDomainEntity.id
- setIsDirectory(true)
- title = this@toDomainEntity.name
- coverArt = this@toDomainEntity.coverArt
- artist = this@toDomainEntity.artist
- artistId = this@toDomainEntity.artistId
- songCount = this@toDomainEntity.songCount.toLong()
- duration = this@toDomainEntity.duration
- created = this@toDomainEntity.created?.time
- year = this@toDomainEntity.year
+fun Album.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.Entry(
+ id = this@toDomainEntity.id,
+ isDirectory = true,
+ title = this@toDomainEntity.name,
+ coverArt = this@toDomainEntity.coverArt,
+ artist = this@toDomainEntity.artist,
+ artistId = this@toDomainEntity.artistId,
+ songCount = this@toDomainEntity.songCount.toLong(),
+ duration = this@toDomainEntity.duration,
+ created = this@toDomainEntity.created?.time,
+ year = this@toDomainEntity.year,
genre = this@toDomainEntity.genre
-}
+)
fun Album.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply {
addAll(this@toMusicDirectoryDomainEntity.songList.map { it.toDomainEntity() })
diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIMusicDirectoryConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIMusicDirectoryConverter.kt
index f20c8c02..e1acb18c 100644
--- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIMusicDirectoryConverter.kt
+++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIMusicDirectoryConverter.kt
@@ -16,7 +16,7 @@ internal val dateFormat: DateFormat by lazy {
fun MusicDirectoryChild.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.Entry().apply {
id = this@toDomainEntity.id
parent = this@toDomainEntity.parent
- setIsDirectory(this@toDomainEntity.isDir)
+ isDirectory = this@toDomainEntity.isDir
title = this@toDomainEntity.title
album = this@toDomainEntity.album
albumId = this@toDomainEntity.albumId
@@ -34,7 +34,7 @@ fun MusicDirectoryChild.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.
duration = this@toDomainEntity.duration
bitRate = this@toDomainEntity.bitRate
path = this@toDomainEntity.path
- setIsVideo(this@toDomainEntity.isVideo)
+ isVideo = this@toDomainEntity.isVideo
created = this@toDomainEntity.created?.time
starred = this@toDomainEntity.starred != null
discNumber = this@toDomainEntity.discNumber
diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/MusicDirectory.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/MusicDirectory.kt
new file mode 100644
index 00000000..df5a00e5
--- /dev/null
+++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/MusicDirectory.kt
@@ -0,0 +1,73 @@
+package org.moire.ultrasonic.domain
+
+import java.io.Serializable
+import java.util.Date
+
+class MusicDirectory {
+ var name: String? = null
+ private val children = mutableListOf()
+
+ fun addAll(entries: Collection) {
+ children.addAll(entries)
+ }
+
+ fun addFirst(child: Entry) {
+ children.add(0, child)
+ }
+
+ fun addChild(child: Entry) {
+ children.add(child)
+ }
+
+ fun findChild(id: String): Entry? = children.lastOrNull { it.id == id }
+
+ @JvmOverloads
+ fun getChildren(
+ includeDirs: Boolean = true,
+ includeFiles: Boolean = true): List {
+ if (includeDirs && includeFiles) {
+ return children
+ }
+
+ return children.filter { it.isDirectory && includeDirs || !it.isDirectory && includeFiles }
+ }
+
+ data class Entry(
+ var id: String? = null,
+ var parent: String? = null,
+ var isDirectory: Boolean = false,
+ var title: String? = null,
+ var album: String? = null,
+ var albumId: String? = null,
+ var artist: String? = null,
+ var artistId: String? = null,
+ var track: Int? = 0,
+ var year: Int? = 0,
+ var genre: String? = null,
+ var contentType: String? = null,
+ var suffix: String? = null,
+ var transcodedContentType: String? = null,
+ var transcodedSuffix: String? = null,
+ var coverArt: String? = null,
+ var size: Long? = null,
+ var songCount: Long? = null,
+ var duration: Int? = null,
+ var bitRate: Int? = null,
+ var path: String? = null,
+ var isVideo: Boolean = false,
+ var starred: Boolean = false,
+ var discNumber: Int? = null,
+ var type: String? = null,
+ var created: Date? = null,
+ var closeness: Int = 0,
+ var bookmarkPosition: Int = 0
+ ) : Serializable {
+ fun setDuration(duration: Long) {
+ this.duration = duration.toInt()
+ }
+
+ companion object {
+ private const val serialVersionUID = -3339106650010798108L
+ }
+ }
+}
diff --git a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIAlbumConverterTest.kt b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIAlbumConverterTest.kt
index 6d027b95..64adb575 100644
--- a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIAlbumConverterTest.kt
+++ b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIAlbumConverterTest.kt
@@ -22,17 +22,17 @@ class APIAlbumConverterTest {
val convertedEntity = entity.toDomainEntity()
with(convertedEntity) {
- id `should equal to` entity.id
- title `should equal to` entity.name
- isDirectory `should equal to` true
- coverArt `should equal to` entity.coverArt
- artist `should equal to` entity.artist
- artistId `should equal to` entity.artistId
- songCount `should equal to` entity.songCount.toLong()
- duration `should equal to` entity.duration
+ id `should equal` entity.id
+ title `should equal` entity.name
+ isDirectory `should equal` true
+ coverArt `should equal` entity.coverArt
+ artist `should equal` entity.artist
+ artistId `should equal` entity.artistId
+ songCount `should equal` entity.songCount.toLong()
+ duration `should equal` entity.duration
created `should equal` entity.created?.time
- year `should equal to` entity.year
- genre `should equal to` entity.genre
+ year `should equal` entity.year
+ genre `should equal` entity.genre
}
}
@@ -47,8 +47,8 @@ class APIAlbumConverterTest {
with(convertedEntity) {
name `should equal` null
- children.size `should equal to` entity.songList.size
- children[0] `should equal` entity.songList[0].toDomainEntity()
+ getChildren().size `should equal to` entity.songList.size
+ getChildren()[0] `should equal` entity.songList[0].toDomainEntity()
}
}