示例#1
0
 public void fillView(User user) {
   TextView textView1 = (TextView) findViewById(R.id.textview1);
   textView1.setText(user.getName());
   if (mLayoutId == R.layout.list_item_user) {
     TextView textView2 = (TextView) findViewById(R.id.textview2);
     textView2.setText(
         TomahawkApp.getContext()
             .getString(
                 R.string.followers_count, user.getFollowersCount(), user.getFollowCount()));
   }
   TextView userTextView1 = (TextView) findViewById(R.id.usertextview1);
   ImageView userImageView1 = (ImageView) findViewById(R.id.userimageview1);
   TomahawkUtils.loadUserImageIntoImageView(
       TomahawkApp.getContext(), userImageView1, user, Image.getSmallImageSize(), userTextView1);
 }
 /**
  * Load a circle-shaped {@link android.graphics.Bitmap} asynchronously
  *
  * @param context the context needed for fetching resources
  * @param imageView the {@link android.widget.ImageView}, which will be used to show the {@link
  *     android.graphics.Bitmap}
  * @param user the user of which to load the data into the views
  * @param width the width in pixels to scale the image down to
  * @param textView the textview which is being used to display the first letter of the user's name
  *     in the placeholder image
  */
 public static void loadUserImageIntoImageView(
     Context context, ImageView imageView, User user, int width, TextView textView) {
   int placeHolder = R.drawable.circle_black;
   if (user.getImage() != null && !TextUtils.isEmpty(user.getImage().getImagePath())) {
     textView.setVisibility(View.GONE);
     String imagePath = buildImagePath(user.getImage(), width);
     Picasso.with(context)
         .load(TomahawkUtils.preparePathForPicasso(imagePath))
         .transform(new CircularImageTransformation())
         .placeholder(placeHolder)
         .error(placeHolder)
         .fit()
         .into(imageView);
   } else {
     textView.setVisibility(View.VISIBLE);
     textView.setText(user.getName().substring(0, 1).toUpperCase());
     Picasso.with(context)
         .load(placeHolder)
         .placeholder(placeHolder)
         .error(placeHolder)
         .fit()
         .into(imageView);
   }
 }
 private void showAddToPlaylist(final TomahawkMainActivity activity, final List<Query> queries) {
   User.getSelf()
       .done(
           new DoneCallback<User>() {
             @Override
             public void onDone(User user) {
               ArrayList<String> queryKeys = new ArrayList<>();
               for (Query query : queries) {
                 queryKeys.add(query.getCacheKey());
               }
               Bundle bundle = new Bundle();
               bundle.putString(TomahawkFragment.USER, user.getId());
               bundle.putInt(
                   TomahawkFragment.CONTENT_HEADER_MODE, ContentHeaderFragment.MODE_HEADER_STATIC);
               bundle.putStringArrayList(TomahawkFragment.QUERYARRAY, queryKeys);
               FragmentUtils.replace(activity, PlaylistsFragment.class, bundle);
             }
           });
 }
  @Override
  public void onResume() {
    super.onResume();

    User.getSelf()
        .done(
            new DoneCallback<User>() {
              @Override
              public void onDone(User user) {
                if (mUser != null) {
                  if (mShowMode == SHOW_MODE_PLAYBACKLOG) {
                    String requestId = InfoSystem.get().resolvePlaybackLog(mUser);
                    if (requestId != null) {
                      mCorrespondingRequestIds.add(requestId);
                    }
                  } else if (mShowMode == SHOW_MODE_LOVEDITEMS) {
                    mHideRemoveButton = true;
                    if (mUser == user) {
                      CollectionManager.get().fetchLovedItemsPlaylist();
                    } else {
                      String requestId = InfoSystem.get().resolveLovedItems(mUser);
                      if (requestId != null) {
                        mCorrespondingRequestIds.add(requestId);
                      }
                    }
                  }
                  if (mUser != user) {
                    mHideRemoveButton = true;
                  } else {
                    CollectionManager.get().fetchPlaylists();
                  }
                } else {
                  mHideRemoveButton = true;
                }
                updateAdapter();
              }
            });
    if (mContainerFragmentClass == null) {
      getActivity().setTitle("");
    }
  }
