From b626f5c5cddb923170392172a63b63435431a5f3 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 20 Apr 2014 22:04:21 -0700 Subject: Fix pull to refresh triggering on any scroll up --- .../daneren2005/dsub/fragments/ChatFragment.java | 12 ++++++++++++ .../daneren2005/dsub/fragments/SearchFragment.java | 17 ++++++++++++++--- .../dsub/fragments/SelectArtistFragment.java | 17 ++++++++++++++--- .../dsub/fragments/SelectDirectoryFragment.java | 18 +++++++++++++++--- .../daneren2005/dsub/fragments/SelectListFragment.java | 17 ++++++++++++++--- 5 files changed, 69 insertions(+), 12 deletions(-) (limited to 'src/github/daneren2005') diff --git a/src/github/daneren2005/dsub/fragments/ChatFragment.java b/src/github/daneren2005/dsub/fragments/ChatFragment.java index 1742a489..3e53f2ad 100644 --- a/src/github/daneren2005/dsub/fragments/ChatFragment.java +++ b/src/github/daneren2005/dsub/fragments/ChatFragment.java @@ -23,6 +23,7 @@ import android.view.ViewGroup; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; +import android.widget.AbsListView; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ListView; @@ -131,6 +132,17 @@ public class ChatFragment extends SubsonicFragment { refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout); refreshLayout.setOnRefreshListener(this); + chatListView.setOnScrollListener(new AbsListView.OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView view, int scrollState) {} + + @Override + public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + int topRowVerticalPosition = (chatListView.getChildCount() == 0) ? 0 : chatListView.getChildAt(0).getTop(); + refreshLayout.setEnabled(topRowVerticalPosition >= 0); + } + }); + return rootView; } diff --git a/src/github/daneren2005/dsub/fragments/SearchFragment.java b/src/github/daneren2005/dsub/fragments/SearchFragment.java index 888a5496..9fc35cd2 100644 --- a/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -13,6 +13,7 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.View; import android.view.MenuItem; +import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ListAdapter; import android.widget.ListView; @@ -92,6 +93,9 @@ public class SearchFragment extends SubsonicFragment { moreAlbumsButton = buttons.findViewById(R.id.search_more_albums); moreSongsButton = buttons.findViewById(R.id.search_more_songs); + refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout); + refreshLayout.setEnabled(false); + list = (ListView) rootView.findViewById(R.id.fragment_list); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @@ -122,6 +126,16 @@ public class SearchFragment extends SubsonicFragment { } }); registerForContextMenu(list); + list.setOnScrollListener(new AbsListView.OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView view, int scrollState) {} + + @Override + public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + int topRowVerticalPosition = (list.getChildCount() == 0) ? 0 : list.getChildAt(0).getTop(); + refreshLayout.setEnabled(topRowVerticalPosition >= 0); + } + }); context.onNewIntent(context.getIntent()); if(searchResult != null) { @@ -129,9 +143,6 @@ public class SearchFragment extends SubsonicFragment { populateList(); } - refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout); - refreshLayout.setEnabled(false); - return rootView; } diff --git a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 29c6c981..b841f0d3 100644 --- a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -10,6 +10,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ListView; import android.widget.TextView; @@ -64,11 +65,24 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { rootView = inflater.inflate(R.layout.abstract_list_fragment, container, false); + refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout); + refreshLayout.setOnRefreshListener(this); + artistList = (ListView) rootView.findViewById(R.id.fragment_list); artistList.setOnItemClickListener(this); if(Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { artistList.setFastScrollAlwaysVisible(true); } + artistList.setOnScrollListener(new AbsListView.OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView view, int scrollState) {} + + @Override + public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + int topRowVerticalPosition = (artistList.getChildCount() == 0) ? 0 : artistList.getChildAt(0).getTop(); + refreshLayout.setEnabled(topRowVerticalPosition >= 0); + } + }); folderButtonParent = inflater.inflate(R.layout.select_artist_header, artistList, false); folderName = (TextView) folderButtonParent.findViewById(R.id.select_artist_folder_2); @@ -90,9 +104,6 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie setMusicFolders(); } - refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout); - refreshLayout.setOnRefreshListener(this); - return rootView; } diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 1ed4f185..1479d4cd 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -15,6 +15,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ImageView; import android.widget.ListView; @@ -95,6 +96,9 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { rootView = inflater.inflate(R.layout.select_album, container, false); + refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout); + refreshLayout.setOnRefreshListener(this); + entryList = (DragSortListView) rootView.findViewById(R.id.select_album_entries); entryList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); entryList.setOnItemClickListener(this); @@ -113,6 +117,17 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } }); + entryList.setOnScrollListener(new AbsListView.OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView view, int scrollState) {} + + @Override + public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + int topRowVerticalPosition = (entryList.getChildCount() == 0) ? 0 : entryList.getChildAt(0).getTop(); + refreshLayout.setEnabled(topRowVerticalPosition >= 0); + } + }); + emptyView = rootView.findViewById(R.id.select_album_empty); registerForContextMenu(entryList); @@ -159,9 +174,6 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter setTitle(name); } - refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout); - refreshLayout.setOnRefreshListener(this); - return rootView; } diff --git a/src/github/daneren2005/dsub/fragments/SelectListFragment.java b/src/github/daneren2005/dsub/fragments/SelectListFragment.java index 9657c66c..35bf95c1 100644 --- a/src/github/daneren2005/dsub/fragments/SelectListFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectListFragment.java @@ -27,6 +27,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AbsListView; import android.widget.Adapter; import android.widget.AdapterView; import android.widget.ArrayAdapter; @@ -76,8 +77,21 @@ public abstract class SelectListFragment extends SubsonicFragment implements public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { rootView = inflater.inflate(R.layout.abstract_list_fragment, container, false); + refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout); + refreshLayout.setOnRefreshListener(this); + listView = (ListView)rootView.findViewById(R.id.fragment_list); listView.setOnItemClickListener(this); + listView.setOnScrollListener(new AbsListView.OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView view, int scrollState) {} + + @Override + public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + int topRowVerticalPosition = (listView.getChildCount() == 0) ? 0 : listView.getChildAt(0).getTop(); + refreshLayout.setEnabled(topRowVerticalPosition >= 0); + } + }); registerForContextMenu(listView); emptyView = rootView.findViewById(R.id.fragment_list_empty); @@ -87,9 +101,6 @@ public abstract class SelectListFragment extends SubsonicFragment implements listView.setAdapter(adapter = getAdapter(objects)); } - refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout); - refreshLayout.setOnRefreshListener(this); - return rootView; } -- cgit v1.2.3 From 6a61a3ab776e54b19fb7055b8c4f86586b85b039 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 21 Apr 2014 20:38:20 -0700 Subject: Make SelectArtistFragment inherit from SelectListFragment --- .../dsub/fragments/SelectArtistFragment.java | 107 +++++++++------------ 1 file changed, 44 insertions(+), 63 deletions(-) (limited to 'src/github/daneren2005') diff --git a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index b841f0d3..c38072cf 100644 --- a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -12,6 +12,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import github.daneren2005.dsub.R; @@ -23,6 +24,7 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.ArtistAdapter; @@ -31,24 +33,21 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; -public class SelectArtistFragment extends SubsonicFragment implements AdapterView.OnItemClickListener { +public class SelectArtistFragment extends SelectListFragment { private static final String TAG = SelectArtistFragment.class.getSimpleName(); private static final int MENU_GROUP_MUSIC_FOLDER = 10; - private ListView artistList; private View folderButtonParent; private View folderButton; private TextView folderName; private List musicFolders = null; private List entries; - private List artists; @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); if(bundle != null) { - artists = (List) bundle.getSerializable(Constants.FRAGMENT_LIST); musicFolders = (List) bundle.getSerializable(Constants.FRAGMENT_LIST2); } artist = true; @@ -57,73 +56,33 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putSerializable(Constants.FRAGMENT_LIST, (Serializable) artists); outState.putSerializable(Constants.FRAGMENT_LIST2, (Serializable) musicFolders); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { - rootView = inflater.inflate(R.layout.abstract_list_fragment, container, false); + super.onCreateView(inflater, container, bundle); - refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout); - refreshLayout.setOnRefreshListener(this); - - artistList = (ListView) rootView.findViewById(R.id.fragment_list); - artistList.setOnItemClickListener(this); if(Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { - artistList.setFastScrollAlwaysVisible(true); + listView.setFastScrollAlwaysVisible(true); } - artistList.setOnScrollListener(new AbsListView.OnScrollListener() { - @Override - public void onScrollStateChanged(AbsListView view, int scrollState) {} - - @Override - public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - int topRowVerticalPosition = (artistList.getChildCount() == 0) ? 0 : artistList.getChildAt(0).getTop(); - refreshLayout.setEnabled(topRowVerticalPosition >= 0); - } - }); - - folderButtonParent = inflater.inflate(R.layout.select_artist_header, artistList, false); - folderName = (TextView) folderButtonParent.findViewById(R.id.select_artist_folder_2); - artistList.addHeaderView(folderButtonParent); - folderButton = folderButtonParent.findViewById(R.id.select_artist_folder); - registerForContextMenu(artistList); - if(artists == null) { - if(!primaryFragment) { - invalidated = true; - } else { - refresh(false); - } - } else { + if(objects != null) { if (Util.isOffline(context) || Util.isTagBrowsing(context)) { folderButton.setVisibility(View.GONE); } - artistList.setAdapter(new ArtistAdapter(context, artists)); setMusicFolders(); } return rootView; } - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { - menuInflater.inflate(R.menu.select_artist, menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - return super.onOptionsItemSelected(item); - - } - @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; - Object entry = artistList.getItemAtPosition(info.position); + Object entry = listView.getItemAtPosition(info.position); if (entry instanceof Artist) { onCreateContextMenu(menu, view, menuInfo, entry); @@ -155,7 +114,7 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie } AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - Artist artist = (Artist) artistList.getItemAtPosition(info.position); + Artist artist = (Artist) listView.getItemAtPosition(info.position); if (artist != null) { return onContextItemSelected(menuItem, artist); @@ -193,19 +152,20 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie } @Override - protected void refresh(boolean refresh) { - load(refresh); - } + protected void refresh(final boolean refresh) { + if(folderButton == null) { + folderButtonParent = getLayoutInflater(null).inflate(R.layout.select_artist_header, listView, false); + folderName = (TextView) folderButtonParent.findViewById(R.id.select_artist_folder_2); + listView.addHeaderView(folderButtonParent); + folderButton = folderButtonParent.findViewById(R.id.select_artist_folder); + } - private void load(final boolean refresh) { - setTitle(R.string.button_bar_browse); - if (Util.isOffline(context) || Util.isTagBrowsing(context)) { folderButton.setVisibility(View.GONE); } else { folderButton.setVisibility(View.VISIBLE); } - artistList.setVisibility(View.INVISIBLE); + listView.setVisibility(View.INVISIBLE); BackgroundTask task = new TabBackgroundTask(this) { @Override @@ -220,21 +180,42 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie @Override protected void done(Indexes result) { - artists = new ArrayList(result.getShortcuts().size() + result.getArtists().size()); - artists.addAll(result.getShortcuts()); - artists.addAll(result.getArtists()); - artistList.setFastScrollEnabled(false); - artistList.setAdapter(new ArtistAdapter(context, artists)); - artistList.setFastScrollEnabled(true); + objects = new ArrayList(result.getShortcuts().size() + result.getArtists().size()); + objects.addAll(result.getShortcuts()); + objects.addAll(result.getArtists()); + listView.setFastScrollEnabled(false); + listView.setAdapter(adapter = getAdapter(objects)); + listView.setFastScrollEnabled(true); entries = result.getEntries(); setMusicFolders(); - artistList.setVisibility(View.VISIBLE); + listView.setVisibility(View.VISIBLE); refreshLayout.setRefreshing(false); } }; task.execute(); } + + @Override + public int getOptionsMenu() { + return R.menu.select_artist; + } + + @Override + public ArrayAdapter getAdapter(List objects) { + return new ArtistAdapter(context, objects); + } + + @Override + public List getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception { + return null; + } + + @Override + public int getTitleResource() { + return R.string.button_bar_browse; + } + private void setMusicFolders() { // Display selected music folder if (musicFolders != null) { -- cgit v1.2.3