@Override
  public void onExecuteSync(Context context, int instance) throws NetworkNotValidException {
    try {
      ArrayList<String> syncedList = SyncUtil.getSyncedMostRecent(context, instance);
      MusicDirectory albumList =
          musicService.getAlbumList("newest", 20, 0, tagBrowsing, context, null);
      List<String> updated = new ArrayList<String>();
      boolean firstRun = false;
      if (syncedList.size() == 0) {
        // Get the initial set of albums on first run, don't sync any of these!
        for (MusicDirectory.Entry album : albumList.getChildren()) {
          syncedList.add(album.getId());
        }
        firstRun = true;
      } else {
        for (MusicDirectory.Entry album : albumList.getChildren()) {
          if (!syncedList.contains(album.getId())) {
            if (!"Podcast".equals(album.getGenre())) {
              try {
                if (downloadRecursively(null, getMusicDirectory(album), context, false)) {
                  updated.add(album.getTitle());
                }
              } catch (Exception e) {
                Log.w(
                    TAG,
                    "Failed to get songs for "
                        + album.getId()
                        + " on "
                        + Util.getServerName(context, instance));
              }
            }
            syncedList.add(album.getId());
          }
        }
      }

      if (updated.size() > 0) {
        while (syncedList.size() > 40) {
          syncedList.remove(0);
        }

        FileUtil.serialize(context, syncedList, SyncUtil.getMostRecentSyncFile(context, instance));

        // If there is a new album on the active server, chances are artists need to be refreshed
        if (Util.getActiveServer(context) == instance) {
          musicService.getIndexes(Util.getSelectedMusicFolderId(context), true, context, null);
        }

        Notifications.showSyncNotification(
            context, R.string.sync_new_albums, SyncUtil.joinNames(updated));
      } else if (firstRun) {
        FileUtil.serialize(context, syncedList, SyncUtil.getMostRecentSyncFile(context, instance));
      }
    } catch (Exception e) {
      Log.e(TAG, "Failed to get most recent list for " + Util.getServerName(context, instance));
    }
  }
Esempio n. 2
0
  public static MusicDirectory.Entry findEntry(MusicDirectory.Entry entry) {
    for (UpdateView view : INSTANCES.keySet()) {
      MusicDirectory.Entry check = null;
      if (view instanceof SongView) {
        check = ((SongView) view).getEntry();
      } else if (view instanceof AlbumView) {
        check = ((AlbumView) view).getEntry();
      }

      if (check != null && entry != check && check.getId().equals(entry.getId())) {
        return check;
      }
    }

    return null;
  }