Skip to content

Commit

Permalink
Bugfix/issue 1/no items exception (#102)
Browse files Browse the repository at this point in the history
Issue-1 - made fix and improved automation
  • Loading branch information
goldy1992 authored Nov 15, 2019
1 parent 8e525cc commit e6d1d04
Show file tree
Hide file tree
Showing 26 changed files with 357 additions and 750 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.github.goldy1992.mp3player.service.library.content.parser.ResultsParser;
import com.github.goldy1992.mp3player.service.library.content.retriever.ContentRetriever;
import com.github.goldy1992.mp3player.service.library.content.retriever.FoldersRetriever;
import com.github.goldy1992.mp3player.service.library.content.retriever.FoldersRetrieverTestImpl;
import com.github.goldy1992.mp3player.service.library.content.retriever.RootRetriever;
import com.github.goldy1992.mp3player.service.library.content.retriever.SongsFromFolderRetriever;
import com.github.goldy1992.mp3player.service.library.content.retriever.SongsRetriever;
Expand Down Expand Up @@ -39,7 +40,7 @@ public Map<Class<? extends ContentRetriever>, ContentRetriever> provideContentRe
mapToReturn.put(RootRetriever.class, rootRetriever);
SongsRetriever songsRetriever = new SongsRetrieverTestImpl(contentResolver, mediaItemBuilderMap.get(MediaItemType.SONG), searchDatabase.songDao(), handler);
mapToReturn.put(SongsRetriever.class, songsRetriever);
FoldersRetriever foldersRetriever = new FoldersRetriever(contentResolver, mediaItemBuilderMap.get(FOLDER), searchDatabase.folderDao(), handler);
FoldersRetriever foldersRetriever = new FoldersRetrieverTestImpl(contentResolver, mediaItemBuilderMap.get(FOLDER), searchDatabase.folderDao(), handler);
mapToReturn.put(FoldersRetriever.class, foldersRetriever);
SongsFromFolderRetriever songsFromFolderRetriever = new SongsFromFolderRetriever(contentResolver, mediaItemBuilderMap.get(SONG), searchDatabase.songDao(), handler);
mapToReturn.put(SongsFromFolderRetriever.class, songsFromFolderRetriever);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.goldy1992.mp3player.service.library.content.retriever;

import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Handler;
import android.provider.MediaStore;

import com.github.goldy1992.mp3player.service.library.content.parser.ResultsParser;
import com.github.goldy1992.mp3player.service.library.search.FolderDao;

import static com.github.goldy1992.mp3player.TestConstants.TEST_DATA_DIR;

public class FoldersRetrieverTestImpl extends FoldersRetriever {
public FoldersRetrieverTestImpl(ContentResolver contentResolver, ResultsParser resultsParser, FolderDao folderDao, Handler handler) {
super(contentResolver, resultsParser, folderDao, handler);
}

private final String WHERE_CLAUSE = MediaStore.Audio.Media.DATA + " LIKE ?";


private final String[] WHERE_ARGS = {"%" + TEST_DATA_DIR + "%"};

@Override
Cursor performGetChildrenQuery(String id) {
return contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, getProjection(),
WHERE_CLAUSE, WHERE_ARGS, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,16 @@ public long getActiveQueueItemId() {

public int getCurrentQueuePosition() {
List<QueueItem> queue = getQueue();
long id = getActiveQueueItemId();

for (int i = 0; i < queue.size(); i++) {
QueueItem queueItem = queue.get(i);
if (queueItem.getQueueId() == id) {
return i;
if (queue != null) {
long id = getActiveQueueItemId();

for (int i = 0; i < queue.size(); i++) {
QueueItem queueItem = queue.get(i);
if (queueItem.getQueueId() == id) {
return i;
}
}
}

return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;

import static com.github.goldy1992.mp3player.commons.MediaItemUtils.getAlbumArtUri;
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;


public class MySongViewAdapter extends MyGenericRecycleViewAdapter {
Expand Down Expand Up @@ -58,7 +59,13 @@ public void onBindViewHolder(@NonNull MediaItemViewHolder holder, int position)
@NonNull
@Override
public String getSectionText(int position) {
return items.get(position).getDescription().getTitle().toString().substring(0, 1);
if (isNotEmpty(items)) {
CharSequence title = items.get(position).getDescription().getTitle();
if (null != title) {
return title.toString().substring(0, 1);
}
}
return "";
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public TrackViewAdapter(AlbumArtPainter albumArtPainter,
List<QueueItem> queue) {
super();
this.queue = queue;
// TODO: if there is no queue make an empty view holder
this.albumArtPainter = albumArtPainter;
this.mainHandler = mainHandler;
}
Expand All @@ -48,7 +49,10 @@ public void onBindViewHolder(@NonNull MediaPlayerTrackViewHolder holder, int pos

@Override
public int getItemCount() {
return queue.size();
if (null != queue) {
return queue.size();
}
return -1;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@

public class PlayPauseButton extends MediaButton implements PlaybackStateListener {

@PlaybackStateCompat.State
public static final int INITIAL_PLAYBACK_STATE = PlaybackStateCompat.STATE_STOPPED;

private static final String LOG_TAG = "PLAY_PAUSE_BUTTON";
@PlaybackStateCompat.State
private int state = PlaybackStateCompat.STATE_NONE;
private int state = INITIAL_PLAYBACK_STATE;

@Inject
public PlayPauseButton(Context context, @NonNull MediaControllerAdapter mediaControllerAdapter,
@Named("main") Handler mainUpdater) {
super(context, mediaControllerAdapter, mainUpdater);
updateState(mediaControllerAdapter.getPlaybackState()) ;
}

@Override
public void init(ImageView view) {
super.init(view);
updateState(this.mediaControllerAdapter.getPlaybackState());
this.mediaControllerAdapter.registerPlaybackStateListener(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
public void onViewCreated(@NonNull View view, Bundle bundle) {
this.recyclerView = view.findViewById(R.id.recycler_view);
this.recyclerView.setAdapter(myViewAdapter);
this.recyclerView.setHideScrollbar(false);
this.recyclerView.addOnItemTouchListener(myGenericItemTouchListener);
this.myGenericItemTouchListener.setParentView(recyclerView);
this.recyclerView.setItemAnimator(new DefaultItemAnimator());
this.recyclerView.setLayoutManager(linearLayoutManager);
this.recyclerView.addOnScrollListener(albumArtPainter.createPreloader(myViewAdapter));
this.recyclerView.setHideScrollbar(true);
}

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import com.github.goldy1992.mp3player.R;
import com.github.goldy1992.mp3player.service.MyDescriptionAdapter;
import com.github.goldy1992.mp3player.service.PlaybackManager;
import com.github.goldy1992.mp3player.service.PlaylistManager;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.ui.PlayerNotificationManager;

Expand Down Expand Up @@ -47,7 +47,7 @@ public PlayerNotificationManager providesPlayerNotificationManager(
@Singleton
public MyDescriptionAdapter providesMyDescriptionAdapter(Context context,
MediaSessionCompat.Token token,
PlaybackManager playbackManager) {
return new MyDescriptionAdapter(context, token, playbackManager);
PlaylistManager playlistManager) {
return new MyDescriptionAdapter(context, token, playlistManager);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import android.support.v4.media.session.MediaSessionCompat;

import com.github.goldy1992.mp3player.service.MyControlDispatcher;
import com.github.goldy1992.mp3player.service.PlaybackManager;
import com.github.goldy1992.mp3player.service.PlaylistManager;
import com.github.goldy1992.mp3player.service.library.ContentManager;
import com.github.goldy1992.mp3player.service.player.AudioBecomingNoisyBroadcastReceiver;
import com.github.goldy1992.mp3player.service.player.DecreaseSpeedProvider;
Expand Down Expand Up @@ -64,8 +64,8 @@ public MyPlaybackPreparer provideMyPlaybackPreparer(ExoPlayer exoPlayer,
@Named("starting_playlist") List<MediaBrowserCompat.MediaItem> items,
MyControlDispatcher myControlDispatcher,
MediaSourceFactory mediaSourceFactory,
PlaybackManager playbackManager) {
return new MyPlaybackPreparer(exoPlayer, contentManager, items, mediaSourceFactory, myControlDispatcher, playbackManager);
PlaylistManager playlistManager) {
return new MyPlaybackPreparer(exoPlayer, contentManager, items, mediaSourceFactory, myControlDispatcher, playlistManager);
}

@Provides
Expand All @@ -82,15 +82,15 @@ public ContentDataSource providesContentDataSource(Context context) {

@Provides
@Singleton
public MyMetadataProvider providesMyMetadataProvider(PlaybackManager playbackManager) {
return new MyMetadataProvider(playbackManager);
public MyMetadataProvider providesMyMetadataProvider(PlaylistManager playlistManager) {
return new MyMetadataProvider(playlistManager);
}

@Provides
@Singleton
public MyTimelineQueueNavigator providesMyTimelineQueueNavigator(MediaSessionCompat mediaSessionCompat,
PlaybackManager playbackManager) {
return new MyTimelineQueueNavigator(mediaSessionCompat, playbackManager);
PlaylistManager playlistManager) {
return new MyTimelineQueueNavigator(mediaSessionCompat, playlistManager);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.support.v4.media.MediaBrowserCompat;

import com.github.goldy1992.mp3player.service.PlaybackManager;
import com.github.goldy1992.mp3player.service.PlaylistManager;
import com.github.goldy1992.mp3player.service.library.ContentManager;

import java.util.List;
Expand All @@ -17,8 +17,8 @@
public class PlaybackManagerModule {
@Singleton
@Provides
public PlaybackManager providePlaybackManager(ContentManager contentManager,
public PlaylistManager providePlaybackManager(ContentManager contentManager,
@Named("starting_playlist")List<MediaBrowserCompat.MediaItem> items) {
return new PlaybackManager(items, 0);
return new PlaylistManager(items, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
import static com.github.goldy1992.mp3player.commons.Constants.MEDIA_SESSION;

public class MyDescriptionAdapter implements PlayerNotificationManager.MediaDescriptionAdapter {
private final PlaybackManager playbackManager;
private final PlaylistManager playlistManager;
private final Context context;
private final Token token;
private static final int REQUEST_CODE = 501;

public MyDescriptionAdapter(Context context,
Token token,
PlaybackManager playbackManager) {
PlaylistManager playlistManager) {
this.context = context;
this.token = token;
this.playbackManager = playbackManager;
this.playlistManager = playlistManager;
}

@Override
Expand Down Expand Up @@ -63,6 +63,6 @@ public Bitmap getCurrentLargeIcon(Player player, PlayerNotificationManager.Bitma

private final MediaItem getCurrentMediaItem(Player player) {
int position = player.getCurrentWindowIndex();
return playbackManager.getItemAtIndex(position);
return playlistManager.getItemAtIndex(position);
}
}
Loading

0 comments on commit e6d1d04

Please sign in to comment.