aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-01-29 17:25:30 -0800
committerScott Jackson <daneren2005@gmail.com>2016-01-29 17:25:30 -0800
commit4b702ea9eed062efb6b220913d568d4d719a629b (patch)
tree2ba40ad8fd63d550497c8d3f7164646c415fd898 /app/src/main/java
parent2153ff1bee4c7826ea902b1f1fddf2d2933b2b5b (diff)
downloaddsub-4b702ea9eed062efb6b220913d568d4d719a629b.tar.gz
dsub-4b702ea9eed062efb6b220913d568d4d719a629b.tar.bz2
dsub-4b702ea9eed062efb6b220913d568d4d719a629b.zip
#456 start of music folder admin
Diffstat (limited to 'app/src/main/java')
-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
6 files changed, 129 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;