From ecca7014525df432376705bf0400ef45b9568149 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 20 Apr 2014 21:53:25 -0700 Subject: Start of adding grid for albums --- .../dsub/fragments/SelectDirectoryFragment.java | 43 +++++++++++++++---- src/github/daneren2005/dsub/view/AlbumCell.java | 19 ++++++++ .../daneren2005/dsub/view/AlbumGridAdapter.java | 50 ++++++++++++++++++++++ 3 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 src/github/daneren2005/dsub/view/AlbumCell.java create mode 100644 src/github/daneren2005/dsub/view/AlbumGridAdapter.java (limited to 'src') diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 1ed4f185..b4ea7857 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -16,6 +16,7 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; +import android.widget.GridView; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; @@ -23,6 +24,7 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.Share; import github.daneren2005.dsub.util.ImageLoader; +import github.daneren2005.dsub.view.AlbumGridAdapter; import github.daneren2005.dsub.view.EntryAdapter; import java.io.Serializable; @@ -49,12 +51,14 @@ import java.util.Set; public class SelectDirectoryFragment extends SubsonicFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectDirectoryFragment.class.getSimpleName(); + private GridView albumList; private DragSortListView entryList; private View emptyView; private boolean hideButtons = false; private Boolean licenseValid; private boolean showHeader = true; private EntryAdapter entryAdapter; + private List albums; private List entries; String id; @@ -95,6 +99,27 @@ 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); + albumList = (GridView) rootView.findViewById(R.id.select_album_albums); + albumList.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position); + SubsonicFragment fragment = new SelectDirectoryFragment(); + Bundle args = new Bundle(); + args.putString(Constants.INTENT_EXTRA_NAME_ID, entry.getId()); + args.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle()); + if ("newest".equals(albumListType)) { + args.putBoolean(Constants.INTENT_EXTRA_REFRESH_LISTINGS, true); + } + if(entry.getArtist() == null && entry.getParent() == null) { + args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true); + } + fragment.setArguments(args); + + replaceFragment(fragment, true); + } + }); + entryList = (DragSortListView) rootView.findViewById(R.id.select_album_entries); entryList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); entryList.setOnItemClickListener(this); @@ -563,7 +588,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter @Override protected void done(Pair result) { - entries = result.getFirst().getChildren(); + albums = result.getFirst().getChildren(true, false); + entries = result.getFirst().getChildren(false, true); licenseValid = result.getSecond(); finishLoading(); } @@ -591,13 +617,14 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } } - emptyView.setVisibility(entries.isEmpty() ? View.VISIBLE : View.GONE); - entryAdapter = new EntryAdapter(context, getImageLoader(), entries, (podcastId == null)); - if(albumListType == null || "starred".equals(albumListType)) { - entryList.setAdapter(entryAdapter); - } else { - entryList.setAdapter(new AlbumListAdapter(context, entryAdapter, albumListType, albumListExtra, albumListSize)); - } + emptyView.setVisibility((entries.isEmpty() && albums.isEmpty()) ? View.VISIBLE : View.GONE); + entryAdapter = new EntryAdapter(context, getImageLoader(), entries, (podcastId == null)); + entryList.setAdapter(entryAdapter); + if(albumListType == null || "starred".equals(albumListType)) { + albumList.setAdapter(new AlbumGridAdapter(context, getImageLoader(), albums)); + } else { + albumList.setAdapter(new AlbumListAdapter(context, new AlbumGridAdapter(context, getImageLoader(), albums), albumListType, albumListExtra, albumListSize)); + } entryList.setVisibility(View.VISIBLE); context.supportInvalidateOptionsMenu(); diff --git a/src/github/daneren2005/dsub/view/AlbumCell.java b/src/github/daneren2005/dsub/view/AlbumCell.java new file mode 100644 index 00000000..b78ed442 --- /dev/null +++ b/src/github/daneren2005/dsub/view/AlbumCell.java @@ -0,0 +1,19 @@ +/* + This file is part of Subsonic. + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see . + Copyright 2014 (C) Scott Jackson +*/ + +package github.daneren2005.dsub.view; + +public class AlbumCell { +} diff --git a/src/github/daneren2005/dsub/view/AlbumGridAdapter.java b/src/github/daneren2005/dsub/view/AlbumGridAdapter.java new file mode 100644 index 00000000..60d4cda6 --- /dev/null +++ b/src/github/daneren2005/dsub/view/AlbumGridAdapter.java @@ -0,0 +1,50 @@ +/* + This file is part of Subsonic. + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see . + Copyright 2014 (C) Scott Jackson +*/ + +package github.daneren2005.dsub.view; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; + +import java.util.List; + +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.util.ImageLoader; + +public class AlbumGridAdapter extends ArrayAdapter { + private final static String TAG = AlbumGridAdapter.class.getSimpleName(); + private final Context activity; + private final ImageLoader imageLoader; + private List entries; + + public AlbumGridAdapter(Context activity, ImageLoader imageLoader, List entries) { + super(activity, android.R.layout.simple_list_item_1, entries); + this.entries = entries; + this.activity = activity; + this.imageLoader = imageLoader; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + MusicDirectory.Entry entry = getItem(position); + + AlbumView view; + view = new AlbumView(activity); + view.setObject(entry, imageLoader); + return view; + } +} -- cgit v1.2.3