Merged fastscroller from cabinet. Temporary fixed the wrong fab margins on KitKat and below caused by the google support design library. Added empty screens to Album Song and Artist views.
This commit is contained in:
parent
ab02195ed0
commit
3082ed1187
30 changed files with 483 additions and 195 deletions
|
|
@ -3,7 +3,6 @@ package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
|||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.interfaces.KabViewsDisableAble;
|
||||
import com.kabouzeid.gramophone.ui.activities.MainActivity;
|
||||
|
||||
|
|
@ -13,14 +12,6 @@ import com.kabouzeid.gramophone.ui.activities.MainActivity;
|
|||
public abstract class AbsMainActivityFragment extends Fragment implements KabViewsDisableAble {
|
||||
private boolean areViewsEnabled;
|
||||
|
||||
protected int getTopPadding() {
|
||||
return getResources().getDimensionPixelSize(R.dimen.list_padding_vertical);
|
||||
}
|
||||
|
||||
protected int getBottomPadding() {
|
||||
return getResources().getDimensionPixelSize(R.dimen.bottom_offset_fab_activity);
|
||||
}
|
||||
|
||||
protected MainActivity getMainActivity() {
|
||||
return (MainActivity) getActivity();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,23 @@
|
|||
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.StringRes;
|
||||
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.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 {
|
||||
public abstract class AbsMainActivityRecyclerViewFragment extends AbsMainActivityFragment implements OnUpdatedListener {
|
||||
|
||||
public static final String TAG = AbsMainActivityRecyclerViewFragment.class.getSimpleName();
|
||||
private RecyclerView recyclerView;
|
||||
|
|
@ -19,20 +25,35 @@ public abstract class AbsMainActivityRecyclerViewFragment extends AbsMainActivit
|
|||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(getLayoutResId(), container, false);
|
||||
return inflater.inflate(R.layout.fragment_main_activity_recycler_view, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
|
||||
|
||||
final FastScroller fastScroller = (FastScroller) view.findViewById(R.id.fast_scroller);
|
||||
fastScroller.setRecyclerView(recyclerView);
|
||||
fastScroller.setOnHandleTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
fastScroller.setPressedHandleColor(getMainActivity().getThemeColorPrimary());
|
||||
|
||||
setUpRecyclerView();
|
||||
|
||||
checkAndProcessAdapterSize();
|
||||
}
|
||||
|
||||
private void setUpRecyclerView() {
|
||||
recyclerView.setLayoutManager(createLayoutManager());
|
||||
recyclerView.setPadding(0, getTopPadding(), 0, getBottomPadding());
|
||||
mAdapter = createAdapter();
|
||||
if (mAdapter instanceof SelfUpdating) ((SelfUpdating) mAdapter).setOnUpdatedListener(this);
|
||||
|
||||
recyclerView.setLayoutManager(createLayoutManager());
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
|
|
@ -52,9 +73,28 @@ public abstract class AbsMainActivityRecyclerViewFragment extends AbsMainActivit
|
|||
recyclerView.setEnabled(false);
|
||||
}
|
||||
|
||||
protected abstract int getLayoutResId();
|
||||
private void checkAndProcessAdapterSize() {
|
||||
final View v = getView();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@StringRes
|
||||
protected int getEmptyMessage() {
|
||||
return R.string.nothing_here;
|
||||
}
|
||||
|
||||
protected abstract RecyclerView.LayoutManager createLayoutManager();
|
||||
|
||||
protected abstract RecyclerView.Adapter createAdapter();
|
||||
|
||||
@Override
|
||||
public void onUpdated(SelfUpdating selfUpdating) {
|
||||
checkAndProcessAdapterSize();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,6 @@ public class AlbumViewFragment extends AbsMainActivityRecyclerViewFragment {
|
|||
|
||||
private GridLayoutManager layoutManager;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.fragment_album_view;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RecyclerView.LayoutManager createLayoutManager() {
|
||||
int columns = Util.isInPortraitMode(getActivity()) ? PreferenceUtils.getInstance(getActivity()).getAlbumGridColumns() : PreferenceUtils.getInstance(getActivity()).getAlbumGridColumnsLand();
|
||||
|
|
@ -33,6 +28,11 @@ public class AlbumViewFragment extends AbsMainActivityRecyclerViewFragment {
|
|||
return new AlbumAdapter(getMainActivity(), getMainActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getEmptyMessage() {
|
||||
return R.string.no_albums;
|
||||
}
|
||||
|
||||
public void setColumns(int columns) {
|
||||
layoutManager.setSpanCount(columns);
|
||||
layoutManager.requestLayout();
|
||||
|
|
|
|||
|
|
@ -1,19 +1,17 @@
|
|||
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
||||
|
||||
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.ArtistAdapter;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ArtistViewFragment extends AbsMainActivityRecyclerViewFragment {
|
||||
public static final String TAG = ArtistViewFragment.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.fragment_artist_view;
|
||||
}
|
||||
public static final String TAG = ArtistViewFragment.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
protected RecyclerView.LayoutManager createLayoutManager() {
|
||||
|
|
@ -24,4 +22,9 @@ public class ArtistViewFragment extends AbsMainActivityRecyclerViewFragment {
|
|||
protected RecyclerView.Adapter createAdapter() {
|
||||
return new ArtistAdapter(getMainActivity(), getMainActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getEmptyMessage() {
|
||||
return R.string.no_artists;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,68 +1,30 @@
|
|||
package com.kabouzeid.gramophone.ui.fragments.mainactivityfragments;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
import com.kabouzeid.gramophone.App;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.PlaylistAdapter;
|
||||
import com.kabouzeid.gramophone.model.DataBaseChangedEvent;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class PlaylistViewFragment extends AbsMainActivityRecyclerViewFragment {
|
||||
|
||||
public static final String TAG = PlaylistViewFragment.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.fragment_playlist_view;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RecyclerView.LayoutManager createLayoutManager() {
|
||||
return new GridLayoutManager(getActivity(), 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
App.bus.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
App.bus.unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RecyclerView.Adapter createAdapter() {
|
||||
PlaylistAdapter adapter = new PlaylistAdapter(getMainActivity(), getMainActivity());
|
||||
View v = getView();
|
||||
if (v != null) {
|
||||
v.findViewById(android.R.id.empty).setVisibility(
|
||||
adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
return adapter;
|
||||
return new PlaylistAdapter(getMainActivity(), getMainActivity());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onDataBaseEvent(DataBaseChangedEvent event) {
|
||||
switch (event.getAction()) {
|
||||
case DataBaseChangedEvent.PLAYLISTS_CHANGED:
|
||||
case DataBaseChangedEvent.DATABASE_CHANGED:
|
||||
PlaylistAdapter adapter = (PlaylistAdapter) getAdapter();
|
||||
adapter.loadDataSet();
|
||||
adapter.notifyDataSetChanged();
|
||||
View v = getView();
|
||||
if (v != null) {
|
||||
v.findViewById(android.R.id.empty).setVisibility(
|
||||
adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@Override
|
||||
protected int getEmptyMessage() {
|
||||
return R.string.no_playlists;
|
||||
}
|
||||
}
|
||||
|
|
@ -13,11 +13,6 @@ public class SongViewFragment extends AbsMainActivityRecyclerViewFragment {
|
|||
|
||||
public static final String TAG = SongViewFragment.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.fragment_songview;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RecyclerView.LayoutManager createLayoutManager() {
|
||||
return new GridLayoutManager(getActivity(), 1);
|
||||
|
|
@ -27,4 +22,9 @@ public class SongViewFragment extends AbsMainActivityRecyclerViewFragment {
|
|||
protected RecyclerView.Adapter createAdapter() {
|
||||
return new SongAdapter(getMainActivity(), getMainActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getEmptyMessage() {
|
||||
return R.string.no_songs;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue