From 96f0553dcd8ce4867a689e4026c159bc565a1282 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 4 Feb 2016 18:15:37 -0800 Subject: #456 Allow specifying music folders when adding --- .../java/github/daneren2005/dsub/adapter/SettingsAdapter.java | 2 +- app/src/main/java/github/daneren2005/dsub/domain/User.java | 7 +++++++ .../java/github/daneren2005/dsub/fragments/AdminFragment.java | 2 +- .../github/daneren2005/dsub/service/RESTMusicService.java | 9 +++++++++ app/src/main/java/github/daneren2005/dsub/util/UserUtil.java | 11 +++++++++-- .../main/java/github/daneren2005/dsub/view/SettingView.java | 2 +- 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 { 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 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 { 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() { + recyclerView.setAdapter(SettingsAdapter.getSettingsAdapter(context, user, null, true, new SectionAdapter.OnItemClickedListener() { @Override public void onItemClicked(UpdateView 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 { 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; } -- cgit v1.2.3