New Search Everywhere
This commit is contained in:
parent
41502ee01e
commit
df9a451242
24 changed files with 516 additions and 140 deletions
|
|
@ -0,0 +1,54 @@
|
|||
package com.kabouzeid.materialmusic.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kabouzeid.materialmusic.R;
|
||||
import com.kabouzeid.materialmusic.model.SearchEntry;
|
||||
import com.kabouzeid.materialmusic.ui.activities.SearchActivity;
|
||||
import com.kabouzeid.materialmusic.util.Util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by karim on 27.02.15.
|
||||
*/
|
||||
public class SearchAdapter extends ArrayAdapter<SearchEntry> {
|
||||
|
||||
public SearchAdapter(Context context, List<SearchEntry> objects) {
|
||||
super(context, R.layout.item_search, objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (convertView == null) {
|
||||
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_search, parent, false);
|
||||
}
|
||||
|
||||
SearchEntry item = getItem(position);
|
||||
|
||||
final TextView title = (TextView) convertView.findViewById(R.id.title);
|
||||
final TextView subTitle = (TextView) convertView.findViewById(R.id.sub_title);
|
||||
final ImageView imageView = (ImageView) convertView.findViewById(R.id.image);
|
||||
|
||||
if (item instanceof SearchActivity.LabelEntry) {
|
||||
subTitle.setVisibility(View.GONE);
|
||||
convertView.setBackgroundColor(Util.resolveColor(getContext(), R.attr.colorPrimary));
|
||||
} else {
|
||||
subTitle.setVisibility(View.VISIBLE);
|
||||
convertView.setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
title.setText(item.getTitle());
|
||||
subTitle.setText(item.getSubTitle());
|
||||
item.loadImage(imageView);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ import android.provider.MediaStore;
|
|||
import com.kabouzeid.materialmusic.model.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -15,6 +17,12 @@ import java.util.List;
|
|||
*/
|
||||
public class AlbumSongLoader {
|
||||
|
||||
public static List<Song> getAlbumSongList(final Context context, final int albumId, Comparator<Song> comparator) {
|
||||
List<Song> songs = getAlbumSongList(context, albumId);
|
||||
Collections.sort(songs, comparator);
|
||||
return songs;
|
||||
}
|
||||
|
||||
public static List<Song> getAlbumSongList(final Context context, final int albumId) {
|
||||
Cursor cursor = makeAlbumSongCursor(context, albumId);
|
||||
List<Song> songs = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ public final class AppKeys {
|
|||
public static final String CL_CURRENT_ACTIVITY = "Current activity";
|
||||
|
||||
public static final String SP_THEME = "com.kabouzeid.materialmusic.THEME";
|
||||
public static final String SP_NAVIGATION_DRAWER_ITEM_POSITION = "com.kabouzeid.materialmusic.NAVIGATION_DRAWER_ITEM_POSITION";
|
||||
public static final String SP_VIEWPAGER_ITEM_POSITION = "com.kabouzeid.materialmusic.NAVIGATION_DRAWER_ITEM_POSITION";
|
||||
public static final String SP_USER_LEARNED_DRAWER = "com.kabouzeid.materialmusic.NAVIGATION_DRAWER_LEARNED";
|
||||
public static final String SP_ONLY_ON_WIFI = "com.kabouzeid.materialmusic.ONLY_ON_WIFI";
|
||||
public static final String SP_SHUFFLE_MODE = "com.kabouzeid.materialmusic.SHUFFLE_MODE";
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.kabouzeid.materialmusic.model;
|
||||
|
||||
import android.widget.ImageView;
|
||||
|
||||
/**
|
||||
* Created by karim on 22.11.14.
|
||||
*/
|
||||
public class Album {
|
||||
public class Album implements SearchEntry {
|
||||
|
||||
public int id;
|
||||
public int artistId;
|
||||
|
|
@ -29,4 +31,19 @@ public class Album {
|
|||
songCount = -1;
|
||||
year = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSubTitle() {
|
||||
return artistName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadImage(ImageView imageView) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
package com.kabouzeid.materialmusic.model;
|
||||
|
||||
import android.widget.ImageView;
|
||||
|
||||
/**
|
||||
* Created by karim on 29.12.14.
|
||||
*/
|
||||
public class Artist {
|
||||
public class Artist implements SearchEntry {
|
||||
public int id;
|
||||
public String name;
|
||||
public int albumCount;
|
||||
public int songCount;
|
||||
|
||||
public Artist(final int id, final String name, final int songCount,
|
||||
final int albumCount) {
|
||||
public Artist(final int id, final String name, final int albumCount, final int songCount) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.songCount = songCount;
|
||||
|
|
@ -23,4 +24,19 @@ public class Artist {
|
|||
songCount = -1;
|
||||
albumCount = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSubTitle() {
|
||||
return songCount + " Songs | " + albumCount + " Albums";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadImage(ImageView imageView) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.kabouzeid.materialmusic.model;
|
||||
|
||||
import android.widget.ImageView;
|
||||
|
||||
/**
|
||||
* Created by karim on 27.02.15.
|
||||
*/
|
||||
public interface SearchEntry {
|
||||
public String getTitle();
|
||||
|
||||
public String getSubTitle();
|
||||
|
||||
public void loadImage(ImageView imageView);
|
||||
}
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
package com.kabouzeid.materialmusic.model;
|
||||
|
||||
import android.widget.ImageView;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by karim on 23.11.14.
|
||||
*/
|
||||
public class Song implements Serializable {
|
||||
public class Song implements Serializable, SearchEntry {
|
||||
public int id;
|
||||
public int albumId;
|
||||
public int artistId;
|
||||
|
|
@ -37,4 +39,19 @@ public class Song implements Serializable {
|
|||
this.duration = -1;
|
||||
this.trackNumber = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSubTitle() {
|
||||
return artistName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadImage(ImageView imageView) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,12 +78,6 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
|||
albumAndArtistName.trim().toLowerCase()
|
||||
});
|
||||
|
||||
} @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 interface AlbumJSONColumns {
|
||||
|
|
@ -92,7 +86,13 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
|||
public static final String JSON = "JSON";
|
||||
}
|
||||
|
||||
|
||||
@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);"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -78,12 +78,6 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
|||
artistName.trim().toLowerCase()
|
||||
});
|
||||
|
||||
} @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 interface ArtistJSONColumns {
|
||||
|
|
@ -92,7 +86,13 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
|||
public static final String JSON = "JSON";
|
||||
}
|
||||
|
||||
|
||||
@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);"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ import com.nostra13.universalimageloader.core.ImageLoader;
|
|||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
|
|
@ -329,8 +328,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements OnMusicRemote
|
|||
}
|
||||
|
||||
private void setUpSongsAdapter() {
|
||||
final List<Song> songs = AlbumSongLoader.getAlbumSongList(this, album.id);
|
||||
Collections.sort(songs, new SongTrackNumberComparator());
|
||||
final List<Song> songs = AlbumSongLoader.getAlbumSongList(this, album.id, new SongTrackNumberComparator());
|
||||
final SongAdapter songAdapter = new SongAdapter(this, this, songs);
|
||||
|
||||
// SwingBottomInAnimationAdapter songsAdapter = new SwingBottomInAnimationAdapter(songAdapter);
|
||||
|
|
@ -410,7 +408,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements OnMusicRemote
|
|||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.action_go_to_artist:
|
||||
goToArtistDetailsActivity(album.artistId, null);
|
||||
goToArtist(album.artistId, null);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
|||
|
|
@ -3,15 +3,14 @@ package com.kabouzeid.materialmusic.ui.activities;
|
|||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
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;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
|
|
@ -30,6 +29,7 @@ import com.kabouzeid.materialmusic.helper.AboutDeveloperDialogHelper;
|
|||
import com.kabouzeid.materialmusic.helper.PlayingQueueDialogHelper;
|
||||
import com.kabouzeid.materialmusic.interfaces.KabViewsDisableAble;
|
||||
import com.kabouzeid.materialmusic.interfaces.OnMusicRemoteEventListener;
|
||||
import com.kabouzeid.materialmusic.misc.AppKeys;
|
||||
import com.kabouzeid.materialmusic.model.MusicRemoteEvent;
|
||||
import com.kabouzeid.materialmusic.model.Song;
|
||||
import com.kabouzeid.materialmusic.ui.activities.base.AbsFabActivity;
|
||||
|
|
@ -64,21 +64,40 @@ public class MainActivity extends AbsFabActivity
|
|||
setContentView(R.layout.activity_main);
|
||||
|
||||
initViews();
|
||||
setUpToolBar();
|
||||
setUpViewPager();
|
||||
|
||||
navigationDrawerFragment.setUp(
|
||||
R.id.navigation_drawer,
|
||||
drawerLayout
|
||||
);
|
||||
setUpToolBar();
|
||||
setUpViewPager();
|
||||
}
|
||||
|
||||
private void setUpViewPager() {
|
||||
viewPagerAdapter = new MainActivityViewPagerAdapter(this);
|
||||
viewPager.setAdapter(viewPagerAdapter);
|
||||
//slidingTabLayout.setDistributeEvenly(true);
|
||||
int startPosition = getApp().getDefaultSharedPreferences().getInt(AppKeys.SP_VIEWPAGER_ITEM_POSITION, 1);
|
||||
viewPager.setCurrentItem(startPosition);
|
||||
navigationDrawerFragment.setItemChecked(startPosition);
|
||||
|
||||
slidingTabLayout.setSelectedIndicatorColors(Util.resolveColor(MainActivity.this, R.attr.colorAccent));
|
||||
slidingTabLayout.setViewPager(viewPager);
|
||||
slidingTabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(final int position) {
|
||||
getApp().getDefaultSharedPreferences().edit().putInt(AppKeys.SP_VIEWPAGER_ITEM_POSITION, position).apply();
|
||||
navigationDrawerFragment.setItemChecked(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
|
|
@ -87,18 +106,6 @@ public class MainActivity extends AbsFabActivity
|
|||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
navigationDrawerFragment = (NavigationDrawerFragment)
|
||||
getFragmentManager().findFragmentById(R.id.navigation_drawer);
|
||||
updateNavigationDrawerHeader();
|
||||
}
|
||||
|
||||
private void updateNavigationDrawerHeader() {
|
||||
if (navigationDrawerFragment != null) {
|
||||
Song song = getApp().getMusicPlayerRemote().getCurrentSong();
|
||||
if (song.id != -1) {
|
||||
ImageLoader.getInstance().displayImage(MusicUtil.getAlbumArtUri(song.albumId).toString(), navigationDrawerFragment.getAlbumArtImageView(), new ImageLoaderUtil.defaultAlbumArtOnFailed());
|
||||
navigationDrawerFragment.getSongTitle().setText(song.title);
|
||||
navigationDrawerFragment.getSongArtist().setText(song.artistName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpToolBar() {
|
||||
|
|
@ -139,6 +146,17 @@ public class MainActivity extends AbsFabActivity
|
|||
updateNavigationDrawerHeader();
|
||||
}
|
||||
|
||||
private void updateNavigationDrawerHeader() {
|
||||
if (navigationDrawerFragment != null) {
|
||||
Song song = getApp().getMusicPlayerRemote().getCurrentSong();
|
||||
if (song.id != -1) {
|
||||
ImageLoader.getInstance().displayImage(MusicUtil.getAlbumArtUri(song.albumId).toString(), navigationDrawerFragment.getAlbumArtImageView(), new ImageLoaderUtil.defaultAlbumArtOnFailed());
|
||||
navigationDrawerFragment.getSongTitle().setText(song.title);
|
||||
navigationDrawerFragment.getSongArtist().setText(song.artistName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableViews() {
|
||||
try {
|
||||
|
|
@ -172,49 +190,16 @@ public class MainActivity extends AbsFabActivity
|
|||
if (position == NavigationDrawerFragment.NAVIGATION_DRAWER_HEADER) {
|
||||
openCurrentPlayingIfPossible(null);
|
||||
} else {
|
||||
goToFragment(position);
|
||||
if (viewPager != null) {
|
||||
viewPager.setCurrentItem(position, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void goToFragment(int position) {
|
||||
//TODO goToFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.drawer, menu);
|
||||
restoreActionBar();
|
||||
|
||||
final MenuItem search = menu.findItem(R.id.action_search);
|
||||
search.setVisible(true); //TODO only when fragment is searchable
|
||||
|
||||
|
||||
SearchView searchView = (SearchView) MenuItemCompat.getActionView(search);
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
//TODO start search
|
||||
return false;
|
||||
}
|
||||
});
|
||||
MenuItemCompat.setOnActionExpandListener(search, new MenuItemCompat.OnActionExpandListener() {
|
||||
@Override
|
||||
public boolean onMenuItemActionExpand(MenuItem item) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemActionCollapse(MenuItem item) {
|
||||
//TODO finish search
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -232,6 +217,9 @@ public class MainActivity extends AbsFabActivity
|
|||
}
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_search:
|
||||
startActivity(new Intent(MainActivity.this, SearchActivity.class));
|
||||
return true;
|
||||
case R.id.action_settings:
|
||||
return true;
|
||||
case R.id.action_about:
|
||||
|
|
|
|||
|
|
@ -418,10 +418,10 @@ public class MusicControllerActivity extends AbsFabActivity implements OnMusicRe
|
|||
SongDetailDialogHelper.getDialog(this, songFile).show();
|
||||
return true;
|
||||
case R.id.action_go_to_album:
|
||||
goToAlbumDetailsActivity(song.albumId, null);
|
||||
goToAlbum(song.albumId, null);
|
||||
return true;
|
||||
case R.id.action_go_to_artist:
|
||||
goToArtistDetailsActivity(song.artistId, null);
|
||||
goToArtist(song.artistId, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,188 @@
|
|||
package com.kabouzeid.materialmusic.ui.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActionBar;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.kabouzeid.materialmusic.R;
|
||||
import com.kabouzeid.materialmusic.adapter.SearchAdapter;
|
||||
import com.kabouzeid.materialmusic.loader.AlbumLoader;
|
||||
import com.kabouzeid.materialmusic.loader.ArtistLoader;
|
||||
import com.kabouzeid.materialmusic.loader.SongLoader;
|
||||
import com.kabouzeid.materialmusic.model.Album;
|
||||
import com.kabouzeid.materialmusic.model.Artist;
|
||||
import com.kabouzeid.materialmusic.model.SearchEntry;
|
||||
import com.kabouzeid.materialmusic.model.Song;
|
||||
import com.kabouzeid.materialmusic.ui.activities.base.AbsBaseActivity;
|
||||
import com.kabouzeid.materialmusic.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SearchActivity extends AbsBaseActivity {
|
||||
public static final String TAG = SearchActivity.class.getSimpleName();
|
||||
|
||||
private ListView listView;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setUpTranslucence(false, false);
|
||||
setTitle(null);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_search);
|
||||
|
||||
if (Util.hasLollipopSDK()) {
|
||||
getWindow().setStatusBarColor(Util.resolveColor(this, R.attr.colorPrimaryDark));
|
||||
getWindow().setNavigationBarColor(Util.resolveColor(this, R.attr.colorPrimaryDark));
|
||||
}
|
||||
|
||||
listView = (ListView) findViewById(R.id.list);
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Object item = parent.getItemAtPosition(position);
|
||||
if (item instanceof SearchEntry) {
|
||||
if (item instanceof Song) {
|
||||
List<Song> playList = new ArrayList<>();
|
||||
playList.add((Song) item);
|
||||
getApp().getMusicPlayerRemote().openQueue(playList, 0, true);
|
||||
} else if (item instanceof Album) {
|
||||
disableViews();
|
||||
goToAlbum(((Album) item).id, new Pair[]{Pair.create(view.findViewById(R.id.image), getResources().getString(R.string.transition_album_cover))});
|
||||
} else if (item instanceof Artist) {
|
||||
disableViews();
|
||||
goToArtist(((Artist) item).id, new Pair[]{Pair.create(view.findViewById(R.id.image), getResources().getString(R.string.transition_artist_image))});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
enableViews();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableViews() {
|
||||
super.enableViews();
|
||||
listView.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableViews() {
|
||||
super.disableViews();
|
||||
listView.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_search, menu);
|
||||
|
||||
final MenuItem search = menu.findItem(R.id.action_search);
|
||||
SearchView searchView = (SearchView) MenuItemCompat.getActionView(search);
|
||||
searchView.setIconified(false);
|
||||
searchView.setIconifiedByDefault(false);
|
||||
|
||||
ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
|
||||
searchView.setLayoutParams(params);
|
||||
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
search(newText);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
MenuItemCompat.setOnActionExpandListener(search, new MenuItemCompat.OnActionExpandListener() {
|
||||
@Override
|
||||
public boolean onMenuItemActionExpand(MenuItem item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemActionCollapse(MenuItem item) {
|
||||
finish();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
MenuItemCompat.expandActionView(search);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_settings) {
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void search(String query) {
|
||||
if (!query.trim().equals("")) {
|
||||
List<SearchEntry> results = new ArrayList<>();
|
||||
results.add(new LabelEntry("Songs"));
|
||||
results.addAll(SongLoader.getSongs(this, query));
|
||||
results.add(new LabelEntry("Artists"));
|
||||
results.addAll(ArtistLoader.getArtists(this, query));
|
||||
results.add(new LabelEntry("Albums"));
|
||||
results.addAll(AlbumLoader.getAlbums(this, query));
|
||||
ArrayAdapter adapter = new SearchAdapter(this, results);
|
||||
listView.setAdapter(adapter);
|
||||
} else {
|
||||
listView.setAdapter(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LabelEntry implements SearchEntry {
|
||||
String label;
|
||||
|
||||
public LabelEntry(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSubTitle() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadImage(ImageView imageView) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -96,15 +96,15 @@ public abstract class AbsBaseActivity extends ActionBarActivity implements KabVi
|
|||
|
||||
@Override
|
||||
public void goToAlbum(int albumId) {
|
||||
goToAlbumDetailsActivity(albumId, null);
|
||||
goToAlbum(albumId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goToArtist(int artistId) {
|
||||
goToArtistDetailsActivity(artistId, null);
|
||||
goToArtist(artistId, null);
|
||||
}
|
||||
|
||||
public void goToArtistDetailsActivity(int artistId, Pair[] sharedViews) {
|
||||
public void goToArtist(int artistId, Pair[] sharedViews) {
|
||||
final Intent intent = new Intent(this, ArtistDetailActivity.class);
|
||||
intent.putExtra(AppKeys.E_ARTIST, artistId);
|
||||
if (sharedViews != null) {
|
||||
|
|
@ -117,7 +117,7 @@ public abstract class AbsBaseActivity extends ActionBarActivity implements KabVi
|
|||
}
|
||||
}
|
||||
|
||||
public void goToAlbumDetailsActivity(int albumId, Pair[] sharedViews) {
|
||||
public void goToAlbum(int albumId, Pair[] sharedViews) {
|
||||
final Intent intent = new Intent(this, AlbumDetailActivity.class);
|
||||
intent.putExtra(AppKeys.E_ALBUM, albumId);
|
||||
if (sharedViews != null) {
|
||||
|
|
|
|||
|
|
@ -112,13 +112,13 @@ public abstract class AbsFabActivity extends AbsBaseActivity implements OnMusicR
|
|||
}
|
||||
|
||||
@Override
|
||||
public void goToArtistDetailsActivity(int artistId, Pair[] sharedViews) {
|
||||
super.goToArtistDetailsActivity(artistId, getSharedViewsWithFab(sharedViews));
|
||||
public void goToArtist(int artistId, Pair[] sharedViews) {
|
||||
super.goToArtist(artistId, getSharedViewsWithFab(sharedViews));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goToAlbumDetailsActivity(int albumId, Pair[] sharedViews) {
|
||||
super.goToAlbumDetailsActivity(albumId, getSharedViewsWithFab(sharedViews));
|
||||
public void goToAlbum(int albumId, Pair[] sharedViews) {
|
||||
super.goToAlbum(albumId, getSharedViewsWithFab(sharedViews));
|
||||
}
|
||||
|
||||
private Pair[] getSharedViewsWithFab(Pair[] sharedViews) {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class NavigationDrawerFragment extends Fragment {
|
|||
private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position";
|
||||
public View fragmentRootView;
|
||||
private App app;
|
||||
private NavigationDrawerCallbacks mCallbacks;
|
||||
private NavigationDrawerCallbacks callbacks;
|
||||
private NavigationDrawerItemAdapter drawerAdapter;
|
||||
private DrawerLayout drawerLayout;
|
||||
private ListView drawerListView;
|
||||
|
|
@ -41,10 +41,11 @@ public class NavigationDrawerFragment extends Fragment {
|
|||
private TextView songTitle;
|
||||
private TextView songArtist;
|
||||
|
||||
private int currentSelectedPosition;
|
||||
private boolean fromSavedInstanceState;
|
||||
private boolean userLearnedDrawer;
|
||||
|
||||
private int checkedPosition = 0;
|
||||
|
||||
public NavigationDrawerFragment() {
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +82,7 @@ public class NavigationDrawerFragment extends Fragment {
|
|||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
try {
|
||||
mCallbacks = (NavigationDrawerCallbacks) activity;
|
||||
callbacks = (NavigationDrawerCallbacks) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");
|
||||
}
|
||||
|
|
@ -91,12 +92,9 @@ public class NavigationDrawerFragment extends Fragment {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
app = (App) getActivity().getApplicationContext();
|
||||
userLearnedDrawer = app.getDefaultSharedPreferences().getBoolean(AppKeys.SP_USER_LEARNED_DRAWER, false);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
currentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
|
||||
setItemChecked(savedInstanceState.getInt(STATE_SELECTED_POSITION));
|
||||
fromSavedInstanceState = true;
|
||||
} else {
|
||||
currentSelectedPosition = app.getDefaultSharedPreferences().getInt(AppKeys.SP_NAVIGATION_DRAWER_ITEM_POSITION, 0);
|
||||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
|
@ -110,13 +108,9 @@ public class NavigationDrawerFragment extends Fragment {
|
|||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
fragmentRootView = view;
|
||||
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
initViews();
|
||||
setUpViews();
|
||||
|
||||
selectItem(currentSelectedPosition);
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
|
|
@ -160,38 +154,41 @@ public class NavigationDrawerFragment extends Fragment {
|
|||
});
|
||||
}
|
||||
|
||||
private void selectItem(int position) {
|
||||
private void selectItem(final int position) {
|
||||
if (position != NAVIGATION_DRAWER_HEADER) {
|
||||
currentSelectedPosition = position;
|
||||
if (drawerAdapter != null) {
|
||||
drawerAdapter.setChecked(position);
|
||||
}
|
||||
setItemChecked(position);
|
||||
if (drawerLayout != null) {
|
||||
//close drawer lag workaround
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
drawerLayout.closeDrawer(fragmentContainerView);
|
||||
}
|
||||
}, 100);
|
||||
}, 400);
|
||||
}
|
||||
app.getDefaultSharedPreferences().edit().putInt(AppKeys.SP_NAVIGATION_DRAWER_ITEM_POSITION, position).apply();
|
||||
|
||||
}
|
||||
if (mCallbacks != null) {
|
||||
mCallbacks.onNavigationDrawerItemSelected(position);
|
||||
if (callbacks != null) {
|
||||
callbacks.onNavigationDrawerItemSelected(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(STATE_SELECTED_POSITION, currentSelectedPosition);
|
||||
outState.putInt(STATE_SELECTED_POSITION, checkedPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mCallbacks = null;
|
||||
callbacks = null;
|
||||
}
|
||||
|
||||
public void setItemChecked(final int position) {
|
||||
if (drawerAdapter != null) {
|
||||
drawerAdapter.setChecked(position);
|
||||
checkedPosition = position;
|
||||
}
|
||||
}
|
||||
|
||||
public static interface NavigationDrawerCallbacks {
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ public class ArtistViewFragment extends MainActivityFragment {
|
|||
if (getActivity() instanceof AbsFabActivity) {
|
||||
AbsFabActivity absFabActivity = (AbsFabActivity) getActivity();
|
||||
Pair[] sharedElements = {Pair.create(artistImageView, getString(R.string.transition_artist_image))};
|
||||
absFabActivity.goToArtistDetailsActivity(artist.id, sharedElements);
|
||||
absFabActivity.goToArtist(artist.id, sharedElements);
|
||||
} else {
|
||||
Intent intent = new Intent(getActivity(), ArtistDetailActivity.class);
|
||||
intent.putExtra(AppKeys.E_ARTIST, artist.id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue