aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/SettingsAdapter.java59
-rw-r--r--app/src/main/java/github/daneren2005/dsub/domain/MusicFolder.java8
-rw-r--r--app/src/main/java/github/daneren2005/dsub/domain/User.java34
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/UserFragment.java4
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/parser/UserParser.java46
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/SettingView.java5
-rw-r--r--app/src/main/res/values/strings.xml2
7 files changed, 131 insertions, 27 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/SettingsAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/SettingsAdapter.java
index 1cb9c34e..112778e3 100644
--- a/app/src/main/java/github/daneren2005/dsub/adapter/SettingsAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/SettingsAdapter.java
@@ -23,11 +23,15 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.domain.User;
import github.daneren2005.dsub.util.ImageLoader;
+import github.daneren2005.dsub.util.UserUtil;
import github.daneren2005.dsub.view.RecyclingImageView;
import github.daneren2005.dsub.view.SettingView;
import github.daneren2005.dsub.view.UpdateView;
@@ -42,8 +46,8 @@ public class SettingsAdapter extends SectionAdapter<Setting> {
private final boolean editable;
private final ImageLoader imageLoader;
- public SettingsAdapter(Context context, User user, ImageLoader imageLoader, boolean editable, OnItemClickedListener<Setting> onItemClickedListener) {
- super(context, user.getSettings(), imageLoader != null);
+ public SettingsAdapter(Context context, User user, List<String> headers, List<List<User.Setting>> settingSections, ImageLoader imageLoader, boolean editable, OnItemClickedListener<Setting> onItemClickedListener) {
+ super(context, headers, settingSections, imageLoader != null);
this.user = user;
this.imageLoader = imageLoader;
this.editable = editable;
@@ -62,25 +66,29 @@ public class SettingsAdapter extends SectionAdapter<Setting> {
return new UpdateView.UpdateViewHolder(header, false);
}
public void onBindHeaderHolder(UpdateView.UpdateViewHolder holder, String description) {
- View header = holder.getView();
-
- RecyclingImageView coverArtView = (RecyclingImageView) header.findViewById(R.id.user_avatar);
- imageLoader.loadAvatar(context, coverArtView, user.getUsername());
- coverArtView.setOnInvalidated(new RecyclingImageView.OnInvalidated() {
- @Override
- public void onInvalidated(RecyclingImageView imageView) {
- imageLoader.loadAvatar(context, imageView, user.getUsername());
+ if(description == null) {
+ View header = holder.getView();
+
+ RecyclingImageView coverArtView = (RecyclingImageView) header.findViewById(R.id.user_avatar);
+ imageLoader.loadAvatar(context, coverArtView, user.getUsername());
+ coverArtView.setOnInvalidated(new RecyclingImageView.OnInvalidated() {
+ @Override
+ public void onInvalidated(RecyclingImageView imageView) {
+ imageLoader.loadAvatar(context, imageView, user.getUsername());
+ }
+ });
+
+ TextView usernameView = (TextView) header.findViewById(R.id.user_username);
+ usernameView.setText(user.getUsername());
+
+ final TextView emailView = (TextView) header.findViewById(R.id.user_email);
+ if (user.getEmail() != null) {
+ emailView.setText(user.getEmail());
+ } else {
+ emailView.setVisibility(View.GONE);
}
- });
-
- TextView usernameView = (TextView) header.findViewById(R.id.user_username);
- usernameView.setText(user.getUsername());
-
- final TextView emailView = (TextView) header.findViewById(R.id.user_email);
- if(user.getEmail() != null) {
- emailView.setText(user.getEmail());
} else {
- emailView.setVisibility(View.GONE);
+
}
}
@@ -105,4 +113,17 @@ public class SettingsAdapter extends SectionAdapter<Setting> {
updateView.setChecked(checked);
}
}
+
+ public static SettingsAdapter getSettingsAdapter(Context context, User user, ImageLoader imageLoader, OnItemClickedListener<Setting> onItemClickedListener) {
+ List<String> headers = new ArrayList<>();
+ List<List<User.Setting>> settingsSections = new ArrayList<>();
+ settingsSections.add(user.getSettings());
+
+ if(user.getMusicFolderSettings() != null) {
+ headers.add(context.getResources().getString(R.string.admin_permissions));
+ headers.add(context.getResources().getString(R.string.admin_musicFolders));
+ settingsSections.add(user.getMusicFolderSettings());
+ }
+ return new SettingsAdapter(context, user, headers, settingsSections, imageLoader, UserUtil.isCurrentAdmin() && ServerInfo.checkServerVersion(context, "1.10"), onItemClickedListener);
+ }
}
diff --git a/app/src/main/java/github/daneren2005/dsub/domain/MusicFolder.java b/app/src/main/java/github/daneren2005/dsub/domain/MusicFolder.java
index 99e86e23..12ca5909 100644
--- a/app/src/main/java/github/daneren2005/dsub/domain/MusicFolder.java
+++ b/app/src/main/java/github/daneren2005/dsub/domain/MusicFolder.java
@@ -30,6 +30,7 @@ public class MusicFolder implements Serializable {
private String id;
private String name;
+ private boolean enabled;
public MusicFolder() {
@@ -46,4 +47,11 @@ public class MusicFolder implements Serializable {
public String getName() {
return name;
}
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+ public boolean getEnabled() {
+ return enabled;
+ }
}
diff --git a/app/src/main/java/github/daneren2005/dsub/domain/User.java b/app/src/main/java/github/daneren2005/dsub/domain/User.java
index 797a1271..8186453b 100644
--- a/app/src/main/java/github/daneren2005/dsub/domain/User.java
+++ b/app/src/main/java/github/daneren2005/dsub/domain/User.java
@@ -15,6 +15,8 @@
package github.daneren2005.dsub.domain;
+import android.util.Pair;
+
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -52,6 +54,7 @@ public class User implements Serializable {
private String email;
private List<Setting> settings = new ArrayList<Setting>();
+ private List<Setting> musicFolders;
public User() {
@@ -92,9 +95,20 @@ public class User implements Serializable {
settings.add(new Setting(name, value));
}
+ public void addMusicFolder(MusicFolder musicFolder) {
+ if(musicFolders == null) {
+ musicFolders = new ArrayList<>();
+ }
+
+ musicFolders.add(new MusicFolderSetting(musicFolder.getId(), musicFolder.getName(), false));
+ }
+ public List<Setting> getMusicFolderSettings() {
+ return musicFolders;
+ }
+
public static class Setting implements Serializable {
- String name;
- Boolean value;
+ private String name;
+ private Boolean value;
public Setting() {
@@ -114,4 +128,20 @@ public class User implements Serializable {
this.value = value;
}
}
+
+ public static class MusicFolderSetting extends Setting {
+ private String label;
+
+ public MusicFolderSetting() {
+
+ }
+ public MusicFolderSetting(String name, String label, Boolean value) {
+ super(name, value);
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+ }
}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/UserFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/UserFragment.java
index dab104bd..dde76624 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/UserFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/UserFragment.java
@@ -20,6 +20,8 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import github.daneren2005.dsub.R;
@@ -78,7 +80,7 @@ public class UserFragment extends SelectRecyclerFragment<User.Setting>{
@Override
public SectionAdapter<User.Setting> getAdapter(List<User.Setting> objs) {
- return new SettingsAdapter(context, user, getImageLoader(), UserUtil.isCurrentAdmin() && ServerInfo.checkServerVersion(context, "1.10"), this);
+ return SettingsAdapter.getSettingsAdapter(context, user, getImageLoader(), this);
}
@Override
diff --git a/app/src/main/java/github/daneren2005/dsub/service/parser/UserParser.java b/app/src/main/java/github/daneren2005/dsub/service/parser/UserParser.java
index e20556c0..fd228a7c 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/parser/UserParser.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/parser/UserParser.java
@@ -16,6 +16,7 @@
package github.daneren2005.dsub.service.parser;
import android.content.Context;
+import android.util.Log;
import org.xmlpull.v1.XmlPullParser;
@@ -23,10 +24,16 @@ import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
+import github.daneren2005.dsub.domain.MusicFolder;
import github.daneren2005.dsub.domain.User;
+import github.daneren2005.dsub.domain.User.MusicFolderSetting;
+import github.daneren2005.dsub.domain.User.Setting;
+import github.daneren2005.dsub.service.MusicService;
+import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.util.ProgressListener;
public class UserParser extends AbstractParser {
+ private static final String TAG = UserParser.class.getSimpleName();
public UserParser(Context context, int instance) {
super(context, instance);
@@ -35,14 +42,17 @@ public class UserParser extends AbstractParser {
public List<User> parse(Reader reader, ProgressListener progressListener) throws Exception {
init(reader);
List<User> result = new ArrayList<User>();
+ List<MusicFolder> musicFolders = null;
+ User user = null;
int eventType;
+ String tagName = null;
do {
eventType = nextParseEvent();
if (eventType == XmlPullParser.START_TAG) {
- String name = getElementName();
- if ("user".equals(name)) {
- User user = new User();
+ tagName = getElementName();
+ if ("user".equals(tagName)) {
+ user = new User();
user.setUsername(get("username"));
user.setEmail(get("email"));
@@ -53,9 +63,32 @@ public class UserParser extends AbstractParser {
parseSetting(user, User.LASTFM);
result.add(user);
- } else if ("error".equals(name)) {
+ } else if ("error".equals(tagName)) {
handleError();
}
+ } else if(eventType == XmlPullParser.TEXT) {
+ if("folder".equals(tagName)) {
+ String id = getText();
+ Log.d(TAG, "id: " + id);
+ if(musicFolders == null) {
+ musicFolders = getMusicFolders();
+ }
+
+ if(user != null) {
+ if(user.getMusicFolderSettings() == null) {
+ for (MusicFolder musicFolder : musicFolders) {
+ user.addMusicFolder(musicFolder);
+ }
+ }
+
+ for(Setting musicFolder: user.getMusicFolderSettings()) {
+ if(musicFolder.getName().equals(id)) {
+ musicFolder.setValue(true);
+ break;
+ }
+ }
+ }
+ }
}
} while (eventType != XmlPullParser.END_DOCUMENT);
@@ -63,6 +96,11 @@ public class UserParser extends AbstractParser {
return result;
}
+
+ private List<MusicFolder> getMusicFolders() throws Exception{
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ return musicService.getMusicFolders(false, context, null);
+ }
private void parseSetting(User user, String name) {
String value = get(name);
diff --git a/app/src/main/java/github/daneren2005/dsub/view/SettingView.java b/app/src/main/java/github/daneren2005/dsub/view/SettingView.java
index d46dc5d2..ba63c52a 100644
--- a/app/src/main/java/github/daneren2005/dsub/view/SettingView.java
+++ b/app/src/main/java/github/daneren2005/dsub/view/SettingView.java
@@ -23,6 +23,7 @@ import android.widget.TextView;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.User;
+import github.daneren2005.dsub.domain.User.MusicFolderSetting;
import static github.daneren2005.dsub.domain.User.Setting;
@@ -56,7 +57,9 @@ public class SettingView extends UpdateView2<Setting, Boolean> {
}
int res = -1;
- if(User.SCROBBLING.equals(name)) {
+ if(setting instanceof MusicFolderSetting) {
+ titleView.setText(((MusicFolderSetting) setting).getLabel());
+ } else if(User.SCROBBLING.equals(name)) {
res = R.string.admin_scrobblingEnabled;
} else if(User.ADMIN.equals(name)) {
res = R.string.admin_role_admin;
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b7efff1a..54520cce 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -532,6 +532,8 @@
<string name="admin.delete_user_error">Failed to delete %1$s</string>
<string name="admin.confirm_password">Confirm Password</string>
<string name="admin.confirm_password_bad">Entered password is wrong</string>
+ <string name="admin.permissions">Permissions</string>
+ <string name="admin.musicFolders">Music Folders</string>
<string name="admin.scrobblingEnabled">Scrobbling allowed</string>
<string name="admin.role.admin">Administrator</string>