Makes full use of the Android Support Design Library. A lot of small things fixed or improved. Added dozens of new colors.

This commit is contained in:
Karim Abou Zeid 2015-05-30 22:51:17 +02:00
commit 31926d7983
45 changed files with 447 additions and 599 deletions

View file

@ -69,7 +69,6 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
private ObservableRecyclerView recyclerView;
private AlbumSongAdapter adapter;
private ArrayList<Song> songs;
private View statusBar;
private ImageView albumArtImageView;
private ImageView albumArtBackground;
private View songsBackgroundView;
@ -99,7 +98,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
// Change alpha of overlay
toolbarAlpha = Math.max(0, Math.min(1, (float) scrollY / flexibleRange));
ViewUtil.setBackgroundAlpha(toolbar, toolbarAlpha, toolbarColor);
ViewUtil.setBackgroundAlpha(statusBar, cab != null && cab.isActive() ? 1 : toolbarAlpha, toolbarColor);
setStatusBarColor(Util.getColorWithAlpha(cab != null && cab.isActive() ? 1 : toolbarAlpha, toolbarColor));
// Translate name text
int maxTitleTranslationY = albumArtViewHeight;
@ -112,6 +111,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
@Override
protected void onCreate(Bundle savedInstanceState) {
setStatusBarTransparent();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_album_detail);
@ -174,7 +174,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
recyclerView = (ObservableRecyclerView) findViewById(R.id.list);
albumTitleView = (TextView) findViewById(R.id.album_title);
songsBackgroundView = findViewById(R.id.list_background);
statusBar = findViewById(R.id.status_bar);
// statusBar = findViewById(R.id.status_bar);
}
private void setUpObservableListViewParams() {
@ -237,7 +237,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
if (vibrantSwatch != null) {
toolbarColor = vibrantSwatch.getRgb();
albumTitleView.setBackgroundColor(toolbarColor);
albumTitleView.setTextColor(vibrantSwatch.getTitleTextColor());
albumTitleView.setTextColor(Util.getOpaqueColor(vibrantSwatch.getTitleTextColor()));
if (Util.isAtLeastLollipop() && PreferenceUtils.getInstance(AlbumDetailActivity.this).coloredNavigationBarAlbumEnabled())
setNavigationBarColor(toolbarColor);
notifyTaskColorChange(toolbarColor);
@ -411,7 +411,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
.start(new MaterialCab.Callback() {
@Override
public boolean onCabCreated(MaterialCab materialCab, Menu menu) {
ViewUtil.setBackgroundAlpha(statusBar, 1, toolbarColor);
setStatusBarColor(Util.getOpaqueColor(toolbarColor));
return callback.onCabCreated(materialCab, menu);
}
@ -422,7 +422,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
@Override
public boolean onCabFinished(MaterialCab materialCab) {
ViewUtil.setBackgroundAlpha(statusBar, toolbarAlpha, toolbarColor);
setStatusBarColor(Util.getColorWithAlpha(toolbarAlpha, toolbarColor));
return callback.onCabFinished(materialCab);
}
});

View file

@ -74,7 +74,6 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
private Artist artist;
private ObservableListView songListView;
private View statusBar;
private ImageView artistImage;
private ImageView artistImageBackground;
private View songsBackgroundView;
@ -112,7 +111,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
// Change alpha of overlay
toolbarAlpha = Math.max(0, Math.min(1, (float) scrollY / flexibleRange));
ViewUtil.setBackgroundAlpha(toolbar, toolbarAlpha, toolbarColor);
ViewUtil.setBackgroundAlpha(statusBar, cab != null && cab.isActive() ? 1 : toolbarAlpha, toolbarColor);
setStatusBarColor(Util.getColorWithAlpha(cab != null && cab.isActive() ? 1 : toolbarAlpha, toolbarColor));
// Translate name text
int maxTitleTranslationY = artistImageViewHeight;
@ -127,6 +126,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
@Override
protected void onCreate(Bundle savedInstanceState) {
setStatusBarTransparent();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_artist_detail);
@ -183,7 +183,6 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
songListView = (ObservableListView) findViewById(R.id.list);
artistNameTv = (TextView) findViewById(R.id.artist_name);
songsBackgroundView = findViewById(R.id.list_background);
statusBar = findViewById(R.id.status_bar);
songListHeader = LayoutInflater.from(this).inflate(R.layout.artist_detail_header, songListView, false);
albumRecyclerView = (RecyclerView) songListHeader.findViewById(R.id.recycler_view);
@ -318,7 +317,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
if (vibrantSwatch != null) {
toolbarColor = vibrantSwatch.getRgb();
artistNameTv.setBackgroundColor(vibrantSwatch.getRgb());
artistNameTv.setTextColor(vibrantSwatch.getTitleTextColor());
artistNameTv.setTextColor(Util.getOpaqueColor(vibrantSwatch.getTitleTextColor()));
if (Util.isAtLeastLollipop() && PreferenceUtils.getInstance(ArtistDetailActivity.this).coloredNavigationBarArtistEnabled())
setNavigationBarColor(vibrantSwatch.getRgb());
notifyTaskColorChange(toolbarColor);
@ -497,7 +496,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
.start(new MaterialCab.Callback() {
@Override
public boolean onCabCreated(MaterialCab materialCab, Menu menu) {
ViewUtil.setBackgroundAlpha(statusBar, 1, toolbarColor);
setStatusBarColor(Util.getOpaqueColor(toolbarColor));
return callback.onCabCreated(materialCab, menu);
}
@ -508,7 +507,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
@Override
public boolean onCabFinished(MaterialCab materialCab) {
ViewUtil.setBackgroundAlpha(statusBar, toolbarAlpha, toolbarColor);
setStatusBarColor(Util.getColorWithAlpha(toolbarAlpha, toolbarColor));
return callback.onCabFinished(materialCab);
}
});

View file

@ -10,6 +10,7 @@ import android.os.Handler;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.design.widget.TabLayout;
import android.support.v4.util.Pair;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
@ -30,7 +31,6 @@ import android.widget.TextView;
import com.afollestad.materialcab.MaterialCab;
import com.afollestad.materialdialogs.ThemeSingleton;
import com.astuetz.PagerSlidingTabStrip;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.adapter.PagerAdapter;
import com.kabouzeid.gramophone.dialogs.AboutDialog;
@ -70,7 +70,7 @@ public class MainActivity extends AbsFabActivity
private Toolbar toolbar;
private PagerAdapter pagerAdapter;
private ViewPager viewPager;
private PagerSlidingTabStrip slidingTabLayout;
private TabLayout tabLayout;
private int currentPage = -1;
private MaterialCab cab;
private NavigationView navigationView;
@ -105,34 +105,34 @@ public class MainActivity extends AbsFabActivity
int startPosition = PreferenceUtils.getInstance(this).getDefaultStartPage();
startPosition = startPosition == -1 ? PreferenceUtils.getInstance(this).getLastStartPage() : startPosition;
currentPage = startPosition;
viewPager.setCurrentItem(startPosition);
navigationView.getMenu().getItem(startPosition).setChecked(true);
slidingTabLayout.setIndicatorColor(ThemeSingleton.get().positiveColor);
slidingTabLayout.setViewPager(viewPager);
slidingTabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
tabLayout.setupWithViewPager(viewPager);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(final int position) {
public void onPageSelected(int position) {
navigationView.getMenu().getItem(position).setChecked(true);
currentPage = position;
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
viewPager.setCurrentItem(startPosition);
}
private void initViews() {
viewPager = (ViewPager) findViewById(R.id.pager);
slidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.tabs);
tabLayout = (TabLayout) findViewById(R.id.tabs);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationView = (NavigationView) findViewById(R.id.nav_view);
}
@ -140,16 +140,15 @@ public class MainActivity extends AbsFabActivity
private void setUpToolBar() {
setTitle(getResources().getString(R.string.app_name));
toolbar = (Toolbar) findViewById(R.id.toolbar);
setToolBarTransparent(PreferenceUtils.getInstance(this).transparentToolbar());
setToolBarColor();
setSupportActionBar(toolbar);
setUpDrawerToggle();
}
private void setToolBarTransparent(boolean transparent) {
float alpha = transparent ? 0.9f : 1f;
final int colorPrimary = PreferenceUtils.getInstance(this).getThemeColorPrimary();
ViewUtil.setBackgroundAlpha(toolbar, alpha, colorPrimary);
ViewUtil.setBackgroundAlpha(slidingTabLayout, alpha, colorPrimary);
private void setToolBarColor() {
final int colorPrimary = getThemeColorPrimary();
toolbar.setBackgroundColor(colorPrimary);
tabLayout.setBackgroundColor(colorPrimary);
}
private void setUpNavigationView() {
@ -163,7 +162,7 @@ public class MainActivity extends AbsFabActivity
new int[]{
// 0,
colorAccent,
Color.argb(222, 0, 0, 0)
ThemeSingleton.get().darkTheme ? Color.argb(222, 255, 255, 255) : Color.argb(222, 0, 0, 0)
}
));
navigationView.setItemIconTintList(new ColorStateList(
@ -175,7 +174,7 @@ public class MainActivity extends AbsFabActivity
new int[]{
// 0,
colorAccent,
Color.argb(138, 0, 0, 0)
ThemeSingleton.get().darkTheme ? Color.argb(138, 255, 255, 255) : Color.argb(138, 0, 0, 0)
}
));
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@ -369,9 +368,6 @@ public class MainActivity extends AbsFabActivity
public void onUIPreferenceChangedEvent(UIPreferenceChangedEvent event) {
super.onUIPreferenceChangedEvent(event);
switch (event.getAction()) {
case UIPreferenceChangedEvent.TOOLBAR_TRANSPARENT_CHANGED:
setToolBarTransparent((boolean) event.getValue());
break;
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_OTHER_SCREENS_CHANGED:
if ((boolean) event.getValue()) setNavigationBarThemeColor();
else resetNavigationBarColor();

View file

@ -81,6 +81,7 @@ public class MusicControllerActivity extends AbsFabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setStatusBarTransparent();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_music_controller);
@ -218,7 +219,7 @@ public class MusicControllerActivity extends AbsFabActivity {
switch (MusicPlayerRemote.getShuffleMode()) {
case MusicService.SHUFFLE_MODE_SHUFFLE:
shuffleButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_shuffle_white_48dp,
ThemeSingleton.get().positiveColor));
getThemeColorAccent() == Color.WHITE ? Color.BLACK : getThemeColorAccent()));
break;
default:
shuffleButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_shuffle_white_48dp,
@ -245,11 +246,11 @@ public class MusicControllerActivity extends AbsFabActivity {
break;
case MusicService.REPEAT_MODE_ALL:
repeatButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_repeat_white_48dp,
ThemeSingleton.get().positiveColor));
getThemeColorAccent() == Color.WHITE ? Color.BLACK : getThemeColorAccent()));
break;
default:
repeatButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_repeat_one_white_48dp,
ThemeSingleton.get().positiveColor));
getThemeColorAccent() == Color.WHITE ? Color.BLACK : getThemeColorAccent()));
break;
}
}
@ -320,7 +321,7 @@ public class MusicControllerActivity extends AbsFabActivity {
if (vibrantSwatch != null) {
final int swatchRgb = vibrantSwatch.getRgb();
animateColorChange(swatchRgb);
animateTextColorChange(Util.getColorWithoutAlpha(vibrantSwatch.getTitleTextColor()));
animateTextColorChange(Util.getOpaqueColor(vibrantSwatch.getTitleTextColor()));
notifyTaskColorChange(swatchRgb);
} else {
resetColors();
@ -333,7 +334,7 @@ public class MusicControllerActivity extends AbsFabActivity {
}
private void resetColors() {
final int textColor = Util.getColorWithoutAlpha(DialogUtils.resolveColor(this, R.attr.title_text_color));
final int textColor = Util.getOpaqueColor(DialogUtils.resolveColor(this, R.attr.title_text_color));
final int defaultBarColor = DialogUtils.resolveColor(this, R.attr.default_bar_color);
animateColorChange(defaultBarColor);
@ -360,7 +361,7 @@ public class MusicControllerActivity extends AbsFabActivity {
else toolbar.setBackgroundColor(Color.TRANSPARENT);
}
setTint(progressSlider, PreferenceUtils.getInstance(this).getThemeColorAccent());
setTint(progressSlider, !ThemeSingleton.get().darkTheme && getThemeColorAccent() == Color.WHITE ? Color.BLACK : getThemeColorAccent());
if (opaqueToolBar) setStatusBarColor(newColor);
else setStatusBarColor(Color.TRANSPARENT);

View file

@ -79,6 +79,7 @@ public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder
if (PreferenceUtils.getInstance(this).coloredNavigationBarPlaylistEnabled())
setNavigationBarThemeColor();
setStatusBarThemeColor();
App.bus.register(this);
}

View file

@ -113,14 +113,6 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
}
});
findPreference("transparent_toolbar").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
App.bus.post(new UIPreferenceChangedEvent(UIPreferenceChangedEvent.TOOLBAR_TRANSPARENT_CHANGED, o));
return true;
}
});
findPreference("colored_album_footers").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {

View file

@ -19,6 +19,7 @@ import com.kabouzeid.gramophone.misc.SmallOnGestureListener;
import com.kabouzeid.gramophone.model.MusicRemoteEvent;
import com.kabouzeid.gramophone.model.Song;
import com.kabouzeid.gramophone.util.NavigationUtil;
import com.kabouzeid.gramophone.util.Util;
import com.kabouzeid.gramophone.views.PlayPauseDrawable;
import com.squareup.otto.Subscribe;
@ -54,7 +55,7 @@ public abstract class AbsFabActivity extends AbsBaseActivity {
getFab().setImageDrawable(playPauseDrawable);
final int accentColor = ThemeSingleton.get().positiveColor;
getFab().setRippleColor(accentColor);
getFab().setBackgroundTintList(Util.getEmptyColorStateList(accentColor));
if (accentColor == Color.WHITE) {
getFab().getDrawable().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
} else {

View file

@ -5,6 +5,7 @@ import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.afollestad.materialdialogs.ThemeSingleton;
import com.kabouzeid.gramophone.R;
@ -17,6 +18,9 @@ import com.kabouzeid.gramophone.util.Util;
*/
public abstract class ThemeBaseActivity extends AppCompatActivity implements KabViewsDisableAble {
private int colorPrimary;
private int colorPrimaryDarker;
private int colorAccent;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -27,7 +31,11 @@ public abstract class ThemeBaseActivity extends AppCompatActivity implements Kab
private void setupTheme() {
ThemeSingleton.get().positiveColor = PreferenceUtils.getInstance(this).getThemeColorAccent();
colorPrimary = PreferenceUtils.getInstance(this).getThemeColorPrimary();
colorPrimaryDarker = Util.shiftColorDown(colorPrimary);
colorAccent = PreferenceUtils.getInstance(this).getThemeColorAccent();
ThemeSingleton.get().positiveColor = colorAccent;
ThemeSingleton.get().negativeColor = ThemeSingleton.get().positiveColor;
ThemeSingleton.get().neutralColor = ThemeSingleton.get().positiveColor;
ThemeSingleton.get().widgetColor = ThemeSingleton.get().positiveColor;
@ -49,27 +57,45 @@ public abstract class ThemeBaseActivity extends AppCompatActivity implements Kab
}
}
protected void setStatusBarTranslucent(boolean statusBarTranslucent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
Util.setStatusBarTranslucent(getWindow(), statusBarTranslucent);
public int getThemeColorPrimary() {
return colorPrimary;
}
public int getThemeColorPrimaryDarker() {
return colorPrimaryDarker;
}
public int getThemeColorAccent() {
return colorAccent;
}
protected void setStatusBarTransparent() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
Util.setAllowDrawUnderStatusBar(getWindow());
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
Util.setStatusBarTranslucent(getWindow(), true);
}
protected final void setNavigationBarColor(int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
getWindow().setNavigationBarColor(color);
getWindow().setNavigationBarColor(Util.shiftColorDown(color));
}
protected final void setStatusBarColor(int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
getWindow().setStatusBarColor(color);
getWindow().setStatusBarColor(Util.shiftColorDown(color));
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
final View statusBar = getWindow().getDecorView().getRootView().findViewById(R.id.status_bar);
if (statusBar != null) statusBar.setBackgroundColor(color);
}
}
protected final void setNavigationBarThemeColor() {
setNavigationBarColor(PreferenceUtils.getInstance(this).getThemeColorPrimaryDarker());
setNavigationBarColor(colorPrimary);
}
protected final void setStatusBarThemeColor() {
setStatusBarColor(PreferenceUtils.getInstance(this).getThemeColorPrimaryDarker());
setStatusBarColor(colorPrimary);
}
protected final void resetNavigationBarColor() {

View file

@ -24,7 +24,6 @@ import com.afollestad.materialdialogs.util.DialogUtils;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollView;
import com.kabouzeid.gramophone.App;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.dialogs.ColorChooserDialog;
import com.kabouzeid.gramophone.misc.AppKeys;
import com.kabouzeid.gramophone.misc.SmallObservableScrollViewCallbacks;
import com.kabouzeid.gramophone.model.DataBaseChangedEvent;
@ -255,8 +254,8 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
header.setBackgroundColor(paletteColorPrimary);
setStatusBarColor(paletteColorPrimary);
if (Util.isAtLeastLollipop() && PreferenceUtils.getInstance(this).coloredNavigationBarTagEditorEnabled())
setNavigationBarColor(ColorChooserDialog.shiftColorDown(paletteColorPrimary));
if (PreferenceUtils.getInstance(this).coloredNavigationBarTagEditorEnabled())
setNavigationBarColor(paletteColorPrimary);
}
protected void dataChanged() {

View file

@ -1,182 +0,0 @@
package com.kabouzeid.gramophone.ui.fragments;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.adapter.NavigationDrawerItemAdapter;
import com.kabouzeid.gramophone.misc.AppKeys;
import com.kabouzeid.gramophone.model.NavigationDrawerItem;
import java.util.ArrayList;
public class NavigationDrawerFragment extends Fragment {
public static final int NAVIGATION_DRAWER_HEADER = -1;
public static final int ABOUT_INDEX = 5;
public static final int SETTINGS_INDEX = 4;
private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position";
public View fragmentRootView;
private NavigationDrawerCallbacks callbacks;
private NavigationDrawerItemAdapter drawerAdapter;
private DrawerLayout drawerLayout;
private RecyclerView drawerRecyclerView;
private View headerButton;
private ImageView albumArt;
private TextView songTitle;
private TextView songArtist;
private boolean fromSavedInstanceState;
private boolean userLearnedDrawer;
private int checkedPosition = 0;
public NavigationDrawerFragment() {
}
public boolean isDrawerOpen() {
return drawerLayout != null && drawerLayout.isDrawerOpen(Gravity.START);
}
public void setUp(final DrawerLayout drawerLayout) {
this.drawerLayout = drawerLayout;
this.drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
if (!userLearnedDrawer && !fromSavedInstanceState) {
this.drawerLayout.openDrawer(Gravity.START);
userLearnedDrawer = true;
PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putBoolean(AppKeys.SP_USER_LEARNED_DRAWER, true).apply();
}
}
public TextView getSongArtist() {
return songArtist;
}
public ImageView getAlbumArtImageView() {
return albumArt;
}
public TextView getSongTitle() {
return songTitle;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
callbacks = (NavigationDrawerCallbacks) activity;
} catch (ClassCastException e) {
throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
userLearnedDrawer = PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean(AppKeys.SP_USER_LEARNED_DRAWER, false);
if (savedInstanceState != null) {
setItemChecked(savedInstanceState.getInt(STATE_SELECTED_POSITION));
fromSavedInstanceState = true;
}
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.navigation_drawer_header, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
fragmentRootView = view;
super.onViewCreated(view, savedInstanceState);
initViews();
setUpViews();
}
private void initViews() {
// drawerRecyclerView = (RecyclerView) fragmentRootView.findViewById(R.id.navigation_drawer_list);
// final View drawerHeader = fragmentRootView.findViewById(R.id.header);
// headerButton = (View) drawerHeader.findViewById(R.id.header_clickable);
// albumArt = (ImageView) drawerHeader.findViewById(R.id.album_art);
// songTitle = (TextView) drawerHeader.findViewById(R.id.song_title);
// songArtist = (TextView) drawerHeader.findViewById(R.id.song_artist);
}
private void setUpViews() {
headerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectItem(NAVIGATION_DRAWER_HEADER);
}
});
setUpListView();
}
private void setUpListView() {
final ArrayList<NavigationDrawerItem> navigationDrawerItems = new ArrayList<>();
navigationDrawerItems.add(new NavigationDrawerItem(getString(R.string.songs), R.drawable.ic_audiotrack_white_24dp));
navigationDrawerItems.add(new NavigationDrawerItem(getString(R.string.albums), R.drawable.ic_album_white_24dp));
navigationDrawerItems.add(new NavigationDrawerItem(getString(R.string.artists), R.drawable.ic_person_white_24dp));
navigationDrawerItems.add(new NavigationDrawerItem(getString(R.string.playlists), R.drawable.ic_queue_music_white_24dp));
navigationDrawerItems.add(new NavigationDrawerItem(getString(R.string.action_settings), R.drawable.ic_settings_white_24dp));
navigationDrawerItems.add(new NavigationDrawerItem(getString(R.string.action_about), R.drawable.ic_help_white_24dp));
drawerAdapter = new NavigationDrawerItemAdapter(getActivity(), navigationDrawerItems, new NavigationDrawerItemAdapter.Callback() {
@Override
public void onItemSelected(int index) {
selectItem(index);
}
});
drawerRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
drawerRecyclerView.setAdapter(drawerAdapter);
}
private void selectItem(final int position) {
if (position != NAVIGATION_DRAWER_HEADER &&
position != ABOUT_INDEX && position != SETTINGS_INDEX) {
setItemChecked(position);
if (drawerLayout != null)
drawerLayout.closeDrawers();
}
if (callbacks != null)
callbacks.onNavigationDrawerItemSelected(position);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(STATE_SELECTED_POSITION, checkedPosition);
}
@Override
public void onDetach() {
super.onDetach();
callbacks = null;
}
public void setItemChecked(final int position) {
if (drawerAdapter != null) {
drawerAdapter.setChecked(position);
checkedPosition = position;
}
}
public interface NavigationDrawerCallbacks {
void onNavigationDrawerItemSelected(int position);
}
}

View file

@ -6,7 +6,6 @@ import android.support.v4.app.Fragment;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.interfaces.KabViewsDisableAble;
import com.kabouzeid.gramophone.ui.activities.MainActivity;
import com.kabouzeid.gramophone.util.Util;
/**
* @author Karim Abou Zeid (kabouzeid)
@ -15,9 +14,7 @@ public abstract class AbsMainActivityFragment extends Fragment implements KabVie
private boolean areViewsEnabled;
protected int getTopPadding() {
return Util.getActionBarSize(getActivity()) +
getResources().getDimensionPixelSize(R.dimen.tab_height) +
getResources().getDimensionPixelSize(R.dimen.list_padding_vertical);
return getResources().getDimensionPixelSize(R.dimen.list_padding_vertical);
}
protected int getBottomPadding() {