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);
}
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);
}
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();
}
}
}
}
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();
}
}
Aggregations