Search in sources :

Example 1 with AbsImageListViewItem

use of org.gateshipone.malp.application.listviewitems.AbsImageListViewItem in project malp by gateship-one.

the class ArtistsFragment method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    mLastPosition = position;
    MPDArtist artist = (MPDArtist) mArtistAdapter.getItem(position);
    Bitmap bitmap = null;
    // Check if correct view type, to be safe
    if (view instanceof AbsImageListViewItem) {
        bitmap = ((AbsImageListViewItem) view).getBitmap();
    }
    mSelectedCallback.onArtistSelected(artist, bitmap);
}
Also used : Bitmap(android.graphics.Bitmap) AbsImageListViewItem(org.gateshipone.malp.application.listviewitems.AbsImageListViewItem) MPDArtist(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)

Example 2 with AbsImageListViewItem

use of org.gateshipone.malp.application.listviewitems.AbsImageListViewItem in project malp by gateship-one.

the class AlbumsFragment method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    mLastPosition = position;
    MPDAlbum album = (MPDAlbum) mAlbumsAdapter.getItem(position);
    Bitmap bitmap = null;
    // Check if correct view type, to be safe
    if (view instanceof AbsImageListViewItem) {
        bitmap = ((AbsImageListViewItem) view).getBitmap();
    }
    // support group commands and therefore do not provide artist tags for albums)
    if (mArtist != null && !mArtist.getArtistName().isEmpty() && album.getArtistName().isEmpty()) {
        album.setArtistName(mArtist.getArtistName());
        album.setArtistSortName(mArtist.getArtistName());
    }
    // Check if the album already has an artist set. If not use the artist of the fragment
    mAlbumSelectCallback.onAlbumSelected(album, bitmap);
}
Also used : Bitmap(android.graphics.Bitmap) AbsImageListViewItem(org.gateshipone.malp.application.listviewitems.AbsImageListViewItem) MPDAlbum(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)

Example 3 with AbsImageListViewItem

use of org.gateshipone.malp.application.listviewitems.AbsImageListViewItem in project malp by gateship-one.

the class ScrollSpeedListener method onScroll.

/**
 * Called when the associated Listview/GridView is scrolled by the user.
 * This method evaluates if the view is scrolled slow enough to start loading images.
 *
 * @param view View that is being scrolled.
 * @param firstVisibleItem Index of the first visible item
 * @param visibleItemCount Count of visible items
 * @param totalItemCount Total item count
 */
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    // New row started if this is true.
    if (firstVisibleItem != mLastFirstVisibleItem) {
        long currentTime = System.currentTimeMillis();
        if (currentTime == mLastTime) {
            return;
        }
        // Calculate the duration of scroll per line
        long timeScrollPerRow = currentTime - mLastTime;
        if (view instanceof GridView) {
            GridView gw = (GridView) view;
            mScrollSpeed = (int) (1000 / timeScrollPerRow) * gw.getNumColumns();
        } else {
            mScrollSpeed = (int) (1000 / timeScrollPerRow);
        }
        // Calculate how many items per second of loading images is possible
        int possibleItems = (int) (1000 / mAdapter.getAverageImageLoadTime());
        // Set the scrollspeed in the adapter
        mAdapter.setScrollSpeed(mScrollSpeed);
        // Save values for next comparsion
        mLastFirstVisibleItem = firstVisibleItem;
        mLastTime = currentTime;
        // The devices is able to render the images needed for the scroll speed
        if (mScrollSpeed < possibleItems) {
            for (int i = 0; i < visibleItemCount; i++) {
                AbsImageListViewItem listItem = (AbsImageListViewItem) mListView.getChildAt(i);
                listItem.startCoverImageTask();
            }
        }
    }
}
Also used : AbsImageListViewItem(org.gateshipone.malp.application.listviewitems.AbsImageListViewItem) GridView(android.widget.GridView)

Example 4 with AbsImageListViewItem

use of org.gateshipone.malp.application.listviewitems.AbsImageListViewItem in project malp by gateship-one.

the class ScrollSpeedListener method onScrollStateChanged.

/**
 * Called when a scroll is started/ended and resets the values.
 * If scrolling stops this will start coverimage tasks
 * @param view View that has a scrolling state change
 * @param scrollState New scrolling state of the view
 */
public void onScrollStateChanged(AbsListView view, int scrollState) {
    if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
        mScrollSpeed = 0;
        mAdapter.setScrollSpeed(0);
        for (int i = 0; i <= mListView.getLastVisiblePosition() - mListView.getFirstVisiblePosition(); i++) {
            AbsImageListViewItem listItem = (AbsImageListViewItem) mListView.getChildAt(i);
            listItem.startCoverImageTask();
        }
    } else if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
        // Reset time values
        mLastTime = System.currentTimeMillis();
    }
}
Also used : AbsImageListViewItem(org.gateshipone.malp.application.listviewitems.AbsImageListViewItem)

Aggregations

AbsImageListViewItem (org.gateshipone.malp.application.listviewitems.AbsImageListViewItem)4 Bitmap (android.graphics.Bitmap)2 GridView (android.widget.GridView)1 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)1 MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)1