From 054f83744088381f99765bf2957ddbed19d8e61f Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 26 Aug 2013 20:07:03 -0700 Subject: Refactor remembering lists so it's done in onCreateView (seems to be only way it keeps position intact) --- .../daneren2005/dsub/fragments/SearchFragment.java | 2 +- .../dsub/fragments/SelectDirectoryFragment.java | 88 +++++++++++----------- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/src/github/daneren2005/dsub/fragments/SearchFragment.java b/src/github/daneren2005/dsub/fragments/SearchFragment.java index 21f810a4..6fa86737 100644 --- a/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -134,6 +134,7 @@ public class SearchFragment extends SubsonicFragment { if(searchResult != null) { skipSearch = true; + populateList(); } return rootView; @@ -192,7 +193,6 @@ public class SearchFragment extends SubsonicFragment { public void search(final String query, final boolean autoplay) { if(skipSearch) { skipSearch = false; - populateList(); return; } mergeAdapter = new MergeAdapter(); diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 60d3eaad..c5489c6c 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -140,13 +140,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter invalidated = true; } } else { - new LoadTask() { - @Override - protected MusicDirectory load(MusicService service) throws Exception { - albumListSize = entries.size(); - return new MusicDirectory(entries); - } - }.execute(); + licenseValid = true; + finishLoading(); } if(name != null) { @@ -437,44 +432,47 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter @Override protected void done(Pair result) { entries = result.getFirst().getChildren(); - - int songCount = 0; - for (MusicDirectory.Entry entry : entries) { - if (!entry.isDirectory()) { - songCount++; - } - } - - if (songCount > 0) { - if(showHeader) { - View header = createHeader(entries); - if(header != null) { - entryList.addHeaderView(header, null, false); - } - } - } else { - showHeader = false; - hideButtons = true; - } - - emptyView.setVisibility(entries.isEmpty() ? View.VISIBLE : View.GONE); - entryAdapter = new EntryAdapter(context, getImageLoader(), entries, (podcastId == null) ? true : false); - if(albumListType == null || "starred".equals(albumListType)) { - entryList.setAdapter(entryAdapter); - } else { - entryList.setAdapter(new AlbumListAdapter(context, entryAdapter, albumListType, albumListExtra, albumListSize)); - } - entryList.setVisibility(View.VISIBLE); - licenseValid = result.getSecond(); - context.supportInvalidateOptionsMenu(); - - Bundle args = getArguments(); - boolean playAll = args.getBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false); - if (playAll && songCount > 0) { - playAll(args.getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, false), false); - } - } - } + licenseValid = result.getSecond(); + finishLoading(); + } + } + + private void finishLoading() { + int songCount = 0; + for (MusicDirectory.Entry entry : entries) { + if (!entry.isDirectory()) { + songCount++; + } + } + + if (songCount > 0) { + if(showHeader) { + View header = createHeader(entries); + if(header != null) { + entryList.addHeaderView(header, null, false); + } + } + } else { + showHeader = false; + hideButtons = true; + } + + emptyView.setVisibility(entries.isEmpty() ? View.VISIBLE : View.GONE); + entryAdapter = new EntryAdapter(context, getImageLoader(), entries, (podcastId == null) ? true : false); + if(albumListType == null || "starred".equals(albumListType)) { + entryList.setAdapter(entryAdapter); + } else { + entryList.setAdapter(new AlbumListAdapter(context, entryAdapter, albumListType, albumListExtra, albumListSize)); + } + entryList.setVisibility(View.VISIBLE); + context.supportInvalidateOptionsMenu(); + + Bundle args = getArguments(); + boolean playAll = args.getBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false); + if (playAll && songCount > 0) { + playAll(args.getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, false), false); + } + } private void playNow(final boolean shuffle, final boolean append) { if(getSelectedSongs().size() > 0) { -- cgit v1.2.3