diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-04-20 22:04:21 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-04-20 22:04:21 -0700 |
commit | b626f5c5cddb923170392172a63b63435431a5f3 (patch) | |
tree | 96ccfd8197026ce3c69abf0b015731a740fcaf73 /src | |
parent | 986be522c8f9614155adf4a970e16311659baf69 (diff) | |
download | dsub-b626f5c5cddb923170392172a63b63435431a5f3.tar.gz dsub-b626f5c5cddb923170392172a63b63435431a5f3.tar.bz2 dsub-b626f5c5cddb923170392172a63b63435431a5f3.zip |
Fix pull to refresh triggering on any scroll up
Diffstat (limited to 'src')
5 files changed, 69 insertions, 12 deletions
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<T> 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<T> extends SubsonicFragment implements listView.setAdapter(adapter = getAdapter(objects));
}
- refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout);
- refreshLayout.setOnRefreshListener(this);
-
return rootView;
}
|