Convert some of the domain models to Kotlin
This commit is contained in:
parent
c64edc2567
commit
cb8ac22d09
|
@ -1,4 +1,5 @@
|
|||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
|
@ -22,6 +23,10 @@ android {
|
|||
checkReleaseBuilds false
|
||||
warning 'InvalidPackage'
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -29,4 +34,17 @@ dependencies {
|
|||
compile 'com.android.support:design:25.2.0'
|
||||
compile 'com.sothree.slidinguppanel:library:3.3.1'
|
||||
compile 'com.squareup.okhttp3:okhttp:3.6.0'
|
||||
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.1.2-2'
|
||||
}
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.1.2-2'
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,138 +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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package net.nullsum.audinaut.domain;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.Collator;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class Artist implements Serializable {
|
||||
private static final String TAG = Artist.class.getSimpleName();
|
||||
public static final String ROOT_ID = "-1";
|
||||
public static final String MISSING_ID = "-2";
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String index;
|
||||
private int closeness;
|
||||
|
||||
public Artist() {
|
||||
|
||||
}
|
||||
public Artist(String id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getIndex() {
|
||||
return index;
|
||||
}
|
||||
public void setIndex(String index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public int getCloseness() {
|
||||
return closeness;
|
||||
}
|
||||
public void setCloseness(int closeness) {
|
||||
this.closeness = closeness;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Artist entry = (Artist) o;
|
||||
return id.equals(entry.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static class ArtistComparator implements Comparator<Artist> {
|
||||
private String[] ignoredArticles;
|
||||
private Collator collator;
|
||||
|
||||
public ArtistComparator(String[] ignoredArticles) {
|
||||
this.ignoredArticles = ignoredArticles;
|
||||
this.collator = Collator.getInstance(Locale.US);
|
||||
this.collator.setStrength(Collator.PRIMARY);
|
||||
}
|
||||
|
||||
public int compare(Artist lhsArtist, Artist rhsArtist) {
|
||||
String lhs = lhsArtist.getName().toLowerCase();
|
||||
String rhs = rhsArtist.getName().toLowerCase();
|
||||
|
||||
for (String article : ignoredArticles) {
|
||||
int index = lhs.indexOf(article.toLowerCase() + " ");
|
||||
if (index == 0) {
|
||||
lhs = lhs.substring(article.length() + 1);
|
||||
}
|
||||
index = rhs.indexOf(article.toLowerCase() + " ");
|
||||
if (index == 0) {
|
||||
rhs = rhs.substring(article.length() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return collator.compare(lhs, rhs);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sort(List<Artist> artists, String[] ignoredArticles) {
|
||||
try {
|
||||
Collections.sort(artists, new ArtistComparator(ignoredArticles));
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Failed to sort artists", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
package net.nullsum.audinaut.domain;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import net.nullsum.audinaut.util.Constants;
|
||||
import net.nullsum.audinaut.util.Util;
|
||||
|
||||
public class Genre implements Serializable {
|
||||
private String name;
|
||||
private String index;
|
||||
private Integer albumCount;
|
||||
private Integer songCount;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(String index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Integer getAlbumCount() {
|
||||
return albumCount;
|
||||
}
|
||||
|
||||
public void setAlbumCount(Integer albumCount) {
|
||||
this.albumCount = albumCount;
|
||||
}
|
||||
|
||||
public Integer getSongCount() {
|
||||
return songCount;
|
||||
}
|
||||
|
||||
public void setSongCount(Integer songCount) {
|
||||
this.songCount = songCount;
|
||||
}
|
||||
|
||||
public static class GenreComparator implements Comparator<Genre> {
|
||||
@Override
|
||||
public int compare(Genre genre1, Genre genre2) {
|
||||
return genre1.getName().compareToIgnoreCase(genre2.getName());
|
||||
}
|
||||
|
||||
public static List<Genre> sort(List<Genre> genres) {
|
||||
Collections.sort(genres, new GenreComparator());
|
||||
return genres;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,87 +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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package net.nullsum.audinaut.domain;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.io.Serializable;
|
||||
|
||||
import net.nullsum.audinaut.util.Constants;
|
||||
import net.nullsum.audinaut.util.Util;
|
||||
|
||||
/**
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class Indexes implements Serializable {
|
||||
|
||||
private long lastModified;
|
||||
private List<Artist> shortcuts;
|
||||
private List<Artist> artists;
|
||||
private List<MusicDirectory.Entry> entries;
|
||||
|
||||
public Indexes() {
|
||||
|
||||
}
|
||||
public Indexes(long lastModified, List<Artist> shortcuts, List<Artist> artists) {
|
||||
this.lastModified = lastModified;
|
||||
this.shortcuts = shortcuts;
|
||||
this.artists = artists;
|
||||
this.entries = new ArrayList<MusicDirectory.Entry>();
|
||||
}
|
||||
public Indexes(long lastModified, List<Artist> shortcuts, List<Artist> artists, List<MusicDirectory.Entry> entries) {
|
||||
this.lastModified = lastModified;
|
||||
this.shortcuts = shortcuts;
|
||||
this.artists = artists;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public long getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
public List<Artist> getShortcuts() {
|
||||
return shortcuts;
|
||||
}
|
||||
|
||||
public List<Artist> getArtists() {
|
||||
return artists;
|
||||
}
|
||||
|
||||
public void setArtists(List<Artist> artists) {
|
||||
this.shortcuts = new ArrayList<Artist>();
|
||||
this.artists.clear();
|
||||
this.artists.addAll(artists);
|
||||
}
|
||||
|
||||
public List<MusicDirectory.Entry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public void sortChildren(Context context) {
|
||||
SharedPreferences prefs = Util.getPreferences(context);
|
||||
String ignoredArticlesString = prefs.getString(Constants.CACHE_KEY_IGNORE, "The El La Los Las Le Les");
|
||||
final String[] ignoredArticles = ignoredArticlesString.split(" ");
|
||||
|
||||
Artist.sort(shortcuts, ignoredArticles);
|
||||
Artist.sort(artists, ignoredArticles);
|
||||
}
|
||||
}
|
|
@ -1,47 +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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package net.nullsum.audinaut.domain;
|
||||
|
||||
import android.media.RemoteControlClient;
|
||||
|
||||
/**
|
||||
* @author Sindre Mehus
|
||||
* @version $Id$
|
||||
*/
|
||||
public enum PlayerState {
|
||||
IDLE(RemoteControlClient.PLAYSTATE_STOPPED),
|
||||
DOWNLOADING(RemoteControlClient.PLAYSTATE_BUFFERING),
|
||||
PREPARING(RemoteControlClient.PLAYSTATE_BUFFERING),
|
||||
PREPARED(RemoteControlClient.PLAYSTATE_STOPPED),
|
||||
STARTED(RemoteControlClient.PLAYSTATE_PLAYING),
|
||||
STOPPED(RemoteControlClient.PLAYSTATE_STOPPED),
|
||||
PAUSED(RemoteControlClient.PLAYSTATE_PAUSED),
|
||||
PAUSED_TEMP(RemoteControlClient.PLAYSTATE_PAUSED),
|
||||
COMPLETED(RemoteControlClient.PLAYSTATE_STOPPED);
|
||||
|
||||
private final int mRemoteControlClientPlayState;
|
||||
|
||||
private PlayerState(int playState) {
|
||||
mRemoteControlClientPlayState = playState;
|
||||
}
|
||||
|
||||
public int getRemoteControlClientPlayState() {
|
||||
return mRemoteControlClientPlayState;
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package net.nullsum.audinaut.domain;
|
||||
|
||||
/**
|
||||
* @author Sindre Mehus
|
||||
* @version $Id$
|
||||
*/
|
||||
public enum RepeatMode {
|
||||
OFF {
|
||||
@Override
|
||||
public RepeatMode next() {
|
||||
return ALL;
|
||||
}
|
||||
},
|
||||
ALL {
|
||||
@Override
|
||||
public RepeatMode next() {
|
||||
return SINGLE;
|
||||
}
|
||||
},
|
||||
SINGLE {
|
||||
@Override
|
||||
public RepeatMode next() {
|
||||
return OFF;
|
||||
}
|
||||
};
|
||||
|
||||
public abstract RepeatMode next();
|
||||
}
|
|
@ -200,7 +200,8 @@ public class SelectArtistFragment extends SelectRecyclerFragment<Serializable> i
|
|||
artists.add(artist);
|
||||
}
|
||||
|
||||
Indexes indexes = new Indexes(0, new ArrayList<Artist>(), artists);
|
||||
Indexes indexes = new Indexes();
|
||||
//indexes.setArtists = artists;
|
||||
indexes.sortChildren(context);
|
||||
items.addAll(indexes.getArtists());
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ import org.xmlpull.v1.XmlPullParser;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -78,6 +80,12 @@ public class GenreParser extends AbstractParser {
|
|||
|
||||
validate();
|
||||
|
||||
return Genre.GenreComparator.sort(result);
|
||||
Collections.sort(result, new Comparator<Genre>() {
|
||||
@Override
|
||||
public int compare(Genre genre1, Genre genre2) {
|
||||
return genre1.getName().compareTo(genre2.getName());
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class GenreView extends UpdateView<Genre> {
|
|||
public void setObjectImpl(Genre genre) {
|
||||
titleView.setText(genre.getName());
|
||||
|
||||
if(genre.getAlbumCount() != null) {
|
||||
if(genre.getAlbumCount() != 0) {
|
||||
songsView.setVisibility(View.VISIBLE);
|
||||
albumsView.setVisibility(View.VISIBLE);
|
||||
songsView.setText(context.getResources().getString(R.string.select_genre_songs, genre.getSongCount()));
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package net.nullsum.audinaut.domain
|
||||
|
||||
import android.util.Log
|
||||
|
||||
import java.io.Serializable
|
||||
import java.text.Collator
|
||||
import java.util.Collections
|
||||
import java.util.Comparator
|
||||
import java.util.Locale
|
||||
|
||||
class Artist constructor(var id: String = "", var name: String = "") : Serializable {
|
||||
val TAG: String = "Artist"
|
||||
val ROOT_ID: String = "-1"
|
||||
val MISSING_ID: String = "-2"
|
||||
|
||||
var index: String = ""
|
||||
var closeness: Int = 0
|
||||
|
||||
fun sort(artists: MutableList<Artist>, ignoredArticles: MutableList<String>) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package net.nullsum.audinaut.domain
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
class Genre : Serializable {
|
||||
var name: String = ""
|
||||
var index: String = ""
|
||||
var albumCount: Int = 0
|
||||
var songCount: Int = 0
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package net.nullsum.audinaut.domain
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
|
||||
import kotlin.collections.MutableList
|
||||
import java.io.Serializable
|
||||
|
||||
import net.nullsum.audinaut.util.Constants
|
||||
import net.nullsum.audinaut.util.Util
|
||||
|
||||
class Indexes constructor(var lastModified: Long = 0,
|
||||
var shortcuts: MutableList<Artist> = mutableListOf<Artist>(),
|
||||
var artists: MutableList<Artist> = mutableListOf<Artist>(),
|
||||
var entries: MutableList<MusicDirectory.Entry> = mutableListOf<MusicDirectory.Entry>()) : Serializable {
|
||||
fun sortChildren(context: Context) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package net.nullsum.audinaut.domain
|
||||
|
||||
import android.media.RemoteControlClient
|
||||
|
||||
enum class PlayerState constructor(val mRemoteControlClientPlayState: Int) {
|
||||
IDLE(RemoteControlClient.PLAYSTATE_STOPPED),
|
||||
DOWNLOADING(RemoteControlClient.PLAYSTATE_BUFFERING),
|
||||
PREPARING(RemoteControlClient.PLAYSTATE_BUFFERING),
|
||||
PREPARED(RemoteControlClient.PLAYSTATE_STOPPED),
|
||||
STARTED(RemoteControlClient.PLAYSTATE_PLAYING),
|
||||
STOPPED(RemoteControlClient.PLAYSTATE_STOPPED),
|
||||
PAUSED(RemoteControlClient.PLAYSTATE_PAUSED),
|
||||
PAUSED_TEMP(RemoteControlClient.PLAYSTATE_PAUSED),
|
||||
COMPLETED(RemoteControlClient.PLAYSTATE_STOPPED);
|
||||
|
||||
fun getRemoteControlClientPlayState(): Int {
|
||||
return mRemoteControlClientPlayState
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package net.nullsum.audinaut.domain
|
||||
|
||||
enum class RepeatMode {
|
||||
OFF {
|
||||
override fun next() = ALL
|
||||
},
|
||||
ALL {
|
||||
override fun next() = SINGLE
|
||||
},
|
||||
SINGLE {
|
||||
override fun next() = OFF
|
||||
};
|
||||
|
||||
abstract fun next(): RepeatMode
|
||||
}
|
Loading…
Reference in New Issue