diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-05-26 18:03:47 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-05-26 18:03:47 -0700 |
commit | 117c246d7e619ab9a3c0fb36fb152b8ad8bf9afe (patch) | |
tree | cd3e5f986ce8449b4b0937c5923f61434bbf72f0 | |
parent | 096f97542c1f8b9baa6cc53fb2f6909f969e261f (diff) | |
download | dsub-117c246d7e619ab9a3c0fb36fb152b8ad8bf9afe.tar.gz dsub-117c246d7e619ab9a3c0fb36fb152b8ad8bf9afe.tar.bz2 dsub-117c246d7e619ab9a3c0fb36fb152b8ad8bf9afe.zip |
Abstract out common logic into SectionAdapter
10 files changed, 375 insertions, 170 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java index 80d1ade9..1a4d96a4 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java @@ -16,7 +16,6 @@ package github.daneren2005.dsub.adapter; import android.content.Context; -import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; import android.view.ViewGroup; @@ -24,7 +23,6 @@ import android.view.ViewGroup; import java.util.ArrayList; import java.util.List; -import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.MusicDirectory.Entry; import github.daneren2005.dsub.util.ImageLoader; @@ -33,30 +31,21 @@ import github.daneren2005.dsub.view.SongView; import github.daneren2005.dsub.view.UpdateView; import github.daneren2005.dsub.view.UpdateView.UpdateViewHolder; -public class EntryGridAdapter extends RecyclerView.Adapter<UpdateViewHolder> { +public class EntryGridAdapter extends SectionAdapter<Entry> { private static String TAG = EntryGridAdapter.class.getSimpleName(); - public static int VIEW_TYPE_HEADER = 0; public static int VIEW_TYPE_ALBUM_CELL = 1; public static int VIEW_TYPE_ALBUM_LINE = 2; public static int VIEW_TYPE_SONG = 3; - protected Context context; - protected List<Entry> entries; private ImageLoader imageLoader; private boolean largeAlbums; private boolean showArtist = false; private boolean checkable = true; - private OnEntryClickedListener onEntryClickedListener; - private View header; - private List<Entry> selected = new ArrayList<Entry>(); - private UpdateView contextView; - private Entry contextEntry; public EntryGridAdapter(Context context, List<Entry> entries, ImageLoader imageLoader, boolean largeCell) { - this.context = context; - this.entries = entries; + super(context, entries); this.imageLoader = imageLoader; this.largeAlbums = largeCell; @@ -74,11 +63,7 @@ public class EntryGridAdapter extends RecyclerView.Adapter<UpdateViewHolder> { } @Override - public UpdateViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - if(viewType == VIEW_TYPE_HEADER) { - return new UpdateViewHolder(header, false); - } - + public UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) { UpdateView updateView = null; if(viewType == VIEW_TYPE_ALBUM_LINE || viewType == VIEW_TYPE_ALBUM_CELL) { updateView = new AlbumView(context, viewType == VIEW_TYPE_ALBUM_CELL); @@ -86,66 +71,12 @@ public class EntryGridAdapter extends RecyclerView.Adapter<UpdateViewHolder> { updateView = new SongView(context); } - if(viewType != VIEW_TYPE_HEADER && updateView != null) { - final UpdateView view = updateView; - updateView.getChildAt(0).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Entry entry = getEntryForView(view); - - if (view.isCheckable() && view instanceof SongView) { - SongView songView = (SongView) view; - - if (selected.contains(entry)) { - selected.remove(entry); - songView.setChecked(false); - } else { - selected.add(entry); - songView.setChecked(true); - } - } else if (onEntryClickedListener != null) { - onEntryClickedListener.onEntryClicked(entry); - } - } - }); - updateView.getChildAt(0).setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - Entry entry = getEntryForView(view); - - setContextEntry(view, entry); - v.showContextMenu(); - return false; - } - }); - - View moreButton = updateView.findViewById(R.id.more_button); - if(moreButton != null) { - moreButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Entry entry = getEntryForView(view); - setContextEntry(view, entry); - v.showContextMenu(); - } - }); - } - } - return new UpdateViewHolder(updateView); } @Override - public void onBindViewHolder(UpdateViewHolder holder, int position) { - // Header already created - if(header != null && position == 0) { - return; - } - + public void onBindViewHolder(UpdateViewHolder holder, Entry entry, int viewType) { UpdateView view = holder.getUpdateView(); - - int viewType = getItemViewType(position); - Entry entry = getEntryForPosition(position); if(viewType == VIEW_TYPE_ALBUM_CELL || viewType == VIEW_TYPE_ALBUM_LINE) { AlbumView albumView = (AlbumView) view; albumView.setShowArtist(showArtist); @@ -153,29 +84,25 @@ public class EntryGridAdapter extends RecyclerView.Adapter<UpdateViewHolder> { } else if(viewType == VIEW_TYPE_SONG) { SongView songView = (SongView) view; songView.setObject(entry, checkable); - songView.setChecked(selected.contains(entry)); } - view.setPosition(position); } @Override - public int getItemCount() { - int size = entries.size(); - - if(header != null) { - size++; + public void setChecked(UpdateView updateView, boolean checked) { + if(updateView instanceof SongView) { + ((SongView) updateView).setChecked(checked); } + } - return size; + public UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) { + return new UpdateViewHolder(header, false); } + public void onBindHeaderHolder(UpdateViewHolder holder, String header) { - @Override - public int getItemViewType(int position) { - if(header != null && position == 0) { - return VIEW_TYPE_HEADER; - } + } - Entry entry = getEntryForPosition(position); + @Override + public int getItemViewType(Entry entry) { if(entry.isDirectory()) { if (largeAlbums) { return VIEW_TYPE_ALBUM_CELL; @@ -187,20 +114,9 @@ public class EntryGridAdapter extends RecyclerView.Adapter<UpdateViewHolder> { } } - public Entry getEntryForView(UpdateView view) { - int position = view.getPosition(); - return getEntryForPosition(position); - } - public Entry getEntryForPosition(int position) { - if(header != null) { - position--; - } - - return entries.get(position); - } - public void setHeader(View header) { this.header = header; + this.singleSectionHeader = true; } public void setShowArtist(boolean showArtist) { @@ -210,46 +126,8 @@ public class EntryGridAdapter extends RecyclerView.Adapter<UpdateViewHolder> { this.checkable = checkable; } - public void setOnEntryClickedListener(OnEntryClickedListener listener) { - this.onEntryClickedListener = listener; - } - - public List<Entry> getSelected() { - List<Entry> selected = new ArrayList<>(); - selected.addAll(this.selected); - return selected; - } - public void clearSelected() { - for(Entry entry: selected) { - int index = entries.indexOf(entry); - this.notifyItemChanged(index); - } - selected.clear(); - } - - public void removeEntry(Entry entry) { - int index = entries.indexOf(entry); - if(index != -1) { - removeAt(index); - } - } public void removeAt(int index) { - entries.remove(index); + sections.get(0).remove(index); notifyItemRemoved(index); } - - public void setContextEntry(UpdateView view, Entry entry) { - this.contextView = view; - this.contextEntry = entry; - } - public UpdateView getContextView() { - return contextView; - } - public Entry getContextEntry() { - return contextEntry; - } - - public interface OnEntryClickedListener { - void onEntryClicked(Entry entry); - } } diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/EntryInfiniteGridAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/EntryInfiniteGridAdapter.java index 288c38a6..7b7dc6fc 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/EntryInfiniteGridAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/EntryInfiniteGridAdapter.java @@ -121,7 +121,7 @@ public class EntryInfiniteGridAdapter extends EntryGridAdapter { protected List<Entry> cacheInBackground() throws Exception { MusicService service = MusicServiceFactory.getMusicService(context); MusicDirectory result; - int offset = entries.size(); + int offset = sections.get(0).size(); if(("genres".equals(type) && ServerInfo.checkServerVersion(context, "1.10.0")) || "years".equals(type)) { result = service.getAlbumList(type, extra, size, offset, context, null); } else if("genres".equals(type) || "genres-songs".equals(type)) { @@ -134,13 +134,13 @@ public class EntryInfiniteGridAdapter extends EntryGridAdapter { protected void appendCachedData(List<Entry> newData) { if(newData.size() > 0) { - int start = entries.size(); - entries.addAll(newData); + int start = sections.get(0).size(); + sections.get(0).addAll(newData); this.notifyItemRangeInserted(start, newData.size()); } } protected boolean isLoadingView(int position) { - return !allLoaded && position >= entries.size(); + return !allLoaded && position >= sections.get(0).size(); } } diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java new file mode 100644 index 00000000..5244c7a6 --- /dev/null +++ b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java @@ -0,0 +1,280 @@ +/* + 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 <http://www.gnu.org/licenses/>. + Copyright 2015 (C) Scott Jackson +*/ + +package github.daneren2005.dsub.adapter; + +import android.content.Context; +import android.support.v7.widget.RecyclerView; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.view.BasicHeaderView; +import github.daneren2005.dsub.view.UpdateView; +import github.daneren2005.dsub.view.UpdateView.UpdateViewHolder; + +public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewHolder<T>> { + private static String TAG = SectionAdapter.class.getSimpleName(); + public static int VIEW_TYPE_HEADER = 0; + + protected Context context; + protected List<String> headers; + protected List<List<T>> sections; + protected boolean singleSectionHeader; + protected OnItemClickedListener<T> onItemClickedListener; + protected UpdateView contextView; + protected T contextItem; + private List<T> selected = new ArrayList<>(); + + public SectionAdapter(Context context, List<T> section) { + this(context, section, false); + } + public SectionAdapter(Context context, List<T> section, boolean singleSectionHeader) { + this.context = context; + this.headers = Arrays.asList("Section"); + this.sections = new ArrayList<>(); + this.sections.add(section); + this.singleSectionHeader = singleSectionHeader; + } + public SectionAdapter(Context context, List<String> headers, List<List<T>> sections) { + this(context, headers, sections, true); + } + public SectionAdapter(Context context, List<String> headers, List<List<T>> sections, boolean singleSectionHeader){ + this.context = context; + this.headers = headers; + this.sections = sections; + this.singleSectionHeader = singleSectionHeader; + } + + @Override + public UpdateViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + if(viewType == VIEW_TYPE_HEADER) { + return onCreateHeaderHolder(parent); + } else { + final UpdateViewHolder<T> holder = onCreateSectionViewHolder(parent, viewType); + final UpdateView updateView = holder.getUpdateView(); + + if(updateView != null) { + updateView.getChildAt(0).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + T item = holder.getItem(); + if(updateView.isCheckable()) { + if (selected.contains(item)) { + selected.remove(item); + setChecked(updateView, false); + } else { + selected.add(item); + setChecked(updateView, true); + } + } else if(onItemClickedListener != null) { + onItemClickedListener.onItemClicked(item); + } + } + }); + updateView.getChildAt(0).setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + T item = holder.getItem(); + setContextItem(updateView, item); + v.showContextMenu(); + return false; + } + }); + + View moreButton = updateView.findViewById(R.id.more_button); + if(moreButton == null) { + moreButton = updateView.findViewById(R.id.item_more); + } + if (moreButton != null) { + moreButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + T item = holder.getItem(); + setContextItem(updateView, item); + v.showContextMenu(); + } + }); + } + } + + return holder; + } + } + + @Override + public void onBindViewHolder(UpdateViewHolder holder, int position) { + UpdateView updateView = holder.getUpdateView(); + + if(sections.size() == 1 && !singleSectionHeader) { + T item = sections.get(0).get(position); + onBindViewHolder(holder, item, getItemViewType(position)); + if(updateView.isCheckable()) { + setChecked(updateView, selected.contains(item)); + } + holder.setItem(item); + return; + } + + int subPosition = 0; + for(List<T> section: sections) { + if(position == subPosition) { + int index = sections.indexOf(section); + onBindHeaderHolder(holder, headers.get(index)); + return; + } + + if(position <= (subPosition + section.size())) { + T item = section.get(position - subPosition - 1); + onBindViewHolder(holder, item, getItemViewType(item)); + + if(updateView.isCheckable()) { + setChecked(updateView, selected.contains(item)); + } + holder.setItem(item); + return; + } + + subPosition += section.size() + 1; + } + } + + @Override + public int getItemCount() { + if(sections.size() == 1 && !singleSectionHeader) { + return sections.get(0).size(); + } + + int count = headers.size(); + for(List<T> section: sections) { + count += section.size(); + } + + return count; + } + + @Override + public int getItemViewType(int position) { + if(sections.size() == 1 && !singleSectionHeader) { + return getItemViewType(sections.get(0).get(position)); + } + + int subPosition = 0; + for(List<T> section: sections) { + if(position == subPosition) { + return VIEW_TYPE_HEADER; + } + + if(position <= (subPosition + section.size())) { + return getItemViewType(section.get(position - subPosition - 1)); + } + + subPosition += section.size() + 1; + } + + return -1; + } + + public UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) { + return new UpdateViewHolder(new BasicHeaderView(context)); + } + public void onBindHeaderHolder(UpdateViewHolder holder, String header) { + UpdateView view = holder.getUpdateView(); + view.setObject(header); + } + + public T getItemForPosition(int position) { + if(sections.size() == 1 && !singleSectionHeader) { + return sections.get(0).get(position); + } + + int subPosition = 0; + for(List<T> section: sections) { + if(position == subPosition) { + return null; + } + + if(position <= (subPosition + section.size())) { + return section.get(position - subPosition - 1); + } + + subPosition += section.size() + 1; + } + + return null; + } + + public void setContextItem(UpdateView updateView, T item) { + contextView = updateView; + contextItem = item; + } + public UpdateView getContextView() { + return contextView; + } + public T getContextItem() { + return contextItem; + } + + public void setOnItemClickedListener(OnItemClickedListener<T> onItemClickedListener) { + this.onItemClickedListener = onItemClickedListener; + } + + public List<T> getSelected() { + List<T> selected = new ArrayList<>(); + selected.addAll(this.selected); + return selected; + } + + public void clearSelected() { + // TODO: This needs to work with multiple sections + for(T item: selected) { + int index = sections.get(0).indexOf(item); + this.notifyItemChanged(index); + } + selected.clear(); + } + + public void removeItem(T item) { + int subPosition = 0; + for(List<T> section: sections) { + if(sections.size() > 1 || singleSectionHeader) { + subPosition++; + } + + int index = section.indexOf(item); + if (index != -1) { + section.remove(item); + notifyItemRemoved(subPosition + index); + break; + } + + subPosition += section.size(); + } + } + + public abstract UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType); + public abstract void onBindViewHolder(UpdateViewHolder holder, T item, int viewType); + public abstract int getItemViewType(T item); + public void setChecked(UpdateView updateView, boolean checked) {} + + public interface OnItemClickedListener<T> { + void onItemClicked(T item); + } +} diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index d427a26d..f21967b9 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -34,6 +34,7 @@ import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.adapter.EntryInfiniteGridAdapter; import github.daneren2005.dsub.adapter.EntryGridAdapter; +import github.daneren2005.dsub.adapter.SectionAdapter; import github.daneren2005.dsub.domain.ArtistInfo; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.ServerInfo; @@ -68,7 +69,7 @@ import java.util.Set; import static github.daneren2005.dsub.domain.MusicDirectory.Entry; -public class SelectDirectoryFragment extends SubsonicFragment implements EntryGridAdapter.OnEntryClickedListener { +public class SelectDirectoryFragment extends SubsonicFragment implements SectionAdapter.OnItemClickedListener<Entry> { private static final String TAG = SelectDirectoryFragment.class.getSimpleName(); private RecyclerView recyclerView; @@ -341,7 +342,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements EntryGr @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); - Entry entry = entryGridAdapter.getContextEntry(); + Entry entry = entryGridAdapter.getContextItem(); UpdateView targetView = entryGridAdapter.getContextView(); menuInfo = new AdapterView.AdapterContextMenuInfo(targetView, 0, 0); @@ -378,7 +379,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements EntryGr if(menuItem.getGroupId() != getSupportTag()) { return false; } - Entry entry = entryGridAdapter.getContextEntry(); + Entry entry = entryGridAdapter.getContextItem(); if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_PLAY_NOW_AFTER, false) && menuItem.getItemId() == R.id.song_menu_play_now) { List<Entry> songs = new ArrayList<Entry>(); @@ -412,7 +413,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements EntryGr } @Override - public void onEntryClicked(Entry entry) { + public void onItemClicked(Entry entry) { if (entry.isDirectory()) { SubsonicFragment fragment = new SelectDirectoryFragment(); Bundle args = new Bundle(); @@ -750,7 +751,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements EntryGr } }); } - entryGridAdapter.setOnEntryClickedListener(this); + entryGridAdapter.setOnItemClickedListener(this); // Always show artist if this is not a artist we are viewing if(!artist) { entryGridAdapter.setShowArtist(true); @@ -1054,7 +1055,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements EntryGr @Override protected void done(Void result) { - entryGridAdapter.removeEntry(episode); + entryGridAdapter.removeItem(episode); } @Override @@ -1115,7 +1116,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements EntryGr Util.toast(context, context.getResources().getString(R.string.starring_content_unstarred, Integer.toString(unstar.size()))); for(Entry entry: unstar) { - entryGridAdapter.removeEntry(entry); + entryGridAdapter.removeItem(entry); } } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java index c19e9b28..cb2ae6d7 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java @@ -26,32 +26,29 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.ListView; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import github.daneren2005.dsub.R; +import github.daneren2005.dsub.adapter.SectionAdapter; 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.GridSpacingDecoration; public abstract class SelectRecyclerFragment<T> extends SubsonicFragment { private static final String TAG = SelectRecyclerFragment.class.getSimpleName(); protected RecyclerView recyclerView; - protected RecyclerView.Adapter adapter; + protected SectionAdapter<T> adapter; protected BackgroundTask<List<T>> currentTask; protected List<T> objects; protected boolean serialize = true; - protected boolean largeCells; + protected boolean largeCells = false; protected int columns; @Override @@ -61,7 +58,6 @@ public abstract class SelectRecyclerFragment<T> extends SubsonicFragment { if(bundle != null && serialize) { objects = (List<T>) bundle.getSerializable(Constants.FRAGMENT_LIST); } - largeCells = Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_LARGE_ALBUM_ART, true); columns = context.getResources().getInteger(R.integer.Grid_Columns); } @@ -89,6 +85,7 @@ public abstract class SelectRecyclerFragment<T> extends SubsonicFragment { } else { recyclerView.setAdapter(adapter = getAdapter(objects)); } + registerForContextMenu(recyclerView); return rootView; } @@ -190,7 +187,7 @@ public abstract class SelectRecyclerFragment<T> extends SubsonicFragment { } public abstract int getOptionsMenu(); - public abstract RecyclerView.Adapter getAdapter(List<T> objs); + public abstract SectionAdapter<T> getAdapter(List<T> objs); public abstract List<T> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception; public abstract int getTitleResource(); diff --git a/app/src/main/java/github/daneren2005/dsub/view/BasicHeaderView.java b/app/src/main/java/github/daneren2005/dsub/view/BasicHeaderView.java new file mode 100644 index 00000000..d8111692 --- /dev/null +++ b/app/src/main/java/github/daneren2005/dsub/view/BasicHeaderView.java @@ -0,0 +1,37 @@ +/* + 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 <http://www.gnu.org/licenses/>. + Copyright 2015 (C) Scott Jackson +*/ + +package github.daneren2005.dsub.view; + +import android.content.Context; +import android.view.LayoutInflater; +import android.widget.TextView; + +import github.daneren2005.dsub.R; + +public class BasicHeaderView extends UpdateView { + TextView nameView; + + public BasicHeaderView(Context context) { + super(context, false); + + LayoutInflater.from(context).inflate(R.layout.basic_header, this, true); + nameView = (TextView) findViewById(R.id.item_name); + } + + protected void setObjectImpl(Object obj) { + nameView.setText((String) obj); + } +} diff --git a/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java b/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java index bdcdc46f..905fbb06 100644 --- a/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java +++ b/app/src/main/java/github/daneren2005/dsub/view/UpdateView.java @@ -66,7 +66,6 @@ public class UpdateView extends LinearLayout { protected SilentBackgroundTask<Void> imageTask = null; protected final boolean autoUpdate; - protected int position; protected boolean checkable; public UpdateView(Context context) { @@ -78,8 +77,8 @@ public class UpdateView extends LinearLayout { this.autoUpdate = autoUpdate; setLayoutParams(new AbsListView.LayoutParams( - ViewGroup.LayoutParams.FILL_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT)); + ViewGroup.LayoutParams.FILL_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT)); if(autoUpdate) { INSTANCES.put(this, null); @@ -285,19 +284,13 @@ public class UpdateView extends LinearLayout { } } - public void setPosition(int position) { - this.position = position; - } - public int getPosition() { - return position; - } - public boolean isCheckable() { return checkable; } - public static class UpdateViewHolder extends RecyclerView.ViewHolder { + public static class UpdateViewHolder<T> extends RecyclerView.ViewHolder { private UpdateView updateView; + private T item; public UpdateViewHolder(UpdateView itemView) { super(itemView); @@ -313,5 +306,11 @@ public class UpdateView extends LinearLayout { public UpdateView getUpdateView() { return updateView; } + public void setItem(T item) { + this.item = item; + } + public T getItem() { + return item; + } } } diff --git a/app/src/main/res/layout/basic_header.xml b/app/src/main/res/layout/basic_header.xml new file mode 100644 index 00000000..39f8722d --- /dev/null +++ b/app/src/main/res/layout/basic_header.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<TextView xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/item_name" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:textAppearance="?android:attr/textAppearanceMedium" + android:background="@android:color/transparent" + android:textColor="@color/cyan" + android:textStyle="bold" + android:paddingLeft="6dp" + android:paddingRight="6dp"/>
\ No newline at end of file diff --git a/app/src/main/res/layout/basic_list_item.xml b/app/src/main/res/layout/basic_list_item.xml index 2338f7e0..4974f4f5 100644 --- a/app/src/main/res/layout/basic_list_item.xml +++ b/app/src/main/res/layout/basic_list_item.xml @@ -3,7 +3,7 @@ android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:background="@android:color/transparent"> + android:background="@drawable/abc_item_background_holo_light"> <TextView android:id="@+id/item_name" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e6e19b4c..bb0a997b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -236,7 +236,9 @@ <string name="starring_content_starred">Starred \"%s\"</string> <string name="starring_content_unstarred">Unstarred \"%s\"</string> <string name="starring_content_error">Failed to update \"%s\", please try later.</string> - + + <string name="playlist.mine">My Playlists</string> + <string name="playlist.shared">Shared Playlists</string> <string name="playlist_error">Failed to grab list of playlists</string> <string name="updated_playlist">Added %1$s songs to \"%2$s\"</string> <string name="updated_playlist_error">Failed to update \"%s\", please try later.</string> |