From cb8ac22d0930c173ec124b8f7fd68609fa9732a2 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Sat, 3 Jun 2017 16:16:19 -0400 Subject: [PATCH] Convert some of the domain models to Kotlin --- app/build.gradle | 58 +++++--- .../net/nullsum/audinaut/domain/Artist.java | 138 ------------------ .../net/nullsum/audinaut/domain/Genre.java | 69 --------- .../net/nullsum/audinaut/domain/Indexes.java | 87 ----------- .../nullsum/audinaut/domain/PlayerState.java | 47 ------ .../nullsum/audinaut/domain/RepeatMode.java | 28 ---- .../fragments/SelectArtistFragment.java | 3 +- .../audinaut/service/parser/GenreParser.java | 10 +- .../net/nullsum/audinaut/view/GenreView.java | 2 +- .../net/nullsum/audinuat/domain/Artist.kt | 21 +++ .../net/nullsum/audinuat/domain/Genre.kt | 10 ++ .../net/nullsum/audinuat/domain/Indexes.kt | 18 +++ .../nullsum/audinuat/domain/PlayerState.kt | 19 +++ .../net/nullsum/audinuat/domain/RepeatMode.kt | 15 ++ 14 files changed, 133 insertions(+), 392 deletions(-) delete mode 100644 app/src/main/java/net/nullsum/audinaut/domain/Artist.java delete mode 100644 app/src/main/java/net/nullsum/audinaut/domain/Genre.java delete mode 100644 app/src/main/java/net/nullsum/audinaut/domain/Indexes.java delete mode 100644 app/src/main/java/net/nullsum/audinaut/domain/PlayerState.java delete mode 100644 app/src/main/java/net/nullsum/audinaut/domain/RepeatMode.java create mode 100644 app/src/main/kotlin/net/nullsum/audinuat/domain/Artist.kt create mode 100644 app/src/main/kotlin/net/nullsum/audinuat/domain/Genre.kt create mode 100644 app/src/main/kotlin/net/nullsum/audinuat/domain/Indexes.kt create mode 100644 app/src/main/kotlin/net/nullsum/audinuat/domain/PlayerState.kt create mode 100644 app/src/main/kotlin/net/nullsum/audinuat/domain/RepeatMode.kt diff --git a/app/build.gradle b/app/build.gradle index 0630a85..54bd182 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,32 +1,50 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 25 + buildToolsVersion "25.0.2" - defaultConfig { - applicationId "net.nullsum.audinaut" - minSdkVersion 19 - targetSdkVersion 25 - versionCode 190 - versionName '0.2.1' - setProperty("archivesBaseName", "Audinaut $versionName") - resConfigs "de", "es", "fr", "hu", "nl", "pt-rPT", "ru", "sv" - } + defaultConfig { + applicationId "net.nullsum.audinaut" + minSdkVersion 19 + targetSdkVersion 25 + versionCode 190 + versionName '0.2.1' + setProperty("archivesBaseName", "Audinaut $versionName") + resConfigs "de", "es", "fr", "hu", "nl", "pt-rPT", "ru", "sv" + } - packagingOptions { - exclude 'META-INF/beans.xml' - } + packagingOptions { + exclude 'META-INF/beans.xml' + } - lintOptions { - checkReleaseBuilds false + lintOptions { + checkReleaseBuilds false warning 'InvalidPackage' - } + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } } dependencies { - compile 'com.esotericsoftware:kryo:4.0.0' - compile 'com.android.support:design:25.2.0' - compile 'com.sothree.slidinguppanel:library:3.3.1' + compile 'com.esotericsoftware:kryo:4.0.0' + 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" + } } diff --git a/app/src/main/java/net/nullsum/audinaut/domain/Artist.java b/app/src/main/java/net/nullsum/audinaut/domain/Artist.java deleted file mode 100644 index 91955aa..0000000 --- a/app/src/main/java/net/nullsum/audinaut/domain/Artist.java +++ /dev/null @@ -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 . - - 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 { - 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 artists, String[] ignoredArticles) { - try { - Collections.sort(artists, new ArtistComparator(ignoredArticles)); - } catch (Exception e) { - Log.w(TAG, "Failed to sort artists", e); - } - } -} diff --git a/app/src/main/java/net/nullsum/audinaut/domain/Genre.java b/app/src/main/java/net/nullsum/audinaut/domain/Genre.java deleted file mode 100644 index b40e27c..0000000 --- a/app/src/main/java/net/nullsum/audinaut/domain/Genre.java +++ /dev/null @@ -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 { - @Override - public int compare(Genre genre1, Genre genre2) { - return genre1.getName().compareToIgnoreCase(genre2.getName()); - } - - public static List sort(List genres) { - Collections.sort(genres, new GenreComparator()); - return genres; - } - - } -} diff --git a/app/src/main/java/net/nullsum/audinaut/domain/Indexes.java b/app/src/main/java/net/nullsum/audinaut/domain/Indexes.java deleted file mode 100644 index 185d3af..0000000 --- a/app/src/main/java/net/nullsum/audinaut/domain/Indexes.java +++ /dev/null @@ -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 . - - 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 shortcuts; - private List artists; - private List entries; - - public Indexes() { - - } - public Indexes(long lastModified, List shortcuts, List artists) { - this.lastModified = lastModified; - this.shortcuts = shortcuts; - this.artists = artists; - this.entries = new ArrayList(); - } - public Indexes(long lastModified, List shortcuts, List artists, List entries) { - this.lastModified = lastModified; - this.shortcuts = shortcuts; - this.artists = artists; - this.entries = entries; - } - - public long getLastModified() { - return lastModified; - } - - public List getShortcuts() { - return shortcuts; - } - - public List getArtists() { - return artists; - } - - public void setArtists(List artists) { - this.shortcuts = new ArrayList(); - this.artists.clear(); - this.artists.addAll(artists); - } - - public List 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); - } -} \ No newline at end of file diff --git a/app/src/main/java/net/nullsum/audinaut/domain/PlayerState.java b/app/src/main/java/net/nullsum/audinaut/domain/PlayerState.java deleted file mode 100644 index 2c2a403..0000000 --- a/app/src/main/java/net/nullsum/audinaut/domain/PlayerState.java +++ /dev/null @@ -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 . - - 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; - } -} diff --git a/app/src/main/java/net/nullsum/audinaut/domain/RepeatMode.java b/app/src/main/java/net/nullsum/audinaut/domain/RepeatMode.java deleted file mode 100644 index 1039f15..0000000 --- a/app/src/main/java/net/nullsum/audinaut/domain/RepeatMode.java +++ /dev/null @@ -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(); -} diff --git a/app/src/main/java/net/nullsum/audinaut/fragments/SelectArtistFragment.java b/app/src/main/java/net/nullsum/audinaut/fragments/SelectArtistFragment.java index 7d7498a..9b30a9d 100644 --- a/app/src/main/java/net/nullsum/audinaut/fragments/SelectArtistFragment.java +++ b/app/src/main/java/net/nullsum/audinaut/fragments/SelectArtistFragment.java @@ -200,7 +200,8 @@ public class SelectArtistFragment extends SelectRecyclerFragment i artists.add(artist); } - Indexes indexes = new Indexes(0, new ArrayList(), artists); + Indexes indexes = new Indexes(); + //indexes.setArtists = artists; indexes.sortChildren(context); items.addAll(indexes.getArtists()); diff --git a/app/src/main/java/net/nullsum/audinaut/service/parser/GenreParser.java b/app/src/main/java/net/nullsum/audinaut/service/parser/GenreParser.java index 670b115..d10c9ec 100644 --- a/app/src/main/java/net/nullsum/audinaut/service/parser/GenreParser.java +++ b/app/src/main/java/net/nullsum/audinaut/service/parser/GenreParser.java @@ -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() { + @Override + public int compare(Genre genre1, Genre genre2) { + return genre1.getName().compareTo(genre2.getName()); + } + }); + return result; } } diff --git a/app/src/main/java/net/nullsum/audinaut/view/GenreView.java b/app/src/main/java/net/nullsum/audinaut/view/GenreView.java index 683a522..a69518a 100644 --- a/app/src/main/java/net/nullsum/audinaut/view/GenreView.java +++ b/app/src/main/java/net/nullsum/audinaut/view/GenreView.java @@ -44,7 +44,7 @@ public class GenreView extends UpdateView { 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())); diff --git a/app/src/main/kotlin/net/nullsum/audinuat/domain/Artist.kt b/app/src/main/kotlin/net/nullsum/audinuat/domain/Artist.kt new file mode 100644 index 0000000..a358bc7 --- /dev/null +++ b/app/src/main/kotlin/net/nullsum/audinuat/domain/Artist.kt @@ -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, ignoredArticles: MutableList) { + } +} diff --git a/app/src/main/kotlin/net/nullsum/audinuat/domain/Genre.kt b/app/src/main/kotlin/net/nullsum/audinuat/domain/Genre.kt new file mode 100644 index 0000000..abed390 --- /dev/null +++ b/app/src/main/kotlin/net/nullsum/audinuat/domain/Genre.kt @@ -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 +} diff --git a/app/src/main/kotlin/net/nullsum/audinuat/domain/Indexes.kt b/app/src/main/kotlin/net/nullsum/audinuat/domain/Indexes.kt new file mode 100644 index 0000000..4091c1f --- /dev/null +++ b/app/src/main/kotlin/net/nullsum/audinuat/domain/Indexes.kt @@ -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 = mutableListOf(), + var artists: MutableList = mutableListOf(), + var entries: MutableList = mutableListOf()) : Serializable { + fun sortChildren(context: Context) { + } +} diff --git a/app/src/main/kotlin/net/nullsum/audinuat/domain/PlayerState.kt b/app/src/main/kotlin/net/nullsum/audinuat/domain/PlayerState.kt new file mode 100644 index 0000000..5af80a8 --- /dev/null +++ b/app/src/main/kotlin/net/nullsum/audinuat/domain/PlayerState.kt @@ -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 + } +} diff --git a/app/src/main/kotlin/net/nullsum/audinuat/domain/RepeatMode.kt b/app/src/main/kotlin/net/nullsum/audinuat/domain/RepeatMode.kt new file mode 100644 index 0000000..61a074a --- /dev/null +++ b/app/src/main/kotlin/net/nullsum/audinuat/domain/RepeatMode.kt @@ -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 +}