Back out of limiters
This commit is contained in:
parent
977d24a324
commit
378a5b3a93
@ -343,7 +343,31 @@ public class LibraryActivity
|
||||
mTextFilter.setText("");
|
||||
setSearchBoxVisible(false);
|
||||
} else {
|
||||
finish();
|
||||
Limiter limiter = mPagerAdapter.getCurrentLimiter();
|
||||
if (limiter != null && limiter.type != MediaUtils.TYPE_FILE) {
|
||||
int pos = -1;
|
||||
switch (limiter.type) {
|
||||
case MediaUtils.TYPE_ALBUM:
|
||||
albumToArtistLimiter(limiter);
|
||||
pos = mPagerAdapter.mAlbumsPosition;
|
||||
break;
|
||||
case MediaUtils.TYPE_ARTIST:
|
||||
mPagerAdapter.clearLimiter(MediaUtils.TYPE_ARTIST);
|
||||
pos = mPagerAdapter.mArtistsPosition;
|
||||
break;
|
||||
case MediaUtils.TYPE_GENRE:
|
||||
mPagerAdapter.clearLimiter(MediaUtils.TYPE_GENRE);
|
||||
pos = mPagerAdapter.mGenresPosition;
|
||||
break;
|
||||
}
|
||||
if (pos == -1) {
|
||||
updateLimiterViews();
|
||||
} else {
|
||||
mViewPager.setCurrentItem(pos);
|
||||
}
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KeyEvent.KEYCODE_SEARCH:
|
||||
@ -561,19 +585,7 @@ public class LibraryActivity
|
||||
Limiter limiter = mPagerAdapter.getCurrentLimiter();
|
||||
int type = limiter.type;
|
||||
if (i == 1 && type == MediaUtils.TYPE_ALBUM) {
|
||||
ContentResolver resolver = getContentResolver();
|
||||
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
||||
String[] projection = new String[] { MediaStore.Audio.Media.ARTIST_ID };
|
||||
Cursor cursor = resolver.query(uri, projection, limiter.data.toString(), null, null);
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToNext()) {
|
||||
String[] fields = { limiter.names[0] };
|
||||
String data = String.format("artist_id=%d", cursor.getLong(0));
|
||||
mPagerAdapter.setLimiter(new Limiter(MediaUtils.TYPE_ARTIST, fields, data));
|
||||
updateLimiterViews();
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
albumToArtistLimiter(limiter);
|
||||
} else if (i > 0) {
|
||||
Assert.assertEquals(MediaUtils.TYPE_FILE, limiter.type);
|
||||
File file = (File)limiter.data;
|
||||
@ -582,16 +594,37 @@ public class LibraryActivity
|
||||
file = file.getParentFile();
|
||||
}
|
||||
mPagerAdapter.setLimiter(FileSystemAdapter.buildLimiter(file));
|
||||
updateLimiterViews();
|
||||
} else {
|
||||
mPagerAdapter.clearLimiter(type);
|
||||
updateLimiterViews();
|
||||
}
|
||||
updateLimiterViews();
|
||||
} else {
|
||||
super.onClick(view);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the given album limiter and set that album's artist as the new
|
||||
* limiter.
|
||||
*
|
||||
* @param limiter A limiter with type = MediaUtils.TYPE_ALBUM
|
||||
*/
|
||||
private void albumToArtistLimiter(Limiter limiter)
|
||||
{
|
||||
ContentResolver resolver = getContentResolver();
|
||||
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
||||
String[] projection = new String[] { MediaStore.Audio.Media.ARTIST_ID };
|
||||
Cursor cursor = resolver.query(uri, projection, limiter.data.toString(), null, null);
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToNext()) {
|
||||
String[] fields = { limiter.names[0] };
|
||||
String data = String.format("artist_id=%d", cursor.getLong(0));
|
||||
mPagerAdapter.setLimiter(new Limiter(MediaUtils.TYPE_ARTIST, fields, data));
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a media query based off the data stored in the given intent.
|
||||
*
|
||||
|
@ -167,11 +167,19 @@ public class LibraryPagerAdapter
|
||||
/**
|
||||
* The position of the songs page, or -1 if it is hidden.
|
||||
*/
|
||||
private int mSongsPosition = -1;
|
||||
public int mSongsPosition = -1;
|
||||
/**
|
||||
* The position of the albums page, or -1 if it is hidden.
|
||||
*/
|
||||
private int mAlbumsPosition = -1;
|
||||
public int mAlbumsPosition = -1;
|
||||
/**
|
||||
* The position of the artists page, or -1 if it is hidden.
|
||||
*/
|
||||
public int mArtistsPosition = -1;
|
||||
/**
|
||||
* The position of the genres page, or -1 if it is hidden.
|
||||
*/
|
||||
public int mGenresPosition = -1;
|
||||
|
||||
private final ContentObserver mPlaylistObserver = new ContentObserver(null) {
|
||||
@Override
|
||||
@ -251,6 +259,8 @@ public class LibraryPagerAdapter
|
||||
int[] order = mTabOrder;
|
||||
int songsPosition = -1;
|
||||
int albumsPosition = -1;
|
||||
int artistsPosition = -1;
|
||||
int genresPosition = -1;
|
||||
for (int i = mTabCount; --i != -1; ) {
|
||||
switch (order[i]) {
|
||||
case MediaUtils.TYPE_ALBUM:
|
||||
@ -259,6 +269,12 @@ public class LibraryPagerAdapter
|
||||
case MediaUtils.TYPE_SONG:
|
||||
songsPosition = i;
|
||||
break;
|
||||
case MediaUtils.TYPE_ARTIST:
|
||||
artistsPosition = i;
|
||||
break;
|
||||
case MediaUtils.TYPE_GENRE:
|
||||
genresPosition = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -271,6 +287,8 @@ public class LibraryPagerAdapter
|
||||
|
||||
mSongsPosition = songsPosition;
|
||||
mAlbumsPosition = albumsPosition;
|
||||
mArtistsPosition = artistsPosition;
|
||||
mGenresPosition = genresPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user