示例#5
0
 static {
   mSelf.setName("Myself");
   mSelf.setIsOffline(true);
 }
  /**
   * Update this {@link org.tomahawk.tomahawk_android.fragments.TomahawkFragment}'s {@link
   * org.tomahawk.tomahawk_android.adapters.TomahawkListAdapter} content
   */
  @Override
  protected void updateAdapter() {
    if (!mIsResumed) {
      return;
    }

    if (mAlbum != null) {
      showContentHeader(mAlbum);
      if (mContainerFragmentClass == null) {
        showAlbumFancyDropDown();
      }
      mCollection
          .getAlbumTracks(mAlbum)
          .done(
              new DoneCallback<Playlist>() {
                @Override
                public void onDone(Playlist playlist) {
                  mCurrentPlaylist = playlist;
                  Segment.Builder builder =
                      new Segment.Builder(playlist)
                          .headerLayout(R.layout.single_line_list_header)
                          .headerString(mAlbum.getArtist().getPrettyName());
                  if (playlist != null && playlist.allFromOneArtist()) {
                    builder.hideArtistName(true);
                    builder.showDuration(true);
                  }
                  builder.showNumeration(true, 1);
                  fillAdapter(builder.build());
                }
              });
    } else if (mUser != null || mPlaylist != null) {
      if (mUser != null) {
        if (mShowMode == SHOW_MODE_PLAYBACKLOG) {
          mCurrentPlaylist = mUser.getPlaybackLog();
        } else if (mShowMode == SHOW_MODE_LOVEDITEMS) {
          mCurrentPlaylist = mUser.getFavorites();
        }
      }
      if (mPlaylist != null) {
        mCurrentPlaylist = mPlaylist;
      }
      if (!mCurrentPlaylist.isFilled()) {
        User.getSelf()
            .done(
                new DoneCallback<User>() {
                  @Override
                  public void onDone(User user) {
                    if (mShowMode < 0) {
                      if (mUser != user) {
                        String requestId = InfoSystem.get().resolve(mCurrentPlaylist);
                        if (requestId != null) {
                          mCorrespondingRequestIds.add(requestId);
                        }
                      } else if (mPlaylist != null) {
                        mPlaylist = DatabaseHelper.get().getPlaylist(mPlaylist.getId());
                        updateAdapter();
                      }
                    }
                  }
                });
      } else {
        Segment.Builder builder = new Segment.Builder(mCurrentPlaylist);
        if (mContainerFragmentClass == null
            || !mContainerFragmentClass.equals(SearchPagerFragment.class.getName())) {
          builder.showNumeration(true, 1);
          if (mContainerFragmentClass == null
              || !mContainerFragmentClass.equals(ChartsPagerFragment.class.getName())) {
            builder
                .headerLayout(R.layout.single_line_list_header)
                .headerString(R.string.playlist_details);
          }
        } else if (mContainerFragmentClass.equals(SearchPagerFragment.class.getName())) {
          builder.showResolverIcon(true);
        }
        Segment segment = builder.build();
        fillAdapter(segment);
        showContentHeader(mCurrentPlaylist);
        showFancyDropDown(0, mCurrentPlaylist.getName(), null, null);
        ThreadManager.get()
            .execute(
                new TomahawkRunnable(TomahawkRunnable.PRIORITY_IS_INFOSYSTEM_LOW) {
                  @Override
                  public void run() {
                    if (mCurrentPlaylist.getTopArtistNames() == null
                        || mCurrentPlaylist.getTopArtistNames().length == 0) {
                      boolean isFavorites =
                          mUser != null && mCurrentPlaylist == mUser.getFavorites();
                      mCurrentPlaylist.updateTopArtistNames(isFavorites);
                    } else {
                      for (int i = 0;
                          i < mCurrentPlaylist.getTopArtistNames().length && i < 5;
                          i++) {
                        String artistName = mCurrentPlaylist.getTopArtistNames()[i];
                        if (!mResolvingTopArtistNames.contains(artistName)) {
                          String requestId =
                              InfoSystem.get().resolve(Artist.get(artistName), false);
                          if (requestId != null) {
                            mCorrespondingRequestIds.add(requestId);
                          }
                          mResolvingTopArtistNames.add(artistName);
                        }
                      }
                    }
                  }
                });
      }
    } else {
      mCollection
          .getQueries(getSortMode())
          .done(
              new DoneCallback<Playlist>() {
                @Override
                public void onDone(final Playlist playlist) {
                  new Thread(
                          new Runnable() {
                            @Override
                            public void run() {
                              mCurrentPlaylist = playlist;
                              String id = mCollection.getId();
                              Segment segment =
                                  new Segment.Builder(playlist)
                                      .headerLayout(R.layout.dropdown_header)
                                      .headerStrings(constructDropdownItems())
                                      .spinner(
                                          constructDropdownListener(
                                              COLLECTION_TRACKS_SPINNER_POSITION + id),
                                          getDropdownPos(COLLECTION_TRACKS_SPINNER_POSITION + id))
                                      .build();
                              fillAdapter(segment);
                            }
                          })
                      .start();
                }
              });
    }
  }
