Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 529d8f02 authored by Santiago Seifert's avatar Santiago Seifert
Browse files

Move applyOptions to MediaBrowserUtils

Bug: b/185136506
Flag: NONE
Test: m (non-functional refactor)
Change-Id: Ib0b980a83db00c3c3d5f37da7252e05508977f92
parent 98a766e4
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@ package android.media.browse;

import android.os.Bundle;

import java.util.Collections;
import java.util.List;

/**
 * @hide
 */
@@ -75,4 +78,29 @@ public class MediaBrowserUtils {
        }
        return false;
    }

    /**
     * Returns a paged version of the given {@code list}, using the paging parameters in {@code
     * options}.
     */
    public static List<MediaBrowser.MediaItem> applyPagingOptions(
            List<MediaBrowser.MediaItem> list, final Bundle options) {
        if (list == null) {
            return null;
        }
        int page = options.getInt(MediaBrowser.EXTRA_PAGE, -1);
        int pageSize = options.getInt(MediaBrowser.EXTRA_PAGE_SIZE, -1);
        if (page == -1 && pageSize == -1) {
            return list;
        }
        int fromIndex = pageSize * page;
        int toIndex = fromIndex + pageSize;
        if (page < 0 || pageSize < 1 || fromIndex >= list.size()) {
            return Collections.EMPTY_LIST;
        }
        if (toIndex > list.size()) {
            toIndex = list.size();
        }
        return list.subList(fromIndex, toIndex);
    }
}
+1 −23
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -728,7 +727,7 @@ public abstract class MediaBrowserService extends Service {

                List<MediaBrowser.MediaItem> filteredList =
                        (flag & RESULT_FLAG_OPTION_NOT_HANDLED) != 0
                                ? applyOptions(list, options) : list;
                                ? MediaBrowserUtils.applyPagingOptions(list, options) : list;
                final ParceledListSlice<MediaBrowser.MediaItem> pls;
                if (filteredList == null) {
                    pls = null;
@@ -762,27 +761,6 @@ public abstract class MediaBrowserService extends Service {
        }
    }

    private List<MediaBrowser.MediaItem> applyOptions(List<MediaBrowser.MediaItem> list,
            final Bundle options) {
        if (list == null) {
            return null;
        }
        int page = options.getInt(MediaBrowser.EXTRA_PAGE, -1);
        int pageSize = options.getInt(MediaBrowser.EXTRA_PAGE_SIZE, -1);
        if (page == -1 && pageSize == -1) {
            return list;
        }
        int fromIndex = pageSize * page;
        int toIndex = fromIndex + pageSize;
        if (page < 0 || pageSize < 1 || fromIndex >= list.size()) {
            return Collections.EMPTY_LIST;
        }
        if (toIndex > list.size()) {
            toIndex = list.size();
        }
        return list.subList(fromIndex, toIndex);
    }

    private void performLoadItem(String itemId, final ConnectionRecord connection,
            final ResultReceiver receiver) {
        final Result<MediaBrowser.MediaItem> result =