New Search Everywhere
This commit is contained in:
parent
41502ee01e
commit
df9a451242
24 changed files with 516 additions and 140 deletions
|
|
@ -1,61 +1,64 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.kabouzeid.materialmusic"
|
package="com.kabouzeid.materialmusic" >
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".App"
|
android:name=".App"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@drawable/ic_launcher"
|
android:icon="@drawable/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/Theme.MaterialMusic">
|
android:theme="@style/Theme.MaterialMusic" >
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.activities.MainActivity"
|
android:name=".ui.activities.MainActivity"
|
||||||
android:label="@string/app_name">
|
android:label="@string/app_name" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".ui.activities.AlbumDetailActivity">
|
<activity android:name=".ui.activities.AlbumDetailActivity" >
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".ui.activities.ArtistDetailActivity">
|
<activity android:name=".ui.activities.ArtistDetailActivity" >
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.activities.MusicControllerActivity"
|
android:name=".ui.activities.MusicControllerActivity"
|
||||||
android:parentActivityName=".ui.activities.MainActivity">
|
android:parentActivityName=".ui.activities.MainActivity" >
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".service.MusicService"
|
android:name=".service.MusicService"
|
||||||
android:enabled="true">
|
android:enabled="true" >
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<receiver android:name=".service.MediaButtonIntentReceiver">
|
<receiver android:name=".service.MediaButtonIntentReceiver" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MEDIA_BUTTON"/>
|
<action android:name="android.intent.action.MEDIA_BUTTON" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="com.crashlytics.ApiKey"
|
android:name="com.crashlytics.ApiKey"
|
||||||
android:value="b23725bd3d266aa65c5a3dd1816b2f801524a189"/>
|
android:value="b23725bd3d266aa65c5a3dd1816b2f801524a189" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.activities.tageditor.SongTagEditorActivity"
|
android:name=".ui.activities.tageditor.SongTagEditorActivity"
|
||||||
android:label="@string/title_activity_tag_editor"
|
android:label="@string/title_activity_tag_editor"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize" >
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.activities.tageditor.AlbumTagEditorActivity"
|
android:name=".ui.activities.tageditor.AlbumTagEditorActivity"
|
||||||
android:label="@string/title_activity_album_tag_editor">
|
android:label="@string/title_activity_album_tag_editor" >
|
||||||
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".ui.activities.SearchActivity"
|
||||||
|
android:label="@string/title_activity_search" >
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 com.kabouzeid.materialmusic.model.Song;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -15,6 +17,12 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class AlbumSongLoader {
|
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) {
|
public static List<Song> getAlbumSongList(final Context context, final int albumId) {
|
||||||
Cursor cursor = makeAlbumSongCursor(context, albumId);
|
Cursor cursor = makeAlbumSongCursor(context, albumId);
|
||||||
List<Song> songs = new ArrayList<>();
|
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 CL_CURRENT_ACTIVITY = "Current activity";
|
||||||
|
|
||||||
public static final String SP_THEME = "com.kabouzeid.materialmusic.THEME";
|
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_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_ONLY_ON_WIFI = "com.kabouzeid.materialmusic.ONLY_ON_WIFI";
|
||||||
public static final String SP_SHUFFLE_MODE = "com.kabouzeid.materialmusic.SHUFFLE_MODE";
|
public static final String SP_SHUFFLE_MODE = "com.kabouzeid.materialmusic.SHUFFLE_MODE";
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
package com.kabouzeid.materialmusic.model;
|
package com.kabouzeid.materialmusic.model;
|
||||||
|
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by karim on 22.11.14.
|
* Created by karim on 22.11.14.
|
||||||
*/
|
*/
|
||||||
public class Album {
|
public class Album implements SearchEntry {
|
||||||
|
|
||||||
public int id;
|
public int id;
|
||||||
public int artistId;
|
public int artistId;
|
||||||
|
|
@ -29,4 +31,19 @@ public class Album {
|
||||||
songCount = -1;
|
songCount = -1;
|
||||||
year = -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;
|
package com.kabouzeid.materialmusic.model;
|
||||||
|
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by karim on 29.12.14.
|
* Created by karim on 29.12.14.
|
||||||
*/
|
*/
|
||||||
public class Artist {
|
public class Artist implements SearchEntry {
|
||||||
public int id;
|
public int id;
|
||||||
public String name;
|
public String name;
|
||||||
public int albumCount;
|
public int albumCount;
|
||||||
public int songCount;
|
public int songCount;
|
||||||
|
|
||||||
public Artist(final int id, final String name, final int songCount,
|
public Artist(final int id, final String name, final int albumCount, final int songCount) {
|
||||||
final int albumCount) {
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.songCount = songCount;
|
this.songCount = songCount;
|
||||||
|
|
@ -23,4 +24,19 @@ public class Artist {
|
||||||
songCount = -1;
|
songCount = -1;
|
||||||
albumCount = -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;
|
package com.kabouzeid.materialmusic.model;
|
||||||
|
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by karim on 23.11.14.
|
* Created by karim on 23.11.14.
|
||||||
*/
|
*/
|
||||||
public class Song implements Serializable {
|
public class Song implements Serializable, SearchEntry {
|
||||||
public int id;
|
public int id;
|
||||||
public int albumId;
|
public int albumId;
|
||||||
public int artistId;
|
public int artistId;
|
||||||
|
|
@ -37,4 +39,19 @@ public class Song implements Serializable {
|
||||||
this.duration = -1;
|
this.duration = -1;
|
||||||
this.trackNumber = -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()
|
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 {
|
public interface AlbumJSONColumns {
|
||||||
|
|
@ -92,7 +86,13 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
||||||
public static final String JSON = "JSON";
|
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
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -78,12 +78,6 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
||||||
artistName.trim().toLowerCase()
|
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 {
|
public interface ArtistJSONColumns {
|
||||||
|
|
@ -92,7 +86,13 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
||||||
public static final String JSON = "JSON";
|
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
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@ import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -329,8 +328,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements OnMusicRemote
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpSongsAdapter() {
|
private void setUpSongsAdapter() {
|
||||||
final List<Song> songs = AlbumSongLoader.getAlbumSongList(this, album.id);
|
final List<Song> songs = AlbumSongLoader.getAlbumSongList(this, album.id, new SongTrackNumberComparator());
|
||||||
Collections.sort(songs, new SongTrackNumberComparator());
|
|
||||||
final SongAdapter songAdapter = new SongAdapter(this, this, songs);
|
final SongAdapter songAdapter = new SongAdapter(this, this, songs);
|
||||||
|
|
||||||
// SwingBottomInAnimationAdapter songsAdapter = new SwingBottomInAnimationAdapter(songAdapter);
|
// SwingBottomInAnimationAdapter songsAdapter = new SwingBottomInAnimationAdapter(songAdapter);
|
||||||
|
|
@ -410,7 +408,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements OnMusicRemote
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_go_to_artist:
|
case R.id.action_go_to_artist:
|
||||||
goToArtistDetailsActivity(album.artistId, null);
|
goToArtist(album.artistId, null);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,14 @@ package com.kabouzeid.materialmusic.ui.activities;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v13.app.FragmentPagerAdapter;
|
import android.support.v13.app.FragmentPagerAdapter;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.ActionBarDrawerToggle;
|
import android.support.v7.app.ActionBarDrawerToggle;
|
||||||
import android.support.v7.widget.SearchView;
|
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
@ -30,6 +29,7 @@ import com.kabouzeid.materialmusic.helper.AboutDeveloperDialogHelper;
|
||||||
import com.kabouzeid.materialmusic.helper.PlayingQueueDialogHelper;
|
import com.kabouzeid.materialmusic.helper.PlayingQueueDialogHelper;
|
||||||
import com.kabouzeid.materialmusic.interfaces.KabViewsDisableAble;
|
import com.kabouzeid.materialmusic.interfaces.KabViewsDisableAble;
|
||||||
import com.kabouzeid.materialmusic.interfaces.OnMusicRemoteEventListener;
|
import com.kabouzeid.materialmusic.interfaces.OnMusicRemoteEventListener;
|
||||||
|
import com.kabouzeid.materialmusic.misc.AppKeys;
|
||||||
import com.kabouzeid.materialmusic.model.MusicRemoteEvent;
|
import com.kabouzeid.materialmusic.model.MusicRemoteEvent;
|
||||||
import com.kabouzeid.materialmusic.model.Song;
|
import com.kabouzeid.materialmusic.model.Song;
|
||||||
import com.kabouzeid.materialmusic.ui.activities.base.AbsFabActivity;
|
import com.kabouzeid.materialmusic.ui.activities.base.AbsFabActivity;
|
||||||
|
|
@ -64,21 +64,40 @@ public class MainActivity extends AbsFabActivity
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
initViews();
|
initViews();
|
||||||
setUpToolBar();
|
|
||||||
setUpViewPager();
|
|
||||||
|
|
||||||
navigationDrawerFragment.setUp(
|
navigationDrawerFragment.setUp(
|
||||||
R.id.navigation_drawer,
|
R.id.navigation_drawer,
|
||||||
drawerLayout
|
drawerLayout
|
||||||
);
|
);
|
||||||
|
setUpToolBar();
|
||||||
|
setUpViewPager();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpViewPager() {
|
private void setUpViewPager() {
|
||||||
viewPagerAdapter = new MainActivityViewPagerAdapter(this);
|
viewPagerAdapter = new MainActivityViewPagerAdapter(this);
|
||||||
viewPager.setAdapter(viewPagerAdapter);
|
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.setSelectedIndicatorColors(Util.resolveColor(MainActivity.this, R.attr.colorAccent));
|
||||||
slidingTabLayout.setViewPager(viewPager);
|
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() {
|
private void initViews() {
|
||||||
|
|
@ -87,18 +106,6 @@ public class MainActivity extends AbsFabActivity
|
||||||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
navigationDrawerFragment = (NavigationDrawerFragment)
|
navigationDrawerFragment = (NavigationDrawerFragment)
|
||||||
getFragmentManager().findFragmentById(R.id.navigation_drawer);
|
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() {
|
private void setUpToolBar() {
|
||||||
|
|
@ -139,6 +146,17 @@ public class MainActivity extends AbsFabActivity
|
||||||
updateNavigationDrawerHeader();
|
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
|
@Override
|
||||||
public void enableViews() {
|
public void enableViews() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -172,49 +190,16 @@ public class MainActivity extends AbsFabActivity
|
||||||
if (position == NavigationDrawerFragment.NAVIGATION_DRAWER_HEADER) {
|
if (position == NavigationDrawerFragment.NAVIGATION_DRAWER_HEADER) {
|
||||||
openCurrentPlayingIfPossible(null);
|
openCurrentPlayingIfPossible(null);
|
||||||
} else {
|
} else {
|
||||||
goToFragment(position);
|
if (viewPager != null) {
|
||||||
|
viewPager.setCurrentItem(position, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void goToFragment(int position) {
|
|
||||||
//TODO goToFragment
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.drawer, menu);
|
getMenuInflater().inflate(R.menu.drawer, menu);
|
||||||
restoreActionBar();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -232,6 +217,9 @@ public class MainActivity extends AbsFabActivity
|
||||||
}
|
}
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
switch (id) {
|
switch (id) {
|
||||||
|
case R.id.action_search:
|
||||||
|
startActivity(new Intent(MainActivity.this, SearchActivity.class));
|
||||||
|
return true;
|
||||||
case R.id.action_settings:
|
case R.id.action_settings:
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_about:
|
case R.id.action_about:
|
||||||
|
|
|
||||||
|
|
@ -418,10 +418,10 @@ public class MusicControllerActivity extends AbsFabActivity implements OnMusicRe
|
||||||
SongDetailDialogHelper.getDialog(this, songFile).show();
|
SongDetailDialogHelper.getDialog(this, songFile).show();
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_go_to_album:
|
case R.id.action_go_to_album:
|
||||||
goToAlbumDetailsActivity(song.albumId, null);
|
goToAlbum(song.albumId, null);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_go_to_artist:
|
case R.id.action_go_to_artist:
|
||||||
goToArtistDetailsActivity(song.artistId, null);
|
goToArtist(song.artistId, null);
|
||||||
return true;
|
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
|
@Override
|
||||||
public void goToAlbum(int albumId) {
|
public void goToAlbum(int albumId) {
|
||||||
goToAlbumDetailsActivity(albumId, null);
|
goToAlbum(albumId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void goToArtist(int artistId) {
|
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);
|
final Intent intent = new Intent(this, ArtistDetailActivity.class);
|
||||||
intent.putExtra(AppKeys.E_ARTIST, artistId);
|
intent.putExtra(AppKeys.E_ARTIST, artistId);
|
||||||
if (sharedViews != null) {
|
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);
|
final Intent intent = new Intent(this, AlbumDetailActivity.class);
|
||||||
intent.putExtra(AppKeys.E_ALBUM, albumId);
|
intent.putExtra(AppKeys.E_ALBUM, albumId);
|
||||||
if (sharedViews != null) {
|
if (sharedViews != null) {
|
||||||
|
|
|
||||||
|
|
@ -112,13 +112,13 @@ public abstract class AbsFabActivity extends AbsBaseActivity implements OnMusicR
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void goToArtistDetailsActivity(int artistId, Pair[] sharedViews) {
|
public void goToArtist(int artistId, Pair[] sharedViews) {
|
||||||
super.goToArtistDetailsActivity(artistId, getSharedViewsWithFab(sharedViews));
|
super.goToArtist(artistId, getSharedViewsWithFab(sharedViews));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void goToAlbumDetailsActivity(int albumId, Pair[] sharedViews) {
|
public void goToAlbum(int albumId, Pair[] sharedViews) {
|
||||||
super.goToAlbumDetailsActivity(albumId, getSharedViewsWithFab(sharedViews));
|
super.goToAlbum(albumId, getSharedViewsWithFab(sharedViews));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pair[] getSharedViewsWithFab(Pair[] 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";
|
private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position";
|
||||||
public View fragmentRootView;
|
public View fragmentRootView;
|
||||||
private App app;
|
private App app;
|
||||||
private NavigationDrawerCallbacks mCallbacks;
|
private NavigationDrawerCallbacks callbacks;
|
||||||
private NavigationDrawerItemAdapter drawerAdapter;
|
private NavigationDrawerItemAdapter drawerAdapter;
|
||||||
private DrawerLayout drawerLayout;
|
private DrawerLayout drawerLayout;
|
||||||
private ListView drawerListView;
|
private ListView drawerListView;
|
||||||
|
|
@ -41,10 +41,11 @@ public class NavigationDrawerFragment extends Fragment {
|
||||||
private TextView songTitle;
|
private TextView songTitle;
|
||||||
private TextView songArtist;
|
private TextView songArtist;
|
||||||
|
|
||||||
private int currentSelectedPosition;
|
|
||||||
private boolean fromSavedInstanceState;
|
private boolean fromSavedInstanceState;
|
||||||
private boolean userLearnedDrawer;
|
private boolean userLearnedDrawer;
|
||||||
|
|
||||||
|
private int checkedPosition = 0;
|
||||||
|
|
||||||
public NavigationDrawerFragment() {
|
public NavigationDrawerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +82,7 @@ public class NavigationDrawerFragment extends Fragment {
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
try {
|
try {
|
||||||
mCallbacks = (NavigationDrawerCallbacks) activity;
|
callbacks = (NavigationDrawerCallbacks) activity;
|
||||||
} catch (ClassCastException e) {
|
} catch (ClassCastException e) {
|
||||||
throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");
|
throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");
|
||||||
}
|
}
|
||||||
|
|
@ -91,12 +92,9 @@ public class NavigationDrawerFragment extends Fragment {
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
app = (App) getActivity().getApplicationContext();
|
app = (App) getActivity().getApplicationContext();
|
||||||
userLearnedDrawer = app.getDefaultSharedPreferences().getBoolean(AppKeys.SP_USER_LEARNED_DRAWER, false);
|
userLearnedDrawer = app.getDefaultSharedPreferences().getBoolean(AppKeys.SP_USER_LEARNED_DRAWER, false);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
currentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
|
setItemChecked(savedInstanceState.getInt(STATE_SELECTED_POSITION));
|
||||||
fromSavedInstanceState = true;
|
fromSavedInstanceState = true;
|
||||||
} else {
|
|
||||||
currentSelectedPosition = app.getDefaultSharedPreferences().getInt(AppKeys.SP_NAVIGATION_DRAWER_ITEM_POSITION, 0);
|
|
||||||
}
|
}
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
@ -110,13 +108,9 @@ public class NavigationDrawerFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
fragmentRootView = view;
|
fragmentRootView = view;
|
||||||
|
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
initViews();
|
initViews();
|
||||||
setUpViews();
|
setUpViews();
|
||||||
|
|
||||||
selectItem(currentSelectedPosition);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initViews() {
|
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) {
|
if (position != NAVIGATION_DRAWER_HEADER) {
|
||||||
currentSelectedPosition = position;
|
setItemChecked(position);
|
||||||
if (drawerAdapter != null) {
|
|
||||||
drawerAdapter.setChecked(position);
|
|
||||||
}
|
|
||||||
if (drawerLayout != null) {
|
if (drawerLayout != null) {
|
||||||
//close drawer lag workaround
|
|
||||||
new Handler().postDelayed(new Runnable() {
|
new Handler().postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
drawerLayout.closeDrawer(fragmentContainerView);
|
drawerLayout.closeDrawer(fragmentContainerView);
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 400);
|
||||||
}
|
}
|
||||||
app.getDefaultSharedPreferences().edit().putInt(AppKeys.SP_NAVIGATION_DRAWER_ITEM_POSITION, position).apply();
|
|
||||||
}
|
}
|
||||||
if (mCallbacks != null) {
|
if (callbacks != null) {
|
||||||
mCallbacks.onNavigationDrawerItemSelected(position);
|
callbacks.onNavigationDrawerItemSelected(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putInt(STATE_SELECTED_POSITION, currentSelectedPosition);
|
outState.putInt(STATE_SELECTED_POSITION, checkedPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.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 {
|
public static interface NavigationDrawerCallbacks {
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ public class ArtistViewFragment extends MainActivityFragment {
|
||||||
if (getActivity() instanceof AbsFabActivity) {
|
if (getActivity() instanceof AbsFabActivity) {
|
||||||
AbsFabActivity absFabActivity = (AbsFabActivity) getActivity();
|
AbsFabActivity absFabActivity = (AbsFabActivity) getActivity();
|
||||||
Pair[] sharedElements = {Pair.create(artistImageView, getString(R.string.transition_artist_image))};
|
Pair[] sharedElements = {Pair.create(artistImageView, getString(R.string.transition_artist_image))};
|
||||||
absFabActivity.goToArtistDetailsActivity(artist.id, sharedElements);
|
absFabActivity.goToArtist(artist.id, sharedElements);
|
||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(getActivity(), ArtistDetailActivity.class);
|
Intent intent = new Intent(getActivity(), ArtistDetailActivity.class);
|
||||||
intent.putExtra(AppKeys.E_ARTIST, artist.id);
|
intent.putExtra(AppKeys.E_ARTIST, artist.id);
|
||||||
|
|
|
||||||
21
app/src/main/res/layout/activity_search.xml
Normal file
21
app/src/main/res/layout/activity_search.xml
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<android.support.v7.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:background="?colorPrimary"
|
||||||
|
android:elevation="@dimen/toolbar_elevation"
|
||||||
|
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:dividerHeight="0dp"
|
||||||
|
android:divider="@null"
|
||||||
|
android:id="@+id/list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
</LinearLayout>
|
||||||
44
app/src/main/res/layout/item_search.xml
Normal file
44
app/src/main/res/layout/item_search.xml
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="64dp"
|
||||||
|
android:descendantFocusability="blocksDescendants"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingLeft="16dp">
|
||||||
|
|
||||||
|
<com.kabouzeid.materialmusic.view.SquareImageView
|
||||||
|
android:id="@+id/image"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="60dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:fontFamily="sans-serif"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/sub_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:fontFamily="sans-serif"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"/>
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
@ -10,11 +10,10 @@
|
||||||
app:showAsAction="always"/>
|
app:showAsAction="always"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_search"
|
android:id="@+id/action_search"
|
||||||
android:icon="@drawable/abc_ic_search_api_mtrl_alpha"
|
android:icon="@drawable/abc_ic_search_api_mtrl_alpha"
|
||||||
android:title="@string/action_search"
|
android:title="@string/action_search"
|
||||||
app:actionViewClass="android.support.v7.widget.SearchView"
|
app:showAsAction="ifRoom"/>
|
||||||
app:showAsAction="collapseActionView|ifRoom"/>
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_playing_queue"
|
android:id="@+id/action_playing_queue"
|
||||||
|
|
|
||||||
11
app/src/main/res/menu/menu_search.xml
Normal file
11
app/src/main/res/menu/menu_search.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<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.SearchActivity">
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_search"
|
||||||
|
android:icon="@drawable/abc_ic_search_api_mtrl_alpha"
|
||||||
|
android:title="@string/action_search"
|
||||||
|
app:actionViewClass="android.support.v7.widget.SearchView"
|
||||||
|
app:showAsAction="ifRoom|collapseActionView"/>
|
||||||
|
</menu>
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
<color name="materialmusic_music_controller_container_color">@color/grey_400</color>
|
<color name="materialmusic_music_controller_container_color">@color/grey_400</color>
|
||||||
|
|
||||||
<color name="materialmusic_dark_color">@color/grey_900</color>
|
<color name="materialmusic_dark_color">@color/grey_900</color>
|
||||||
<color name="materialmusic_dark_color_darker">@color/black</color>
|
<color name="materialmusic_dark_color_darker">#161616</color>
|
||||||
|
|
||||||
<color name="materialmusic_dark_accent_color">@color/pink_500</color>
|
<color name="materialmusic_dark_accent_color">@color/pink_500</color>
|
||||||
<color name="materialmusic_dark_accent_color_darker">@color/pink_600</color>
|
<color name="materialmusic_dark_accent_color_darker">@color/pink_600</color>
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@
|
||||||
<string name="close">Close</string>
|
<string name="close">Close</string>
|
||||||
<string name="save_as_playlist">Save as playlist</string>
|
<string name="save_as_playlist">Save as playlist</string>
|
||||||
<string name="credits">Material Music is a completely free material designed music player by <b>Karim Abou Zeid</b>.\n\n<a href="https://plus.google.com/+KarimAbouZeid23697">Google+</a>   <a href="https://twitter.com/karim23697">Twitter</a></string>
|
<string name="credits">Material Music is a completely free material designed music player by <b>Karim Abou Zeid</b>.\n\n<a href="https://plus.google.com/+KarimAbouZeid23697">Google+</a>   <a href="https://twitter.com/karim23697">Twitter</a></string>
|
||||||
|
<string name="title_activity_search">SearchActivity</string>
|
||||||
|
<string name="more">more</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue