aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-02-04 18:15:37 -0800
committerScott Jackson <daneren2005@gmail.com>2016-02-04 18:15:37 -0800
commit96f0553dcd8ce4867a689e4026c159bc565a1282 (patch)
tree276978de02a14be394a3c2c5cf620ddea4a0db3d
parentfc4a916e766ac7f6c5893c823dec05bfc2ed963e (diff)
downloaddsub-96f0553dcd8ce4867a689e4026c159bc565a1282.tar.gz
dsub-96f0553dcd8ce4867a689e4026c159bc565a1282.tar.bz2
dsub-96f0553dcd8ce4867a689e4026c159bc565a1282.zip
#456 Allow specifying music folders when adding
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/SettingsAdapter.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/domain/User.java7
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java9
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/UserUtil.java11
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/SettingView.java2
6 files changed, 28 insertions, 5 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 b4456aa0..d1deaf6f 100644
--- a/app/src/main/java/github/daneren2005/dsub/adapter/SettingsAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/SettingsAdapter.java
@@ -67,7 +67,7 @@ public class SettingsAdapter extends SectionAdapter<Setting> {
public int getItemViewType(int position) {
int viewType = super.getItemViewType(position);
if(viewType == SectionAdapter.VIEW_TYPE_HEADER) {
- if(position == 0) {
+ if(position == 0 && imageLoader != null) {
return VIEW_TYPE_HEADER;
} else {
return VIEW_TYPE_SETTING_HEADER;
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 8186453b..b5ee6188 100644
--- a/app/src/main/java/github/daneren2005/dsub/domain/User.java
+++ b/app/src/main/java/github/daneren2005/dsub/domain/User.java
@@ -102,6 +102,13 @@ public class User implements Serializable {
musicFolders.add(new MusicFolderSetting(musicFolder.getId(), musicFolder.getName(), false));
}
+ public void addMusicFolder(MusicFolderSetting musicFolderSetting, boolean defaultValue) {
+ if(musicFolders == null) {
+ musicFolders = new ArrayList<>();
+ }
+
+ musicFolders.add(new MusicFolderSetting(musicFolderSetting.getName(), musicFolderSetting.getLabel(), defaultValue));
+ }
public List<Setting> getMusicFolderSettings() {
return musicFolders;
}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java
index 630acf2c..187f0d55 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/AdminFragment.java
@@ -47,7 +47,7 @@ public class AdminFragment extends SelectRecyclerFragment<User> {
switch (item.getItemId()) {
case R.id.menu_add_user:
- UserUtil.addNewUser(context, this);
+ UserUtil.addNewUser(context, this, objects.get(0));
break;
}
diff --git a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
index a7a68205..a5bb3597 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java
@@ -1499,6 +1499,15 @@ public class RESTMusicService implements MusicService {
values.add(setting.getValue());
}
+ if(user.getMusicFolderSettings() != null) {
+ for(User.Setting setting: user.getMusicFolderSettings()) {
+ if(setting.getValue()) {
+ names.add("musicFolderId");
+ values.add(setting.getName());
+ }
+ }
+ }
+
Reader reader = getReader(context, progressListener, "createUser", null, names, values);
try {
new ErrorParser(context, getInstance(context)).parse(reader);
diff --git a/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java b/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java
index 6417dc81..bf5d3a29 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/UserUtil.java
@@ -373,7 +373,7 @@ public final class UserUtil {
});
}
- public static void addNewUser(final Activity context, final SubsonicFragment fragment) {
+ public static void addNewUser(final Activity context, final SubsonicFragment fragment, User sampleUser) {
final User user = new User();
for(String role: User.ROLES) {
if(role.equals(User.SETTINGS) || role.equals(User.STREAM)) {
@@ -383,6 +383,13 @@ public final class UserUtil {
}
}
+ if(sampleUser.getMusicFolderSettings() != null) {
+ for(User.Setting setting: sampleUser.getMusicFolderSettings()) {
+ User.MusicFolderSetting musicFolderSetting = (User.MusicFolderSetting) setting;
+ user.addMusicFolder(musicFolderSetting, false);
+ }
+ }
+
View layout = context.getLayoutInflater().inflate(R.layout.create_user, null);
final TextView usernameView = (TextView) layout.findViewById(R.id.username);
final TextView emailView = (TextView) layout.findViewById(R.id.email);
@@ -391,7 +398,7 @@ public final class UserUtil {
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
- recyclerView.setAdapter(new SettingsAdapter(context, user, null, true, new SectionAdapter.OnItemClickedListener<User.Setting>() {
+ recyclerView.setAdapter(SettingsAdapter.getSettingsAdapter(context, user, null, true, new SectionAdapter.OnItemClickedListener<User.Setting>() {
@Override
public void onItemClicked(UpdateView<User.Setting> updateView, User.Setting item) {
if(updateView.isCheckable()) {
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 ba63c52a..efd8bc83 100644
--- a/app/src/main/java/github/daneren2005/dsub/view/SettingView.java
+++ b/app/src/main/java/github/daneren2005/dsub/view/SettingView.java
@@ -52,7 +52,7 @@ public class SettingView extends UpdateView2<Setting, Boolean> {
protected void setObjectImpl(Setting setting, Boolean isEditable) {
// Can't edit non-role parts
String name = setting.getName();
- if(name.indexOf("Role") == -1) {
+ if(name.indexOf("Role") == -1 && !(setting instanceof MusicFolderSetting)) {
item2 = false;
}