All smart playlists are working now.
This commit is contained in:
parent
a95e71c52c
commit
50f73c1dde
19 changed files with 1019 additions and 271 deletions
|
|
@ -438,6 +438,9 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
|||
@Override
|
||||
public void onBackPressed() {
|
||||
if (cab != null && cab.isActive()) cab.finish();
|
||||
else super.onBackPressed();
|
||||
else {
|
||||
recyclerView.stopScroll();
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ import butterknife.InjectView;
|
|||
|
||||
/**
|
||||
* A lot of hackery is done in this activity. Changing things may will brake the whole activity.
|
||||
* <p>
|
||||
* <p/>
|
||||
* Should be kinda stable ONLY AS IT IS!!!
|
||||
*/
|
||||
public class ArtistDetailActivity extends AbsFabActivity implements PaletteColorHolder, CabHolder {
|
||||
|
|
@ -423,6 +423,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
|||
super.enableViews();
|
||||
songListView.setEnabled(true);
|
||||
toolbar.setEnabled(true);
|
||||
albumRecyclerView.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -430,6 +431,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
|||
super.disableViews();
|
||||
songListView.setEnabled(false);
|
||||
toolbar.setEnabled(false);
|
||||
albumRecyclerView.setEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -524,6 +526,9 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
|||
@Override
|
||||
public void onBackPressed() {
|
||||
if (cab != null && cab.isActive()) cab.finish();
|
||||
else super.onBackPressed();
|
||||
else {
|
||||
albumRecyclerView.stopScroll();
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,17 +7,21 @@ import android.support.v7.widget.Toolbar;
|
|||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.afollestad.materialcab.MaterialCab;
|
||||
import com.kabouzeid.gramophone.App;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.songadapter.AbsPlaylistSongAdapter;
|
||||
import com.kabouzeid.gramophone.adapter.songadapter.PlaylistSongAdapter;
|
||||
import com.kabouzeid.gramophone.adapter.songadapter.smartplaylist.SmartPlaylistSongAdapter;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.loader.PlaylistSongLoader;
|
||||
import com.kabouzeid.gramophone.misc.DragSortRecycler;
|
||||
import com.kabouzeid.gramophone.model.DataBaseChangedEvent;
|
||||
import com.kabouzeid.gramophone.model.Playlist;
|
||||
import com.kabouzeid.gramophone.model.PlaylistSong;
|
||||
import com.kabouzeid.gramophone.model.smartplaylist.SmartPlaylist;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsFabActivity;
|
||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||
import com.kabouzeid.gramophone.util.PlaylistsUtil;
|
||||
|
|
@ -26,56 +30,40 @@ import com.squareup.otto.Subscribe;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
|
||||
public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder {
|
||||
|
||||
public static final String TAG = PlaylistDetailActivity.class.getSimpleName();
|
||||
|
||||
public static String EXTRA_PLAYLIST = "extra_playlist";
|
||||
|
||||
@InjectView(R.id.recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
@InjectView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
@InjectView(android.R.id.empty)
|
||||
TextView empty;
|
||||
|
||||
private Playlist playlist;
|
||||
private MaterialCab cab;
|
||||
private PlaylistSongAdapter adapter;
|
||||
private AbsPlaylistSongAdapter adapter;
|
||||
private ArrayList<PlaylistSong> songs;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_playlist_detail);
|
||||
ButterKnife.inject(this);
|
||||
|
||||
getIntentExtras();
|
||||
|
||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
||||
songs = PlaylistSongLoader.getPlaylistSongList(this, playlist.id);
|
||||
adapter = new PlaylistSongAdapter(this, songs, this);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 1));
|
||||
recyclerView.setAdapter(adapter);
|
||||
setUpRecyclerView();
|
||||
|
||||
findViewById(android.R.id.empty).setVisibility(
|
||||
songs.size() == 0 ? View.VISIBLE : View.GONE
|
||||
);
|
||||
checkIsEmpty();
|
||||
|
||||
DragSortRecycler dragSortRecycler = new DragSortRecycler();
|
||||
dragSortRecycler.setViewHandleId(R.id.album_art);
|
||||
|
||||
dragSortRecycler.setOnItemMovedListener(new DragSortRecycler.OnItemMovedListener() {
|
||||
@Override
|
||||
public void onItemMoved(int from, int to) {
|
||||
PlaylistSong song = songs.remove(from);
|
||||
songs.add(to, song);
|
||||
adapter.notifyDataSetChanged();
|
||||
PlaylistsUtil.moveItem(PlaylistDetailActivity.this, playlist.id, from, to);
|
||||
}
|
||||
});
|
||||
|
||||
recyclerView.addItemDecoration(dragSortRecycler);
|
||||
recyclerView.addOnItemTouchListener(dragSortRecycler);
|
||||
recyclerView.setOnScrollListener(dragSortRecycler.getScrollListener());
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
toolbar.setBackgroundColor(PreferenceUtils.getInstance(this).getThemeColorPrimary());
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setTitle(playlist.name);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
setUpToolBar();
|
||||
|
||||
if (PreferenceUtils.getInstance(this).coloredNavigationBarPlaylist())
|
||||
setNavigationBarThemeColor();
|
||||
|
|
@ -84,6 +72,41 @@ public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder
|
|||
App.bus.register(this);
|
||||
}
|
||||
|
||||
private void setUpRecyclerView() {
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 1));
|
||||
if (playlist instanceof SmartPlaylist) {
|
||||
adapter = ((SmartPlaylist) playlist).createAdapter(this, this);
|
||||
} else {
|
||||
songs = PlaylistSongLoader.getPlaylistSongList(this, playlist.id);
|
||||
adapter = new PlaylistSongAdapter(this, songs, this);
|
||||
|
||||
DragSortRecycler dragSortRecycler = new DragSortRecycler();
|
||||
dragSortRecycler.setViewHandleId(R.id.album_art);
|
||||
dragSortRecycler.setOnItemMovedListener(new DragSortRecycler.OnItemMovedListener() {
|
||||
@Override
|
||||
public void onItemMoved(int from, int to) {
|
||||
PlaylistSong song = songs.remove(from);
|
||||
songs.add(to, song);
|
||||
adapter.notifyDataSetChanged();
|
||||
PlaylistsUtil.moveItem(PlaylistDetailActivity.this, playlist.id, from, to);
|
||||
}
|
||||
});
|
||||
|
||||
recyclerView.addItemDecoration(dragSortRecycler);
|
||||
recyclerView.addOnItemTouchListener(dragSortRecycler);
|
||||
recyclerView.setOnScrollListener(dragSortRecycler.getScrollListener());
|
||||
}
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private void setUpToolBar() {
|
||||
toolbar.setBackgroundColor(getThemeColorPrimary());
|
||||
setSupportActionBar(toolbar);
|
||||
//noinspection ConstantConditions
|
||||
getSupportActionBar().setTitle(playlist.name);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
private void getIntentExtras() {
|
||||
Bundle intentExtras = getIntent().getExtras();
|
||||
try {
|
||||
|
|
@ -114,7 +137,7 @@ public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder
|
|||
NavigationUtil.openEqualizer(this);
|
||||
return true;
|
||||
case android.R.id.home:
|
||||
super.onBackPressed();
|
||||
onBackPressed();
|
||||
return true;
|
||||
case R.id.action_current_playing:
|
||||
NavigationUtil.openCurrentPlayingIfPossible(this, getSharedViewsWithFab(null));
|
||||
|
|
@ -147,11 +170,14 @@ public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder
|
|||
switch (event.getAction()) {
|
||||
case DataBaseChangedEvent.PLAYLISTS_CHANGED:
|
||||
case DataBaseChangedEvent.DATABASE_CHANGED:
|
||||
songs = PlaylistSongLoader.getPlaylistSongList(this, playlist.id);
|
||||
adapter.updateDataSet(songs);
|
||||
findViewById(android.R.id.empty).setVisibility(
|
||||
songs.size() == 0 ? View.VISIBLE : View.GONE
|
||||
);
|
||||
if (adapter instanceof SmartPlaylistSongAdapter) {
|
||||
((SmartPlaylistSongAdapter) adapter).updateDataSet();
|
||||
} else {
|
||||
songs = PlaylistSongLoader.getPlaylistSongList(this, playlist.id);
|
||||
//noinspection unchecked
|
||||
adapter.updateDataSet(songs);
|
||||
}
|
||||
checkIsEmpty();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -159,6 +185,15 @@ public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder
|
|||
@Override
|
||||
public void onBackPressed() {
|
||||
if (cab != null && cab.isActive()) cab.finish();
|
||||
else super.onBackPressed();
|
||||
else {
|
||||
recyclerView.stopScroll();
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIsEmpty() {
|
||||
empty.setVisibility(
|
||||
adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,158 +0,0 @@
|
|||
package com.kabouzeid.gramophone.ui.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.afollestad.materialcab.MaterialCab;
|
||||
import com.kabouzeid.gramophone.App;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.songadapter.smartplaylist.SmartPlaylistSongAdapter;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.model.DataBaseChangedEvent;
|
||||
import com.kabouzeid.gramophone.model.smartplaylist.SmartPlaylist;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsFabActivity;
|
||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
|
||||
public class SmartPlaylistDetailActivity extends AbsFabActivity implements CabHolder {
|
||||
|
||||
public static final String TAG = SmartPlaylistDetailActivity.class.getSimpleName();
|
||||
|
||||
@InjectView(R.id.recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
@InjectView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
@InjectView(android.R.id.empty)
|
||||
TextView empty;
|
||||
|
||||
private SmartPlaylist playlist;
|
||||
private MaterialCab cab;
|
||||
private SmartPlaylistSongAdapter adapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_playlist_detail);
|
||||
ButterKnife.inject(this);
|
||||
|
||||
getIntentExtras();
|
||||
|
||||
setUpRecyclerView();
|
||||
|
||||
checkIsEmpty();
|
||||
|
||||
setUpToolBar();
|
||||
|
||||
if (PreferenceUtils.getInstance(this).coloredNavigationBarPlaylist())
|
||||
setNavigationBarThemeColor();
|
||||
setStatusBarThemeColor();
|
||||
|
||||
App.bus.register(this);
|
||||
}
|
||||
|
||||
private void setUpRecyclerView() {
|
||||
adapter = playlist.createAdapter(this, this);
|
||||
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 1));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private void setUpToolBar() {
|
||||
toolbar.setBackgroundColor(getThemeColorPrimary());
|
||||
setSupportActionBar(toolbar);
|
||||
//noinspection ConstantConditions
|
||||
getSupportActionBar().setTitle(playlist.name);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
private void getIntentExtras() {
|
||||
Bundle intentExtras = getIntent().getExtras();
|
||||
try {
|
||||
playlist = (SmartPlaylist) intentExtras.getSerializable(PlaylistDetailActivity.EXTRA_PLAYLIST);
|
||||
} catch (ClassCastException ignored) {
|
||||
}
|
||||
if (playlist == null) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_playlist_detail, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_equalizer:
|
||||
NavigationUtil.openEqualizer(this);
|
||||
return true;
|
||||
case android.R.id.home:
|
||||
super.onBackPressed();
|
||||
return true;
|
||||
case R.id.action_current_playing:
|
||||
NavigationUtil.openCurrentPlayingIfPossible(this, getSharedViewsWithFab(null));
|
||||
return true;
|
||||
case R.id.action_playing_queue:
|
||||
NavigationUtil.openPlayingQueueDialog(this);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialCab openCab(final int menu, final MaterialCab.Callback callback) {
|
||||
if (cab != null && cab.isActive()) cab.finish();
|
||||
cab = new MaterialCab(this, R.id.cab_stub)
|
||||
.setMenu(menu)
|
||||
.setBackgroundColor(PreferenceUtils.getInstance(this).getThemeColorPrimary())
|
||||
.start(callback);
|
||||
return cab;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
App.bus.unregister(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onDataBaseEvent(DataBaseChangedEvent event) {
|
||||
switch (event.getAction()) {
|
||||
case DataBaseChangedEvent.PLAYLISTS_CHANGED:
|
||||
case DataBaseChangedEvent.DATABASE_CHANGED:
|
||||
adapter.updateDataSet();
|
||||
checkIsEmpty();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (cab != null && cab.isActive()) cab.finish();
|
||||
else super.onBackPressed();
|
||||
}
|
||||
|
||||
private void checkIsEmpty() {
|
||||
empty.setVisibility(
|
||||
adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.design.widget.AppBarLayout.OnOffsetChangedListener;
|
||||
|
|
@ -29,9 +30,11 @@ public abstract class AbsMainActivityRecyclerViewFragment extends AbsMainActivit
|
|||
|
||||
@InjectView(R.id.recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
@Nullable
|
||||
@Optional
|
||||
@InjectView(android.R.id.empty)
|
||||
TextView empty;
|
||||
@Nullable
|
||||
@Optional
|
||||
@InjectView(R.id.fast_scroller)
|
||||
FastScroller fastScroller;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue