From 454b59dea73407db84076da130f260d58386768e Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 7 Apr 2015 08:38:36 -0700 Subject: Move adapters to dedicated dir --- .../dsub/activity/SubsonicActivity.java | 4 +- .../daneren2005/dsub/adapter/AlbumGridAdapter.java | 73 ++++++ .../daneren2005/dsub/adapter/AlbumListAdapter.java | 84 ++++++ .../daneren2005/dsub/adapter/ArtistAdapter.java | 97 +++++++ .../daneren2005/dsub/adapter/BookmarkAdapter.java | 64 +++++ .../daneren2005/dsub/adapter/ChatAdapter.java | 109 ++++++++ .../dsub/adapter/DownloadFileAdapter.java | 49 ++++ .../daneren2005/dsub/adapter/DrawerAdapter.java | 126 +++++++++ .../daneren2005/dsub/adapter/EntryAdapter.java | 82 ++++++ .../daneren2005/dsub/adapter/GenreAdapter.java | 60 +++++ .../daneren2005/dsub/adapter/MergeAdapter.java | 290 ++++++++++++++++++++ .../daneren2005/dsub/adapter/PlaylistAdapter.java | 70 +++++ .../dsub/adapter/PodcastChannelAdapter.java | 60 +++++ .../dsub/adapter/SackOfViewsAdapter.java | 181 +++++++++++++ .../daneren2005/dsub/adapter/SettingsAdapter.java | 59 +++++ .../daneren2005/dsub/adapter/ShareAdapter.java | 56 ++++ .../daneren2005/dsub/adapter/UserAdapter.java | 52 ++++ .../daneren2005/dsub/fragments/AdminFragment.java | 10 +- .../daneren2005/dsub/fragments/ChatFragment.java | 5 +- .../dsub/fragments/DownloadFragment.java | 5 +- .../daneren2005/dsub/fragments/MainFragment.java | 2 +- .../dsub/fragments/NowPlayingFragment.java | 3 +- .../daneren2005/dsub/fragments/SearchFragment.java | 7 +- .../dsub/fragments/SelectArtistFragment.java | 4 +- .../dsub/fragments/SelectBookmarkFragment.java | 12 +- .../dsub/fragments/SelectDirectoryFragment.java | 11 +- .../dsub/fragments/SelectGenreFragment.java | 2 +- .../dsub/fragments/SelectListFragment.java | 5 - .../dsub/fragments/SelectPlaylistFragment.java | 2 +- .../dsub/fragments/SelectPodcastsFragment.java | 2 +- .../dsub/fragments/SelectShareFragment.java | 2 +- .../dsub/fragments/SelectVideoFragment.java | 2 +- .../dsub/fragments/SimilarArtistFragment.java | 7 +- .../daneren2005/dsub/fragments/UserFragment.java | 10 +- .../dsub/service/parser/PlaylistsParser.java | 4 +- src/github/daneren2005/dsub/util/UserUtil.java | 6 +- .../daneren2005/dsub/view/AlbumGridAdapter.java | 72 ----- .../daneren2005/dsub/view/AlbumListAdapter.java | 84 ------ .../daneren2005/dsub/view/ArtistAdapter.java | 95 ------- .../daneren2005/dsub/view/BookmarkAdapter.java | 63 ----- src/github/daneren2005/dsub/view/ChatAdapter.java | 109 -------- .../daneren2005/dsub/view/DownloadFileAdapter.java | 48 ---- .../daneren2005/dsub/view/DrawerAdapter.java | 128 --------- src/github/daneren2005/dsub/view/EntryAdapter.java | 79 ------ src/github/daneren2005/dsub/view/GenreAdapter.java | 59 ----- src/github/daneren2005/dsub/view/MergeAdapter.java | 292 --------------------- .../daneren2005/dsub/view/PlaylistAdapter.java | 68 ----- .../dsub/view/PodcastChannelAdapter.java | 59 ----- .../daneren2005/dsub/view/SackOfViewsAdapter.java | 181 ------------- .../daneren2005/dsub/view/SettingsAdapter.java | 58 ---- src/github/daneren2005/dsub/view/ShareAdapter.java | 55 ---- src/github/daneren2005/dsub/view/UserAdapter.java | 51 ---- 52 files changed, 1536 insertions(+), 1582 deletions(-) create mode 100644 src/github/daneren2005/dsub/adapter/AlbumGridAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/AlbumListAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/ArtistAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/BookmarkAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/ChatAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/DownloadFileAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/DrawerAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/EntryAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/GenreAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/MergeAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/PlaylistAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/SackOfViewsAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/SettingsAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/ShareAdapter.java create mode 100644 src/github/daneren2005/dsub/adapter/UserAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/AlbumGridAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/AlbumListAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/ArtistAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/BookmarkAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/ChatAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/DownloadFileAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/DrawerAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/EntryAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/GenreAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/MergeAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/PlaylistAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/PodcastChannelAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/SackOfViewsAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/SettingsAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/ShareAdapter.java delete mode 100644 src/github/daneren2005/dsub/view/UserAdapter.java diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index f28d023a..97b86e19 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -26,7 +26,6 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.TypedArray; -import android.graphics.Color; import android.media.AudioManager; import android.os.Build; import android.os.Bundle; @@ -61,7 +60,6 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Locale; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.ServerInfo; @@ -71,7 +69,7 @@ import github.daneren2005.dsub.service.HeadphoneListenerService; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.ImageLoader; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.DrawerAdapter; +import github.daneren2005.dsub.adapter.DrawerAdapter; import github.daneren2005.dsub.view.UpdateView; import github.daneren2005.dsub.util.UserUtil; diff --git a/src/github/daneren2005/dsub/adapter/AlbumGridAdapter.java b/src/github/daneren2005/dsub/adapter/AlbumGridAdapter.java new file mode 100644 index 00000000..eb187569 --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/AlbumGridAdapter.java @@ -0,0 +1,73 @@ +/* + 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.adapter; + +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; +import github.daneren2005.dsub.view.AlbumCell; + +public class AlbumGridAdapter extends ArrayAdapter { + private final static String TAG = AlbumGridAdapter.class.getSimpleName(); + private final Context activity; + private final ImageLoader imageLoader; + private List entries; + private boolean showArtist; + + public AlbumGridAdapter(Context activity, ImageLoader imageLoader, List entries, boolean showArtist) { + super(activity, android.R.layout.simple_list_item_1, entries); + this.entries = entries; + this.activity = activity; + this.imageLoader = imageLoader; + + // Always show artist if they aren't all the same + if(!showArtist) { + String artist = null; + for(MusicDirectory.Entry entry: entries) { + if(artist == null) { + artist = entry.getArtist(); + } + + if(artist != null && !artist.equals(entry.getArtist())) { + showArtist = true; + } + } + } + this.showArtist = showArtist; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + MusicDirectory.Entry entry = getItem(position); + + AlbumCell view; + if(convertView instanceof AlbumCell) { + view = (AlbumCell) convertView; + } else { + view = new AlbumCell(activity); + } + + view.setShowArtist(showArtist); + view.setObject(entry, imageLoader); + return view; + } +} diff --git a/src/github/daneren2005/dsub/adapter/AlbumListAdapter.java b/src/github/daneren2005/dsub/adapter/AlbumListAdapter.java new file mode 100644 index 00000000..2e91d949 --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/AlbumListAdapter.java @@ -0,0 +1,84 @@ +/* + 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 2010 (C) Sindre Mehus + */ +package github.daneren2005.dsub.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import com.commonsware.cwac.endless.EndlessAdapter; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.domain.ServerInfo; +import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.service.MusicServiceFactory; +import github.daneren2005.dsub.util.Util; + +import java.util.List; + +public class AlbumListAdapter extends EndlessAdapter { + Context context; + ArrayAdapter adapter; + String type; + String extra; + int size; + int offset; + List entries; + + public AlbumListAdapter(Context context, ArrayAdapter adapter, String type, String extra, int size) { + super(adapter); + this.context = context; + this.adapter = adapter; + this.type = type; + this.extra = extra; + this.size = size; + this.offset = size; + } + + @Override + protected boolean cacheInBackground() throws Exception { + MusicService service = MusicServiceFactory.getMusicService(context); + MusicDirectory result; + 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)) { + result = service.getSongsByGenre(extra, size, offset, context, null); + } else { + result = service.getAlbumList(type, size, offset, context, null); + } + entries = result.getChildren(); + return entries.size() > 0; + } + + @Override + protected void appendCachedData() { + for(MusicDirectory.Entry entry: entries) { + adapter.add(entry); + } + offset += entries.size(); + } + + @Override + protected View getPendingView(ViewGroup parent) { + View progress = LayoutInflater.from(context).inflate(R.layout.tab_progress, null); + progress.setVisibility(View.VISIBLE); + return progress; + } +} diff --git a/src/github/daneren2005/dsub/adapter/ArtistAdapter.java b/src/github/daneren2005/dsub/adapter/ArtistAdapter.java new file mode 100644 index 00000000..4d469faf --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/ArtistAdapter.java @@ -0,0 +1,97 @@ +/* + 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 2010 (C) Sindre Mehus + */ +package github.daneren2005.dsub.adapter; + +import android.content.Context; +import github.daneren2005.dsub.R; +import java.util.List; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.SectionIndexer; +import github.daneren2005.dsub.domain.Artist; +import github.daneren2005.dsub.view.ArtistView; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * @author Sindre Mehus + */ +public class ArtistAdapter extends ArrayAdapter implements SectionIndexer { + + private final Context activity; + + // Both arrays are indexed by section ID. + private final Object[] sections; + private final Integer[] positions; + + public ArtistAdapter(Context activity, List artists) { + super(activity, R.layout.basic_list_item, artists); + this.activity = activity; + + Set sectionSet = new LinkedHashSet(30); + List positionList = new ArrayList(30); + for (int i = 0; i < artists.size(); i++) { + Artist artist = artists.get(i); + String index = artist.getIndex(); + if (!sectionSet.contains(index)) { + sectionSet.add(index); + positionList.add(i); + } + } + sections = sectionSet.toArray(new Object[sectionSet.size()]); + positions = positionList.toArray(new Integer[positionList.size()]); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Artist entry = getItem(position); + ArtistView view; + if (convertView != null && convertView instanceof ArtistView) { + view = (ArtistView) convertView; + } else { + view = new ArtistView(activity); + } + view.setObject(entry); + return view; + } + + @Override + public Object[] getSections() { + return sections; + } + + @Override + public int getPositionForSection(int section) { + section = Math.min(section, positions.length - 1); + return positions[section]; + } + + @Override + public int getSectionForPosition(int pos) { + for (int i = 0; i < sections.length - 1; i++) { + if (pos < positions[i + 1]) { + return i; + } + } + return sections.length - 1; + } +} diff --git a/src/github/daneren2005/dsub/adapter/BookmarkAdapter.java b/src/github/daneren2005/dsub/adapter/BookmarkAdapter.java new file mode 100644 index 00000000..26d3e16a --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/BookmarkAdapter.java @@ -0,0 +1,64 @@ +/* + 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 2010 (C) Sindre Mehus +*/ + +package github.daneren2005.dsub.adapter; + +import android.content.Context; + +import java.util.List; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.Bookmark; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.util.Util; +import github.daneren2005.dsub.view.SongView; + +public class BookmarkAdapter extends ArrayAdapter { + private final static String TAG = BookmarkAdapter.class.getSimpleName(); + private Context activity; + + public BookmarkAdapter(Context activity, List bookmarks) { + super(activity, android.R.layout.simple_list_item_1, bookmarks); + this.activity = activity; + } + + public View getView(int position, View convertView, ViewGroup parent) { + MusicDirectory.Entry entry = getItem(position); + Bookmark bookmark = entry.getBookmark(); + + SongView view; + if (convertView != null) { + view = (SongView) convertView; + } else { + view = new SongView(activity); + } + view.setObject(entry, false); + + // Add current position to duration + TextView durationTextView = (TextView) view.findViewById(R.id.song_duration); + String duration = durationTextView.getText().toString(); + durationTextView.setText(Util.formatDuration(bookmark.getPosition() / 1000) + " / " + duration); + + return view; + } +} diff --git a/src/github/daneren2005/dsub/adapter/ChatAdapter.java b/src/github/daneren2005/dsub/adapter/ChatAdapter.java new file mode 100644 index 00000000..0c116d39 --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/ChatAdapter.java @@ -0,0 +1,109 @@ +package github.daneren2005.dsub.adapter; + +import android.text.method.LinkMovementMethod; +import android.text.util.Linkify; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.activity.SubsonicActivity; +import github.daneren2005.dsub.domain.ChatMessage; +import github.daneren2005.dsub.util.ImageLoader; +import github.daneren2005.dsub.util.UserUtil; +import github.daneren2005.dsub.util.Util; + +import java.text.DateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.regex.Pattern; + +public class ChatAdapter extends ArrayAdapter { + + private final SubsonicActivity activity; + private ArrayList messages; + private final ImageLoader imageLoader; + + private static final String phoneRegex = "1?\\W*([2-9][0-8][0-9])\\W*([2-9][0-9]{2})\\W*([0-9]{4})"; //you can just place your support phone here + private static final Pattern phoneMatcher = Pattern.compile(phoneRegex); + + public ChatAdapter(SubsonicActivity activity, ArrayList messages, ImageLoader imageLoader) { + super(activity, R.layout.chat_item, messages); + this.activity = activity; + this.messages = messages; + this.imageLoader = imageLoader; + } + + @Override + public int getCount() { + return messages.size(); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ChatMessage message = this.getItem(position); + + ViewHolder holder; + int layout; + + String messageUser = message.getUsername(); + Date messageTime = new java.util.Date(message.getTime()); + String messageText = message.getMessage(); + + String me = UserUtil.getCurrentUsername(activity); + + if (messageUser.equals(me)) { + layout = R.layout.chat_item_reverse; + } else { + layout = R.layout.chat_item; + } + + if (convertView == null) + { + holder = new ViewHolder(); + + convertView = LayoutInflater.from(activity).inflate(layout, parent, false); + + TextView usernameView = (TextView) convertView.findViewById(R.id.chat_username); + TextView timeView = (TextView) convertView.findViewById(R.id.chat_time); + TextView messageView = (TextView) convertView.findViewById(R.id.chat_message); + + messageView.setMovementMethod(LinkMovementMethod.getInstance()); + Linkify.addLinks(messageView, Linkify.EMAIL_ADDRESSES); + Linkify.addLinks(messageView, Linkify.WEB_URLS); + Linkify.addLinks(messageView, phoneMatcher, "tel:"); + + holder.message = messageView; + holder.username = usernameView; + holder.time = timeView; + holder.avatar = (ImageView) convertView.findViewById(R.id.chat_avatar); + + convertView.setTag(holder); + } + else + { + holder = (ViewHolder) convertView.getTag(); + } + + DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); + String messageTimeFormatted = String.format("[%s]", timeFormat.format(messageTime)); + + holder.username.setText(messageUser); + holder.message.setText(messageText); + holder.time.setText(messageTimeFormatted); + + imageLoader.loadAvatar(activity, holder.avatar, messageUser); + + return convertView; + } + + private static class ViewHolder + { + TextView message; + TextView username; + TextView time; + ImageView avatar; + } +} diff --git a/src/github/daneren2005/dsub/adapter/DownloadFileAdapter.java b/src/github/daneren2005/dsub/adapter/DownloadFileAdapter.java new file mode 100644 index 00000000..be9b4cb9 --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/DownloadFileAdapter.java @@ -0,0 +1,49 @@ +/* + 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.adapter; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; + +import java.util.List; + +import github.daneren2005.dsub.service.DownloadFile; +import github.daneren2005.dsub.view.SongView; + +public class DownloadFileAdapter extends ArrayAdapter { + Context context; + + public DownloadFileAdapter(Context context, List entries) { + super(context, android.R.layout.simple_list_item_1, entries); + this.context = context; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + SongView view; + if (convertView != null && convertView instanceof SongView) { + view = (SongView) convertView; + } else { + view = new SongView(context); + } + DownloadFile downloadFile = getItem(position); + view.setObject(downloadFile.getSong(), false); + view.setDownloadFile(downloadFile); + return view; + } +} diff --git a/src/github/daneren2005/dsub/adapter/DrawerAdapter.java b/src/github/daneren2005/dsub/adapter/DrawerAdapter.java new file mode 100644 index 00000000..b0a4a33d --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/DrawerAdapter.java @@ -0,0 +1,126 @@ +/* + 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.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import java.util.List; + +import github.daneren2005.dsub.R; + +/** + * Created by Scott on 11/8/13. + */ +public class DrawerAdapter extends ArrayAdapter { + private static String TAG = DrawerAdapter.class.getSimpleName(); + private Context context; + private List items; + private List icons; + private List visible; + private int selectedPosition = -1; + + public DrawerAdapter(Context context, List items, List icons, List visible) { + super(context, R.layout.drawer_list_item, items); + + this.context = context; + this.items = items; + this.icons = icons; + this.visible = visible; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + position = getActualPosition(position); + String item = items.get(position); + Integer icon = icons.get(position); + + if(convertView == null) { + convertView = LayoutInflater.from(context).inflate(R.layout.drawer_list_item, null); + } + + TextView textView = (TextView) convertView.findViewById(R.id.drawer_name); + textView.setText(item); + + if(selectedPosition == position) { + textView.setTextAppearance(context, R.style.DSub_TextViewStyle_Bold); + selectedPosition = -1; + } + + ImageView iconView = (ImageView) convertView.findViewById(R.id.drawer_icon); + iconView.setImageResource(icon); + + return convertView; + } + + @Override + public int getCount() { + int count = 0; + for(int i = 0; i < visible.size(); i++) { + if(visible.get(i)) { + count++; + } + } + + return count; + } + + public int getActualPosition(int position) { + for(int i = 0; i <= position; i++) { + if(!visible.get(i)) { + position++; + } + } + + return position; + } + public int getAdapterPosition(int position) { + if(!visible.get(position)) { + visible.set(position, true); + notifyDataSetChanged(); + } + + for(int i = position; i >= 0; i--) { + if(!visible.get(i)) { + position--; + } + } + + return position; + } + + public void setItemVisible(int position, boolean visible) { + if(this.visible.get(position) != visible) { + this.visible.set(position, visible); + notifyDataSetInvalidated(); + } + } + public void setDownloadVisible(boolean visible) { + setItemVisible(items.size() - 2, visible); + } + + public void setSelectedPosition(int position) { + selectedPosition = position; + } +} diff --git a/src/github/daneren2005/dsub/adapter/EntryAdapter.java b/src/github/daneren2005/dsub/adapter/EntryAdapter.java new file mode 100644 index 00000000..9e506e5a --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/EntryAdapter.java @@ -0,0 +1,82 @@ +/* + 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 2010 (C) Sindre Mehus + */ +package github.daneren2005.dsub.adapter; + +import android.content.Context; + +import java.util.List; + +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.util.ImageLoader; +import github.daneren2005.dsub.view.AlbumView; +import github.daneren2005.dsub.view.ArtistEntryView; +import github.daneren2005.dsub.view.SongView; + +/** + * @author Sindre Mehus + */ +public class EntryAdapter extends ArrayAdapter { + private final static String TAG = EntryAdapter.class.getSimpleName(); + private final Context activity; + private final ImageLoader imageLoader; + private final boolean checkable; + private List entries; + + public EntryAdapter(Context activity, ImageLoader imageLoader, List entries, boolean checkable) { + super(activity, android.R.layout.simple_list_item_1, entries); + this.entries = entries; + this.activity = activity; + this.imageLoader = imageLoader; + this.checkable = checkable; + } + + public void removeAt(int position) { + entries.remove(position); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + MusicDirectory.Entry entry = getItem(position); + + if (entry.isDirectory()) { + if(entry.isAlbum()) { + 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; + } + } +} diff --git a/src/github/daneren2005/dsub/adapter/GenreAdapter.java b/src/github/daneren2005/dsub/adapter/GenreAdapter.java new file mode 100644 index 00000000..abb208c9 --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/GenreAdapter.java @@ -0,0 +1,60 @@ +/* + 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 2010 (C) Sindre Mehus + */ +package github.daneren2005.dsub.adapter; + +import android.widget.ArrayAdapter; +import android.widget.SectionIndexer; +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.Genre; +import github.daneren2005.dsub.view.GenreView; + +import java.util.List; +import java.util.Set; +import java.util.LinkedHashSet; +import java.util.ArrayList; + +/** + * @author Sindre Mehus +*/ +public class GenreAdapter extends ArrayAdapter{ + private Context activity; + private List genres; + + public GenreAdapter(Context context, List genres) { + super(context, android.R.layout.simple_list_item_1, genres); + this.activity = context; + this.genres = genres; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Genre genre = genres.get(position); + GenreView view; + if (convertView != null && convertView instanceof GenreView) { + view = (GenreView) convertView; + } else { + view = new GenreView(activity); + } + view.setObject(genre); + return view; + } +} diff --git a/src/github/daneren2005/dsub/adapter/MergeAdapter.java b/src/github/daneren2005/dsub/adapter/MergeAdapter.java new file mode 100644 index 00000000..a2db4cf0 --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/MergeAdapter.java @@ -0,0 +1,290 @@ +/*** + Copyright (c) 2008-2009 CommonsWare, LLC + Portions (c) 2009 Google, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); you may + not use this file except in compliance with the License. You may obtain + a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +package github.daneren2005.dsub.adapter; + +import android.database.DataSetObserver; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ListAdapter; + +import java.util.ArrayList; +import java.util.List; +import java.util.Arrays; + +/** + * Adapter that merges multiple child adapters and views + * into a single contiguous whole. + *

+ * Adapters used as pieces within MergeAdapter must + * have view type IDs monotonically increasing from 0. Ideally, + * adapters also have distinct ranges for their row ids, as + * returned by getItemId(). + */ +public class MergeAdapter extends BaseAdapter { + + private final CascadeDataSetObserver observer = new CascadeDataSetObserver(); + private final ArrayList pieces = new ArrayList(); + + /** + * Stock constructor, simply chaining to the superclass. + */ + public MergeAdapter() { + super(); + } + + /** + * Adds a new adapter to the roster of things to appear + * in the aggregate list. + * + * @param adapter Source for row views for this section + */ + public void addAdapter(ListAdapter adapter) { + pieces.add(adapter); + adapter.registerDataSetObserver(observer); + } + + public void removeAdapter(ListAdapter adapter) { + adapter.unregisterDataSetObserver(observer); + pieces.remove(adapter); + } + + /** + * Adds a new View to the roster of things to appear + * in the aggregate list. + * + * @param view Single view to add + */ + public ListAdapter addView(View view) { + return addView(view, false); + } + + /** + * Adds a new View to the roster of things to appear + * in the aggregate list. + * + * @param view Single view to add + * @param enabled false if views are disabled, true if enabled + */ + public ListAdapter addView(View view, boolean enabled) { + return addViews(Arrays.asList(view), enabled); + } + + /** + * Adds a list of views to the roster of things to appear + * in the aggregate list. + * + * @param views List of views to add + */ + public ListAdapter addViews(List views) { + return addViews(views, false); + } + + /** + * Adds a list of views to the roster of things to appear + * in the aggregate list. + * + * @param views List of views to add + * @param enabled false if views are disabled, true if enabled + */ + public ListAdapter addViews(List views, boolean enabled) { + ListAdapter adapter = enabled ? new EnabledSackAdapter(views) : new SackOfViewsAdapter(views); + addAdapter(adapter); + return adapter; + } + + /** + * Get the data item associated with the specified + * position in the data set. + * + * @param position Position of the item whose data we want + */ + @Override + public Object getItem(int position) { + for (ListAdapter piece : pieces) { + int size = piece.getCount(); + + if (position < size) { + return (piece.getItem(position)); + } + + position -= size; + } + + return (null); + } + + /** + * How many items are in the data set represented by this + * Adapter. + */ + @Override + public int getCount() { + int total = 0; + + for (ListAdapter piece : pieces) { + total += piece.getCount(); + } + + return (total); + } + + /** + * Returns the number of types of Views that will be + * created by getView(). + */ + @Override + public int getViewTypeCount() { + int total = 0; + + for (ListAdapter piece : pieces) { + total += piece.getViewTypeCount(); + } + + return (Math.max(total, 1)); // needed for setListAdapter() before content add' + } + + /** + * Get the type of View that will be created by getView() + * for the specified item. + * + * @param position Position of the item whose data we want + */ + @Override + public int getItemViewType(int position) { + int typeOffset = 0; + int result = -1; + + for (ListAdapter piece : pieces) { + int size = piece.getCount(); + + if (position < size) { + result = typeOffset + piece.getItemViewType(position); + break; + } + + position -= size; + typeOffset += piece.getViewTypeCount(); + } + + return (result); + } + + /** + * Are all items in this ListAdapter enabled? If yes it + * means all items are selectable and clickable. + */ + @Override + public boolean areAllItemsEnabled() { + return (false); + } + + /** + * Returns true if the item at the specified position is + * not a separator. + * + * @param position Position of the item whose data we want + */ + @Override + public boolean isEnabled(int position) { + for (ListAdapter piece : pieces) { + int size = piece.getCount(); + + if (position < size) { + return (piece.isEnabled(position)); + } + + position -= size; + } + + return (false); + } + + /** + * Get a View that displays the data at the specified + * position in the data set. + * + * @param position Position of the item whose data we want + * @param convertView View to recycle, if not null + * @param parent ViewGroup containing the returned View + */ + @Override + public View getView(int position, View convertView, + ViewGroup parent) { + for (ListAdapter piece : pieces) { + int size = piece.getCount(); + + if (position < size) { + + return (piece.getView(position, convertView, parent)); + } + + position -= size; + } + + return (null); + } + + /** + * Get the row id associated with the specified position + * in the list. + * + * @param position Position of the item whose data we want + */ + @Override + public long getItemId(int position) { + for (ListAdapter piece : pieces) { + int size = piece.getCount(); + + if (position < size) { + return (piece.getItemId(position)); + } + + position -= size; + } + + return (-1); + } + + private static class EnabledSackAdapter extends SackOfViewsAdapter { + public EnabledSackAdapter(List views) { + super(views); + } + + @Override + public boolean areAllItemsEnabled() { + return (true); + } + + @Override + public boolean isEnabled(int position) { + return (true); + } + } + + private class CascadeDataSetObserver extends DataSetObserver { + @Override + public void onChanged() { + notifyDataSetChanged(); + } + + @Override + public void onInvalidated() { + notifyDataSetInvalidated(); + } + } +} + diff --git a/src/github/daneren2005/dsub/adapter/PlaylistAdapter.java b/src/github/daneren2005/dsub/adapter/PlaylistAdapter.java new file mode 100644 index 00000000..d56a6b97 --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/PlaylistAdapter.java @@ -0,0 +1,70 @@ +/* + 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 2010 (C) Sindre Mehus + */ +package github.daneren2005.dsub.adapter; + +import android.content.Context; +import github.daneren2005.dsub.R; +import java.util.List; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import github.daneren2005.dsub.domain.Playlist; +import github.daneren2005.dsub.view.PlaylistView; + +import java.util.Collections; +import java.util.Comparator; + +/** + * @author Sindre Mehus + */ +public class PlaylistAdapter extends ArrayAdapter { + + private final Context activity; + + public PlaylistAdapter(Context activity, List Playlists) { + super(activity, R.layout.basic_list_item, Playlists); + this.activity = activity; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Playlist entry = getItem(position); + PlaylistView view; + if (convertView != null && convertView instanceof PlaylistView) { + view = (PlaylistView) convertView; + } else { + view = new PlaylistView(activity); + } + view.setObject(entry); + return view; + } + + public static class PlaylistComparator implements Comparator { + @Override + public int compare(Playlist playlist1, Playlist playlist2) { + return playlist1.getName().compareToIgnoreCase(playlist2.getName()); + } + + public static List sort(List playlists) { + Collections.sort(playlists, new PlaylistComparator()); + return playlists; + } + + } +} diff --git a/src/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java b/src/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java new file mode 100644 index 00000000..8ee39a10 --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java @@ -0,0 +1,60 @@ +/* + 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 2010 (C) Sindre Mehus + */ +package github.daneren2005.dsub.adapter; + +import android.widget.ArrayAdapter; +import android.widget.SectionIndexer; +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.PodcastChannel; +import github.daneren2005.dsub.view.PodcastChannelView; + +import java.util.List; +import java.util.Set; +import java.util.LinkedHashSet; +import java.util.ArrayList; + +/** + * @author Sindre Mehus +*/ +public class PodcastChannelAdapter extends ArrayAdapter{ + private Context activity; + private List podcasts; + + public PodcastChannelAdapter(Context context, List podcasts) { + super(context, android.R.layout.simple_list_item_1, podcasts); + this.activity = context; + this.podcasts = podcasts; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + PodcastChannel podcast = podcasts.get(position); + PodcastChannelView view; + if (convertView != null && convertView instanceof PodcastChannelView) { + view = (PodcastChannelView) convertView; + } else { + view = new PodcastChannelView(activity); + } + view.setObject(podcast); + return view; + } +} diff --git a/src/github/daneren2005/dsub/adapter/SackOfViewsAdapter.java b/src/github/daneren2005/dsub/adapter/SackOfViewsAdapter.java new file mode 100644 index 00000000..e4744cc5 --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/SackOfViewsAdapter.java @@ -0,0 +1,181 @@ +/*** + Copyright (c) 2008-2009 CommonsWare, LLC + Portions (c) 2009 Google, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); you may + not use this file except in compliance with the License. You may obtain + a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +package github.daneren2005.dsub.adapter; + +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ListView; + +import java.util.ArrayList; +import java.util.List; + +/** + * Adapter that simply returns row views from a list. + *

+ * If you supply a size, you must implement newView(), to + * create a required view. The adapter will then cache these + * views. + *

+ * If you supply a list of views in the constructor, that + * list will be used directly. If any elements in the list + * are null, then newView() will be called just for those + * slots. + *

+ * Subclasses may also wish to override areAllItemsEnabled() + * (default: false) and isEnabled() (default: false), if some + * of their rows should be selectable. + *

+ * It is assumed each view is unique, and therefore will not + * get recycled. + *

+ * Note that this adapter is not designed for long lists. It + * is more for screens that should behave like a list. This + * is particularly useful if you combine this with other + * adapters (e.g., SectionedAdapter) that might have an + * arbitrary number of rows, so it all appears seamless. + */ +public class SackOfViewsAdapter extends BaseAdapter { + private List views = null; + + /** + * Constructor creating an empty list of views, but with + * a specified count. Subclasses must override newView(). + */ + public SackOfViewsAdapter(int count) { + super(); + + views = new ArrayList(count); + + for (int i = 0; i < count; i++) { + views.add(null); + } + } + + /** + * Constructor wrapping a supplied list of views. + * Subclasses must override newView() if any of the elements + * in the list are null. + */ + public SackOfViewsAdapter(List views) { + for (View view : views) { + view.setLayoutParams(new ListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + } + this.views = views; + } + + /** + * Get the data item associated with the specified + * position in the data set. + * + * @param position Position of the item whose data we want + */ + @Override + public Object getItem(int position) { + return (views.get(position)); + } + + /** + * How many items are in the data set represented by this + * Adapter. + */ + @Override + public int getCount() { + return (views.size()); + } + + /** + * Returns the number of types of Views that will be + * created by getView(). + */ + @Override + public int getViewTypeCount() { + return (getCount()); + } + + /** + * Get the type of View that will be created by getView() + * for the specified item. + * + * @param position Position of the item whose data we want + */ + @Override + public int getItemViewType(int position) { + return (position); + } + + /** + * Are all items in this ListAdapter enabled? If yes it + * means all items are selectable and clickable. + */ + @Override + public boolean areAllItemsEnabled() { + return (false); + } + + /** + * Returns true if the item at the specified position is + * not a separator. + * + * @param position Position of the item whose data we want + */ + @Override + public boolean isEnabled(int position) { + return (false); + } + + /** + * Get a View that displays the data at the specified + * position in the data set. + * + * @param position Position of the item whose data we want + * @param convertView View to recycle, if not null + * @param parent ViewGroup containing the returned View + */ + @Override + public View getView(int position, View convertView, + ViewGroup parent) { + View result = views.get(position); + + if (result == null) { + result = newView(position, parent); + views.set(position, result); + } + + return (result); + } + + /** + * Get the row id associated with the specified position + * in the list. + * + * @param position Position of the item whose data we want + */ + @Override + public long getItemId(int position) { + return (position); + } + + /** + * Create a new View to go into the list at the specified + * position. + * + * @param position Position of the item whose data we want + * @param parent ViewGroup containing the returned View + */ + protected View newView(int position, ViewGroup parent) { + throw new RuntimeException("You must override newView()!"); + } +} diff --git a/src/github/daneren2005/dsub/adapter/SettingsAdapter.java b/src/github/daneren2005/dsub/adapter/SettingsAdapter.java new file mode 100644 index 00000000..45c3ead1 --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/SettingsAdapter.java @@ -0,0 +1,59 @@ +/* + 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.adapter; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; + +import java.util.List; + +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.User; +import github.daneren2005.dsub.view.SettingView; + +import static github.daneren2005.dsub.domain.User.Setting; + +public class SettingsAdapter extends ArrayAdapter { + private final Context context; + private final boolean editable; + + public SettingsAdapter(Context context, User user, boolean editable) { + super(context, R.layout.basic_list_item, user.getSettings()); + this.context = context; + this.editable = editable; + } + + public SettingsAdapter(Context context, List settings, boolean editable) { + super(context, R.layout.basic_list_item, settings); + this.context = context; + this.editable = editable; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Setting entry = getItem(position); + SettingView view; + if (convertView != null && convertView instanceof SettingView) { + view = (SettingView) convertView; + } else { + view = new SettingView(context); + } + view.setObject(entry, editable); + return view; + } +} diff --git a/src/github/daneren2005/dsub/adapter/ShareAdapter.java b/src/github/daneren2005/dsub/adapter/ShareAdapter.java new file mode 100644 index 00000000..4121a85a --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/ShareAdapter.java @@ -0,0 +1,56 @@ +/* + 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 2010 (C) Sindre Mehus + */ +package github.daneren2005.dsub.adapter; + +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.Share; +import github.daneren2005.dsub.view.ShareView; + +/** + * @author Sindre Mehus +*/ +public class ShareAdapter extends ArrayAdapter{ + private Context activity; + private List shares; + + public ShareAdapter(Context context, List shares) { + super(context, android.R.layout.simple_list_item_1, shares); + this.activity = context; + this.shares = shares; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Share share = shares.get(position); + ShareView view; + if (convertView != null && convertView instanceof ShareView) { + view = (ShareView) convertView; + } else { + view = new ShareView(activity); + } + view.setObject(share); + return view; + } +} diff --git a/src/github/daneren2005/dsub/adapter/UserAdapter.java b/src/github/daneren2005/dsub/adapter/UserAdapter.java new file mode 100644 index 00000000..f0f78d97 --- /dev/null +++ b/src/github/daneren2005/dsub/adapter/UserAdapter.java @@ -0,0 +1,52 @@ +/* + 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.adapter; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; + +import java.util.List; + +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.User; +import github.daneren2005.dsub.util.ImageLoader; +import github.daneren2005.dsub.view.UserView; + +public class UserAdapter extends ArrayAdapter { + private final Context activity; + private final ImageLoader imageLoader; + + public UserAdapter(Context activity, List users, ImageLoader imageLoader) { + super(activity, R.layout.basic_list_item, users); + this.activity = activity; + this.imageLoader = imageLoader; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + User entry = getItem(position); + UserView view; + if (convertView != null && convertView instanceof UserView) { + view = (UserView) convertView; + } else { + view = new UserView(activity); + } + view.setObject(entry, imageLoader); + return view; + } +} \ No newline at end of file diff --git a/src/github/daneren2005/dsub/fragments/AdminFragment.java b/src/github/daneren2005/dsub/fragments/AdminFragment.java index 021e80d1..d59526b6 100644 --- a/src/github/daneren2005/dsub/fragments/AdminFragment.java +++ b/src/github/daneren2005/dsub/fragments/AdminFragment.java @@ -15,17 +15,13 @@ package github.daneren2005.dsub.fragments; -import android.app.AlertDialog; -import android.content.DialogInterface; import android.os.Bundle; -import android.util.Log; import android.view.ContextMenu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.TextView; import java.io.File; import java.util.ArrayList; @@ -34,16 +30,12 @@ import java.util.List; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.User; import github.daneren2005.dsub.service.MusicService; -import github.daneren2005.dsub.service.MusicServiceFactory; -import github.daneren2005.dsub.service.OfflineException; -import github.daneren2005.dsub.service.ServerTooOldException; import github.daneren2005.dsub.service.parser.SubsonicRESTException; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.ProgressListener; -import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.UserUtil; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.UserAdapter; +import github.daneren2005.dsub.adapter.UserAdapter; public class AdminFragment extends SelectListFragment { private static String TAG = AdminFragment.class.getSimpleName(); diff --git a/src/github/daneren2005/dsub/fragments/ChatFragment.java b/src/github/daneren2005/dsub/fragments/ChatFragment.java index d51be830..5d017fa7 100644 --- a/src/github/daneren2005/dsub/fragments/ChatFragment.java +++ b/src/github/daneren2005/dsub/fragments/ChatFragment.java @@ -12,7 +12,6 @@ import android.os.Handler; import android.support.v4.widget.SwipeRefreshLayout; import android.text.Editable; import android.text.TextWatcher; -import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; @@ -20,10 +19,8 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; 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; @@ -35,7 +32,7 @@ import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.ChatAdapter; +import github.daneren2005.dsub.adapter.ChatAdapter; import github.daneren2005.dsub.util.Constants; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; diff --git a/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/src/github/daneren2005/dsub/fragments/DownloadFragment.java index a72ef8da..24c9d303 100644 --- a/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -18,7 +18,6 @@ package github.daneren2005.dsub.fragments; import android.content.DialogInterface; import android.os.Handler; import android.view.ContextMenu; -import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; @@ -38,9 +37,7 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.DownloadFileAdapter; - -import static github.daneren2005.dsub.domain.MusicDirectory.Entry; +import github.daneren2005.dsub.adapter.DownloadFileAdapter; public class DownloadFragment extends SelectListFragment { private long currentRevision; diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java index 0e1b587e..ebe84d77 100644 --- a/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -30,7 +30,7 @@ import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.Pair; import github.daneren2005.dsub.util.UserUtil; -import github.daneren2005.dsub.view.MergeAdapter; +import github.daneren2005.dsub.adapter.MergeAdapter; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; diff --git a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java index c0f528de..198e1779 100644 --- a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -25,7 +25,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; -import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.os.Handler; @@ -68,7 +67,7 @@ import github.daneren2005.dsub.service.OfflineException; import github.daneren2005.dsub.service.ServerTooOldException; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.SilentBackgroundTask; -import github.daneren2005.dsub.view.DownloadFileAdapter; +import github.daneren2005.dsub.adapter.DownloadFileAdapter; import github.daneren2005.dsub.view.FadeOutAnimation; import github.daneren2005.dsub.view.UpdateView; import github.daneren2005.dsub.util.Util; diff --git a/src/github/daneren2005/dsub/fragments/SearchFragment.java b/src/github/daneren2005/dsub/fragments/SearchFragment.java index f73989fb..066a940f 100644 --- a/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -13,7 +13,6 @@ 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; @@ -27,11 +26,11 @@ import github.daneren2005.dsub.domain.SearchResult; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.service.DownloadService; -import github.daneren2005.dsub.view.ArtistAdapter; +import github.daneren2005.dsub.adapter.ArtistAdapter; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.Constants; -import github.daneren2005.dsub.view.EntryAdapter; -import github.daneren2005.dsub.view.MergeAdapter; +import github.daneren2005.dsub.adapter.EntryAdapter; +import github.daneren2005.dsub.adapter.MergeAdapter; import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; diff --git a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 9b6e86d3..1c3f06a4 100644 --- a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -1,10 +1,8 @@ package github.daneren2005.dsub.fragments; import android.annotation.TargetApi; -import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; -import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.Menu; @@ -25,7 +23,7 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.ArtistAdapter; +import github.daneren2005.dsub.adapter.ArtistAdapter; import java.io.Serializable; import java.util.ArrayList; diff --git a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java index 85895dd2..c71d99f6 100644 --- a/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java @@ -18,8 +18,6 @@ */ package github.daneren2005.dsub.fragments; -import android.content.DialogInterface; -import android.util.Log; import android.view.ContextMenu; import android.view.MenuInflater; import android.view.MenuItem; @@ -30,21 +28,13 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.DownloadActivity; import github.daneren2005.dsub.domain.Bookmark; import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.MusicService; -import github.daneren2005.dsub.service.MusicServiceFactory; -import github.daneren2005.dsub.service.OfflineException; -import github.daneren2005.dsub.service.ServerTooOldException; -import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.BookmarkAdapter; -import github.daneren2005.dsub.view.SongView; +import github.daneren2005.dsub.adapter.BookmarkAdapter; -import java.text.Format; -import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.List; diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 327f1828..7b6a7261 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -5,18 +5,14 @@ import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.Canvas; -import android.graphics.Paint; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.text.Html; -import android.text.Layout; import android.text.SpannableString; import android.text.Spanned; import android.text.method.LinkMovementMethod; -import android.text.style.LeadingMarginSpan; import android.util.Log; import android.view.ContextMenu; import android.view.Display; @@ -28,7 +24,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; -import android.widget.FrameLayout; import android.widget.GridView; import android.widget.ImageButton; import android.widget.ImageView; @@ -44,8 +39,8 @@ import github.daneren2005.dsub.domain.ServerInfo; import github.daneren2005.dsub.domain.Share; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.util.ImageLoader; -import github.daneren2005.dsub.view.AlbumGridAdapter; -import github.daneren2005.dsub.view.EntryAdapter; +import github.daneren2005.dsub.adapter.AlbumGridAdapter; +import github.daneren2005.dsub.adapter.EntryAdapter; import java.io.Serializable; import java.util.Iterator; @@ -63,7 +58,7 @@ import github.daneren2005.dsub.util.Pair; import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.UserUtil; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.AlbumListAdapter; +import github.daneren2005.dsub.adapter.AlbumListAdapter; import github.daneren2005.dsub.view.HeaderGridView; import github.daneren2005.dsub.view.MyLeadingMarginSpan2; diff --git a/src/github/daneren2005/dsub/fragments/SelectGenreFragment.java b/src/github/daneren2005/dsub/fragments/SelectGenreFragment.java index 9cf505b3..4068dca2 100644 --- a/src/github/daneren2005/dsub/fragments/SelectGenreFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectGenreFragment.java @@ -27,7 +27,7 @@ import github.daneren2005.dsub.domain.Genre; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.ProgressListener; -import github.daneren2005.dsub.view.GenreAdapter; +import github.daneren2005.dsub.adapter.GenreAdapter; import java.util.List; diff --git a/src/github/daneren2005/dsub/fragments/SelectListFragment.java b/src/github/daneren2005/dsub/fragments/SelectListFragment.java index 3329e848..749ef842 100644 --- a/src/github/daneren2005/dsub/fragments/SelectListFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectListFragment.java @@ -27,11 +27,8 @@ 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; -import android.widget.ListAdapter; import android.widget.ListView; import java.io.Serializable; @@ -39,14 +36,12 @@ import java.util.ArrayList; import java.util.List; import github.daneren2005.dsub.R; -import github.daneren2005.dsub.domain.Genre; 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.view.GenreAdapter; public abstract class SelectListFragment extends SubsonicFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectListFragment.class.getSimpleName(); diff --git a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 8c16edd5..af372076 100644 --- a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -29,7 +29,7 @@ import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.UserUtil; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.PlaylistAdapter; +import github.daneren2005.dsub.adapter.PlaylistAdapter; import java.util.List; diff --git a/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java b/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java index 73a415ba..09307476 100644 --- a/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java @@ -41,7 +41,7 @@ import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.UserUtil; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.PodcastChannelAdapter; +import github.daneren2005.dsub.adapter.PodcastChannelAdapter; import java.util.ArrayList; import java.util.List; diff --git a/src/github/daneren2005/dsub/fragments/SelectShareFragment.java b/src/github/daneren2005/dsub/fragments/SelectShareFragment.java index 692df7d0..d15f170d 100644 --- a/src/github/daneren2005/dsub/fragments/SelectShareFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectShareFragment.java @@ -26,7 +26,7 @@ import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.ShareAdapter; +import github.daneren2005.dsub.adapter.ShareAdapter; /** * Created by Scott on 12/28/13. diff --git a/src/github/daneren2005/dsub/fragments/SelectVideoFragment.java b/src/github/daneren2005/dsub/fragments/SelectVideoFragment.java index 0c8519e8..b4d34ff9 100644 --- a/src/github/daneren2005/dsub/fragments/SelectVideoFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectVideoFragment.java @@ -27,7 +27,7 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.util.ProgressListener; -import github.daneren2005.dsub.view.EntryAdapter; +import github.daneren2005.dsub.adapter.EntryAdapter; public class SelectVideoFragment extends SelectListFragment { @Override diff --git a/src/github/daneren2005/dsub/fragments/SimilarArtistFragment.java b/src/github/daneren2005/dsub/fragments/SimilarArtistFragment.java index 06427a5d..b87db495 100644 --- a/src/github/daneren2005/dsub/fragments/SimilarArtistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SimilarArtistFragment.java @@ -15,17 +15,12 @@ package github.daneren2005.dsub.fragments; -import android.app.AlertDialog; import android.os.Bundle; -import android.text.method.LinkMovementMethod; import android.view.ContextMenu; -import android.view.Menu; -import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.Artist; @@ -37,7 +32,7 @@ import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.ArtistAdapter; +import github.daneren2005.dsub.adapter.ArtistAdapter; import java.net.URLEncoder; import java.util.LinkedList; diff --git a/src/github/daneren2005/dsub/fragments/UserFragment.java b/src/github/daneren2005/dsub/fragments/UserFragment.java index 2391762e..2fa804cc 100644 --- a/src/github/daneren2005/dsub/fragments/UserFragment.java +++ b/src/github/daneren2005/dsub/fragments/UserFragment.java @@ -16,8 +16,6 @@ package github.daneren2005.dsub.fragments; import android.app.Activity; -import android.app.AlertDialog; -import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.view.LayoutInflater; @@ -34,16 +32,10 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.SubsonicActivity; import github.daneren2005.dsub.domain.ServerInfo; import github.daneren2005.dsub.domain.User; -import github.daneren2005.dsub.service.MusicService; -import github.daneren2005.dsub.service.MusicServiceFactory; -import github.daneren2005.dsub.service.OfflineException; -import github.daneren2005.dsub.service.ServerTooOldException; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.ImageLoader; -import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.UserUtil; -import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.SettingsAdapter; +import github.daneren2005.dsub.adapter.SettingsAdapter; public class UserFragment extends SubsonicFragment{ private ListView listView; diff --git a/src/github/daneren2005/dsub/service/parser/PlaylistsParser.java b/src/github/daneren2005/dsub/service/parser/PlaylistsParser.java index ee978167..6f01d510 100644 --- a/src/github/daneren2005/dsub/service/parser/PlaylistsParser.java +++ b/src/github/daneren2005/dsub/service/parser/PlaylistsParser.java @@ -19,10 +19,10 @@ package github.daneren2005.dsub.service.parser; import android.content.Context; -import github.daneren2005.dsub.R; + import github.daneren2005.dsub.domain.Playlist; import github.daneren2005.dsub.util.ProgressListener; -import github.daneren2005.dsub.view.PlaylistAdapter; +import github.daneren2005.dsub.adapter.PlaylistAdapter; import org.xmlpull.v1.XmlPullParser; import java.io.Reader; diff --git a/src/github/daneren2005/dsub/util/UserUtil.java b/src/github/daneren2005/dsub/util/UserUtil.java index 19e8b918..c5da93d3 100644 --- a/src/github/daneren2005/dsub/util/UserUtil.java +++ b/src/github/daneren2005/dsub/util/UserUtil.java @@ -20,17 +20,13 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; -import android.os.Build; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.View; -import android.widget.Adapter; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; -import java.io.File; - import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.User; import github.daneren2005.dsub.fragments.SubsonicFragment; @@ -39,7 +35,7 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.service.OfflineException; import github.daneren2005.dsub.service.ServerTooOldException; -import github.daneren2005.dsub.view.SettingsAdapter; +import github.daneren2005.dsub.adapter.SettingsAdapter; public final class UserUtil { private static final String TAG = UserUtil.class.getSimpleName(); diff --git a/src/github/daneren2005/dsub/view/AlbumGridAdapter.java b/src/github/daneren2005/dsub/view/AlbumGridAdapter.java deleted file mode 100644 index 3347002c..00000000 --- a/src/github/daneren2005/dsub/view/AlbumGridAdapter.java +++ /dev/null @@ -1,72 +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 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; - private boolean showArtist; - - public AlbumGridAdapter(Context activity, ImageLoader imageLoader, List entries, boolean showArtist) { - super(activity, android.R.layout.simple_list_item_1, entries); - this.entries = entries; - this.activity = activity; - this.imageLoader = imageLoader; - - // Always show artist if they aren't all the same - if(!showArtist) { - String artist = null; - for(MusicDirectory.Entry entry: entries) { - if(artist == null) { - artist = entry.getArtist(); - } - - if(artist != null && !artist.equals(entry.getArtist())) { - showArtist = true; - } - } - } - this.showArtist = showArtist; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - MusicDirectory.Entry entry = getItem(position); - - AlbumCell view; - if(convertView instanceof AlbumCell) { - view = (AlbumCell) convertView; - } else { - view = new AlbumCell(activity); - } - - view.setShowArtist(showArtist); - view.setObject(entry, imageLoader); - return view; - } -} diff --git a/src/github/daneren2005/dsub/view/AlbumListAdapter.java b/src/github/daneren2005/dsub/view/AlbumListAdapter.java deleted file mode 100644 index 6c3b2f73..00000000 --- a/src/github/daneren2005/dsub/view/AlbumListAdapter.java +++ /dev/null @@ -1,84 +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 2010 (C) Sindre Mehus - */ -package github.daneren2005.dsub.view; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import com.commonsware.cwac.endless.EndlessAdapter; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.domain.ServerInfo; -import github.daneren2005.dsub.service.MusicService; -import github.daneren2005.dsub.service.MusicServiceFactory; -import github.daneren2005.dsub.util.Util; - -import java.util.List; - -public class AlbumListAdapter extends EndlessAdapter { - Context context; - ArrayAdapter adapter; - String type; - String extra; - int size; - int offset; - List entries; - - public AlbumListAdapter(Context context, ArrayAdapter adapter, String type, String extra, int size) { - super(adapter); - this.context = context; - this.adapter = adapter; - this.type = type; - this.extra = extra; - this.size = size; - this.offset = size; - } - - @Override - protected boolean cacheInBackground() throws Exception { - MusicService service = MusicServiceFactory.getMusicService(context); - MusicDirectory result; - 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)) { - result = service.getSongsByGenre(extra, size, offset, context, null); - } else { - result = service.getAlbumList(type, size, offset, context, null); - } - entries = result.getChildren(); - return entries.size() > 0; - } - - @Override - protected void appendCachedData() { - for(MusicDirectory.Entry entry: entries) { - adapter.add(entry); - } - offset += entries.size(); - } - - @Override - protected View getPendingView(ViewGroup parent) { - View progress = LayoutInflater.from(context).inflate(R.layout.tab_progress, null); - progress.setVisibility(View.VISIBLE); - return progress; - } -} diff --git a/src/github/daneren2005/dsub/view/ArtistAdapter.java b/src/github/daneren2005/dsub/view/ArtistAdapter.java deleted file mode 100644 index 1998eaed..00000000 --- a/src/github/daneren2005/dsub/view/ArtistAdapter.java +++ /dev/null @@ -1,95 +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 2010 (C) Sindre Mehus - */ -package github.daneren2005.dsub.view; - -import android.content.Context; -import github.daneren2005.dsub.R; -import java.util.List; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.SectionIndexer; -import github.daneren2005.dsub.domain.Artist; -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.Set; - -/** - * @author Sindre Mehus - */ -public class ArtistAdapter extends ArrayAdapter implements SectionIndexer { - - private final Context activity; - - // Both arrays are indexed by section ID. - private final Object[] sections; - private final Integer[] positions; - - public ArtistAdapter(Context activity, List artists) { - super(activity, R.layout.basic_list_item, artists); - this.activity = activity; - - Set sectionSet = new LinkedHashSet(30); - List positionList = new ArrayList(30); - for (int i = 0; i < artists.size(); i++) { - Artist artist = artists.get(i); - String index = artist.getIndex(); - if (!sectionSet.contains(index)) { - sectionSet.add(index); - positionList.add(i); - } - } - sections = sectionSet.toArray(new Object[sectionSet.size()]); - positions = positionList.toArray(new Integer[positionList.size()]); - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - Artist entry = getItem(position); - ArtistView view; - if (convertView != null && convertView instanceof ArtistView) { - view = (ArtistView) convertView; - } else { - view = new ArtistView(activity); - } - view.setObject(entry); - return view; - } - - @Override - public Object[] getSections() { - return sections; - } - - @Override - public int getPositionForSection(int section) { - section = Math.min(section, positions.length - 1); - return positions[section]; - } - - @Override - public int getSectionForPosition(int pos) { - for (int i = 0; i < sections.length - 1; i++) { - if (pos < positions[i + 1]) { - return i; - } - } - return sections.length - 1; - } -} diff --git a/src/github/daneren2005/dsub/view/BookmarkAdapter.java b/src/github/daneren2005/dsub/view/BookmarkAdapter.java deleted file mode 100644 index ea585744..00000000 --- a/src/github/daneren2005/dsub/view/BookmarkAdapter.java +++ /dev/null @@ -1,63 +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 2010 (C) Sindre Mehus -*/ - -package github.daneren2005.dsub.view; - -import android.content.Context; - -import java.util.List; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.TextView; - -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.domain.Bookmark; -import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.util.Util; - -public class BookmarkAdapter extends ArrayAdapter { - private final static String TAG = BookmarkAdapter.class.getSimpleName(); - private Context activity; - - public BookmarkAdapter(Context activity, List bookmarks) { - super(activity, android.R.layout.simple_list_item_1, bookmarks); - this.activity = activity; - } - - public View getView(int position, View convertView, ViewGroup parent) { - MusicDirectory.Entry entry = getItem(position); - Bookmark bookmark = entry.getBookmark(); - - SongView view; - if (convertView != null) { - view = (SongView) convertView; - } else { - view = new SongView(activity); - } - view.setObject(entry, false); - - // Add current position to duration - TextView durationTextView = (TextView) view.findViewById(R.id.song_duration); - String duration = durationTextView.getText().toString(); - durationTextView.setText(Util.formatDuration(bookmark.getPosition() / 1000) + " / " + duration); - - return view; - } -} diff --git a/src/github/daneren2005/dsub/view/ChatAdapter.java b/src/github/daneren2005/dsub/view/ChatAdapter.java deleted file mode 100644 index 0ce757a9..00000000 --- a/src/github/daneren2005/dsub/view/ChatAdapter.java +++ /dev/null @@ -1,109 +0,0 @@ -package github.daneren2005.dsub.view; - -import android.text.method.LinkMovementMethod; -import android.text.util.Linkify; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.TextView; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.activity.SubsonicActivity; -import github.daneren2005.dsub.domain.ChatMessage; -import github.daneren2005.dsub.util.ImageLoader; -import github.daneren2005.dsub.util.UserUtil; -import github.daneren2005.dsub.util.Util; - -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.regex.Pattern; - -public class ChatAdapter extends ArrayAdapter { - - private final SubsonicActivity activity; - private ArrayList messages; - private final ImageLoader imageLoader; - - private static final String phoneRegex = "1?\\W*([2-9][0-8][0-9])\\W*([2-9][0-9]{2})\\W*([0-9]{4})"; //you can just place your support phone here - private static final Pattern phoneMatcher = Pattern.compile(phoneRegex); - - public ChatAdapter(SubsonicActivity activity, ArrayList messages, ImageLoader imageLoader) { - super(activity, R.layout.chat_item, messages); - this.activity = activity; - this.messages = messages; - this.imageLoader = imageLoader; - } - - @Override - public int getCount() { - return messages.size(); - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - ChatMessage message = this.getItem(position); - - ViewHolder holder; - int layout; - - String messageUser = message.getUsername(); - Date messageTime = new java.util.Date(message.getTime()); - String messageText = message.getMessage(); - - String me = UserUtil.getCurrentUsername(activity); - - if (messageUser.equals(me)) { - layout = R.layout.chat_item_reverse; - } else { - layout = R.layout.chat_item; - } - - if (convertView == null) - { - holder = new ViewHolder(); - - convertView = LayoutInflater.from(activity).inflate(layout, parent, false); - - TextView usernameView = (TextView) convertView.findViewById(R.id.chat_username); - TextView timeView = (TextView) convertView.findViewById(R.id.chat_time); - TextView messageView = (TextView) convertView.findViewById(R.id.chat_message); - - messageView.setMovementMethod(LinkMovementMethod.getInstance()); - Linkify.addLinks(messageView, Linkify.EMAIL_ADDRESSES); - Linkify.addLinks(messageView, Linkify.WEB_URLS); - Linkify.addLinks(messageView, phoneMatcher, "tel:"); - - holder.message = messageView; - holder.username = usernameView; - holder.time = timeView; - holder.avatar = (ImageView) convertView.findViewById(R.id.chat_avatar); - - convertView.setTag(holder); - } - else - { - holder = (ViewHolder) convertView.getTag(); - } - - DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); - String messageTimeFormatted = String.format("[%s]", timeFormat.format(messageTime)); - - holder.username.setText(messageUser); - holder.message.setText(messageText); - holder.time.setText(messageTimeFormatted); - - imageLoader.loadAvatar(activity, holder.avatar, messageUser); - - return convertView; - } - - private static class ViewHolder - { - TextView message; - TextView username; - TextView time; - ImageView avatar; - } -} diff --git a/src/github/daneren2005/dsub/view/DownloadFileAdapter.java b/src/github/daneren2005/dsub/view/DownloadFileAdapter.java deleted file mode 100644 index f535acef..00000000 --- a/src/github/daneren2005/dsub/view/DownloadFileAdapter.java +++ /dev/null @@ -1,48 +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 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.service.DownloadFile; - -public class DownloadFileAdapter extends ArrayAdapter { - Context context; - - public DownloadFileAdapter(Context context, List entries) { - super(context, android.R.layout.simple_list_item_1, entries); - this.context = context; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - SongView view; - if (convertView != null && convertView instanceof SongView) { - view = (SongView) convertView; - } else { - view = new SongView(context); - } - DownloadFile downloadFile = getItem(position); - view.setObject(downloadFile.getSong(), false); - view.setDownloadFile(downloadFile); - return view; - } -} diff --git a/src/github/daneren2005/dsub/view/DrawerAdapter.java b/src/github/daneren2005/dsub/view/DrawerAdapter.java deleted file mode 100644 index 1f2c7f4f..00000000 --- a/src/github/daneren2005/dsub/view/DrawerAdapter.java +++ /dev/null @@ -1,128 +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.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.TextView; - -import java.util.ArrayList; -import java.util.List; - -import github.daneren2005.dsub.R; - -/** - * Created by Scott on 11/8/13. - */ -public class DrawerAdapter extends ArrayAdapter { - private static String TAG = DrawerAdapter.class.getSimpleName(); - private Context context; - private List items; - private List icons; - private List visible; - private int selectedPosition = -1; - - public DrawerAdapter(Context context, List items, List icons, List visible) { - super(context, R.layout.drawer_list_item, items); - - this.context = context; - this.items = items; - this.icons = icons; - this.visible = visible; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - position = getActualPosition(position); - String item = items.get(position); - Integer icon = icons.get(position); - - if(convertView == null) { - convertView = LayoutInflater.from(context).inflate(R.layout.drawer_list_item, null); - } - - TextView textView = (TextView) convertView.findViewById(R.id.drawer_name); - textView.setText(item); - - if(selectedPosition == position) { - textView.setTextAppearance(context, R.style.DSub_TextViewStyle_Bold); - selectedPosition = -1; - } - - ImageView iconView = (ImageView) convertView.findViewById(R.id.drawer_icon); - iconView.setImageResource(icon); - - return convertView; - } - - @Override - public int getCount() { - int count = 0; - for(int i = 0; i < visible.size(); i++) { - if(visible.get(i)) { - count++; - } - } - - return count; - } - - public int getActualPosition(int position) { - for(int i = 0; i <= position; i++) { - if(!visible.get(i)) { - position++; - } - } - - return position; - } - public int getAdapterPosition(int position) { - if(!visible.get(position)) { - visible.set(position, true); - notifyDataSetChanged(); - } - - for(int i = position; i >= 0; i--) { - if(!visible.get(i)) { - position--; - } - } - - return position; - } - - public void setItemVisible(int position, boolean visible) { - if(this.visible.get(position) != visible) { - this.visible.set(position, visible); - notifyDataSetInvalidated(); - } - } - public void setDownloadVisible(boolean visible) { - setItemVisible(items.size() - 2, visible); - } - - public void setSelectedPosition(int position) { - selectedPosition = position; - } -} diff --git a/src/github/daneren2005/dsub/view/EntryAdapter.java b/src/github/daneren2005/dsub/view/EntryAdapter.java deleted file mode 100644 index e9611692..00000000 --- a/src/github/daneren2005/dsub/view/EntryAdapter.java +++ /dev/null @@ -1,79 +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 2010 (C) Sindre Mehus - */ -package github.daneren2005.dsub.view; - -import android.content.Context; - -import java.util.List; - -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.util.ImageLoader; - -/** - * @author Sindre Mehus - */ -public class EntryAdapter extends ArrayAdapter { - private final static String TAG = EntryAdapter.class.getSimpleName(); - private final Context activity; - private final ImageLoader imageLoader; - private final boolean checkable; - private List entries; - - public EntryAdapter(Context activity, ImageLoader imageLoader, List entries, boolean checkable) { - super(activity, android.R.layout.simple_list_item_1, entries); - this.entries = entries; - this.activity = activity; - this.imageLoader = imageLoader; - this.checkable = checkable; - } - - public void removeAt(int position) { - entries.remove(position); - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - MusicDirectory.Entry entry = getItem(position); - - if (entry.isDirectory()) { - if(entry.isAlbum()) { - 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; - } - } -} diff --git a/src/github/daneren2005/dsub/view/GenreAdapter.java b/src/github/daneren2005/dsub/view/GenreAdapter.java deleted file mode 100644 index 05cc0da9..00000000 --- a/src/github/daneren2005/dsub/view/GenreAdapter.java +++ /dev/null @@ -1,59 +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 2010 (C) Sindre Mehus - */ -package github.daneren2005.dsub.view; - -import android.widget.ArrayAdapter; -import android.widget.SectionIndexer; -import android.content.Context; -import android.view.View; -import android.view.ViewGroup; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.domain.Genre; - -import java.util.List; -import java.util.Set; -import java.util.LinkedHashSet; -import java.util.ArrayList; - -/** - * @author Sindre Mehus -*/ -public class GenreAdapter extends ArrayAdapter{ - private Context activity; - private List genres; - - public GenreAdapter(Context context, List genres) { - super(context, android.R.layout.simple_list_item_1, genres); - this.activity = context; - this.genres = genres; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - Genre genre = genres.get(position); - GenreView view; - if (convertView != null && convertView instanceof GenreView) { - view = (GenreView) convertView; - } else { - view = new GenreView(activity); - } - view.setObject(genre); - return view; - } -} diff --git a/src/github/daneren2005/dsub/view/MergeAdapter.java b/src/github/daneren2005/dsub/view/MergeAdapter.java deleted file mode 100644 index bfe777ea..00000000 --- a/src/github/daneren2005/dsub/view/MergeAdapter.java +++ /dev/null @@ -1,292 +0,0 @@ -/*** - Copyright (c) 2008-2009 CommonsWare, LLC - Portions (c) 2009 Google, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -package github.daneren2005.dsub.view; - -import android.database.DataSetObserver; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.ListAdapter; - -import java.util.ArrayList; -import java.util.List; -import java.util.Arrays; - -import github.daneren2005.dsub.view.SackOfViewsAdapter; - -/** - * Adapter that merges multiple child adapters and views - * into a single contiguous whole. - *

- * Adapters used as pieces within MergeAdapter must - * have view type IDs monotonically increasing from 0. Ideally, - * adapters also have distinct ranges for their row ids, as - * returned by getItemId(). - */ -public class MergeAdapter extends BaseAdapter { - - private final CascadeDataSetObserver observer = new CascadeDataSetObserver(); - private final ArrayList pieces = new ArrayList(); - - /** - * Stock constructor, simply chaining to the superclass. - */ - public MergeAdapter() { - super(); - } - - /** - * Adds a new adapter to the roster of things to appear - * in the aggregate list. - * - * @param adapter Source for row views for this section - */ - public void addAdapter(ListAdapter adapter) { - pieces.add(adapter); - adapter.registerDataSetObserver(observer); - } - - public void removeAdapter(ListAdapter adapter) { - adapter.unregisterDataSetObserver(observer); - pieces.remove(adapter); - } - - /** - * Adds a new View to the roster of things to appear - * in the aggregate list. - * - * @param view Single view to add - */ - public ListAdapter addView(View view) { - return addView(view, false); - } - - /** - * Adds a new View to the roster of things to appear - * in the aggregate list. - * - * @param view Single view to add - * @param enabled false if views are disabled, true if enabled - */ - public ListAdapter addView(View view, boolean enabled) { - return addViews(Arrays.asList(view), enabled); - } - - /** - * Adds a list of views to the roster of things to appear - * in the aggregate list. - * - * @param views List of views to add - */ - public ListAdapter addViews(List views) { - return addViews(views, false); - } - - /** - * Adds a list of views to the roster of things to appear - * in the aggregate list. - * - * @param views List of views to add - * @param enabled false if views are disabled, true if enabled - */ - public ListAdapter addViews(List views, boolean enabled) { - ListAdapter adapter = enabled ? new EnabledSackAdapter(views) : new SackOfViewsAdapter(views); - addAdapter(adapter); - return adapter; - } - - /** - * Get the data item associated with the specified - * position in the data set. - * - * @param position Position of the item whose data we want - */ - @Override - public Object getItem(int position) { - for (ListAdapter piece : pieces) { - int size = piece.getCount(); - - if (position < size) { - return (piece.getItem(position)); - } - - position -= size; - } - - return (null); - } - - /** - * How many items are in the data set represented by this - * Adapter. - */ - @Override - public int getCount() { - int total = 0; - - for (ListAdapter piece : pieces) { - total += piece.getCount(); - } - - return (total); - } - - /** - * Returns the number of types of Views that will be - * created by getView(). - */ - @Override - public int getViewTypeCount() { - int total = 0; - - for (ListAdapter piece : pieces) { - total += piece.getViewTypeCount(); - } - - return (Math.max(total, 1)); // needed for setListAdapter() before content add' - } - - /** - * Get the type of View that will be created by getView() - * for the specified item. - * - * @param position Position of the item whose data we want - */ - @Override - public int getItemViewType(int position) { - int typeOffset = 0; - int result = -1; - - for (ListAdapter piece : pieces) { - int size = piece.getCount(); - - if (position < size) { - result = typeOffset + piece.getItemViewType(position); - break; - } - - position -= size; - typeOffset += piece.getViewTypeCount(); - } - - return (result); - } - - /** - * Are all items in this ListAdapter enabled? If yes it - * means all items are selectable and clickable. - */ - @Override - public boolean areAllItemsEnabled() { - return (false); - } - - /** - * Returns true if the item at the specified position is - * not a separator. - * - * @param position Position of the item whose data we want - */ - @Override - public boolean isEnabled(int position) { - for (ListAdapter piece : pieces) { - int size = piece.getCount(); - - if (position < size) { - return (piece.isEnabled(position)); - } - - position -= size; - } - - return (false); - } - - /** - * Get a View that displays the data at the specified - * position in the data set. - * - * @param position Position of the item whose data we want - * @param convertView View to recycle, if not null - * @param parent ViewGroup containing the returned View - */ - @Override - public View getView(int position, View convertView, - ViewGroup parent) { - for (ListAdapter piece : pieces) { - int size = piece.getCount(); - - if (position < size) { - - return (piece.getView(position, convertView, parent)); - } - - position -= size; - } - - return (null); - } - - /** - * Get the row id associated with the specified position - * in the list. - * - * @param position Position of the item whose data we want - */ - @Override - public long getItemId(int position) { - for (ListAdapter piece : pieces) { - int size = piece.getCount(); - - if (position < size) { - return (piece.getItemId(position)); - } - - position -= size; - } - - return (-1); - } - - private static class EnabledSackAdapter extends SackOfViewsAdapter { - public EnabledSackAdapter(List views) { - super(views); - } - - @Override - public boolean areAllItemsEnabled() { - return (true); - } - - @Override - public boolean isEnabled(int position) { - return (true); - } - } - - private class CascadeDataSetObserver extends DataSetObserver { - @Override - public void onChanged() { - notifyDataSetChanged(); - } - - @Override - public void onInvalidated() { - notifyDataSetInvalidated(); - } - } -} - diff --git a/src/github/daneren2005/dsub/view/PlaylistAdapter.java b/src/github/daneren2005/dsub/view/PlaylistAdapter.java deleted file mode 100644 index ff0294b7..00000000 --- a/src/github/daneren2005/dsub/view/PlaylistAdapter.java +++ /dev/null @@ -1,68 +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 2010 (C) Sindre Mehus - */ -package github.daneren2005.dsub.view; - -import android.content.Context; -import github.daneren2005.dsub.R; -import java.util.List; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import github.daneren2005.dsub.domain.Playlist; -import java.util.Collections; -import java.util.Comparator; - -/** - * @author Sindre Mehus - */ -public class PlaylistAdapter extends ArrayAdapter { - - private final Context activity; - - public PlaylistAdapter(Context activity, List Playlists) { - super(activity, R.layout.basic_list_item, Playlists); - this.activity = activity; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - Playlist entry = getItem(position); - PlaylistView view; - if (convertView != null && convertView instanceof PlaylistView) { - view = (PlaylistView) convertView; - } else { - view = new PlaylistView(activity); - } - view.setObject(entry); - return view; - } - - public static class PlaylistComparator implements Comparator { - @Override - public int compare(Playlist playlist1, Playlist playlist2) { - return playlist1.getName().compareToIgnoreCase(playlist2.getName()); - } - - public static List sort(List playlists) { - Collections.sort(playlists, new PlaylistComparator()); - return playlists; - } - - } -} diff --git a/src/github/daneren2005/dsub/view/PodcastChannelAdapter.java b/src/github/daneren2005/dsub/view/PodcastChannelAdapter.java deleted file mode 100644 index 3a7ab922..00000000 --- a/src/github/daneren2005/dsub/view/PodcastChannelAdapter.java +++ /dev/null @@ -1,59 +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 2010 (C) Sindre Mehus - */ -package github.daneren2005.dsub.view; - -import android.widget.ArrayAdapter; -import android.widget.SectionIndexer; -import android.content.Context; -import android.view.View; -import android.view.ViewGroup; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.domain.PodcastChannel; - -import java.util.List; -import java.util.Set; -import java.util.LinkedHashSet; -import java.util.ArrayList; - -/** - * @author Sindre Mehus -*/ -public class PodcastChannelAdapter extends ArrayAdapter{ - private Context activity; - private List podcasts; - - public PodcastChannelAdapter(Context context, List podcasts) { - super(context, android.R.layout.simple_list_item_1, podcasts); - this.activity = context; - this.podcasts = podcasts; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - PodcastChannel podcast = podcasts.get(position); - PodcastChannelView view; - if (convertView != null && convertView instanceof PodcastChannelView) { - view = (PodcastChannelView) convertView; - } else { - view = new PodcastChannelView(activity); - } - view.setObject(podcast); - return view; - } -} diff --git a/src/github/daneren2005/dsub/view/SackOfViewsAdapter.java b/src/github/daneren2005/dsub/view/SackOfViewsAdapter.java deleted file mode 100644 index ff2280c1..00000000 --- a/src/github/daneren2005/dsub/view/SackOfViewsAdapter.java +++ /dev/null @@ -1,181 +0,0 @@ -/*** - Copyright (c) 2008-2009 CommonsWare, LLC - Portions (c) 2009 Google, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ -package github.daneren2005.dsub.view; - -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.ListView; - -import java.util.ArrayList; -import java.util.List; - -/** - * Adapter that simply returns row views from a list. - *

- * If you supply a size, you must implement newView(), to - * create a required view. The adapter will then cache these - * views. - *

- * If you supply a list of views in the constructor, that - * list will be used directly. If any elements in the list - * are null, then newView() will be called just for those - * slots. - *

- * Subclasses may also wish to override areAllItemsEnabled() - * (default: false) and isEnabled() (default: false), if some - * of their rows should be selectable. - *

- * It is assumed each view is unique, and therefore will not - * get recycled. - *

- * Note that this adapter is not designed for long lists. It - * is more for screens that should behave like a list. This - * is particularly useful if you combine this with other - * adapters (e.g., SectionedAdapter) that might have an - * arbitrary number of rows, so it all appears seamless. - */ -public class SackOfViewsAdapter extends BaseAdapter { - private List views = null; - - /** - * Constructor creating an empty list of views, but with - * a specified count. Subclasses must override newView(). - */ - public SackOfViewsAdapter(int count) { - super(); - - views = new ArrayList(count); - - for (int i = 0; i < count; i++) { - views.add(null); - } - } - - /** - * Constructor wrapping a supplied list of views. - * Subclasses must override newView() if any of the elements - * in the list are null. - */ - public SackOfViewsAdapter(List views) { - for (View view : views) { - view.setLayoutParams(new ListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - } - this.views = views; - } - - /** - * Get the data item associated with the specified - * position in the data set. - * - * @param position Position of the item whose data we want - */ - @Override - public Object getItem(int position) { - return (views.get(position)); - } - - /** - * How many items are in the data set represented by this - * Adapter. - */ - @Override - public int getCount() { - return (views.size()); - } - - /** - * Returns the number of types of Views that will be - * created by getView(). - */ - @Override - public int getViewTypeCount() { - return (getCount()); - } - - /** - * Get the type of View that will be created by getView() - * for the specified item. - * - * @param position Position of the item whose data we want - */ - @Override - public int getItemViewType(int position) { - return (position); - } - - /** - * Are all items in this ListAdapter enabled? If yes it - * means all items are selectable and clickable. - */ - @Override - public boolean areAllItemsEnabled() { - return (false); - } - - /** - * Returns true if the item at the specified position is - * not a separator. - * - * @param position Position of the item whose data we want - */ - @Override - public boolean isEnabled(int position) { - return (false); - } - - /** - * Get a View that displays the data at the specified - * position in the data set. - * - * @param position Position of the item whose data we want - * @param convertView View to recycle, if not null - * @param parent ViewGroup containing the returned View - */ - @Override - public View getView(int position, View convertView, - ViewGroup parent) { - View result = views.get(position); - - if (result == null) { - result = newView(position, parent); - views.set(position, result); - } - - return (result); - } - - /** - * Get the row id associated with the specified position - * in the list. - * - * @param position Position of the item whose data we want - */ - @Override - public long getItemId(int position) { - return (position); - } - - /** - * Create a new View to go into the list at the specified - * position. - * - * @param position Position of the item whose data we want - * @param parent ViewGroup containing the returned View - */ - protected View newView(int position, ViewGroup parent) { - throw new RuntimeException("You must override newView()!"); - } -} diff --git a/src/github/daneren2005/dsub/view/SettingsAdapter.java b/src/github/daneren2005/dsub/view/SettingsAdapter.java deleted file mode 100644 index ce6c12ed..00000000 --- a/src/github/daneren2005/dsub/view/SettingsAdapter.java +++ /dev/null @@ -1,58 +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 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.R; -import github.daneren2005.dsub.domain.User; - -import static github.daneren2005.dsub.domain.User.Setting; - -public class SettingsAdapter extends ArrayAdapter { - private final Context context; - private final boolean editable; - - public SettingsAdapter(Context context, User user, boolean editable) { - super(context, R.layout.basic_list_item, user.getSettings()); - this.context = context; - this.editable = editable; - } - - public SettingsAdapter(Context context, List settings, boolean editable) { - super(context, R.layout.basic_list_item, settings); - this.context = context; - this.editable = editable; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - Setting entry = getItem(position); - SettingView view; - if (convertView != null && convertView instanceof SettingView) { - view = (SettingView) convertView; - } else { - view = new SettingView(context); - } - view.setObject(entry, editable); - return view; - } -} diff --git a/src/github/daneren2005/dsub/view/ShareAdapter.java b/src/github/daneren2005/dsub/view/ShareAdapter.java deleted file mode 100644 index 362e1c83..00000000 --- a/src/github/daneren2005/dsub/view/ShareAdapter.java +++ /dev/null @@ -1,55 +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 2010 (C) Sindre Mehus - */ -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.Share; - -/** - * @author Sindre Mehus -*/ -public class ShareAdapter extends ArrayAdapter{ - private Context activity; - private List shares; - - public ShareAdapter(Context context, List shares) { - super(context, android.R.layout.simple_list_item_1, shares); - this.activity = context; - this.shares = shares; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - Share share = shares.get(position); - ShareView view; - if (convertView != null && convertView instanceof ShareView) { - view = (ShareView) convertView; - } else { - view = new ShareView(activity); - } - view.setObject(share); - return view; - } -} diff --git a/src/github/daneren2005/dsub/view/UserAdapter.java b/src/github/daneren2005/dsub/view/UserAdapter.java deleted file mode 100644 index 70a1748a..00000000 --- a/src/github/daneren2005/dsub/view/UserAdapter.java +++ /dev/null @@ -1,51 +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 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.R; -import github.daneren2005.dsub.domain.User; -import github.daneren2005.dsub.util.ImageLoader; - -public class UserAdapter extends ArrayAdapter { - private final Context activity; - private final ImageLoader imageLoader; - - public UserAdapter(Context activity, List users, ImageLoader imageLoader) { - super(activity, R.layout.basic_list_item, users); - this.activity = activity; - this.imageLoader = imageLoader; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - User entry = getItem(position); - UserView view; - if (convertView != null && convertView instanceof UserView) { - view = (UserView) convertView; - } else { - view = new UserView(activity); - } - view.setObject(entry, imageLoader); - return view; - } -} \ No newline at end of file -- cgit v1.2.3