Skip to content

Commit

Permalink
[android] fixes issue where last added favorite wasn't displaying. ot…
Browse files Browse the repository at this point in the history
…her refresh issues remain.
  • Loading branch information
gubatron committed Mar 2, 2016
1 parent 989829a commit 0466053
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,12 @@ public int getOffset() {
@Override
public int getCount() {
if (mDataList != null) {
return mDataList.size();
int size = mDataList.size();
return size == 0 ? 0 : size + getOffset();

This comment has been minimized.

Copy link
@aldenml

aldenml Mar 2, 2016

Collaborator

How is this working? getCount is the same as getViewCount?

This comment has been minimized.

Copy link
@gubatron

gubatron Mar 3, 2016

Author Collaborator

getViewCount() wasn't used anywhere, I noticed by looking at why the favorite list was aways showng n-1 elements.

Then I looked at the old getCount() code and figured I had started coding this getViewCount() method, but I never plugged it anywhere.

}
return super.getCount();
}

/**
* The view count, including a header element if present for this adapter.
*
* @return
*/
public int getViewCount() {
return getCount() + getOffset();
}

/**
* @param position - The ACTUAL position in the model container. If you're using an offset based on a list view that has a header element at 0, you must subtract to the position you might have.
* @return The element at the indexed position in the model container (not the view). null if position is out of bounds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,11 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.andrew.apollo.utils.Ref;
import com.frostwire.android.R;
import com.andrew.apollo.model.Song;
import com.andrew.apollo.ui.MusicViewHolder;
import com.andrew.apollo.ui.fragments.profile.AlbumSongFragment;
import com.andrew.apollo.ui.fragments.profile.ArtistSongFragment;
import com.andrew.apollo.ui.fragments.profile.FavoriteFragment;
import com.andrew.apollo.ui.fragments.profile.GenreSongFragment;
import com.andrew.apollo.ui.fragments.profile.LastAddedFragment;
import com.andrew.apollo.ui.fragments.profile.PlaylistSongFragment;
import com.andrew.apollo.ui.fragments.profile.*;
import com.andrew.apollo.utils.MusicUtils;
import com.frostwire.logging.Logger;
import com.frostwire.android.R;

/**
* This {@link ArrayAdapter} is used to display the songs for a particular
Expand All @@ -41,7 +33,7 @@
*/
public class ProfileSongAdapter extends ApolloFragmentAdapter<Song> {

public static final Logger LOGGER = Logger.getLogger(ProfileSongAdapter.class);
//public static final Logger LOGGER = Logger.getLogger(ProfileSongAdapter.class);

/**
* Default display setting: title/album
Expand Down Expand Up @@ -97,7 +89,7 @@ public ProfileSongAdapter(final Context context, final int layoutId, final int s
// Cache the header
mHeader = mInflater.inflate(R.layout.faux_carousel, null);
// Know what to put in line two
mDisplaySetting = setting;
mDisplaySetting = setting;

setNotifyOnChange(true);
}
Expand Down Expand Up @@ -135,6 +127,7 @@ public View getView(final int position, View convertView, final ViewGroup parent
}

// Retrieve the album
LOGGER.info("getView(position=="+position+") : getOffset() -> " + getOffset() + " => position - getOffset() => " + (position - getOffset()));
final Song song = getItem(position - getOffset());

// Set each track name (line one)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.andrew.apollo.widgets.VerticalScrollListener;
import com.devspark.appmsg.AppMsg;
import com.frostwire.android.R;
import com.frostwire.logging.Logger;
import com.viewpagerindicator.TitlePageIndicator;

import java.util.List;
Expand All @@ -61,7 +62,7 @@ public abstract class ApolloFragment<T extends ApolloFragmentAdapter<I>, I>
AbsListView.OnScrollListener,
MusicStateListener {

//private static Logger LOGGER = Logger.getLogger(ApolloFragment.class);
private static Logger LOGGER = Logger.getLogger(ApolloFragment.class);

private final int GROUP_ID;
/**
Expand Down Expand Up @@ -300,7 +301,7 @@ public boolean onContextItemSelected(final android.view.MenuItem item) {
private boolean onRemoveFromRecent() {
RecentStore.getInstance(getActivity()).removeItem(mSelectedId);
MusicUtils.refresh();
refresh();
restartLoader(true);
return true;
}

Expand All @@ -325,6 +326,7 @@ public void onDelete(long[] id) {
refresh();
}
}).show(getFragmentManager(), "DeleteDialog");
restartLoader(true);
return true;
}

Expand All @@ -334,7 +336,7 @@ private boolean onRemoveFromPlaylist() {
if (mItem instanceof Song) {
Song song = (Song) mItem;
MusicUtils.removeFromPlaylist(getActivity(), song.mSongId, mPlaylistId);
refresh();
restartLoader(true);
return true;
}
return false;
Expand Down Expand Up @@ -369,7 +371,7 @@ private void onRemoveFromFavorites() {
mAdapter.remove(mItem);
mAdapter.notifyDataSetChanged();
FavoritesStore.getInstance(getActivity()).removeItem(mSelectedId);
restartLoader(true);
refresh();
}

/**
Expand All @@ -380,7 +382,7 @@ public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Enable the options menu
setHasOptionsMenu(true);
restartLoader(true);
initLoader();
}

@Override
Expand Down Expand Up @@ -465,7 +467,7 @@ public void refresh() {
mAdapter.clear();
}

restartLoader(true);
restartLoader(); // this won't be executed if it was recently called. no risk of endless loop.

if (mAdapter != null) {
mAdapter.notifyDataSetChanged();
Expand Down Expand Up @@ -493,9 +495,14 @@ public void restartLoader(boolean force) {
if (force || (System.currentTimeMillis() - lastRestartLoader) >= 5000) {
lastRestartLoader = System.currentTimeMillis();
getLoaderManager().restartLoader(LOADER_ID, getArguments(), this);
refresh(); // won't end up in recursive call because we just refreshed.
}
}

public void initLoader() {
getLoaderManager().initLoader(LOADER_ID, null, this);
}

public void onMetaChanged() {
restartLoader();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ public FavoriteFragment() {

@Override
protected ProfileSongAdapter createAdapter() {
return new ProfileSongAdapter(
getActivity(),
R.layout.list_item_simple,
ProfileSongAdapter.DISPLAY_PLAYLIST_SETTING
);
return new ProfileSongAdapter(getActivity(), R.layout.list_item_simple, ProfileSongAdapter.DISPLAY_PLAYLIST_SETTING);
}

@Override
Expand Down

0 comments on commit 0466053

Please sign in to comment.