Changed the way to check if a view is empty, fixed some strings, fixed fastscroller alignment.
This commit is contained in:
parent
450aca9149
commit
8ba0c72037
43 changed files with 185 additions and 204 deletions
|
|
@ -1,11 +1,13 @@
|
|||
package com.kabouzeid.gramophone.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.afollestad.materialcab.MaterialCab;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -18,11 +20,13 @@ public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder,
|
|||
private MaterialCab cab;
|
||||
private ArrayList<I> checked;
|
||||
private int menuRes;
|
||||
private final Context context;
|
||||
|
||||
public AbsMultiSelectAdapter(@Nullable CabHolder cabHolder, int menuRes) {
|
||||
public AbsMultiSelectAdapter(Context context, @Nullable CabHolder cabHolder, int menuRes) {
|
||||
this.cabHolder = cabHolder;
|
||||
checked = new ArrayList<>();
|
||||
this.menuRes = menuRes;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
protected void toggleChecked(final int position) {
|
||||
|
|
@ -36,7 +40,7 @@ public abstract class AbsMultiSelectAdapter<VH extends RecyclerView.ViewHolder,
|
|||
final int size = checked.size();
|
||||
if (size <= 0) cab.finish();
|
||||
else if (size == 1) cab.setTitle(checked.get(0).toString());
|
||||
else if (size > 1) cab.setTitle(String.valueOf(size));
|
||||
else if (size > 1) cab.setTitle(context.getString(R.string.x_selected, size));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,6 @@ import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
|||
import com.kabouzeid.gramophone.dialogs.DeleteSongsDialog;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.interfaces.OnUpdatedListener;
|
||||
import com.kabouzeid.gramophone.interfaces.SelfUpdating;
|
||||
import com.kabouzeid.gramophone.loader.AlbumLoader;
|
||||
import com.kabouzeid.gramophone.loader.AlbumSongLoader;
|
||||
import com.kabouzeid.gramophone.model.Album;
|
||||
|
|
@ -49,13 +47,12 @@ import java.util.List;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder, Album> implements SelfUpdating {
|
||||
public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder, Album> {
|
||||
|
||||
public static final String TAG = AlbumAdapter.class.getSimpleName();
|
||||
private final AppCompatActivity activity;
|
||||
private boolean usePalette;
|
||||
private List<Album> dataSet;
|
||||
private OnUpdatedListener listener;
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
|
|
@ -133,11 +130,6 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
|||
return songs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnUpdatedListener(OnUpdatedListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
final ImageView albumArt;
|
||||
final TextView title;
|
||||
|
|
@ -193,7 +185,7 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
|||
}
|
||||
|
||||
public AlbumAdapter(AppCompatActivity activity, @Nullable CabHolder cabHolder) {
|
||||
super(cabHolder, R.menu.menu_media_selection);
|
||||
super(activity, cabHolder, R.menu.menu_media_selection);
|
||||
this.activity = activity;
|
||||
usePalette = PreferenceUtils.getInstance(activity).coloredAlbumFootersEnabled();
|
||||
loadDataSet();
|
||||
|
|
@ -201,7 +193,6 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
|||
|
||||
private void loadDataSet() {
|
||||
dataSet = AlbumLoader.getAllAlbums(activity);
|
||||
if (listener != null) listener.onUpdated(this);
|
||||
}
|
||||
|
||||
private void applyPalette(Bitmap bitmap, final TextView title, final TextView artist, final View footer) {
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
|||
import com.kabouzeid.gramophone.dialogs.DeleteSongsDialog;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.interfaces.OnUpdatedListener;
|
||||
import com.kabouzeid.gramophone.interfaces.SelfUpdating;
|
||||
import com.kabouzeid.gramophone.lastfm.artist.LastFMArtistThumbnailUrlLoader;
|
||||
import com.kabouzeid.gramophone.loader.ArtistLoader;
|
||||
import com.kabouzeid.gramophone.loader.ArtistSongLoader;
|
||||
|
|
@ -38,20 +36,18 @@ import java.util.List;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolder, Artist> implements SelfUpdating {
|
||||
public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolder, Artist> {
|
||||
protected final AppCompatActivity activity;
|
||||
protected List<Artist> dataSet;
|
||||
private OnUpdatedListener listener;
|
||||
|
||||
public ArtistAdapter(AppCompatActivity activity, @Nullable CabHolder cabHolder) {
|
||||
super(cabHolder, R.menu.menu_media_selection);
|
||||
super(activity, cabHolder, R.menu.menu_media_selection);
|
||||
this.activity = activity;
|
||||
loadDataSet();
|
||||
}
|
||||
|
||||
private void loadDataSet() {
|
||||
dataSet = ArtistLoader.getAllArtists(activity);
|
||||
if (listener != null) listener.onUpdated(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -116,11 +112,6 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
|||
return songs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnUpdatedListener(OnUpdatedListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
final TextView artistName;
|
||||
final TextView artistInfo;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class ArtistAlbumAdapter extends AbsMultiSelectAdapter<ArtistAlbumAdapter
|
|||
private final int listMargin;
|
||||
|
||||
public ArtistAlbumAdapter(AppCompatActivity activity, ArrayList<Album> objects, @Nullable CabHolder cabHolder) {
|
||||
super(cabHolder, R.menu.menu_media_selection);
|
||||
super(activity, cabHolder, R.menu.menu_media_selection);
|
||||
this.activity = activity;
|
||||
dataSet = objects;
|
||||
listMargin = activity.getResources().getDimensionPixelSize(R.dimen.default_item_margin);
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ import com.kabouzeid.gramophone.dialogs.DeletePlaylistDialog;
|
|||
import com.kabouzeid.gramophone.helper.MenuItemClickHelper;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.interfaces.OnUpdatedListener;
|
||||
import com.kabouzeid.gramophone.interfaces.SelfUpdating;
|
||||
import com.kabouzeid.gramophone.loader.PlaylistLoader;
|
||||
import com.kabouzeid.gramophone.loader.PlaylistSongLoader;
|
||||
import com.kabouzeid.gramophone.model.DataBaseChangedEvent;
|
||||
|
|
@ -35,22 +33,20 @@ import java.util.List;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class PlaylistAdapter extends AbsMultiSelectAdapter<PlaylistAdapter.ViewHolder, Playlist> implements SelfUpdating {
|
||||
public class PlaylistAdapter extends AbsMultiSelectAdapter<PlaylistAdapter.ViewHolder, Playlist> {
|
||||
|
||||
public static final String TAG = PlaylistAdapter.class.getSimpleName();
|
||||
protected final AppCompatActivity activity;
|
||||
protected List<Playlist> dataSet;
|
||||
private OnUpdatedListener listener;
|
||||
|
||||
public PlaylistAdapter(AppCompatActivity activity, @Nullable CabHolder cabHolder) {
|
||||
super(cabHolder, R.menu.menu_playlists_selection);
|
||||
super(activity, cabHolder, R.menu.menu_playlists_selection);
|
||||
this.activity = activity;
|
||||
loadDataSet();
|
||||
}
|
||||
|
||||
public void loadDataSet() {
|
||||
dataSet = PlaylistLoader.getAllPlaylists(activity);
|
||||
if (listener != null) listener.onUpdated(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -99,11 +95,6 @@ public class PlaylistAdapter extends AbsMultiSelectAdapter<PlaylistAdapter.ViewH
|
|||
return songs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnUpdatedListener(OnUpdatedListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
public final TextView playlistName;
|
||||
private final View menu;
|
||||
|
|
|
|||
|
|
@ -72,9 +72,6 @@ public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder
|
|||
results.addAll(albums);
|
||||
}
|
||||
}
|
||||
if (results.isEmpty()) {
|
||||
results.add(activity.getResources().getString(R.string.no_results).toUpperCase());
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class AlbumSongAdapter extends AbsMultiSelectAdapter<AlbumSongAdapter.Vie
|
|||
protected ArrayList<Song> dataSet;
|
||||
|
||||
public AlbumSongAdapter(AppCompatActivity activity, ArrayList<Song> objects, @Nullable CabHolder cabHolder) {
|
||||
super(cabHolder, R.menu.menu_media_selection);
|
||||
super(activity, cabHolder, R.menu.menu_media_selection);
|
||||
this.activity = activity;
|
||||
dataSet = objects;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import android.widget.TextView;
|
|||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.AbsMultiSelectAdapter;
|
||||
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
||||
import com.kabouzeid.gramophone.dialogs.DeleteFromPlaylistDialog;
|
||||
import com.kabouzeid.gramophone.dialogs.RemoveFromPlaylistDialog;
|
||||
import com.kabouzeid.gramophone.helper.MenuItemClickHelper;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
|
|
@ -40,7 +40,7 @@ public class PlaylistSongAdapter extends AbsMultiSelectAdapter<PlaylistSongAdapt
|
|||
protected ArrayList<PlaylistSong> dataSet;
|
||||
|
||||
public PlaylistSongAdapter(AppCompatActivity activity, ArrayList<PlaylistSong> objects, @Nullable CabHolder cabHolder) {
|
||||
super(cabHolder, R.menu.menu_playlists_songs_selection);
|
||||
super(activity, cabHolder, R.menu.menu_playlists_songs_selection);
|
||||
this.activity = activity;
|
||||
dataSet = objects;
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ public class PlaylistSongAdapter extends AbsMultiSelectAdapter<PlaylistSongAdapt
|
|||
protected void onMultipleItemAction(MenuItem menuItem, ArrayList<PlaylistSong> selection) {
|
||||
switch (menuItem.getItemId()) {
|
||||
case R.id.action_delete_from_playlist:
|
||||
DeleteFromPlaylistDialog.create(selection).show(activity.getSupportFragmentManager(), "DELETE_FROM_PLAYLIST");
|
||||
RemoveFromPlaylistDialog.create(selection).show(activity.getSupportFragmentManager(), "DELETE_FROM_PLAYLIST");
|
||||
break;
|
||||
case R.id.action_add_to_playlist:
|
||||
//noinspection unchecked
|
||||
|
|
@ -127,7 +127,7 @@ public class PlaylistSongAdapter extends AbsMultiSelectAdapter<PlaylistSongAdapt
|
|||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_delete_from_playlist:
|
||||
DeleteFromPlaylistDialog.create(dataSet.get(getAdapterPosition())).show(activity.getSupportFragmentManager(), "DELETE_FROM_PLAYLIST");
|
||||
RemoveFromPlaylistDialog.create(dataSet.get(getAdapterPosition())).show(activity.getSupportFragmentManager(), "DELETE_FROM_PLAYLIST");
|
||||
return true;
|
||||
case R.id.action_go_to_album:
|
||||
Pair[] albumPairs = new Pair[]{
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@ import com.kabouzeid.gramophone.dialogs.DeleteSongsDialog;
|
|||
import com.kabouzeid.gramophone.helper.MenuItemClickHelper;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.interfaces.OnUpdatedListener;
|
||||
import com.kabouzeid.gramophone.interfaces.SelfUpdating;
|
||||
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||
import com.kabouzeid.gramophone.model.DataBaseChangedEvent;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
|
|
@ -39,7 +37,7 @@ import java.util.ArrayList;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, Song> implements MaterialCab.Callback, SelfUpdating {
|
||||
public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, Song> implements MaterialCab.Callback {
|
||||
|
||||
public static final String TAG = AlbumSongAdapter.class.getSimpleName();
|
||||
private static final int SHUFFLE_BUTTON = 0;
|
||||
|
|
@ -47,17 +45,15 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
|||
|
||||
protected final AppCompatActivity activity;
|
||||
protected ArrayList<Song> dataSet;
|
||||
private OnUpdatedListener listener;
|
||||
|
||||
public SongAdapter(AppCompatActivity activity, CabHolder cabHolder) {
|
||||
super(cabHolder, R.menu.menu_media_selection);
|
||||
super(activity, cabHolder, R.menu.menu_media_selection);
|
||||
this.activity = activity;
|
||||
loadDataSet();
|
||||
}
|
||||
|
||||
private void loadDataSet() {
|
||||
dataSet = SongLoader.getAllSongs(activity);
|
||||
if (listener != null) listener.onUpdated(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -129,11 +125,6 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnUpdatedListener(OnUpdatedListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||
final TextView songTitle;
|
||||
final TextView songInfo;
|
||||
|
|
|
|||
|
|
@ -16,16 +16,16 @@ import java.util.ArrayList;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class DeleteFromPlaylistDialog extends DialogFragment {
|
||||
public class RemoveFromPlaylistDialog extends DialogFragment {
|
||||
|
||||
public static DeleteFromPlaylistDialog create(PlaylistSong song) {
|
||||
public static RemoveFromPlaylistDialog create(PlaylistSong song) {
|
||||
ArrayList<PlaylistSong> list = new ArrayList<>();
|
||||
list.add(song);
|
||||
return create(list);
|
||||
}
|
||||
|
||||
public static DeleteFromPlaylistDialog create(ArrayList<PlaylistSong> songs) {
|
||||
DeleteFromPlaylistDialog dialog = new DeleteFromPlaylistDialog();
|
||||
public static RemoveFromPlaylistDialog create(ArrayList<PlaylistSong> songs) {
|
||||
RemoveFromPlaylistDialog dialog = new RemoveFromPlaylistDialog();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable("songs", songs);
|
||||
dialog.setArguments(args);
|
||||
|
|
@ -40,16 +40,16 @@ public class DeleteFromPlaylistDialog extends DialogFragment {
|
|||
int title;
|
||||
CharSequence content;
|
||||
if (songs.size() > 1) {
|
||||
title = R.string.delete_songs_from_playlist_title;
|
||||
content = Html.fromHtml(getString(R.string.delete_x_songs_from_playlist, songs.size()));
|
||||
title = R.string.remove_songs_from_playlist_title;
|
||||
content = Html.fromHtml(getString(R.string.remove_x_songs_from_playlist, songs.size()));
|
||||
} else {
|
||||
title = R.string.delete_song_from_playlist_title;
|
||||
content = Html.fromHtml(getString(R.string.delete_song_x_from_playlist, songs.get(0).title));
|
||||
title = R.string.remove_song_from_playlist_title;
|
||||
content = Html.fromHtml(getString(R.string.remove_song_x_from_playlist, songs.get(0).title));
|
||||
}
|
||||
return new MaterialDialog.Builder(getActivity())
|
||||
.title(title)
|
||||
.content(content)
|
||||
.positiveText(R.string.delete_action)
|
||||
.positiveText(R.string.remove_action)
|
||||
.negativeText(android.R.string.cancel)
|
||||
.callback(new MaterialDialog.ButtonCallback() {
|
||||
@Override
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package com.kabouzeid.gramophone.interfaces;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public interface OnUpdatedListener {
|
||||
|
||||
void onUpdated(SelfUpdating selfUpdating);
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package com.kabouzeid.gramophone.interfaces;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public interface SelfUpdating {
|
||||
|
||||
void setOnUpdatedListener(OnUpdatedListener listener);
|
||||
}
|
||||
|
|
@ -9,6 +9,8 @@ import android.os.Bundle;
|
|||
import android.os.Handler;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.design.widget.AppBarLayout.OnOffsetChangedListener;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.util.Pair;
|
||||
|
|
@ -67,6 +69,7 @@ public class MainActivity extends AbsFabActivity
|
|||
|
||||
private DrawerLayout drawerLayout;
|
||||
private ActionBarDrawerToggle drawerToggle;
|
||||
private AppBarLayout appBar;
|
||||
private Toolbar toolbar;
|
||||
private PagerAdapter pagerAdapter;
|
||||
private ViewPager viewPager;
|
||||
|
|
@ -83,7 +86,7 @@ public class MainActivity extends AbsFabActivity
|
|||
|
||||
initViews();
|
||||
setUpDrawerLayout();
|
||||
setUpToolBar();
|
||||
setUpToolbar();
|
||||
setUpViewPager();
|
||||
|
||||
if (PreferenceUtils.getInstance(this).coloredNavigationBarOtherScreensEnabled())
|
||||
|
|
@ -135,20 +138,19 @@ public class MainActivity extends AbsFabActivity
|
|||
tabLayout = (TabLayout) findViewById(R.id.tabs);
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
navigationView = (NavigationView) findViewById(R.id.nav_view);
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
appBar = (AppBarLayout) findViewById(R.id.appbar);
|
||||
}
|
||||
|
||||
private void setUpToolBar() {
|
||||
private void setUpToolbar() {
|
||||
setTitle(getResources().getString(R.string.app_name));
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setToolBarColor();
|
||||
setAppBarColor();
|
||||
setSupportActionBar(toolbar);
|
||||
setUpDrawerToggle();
|
||||
}
|
||||
|
||||
private void setToolBarColor() {
|
||||
final int colorPrimary = getThemeColorPrimary();
|
||||
toolbar.setBackgroundColor(colorPrimary);
|
||||
tabLayout.setBackgroundColor(colorPrimary);
|
||||
private void setAppBarColor() {
|
||||
appBar.setBackgroundColor(getThemeColorPrimary());
|
||||
}
|
||||
|
||||
private void setUpNavigationView() {
|
||||
|
|
@ -597,4 +599,16 @@ public class MainActivity extends AbsFabActivity
|
|||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public void addOnAppBarOffsetChangedListener(OnOffsetChangedListener onOffsetChangedListener) {
|
||||
appBar.addOnOffsetChangedListener(onOffsetChangedListener);
|
||||
}
|
||||
|
||||
public void removeOnAppBArOffsetChangedListener(OnOffsetChangedListener onOffsetChangedListener) {
|
||||
appBar.removeOnOffsetChangedListener(onOffsetChangedListener);
|
||||
}
|
||||
|
||||
public int getTotalAppBarScrollingRange() {
|
||||
return appBar.getTotalScrollRange();
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@ public class SearchActivity extends AbsBaseActivity {
|
|||
private RecyclerView recyclerView;
|
||||
private SearchView searchView;
|
||||
private SearchAdapter searchAdapter;
|
||||
private View noResults;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
|
|
@ -37,6 +38,7 @@ public class SearchActivity extends AbsBaseActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_search);
|
||||
|
||||
noResults = findViewById(android.R.id.empty);
|
||||
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
searchAdapter = new SearchAdapter(this);
|
||||
|
|
@ -132,7 +134,9 @@ public class SearchActivity extends AbsBaseActivity {
|
|||
}
|
||||
|
||||
private void search(String query) {
|
||||
if (searchAdapter != null)
|
||||
if (searchAdapter != null) {
|
||||
searchAdapter.search(query);
|
||||
noResults.setVisibility(searchAdapter.getItemCount() < 1 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,26 +2,29 @@ package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.design.widget.AppBarLayout.OnOffsetChangedListener;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.interfaces.OnUpdatedListener;
|
||||
import com.kabouzeid.gramophone.interfaces.SelfUpdating;
|
||||
import com.kabouzeid.gramophone.views.FastScroller;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public abstract class AbsMainActivityRecyclerViewFragment extends AbsMainActivityFragment implements OnUpdatedListener {
|
||||
public abstract class AbsMainActivityRecyclerViewFragment extends AbsMainActivityFragment implements OnOffsetChangedListener {
|
||||
|
||||
public static final String TAG = AbsMainActivityRecyclerViewFragment.class.getSimpleName();
|
||||
private RecyclerView recyclerView;
|
||||
private RecyclerView.Adapter mAdapter;
|
||||
private FastScroller fastScroller;
|
||||
private TextView empty;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
|
@ -33,25 +36,34 @@ public abstract class AbsMainActivityRecyclerViewFragment extends AbsMainActivit
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
|
||||
fastScroller = (FastScroller) view.findViewById(R.id.fast_scroller);
|
||||
empty = (TextView) view.findViewById(android.R.id.empty);
|
||||
|
||||
final FastScroller fastScroller = (FastScroller) view.findViewById(R.id.fast_scroller);
|
||||
fastScroller.setRecyclerView(recyclerView);
|
||||
fastScroller.setPressedHandleColor(getMainActivity().getThemeColorPrimary());
|
||||
fastScroller.setOnHandleTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
fastScroller.setPressedHandleColor(getMainActivity().getThemeColorPrimary());
|
||||
|
||||
getMainActivity().addOnAppBarOffsetChangedListener(this);
|
||||
|
||||
setUpRecyclerView();
|
||||
|
||||
checkAndProcessAdapterSize();
|
||||
showEmptyMessageIfEmpty();
|
||||
}
|
||||
|
||||
private void setUpRecyclerView() {
|
||||
mAdapter = createAdapter();
|
||||
if (mAdapter instanceof SelfUpdating) ((SelfUpdating) mAdapter).setOnUpdatedListener(this);
|
||||
mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
|
||||
@Override
|
||||
public void onChanged() {
|
||||
super.onChanged();
|
||||
showEmptyMessageIfEmpty();
|
||||
}
|
||||
});
|
||||
|
||||
recyclerView.setLayoutManager(createLayoutManager());
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
|
@ -61,6 +73,13 @@ public abstract class AbsMainActivityRecyclerViewFragment extends AbsMainActivit
|
|||
return mAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
|
||||
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) fastScroller.getLayoutParams();
|
||||
params.setMargins(params.leftMargin, params.topMargin, params.rightMargin, getMainActivity().getTotalAppBarScrollingRange() + i);
|
||||
fastScroller.setLayoutParams(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableViews() {
|
||||
super.enableViews();
|
||||
|
|
@ -73,14 +92,11 @@ public abstract class AbsMainActivityRecyclerViewFragment extends AbsMainActivit
|
|||
recyclerView.setEnabled(false);
|
||||
}
|
||||
|
||||
private void checkAndProcessAdapterSize() {
|
||||
final View v = getView();
|
||||
private void showEmptyMessageIfEmpty() {
|
||||
RecyclerView.Adapter adapter = getAdapter();
|
||||
if (adapter != null && v != null) {
|
||||
final TextView emptyTextView = (TextView) v.findViewById(android.R.id.empty);
|
||||
|
||||
emptyTextView.setText(getEmptyMessage());
|
||||
emptyTextView.setVisibility(adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
if (adapter != null) {
|
||||
empty.setText(getEmptyMessage());
|
||||
empty.setVisibility(adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -92,9 +108,4 @@ public abstract class AbsMainActivityRecyclerViewFragment extends AbsMainActivit
|
|||
protected abstract RecyclerView.LayoutManager createLayoutManager();
|
||||
|
||||
protected abstract RecyclerView.Adapter createAdapter();
|
||||
|
||||
@Override
|
||||
public void onUpdated(SelfUpdating selfUpdating) {
|
||||
checkAndProcessAdapterSize();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,11 +91,11 @@ public class FastScroller extends FrameLayout {
|
|||
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
||||
mHandle.setPressed(true);
|
||||
|
||||
mInitialBarHeight = mBar.getHeight();
|
||||
mInitialBarHeight = getBarHeight();
|
||||
mLastPressedYAdjustedToInitial = event.getY() + mHandle.getY() + mBar.getY();
|
||||
} else if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
|
||||
float newHandlePressedY = event.getY() + mHandle.getY() + mBar.getY();
|
||||
int barHeight = mBar.getHeight();
|
||||
int barHeight = getBarHeight();
|
||||
float newHandlePressedYAdjustedToInitial =
|
||||
newHandlePressedY + (mInitialBarHeight - barHeight);
|
||||
|
||||
|
|
@ -218,7 +218,7 @@ public class FastScroller extends FrameLayout {
|
|||
int verticalScrollRange = mRecyclerView.computeVerticalScrollRange()
|
||||
+ mRecyclerView.getPaddingBottom();
|
||||
|
||||
int barHeight = mBar.getHeight();
|
||||
int barHeight = getBarHeight();
|
||||
float ratio = (float) scrollOffset / (verticalScrollRange - barHeight);
|
||||
|
||||
int calculatedHandleHeight = (int) ((float) barHeight / verticalScrollRange * barHeight);
|
||||
|
|
@ -245,4 +245,8 @@ public class FastScroller extends FrameLayout {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getBarHeight() {
|
||||
return mBar.getHeight();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue