aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github/daneren2005/dsub/service/parser/UserParser.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/github/daneren2005/dsub/service/parser/UserParser.java')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/parser/UserParser.java46
1 files changed, 42 insertions, 4 deletions
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);