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 --- res/layout/select_album.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'res') diff --git a/res/layout/select_album.xml b/res/layout/select_album.xml index 9b1e36dd..b9bd3196 100644 --- a/res/layout/select_album.xml +++ b/res/layout/select_album.xml @@ -25,6 +25,17 @@ android:layout_height="wrap_content" android:padding="10dip"/> + + Date: Tue, 22 Apr 2014 20:44:53 -0700 Subject: More work on showing albums in grid --- res/layout/album_cell_item.xml | 56 +++++++++++++++++ res/layout/select_album.xml | 1 - .../dsub/fragments/SelectDirectoryFragment.java | 4 +- src/github/daneren2005/dsub/view/AlbumCell.java | 71 +++++++++++++++++++++- .../daneren2005/dsub/view/AlbumGridAdapter.java | 9 ++- .../daneren2005/dsub/view/SquareImageView.java | 32 ++++++++++ 6 files changed, 167 insertions(+), 6 deletions(-) create mode 100644 res/layout/album_cell_item.xml create mode 100644 src/github/daneren2005/dsub/view/SquareImageView.java (limited to 'res') diff --git a/res/layout/album_cell_item.xml b/res/layout/album_cell_item.xml new file mode 100644 index 00000000..9cc85c6e --- /dev/null +++ b/res/layout/album_cell_item.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/select_album.xml b/res/layout/select_album.xml index b9bd3196..53b6bb63 100644 --- a/res/layout/select_album.xml +++ b/res/layout/select_album.xml @@ -30,7 +30,6 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:numColumns="auto_fit" - android:columnWidth="90dp" android:horizontalSpacing="10dp" android:verticalSpacing="10dp" android:gravity="center" diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 499732f1..fb03f325 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -142,13 +142,13 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } }); - entryList.setOnScrollListener(new AbsListView.OnScrollListener() { + albumList.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(); + int topRowVerticalPosition = (albumList.getChildCount() == 0) ? 0 : albumList.getChildAt(0).getTop(); refreshLayout.setEnabled(topRowVerticalPosition >= 0); } }); diff --git a/src/github/daneren2005/dsub/view/AlbumCell.java b/src/github/daneren2005/dsub/view/AlbumCell.java index b78ed442..9cee0c41 100644 --- a/src/github/daneren2005/dsub/view/AlbumCell.java +++ b/src/github/daneren2005/dsub/view/AlbumCell.java @@ -15,5 +15,74 @@ package github.daneren2005.dsub.view; -public class AlbumCell { +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; + +import java.io.File; + +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.util.FileUtil; +import github.daneren2005.dsub.util.ImageLoader; + +public class AlbumCell extends UpdateView { + private static final String TAG = AlbumCell.class.getSimpleName(); + + private Context context; + private MusicDirectory.Entry album; + private File file; + + private View coverArtView; + private TextView titleView; + private TextView artistView; + + public AlbumCell(Context context) { + super(context); + this.context = context; + LayoutInflater.from(context).inflate(R.layout.album_cell_item, this, true); + + coverArtView = findViewById(R.id.album_coverart); + titleView = (TextView) findViewById(R.id.album_title); + artistView = (TextView) findViewById(R.id.album_artist); + moreButton = (ImageView) findViewById(R.id.album_more); + moreButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + v.showContextMenu(); + } + }); + } + + protected void setObjectImpl(Object obj1, Object obj2) { + this.album = (MusicDirectory.Entry) obj1; + if(album.getAlbum() == null) { + titleView.setText(album.getTitle()); + } else { + titleView.setText(album.getAlbum()); + } + String artist = album.getArtist(); + if(artist == null) { + artist = ""; + } + if(album.getYear() != null) { + artist += " - " + album.getYear(); + } + artistView.setText(artist); + artistView.setVisibility(album.getArtist() == null ? View.GONE : View.VISIBLE); + ((ImageLoader)obj2).loadImage(coverArtView, album, false, true); + file = null; + } + + @Override + protected void updateBackground() { + if(file == null) { + file = FileUtil.getAlbumDirectory(context, album); + } + + exists = file.exists(); + isStarred = album.isStarred(); + } } diff --git a/src/github/daneren2005/dsub/view/AlbumGridAdapter.java b/src/github/daneren2005/dsub/view/AlbumGridAdapter.java index 60d4cda6..3c81fa9a 100644 --- a/src/github/daneren2005/dsub/view/AlbumGridAdapter.java +++ b/src/github/daneren2005/dsub/view/AlbumGridAdapter.java @@ -42,8 +42,13 @@ public class AlbumGridAdapter extends ArrayAdapter { public View getView(int position, View convertView, ViewGroup parent) { MusicDirectory.Entry entry = getItem(position); - AlbumView view; - view = new AlbumView(activity); + AlbumCell view; + if(convertView instanceof AlbumCell) { + view = (AlbumCell) convertView; + } else { + view = new AlbumCell(activity); + } + view.setObject(entry, imageLoader); return view; } diff --git a/src/github/daneren2005/dsub/view/SquareImageView.java b/src/github/daneren2005/dsub/view/SquareImageView.java new file mode 100644 index 00000000..77ca50db --- /dev/null +++ b/src/github/daneren2005/dsub/view/SquareImageView.java @@ -0,0 +1,32 @@ +/* + 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.util.AttributeSet; +import android.widget.ImageView; + +public class SquareImageView extends ImageView { + public SquareImageView(final Context context, final AttributeSet attrs) { + super(context, attrs); + } + + @Override + public void onMeasure(final int widthSpec, final int heightSpec) { + super.onMeasure(widthSpec, heightSpec); + setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); + } +} -- cgit v1.2.3 From 3866cadd13a6a2ac65d617d14bef749688f7db50 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 26 Apr 2014 16:41:42 -0700 Subject: Fixed having both GridView and ListView together by putting GridView in ListView's header --- res/layout/grid_view.xml | 10 +++ res/layout/select_album.xml | 16 +--- .../dsub/fragments/SelectDirectoryFragment.java | 69 ++++++-------- src/github/daneren2005/dsub/view/AlbumView.java | 100 --------------------- .../daneren2005/dsub/view/ArtistEntryView.java | 2 +- src/github/daneren2005/dsub/view/EntryAdapter.java | 29 ++---- .../dsub/view/UnscrollableGridView.java | 81 +++++++++++++++++ 7 files changed, 129 insertions(+), 178 deletions(-) create mode 100644 res/layout/grid_view.xml delete mode 100644 src/github/daneren2005/dsub/view/AlbumView.java create mode 100644 src/github/daneren2005/dsub/view/UnscrollableGridView.java (limited to 'res') diff --git a/res/layout/grid_view.xml b/res/layout/grid_view.xml new file mode 100644 index 00000000..549f9ae5 --- /dev/null +++ b/res/layout/grid_view.xml @@ -0,0 +1,10 @@ + + \ No newline at end of file diff --git a/res/layout/select_album.xml b/res/layout/select_album.xml index 53b6bb63..954fbcf6 100644 --- a/res/layout/select_album.xml +++ b/res/layout/select_album.xml @@ -25,23 +25,11 @@ android:layout_height="wrap_content" android:padding="10dip"/> - - - + android:layout_weight="1.0"/> \ No newline at end of file diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index c4151220..34be2d8c 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -53,7 +53,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter private static final String TAG = SelectDirectoryFragment.class.getSimpleName(); private GridView albumList; - private DragSortListView entryList; + private ListView entryList; private View emptyView; private boolean hideButtons = false; private Boolean licenseValid; @@ -104,7 +104,22 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout); refreshLayout.setOnRefreshListener(this); - albumList = (GridView) rootView.findViewById(R.id.select_album_albums); + entryList = (ListView) rootView.findViewById(R.id.select_album_entries); + entryList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); + entryList.setOnItemClickListener(this); + + 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); + } + }); + + albumList = (GridView) inflater.inflate(R.layout.grid_view, entryList, false); albumList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { @@ -124,46 +139,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter replaceFragment(fragment, true); } }); - - albumList.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 = (albumList.getChildCount() == 0) ? 0 : albumList.getChildAt(0).getTop(); - refreshLayout.setEnabled(topRowVerticalPosition >= 0); - } - }); - - entryList = (DragSortListView) rootView.findViewById(R.id.select_album_entries); - entryList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); - entryList.setOnItemClickListener(this); - entryList.setDropListener(new DragSortListView.DropListener() { - @Override - public void drop(int from, int to) { - int max = entries.size(); - if(to >= max) { - to = max - 1; - } - else if(to < 0) { - to = 0; - } - entries.add(to, entries.remove(from)); - entryAdapter.notifyDataSetChanged(); - } - }); - - 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); - } - }); + entryList.addHeaderView(albumList); emptyView = rootView.findViewById(R.id.select_album_empty); @@ -324,6 +300,9 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter MusicDirectory.Entry entry; if(view.getId() == R.id.select_album_entries) { + if(info.position == 0) { + return; + } entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position); albumContext = false; } else { @@ -360,6 +339,10 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter if(albumContext) { selectedItem = albums.get(showHeader ? (info.position - 1) : info.position); } else { + if(info.position == 0) { + return false; + } + info.position--; selectedItem = entries.get(showHeader ? (info.position - 1) : info.position); } @@ -645,7 +628,9 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter if(showHeader) { View header = createHeader(entries); if(header != null) { + entryList.removeHeaderView(albumList); entryList.addHeaderView(header, null, false); + entryList.addHeaderView(albumList); } } } else { diff --git a/src/github/daneren2005/dsub/view/AlbumView.java b/src/github/daneren2005/dsub/view/AlbumView.java deleted file mode 100644 index be13aa5c..00000000 --- a/src/github/daneren2005/dsub/view/AlbumView.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - 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 2009 (C) Sindre Mehus - */ -package github.daneren2005.dsub.view; - -import android.content.Context; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.ImageButton; -import android.widget.ImageView; -import android.widget.TextView; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.util.FileUtil; -import github.daneren2005.dsub.util.ImageLoader; -import github.daneren2005.dsub.util.Util; -import java.io.File; -import java.util.List; - -/** - * Used to display albums in a {@code ListView}. - * - * @author Sindre Mehus - */ -public class AlbumView extends UpdateView { - private static final String TAG = AlbumView.class.getSimpleName(); - - private Context context; - private MusicDirectory.Entry album; - private File file; - - private TextView titleView; - private TextView artistView; - private View coverArtView; - - public AlbumView(Context context) { - super(context); - this.context = context; - LayoutInflater.from(context).inflate(R.layout.album_list_item, this, true); - - titleView = (TextView) findViewById(R.id.album_title); - artistView = (TextView) findViewById(R.id.album_artist); - coverArtView = findViewById(R.id.album_coverart); - starButton = (ImageButton) findViewById(R.id.album_star); - starButton.setFocusable(false); - - moreButton = (ImageView) findViewById(R.id.album_more); - moreButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - v.showContextMenu(); - } - }); - } - - protected void setObjectImpl(Object obj1, Object obj2) { - this.album = (MusicDirectory.Entry) obj1; - if(album.getAlbum() == null) { - titleView.setText(album.getTitle()); - } else { - titleView.setText(album.getAlbum()); - } - String artist = album.getArtist(); - if(artist == null) { - artist = ""; - } - if(album.getYear() != null) { - artist += " - " + album.getYear(); - } - artistView.setText(artist); - artistView.setVisibility(album.getArtist() == null ? View.GONE : View.VISIBLE); - ((ImageLoader)obj2).loadImage(coverArtView, album, false, true); - file = null; - } - - @Override - protected void updateBackground() { - if(file == null) { - file = FileUtil.getAlbumDirectory(context, album); - } - - exists = file.exists(); - isStarred = album.isStarred(); - } -} diff --git a/src/github/daneren2005/dsub/view/ArtistEntryView.java b/src/github/daneren2005/dsub/view/ArtistEntryView.java index 958b4b87..86fe7b1f 100644 --- a/src/github/daneren2005/dsub/view/ArtistEntryView.java +++ b/src/github/daneren2005/dsub/view/ArtistEntryView.java @@ -37,7 +37,7 @@ import java.io.File; * @author Sindre Mehus */ public class ArtistEntryView extends UpdateView { - private static final String TAG = AlbumView.class.getSimpleName(); + private static final String TAG = ArtistEntryView.class.getSimpleName(); private Context context; private MusicDirectory.Entry artist; diff --git a/src/github/daneren2005/dsub/view/EntryAdapter.java b/src/github/daneren2005/dsub/view/EntryAdapter.java index 4fa5cdf0..7da6e5a1 100644 --- a/src/github/daneren2005/dsub/view/EntryAdapter.java +++ b/src/github/daneren2005/dsub/view/EntryAdapter.java @@ -54,26 +54,13 @@ public class EntryAdapter extends ArrayAdapter { public View getView(int position, View convertView, ViewGroup parent) { MusicDirectory.Entry entry = getItem(position); - if (entry.isDirectory()) { - if(entry.getArtist() != null || entry.getParent() != null) { - AlbumView view; - view = new AlbumView(activity); - view.setObject(entry, imageLoader); - return view; - } else { - ArtistEntryView view = new ArtistEntryView(activity); - view.setObject(entry); - return view; - } - } else { - SongView view; - if (convertView != null && convertView instanceof SongView) { - view = (SongView) convertView; - } else { - view = new SongView(activity); - } - view.setObject(entry, checkable); - return view; - } + SongView view; + if (convertView != null && convertView instanceof SongView) { + view = (SongView) convertView; + } else { + view = new SongView(activity); + } + view.setObject(entry, checkable); + return view; } } diff --git a/src/github/daneren2005/dsub/view/UnscrollableGridView.java b/src/github/daneren2005/dsub/view/UnscrollableGridView.java new file mode 100644 index 00000000..a36a7b79 --- /dev/null +++ b/src/github/daneren2005/dsub/view/UnscrollableGridView.java @@ -0,0 +1,81 @@ +package github.daneren2005.dsub.view; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.widget.AbsListView; +import android.widget.GridView; +import android.widget.ListAdapter; + +/** + * Created by Scott on 4/26/2014. + */ +public class UnscrollableGridView extends GridView { + public UnscrollableGridView(Context context) { + super(context); + } + + public UnscrollableGridView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public UnscrollableGridView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + public int getColumnWidth() { + // This method will be called from onMeasure() too. + // It's better to use getMeasuredWidth(), as it is safe in this case. + final int totalHorizontalSpacing = getNumColumns() > 0 ? (getNumColumns() - 1) * getHorizontalSpacing() : 0; + return (getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - totalHorizontalSpacing) / getNumColumns(); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + // Sets the padding for this view. + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + + final int measuredWidth = getMeasuredWidth(); + final int childWidth = getColumnWidth(); + int childHeight = 0; + + // If there's an adapter, use it to calculate the height of this view. + final ListAdapter adapter = getAdapter(); + final int count; + + // There shouldn't be any inherent size (due to padding) if there are no child views. + if (adapter == null || (count = adapter.getCount()) == 0) { + setMeasuredDimension(0, 0); + return; + } + + // Get the first child from the adapter. + final View child = adapter.getView(0, null, this); + if (child != null) { + // Set a default LayoutParams on the child, if it doesn't have one on its own. + AbsListView.LayoutParams params = (AbsListView.LayoutParams) child.getLayoutParams(); + if (params == null) { + params = new AbsListView.LayoutParams(AbsListView.LayoutParams.WRAP_CONTENT, + AbsListView.LayoutParams.WRAP_CONTENT); + child.setLayoutParams(params); + } + + // Measure the exact width of the child, and the height based on the width. + // Note: the child takes care of calculating its height. + int childWidthSpec = MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY); + int childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); + child.measure(childWidthSpec, childHeightSpec); + childHeight = child.getMeasuredHeight(); + } + + // Number of rows required to 'mTotal' items. + final int rows = (int) Math.ceil((double) getCount() / getNumColumns()); + final int childrenHeight = childHeight * rows; + final int totalVerticalSpacing = rows > 0 ? (rows - 1) * getVerticalSpacing() : 0; + + // Total height of this view. + final int measuredHeight = childrenHeight + getPaddingTop() + getPaddingBottom() + totalVerticalSpacing; + setMeasuredDimension(measuredWidth, measuredHeight); + } +} -- cgit v1.2.3 From 0be9df3ac3e66c806705c5312910be17007bacb2 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 26 Apr 2014 16:54:03 -0700 Subject: Delete unused res --- res/layout/album_list_item.xml | 58 ------------------------------------------ 1 file changed, 58 deletions(-) delete mode 100644 res/layout/album_list_item.xml (limited to 'res') diff --git a/res/layout/album_list_item.xml b/res/layout/album_list_item.xml deleted file mode 100644 index 99a9ed88..00000000 --- a/res/layout/album_list_item.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - -- cgit v1.2.3