MainActivity SlidingTabs [BETA]
This commit is contained in:
parent
99aaba4c16
commit
496b64a5cf
18 changed files with 346 additions and 313 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package com.kabouzeid.materialmusic;
|
||||
|
||||
import android.app.Application;
|
||||
import android.app.Fragment;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.preference.PreferenceManager;
|
||||
|
|
@ -22,7 +21,6 @@ import io.fabric.sdk.android.Fabric;
|
|||
public class App extends Application {
|
||||
private static final String TAG = App.class.getSimpleName();
|
||||
|
||||
public Fragment[] MainActivityFragments = new Fragment[5];
|
||||
private MusicPlayerRemote playerRemote;
|
||||
private int appTheme;
|
||||
private SharedPreferences defaultSharedPreferences;
|
||||
|
|
@ -59,7 +57,7 @@ public class App extends Application {
|
|||
|
||||
public void setAppTheme(int appTheme) {
|
||||
this.appTheme = appTheme;
|
||||
defaultSharedPreferences.edit().putInt(AppKeys.SP_THEME, appTheme);
|
||||
defaultSharedPreferences.edit().putInt(AppKeys.SP_THEME, appTheme).apply();
|
||||
}
|
||||
|
||||
public boolean isTablet() {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class ArtistAlbumLoader {
|
|||
}
|
||||
|
||||
public static Cursor makeArtistAlbumCursor(final Context context, final int artistId) {
|
||||
if(artistId == -1) return null;
|
||||
if (artistId == -1) return null;
|
||||
return context.getContentResolver().query(
|
||||
MediaStore.Audio.Artists.Albums.getContentUri("external", artistId), new String[]{
|
||||
/* 0 */
|
||||
|
|
|
|||
|
|
@ -43,12 +43,6 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
|||
database.insert(AlbumJSONColumns.NAME, null, values);
|
||||
database.setTransactionSuccessful();
|
||||
database.endTransaction();
|
||||
} @Override
|
||||
public void onCreate(final SQLiteDatabase db) {
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS " + AlbumJSONColumns.NAME +
|
||||
" (" + AlbumJSONColumns.ALBUMANDARTIST_NAME + " TEXT NOT NULL," +
|
||||
AlbumJSONColumns.JSON + " TEXT NOT NULL);"
|
||||
);
|
||||
}
|
||||
|
||||
public String getAlbumJSON(final String albumAndArtistName) {
|
||||
|
|
@ -76,6 +70,12 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
|||
cursor.close();
|
||||
}
|
||||
return null;
|
||||
} @Override
|
||||
public void onCreate(final SQLiteDatabase db) {
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS " + AlbumJSONColumns.NAME +
|
||||
" (" + AlbumJSONColumns.ALBUMANDARTIST_NAME + " TEXT NOT NULL," +
|
||||
AlbumJSONColumns.JSON + " TEXT NOT NULL);"
|
||||
);
|
||||
}
|
||||
|
||||
public void removeItem(final String albumAndArtistName) {
|
||||
|
|
@ -90,15 +90,15 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
|||
public static final String NAME = "AlbumJSON";
|
||||
public static final String ALBUMANDARTIST_NAME = "AlbumAndArtistName";
|
||||
public static final String JSON = "JSON";
|
||||
} @Override
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + AlbumJSONColumns.NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,12 +43,6 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
|||
database.insert(ArtistJSONColumns.NAME, null, values);
|
||||
database.setTransactionSuccessful();
|
||||
database.endTransaction();
|
||||
} @Override
|
||||
public void onCreate(final SQLiteDatabase db) {
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS " + ArtistJSONColumns.NAME +
|
||||
" (" + ArtistJSONColumns.ARTIST_NAME + " TEXT NOT NULL," +
|
||||
ArtistJSONColumns.JSON + " TEXT NOT NULL);"
|
||||
);
|
||||
}
|
||||
|
||||
public String getArtistJSON(final String artistName) {
|
||||
|
|
@ -76,6 +70,12 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
|||
cursor.close();
|
||||
}
|
||||
return null;
|
||||
} @Override
|
||||
public void onCreate(final SQLiteDatabase db) {
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS " + ArtistJSONColumns.NAME +
|
||||
" (" + ArtistJSONColumns.ARTIST_NAME + " TEXT NOT NULL," +
|
||||
ArtistJSONColumns.JSON + " TEXT NOT NULL);"
|
||||
);
|
||||
}
|
||||
|
||||
public void removeItem(final String artistName) {
|
||||
|
|
@ -90,15 +90,15 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
|||
public static final String NAME = "ArtistJSON";
|
||||
public static final String ARTIST_NAME = "ArtistName";
|
||||
public static final String JSON = "JSON";
|
||||
} @Override
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + ArtistJSONColumns.NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -372,6 +372,24 @@ public class MusicService extends Service implements MediaPlayer.OnPreparedListe
|
|||
return playingQueue;
|
||||
}
|
||||
|
||||
public int getRepeatMode() {
|
||||
return repeatMode;
|
||||
}
|
||||
|
||||
public void setRepeatMode(final int repeatMode) {
|
||||
switch (repeatMode) {
|
||||
case REPEAT_MODE_NONE:
|
||||
case REPEAT_MODE_ALL:
|
||||
case REPEAT_MODE_THIS:
|
||||
this.repeatMode = repeatMode;
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
||||
.putInt(AppKeys.SP_REPEAT_MODE, repeatMode)
|
||||
.apply();
|
||||
notifyOnMusicRemoteEventListeners(MusicRemoteEvent.REPEAT_MODE_CHANGED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onError(MediaPlayer mp, int what, int extra) {
|
||||
isPlayerPrepared = false;
|
||||
|
|
@ -588,24 +606,6 @@ public class MusicService extends Service implements MediaPlayer.OnPreparedListe
|
|||
}
|
||||
}
|
||||
|
||||
public int getRepeatMode() {
|
||||
return repeatMode;
|
||||
}
|
||||
|
||||
public void setRepeatMode(final int repeatMode) {
|
||||
switch (repeatMode) {
|
||||
case REPEAT_MODE_NONE:
|
||||
case REPEAT_MODE_ALL:
|
||||
case REPEAT_MODE_THIS:
|
||||
this.repeatMode = repeatMode;
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
||||
.putInt(AppKeys.SP_REPEAT_MODE, repeatMode)
|
||||
.apply();
|
||||
notifyOnMusicRemoteEventListeners(MusicRemoteEvent.REPEAT_MODE_CHANGED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleShuffle() {
|
||||
if (getShuffleMode() == SHUFFLE_MODE_NONE) {
|
||||
setShuffleMode(SHUFFLE_MODE_SHUFFLE);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import com.kabouzeid.materialmusic.loader.AlbumSongLoader;
|
|||
import com.kabouzeid.materialmusic.misc.AppKeys;
|
||||
import com.kabouzeid.materialmusic.misc.SmallObservableScrollViewCallbacks;
|
||||
import com.kabouzeid.materialmusic.model.Album;
|
||||
import com.kabouzeid.materialmusic.model.MusicRemoteEvent;
|
||||
import com.kabouzeid.materialmusic.model.Song;
|
||||
import com.kabouzeid.materialmusic.ui.activities.base.AbsFabActivity;
|
||||
import com.kabouzeid.materialmusic.ui.activities.tageditor.AlbumTagEditorActivity;
|
||||
|
|
@ -38,7 +37,6 @@ import com.kabouzeid.materialmusic.util.ImageLoaderUtil;
|
|||
import com.kabouzeid.materialmusic.util.MusicUtil;
|
||||
import com.kabouzeid.materialmusic.util.Util;
|
||||
import com.kabouzeid.materialmusic.util.ViewUtil;
|
||||
import com.melnykov.fab.FloatingActionButton;
|
||||
import com.nhaarman.listviewanimations.appearance.AnimationAdapter;
|
||||
import com.nhaarman.listviewanimations.appearance.simple.ScaleInAnimationAdapter;
|
||||
import com.nineoldandroids.view.ViewHelper;
|
||||
|
|
@ -353,6 +351,11 @@ public class AlbumDetailActivity extends AbsFabActivity implements OnMusicRemote
|
|||
.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goToAlbum(int albumId) {
|
||||
if (album.id != albumId) {
|
||||
|
|
@ -360,11 +363,6 @@ public class AlbumDetailActivity extends AbsFabActivity implements OnMusicRemote
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
private void lollipopTransitionImageWrongSizeFix() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
getWindow().getSharedElementEnterTransition().addListener(new Transition.TransitionListener() {
|
||||
|
|
|
|||
|
|
@ -335,6 +335,11 @@ public class ArtistDetailActivity extends AbsFabActivity implements OnMusicRemot
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goToArtist(int artistId) {
|
||||
if (artist.id != artistId) {
|
||||
|
|
@ -342,11 +347,6 @@ public class ArtistDetailActivity extends AbsFabActivity implements OnMusicRemot
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
private void lollipopTransitionImageWrongSizeFix() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
getWindow().getSharedElementEnterTransition().addListener(new Transition.TransitionListener() {
|
||||
|
|
@ -434,7 +434,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements OnMusicRemot
|
|||
|
||||
private String[] titles;
|
||||
|
||||
private static SparseArray<Fragment> pages;
|
||||
private SparseArray<Fragment> pages; //TODO check if this must be static
|
||||
private Artist artist;
|
||||
private Context context;
|
||||
|
||||
|
|
@ -471,10 +471,6 @@ public class ArtistDetailActivity extends AbsFabActivity implements OnMusicRemot
|
|||
super.destroyItem(container, position, object);
|
||||
}
|
||||
|
||||
public Fragment getItemAt(int position) {
|
||||
return pages.get(position, null);
|
||||
}
|
||||
|
||||
private Fragment getOrCreateFragmentAt(int position) {
|
||||
switch (position) {
|
||||
case 1:
|
||||
|
|
@ -488,6 +484,10 @@ public class ArtistDetailActivity extends AbsFabActivity implements OnMusicRemot
|
|||
}
|
||||
}
|
||||
|
||||
public Fragment getItemAt(int position) {
|
||||
return pages.get(position, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return titles.length;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
package com.kabouzeid.materialmusic.ui.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v13.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
|
|
@ -13,6 +16,7 @@ import android.support.v7.widget.SearchView;
|
|||
import android.support.v7.widget.Toolbar;
|
||||
import android.transition.Explode;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
|
@ -22,10 +26,10 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.google.samples.apps.iosched.ui.widget.SlidingTabLayout;
|
||||
import com.kabouzeid.materialmusic.R;
|
||||
import com.kabouzeid.materialmusic.helper.AboutDeveloperDialogHelper;
|
||||
import com.kabouzeid.materialmusic.helper.PlayingQueueDialogHelper;
|
||||
import com.kabouzeid.materialmusic.interfaces.KabSearchAbleFragment;
|
||||
import com.kabouzeid.materialmusic.interfaces.KabViewsDisableAble;
|
||||
import com.kabouzeid.materialmusic.interfaces.OnMusicRemoteEventListener;
|
||||
import com.kabouzeid.materialmusic.model.MusicRemoteEvent;
|
||||
|
|
@ -46,14 +50,14 @@ public class MainActivity extends AbsFabActivity
|
|||
implements NavigationDrawerFragment.NavigationDrawerCallbacks, OnMusicRemoteEventListener, KabViewsDisableAble {
|
||||
public static final String TAG = MainActivity.class.getSimpleName();
|
||||
|
||||
private int currentFragmentPosition = -1;
|
||||
|
||||
private DrawerLayout drawerLayout;
|
||||
private ActionBarDrawerToggle drawerToggle;
|
||||
private NavigationDrawerFragment navigationDrawerFragment;
|
||||
private CharSequence toolbarTitle;
|
||||
private Toolbar toolbar;
|
||||
private View statusBar;
|
||||
private MainActivityViewPagerAdapter viewPagerAdapter;
|
||||
private ViewPager viewPager;
|
||||
private SlidingTabLayout slidingTabLayout;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -63,6 +67,7 @@ public class MainActivity extends AbsFabActivity
|
|||
|
||||
initViews();
|
||||
setUpToolBar();
|
||||
setUpViewPager();
|
||||
|
||||
navigationDrawerFragment.setUp(
|
||||
R.id.navigation_drawer,
|
||||
|
|
@ -74,7 +79,17 @@ public class MainActivity extends AbsFabActivity
|
|||
}
|
||||
}
|
||||
|
||||
private void setUpViewPager() {
|
||||
viewPagerAdapter = new MainActivityViewPagerAdapter(this);
|
||||
viewPager.setAdapter(viewPagerAdapter);
|
||||
slidingTabLayout.setDistributeEvenly(true);
|
||||
slidingTabLayout.setSelectedIndicatorColors(Util.resolveColor(MainActivity.this, R.attr.colorAccent));
|
||||
slidingTabLayout.setViewPager(viewPager);
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
viewPager = (ViewPager) findViewById(R.id.pager);
|
||||
slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
navigationDrawerFragment = (NavigationDrawerFragment)
|
||||
getFragmentManager().findFragmentById(R.id.navigation_drawer);
|
||||
|
|
@ -96,8 +111,10 @@ public class MainActivity extends AbsFabActivity
|
|||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
statusBar = findViewById(R.id.statusBar);
|
||||
setSupportActionBar(toolbar);
|
||||
ViewUtil.setBackgroundAlpha(toolbar, 0.97f, Util.resolveColor(this, R.attr.colorPrimary));
|
||||
ViewUtil.setBackgroundAlpha(statusBar, 0.97f, Util.resolveColor(this, R.attr.colorPrimary));
|
||||
float alpha = 0.97f;
|
||||
ViewUtil.setBackgroundAlpha(toolbar, alpha, Util.resolveColor(this, R.attr.colorPrimary));
|
||||
ViewUtil.setBackgroundAlpha(statusBar, alpha, Util.resolveColor(this, R.attr.colorPrimary));
|
||||
ViewUtil.setBackgroundAlpha(slidingTabLayout, alpha, Util.resolveColor(this, R.attr.colorPrimary));
|
||||
setUpDrawerToggle();
|
||||
}
|
||||
|
||||
|
|
@ -117,6 +134,11 @@ public class MainActivity extends AbsFabActivity
|
|||
drawerLayout.setDrawerListener(drawerToggle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
|
@ -129,7 +151,7 @@ public class MainActivity extends AbsFabActivity
|
|||
super.enableViews();
|
||||
toolbar.setEnabled(true);
|
||||
} catch (NullPointerException e) {
|
||||
Log.e(TAG, "wasn't able to enable the views", e.fillInStackTrace());
|
||||
Log.e(TAG, "wasn't able to enable the views", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -139,13 +161,16 @@ public class MainActivity extends AbsFabActivity
|
|||
super.disableViews();
|
||||
toolbar.setEnabled(false);
|
||||
} catch (NullPointerException e) {
|
||||
Log.e(TAG, "wasn't able to disable the views", e.fillInStackTrace());
|
||||
Log.e(TAG, "wasn't able to disable the views", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
public void onMusicRemoteEvent(MusicRemoteEvent event) {
|
||||
super.onMusicRemoteEvent(event);
|
||||
if (event.getAction() == MusicRemoteEvent.STATE_RESTORED || event.getAction() == MusicRemoteEvent.TRACK_CHANGED) {
|
||||
updateNavigationDrawerHeader();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -153,54 +178,12 @@ public class MainActivity extends AbsFabActivity
|
|||
if (position == NavigationDrawerFragment.NAVIGATION_DRAWER_HEADER) {
|
||||
openCurrentPlayingIfPossible(null);
|
||||
} else {
|
||||
setFragment(position);
|
||||
goToFragment(position);
|
||||
}
|
||||
}
|
||||
|
||||
private void setFragment(int position) {
|
||||
if (currentFragmentPosition != position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
if (getApp().MainActivityFragments[position] == null) {
|
||||
getApp().MainActivityFragments[position] = new SongViewFragment();
|
||||
}
|
||||
toolbarTitle = getString(R.string.all_songs);
|
||||
break;
|
||||
case 1:
|
||||
if (getApp().MainActivityFragments[position] == null) {
|
||||
getApp().MainActivityFragments[position] = new AlbumViewFragment();
|
||||
}
|
||||
toolbarTitle = getString(R.string.albums);
|
||||
break;
|
||||
case 2:
|
||||
if (getApp().MainActivityFragments[position] == null) {
|
||||
getApp().MainActivityFragments[position] = new ArtistViewFragment();
|
||||
}
|
||||
toolbarTitle = getString(R.string.artists);
|
||||
break;
|
||||
case 3:
|
||||
if (getApp().MainActivityFragments[position] == null) {
|
||||
getApp().MainActivityFragments[position] = new PlaceholderFragment();
|
||||
}
|
||||
toolbarTitle = getString(R.string.genres);
|
||||
break;
|
||||
case 4:
|
||||
if (getApp().MainActivityFragments[position] == null) {
|
||||
getApp().MainActivityFragments[position] = new PlaceholderFragment();
|
||||
}
|
||||
toolbarTitle = getString(R.string.playlists);
|
||||
break;
|
||||
default:
|
||||
toolbarTitle = getString(R.string.app_name);
|
||||
return;
|
||||
}
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.container, getApp().MainActivityFragments[position])
|
||||
.commit();
|
||||
currentFragmentPosition = position;
|
||||
supportInvalidateOptionsMenu();
|
||||
}
|
||||
private void goToFragment(int position) {
|
||||
//TODO goToFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -209,7 +192,7 @@ public class MainActivity extends AbsFabActivity
|
|||
restoreActionBar();
|
||||
|
||||
final MenuItem search = menu.findItem(R.id.action_search);
|
||||
search.setVisible(currentFragmentPosition != -1 && getApp().MainActivityFragments[currentFragmentPosition] instanceof KabSearchAbleFragment);
|
||||
search.setVisible(true); //TODO only when fragment is searchable
|
||||
|
||||
|
||||
SearchView searchView = (SearchView) MenuItemCompat.getActionView(search);
|
||||
|
|
@ -221,9 +204,7 @@ public class MainActivity extends AbsFabActivity
|
|||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if (currentFragmentPosition != -1 && getApp().MainActivityFragments[currentFragmentPosition] instanceof KabSearchAbleFragment) {
|
||||
((KabSearchAbleFragment) getApp().MainActivityFragments[currentFragmentPosition]).search(newText);
|
||||
}
|
||||
//TODO start search
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
|
@ -236,9 +217,7 @@ public class MainActivity extends AbsFabActivity
|
|||
|
||||
@Override
|
||||
public boolean onMenuItemActionCollapse(MenuItem item) {
|
||||
if (currentFragmentPosition != -1 && getApp().MainActivityFragments[currentFragmentPosition] instanceof KabSearchAbleFragment) {
|
||||
((KabSearchAbleFragment) getApp().MainActivityFragments[currentFragmentPosition]).returnToNonSearch();
|
||||
}
|
||||
//TODO finish search
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
|
@ -250,7 +229,6 @@ public class MainActivity extends AbsFabActivity
|
|||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
actionBar.setTitle(toolbarTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -302,38 +280,17 @@ public class MainActivity extends AbsFabActivity
|
|||
}
|
||||
|
||||
private void disableFragmentViews() {
|
||||
if (currentFragmentPosition >= 0 && currentFragmentPosition < getApp().MainActivityFragments.length) {
|
||||
if (getApp().MainActivityFragments[currentFragmentPosition] instanceof KabViewsDisableAble) {
|
||||
((KabViewsDisableAble) getApp().MainActivityFragments[currentFragmentPosition]).disableViews();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void enableFragmentViews() {
|
||||
if (currentFragmentPosition >= 0 && currentFragmentPosition < getApp().MainActivityFragments.length) {
|
||||
if (getApp().MainActivityFragments[currentFragmentPosition] instanceof KabViewsDisableAble) {
|
||||
((KabViewsDisableAble) getApp().MainActivityFragments[currentFragmentPosition]).enableViews();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean areFragmentViewsEnabled() {
|
||||
if (currentFragmentPosition >= 0 && currentFragmentPosition < getApp().MainActivityFragments.length) {
|
||||
if (getApp().MainActivityFragments[currentFragmentPosition] instanceof KabViewsDisableAble) {
|
||||
return ((KabViewsDisableAble) getApp().MainActivityFragments[currentFragmentPosition]).areViewsEnabled();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMusicRemoteEvent(MusicRemoteEvent event) {
|
||||
super.onMusicRemoteEvent(event);
|
||||
if (event.getAction() == MusicRemoteEvent.STATE_RESTORED || event.getAction() == MusicRemoteEvent.TRACK_CHANGED) {
|
||||
updateNavigationDrawerHeader();
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlaceholderFragment extends Fragment {
|
||||
|
||||
public PlaceholderFragment() {
|
||||
|
|
@ -343,9 +300,57 @@ public class MainActivity extends AbsFabActivity
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_place_holder, container, false);
|
||||
TextView text = (TextView)rootView.findViewById(R.id.text);
|
||||
TextView text = (TextView) rootView.findViewById(R.id.text);
|
||||
text.setText("Coming soon!");
|
||||
return rootView;
|
||||
}
|
||||
}
|
||||
|
||||
private class MainActivityViewPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
private String[] titles;
|
||||
|
||||
private SparseArray<Fragment> pages; //TODO check if this must be static
|
||||
private Context context;
|
||||
|
||||
public MainActivityViewPagerAdapter(Activity activity) {
|
||||
super(activity.getFragmentManager());
|
||||
pages = new SparseArray<>();
|
||||
context = activity;
|
||||
titles = new String[]{
|
||||
context.getResources().getString(R.string.all_songs),
|
||||
context.getResources().getString(R.string.albums),
|
||||
context.getResources().getString(R.string.artists),
|
||||
context.getResources().getString(R.string.genres),
|
||||
context.getResources().getString(R.string.playlists)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(final int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return pages.get(position, new SongViewFragment());
|
||||
case 1:
|
||||
return pages.get(position, new AlbumViewFragment());
|
||||
case 2:
|
||||
return pages.get(position, new ArtistViewFragment());
|
||||
case 3:
|
||||
//TODO genres
|
||||
case 4:
|
||||
//TODO playlists
|
||||
}
|
||||
return pages.get(position, new PlaceholderFragment());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return titles.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return titles[position];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,104 +83,6 @@ public class MusicControllerActivity extends AbsFabActivity implements OnMusicRe
|
|||
setUpToolBar();
|
||||
}
|
||||
|
||||
private void updateCurrentSong() {
|
||||
getCurrentSong();
|
||||
setHeadersText();
|
||||
setUpArtistArt();
|
||||
setUpAlbumArtAndApplyPalette();
|
||||
totalSongDuration.setText(MusicUtil.getReadableDurationString(song.duration));
|
||||
currentSongProgress.setText(MusicUtil.getReadableDurationString(-1));
|
||||
}
|
||||
|
||||
private void setHeadersText() {
|
||||
songTitle.setText(song.title);
|
||||
songArtist.setText(song.artistName);
|
||||
}
|
||||
|
||||
private void setUpAlbumArtAndApplyPalette() {
|
||||
ImageLoader.getInstance().displayImage(MusicUtil.getAlbumArtUri(song.albumId).toString(), albumArt, new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
albumArt.setImageResource(R.drawable.default_album_art);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
albumArt.setImageResource(R.drawable.default_album_art);
|
||||
setStandardColors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, final View view, Bitmap loadedImage) {
|
||||
applyPalette(loadedImage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
albumArt.setImageResource(R.drawable.default_album_art);
|
||||
setStandardColors();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void applyPalette(Bitmap bitmap) {
|
||||
Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
|
||||
@Override
|
||||
public void onGenerated(Palette palette) {
|
||||
Palette.Swatch swatch = palette.getVibrantSwatch();
|
||||
if (swatch != null) {
|
||||
animateColorChange(swatch.getRgb());
|
||||
songTitle.setTextColor(swatch.getTitleTextColor());
|
||||
songArtist.setTextColor(swatch.getBodyTextColor());
|
||||
} else {
|
||||
setStandardColors();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setStandardColors() {
|
||||
int songTitleTextColor = Util.resolveColor(this, R.attr.title_text_color);
|
||||
int artistNameTextColor = Util.resolveColor(this, R.attr.caption_text_color);
|
||||
int colorPrimary = Util.resolveColor(MusicControllerActivity.this, R.attr.colorPrimary);
|
||||
|
||||
animateColorChange(colorPrimary);
|
||||
|
||||
songTitle.setTextColor(songTitleTextColor);
|
||||
songArtist.setTextColor(artistNameTextColor);
|
||||
}
|
||||
|
||||
private void animateColorChange(final int newColor) {
|
||||
if (lastFooterColor != -1 && lastFooterColor != newColor) {
|
||||
ViewUtil.animateViewColor(footer, lastFooterColor, newColor, 300);
|
||||
} else {
|
||||
footer.setBackgroundColor(newColor);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
getWindow().setNavigationBarColor(newColor);
|
||||
}
|
||||
lastFooterColor = newColor;
|
||||
}
|
||||
|
||||
private void setUpArtistArt() {
|
||||
if (artistArt != null) {
|
||||
artistArt.setImageResource(R.drawable.default_artist_image);
|
||||
LastFMArtistImageLoader.loadArtistImage(this, song.artistName, new LastFMArtistImageLoader.ArtistImageLoaderCallback() {
|
||||
@Override
|
||||
public void onArtistImageLoaded(Bitmap artistImage) {
|
||||
artistArt.setImageBitmap(artistImage);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void getCurrentSong() {
|
||||
song = getApp().getMusicPlayerRemote().getCurrentSong();
|
||||
if(song.id == -1){
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void moveSeekBarIntoPlace() {
|
||||
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) progressSlider.getLayoutParams();
|
||||
progressSlider.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
|
||||
|
|
@ -300,6 +202,11 @@ public class MusicControllerActivity extends AbsFabActivity implements OnMusicRe
|
|||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
|
@ -307,6 +214,104 @@ public class MusicControllerActivity extends AbsFabActivity implements OnMusicRe
|
|||
updateCurrentSong();
|
||||
}
|
||||
|
||||
private void updateCurrentSong() {
|
||||
getCurrentSong();
|
||||
setHeadersText();
|
||||
setUpArtistArt();
|
||||
setUpAlbumArtAndApplyPalette();
|
||||
totalSongDuration.setText(MusicUtil.getReadableDurationString(song.duration));
|
||||
currentSongProgress.setText(MusicUtil.getReadableDurationString(-1));
|
||||
}
|
||||
|
||||
private void setHeadersText() {
|
||||
songTitle.setText(song.title);
|
||||
songArtist.setText(song.artistName);
|
||||
}
|
||||
|
||||
private void setUpAlbumArtAndApplyPalette() {
|
||||
ImageLoader.getInstance().displayImage(MusicUtil.getAlbumArtUri(song.albumId).toString(), albumArt, new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
albumArt.setImageResource(R.drawable.default_album_art);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
albumArt.setImageResource(R.drawable.default_album_art);
|
||||
setStandardColors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, final View view, Bitmap loadedImage) {
|
||||
applyPalette(loadedImage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
albumArt.setImageResource(R.drawable.default_album_art);
|
||||
setStandardColors();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void applyPalette(Bitmap bitmap) {
|
||||
Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
|
||||
@Override
|
||||
public void onGenerated(Palette palette) {
|
||||
Palette.Swatch swatch = palette.getVibrantSwatch();
|
||||
if (swatch != null) {
|
||||
animateColorChange(swatch.getRgb());
|
||||
songTitle.setTextColor(swatch.getTitleTextColor());
|
||||
songArtist.setTextColor(swatch.getBodyTextColor());
|
||||
} else {
|
||||
setStandardColors();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setStandardColors() {
|
||||
int songTitleTextColor = Util.resolveColor(this, R.attr.title_text_color);
|
||||
int artistNameTextColor = Util.resolveColor(this, R.attr.caption_text_color);
|
||||
int colorPrimary = Util.resolveColor(MusicControllerActivity.this, R.attr.colorPrimary);
|
||||
|
||||
animateColorChange(colorPrimary);
|
||||
|
||||
songTitle.setTextColor(songTitleTextColor);
|
||||
songArtist.setTextColor(artistNameTextColor);
|
||||
}
|
||||
|
||||
private void animateColorChange(final int newColor) {
|
||||
if (lastFooterColor != -1 && lastFooterColor != newColor) {
|
||||
ViewUtil.animateViewColor(footer, lastFooterColor, newColor, 300);
|
||||
} else {
|
||||
footer.setBackgroundColor(newColor);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
getWindow().setNavigationBarColor(newColor);
|
||||
}
|
||||
lastFooterColor = newColor;
|
||||
}
|
||||
|
||||
private void setUpArtistArt() {
|
||||
if (artistArt != null) {
|
||||
artistArt.setImageResource(R.drawable.default_artist_image);
|
||||
LastFMArtistImageLoader.loadArtistImage(this, song.artistName, new LastFMArtistImageLoader.ArtistImageLoaderCallback() {
|
||||
@Override
|
||||
public void onArtistImageLoaded(Bitmap artistImage) {
|
||||
artistArt.setImageBitmap(artistImage);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void getCurrentSong() {
|
||||
song = getApp().getMusicPlayerRemote().getCurrentSong();
|
||||
if (song.id == -1) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void startMusicControllerStateUpdateThread() {
|
||||
killThreads = false;
|
||||
new Thread(new Runnable() {
|
||||
|
|
@ -344,11 +349,6 @@ public class MusicControllerActivity extends AbsFabActivity implements OnMusicRe
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateControllerState() {
|
||||
super.updateControllerState();
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ public abstract class AbsBaseActivity extends ActionBarActivity implements KabVi
|
|||
return app;
|
||||
}
|
||||
|
||||
public abstract String getTag();
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
|
@ -127,6 +129,4 @@ public abstract class AbsBaseActivity extends ActionBarActivity implements KabVi
|
|||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract String getTag();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public abstract class AbsFabActivity extends AbsBaseActivity implements OnMusicR
|
|||
protected FloatingActionButton getFab() {
|
||||
if (fab == null) {
|
||||
fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
if(fab == null){
|
||||
if (fab == null) {
|
||||
fab = new FloatingActionButton(this);
|
||||
Log.e(getTag(), "No FAB found created default FAB.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -438,42 +438,48 @@ public abstract class AbsTagEditorActivity extends ActionBarActivity {
|
|||
protected String getAlbumTitle() {
|
||||
try {
|
||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM);
|
||||
} catch (NullPointerException ignored) {}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getArtistName() {
|
||||
try {
|
||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ARTIST);
|
||||
} catch (NullPointerException ignored) {}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getAlbumArtistName() {
|
||||
try {
|
||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM_ARTIST);
|
||||
} catch (NullPointerException ignored) {}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getGenreName() {
|
||||
try {
|
||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.GENRE);
|
||||
} catch (NullPointerException ignored) {}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getSongYear() {
|
||||
try {
|
||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.YEAR);
|
||||
} catch (NullPointerException ignored) {}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getTrackNumber() {
|
||||
try {
|
||||
return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TRACK);
|
||||
} catch (NullPointerException ignored) {}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -484,7 +490,8 @@ public abstract class AbsTagEditorActivity extends ActionBarActivity {
|
|||
byte[] artworkBinaryData = artworkTag.getBinaryData();
|
||||
return BitmapFactory.decodeByteArray(artworkBinaryData, 0, artworkBinaryData.length);
|
||||
}
|
||||
} catch (NullPointerException ignored) {}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package com.kabouzeid.materialmusic.ui.fragments.mainactivityfragments;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.ActivityOptionsCompat;
|
||||
|
|
@ -17,13 +15,11 @@ import com.kabouzeid.materialmusic.App;
|
|||
import com.kabouzeid.materialmusic.R;
|
||||
import com.kabouzeid.materialmusic.adapter.AlbumViewGridAdapter;
|
||||
import com.kabouzeid.materialmusic.comparator.AlbumAlphabeticComparator;
|
||||
import com.kabouzeid.materialmusic.interfaces.KabSearchAbleFragment;
|
||||
import com.kabouzeid.materialmusic.interfaces.KabViewsDisableAble;
|
||||
import com.kabouzeid.materialmusic.loader.AlbumLoader;
|
||||
import com.kabouzeid.materialmusic.misc.AppKeys;
|
||||
import com.kabouzeid.materialmusic.model.Album;
|
||||
import com.kabouzeid.materialmusic.ui.activities.AlbumDetailActivity;
|
||||
import com.kabouzeid.materialmusic.util.Util;
|
||||
import com.melnykov.fab.FloatingActionButton;
|
||||
|
||||
import java.util.Collections;
|
||||
|
|
@ -32,7 +28,7 @@ import java.util.List;
|
|||
/**
|
||||
* Created by karim on 22.11.14.
|
||||
*/
|
||||
public class AlbumViewFragment extends Fragment implements KabViewsDisableAble, KabSearchAbleFragment {
|
||||
public class AlbumViewFragment extends MainActivityFragment {
|
||||
public static final String TAG = AlbumViewFragment.class.getSimpleName();
|
||||
|
||||
private App app;
|
||||
|
|
@ -113,15 +109,7 @@ public class AlbumViewFragment extends Fragment implements KabViewsDisableAble,
|
|||
}
|
||||
});
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
if (app.isInPortraitMode() || app.isTablet()) {
|
||||
absListView.setPadding(0, Util.getActionBarSize(getActivity()) + Util.getStatusBarHeight(getActivity()), 0, Util.getNavigationBarHeight(getActivity()));
|
||||
} else {
|
||||
absListView.setPadding(0, Util.getActionBarSize(getActivity()) + Util.getStatusBarHeight(getActivity()), 0, 0);
|
||||
}
|
||||
} else {
|
||||
absListView.setPadding(0, Util.getActionBarSize(getActivity()), 0, 0);
|
||||
}
|
||||
absListView.setPadding(0, getTopPadding(app), 0, getBottomPadding(app));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package com.kabouzeid.materialmusic.ui.fragments.mainactivityfragments;
|
|||
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.view.LayoutInflater;
|
||||
|
|
@ -16,14 +15,12 @@ import com.kabouzeid.materialmusic.App;
|
|||
import com.kabouzeid.materialmusic.R;
|
||||
import com.kabouzeid.materialmusic.adapter.ArtistViewListAdapter;
|
||||
import com.kabouzeid.materialmusic.comparator.ArtistAlphabeticComparator;
|
||||
import com.kabouzeid.materialmusic.interfaces.KabSearchAbleFragment;
|
||||
import com.kabouzeid.materialmusic.interfaces.KabViewsDisableAble;
|
||||
import com.kabouzeid.materialmusic.loader.ArtistLoader;
|
||||
import com.kabouzeid.materialmusic.misc.AppKeys;
|
||||
import com.kabouzeid.materialmusic.model.Artist;
|
||||
import com.kabouzeid.materialmusic.ui.activities.ArtistDetailActivity;
|
||||
import com.kabouzeid.materialmusic.ui.activities.base.AbsFabActivity;
|
||||
import com.kabouzeid.materialmusic.util.Util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
@ -31,7 +28,7 @@ import java.util.List;
|
|||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
public class ArtistViewFragment extends Fragment implements KabSearchAbleFragment, KabViewsDisableAble {
|
||||
public class ArtistViewFragment extends MainActivityFragment {
|
||||
public static final String TAG = ArtistViewFragment.class.getSimpleName();
|
||||
|
||||
private App app;
|
||||
|
|
@ -117,15 +114,8 @@ public class ArtistViewFragment extends Fragment implements KabSearchAbleFragmen
|
|||
}
|
||||
});
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
if (app.isInPortraitMode() || app.isTablet()) {
|
||||
absListView.setPadding(0, Util.getActionBarSize(getActivity()) + Util.getStatusBarHeight(getActivity()), 0, Util.getNavigationBarHeight(getActivity()));
|
||||
} else {
|
||||
absListView.setPadding(0, Util.getActionBarSize(getActivity()) + Util.getStatusBarHeight(getActivity()), 0, 0);
|
||||
}
|
||||
} else {
|
||||
absListView.setPadding(0, Util.getActionBarSize(getActivity()), 0, 0);
|
||||
}
|
||||
absListView.setPadding(0, getTopPadding(app), 0, getBottomPadding(app));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
package com.kabouzeid.materialmusic.ui.fragments.mainactivityfragments;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.os.Build;
|
||||
|
||||
import com.kabouzeid.materialmusic.App;
|
||||
import com.kabouzeid.materialmusic.R;
|
||||
import com.kabouzeid.materialmusic.interfaces.KabSearchAbleFragment;
|
||||
import com.kabouzeid.materialmusic.interfaces.KabViewsDisableAble;
|
||||
import com.kabouzeid.materialmusic.util.Util;
|
||||
|
||||
/**
|
||||
* Created by karim on 27.02.15.
|
||||
*/
|
||||
public abstract class MainActivityFragment extends Fragment implements KabViewsDisableAble, KabSearchAbleFragment {
|
||||
protected int getTopPadding(App app) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
if (app.isInPortraitMode() || app.isTablet()) {
|
||||
return Util.getActionBarSize(getActivity()) + getResources().getDimensionPixelSize(R.dimen.tab_height) + Util.getStatusBarHeight(getActivity());
|
||||
}
|
||||
return Util.getActionBarSize(getActivity()) + getResources().getDimensionPixelSize(R.dimen.tab_height) + Util.getStatusBarHeight(getActivity());
|
||||
}
|
||||
return Util.getActionBarSize(getActivity()) + getResources().getDimensionPixelSize(R.dimen.tab_height);
|
||||
}
|
||||
|
||||
protected int getBottomPadding(App app) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
if (app.isInPortraitMode() || app.isTablet()) {
|
||||
return Util.getNavigationBarHeight(getActivity());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
package com.kabouzeid.materialmusic.ui.fragments.mainactivityfragments;
|
||||
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
|
@ -14,11 +12,9 @@ import com.kabouzeid.materialmusic.App;
|
|||
import com.kabouzeid.materialmusic.R;
|
||||
import com.kabouzeid.materialmusic.adapter.songadapter.SongViewListAdapter;
|
||||
import com.kabouzeid.materialmusic.comparator.SongAlphabeticComparator;
|
||||
import com.kabouzeid.materialmusic.interfaces.KabSearchAbleFragment;
|
||||
import com.kabouzeid.materialmusic.loader.SongLoader;
|
||||
import com.kabouzeid.materialmusic.model.Song;
|
||||
import com.kabouzeid.materialmusic.ui.activities.base.AbsBaseActivity;
|
||||
import com.kabouzeid.materialmusic.util.Util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
@ -26,7 +22,7 @@ import java.util.List;
|
|||
/**
|
||||
* Created by karim on 29.12.14.
|
||||
*/
|
||||
public class SongViewFragment extends Fragment implements KabSearchAbleFragment {
|
||||
public class SongViewFragment extends MainActivityFragment {
|
||||
public static final String TAG = SongViewFragment.class.getSimpleName();
|
||||
|
||||
private App app;
|
||||
|
|
@ -81,15 +77,7 @@ public class SongViewFragment extends Fragment implements KabSearchAbleFragment
|
|||
}
|
||||
});
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
if (app.isInPortraitMode() || app.isTablet()) {
|
||||
absListView.setPadding(0, Util.getActionBarSize(getActivity()) + Util.getStatusBarHeight(getActivity()), 0, Util.getNavigationBarHeight(getActivity()));
|
||||
} else {
|
||||
absListView.setPadding(0, Util.getActionBarSize(getActivity()) + Util.getStatusBarHeight(getActivity()), 0, 0);
|
||||
}
|
||||
} else {
|
||||
absListView.setPadding(0, Util.getActionBarSize(getActivity()), 0, 0);
|
||||
}
|
||||
absListView.setPadding(0, getTopPadding(app), 0, getBottomPadding(app));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -106,4 +94,19 @@ public class SongViewFragment extends Fragment implements KabSearchAbleFragment
|
|||
public void returnToNonSearch() {
|
||||
setUpAbsListView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableViews() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableViews() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areViewsEnabled() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,12 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/container"
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"/>
|
||||
android:clipToPadding="false"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -42,6 +43,13 @@
|
|||
android:background="?colorPrimary"
|
||||
android:elevation="@dimen/toolbar_elevation"
|
||||
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
||||
|
||||
<com.google.samples.apps.iosched.ui.widget.SlidingTabLayout
|
||||
android:id="@+id/sliding_tabs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/tab_height"
|
||||
android:background="?colorPrimary"
|
||||
android:elevation="2dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
@ -60,13 +68,6 @@
|
|||
|
||||
</FrameLayout>
|
||||
|
||||
<!-- android:layout_gravity="start" tells DrawerLayout to treat
|
||||
this as a sliding drawer on the left side for left-to-right
|
||||
languages and on the right side for right-to-left languages.
|
||||
If you're not building against API 17 or higher, use
|
||||
android:layout_gravity="left" instead. -->
|
||||
<!-- The drawer is given a fixed width in dp and extends the full height of
|
||||
the container. -->
|
||||
<fragment
|
||||
android:id="@+id/navigation_drawer"
|
||||
android:name="com.kabouzeid.materialmusic.ui.fragments.NavigationDrawerFragment"
|
||||
|
|
|
|||
9
app/src/main/res/menu/menu_tab_test.xml
Normal file
9
app/src/main/res/menu/menu_tab_test.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.kabouzeid.materialmusic.ui.activities.TabTest">
|
||||
<item android:id="@+id/action_settings"
|
||||
android:title="@string/action_settings"
|
||||
android:orderInCategory="100"
|
||||
app:showAsAction="never"/>
|
||||
</menu>
|
||||
Loading…
Add table
Add a link
Reference in a new issue