Skip to content

Commit

Permalink
[android] mistery solved, several fixes, lots of logging to find it.
Browse files Browse the repository at this point in the history
  • Loading branch information
gubatron committed Feb 7, 2016
1 parent 573fc47 commit c030c48
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class AlbumAdapter extends ApolloFragmentAdapter<Album> implements Apollo
* Constructor of <code>AlbumAdapter</code>
*/
public AlbumAdapter(final Activity context, final int layoutId) {
super(context, layoutId);
super(context, layoutId, 0);
// Cache the transparent overlay
mOverlay = context.getResources().getColor(R.color.list_item_background);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public interface Cacheable {

protected final int mLayoutId;

public ApolloFragmentAdapter(Context context, int mLayoutId) {
super(context, mLayoutId);
public ApolloFragmentAdapter(Context context, int mLayoutId, int textViewResourceId) {
super(context, textViewResourceId);
this.mLayoutId = mLayoutId;
if (context instanceof Activity) {
mImageFetcher = ApolloUtils.getImageFetcher((Activity) context);
Expand Down Expand Up @@ -187,6 +187,7 @@ public int getOffset() {
if (getItemViewType(0) == ITEM_VIEW_TYPE_HEADER) {
offset = 1;
}
LOGGER.info(getClass().getCanonicalName() + ".getOffset() -> " + offset);
return offset;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ArtistAdapter extends ApolloFragmentAdapter<Artist> implements Apol
* @param layoutId The resource Id of the view to inflate.
*/
public ArtistAdapter(final Activity context, final int layoutId) {
super(context, layoutId);
super(context, layoutId, 0);
// Cache the transparent overlay
mOverlayColor = context.getResources().getColor(R.color.list_item_background);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ArtistAlbumAdapter extends ApolloFragmentAdapter<Album> {
* @param layoutId The resource Id of the view to inflate.
*/
public ArtistAlbumAdapter(final Activity context, final int layoutId) {
super(context, layoutId);
super(context, layoutId, 0);
// Used to create the custom layout
mInflater = LayoutInflater.from(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class GenreAdapter extends ApolloFragmentAdapter<Genre> implements Apollo
private static final int VIEW_TYPE_COUNT = 1;

public GenreAdapter(final Context context, final int layoutId) {
super(context, layoutId);
super(context, layoutId, 0);
}

@Override
Expand Down
16 changes: 8 additions & 8 deletions android/apollo/src/com/andrew/apollo/adapters/PagerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,31 +163,31 @@ public enum MusicFragments {
/**
* The Last Songs added Fragment
*/
LAST(LastAddedFragment.class),
LAST(LastAddedFragment.class);
/**
* The playlist fragment
*/
PLAYLIST(PlaylistFragment.class),
//PLAYLIST(PlaylistFragment.class),
/**
* The recent fragment
*/
RECENT(RecentFragment.class),
//RECENT(RecentFragment.class),
/**
* The artist fragment
*/
ARTIST(ArtistFragment.class),
//ARTIST(ArtistFragment.class),
/**
* The song fragment
*/
SONG(SongFragment.class),
//SONG(SongFragment.class),
/**
* The album fragment
*/
ALBUM(AlbumFragment.class),
//ALBUM(AlbumFragment.class),
/**
* The genre fragment
*/
GENRE(GenreFragment.class);
//GENRE(GenreFragment.class);

private Class<? extends Fragment> mFragmentClass;

Expand All @@ -196,7 +196,7 @@ public enum MusicFragments {
*
* @param fragmentClass The fragment class
*/
private MusicFragments(final Class<? extends Fragment> fragmentClass) {
MusicFragments(final Class<? extends Fragment> fragmentClass) {
mFragmentClass = fragmentClass;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class PlaylistAdapter extends ApolloFragmentAdapter<Playlist> implements
* @param layoutId The resource Id of the view to inflate.
*/
public PlaylistAdapter(final Context context, final int layoutId) {
super(context, layoutId);
super(context, layoutId, 0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class ProfileSongAdapter extends ApolloFragmentAdapter<Song> {
* @param setting defines the content of the second line
*/
public ProfileSongAdapter(final Context context, final int layoutId, final int setting) {
super(context, layoutId);
super(context, layoutId, 0);
// Used to create the custom layout
mInflater = LayoutInflater.from(context);
// Cache the header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class SongAdapter extends ApolloFragmentAdapter<Song> implements ApolloFr
private static final int VIEW_TYPE_COUNT = 1;

public SongAdapter(Context context, int mLayoutId) {
super(context, mLayoutId);
super(context, mLayoutId, 0);
}

/**
Expand Down Expand Up @@ -71,6 +71,10 @@ public View getView(final int position, View convertView, final ViewGroup parent
holder.mLineOneRight.get().setTextColor(getContext().getResources().getColor(com.frostwire.android.R.color.app_text_primary));
holder.mLineTwo.get().setTextColor(getContext().getResources().getColor(com.frostwire.android.R.color.app_text_primary));
}
//LOGGER.info(".getView() - returning a convertView != null ? " + (convertView != null));
if (convertView == null && Ref.alive(holder.mConvertView)) {
convertView = holder.mConvertView.get();
}

return convertView;
}
Expand Down
7 changes: 3 additions & 4 deletions android/apollo/src/com/andrew/apollo/loaders/AlbumLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ public List<Album> loadInBackground() {

// Gather the data
if (mCursor != null && mCursor.moveToFirst()) {
String an = mCursor.getString(1) != null ? mCursor.getString(1) : "n/a";
String art = mCursor.getString(2) != null ? mCursor.getString(2) : "n/a";
LOGGER.info("first album loaded? id: " + mCursor.getLong(0) + " - albumName: " + an + " - artist: " + art);

do {
// Copy the album id
final long id = mCursor.getLong(0);
Expand All @@ -87,6 +83,9 @@ public List<Album> loadInBackground() {

// Add everything up
mAlbumsList.add(album);
//String an = mCursor.getString(1) != null ? mCursor.getString(1) : "n/a";
//String art = mCursor.getString(2) != null ? mCursor.getString(2) : "n/a";
//LOGGER.info("Adding id: " + mCursor.getLong(0) + " - albumName: " + an + " - artist: " + art);
} while (mCursor.moveToNext());
}
// Close the cursor
Expand Down
13 changes: 10 additions & 3 deletions android/apollo/src/com/andrew/apollo/loaders/LastAddedLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.andrew.apollo.model.Song;
import com.andrew.apollo.utils.Lists;
import com.frostwire.logging.Logger;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -31,7 +32,7 @@
* @author Angel Leon (gubatron@gmail.com)
*/
public class LastAddedLoader extends SongLoader {

private static Logger LOGGER = Logger.getLogger(LastAddedLoader.class);
/**
* Constructor of <code>LastAddedHandler</code>
*
Expand All @@ -43,21 +44,25 @@ public LastAddedLoader(final Context context) {

@Override
public Cursor makeCursor(Context context) {
return makeLastAddedCursor(getContext());
LOGGER.info("makeCursor() start. (Overrides SongLoader's makeCursor())");
Cursor c = makeLastAddedCursor(getContext());
LOGGER.info("makCursor() finished.");
return c;
}

/**
* @param context The {@link Context} to use.
* @return The {@link Cursor} used to run the song query.
*/
public static Cursor makeLastAddedCursor(final Context context) {
LOGGER.info("makeLastAddedCursor() start.");
final int fourWeeks = 4 * 3600 * 24 * 7;
final StringBuilder selection = new StringBuilder();
selection.append(AudioColumns.IS_MUSIC + "=1");
selection.append(" AND " + AudioColumns.TITLE + " != ''"); //$NON-NLS-2$
selection.append(" AND " + MediaStore.Audio.Media.DATE_ADDED + ">"); //$NON-NLS-2$
selection.append(System.currentTimeMillis() / 1000 - fourWeeks);
return context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
Cursor c = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] {
/* 0 */
BaseColumns._ID,
Expand All @@ -70,5 +75,7 @@ public static Cursor makeLastAddedCursor(final Context context) {
/* 4 */
AudioColumns.DURATION
}, selection.toString(), null, MediaStore.Audio.Media.DATE_ADDED + " DESC");
LOGGER.info("makeLastAddedCursor() finished with " + c.getCount() + " elements.");
return c;
}
}
9 changes: 7 additions & 2 deletions android/apollo/src/com/andrew/apollo/loaders/SongLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.andrew.apollo.model.Song;
import com.andrew.apollo.utils.Lists;
import com.andrew.apollo.utils.PreferenceUtils;
import com.frostwire.logging.Logger;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -31,7 +32,7 @@
* @author Andrew Neal (andrewdneal@gmail.com)
*/
public class SongLoader extends WrappedAsyncTaskLoader<List<Song>> {

private static Logger LOGGER = Logger.getLogger(SongLoader.class);
/**
* Constructor of <code>SongLoader</code>
*
Expand All @@ -48,14 +49,16 @@ public SongLoader(final Context context) {
public List<Song> loadInBackground() {
ArrayList<Song> mSongList = Lists.newArrayList();
// Create the Cursor
Cursor mCursor = null;
Cursor mCursor;
try {
mCursor = makeCursor(getContext());
} catch (Throwable ignored) {
LOGGER.error("SongLoader.loadInBackground(): " + ignored.getMessage(), ignored);
return Collections.EMPTY_LIST;
}

if (mCursor == null) {
LOGGER.warn("loadInBackground() - cursor == null, returning empty list.");
return Collections.EMPTY_LIST;
}

Expand All @@ -81,6 +84,7 @@ public List<Song> loadInBackground() {
duration = mCursor.getLong(4);
durationInSecs = (int) duration / 1000;
} catch (Throwable ignored) {
LOGGER.error("SongLoader.loadInBackground(): " +ignored.getMessage(), ignored);
}

// Create a new song
Expand All @@ -94,6 +98,7 @@ public List<Song> loadInBackground() {
if (mCursor != null) {
mCursor.close();
}
LOGGER.info("loadInBackground() done (" + mSongList.size() + " songs)");
return mSongList;
}

Expand Down
3 changes: 3 additions & 0 deletions android/apollo/src/com/andrew/apollo/ui/MusicViewHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* @author Andrew Neal (andrewdneal@gmail.com)
*/
public class MusicViewHolder {
public WeakReference<View> mConvertView;

/**
* This is the overlay ontop of the background artist, playlist, or genre
Expand Down Expand Up @@ -80,6 +81,8 @@ public class MusicViewHolder {
*/
public MusicViewHolder(final View view) {
super();
mConvertView = new WeakReference<>(view);

// Initialize mOverlay
mOverlay = new WeakReference<>((RelativeLayout)view.findViewById(R.id.image_background));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,18 @@

package com.andrew.apollo.ui.fragments;

import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.view.*;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import com.andrew.apollo.MusicStateListener;
import com.andrew.apollo.adapters.SongAdapter;
import com.andrew.apollo.loaders.LastAddedLoader;
import com.andrew.apollo.menu.CreateNewPlaylist;
import com.andrew.apollo.menu.DeleteDialog;
import com.andrew.apollo.menu.FragmentMenuItems;
import com.andrew.apollo.model.Song;
import com.andrew.apollo.provider.FavoritesStore;
import com.andrew.apollo.recycler.RecycleHolder;
import com.andrew.apollo.ui.activities.BaseActivity;
import com.andrew.apollo.ui.fragments.profile.ApolloFragment;
import com.andrew.apollo.utils.MusicUtils;
import com.andrew.apollo.utils.NavUtils;
import com.andrew.apollo.utils.PreferenceUtils;
import com.frostwire.android.R;
import com.viewpagerindicator.TitlePageIndicator;

import java.util.List;

Expand Down Expand Up @@ -81,4 +64,16 @@ public void onItemClick(final AdapterView<?> parent, final View view, final int
public Loader<List<Song>> onCreateLoader(final int id, final Bundle args) {
return new LastAddedLoader(getActivity());
}

@Override
protected boolean isSimpleLayout() {
return true;
}

@Override
public void onMetaChanged() {
if (mAdapter != null) {
mAdapter.notifyDataSetChanged();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,12 @@
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.andrew.apollo.ui.fragments.*;
import com.frostwire.android.R;
import android.view.*;
import com.andrew.apollo.adapters.PagerAdapter;
import com.andrew.apollo.adapters.PagerAdapter.MusicFragments;
import com.andrew.apollo.utils.MusicUtils;
import com.andrew.apollo.utils.NavUtils;
import com.andrew.apollo.utils.PreferenceUtils;
import com.andrew.apollo.utils.SortOrder;
import com.andrew.apollo.utils.ThemeUtils;
import com.andrew.apollo.ui.fragments.*;
import com.andrew.apollo.utils.*;
import com.frostwire.android.R;
import com.viewpagerindicator.TitlePageIndicator;
import com.viewpagerindicator.TitlePageIndicator.OnCenterItemClickListener;

Expand Down Expand Up @@ -123,7 +113,7 @@ public View onCreateView(final LayoutInflater inflater, final ViewGroup containe
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Initialze the theme resources
// Initialize the theme resources
mResources = new ThemeUtils(getActivity());
// Enable the options menu
setHasOptionsMenu(true);
Expand Down

0 comments on commit c030c48

Please sign in to comment.