aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/drawable-hdpi/ic_menu_add_person_dark.pngbin0 -> 990 bytes
-rw-r--r--res/drawable-hdpi/ic_menu_add_person_light.pngbin0 -> 1191 bytes
-rw-r--r--res/drawable-hdpi/ic_menu_admin_dark.pngbin0 -> 1263 bytes
-rw-r--r--res/drawable-hdpi/ic_menu_admin_light.pngbin0 -> 1524 bytes
-rw-r--r--res/drawable-mdpi/ic_menu_add_person_dark.pngbin0 -> 652 bytes
-rw-r--r--res/drawable-mdpi/ic_menu_add_person_light.pngbin0 -> 811 bytes
-rw-r--r--res/drawable-mdpi/ic_menu_admin_dark.pngbin0 -> 781 bytes
-rw-r--r--res/drawable-mdpi/ic_menu_admin_light.pngbin0 -> 966 bytes
-rw-r--r--res/drawable-xhdpi/ic_menu_add_person_dark.pngbin0 -> 1284 bytes
-rw-r--r--res/drawable-xhdpi/ic_menu_add_person_light.pngbin0 -> 1534 bytes
-rw-r--r--res/drawable-xhdpi/ic_menu_admin_dark.pngbin0 -> 1807 bytes
-rw-r--r--res/drawable-xhdpi/ic_menu_admin_light.pngbin0 -> 2119 bytes
-rw-r--r--res/drawable-xxhdpi/ic_menu_add_person_dark.pngbin0 -> 2036 bytes
-rw-r--r--res/drawable-xxhdpi/ic_menu_add_person_light.pngbin0 -> 2350 bytes
-rw-r--r--res/drawable-xxhdpi/ic_menu_admin_dark.pngbin0 -> 2992 bytes
-rw-r--r--res/drawable-xxhdpi/ic_menu_admin_light.pngbin0 -> 3467 bytes
-rw-r--r--res/layout/change_password.xml28
-rw-r--r--res/menu/admin.xml12
-rw-r--r--res/menu/admin_context.xml16
-rw-r--r--res/menu/empty.xml3
-rw-r--r--res/values/arrays.xml4
-rw-r--r--res/values/attrs.xml1
-rw-r--r--res/values/strings.xml14
-rw-r--r--res/values/themes.xml3
-rw-r--r--res/xml/settings.xml6
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicActivity.java11
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java3
-rw-r--r--src/github/daneren2005/dsub/domain/User.java161
-rw-r--r--src/github/daneren2005/dsub/fragments/AdminFragment.java208
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectListFragment.java6
-rw-r--r--src/github/daneren2005/dsub/fragments/UserFragment.java61
-rw-r--r--src/github/daneren2005/dsub/service/CachedMusicService.java62
-rw-r--r--src/github/daneren2005/dsub/service/MusicService.java15
-rw-r--r--src/github/daneren2005/dsub/service/OfflineMusicService.java40
-rw-r--r--src/github/daneren2005/dsub/service/RESTMusicService.java74
-rw-r--r--src/github/daneren2005/dsub/service/parser/UserParser.java73
-rw-r--r--src/github/daneren2005/dsub/util/Constants.java1
-rw-r--r--src/github/daneren2005/dsub/util/Util.java5
-rw-r--r--src/github/daneren2005/dsub/view/UserAdapter.java48
-rw-r--r--src/github/daneren2005/dsub/view/UserView.java50
40 files changed, 898 insertions, 7 deletions
diff --git a/res/drawable-hdpi/ic_menu_add_person_dark.png b/res/drawable-hdpi/ic_menu_add_person_dark.png
new file mode 100644
index 00000000..971048d5
--- /dev/null
+++ b/res/drawable-hdpi/ic_menu_add_person_dark.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_menu_add_person_light.png b/res/drawable-hdpi/ic_menu_add_person_light.png
new file mode 100644
index 00000000..f94446d0
--- /dev/null
+++ b/res/drawable-hdpi/ic_menu_add_person_light.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_menu_admin_dark.png b/res/drawable-hdpi/ic_menu_admin_dark.png
new file mode 100644
index 00000000..76da5ade
--- /dev/null
+++ b/res/drawable-hdpi/ic_menu_admin_dark.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_menu_admin_light.png b/res/drawable-hdpi/ic_menu_admin_light.png
new file mode 100644
index 00000000..5431889c
--- /dev/null
+++ b/res/drawable-hdpi/ic_menu_admin_light.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_menu_add_person_dark.png b/res/drawable-mdpi/ic_menu_add_person_dark.png
new file mode 100644
index 00000000..7d64f5d3
--- /dev/null
+++ b/res/drawable-mdpi/ic_menu_add_person_dark.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_menu_add_person_light.png b/res/drawable-mdpi/ic_menu_add_person_light.png
new file mode 100644
index 00000000..55c38c26
--- /dev/null
+++ b/res/drawable-mdpi/ic_menu_add_person_light.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_menu_admin_dark.png b/res/drawable-mdpi/ic_menu_admin_dark.png
new file mode 100644
index 00000000..f88f5f15
--- /dev/null
+++ b/res/drawable-mdpi/ic_menu_admin_dark.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_menu_admin_light.png b/res/drawable-mdpi/ic_menu_admin_light.png
new file mode 100644
index 00000000..35cd14f4
--- /dev/null
+++ b/res/drawable-mdpi/ic_menu_admin_light.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_menu_add_person_dark.png b/res/drawable-xhdpi/ic_menu_add_person_dark.png
new file mode 100644
index 00000000..30c78e5a
--- /dev/null
+++ b/res/drawable-xhdpi/ic_menu_add_person_dark.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_menu_add_person_light.png b/res/drawable-xhdpi/ic_menu_add_person_light.png
new file mode 100644
index 00000000..b3fb3808
--- /dev/null
+++ b/res/drawable-xhdpi/ic_menu_add_person_light.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_menu_admin_dark.png b/res/drawable-xhdpi/ic_menu_admin_dark.png
new file mode 100644
index 00000000..09f90c15
--- /dev/null
+++ b/res/drawable-xhdpi/ic_menu_admin_dark.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_menu_admin_light.png b/res/drawable-xhdpi/ic_menu_admin_light.png
new file mode 100644
index 00000000..4bd3beaf
--- /dev/null
+++ b/res/drawable-xhdpi/ic_menu_admin_light.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_menu_add_person_dark.png b/res/drawable-xxhdpi/ic_menu_add_person_dark.png
new file mode 100644
index 00000000..446985ea
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_menu_add_person_dark.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_menu_add_person_light.png b/res/drawable-xxhdpi/ic_menu_add_person_light.png
new file mode 100644
index 00000000..0f1d36bc
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_menu_add_person_light.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_menu_admin_dark.png b/res/drawable-xxhdpi/ic_menu_admin_dark.png
new file mode 100644
index 00000000..0e57c9ed
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_menu_admin_dark.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_menu_admin_light.png b/res/drawable-xxhdpi/ic_menu_admin_light.png
new file mode 100644
index 00000000..63ab2f83
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_menu_admin_light.png
Binary files differ
diff --git a/res/layout/change_password.xml b/res/layout/change_password.xml
new file mode 100644
index 00000000..ad3e9cd8
--- /dev/null
+++ b/res/layout/change_password.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/new_password_label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="4dp"
+ android:textSize="20dp"
+ android:text="@string/admin.change_password_label" />
+ <EditText
+ android:id="@+id/new_password"
+ android:inputType="textPassword"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_marginLeft="4dp" />
+ </LinearLayout>
+
+</LinearLayout> \ No newline at end of file
diff --git a/res/menu/admin.xml b/res/menu/admin.xml
new file mode 100644
index 00000000..f16e89f7
--- /dev/null
+++ b/res/menu/admin.xml
@@ -0,0 +1,12 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:compat="http://schemas.android.com/apk/res-auto">
+ <item
+ android:id="@+id/menu_add_user"
+ android:title="@string/menu.add_user"
+ android:icon="?attr/add_person"
+ compat:showAsAction="always|withText"/>
+
+ <item
+ android:id="@+id/menu_exit"
+ android:title="@string/menu.exit"/>
+</menu> \ No newline at end of file
diff --git a/res/menu/admin_context.xml b/res/menu/admin_context.xml
new file mode 100644
index 00000000..e4948acd
--- /dev/null
+++ b/res/menu/admin_context.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:compat="http://schemas.android.com/apk/res-auto">
+
+ <item
+ android:id="@+id/admin_update_permissions"
+ android:title="@string/admin.update_permissions"/>
+
+ <item
+ android:id="@+id/admin_change_password"
+ android:title="@string/admin.change_password"/>
+
+ <item
+ android:id="@+id/admin_delete_user"
+ android:title="@string/admin.delete_user"/>
+</menu>
diff --git a/res/menu/empty.xml b/res/menu/empty.xml
index cf7b82de..7abe954b 100644
--- a/res/menu/empty.xml
+++ b/res/menu/empty.xml
@@ -2,4 +2,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:compat="http://schemas.android.com/apk/res-auto">
+ <item
+ android:id="@+id/menu_exit"
+ android:title="@string/menu.exit"/>
</menu>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index e8eee980..aca7b9ee 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -8,6 +8,7 @@
<item>@string/button_bar.bookmarks</item>
<item>@string/button_bar.shares</item>
<item>@string/button_bar.chat</item>
+ <item>@string/button_bar.admin</item>
<item>@string/button_bar.downloading</item>
<item>@string/menu.settings</item>
</string-array>
@@ -20,6 +21,7 @@
<item>Bookmark</item>
<item>Share</item>
<item>Chat</item>
+ <item>Admin</item>
<item>Download</item>
<item>Settings</item>
</string-array>
@@ -32,6 +34,7 @@
<item>@drawable/ic_menu_bookmark_light</item>
<item>@drawable/ic_menu_share_light</item>
<item>@drawable/ic_menu_chat_light</item>
+ <item>@drawable/ic_menu_admin_light</item>
<item>@drawable/ic_menu_download_light</item>
<item>@drawable/ic_menu_settings_light</item>
</array>
@@ -44,6 +47,7 @@
<item>@drawable/ic_menu_bookmark_dark</item>
<item>@drawable/ic_menu_share_dark</item>
<item>@drawable/ic_menu_chat_dark</item>
+ <item>@drawable/ic_menu_admin_dark</item>
<item>@drawable/ic_menu_download_dark</item>
<item>@drawable/ic_menu_settings_dark</item>
</array>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index d025a48f..b820c371 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -21,5 +21,6 @@
<attr name="downloading" format="reference"/>
<attr name="bookmark" format="reference"/>
<attr name="share" format="reference"/>
+ <attr name="add_person" format="reference"/>
<attr name="drawerItemsIcons" format="reference"/>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3cc120d6..add99c11 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -35,6 +35,7 @@
<string name="button_bar.bookmarks">Bookmarks</string>
<string name="button_bar.shares">Shares</string>
<string name="button_bar.chat">Chat</string>
+ <string name="button_bar.admin">Admin</string>
<string name="button_bar.downloading">Downloading</string>
<string name="main.welcome_title">Welcome!</string>
@@ -99,6 +100,7 @@
<string name="menu.delete_cache">Delete Cache</string>
<string name="menu.cast">Cast To Device</string>
<string name="menu.faq">FAQ</string>
+ <string name="menu.add_user">Add User</string>
<string name="playlist.label">Playlists</string>
<string name="playlist.update_info">Update Information</string>
@@ -416,6 +418,8 @@
<string name="settings.play_now_after_summary">Play Now context menu for a song plays everything after selected item (like the Subsonic web GUI)</string>
<string name="settings.large_album_art">Large Album Art</string>
<string name="settings.large_album_art_summary">Display albums with large album art instead of in a list</string>
+ <string name="settings.admin_enabled">Admin Enabled</string>
+ <string name="settings.admin_enabled_summary">Whether or not to display the admin listing in the pull out drawer</string>
<string name="shuffle.title">Shuffle By</string>
<string name="shuffle.startYear">Start Year:</string>
@@ -443,6 +447,16 @@
<string name="share.via">Share via</string>
<string name="share.delete">Delete Share</string>
+ <string name="admin.update_permissions">Update Permissions</string>
+ <string name="admin.change_password">Change Password</string>
+ <string name="admin.change_password_success">Successfully changed password for %1$s</string>
+ <string name="admin.change_password_error">Failed to change password for %1$s</string>
+ <string name="admin.change_password_label">New Password:</string>
+ <string name="admin.change_password_invalid">Enter a valid password</string>
+ <string name="admin.delete_user">Delete User</string>
+ <string name="admin.delete_user_success">Successfully deleted %1$s</string>
+ <string name="admin.delete_user_error">Failed to delete %1$s</string>
+
<string name="music_service.retry">A network error occurred. Retrying %1$d of %2$d.</string>
<string name="background_task.wait">Please wait...</string>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 677ee4e1..0f464baa 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -24,6 +24,7 @@
<item name="downloading">@drawable/downloading_light</item>
<item name="bookmark">@drawable/ic_menu_bookmark_light</item>
<item name="share">@drawable/ic_menu_share_light</item>
+ <item name="add_person">@drawable/ic_menu_add_person_light</item>
<item name="drawerItemsIcons">@array/drawerItemIconsLight</item>
<item name="android:textViewStyle">@style/DSub.TextViewStyle</item>
<item name="android:buttonStyle">@style/DSub.ButtonStyle.Light</item>
@@ -53,6 +54,7 @@
<item name="downloading">@drawable/downloading_dark</item>
<item name="bookmark">@drawable/ic_menu_bookmark_dark</item>
<item name="share">@drawable/ic_menu_share_dark</item>
+ <item name="add_person">@drawable/ic_menu_add_person_dark</item>
<item name="drawerItemsIcons">@array/drawerItemIconsDark</item>
<item name="android:textViewStyle">@style/DSub.TextViewStyle</item>
<item name="android:buttonStyle">@style/DSub.ButtonStyle.Dark</item>
@@ -85,6 +87,7 @@
<item name="downloading">@drawable/downloading_dark</item>
<item name="bookmark">@drawable/ic_menu_bookmark_dark</item>
<item name="share">@drawable/ic_menu_share_dark</item>
+ <item name="add_person">@drawable/ic_menu_add_person_dark</item>
<item name="drawerItemsIcons">@array/drawerItemIconsDark</item>
<item name="android:textViewStyle">@style/DSub.TextViewStyle</item>
<item name="android:buttonStyle">@style/DSub.ButtonStyle.Dark</item>
diff --git a/res/xml/settings.xml b/res/xml/settings.xml
index 9f1b5b67..cf3868f5 100644
--- a/res/xml/settings.xml
+++ b/res/xml/settings.xml
@@ -139,6 +139,12 @@
android:summary="@string/settings.shares_enabled_summary"
android:key="sharedEnabled"
android:defaultValue="true"/>
+
+ <CheckBoxPreference
+ android:title="@string/settings.admin_enabled"
+ android:summary="@string/settings.admin_enabled_summary"
+ android:key="adminEnabled"
+ android:defaultValue="true"/>
</PreferenceCategory>
<PreferenceCategory
diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
index 646fa295..edec6b90 100644
--- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -75,7 +75,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
private String[] drawerItemsDescriptions;
private String[] drawerItems;
private boolean drawerIdle = true;
- private boolean[] enabledItems = {true, true, true, true};
+ private boolean[] enabledItems = {true, true, true, true, true};
private boolean destroyed = false;
private boolean finished = false;
protected List<SubsonicFragment> backStack = new ArrayList<SubsonicFragment>();
@@ -386,8 +386,9 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
boolean bookmarksEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED, true) && !Util.isOffline(this);
boolean sharedEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SHARED_ENABLED, true) && !Util.isOffline(this);
boolean chatEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_CHAT_ENABLED, true) && !Util.isOffline(this);
+ boolean adminEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_ADMIN_ENABLED, true) && !Util.isOffline(this);
- if(drawerItems == null || !enabledItems[0] == podcastsEnabled || !enabledItems[1] == bookmarksEnabled || !enabledItems[2] == sharedEnabled || !enabledItems[3] == chatEnabled) {
+ if(drawerItems == null || !enabledItems[0] == podcastsEnabled || !enabledItems[1] == bookmarksEnabled || !enabledItems[2] == sharedEnabled || !enabledItems[3] == chatEnabled || !enabledItems[4] == adminEnabled) {
drawerItems = getResources().getStringArray(R.array.drawerItems);
drawerItemsDescriptions = getResources().getStringArray(R.array.drawerItemsDescriptions);
@@ -419,15 +420,19 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
if(!chatEnabled) {
drawerItemsVisibleList.set(6, false);
}
- if(!getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) {
+ if(!adminEnabled) {
drawerItemsVisibleList.set(7, false);
}
+ if(!getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) {
+ drawerItemsVisibleList.set(8, false);
+ }
drawerList.setAdapter(drawerAdapter = new DrawerAdapter(this, drawerItemsList, drawerItemsIconsList, drawerItemsVisibleList));
enabledItems[0] = podcastsEnabled;
enabledItems[1] = bookmarksEnabled;
enabledItems[2] = sharedEnabled;
enabledItems[3] = chatEnabled;
+ enabledItems[4] = adminEnabled;
String fragmentType = getIntent().getStringExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE);
if(fragmentType != null && lastSelectedPosition == 0) {
diff --git a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
index ebedf9b1..2afdaf3f 100644
--- a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
+++ b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
@@ -44,6 +44,7 @@ import java.util.concurrent.TimeUnit;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PlayerState;
+import github.daneren2005.dsub.fragments.AdminFragment;
import github.daneren2005.dsub.fragments.ChatFragment;
import github.daneren2005.dsub.fragments.DownloadFragment;
import github.daneren2005.dsub.fragments.MainFragment;
@@ -392,6 +393,8 @@ public class SubsonicFragmentActivity extends SubsonicActivity {
return new SelectBookmarkFragment();
} else if("Share".equals(fragmentType)) {
return new SelectShareFragment();
+ } else if("Admin".equals(fragmentType)) {
+ return new AdminFragment();
} else if("Download".equals(fragmentType)) {
return new DownloadFragment();
} else {
diff --git a/src/github/daneren2005/dsub/domain/User.java b/src/github/daneren2005/dsub/domain/User.java
new file mode 100644
index 00000000..63ead042
--- /dev/null
+++ b/src/github/daneren2005/dsub/domain/User.java
@@ -0,0 +1,161 @@
+/*
+ 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 2014 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.domain;
+
+import java.io.Serializable;
+
+public class User implements Serializable {
+ private String username;
+ private String password;
+ private String email;
+ private Boolean scrobblingEnabled;
+
+ private Boolean adminRole;
+ private Boolean settingsRole;
+ private Boolean downloadRole;
+ private Boolean uploadRole;
+ private Boolean playlistRole;
+ private Boolean coverArtRole;
+ private Boolean commentRole;
+ private Boolean podcastRole;
+ private Boolean streamRole;
+ private Boolean jukeboxRole;
+ private Boolean shareRole;
+
+ public User() {
+
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public Boolean getScrobblingEnabled() {
+ return scrobblingEnabled;
+ }
+
+ public void setScrobblingEnabled(Boolean scrobblingEnabled) {
+ this.scrobblingEnabled = scrobblingEnabled;
+ }
+
+ public Boolean getAdminRole() {
+ return adminRole;
+ }
+
+ public void setAdminRole(Boolean adminRole) {
+ this.adminRole = adminRole;
+ }
+
+ public Boolean getSettingsRole() {
+ return settingsRole;
+ }
+
+ public void setSettingsRole(Boolean settingsRole) {
+ this.settingsRole = settingsRole;
+ }
+
+ public Boolean getDownloadRole() {
+ return downloadRole;
+ }
+
+ public void setDownloadRole(Boolean downloadRole) {
+ this.downloadRole = downloadRole;
+ }
+
+ public Boolean getUploadRole() {
+ return uploadRole;
+ }
+
+ public void setUploadRole(Boolean uploadRole) {
+ this.uploadRole = uploadRole;
+ }
+
+ public Boolean getPlaylistRole() {
+ return playlistRole;
+ }
+
+ public void setPlaylistRole(Boolean playlistRole) {
+ this.playlistRole = playlistRole;
+ }
+
+ public Boolean getCoverArtRole() {
+ return coverArtRole;
+ }
+
+ public void setCoverArtRole(Boolean coverArtRole) {
+ this.coverArtRole = coverArtRole;
+ }
+
+ public Boolean getCommentRole() {
+ return commentRole;
+ }
+
+ public void setCommentRole(Boolean commentRole) {
+ this.commentRole = commentRole;
+ }
+
+ public Boolean getPodcastRole() {
+ return podcastRole;
+ }
+
+ public void setPodcastRole(Boolean podcastRole) {
+ this.podcastRole = podcastRole;
+ }
+
+ public Boolean getStreamRole() {
+ return streamRole;
+ }
+
+ public void setStreamRole(Boolean streamRole) {
+ this.streamRole = streamRole;
+ }
+
+ public Boolean getJukeboxRole() {
+ return jukeboxRole;
+ }
+
+ public void setJukeboxRole(Boolean jukeboxRole) {
+ this.jukeboxRole = jukeboxRole;
+ }
+
+ public Boolean getShareRole() {
+ return shareRole;
+ }
+
+ public void setShareRole(Boolean shareRole) {
+ this.shareRole = shareRole;
+ }
+}
diff --git a/src/github/daneren2005/dsub/fragments/AdminFragment.java b/src/github/daneren2005/dsub/fragments/AdminFragment.java
new file mode 100644
index 00000000..f6e8e153
--- /dev/null
+++ b/src/github/daneren2005/dsub/fragments/AdminFragment.java
@@ -0,0 +1,208 @@
+/*
+ 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 2014 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.fragments;
+
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.ContextMenu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.User;
+import github.daneren2005.dsub.service.MusicService;
+import github.daneren2005.dsub.service.MusicServiceFactory;
+import github.daneren2005.dsub.service.OfflineException;
+import github.daneren2005.dsub.service.ServerTooOldException;
+import github.daneren2005.dsub.service.parser.SubsonicRESTException;
+import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.ProgressListener;
+import github.daneren2005.dsub.util.SilentBackgroundTask;
+import github.daneren2005.dsub.util.Util;
+import github.daneren2005.dsub.view.UserAdapter;
+
+public class AdminFragment extends SelectListFragment<User> {
+ private static String TAG = AdminFragment.class.getSimpleName();
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, view, menuInfo);
+
+ MenuInflater inflater = context.getMenuInflater();
+ inflater.inflate(R.menu.admin_context, menu);
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem menuItem) {
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
+ User user = objects.get(info.position);
+
+ switch(menuItem.getItemId()) {
+ case R.id.admin_update_permissions:
+ break;
+ case R.id.admin_change_password:
+ changePassword(user);
+ break;
+ case R.id.admin_delete_user:
+ deleteUser(user);
+ break;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int getOptionsMenu() {
+ return R.menu.admin;
+ }
+
+ @Override
+ public ArrayAdapter getAdapter(List<User> objs) {
+ return new UserAdapter(context, objs);
+ }
+
+ @Override
+ public List<User> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception {
+ try {
+ // Will only work if user is admin
+ return musicService.getUsers(refresh, context, listener);
+ } catch(SubsonicRESTException e) {
+ // Delete cached users if not allowed to get them
+ String s = Util.getRestUrl(context, null, false);
+ String cache = "users-" + s.hashCode() + ".ser";
+ File file = new File(context.getCacheDir(), cache);
+ file.delete();
+
+ List<User> users = new ArrayList<User>();
+ users.add(musicService.getUser(refresh, Util.getCurrentUsername(context), context, listener));
+ return users;
+ }
+ }
+
+ @Override
+ public int getTitleResource() {
+ return R.string.button_bar_admin;
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ User user = (User) parent.getItemAtPosition(position);
+
+ SubsonicFragment fragment = new UserFragment();
+ Bundle args = new Bundle();
+ args.putSerializable(Constants.INTENT_EXTRA_NAME_ID, user);
+ fragment.setArguments(args);
+
+ replaceFragment(fragment);
+ }
+
+ private void changePassword(final User user) {
+ View layout = context.getLayoutInflater().inflate(R.layout.change_password, null);
+ final TextView passwordView = (TextView) layout.findViewById(R.id.new_password);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle(R.string.admin_change_password)
+ .setView(layout)
+ .setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ final String password = passwordView.getText().toString();
+ // Don't allow blank passwords
+ if ("".equals(password)) {
+ Util.toast(context, R.string.admin_change_password_invalid);
+ return;
+ }
+
+ new SilentBackgroundTask<Void>(context) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ musicService.changePassword(user.getUsername(), password, context, null);
+ return null;
+ }
+
+ @Override
+ protected void done(Void v) {
+ Util.toast(context, context.getResources().getString(R.string.admin_change_password_success, user.getUsername()));
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = context.getResources().getString(R.string.admin_change_password_error, user.getUsername());
+ }
+
+ Util.toast(context, msg);
+ }
+ }.execute();
+ }
+ })
+ .setNegativeButton(R.string.common_cancel, null)
+ .setCancelable(true);
+
+ AlertDialog dialog = builder.create();
+ dialog.show();
+ }
+
+ private void deleteUser(final User user) {
+ Util.confirmDialog(context, R.string.common_delete, user.getUsername(), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ new SilentBackgroundTask<Void>(context) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ musicService.deleteUser(user.getUsername(), context, null);
+ return null;
+ }
+
+ @Override
+ protected void done(Void v) {
+ adapter.remove(user);
+ adapter.notifyDataSetChanged();
+
+ Util.toast(context, context.getResources().getString(R.string.admin_delete_user_success, user.getUsername()));
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = context.getResources().getString(R.string.admin_delete_user_error, user.getUsername());
+ }
+
+ Util.toast(context, msg);
+ }
+ }.execute();
+ }
+ });
+ }
+}
diff --git a/src/github/daneren2005/dsub/fragments/SelectListFragment.java b/src/github/daneren2005/dsub/fragments/SelectListFragment.java
index 4938fb3b..1c77ad68 100644
--- a/src/github/daneren2005/dsub/fragments/SelectListFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectListFragment.java
@@ -107,12 +107,14 @@ public abstract class SelectListFragment<T> extends SubsonicFragment implements
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
-
}
@Override
protected void refresh(final boolean refresh) {
- setTitle(getTitleResource());
+ int titleRes = getTitleResource();
+ if(titleRes != 0) {
+ setTitle(getTitleResource());
+ }
listView.setVisibility(View.INVISIBLE);
emptyView.setVisibility(View.GONE);
diff --git a/src/github/daneren2005/dsub/fragments/UserFragment.java b/src/github/daneren2005/dsub/fragments/UserFragment.java
new file mode 100644
index 00000000..3a85c6bb
--- /dev/null
+++ b/src/github/daneren2005/dsub/fragments/UserFragment.java
@@ -0,0 +1,61 @@
+/*
+ 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 2014 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.fragments;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ListView;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.User;
+import github.daneren2005.dsub.util.Constants;
+
+public class UserFragment extends SubsonicFragment{
+ private ListView listView;
+ private LayoutInflater inflater;
+ private User user;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
+ this.inflater = inflater;
+ rootView = inflater.inflate(R.layout.abstract_list_fragment, container, false);
+
+ Bundle args = getArguments();
+ user = (User) args.getSerializable(Constants.INTENT_EXTRA_NAME_ID);
+ setTitle(user.getUsername());
+
+ return rootView;
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
+ if(!primaryFragment) {
+ return;
+ }
+
+ menuInflater.inflate(R.menu.empty, menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java
index d0740704..1f1715c4 100644
--- a/src/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/src/github/daneren2005/dsub/service/CachedMusicService.java
@@ -41,6 +41,7 @@ import github.daneren2005.dsub.domain.PodcastChannel;
import github.daneren2005.dsub.domain.SearchCritera;
import github.daneren2005.dsub.domain.SearchResult;
import github.daneren2005.dsub.domain.Share;
+import github.daneren2005.dsub.domain.User;
import github.daneren2005.dsub.domain.Version;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.ProgressListener;
@@ -507,6 +508,67 @@ public class CachedMusicService implements MusicService {
}
@Override
+ public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception {
+ User result = null;
+
+ if(!refresh) {
+ result = FileUtil.deserialize(context, getCacheName(context, "user-" + username), User.class);
+ }
+
+ if(result == null) {
+ result = musicService.getUser(refresh, username, context, progressListener);
+ FileUtil.serialize(context, result, getCacheName(context, "user-" + username));
+ }
+
+ return result;
+ }
+
+ @Override
+ public List<User> getUsers(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ List<User> result = null;
+
+ if(!refresh) {
+ result = FileUtil.deserialize(context, getCacheName(context, "users"), ArrayList.class);
+ }
+
+ if(result == null) {
+ result = musicService.getUsers(refresh, context, progressListener);
+ FileUtil.serialize(context, new ArrayList<User>(result), getCacheName(context, "users"));
+ }
+
+ return result;
+ }
+
+ @Override
+ public void createUser(User user, Context context, ProgressListener progressListener) throws Exception {
+ musicService.createUser(user, context, progressListener);
+ }
+
+ @Override
+ public void updateUser(User user, Context context, ProgressListener progressListener) throws Exception {
+ musicService.updateUser(user, context, progressListener);
+ }
+
+ @Override
+ public void deleteUser(String username, Context context, ProgressListener progressListener) throws Exception {
+ musicService.deleteUser(username, context, progressListener);
+
+ // Delete cached users if any have been removed from list
+ File file = new File(context.getCacheDir(), getCacheName(context, "users"));
+ file.delete();
+ }
+
+ @Override
+ public void changePassword(String username, String password, Context context, ProgressListener progressListener) throws Exception {
+ musicService.changePassword(username, password, context, progressListener);
+ }
+
+ @Override
+ public Bitmap getAvatar(String username, Context context, ProgressListener progressListener) throws Exception {
+ return musicService.getAvatar(username, context, progressListener);
+ }
+
+ @Override
public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{
return musicService.processOfflineSyncs(context, progressListener);
}
diff --git a/src/github/daneren2005/dsub/service/MusicService.java b/src/github/daneren2005/dsub/service/MusicService.java
index 0522a4be..6f58603c 100644
--- a/src/github/daneren2005/dsub/service/MusicService.java
+++ b/src/github/daneren2005/dsub/service/MusicService.java
@@ -38,6 +38,7 @@ import github.daneren2005.dsub.domain.PodcastChannel;
import github.daneren2005.dsub.domain.SearchCritera;
import github.daneren2005.dsub.domain.SearchResult;
import github.daneren2005.dsub.domain.Share;
+import github.daneren2005.dsub.domain.User;
import github.daneren2005.dsub.domain.Version;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.ProgressListener;
@@ -160,6 +161,20 @@ public interface MusicService {
void createBookmark(String id, int position, String comment, Context context, ProgressListener progressListener) throws Exception;
void deleteBookmark(String id, Context context, ProgressListener progressListener) throws Exception;
+
+ User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception;
+
+ List<User> getUsers(boolean refresh, Context context, ProgressListener progressListener) throws Exception;
+
+ void createUser(User user, Context context, ProgressListener progressListener) throws Exception;
+
+ void updateUser(User user, Context context, ProgressListener progressListener) throws Exception;
+
+ void deleteUser(String username, Context context, ProgressListener progressListener) throws Exception;
+
+ void changePassword(String username, String password, Context context, ProgressListener progressListener) throws Exception;
+
+ Bitmap getAvatar(String username, Context context, ProgressListener progressListener) throws Exception;
int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception;
diff --git a/src/github/daneren2005/dsub/service/OfflineMusicService.java b/src/github/daneren2005/dsub/service/OfflineMusicService.java
index cf697441..9e2b9e13 100644
--- a/src/github/daneren2005/dsub/service/OfflineMusicService.java
+++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java
@@ -46,6 +46,7 @@ import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.domain.PodcastChannel;
import github.daneren2005.dsub.domain.SearchCritera;
import github.daneren2005.dsub.domain.SearchResult;
+import github.daneren2005.dsub.domain.User;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.ProgressListener;
@@ -688,8 +689,43 @@ public class OfflineMusicService extends RESTMusicService {
public void deleteBookmark(String id, Context context, ProgressListener progressListener) throws Exception {
throw new OfflineException("Deleting bookmarks not available in offline mode");
}
-
- @Override
+
+ @Override
+ public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Getting user not available in offline mode");
+ }
+
+ @Override
+ public List<User> getUsers(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Getting users not available in offline mode");
+ }
+
+ @Override
+ public void createUser(User user, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Creating users not available in offline mode");
+ }
+
+ @Override
+ public void updateUser(User user, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Updating users not available in offline mode");
+ }
+
+ @Override
+ public void deleteUser(String username, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Deleting users not available in offline mode");
+ }
+
+ @Override
+ public void changePassword(String username, String password, Context context, ProgressListener progressListener) throws Exception {
+ throw new OfflineException("Changing passwords not available in offline mode");
+ }
+
+ @Override
+ public Bitmap getAvatar(String username, Context context, ProgressListener progressListener) throws Exception {
+ return null;
+ }
+
+ @Override
public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{
throw new OfflineException("Offline scrobble cached can not be processes while in offline mode");
}
diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java
index eeddcaa2..20328d54 100644
--- a/src/github/daneren2005/dsub/service/RESTMusicService.java
+++ b/src/github/daneren2005/dsub/service/RESTMusicService.java
@@ -88,6 +88,7 @@ import github.daneren2005.dsub.service.parser.SearchResult2Parser;
import github.daneren2005.dsub.service.parser.SearchResultParser;
import github.daneren2005.dsub.service.parser.ShareParser;
import github.daneren2005.dsub.service.parser.StarredListParser;
+import github.daneren2005.dsub.service.parser.UserParser;
import github.daneren2005.dsub.service.parser.VersionParser;
import github.daneren2005.dsub.service.ssl.SSLSocketFactory;
import github.daneren2005.dsub.service.ssl.TrustSelfSignedStrategy;
@@ -1190,6 +1191,79 @@ public class RESTMusicService implements MusicService {
}
@Override
+ public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception {
+ Reader reader = getReader(context, progressListener, "getUser", null, Arrays.asList("username"), Arrays.<Object>asList(username));
+ try {
+ List<User> users = new UserParser(context).parse(reader, progressListener);
+ if(users.size() > 0) {
+ // Should only have returned one anyways
+ return users.get(0);
+ } else {
+ return null;
+ }
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public List<User> getUsers(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
+ checkServerVersion(context, "1.8", "Getting user list is not supported");
+
+ Reader reader = getReader(context, progressListener, "getUsers", null);
+ try {
+ return new UserParser(context).parse(reader, progressListener);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public void createUser(User user, Context context, ProgressListener progressListener) throws Exception {
+ Reader reader = getReader(context, progressListener, "createUser", null);
+ try {
+ new ErrorParser(context).parse(reader);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public void updateUser(User user, Context context, ProgressListener progressListener) throws Exception {
+ Reader reader = getReader(context, progressListener, "createUser", null);
+ try {
+ new ErrorParser(context).parse(reader);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public void deleteUser(String username, Context context, ProgressListener progressListener) throws Exception {
+ Reader reader = getReader(context, progressListener, "deleteUser", null, Arrays.asList("username"), Arrays.<Object>asList(username));
+ try {
+ new ErrorParser(context).parse(reader);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public void changePassword(String username, String password, Context context, ProgressListener progressListener) throws Exception {
+ Reader reader = getReader(context, progressListener, "changePassword", null, Arrays.asList("username", "password"), Arrays.<Object>asList(username, password));
+ try {
+ new ErrorParser(context).parse(reader);
+ } finally {
+ Util.close(reader);
+ }
+ }
+
+ @Override
+ public Bitmap getAvatar(String username, Context context, ProgressListener progressListener) throws Exception {
+ return null;
+ }
+
+ @Override
public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{
return processOfflineScrobbles(context, progressListener) + processOfflineStars(context, progressListener);
}
diff --git a/src/github/daneren2005/dsub/service/parser/UserParser.java b/src/github/daneren2005/dsub/service/parser/UserParser.java
new file mode 100644
index 00000000..a66e0b63
--- /dev/null
+++ b/src/github/daneren2005/dsub/service/parser/UserParser.java
@@ -0,0 +1,73 @@
+/*
+ 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 2014 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.service.parser;
+
+import android.content.Context;
+
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+import github.daneren2005.dsub.domain.User;
+import github.daneren2005.dsub.util.ProgressListener;
+
+public class UserParser extends AbstractParser {
+
+ public UserParser(Context context) {
+ super(context);
+ }
+
+ public List<User> parse(Reader reader, ProgressListener progressListener) throws Exception {
+ init(reader);
+ List<User> result = new ArrayList<User>();
+ int eventType;
+
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+ if ("user".equals(name)) {
+ User user = new User();
+
+ user.setUsername(get("username"));
+ user.setEmail(get("email"));
+ user.setScrobblingEnabled(getBoolean("scrobblingEnabled"));
+ user.setAdminRole(getBoolean("adminRole"));
+ user.setSettingsRole(getBoolean("settingsRole"));
+ user.setDownloadRole(getBoolean("downloadRole"));
+ user.setUploadRole(getBoolean("uploadRole"));
+ user.setPlaylistRole(getBoolean("playlistRole"));
+ user.setCoverArtRole(getBoolean("coverArtRole"));
+ user.setCommentRole(getBoolean("commentRole"));
+ user.setPodcastRole(getBoolean("podcastRole"));
+ user.setStreamRole(getBoolean("streamRole"));
+ user.setJukeboxRole(getBoolean("jukeboxRole"));
+ user.setShareRole(getBoolean("shareRole"));
+
+ result.add(user);
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+
+ return result;
+ }
+} \ No newline at end of file
diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java
index 2b7f8757..34bf734d 100644
--- a/src/github/daneren2005/dsub/util/Constants.java
+++ b/src/github/daneren2005/dsub/util/Constants.java
@@ -141,6 +141,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_OVERRIDE_SYSTEM_LANGUAGE = "overrideSystemLanguage";
public static final String PREFERENCES_KEY_PLAY_NOW_AFTER = "playNowAfter";
public static final String PREFERENCES_KEY_LARGE_ALBUM_ART = "largeAlbumArt";
+ public static final String PREFERENCES_KEY_ADMIN_ENABLED = "adminEnabled";
public static final String OFFLINE_SCROBBLE_COUNT = "scrobbleCount";
public static final String OFFLINE_SCROBBLE_ID = "scrobbleID";
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java
index b62b3382..dad557e3 100644
--- a/src/github/daneren2005/dsub/util/Util.java
+++ b/src/github/daneren2005/dsub/util/Util.java
@@ -169,6 +169,11 @@ public final class Util {
SharedPreferences prefs = getPreferences(context);
return prefs.getBoolean(Constants.PREFERENCES_KEY_OFFLINE, false) ? 0 : prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
}
+
+ public static String getCurrentUsername(Context context) {
+ SharedPreferences prefs = getPreferences(context);
+ return prefs.getString(Constants.PREFERENCES_KEY_USERNAME + getActiveServer(context), null);
+ }
public static boolean checkServerVersion(Context context, String requiredVersion) {
Version version = Util.getServerRestVersion(context);
diff --git a/src/github/daneren2005/dsub/view/UserAdapter.java b/src/github/daneren2005/dsub/view/UserAdapter.java
new file mode 100644
index 00000000..937e2e92
--- /dev/null
+++ b/src/github/daneren2005/dsub/view/UserAdapter.java
@@ -0,0 +1,48 @@
+/*
+ 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 2014 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.view;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+
+import java.util.List;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.User;
+
+public class UserAdapter extends ArrayAdapter<User> {
+ private final Context activity;
+
+ public UserAdapter(Context activity, List<User> users) {
+ super(activity, R.layout.basic_list_item, users);
+ this.activity = activity;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ User entry = getItem(position);
+ UserView view;
+ if (convertView != null && convertView instanceof UserView) {
+ view = (UserView) convertView;
+ } else {
+ view = new UserView(activity);
+ }
+ view.setObject(entry);
+ return view;
+ }
+} \ No newline at end of file
diff --git a/src/github/daneren2005/dsub/view/UserView.java b/src/github/daneren2005/dsub/view/UserView.java
new file mode 100644
index 00000000..f966f28f
--- /dev/null
+++ b/src/github/daneren2005/dsub/view/UserView.java
@@ -0,0 +1,50 @@
+/*
+ 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 2014 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.view;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.User;
+
+public class UserView extends UpdateView {
+ private User user;
+
+ private TextView userNameView;
+
+ public UserView(Context context) {
+ super(context);
+ this.context = context;
+ LayoutInflater.from(context).inflate(R.layout.basic_list_item, this, true);
+
+ userNameView = (TextView) findViewById(R.id.item_name);
+ moreButton = (ImageView) findViewById(R.id.item_more);
+ moreButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ v.showContextMenu();
+ }
+ });
+ }
+
+ protected void setObjectImpl(Object obj) {
+ this.user = (User) obj;
+ userNameView.setText(user.getUsername());
+ }
+}