From f47da3c25f2ee0d4f74392a0a7e4a570cc121516 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 8 Jun 2015 17:55:06 -0700 Subject: #232 Switch NowPlayingFragment to RecyclerView, add swipe to remove and better drag + drop support --- .../dsub/activity/SubsonicFragmentActivity.java | 25 ++-- .../dsub/adapter/DownloadFileAdapter.java | 37 +++-- .../daneren2005/dsub/adapter/SectionAdapter.java | 17 +++ .../dsub/fragments/DownloadFragment.java | 25 ++-- .../dsub/fragments/NowPlayingFragment.java | 140 ++++++++++-------- .../dsub/fragments/SelectListFragment.java | 163 --------------------- .../daneren2005/dsub/service/DownloadService.java | 7 + app/src/main/res/layout/download_playlist.xml | 33 ++--- app/src/main/res/values/styles.xml | 17 --- 9 files changed, 166 insertions(+), 298 deletions(-) delete mode 100644 app/src/main/java/github/daneren2005/dsub/fragments/SelectListFragment.java (limited to 'app/src') diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index 774a8def..92e711a3 100644 --- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -565,19 +565,22 @@ public class SubsonicFragmentActivity extends SubsonicActivity { artistView.setText(R.string.main_artist); } - SilentBackgroundTask task = getImageLoader().loadImage(coverArtView, song, false, coverArtView.getHeight(), false); - if(slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) { - if(task == null) { - getSupportActionBar().setHomeAsUpIndicator(coverArtView.getDrawable()); - } else { - task.setOnCompletionListener(new Runnable() { - @Override - public void run() { - getSupportActionBar().setHomeAsUpIndicator(coverArtView.getDrawable()); - } - }); + if(coverArtView.getHeight() > 0 ) { + SilentBackgroundTask task = getImageLoader().loadImage(coverArtView, song, false, coverArtView.getHeight(), false); + if (slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) { + if (task == null) { + getSupportActionBar().setHomeAsUpIndicator(coverArtView.getDrawable()); + } else { + task.setOnCompletionListener(new Runnable() { + @Override + public void run() { + getSupportActionBar().setHomeAsUpIndicator(coverArtView.getDrawable()); + } + }); + } } } + int[] attrs = new int[] {(state == PlayerState.STARTED) ? R.attr.media_button_pause : R.attr.media_button_start}; TypedArray typedArray = this.obtainStyledAttributes(attrs); startButton.setImageResource(typedArray.getResourceId(0, 0)); diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/DownloadFileAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/DownloadFileAdapter.java index be9b4cb9..7e926d51 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/DownloadFileAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/DownloadFileAdapter.java @@ -24,26 +24,33 @@ import java.util.List; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.view.SongView; +import github.daneren2005.dsub.view.UpdateView; -public class DownloadFileAdapter extends ArrayAdapter { - Context context; +public class DownloadFileAdapter extends SectionAdapter { + public static int VIEW_TYPE_DOWNLOAD_FILE = 1; public DownloadFileAdapter(Context context, List entries) { - super(context, android.R.layout.simple_list_item_1, entries); - this.context = context; + super(context, entries); + } + public DownloadFileAdapter(Context context, List entries, OnItemClickedListener onItemClickedListener) { + super(context, entries); + this.onItemClickedListener = onItemClickedListener; + } + + @Override + public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) { + return new UpdateView.UpdateViewHolder(new SongView(context)); + } + + @Override + public void onBindViewHolder(UpdateView.UpdateViewHolder holder, DownloadFile item, int viewType) { + SongView songView = (SongView) holder.getUpdateView(); + songView.setObject(item.getSong(), false); + songView.setDownloadFile(item); } @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; + public int getItemViewType(DownloadFile item) { + return VIEW_TYPE_DOWNLOAD_FILE; } } diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java index 8d9a8682..599870d7 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java @@ -224,6 +224,23 @@ public abstract class SectionAdapter extends RecyclerView.Adapter section: sections) { + subPosition += section.size() + 1; + + int position = section.indexOf(item); + if(position != -1) { + return position + subPosition; + } + } + + return -1; + } public void setContextItem(UpdateView updateView, T item) { contextView = updateView; diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java index 59229c3f..5a3d63ad 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -30,6 +30,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import github.daneren2005.dsub.R; +import github.daneren2005.dsub.adapter.SectionAdapter; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.DownloadService; @@ -38,13 +39,15 @@ import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.adapter.DownloadFileAdapter; +import github.daneren2005.dsub.view.UpdateView; -public class DownloadFragment extends SelectListFragment { +public class DownloadFragment extends SelectRecyclerFragment { private long currentRevision; private ScheduledExecutorService executorService; public DownloadFragment() { serialize = false; + pullToRefresh = false; } @Override @@ -80,7 +83,7 @@ public class DownloadFragment extends SelectListFragment { } @Override - public ArrayAdapter getAdapter(List objs) { + public SectionAdapter getAdapter(List objs) { return new DownloadFileAdapter(context, objs); } @@ -91,9 +94,6 @@ public class DownloadFragment extends SelectListFragment { return new ArrayList(); } - listView.setOnScrollListener(null); - refreshLayout.setEnabled(false); - List songList = new ArrayList(); songList.addAll(downloadService.getBackgroundDownloads()); currentRevision = downloadService.getDownloadListUpdateRevision(); @@ -106,7 +106,7 @@ public class DownloadFragment extends SelectListFragment { } @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { + public void onItemClicked(DownloadFile item) { } @@ -144,11 +144,13 @@ public class DownloadFragment extends SelectListFragment { @Override public void onCreateContextMenu(android.view.ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); + UpdateView targetView = adapter.getContextView(); + menuInfo = new AdapterView.AdapterContextMenuInfo(targetView, 0, 0); - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; - Object selectedItem = ((DownloadFile) listView.getItemAtPosition(info.position)).getSong(); + DownloadFile downloadFile = adapter.getContextItem(); + MusicDirectory.Entry selectedItem = downloadFile.getSong(); onCreateContextMenu(menu, view, menuInfo, selectedItem); - if(selectedItem instanceof MusicDirectory.Entry && !((MusicDirectory.Entry) selectedItem).isVideo() && !Util.isOffline(context)) { + if(!selectedItem.isVideo() && !Util.isOffline(context)) { menu.removeItem(R.id.song_menu_remove_playlist); } @@ -161,9 +163,8 @@ public class DownloadFragment extends SelectListFragment { return false; } - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - Object selectedItem = ((DownloadFile) listView.getItemAtPosition(info.position)).getSong(); - + DownloadFile downloadFile = adapter.getContextItem(); + MusicDirectory.Entry selectedItem = downloadFile.getSong(); if(onContextItemSelected(menuItem, selectedItem)) { return true; } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java index 6f325a4e..cbceccbe 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -31,6 +31,9 @@ import android.os.Bundle; import android.os.Handler; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.MediaRouteButton; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.helper.ItemTouchHelper; import android.util.Log; import android.view.ContextMenu; import android.view.Display; @@ -55,6 +58,7 @@ import android.widget.TextView; import android.widget.ViewFlipper; import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.SubsonicFragmentActivity; +import github.daneren2005.dsub.adapter.SectionAdapter; import github.daneren2005.dsub.audiofx.EqualizerController; import github.daneren2005.dsub.domain.Bookmark; import github.daneren2005.dsub.domain.PlayerState; @@ -70,6 +74,7 @@ import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.adapter.DownloadFileAdapter; import github.daneren2005.dsub.view.FadeOutAnimation; +import github.daneren2005.dsub.view.SongView; import github.daneren2005.dsub.view.UpdateView; import github.daneren2005.dsub.util.Util; @@ -79,10 +84,9 @@ import github.daneren2005.dsub.util.*; import github.daneren2005.dsub.view.AutoRepeatButton; import java.util.ArrayList; import java.util.concurrent.ScheduledFuture; -import com.mobeta.android.dslv.*; import github.daneren2005.dsub.activity.SubsonicActivity; -public class NowPlayingFragment extends SubsonicFragment implements OnGestureListener { +public class NowPlayingFragment extends SubsonicFragment implements OnGestureListener, SectionAdapter.OnItemClickedListener { private static final String TAG = NowPlayingFragment.class.getSimpleName(); private static final int PERCENTAGE_OF_SCREEN_FOR_SWIPE = 10; private static final int INCREMENT_TIME = 5000; @@ -97,7 +101,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis private TextView emptyTextView; private TextView songTitleTextView; private ImageView albumArtImageView; - private DragSortListView playlistView; + private RecyclerView playlistView; private TextView positionTextView; private TextView durationTextView; private TextView statusTextView; @@ -172,7 +176,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis durationTextView = (TextView)rootView.findViewById(R.id.download_duration); statusTextView = (TextView)rootView.findViewById(R.id.download_status); progressBar = (SeekBar)rootView.findViewById(R.id.download_progress_bar); - playlistView = (DragSortListView)rootView.findViewById(R.id.download_list); previousButton = (AutoRepeatButton)rootView.findViewById(R.id.download_previous); nextButton = (AutoRepeatButton)rootView.findViewById(R.id.download_next); pauseButton =rootView.findViewById(R.id.download_pause); @@ -184,6 +187,45 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis rateGoodButton = (ImageButton) rootView.findViewById(R.id.download_rating_good); toggleListButton =rootView.findViewById(R.id.download_toggle_list); + playlistView = (RecyclerView)rootView.findViewById(R.id.download_list); + setupLayoutManager(playlistView, false); + ItemTouchHelper touchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT) { + @Override + public boolean onMove(RecyclerView recyclerView, final RecyclerView.ViewHolder fromHolder, final RecyclerView.ViewHolder toHolder) { + new SilentBackgroundTask(context) { + private int from; + private int to; + + @Override + protected Void doInBackground() throws Throwable { + from = fromHolder.getAdapterPosition(); + to = toHolder.getAdapterPosition(); + getDownloadService().swap(true, from, to); + return null; + } + + @Override + protected void done(Void result) { + songListAdapter.notifyItemMoved(from, to); + } + }.execute(); + + return true; + } + + @Override + public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { + SongView songView = (SongView) ((UpdateView.UpdateViewHolder) viewHolder).getUpdateView(); + DownloadFile downloadFile = songView.getDownloadFile(); + + DownloadService downloadService = getDownloadService(); + downloadService.remove(downloadFile); + songListAdapter.removeItem(downloadFile); + currentRevision = downloadService.getDownloadListUpdateRevision(); + } + }); + touchHelper.attachToRecyclerView(playlistView); + starButton = (ImageButton)rootView.findViewById(R.id.download_star); if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true)) { starButton.setOnClickListener(new OnClickListener() { @@ -499,47 +541,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis } } }); - playlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, final int position, long id) { - warnIfStorageUnavailable(); - new SilentBackgroundTask(context) { - @Override - protected Void doInBackground() throws Throwable { - getDownloadService().play(position); - return null; - } - - @Override - protected void done(Void result) { - onCurrentChanged(); - onProgressChanged(); - } - }.execute(); - } - }); - playlistView.setDropListener(new DragSortListView.DropListener() { - @Override - public void drop(final int from, final int to) { - new SilentBackgroundTask(context) { - @Override - protected Void doInBackground() throws Throwable { - getDownloadService().swap(true, from, to); - onDownloadListChanged(); - - return null; - } - }.execute(); - } - }); - playlistView.setRemoveListener(new DragSortListView.RemoveListener() { - @Override - public void remove(int which) { - getDownloadService().remove(which); - onDownloadListChanged(); - } - }); - registerForContextMenu(playlistView); if(Build.MODEL.equals("Nexus 4") || Build.MODEL.equals("GT-I9100")) { @@ -605,10 +606,11 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis if(!primaryFragment) { return; } + UpdateView targetView = songListAdapter.getContextView(); + menuInfo = new AdapterView.AdapterContextMenuInfo(targetView, 0, 0); if (view == playlistView) { - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; - DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position); + DownloadFile downloadFile = songListAdapter.getContextItem(); android.view.MenuInflater inflater = context.getMenuInflater(); if(Util.isOffline(context)) { @@ -633,8 +635,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis return false; } - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position); + DownloadFile downloadFile = songListAdapter.getContextItem(); return menuItemSelected(menuItem.getItemId(), downloadFile) || super.onContextItemSelected(menuItem); } @@ -996,18 +997,18 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis return; } - for (int i = 0; i < songListAdapter.getCount(); i++) { - if (currentPlaying == playlistView.getItemAtPosition(i)) { - playlistView.setSelectionFromTop(i, 40); - return; - } + // Try to get position of current playing/downloading + int position = songListAdapter.getItemPosition(currentPlaying); + if(position == -1) { + DownloadFile currentDownloading = getDownloadService().getCurrentDownloading(); + position = songListAdapter.getItemPosition(currentDownloading); } - DownloadFile currentDownloading = getDownloadService().getCurrentDownloading(); - for (int i = 0; i < songListAdapter.getCount(); i++) { - if (currentDownloading == playlistView.getItemAtPosition(i)) { - playlistView.setSelectionFromTop(i, 40); - return; - } + + // If found, scroll to it + if(position != -1) { + // RecyclerView.scrollToPosition just puts it on the screen (ie: bottom if scrolled below it) + LinearLayoutManager layoutManager = (LinearLayoutManager) playlistView.getLayoutManager(); + layoutManager.scrollToPositionWithOffset(position, 0); } } @@ -1161,9 +1162,9 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis } if(songListAdapter == null || refresh) { - songList = new ArrayList(); + songList = new ArrayList<>(); songList.addAll(list); - playlistView.setAdapter(songListAdapter = new DownloadFileAdapter(context, songList)); + playlistView.setAdapter(songListAdapter = new DownloadFileAdapter(context, songList, NowPlayingFragment.this)); } else { songList.clear(); songList.addAll(list); @@ -1589,4 +1590,19 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis public boolean onSingleTapUp(MotionEvent e) { return false; } + + @Override + public void onItemClicked(final DownloadFile item) { + warnIfStorageUnavailable(); + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + getDownloadService().play(item); + + onCurrentChanged(); + onProgressChanged(); + return null; + } + }.execute(); + } } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectListFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectListFragment.java deleted file mode 100644 index 6f73f6e8..00000000 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectListFragment.java +++ /dev/null @@ -1,163 +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.fragments; - -import android.os.Bundle; -import android.support.v4.widget.SwipeRefreshLayout; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.ListView; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.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; - -public abstract class SelectListFragment extends SubsonicFragment implements AdapterView.OnItemClickListener { - private static final String TAG = SelectListFragment.class.getSimpleName(); - protected ListView listView; - protected ArrayAdapter adapter; - protected BackgroundTask> currentTask; - protected List objects; - protected boolean serialize = true; - - @Override - public void onCreate(Bundle bundle) { - super.onCreate(bundle); - - if(bundle != null && serialize) { - objects = (List) bundle.getSerializable(Constants.FRAGMENT_LIST); - } - } - - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - if(serialize) { - outState.putSerializable(Constants.FRAGMENT_LIST, (Serializable) objects); - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { - rootView = inflater.inflate(R.layout.abstract_list_fragment, container, false); - - refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout); - refreshLayout.setOnRefreshListener(this); - - listView = (ListView)rootView.findViewById(R.id.fragment_list); - listView.setOnItemClickListener(this); - setupScrollList(listView); - registerForContextMenu(listView); - - if(objects == null) { - refresh(false); - } else { - listView.setAdapter(adapter = getAdapter(objects)); - } - - return rootView; - } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { - if(!primaryFragment) { - return; - } - - menuInflater.inflate(getOptionsMenu(), menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - return super.onOptionsItemSelected(item); - } - - @Override - protected void refresh(final boolean refresh) { - int titleRes = getTitleResource(); - if(titleRes != 0) { - setTitle(getTitleResource()); - } - listView.setVisibility(View.GONE); - - // Cancel current running task before starting another one - if(currentTask != null) { - currentTask.cancel(); - } - - currentTask = new TabBackgroundTask>(this) { - @Override - protected List doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(context); - - objects = new ArrayList(); - - try { - objects = getObjects(musicService, refresh, this); - } catch (Exception x) { - Log.e(TAG, "Failed to load", x); - } - - return objects; - } - - @Override - protected void done(List result) { - if (result != null && !result.isEmpty()) { - // Toggle fast scroll to get around issue when length of list changes - listView.setFastScrollEnabled(false); - listView.setAdapter(adapter = getAdapter(result)); - listView.setFastScrollEnabled(true); - - onFinishRefresh(); - listView.setVisibility(View.VISIBLE); - } else { - setEmpty(true); - } - - currentTask = null; - } - }; - currentTask.execute(); - } - - public abstract int getOptionsMenu(); - public abstract ArrayAdapter getAdapter(List objs); - public abstract List getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception; - public abstract int getTitleResource(); - - public void onFinishRefresh() { - - } -} diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java index c1f8870e..0a542689 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -870,6 +870,9 @@ public class DownloadService extends Service { public synchronized void play(int index) { play(index, true); } + public synchronized void play(DownloadFile downloadFile) { + play(downloadList.indexOf(downloadFile)); + } private synchronized void play(int index, boolean start) { play(index, start, 0); } @@ -1802,6 +1805,10 @@ public class DownloadService extends Service { applyReplayGain(mediaPlayer, currentPlaying); } + public synchronized void swap(boolean mainList, DownloadFile from, DownloadFile to) { + List list = mainList ? downloadList : backgroundDownloadList; + swap(mainList, list.indexOf(from), list.indexOf(to)); + } public synchronized void swap(boolean mainList, int from, int to) { List list = mainList ? downloadList : backgroundDownloadList; int max = list.size(); diff --git a/app/src/main/res/layout/download_playlist.xml b/app/src/main/res/layout/download_playlist.xml index 8a73ef3b..afb46081 100644 --- a/app/src/main/res/layout/download_playlist.xml +++ b/app/src/main/res/layout/download_playlist.xml @@ -1,31 +1,28 @@ - + xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:layout_weight="1"> + android:layout_width="fill_parent" + android:layout_height="1px" + android:background="@color/dividerColor"/> + android:id="@+id/download_empty" + android:text="@string/download.empty" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:padding="10dip"/> - + android:scrollbars="vertical"/> \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c4a53b99..cfe446f3 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -59,23 +59,6 @@ 16dip - -