示例#7
0
  public List storeRecords(
      JsonObject object,
      int resultType,
      int requestType,
      boolean isBackgroundRequest,
      QueryParams params)
      throws IOException {
    List results = new ArrayList();
    JsonElement elements = object.get("images");
    if (elements instanceof JsonArray) {
      for (JsonElement element : (JsonArray) elements) {
        if (element instanceof JsonObject) {
          JsonObject o = (JsonObject) element;
          String id = getAsString(o, "id");
          Image image = (Image) mCache.get(TYPE_IMAGES).get(id);
          if (image == null) {
            String url = getAsString(o, "url");
            int width = getAsInt(o, "width");
            int height = getAsInt(o, "height");
            image = Image.get(url, true, width, height);
            mCache.get(TYPE_IMAGES).put(id, image);
          }
          if (resultType == TYPE_IMAGES) {
            results.add(image);
          }
        }
      }
    }
    elements = object.get("artists");
    if (elements instanceof JsonArray) {
      for (JsonElement element : (JsonArray) elements) {
        if (element instanceof JsonObject) {
          JsonObject o = (JsonObject) element;
          String id = getAsString(o, "id");
          Artist artist = (Artist) mCache.get(TYPE_ARTISTS).get(id);
          if (artist == null) {
            String name = getAsString(o, "name");
            String wiki = getAsString(o, "wikiabstract");
            artist = Artist.get(name);
            artist.setBio(new ListItemString(wiki));
            JsonElement images = get(o, "images");
            if (images instanceof JsonArray && ((JsonArray) images).size() > 0) {
              String imageId = ((JsonArray) images).get(0).getAsString();
              Image image = (Image) findRecord(imageId, TYPE_IMAGES, isBackgroundRequest);
              artist.setImage(image);
            }
            mCache.get(TYPE_ARTISTS).put(id, artist);
          }

          if (requestType == InfoRequestData.INFOREQUESTDATA_TYPE_ARTISTS_ALBUMS) {
            JsonElement rawAlbums = get(o, "albums");
            if (rawAlbums instanceof JsonObject) {
              results.addAll(
                  storeRecords((JsonObject) rawAlbums, TYPE_ALBUMS, isBackgroundRequest));
            }
          } else if (requestType == InfoRequestData.INFOREQUESTDATA_TYPE_ARTISTS_TOPHITS) {
            JsonElement rawTopHits = get(o, "topHits");
            if (rawTopHits instanceof JsonObject) {
              results.addAll(
                  storeRecords((JsonObject) rawTopHits, TYPE_TRACKS, isBackgroundRequest));
            }
          }
          if (resultType == TYPE_ARTISTS) {
            results.add(artist);
          }
        }
      }
    }
    elements = object.get("albums");
    if (elements instanceof JsonArray) {
      for (JsonElement element : (JsonArray) elements) {
        if (element instanceof JsonObject) {
          JsonObject o = (JsonObject) element;
          String id = getAsString(o, "id");
          Album album = (Album) mCache.get(TYPE_ALBUMS).get(id);
          if (album == null) {
            String name = getAsString(o, "name");
            String artistId = getAsString(o, "artist");
            Artist artist = (Artist) findRecord(artistId, TYPE_ARTISTS, isBackgroundRequest);
            album = Album.get(name, artist);
            JsonElement images = get(o, "images");
            if (images instanceof JsonArray && ((JsonArray) images).size() > 0) {
              String imageId = ((JsonArray) images).get(0).getAsString();
              Image image = (Image) findRecord(imageId, TYPE_IMAGES, isBackgroundRequest);
              album.setImage(image);
            }
            mCache.get(TYPE_ALBUMS).put(id, album);
          }

          if (requestType == InfoRequestData.INFOREQUESTDATA_TYPE_ALBUMS_TRACKS) {
            JsonElement rawTracks = get(o, "tracks");
            if (rawTracks instanceof JsonObject) {
              results.addAll(
                  storeRecords((JsonObject) rawTracks, TYPE_TRACKS, isBackgroundRequest));
            }
          }
          if (resultType == TYPE_ALBUMS) {
            results.add(album);
          }
        }
      }
    }
    elements = object.get("tracks");
    if (elements instanceof JsonArray) {
      for (JsonElement element : (JsonArray) elements) {
        if (element instanceof JsonObject) {
          JsonObject o = (JsonObject) element;
          String id = getAsString(o, "id");
          Query query = (Query) mCache.get(TYPE_TRACKS).get(id);
          if (query == null) {
            String name = getAsString(o, "name");
            String artistId = getAsString(o, "artist");
            Artist artist = (Artist) findRecord(artistId, TYPE_ARTISTS, isBackgroundRequest);
            query = Query.get(name, null, artist.getName(), false, true);
            mCache.get(TYPE_TRACKS).put(id, query);
          }
          if (resultType == TYPE_TRACKS) {
            results.add(query);
          }
        }
      }
    }
    elements = object.get("users");
    if (elements instanceof JsonArray) {
      for (JsonElement element : (JsonArray) elements) {
        if (element instanceof JsonObject) {
          JsonObject o = (JsonObject) element;
          String id = getAsString(o, "id");
          User user = User.get(id);
          String name = getAsString(o, "name");
          user.setName(name);
          String about = getAsString(o, "about");
          user.setAbout(about);
          int followersCount = getAsInt(o, "followersCount");
          user.setFollowersCount(followersCount);
          int followCount = getAsInt(o, "followCount");
          user.setFollowCount(followCount);
          String nowplayingId = getAsString(o, "nowplaying");
          if (nowplayingId != null) {
            Query nowplaying = (Query) findRecord(nowplayingId, TYPE_TRACKS, isBackgroundRequest);
            user.setNowPlaying(nowplaying);
          }
          String nowplayingtimestamp = getAsString(o, "nowplayingtimestamp");
          user.setNowPlayingTimeStamp(ISO8601Utils.parse(nowplayingtimestamp));
          String avatar = getAsString(o, "avatar");
          if (avatar != null) {
            Image image = (Image) findRecord(avatar, TYPE_IMAGES, isBackgroundRequest);
            user.setImage(image);
          }

          if (requestType == InfoRequestData.INFOREQUESTDATA_TYPE_USERS_PLAYLISTS) {
            JsonElement rawPlaylists = get(o, "playlists");
            if (rawPlaylists instanceof JsonObject) {
              List playlists =
                  storeRecords((JsonObject) rawPlaylists, TYPE_PLAYLISTS, isBackgroundRequest);
              user.setPlaylists(playlists);
            }
          } else if (requestType == InfoRequestData.INFOREQUESTDATA_TYPE_USERS_LOVEDITEMS) {
            JsonElement rawLovedItems = get(o, "lovedItems");
            if (rawLovedItems instanceof JsonObject) {
              List playlists =
                  storeRecords((JsonObject) rawLovedItems, TYPE_PLAYLISTS, isBackgroundRequest);
              if (playlists != null && playlists.size() > 0) {
                user.setFavorites((Playlist) playlists.get(0));
              }
            }
          } else if (requestType == InfoRequestData.INFOREQUESTDATA_TYPE_USERS_LOVEDALBUMS) {
            JsonElement rawLovedAlbums = get(o, "lovedAlbums");
            if (rawLovedAlbums instanceof JsonObject) {
              List albums =
                  storeRecords((JsonObject) rawLovedAlbums, TYPE_ALBUMS, isBackgroundRequest);
              user.setStarredAlbums(albums);
            }
          } else if (requestType == InfoRequestData.INFOREQUESTDATA_TYPE_USERS_LOVEDARTISTS) {
            JsonElement rawLovedArtists = get(o, "lovedArtists");
            if (rawLovedArtists instanceof JsonObject) {
              List artists =
                  storeRecords((JsonObject) rawLovedArtists, TYPE_ARTISTS, isBackgroundRequest);
              user.setStarredArtists(artists);
            }
          } else if (requestType == InfoRequestData.INFOREQUESTDATA_TYPE_USERS_PLAYBACKLOG) {
            JsonElement rawPlaybackLog = get(o, "playbacklog");
            if (rawPlaybackLog instanceof JsonObject) {
              List playlists =
                  storeRecords((JsonObject) rawPlaybackLog, TYPE_PLAYLISTS, isBackgroundRequest);
              if (playlists != null && playlists.size() > 0) {
                user.setPlaybackLog((Playlist) playlists.get(0));
              }
            }
          } else if (requestType == InfoRequestData.INFOREQUESTDATA_TYPE_USERS_FOLLOWS
              || requestType == InfoRequestData.INFOREQUESTDATA_TYPE_USERS_FOLLOWERS) {
            boolean isFollows = requestType == InfoRequestData.INFOREQUESTDATA_TYPE_USERS_FOLLOWS;
            JsonElement rawFollows = get(o, isFollows ? "follows" : "followers");
            if (rawFollows instanceof JsonObject) {
              JsonObject follows = (JsonObject) rawFollows;
              storeRecords(follows, -1, isBackgroundRequest);
              JsonElement relationships = get(follows, "relationships");
              if (relationships instanceof JsonArray) {
                TreeMap<User, String> followsMap = new TreeMap<>(new AlphaComparator());
                for (JsonElement relationship : (JsonArray) relationships) {
                  JsonObject relationshipObj = (JsonObject) relationship;
                  String relationshipId = getAsString(relationshipObj, "id");
                  String userId = getAsString(relationshipObj, isFollows ? "targetUser" : "user");
                  User followedUser = (User) findRecord(userId, TYPE_USERS, isBackgroundRequest);
                  followsMap.put(followedUser, relationshipId);
                }
                if (isFollows) {
                  user.setFollowings(followsMap);
                } else {
                  user.setFollowers(followsMap);
                }
              }
            }
          } else if (requestType == InfoRequestData.INFOREQUESTDATA_TYPE_USERS_PLAYBACKLOG) {
            JsonElement rawPlaybackLog = get(o, "playbacklog");
            if (rawPlaybackLog instanceof JsonObject) {
              List playlists =
                  storeRecords((JsonObject) rawPlaybackLog, TYPE_PLAYLISTS, isBackgroundRequest);
              if (playlists != null && playlists.size() > 0) {
                user.setPlaybackLog((Playlist) playlists.get(0));
              }
            }
          }
          mCache.get(TYPE_USERS).put(id, user);
          if (resultType == TYPE_USERS) {
            results.add(user);
          }
        }
      }
    }
    elements = object.get("playlistEntries");
    if (elements instanceof JsonArray) {
      for (JsonElement element : (JsonArray) elements) {
        if (element instanceof JsonObject) {
          JsonObject o = (JsonObject) element;
          String id = getAsString(o, "id");
          Query query = (Query) mCache.get(TYPE_PLAYLISTENTRIES).get(id);
          if (query == null) {
            String trackId = getAsString(o, "track");
            query = (Query) findRecord(trackId, TYPE_TRACKS, isBackgroundRequest);
            mCache.get(TYPE_PLAYLISTENTRIES).put(id, query);
          }
          if (resultType == TYPE_PLAYLISTENTRIES) {
            results.add(query);
          }
        }
      }
    }
    elements = object.get("playlists");
    if (elements instanceof JsonArray) {
      for (JsonElement element : (JsonArray) elements) {
        if (element instanceof JsonObject) {
          JsonObject o = (JsonObject) element;
          String id = getAsString(o, "id");
          String title = getAsString(o, "title");
          String currentrevision = getAsString(o, "currentrevision");
          String localId = DatabaseHelper.get().getPlaylistLocalId(id);
          if (localId == null) {
            localId = id;
          }
          Playlist playlist = null;
          if (requestType == InfoRequestData.INFOREQUESTDATA_TYPE_PLAYLISTS_PLAYLISTENTRIES) {
            JsonElement rawEntries = get(o, "playlistEntries");
            if (rawEntries instanceof JsonObject) {
              List<PlaylistEntry> entries =
                  storeRecords((JsonObject) rawEntries, TYPE_PLAYLISTENTRIES, isBackgroundRequest);
              if (entries != null) {
                playlist = Playlist.fromEntriesList(localId, null, null, entries);
                playlist.setFilled(true);
              }
            }
          } else {
            JsonElement entryIds = o.get("playlistEntries");
            if (entryIds instanceof JsonArray) {
              List<Query> queries = new ArrayList<>();
              for (JsonElement entryId : (JsonArray) entryIds) {
                Query query =
                    (Query)
                        findRecord(
                            entryId.getAsString(), TYPE_PLAYLISTENTRIES, isBackgroundRequest);
                queries.add(query);
              }
              playlist = Playlist.fromQueryList(localId, null, null, queries);
              playlist.setFilled(true);
            }
          }
          if (playlist == null) {
            playlist = Playlist.get(localId);
          }
          playlist.setName(title);
          playlist.setCurrentRevision(currentrevision);
          playlist.setHatchetId(id);
          JsonElement popularArtists = get(o, "popularArtists");
          if (popularArtists instanceof JsonArray) {
            ArrayList<String> topArtistNames = new ArrayList<>();
            for (JsonElement popularArtist : (JsonArray) popularArtists) {
              String artistId = popularArtist.getAsString();
              Artist artist = (Artist) findRecord(artistId, TYPE_ARTISTS, isBackgroundRequest);
              if (artist != null) {
                topArtistNames.add(artist.getName());
              }
            }
            playlist.setTopArtistNames(topArtistNames.toArray(new String[topArtistNames.size()]));
          }
          mCache.get(TYPE_PLAYLISTS).put(id, playlist);
          if (resultType == TYPE_PLAYLISTS) {
            results.add(playlist);
          }
        }
      }
    }
    elements = object.get("playbacklogEntries");
    if (elements instanceof JsonArray) {
      for (JsonElement element : (JsonArray) elements) {
        if (element instanceof JsonObject) {
          JsonObject o = (JsonObject) element;
          String id = getAsString(o, "id");
          Query query = (Query) mCache.get(TYPE_PLAYLISTENTRIES).get(id);
          if (query == null) {
            String trackId = getAsString(o, "track");
            query = (Query) findRecord(trackId, TYPE_TRACKS, isBackgroundRequest);
            mCache.get(TYPE_PLAYLISTENTRIES).put(id, query);
          }
          if (resultType == TYPE_PLAYLISTENTRIES) {
            results.add(query);
          }
        }
      }
    }
    elements = object.get("playbacklogs");
    if (elements instanceof JsonArray) {
      for (JsonElement element : (JsonArray) elements) {
        if (element instanceof JsonObject) {
          JsonObject o = (JsonObject) element;
          String id = getAsString(o, "id");
          JsonArray playbacklogEntries = get(o, "playbacklogEntries").getAsJsonArray();
          ArrayList<Query> queries = new ArrayList<>();
          for (JsonElement entry : playbacklogEntries) {
            String entryId = entry.getAsString();
            Query query = (Query) findRecord(entryId, TYPE_PLAYLISTENTRIES, isBackgroundRequest);
            queries.add(query);
          }
          Playlist playlist =
              Playlist.fromQueryList(
                  TomahawkMainActivity.getLifetimeUniqueStringId(), "Playbacklog", null, queries);
          playlist.setHatchetId(id);
          playlist.setFilled(true);
          mCache.get(TYPE_PLAYLISTS).put(id, playlist);
          if (resultType == TYPE_PLAYLISTS) {
            results.add(playlist);
          }
        }
      }
    }
    elements = object.get("socialActions");
    if (elements instanceof JsonArray) {
      for (JsonElement element : (JsonArray) elements) {
        if (element instanceof JsonObject) {
          JsonObject o = (JsonObject) element;
          String id = getAsString(o, "id");
          SocialAction socialAction = (SocialAction) mCache.get(TYPE_SOCIALACTIONS).get(id);
          if (socialAction == null) {
            socialAction = SocialAction.get(id);
            String action = getAsString(o, "action");
            socialAction.setAction(action);
            String date = getAsString(o, "date");
            socialAction.setDate(ISO8601Utils.parse(date));
            String actionType = getAsString(o, "type");
            socialAction.setType(actionType);
            String trackId = getAsString(o, "track");
            if (trackId != null) {
              Query query = (Query) findRecord(trackId, TYPE_TRACKS, isBackgroundRequest);
              socialAction.setQuery(query);
            }
            String artistId = getAsString(o, "artist");
            if (artistId != null) {
              Artist artist = (Artist) findRecord(artistId, TYPE_ARTISTS, isBackgroundRequest);
              socialAction.setArtist(artist);
            }
            String albumId = getAsString(o, "album");
            if (albumId != null) {
              Album album = (Album) findRecord(albumId, TYPE_ALBUMS, isBackgroundRequest);
              socialAction.setAlbum(album);
            }
            String userId = getAsString(o, "user");
            if (userId != null) {
              User user = (User) findRecord(userId, TYPE_USERS, isBackgroundRequest);
              socialAction.setUser(user);
            }
            String targetId = getAsString(o, "target");
            if (targetId != null) {
              User target = (User) findRecord(targetId, TYPE_USERS, isBackgroundRequest);
              socialAction.setTarget(target);
            }
            String playlistId = getAsString(o, "playlist");
            if (playlistId != null) {
              Playlist playlist =
                  (Playlist) findRecord(playlistId, TYPE_PLAYLISTS, isBackgroundRequest);
              socialAction.setPlaylist(playlist);
            }
            mCache.get(TYPE_SOCIALACTIONS).put(id, socialAction);
          }
          if (resultType == TYPE_SOCIALACTIONS) {
            results.add(socialAction);
          }
        }
      }
      if (params != null) {
        User user = (User) findRecord(params.userid, TYPE_USERS, false);
        if (user != null) {
          if (HatchetInfoPlugin.HATCHET_SOCIALACTION_PARAMTYPE_FRIENDSFEED.equals(params.type)) {
            user.setFriendsFeed(results, params.before_date);
          } else {
            user.setSocialActions(results, params.before_date);
          }
        }
      }
    }
    elements = object.get("searchResults");
    if (elements instanceof JsonArray) {
      for (JsonElement element : (JsonArray) elements) {
        if (element instanceof JsonObject) {
          JsonObject o = (JsonObject) element;
          String id = getAsString(o, "id");
          SearchResult searchResult = (SearchResult) mCache.get(TYPE_SEARCHRESULTS).get(id);
          if (searchResult == null) {
            float score = getAsFloat(o, "score");
            String trackId = getAsString(o, "track");
            if (trackId != null) {
              Query query = (Query) findRecord(trackId, TYPE_TRACKS, isBackgroundRequest);
              searchResult = new SearchResult(score, query);
            }
            String artistId = getAsString(o, "artist");
            if (artistId != null) {
              Artist artist = (Artist) findRecord(artistId, TYPE_ARTISTS, isBackgroundRequest);
              searchResult = new SearchResult(score, artist);
            }
            String albumId = getAsString(o, "album");
            if (albumId != null) {
              Album album = (Album) findRecord(albumId, TYPE_ALBUMS, isBackgroundRequest);
              searchResult = new SearchResult(score, album);
            }
            String userId = getAsString(o, "user");
            if (userId != null) {
              User user = (User) findRecord(userId, TYPE_USERS, isBackgroundRequest);
              searchResult = new SearchResult(score, user);
            }
            String playlistId = getAsString(o, "playlist");
            if (playlistId != null) {
              Playlist playlist =
                  (Playlist) findRecord(playlistId, TYPE_PLAYLISTS, isBackgroundRequest);
              searchResult = new SearchResult(score, playlist);
            }
            if (searchResult == null) {
              throw new IOException("searchResult contained no actual result object!");
            }
            mCache.get(TYPE_SEARCHRESULTS).put(id, searchResult);
          }
          if (resultType == TYPE_SEARCHRESULTS) {
            results.add(searchResult);
          }
        }
      }
    }
    elements = object.get("searches");
    if (elements instanceof JsonArray) {
      for (JsonElement element : (JsonArray) elements) {
        if (element instanceof JsonObject) {
          JsonObject o = (JsonObject) element;
          String id = getAsString(o, "id");
          JsonArray rawSearchResults = get(o, "searchResults").getAsJsonArray();
          ArrayList<SearchResult> searchResults = new ArrayList<>();
          for (JsonElement rawSearchResult : rawSearchResults) {
            String resultId = rawSearchResult.getAsString();
            SearchResult searchResult =
                (SearchResult) findRecord(resultId, TYPE_SEARCHRESULTS, isBackgroundRequest);
            searchResults.add(searchResult);
          }
          Search search = new Search(searchResults);
          mCache.get(TYPE_SEARCHES).put(id, search);
          if (resultType == TYPE_SEARCHES) {
            results.add(search);
          }
        }
      }
    }
    elements = object.get("relationships");
    if (elements instanceof JsonArray) {
      for (JsonElement element : (JsonArray) elements) {
        if (element instanceof JsonObject) {
          JsonObject o = (JsonObject) element;
          String id = getAsString(o, "id");
          String type = getAsString(o, "type");
          if (type.equals(HatchetInfoPlugin.HATCHET_RELATIONSHIPS_TYPE_LOVE)) {
            String userId = getAsString(o, "user");
            User user = (User) findRecord(userId, TYPE_USERS, isBackgroundRequest);
            String trackId = getAsString(o, "targetTrack");
            if (trackId != null) {
              Query query = (Query) findRecord(trackId, TYPE_TRACKS, isBackgroundRequest);
              user.putRelationShipId(query, id);
            }
            String albumId = getAsString(o, "targetAlbum");
            if (albumId != null) {
              Album album = (Album) findRecord(albumId, TYPE_ALBUMS, isBackgroundRequest);
              user.putRelationShipId(album, id);
            }
            String artistId = getAsString(o, "targetArtist");
            if (artistId != null) {
              Artist artist = (Artist) findRecord(artistId, TYPE_ARTISTS, isBackgroundRequest);
              user.putRelationShipId(artist, id);
            }
          }
        }
      }
    }
    return results;
  }