aboutsummaryrefslogtreecommitdiff
path: root/src/github/daneren2005
diff options
context:
space:
mode:
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r--src/github/daneren2005/dsub/fragments/ChatFragment.java12
-rw-r--r--src/github/daneren2005/dsub/fragments/SearchFragment.java17
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectArtistFragment.java98
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java18
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectListFragment.java17
5 files changed, 100 insertions, 62 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..c38072cf 100644
--- a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java
@@ -10,7 +10,9 @@ 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.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import github.daneren2005.dsub.R;
@@ -22,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;
@@ -30,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<Artist> {
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<MusicFolder> musicFolders = null;
private List<MusicDirectory.Entry> entries;
- private List<Artist> artists;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
if(bundle != null) {
- artists = (List<Artist>) bundle.getSerializable(Constants.FRAGMENT_LIST);
musicFolders = (List<MusicFolder>) bundle.getSerializable(Constants.FRAGMENT_LIST2);
}
artist = true;
@@ -56,63 +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);
- 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);
}
- 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();
}
- refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout);
- refreshLayout.setOnRefreshListener(this);
-
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);
@@ -144,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);
@@ -182,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<Indexes> task = new TabBackgroundTask<Indexes>(this) {
@Override
@@ -209,21 +180,42 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie
@Override
protected void done(Indexes result) {
- artists = new ArrayList<Artist>(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<Artist>(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<Artist> objects) {
+ return new ArtistAdapter(context, objects);
+ }
+
+ @Override
+ public List<Artist> 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) {
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
index b4ea7857..499732f1 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.GridView;
import android.widget.ImageView;
@@ -99,6 +100,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);
+
albumList = (GridView) rootView.findViewById(R.id.select_album_albums);
albumList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
@@ -138,6 +142,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);
@@ -184,9 +199,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;
}