Commits

Anonymous committed 41aca78

Adding playlist inprogress

  • Participants
  • Parent commits 605d770

Comments (0)

Files changed (18)

File res/drawable-hdpi/ic_launcher.png

Old
Old image
New
New image

File res/drawable-mdpi/ic_launcher.png

Old
Old image
New
New image

File res/drawable-xhdpi/ic_launcher.png

Old
Old image
New
New image

File res/drawable-xxhdpi/ic_launcher.png

Old
Old image
New
New image

File res/layout/each_song.xml

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/song_lable_parent_ll"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal" >

File res/layout/fragment_music_player.xml

         android:layout_height="wrap_content"
         android:layout_above="@+id/rl2"
         android:layout_alignParentLeft="true"
-        android:background="@color/Snow"
         android:gravity="center" >
 
         <Button

File res/layout/song_dialog_popup.xml

             android:layout_width="50dp"
             android:layout_height="50dp"
             android:layout_gravity="center_vertical"
+            android:layout_margin="2dp"
             android:background="@drawable/dummy_album_art"
             android:contentDescription="@string/image_content_desc"
             android:gravity="center_vertical"
-            android:layout_margin="2dp"
             android:scaleType="centerCrop" />
 
         <com.w4rlock.backpapermusic.views.TextViewPlus
         android:id="@+id/alert_dialog_list"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_above="@+id/alert_dialog_cancel"
+        android:layout_above="@+id/alert_dialog_cancel_ll"
         android:layout_alignParentLeft="true"
         android:layout_below="@+id/linearLayout1"
         android:choiceMode="singleChoice"
         android:dividerHeight="0dp" >
     </ListView>
 
-    <com.w4rlock.backpapermusic.views.ButtonPlus
-        android:id="@+id/alert_dialog_cancel"
-        style="@style/Widget.AppCompat.ActionButton"
+    <LinearLayout
+        android:id="@+id/alert_dialog_cancel_ll"
         android:layout_width="match_parent"
         android:layout_height="50dp"
         android:layout_alignParentBottom="true"
         android:layout_alignParentLeft="true"
         android:gravity="center_vertical|center_horizontal"
-        android:text="@string/cancel"
-        android:textSize="20sp" />
+        android:orientation="horizontal" >
+
+        <com.w4rlock.backpapermusic.views.ButtonPlus
+            android:id="@+id/alert_dialog_cancel"
+            style="@style/Widget.AppCompat.ActionButton"
+            android:layout_width="0dp"
+            android:layout_height="50dp"
+            android:layout_weight="1"
+            android:text="@string/cancel"
+            android:textSize="20sp" />
+
+        <com.w4rlock.backpapermusic.views.ButtonPlus
+            android:id="@+id/alert_dialog_add"
+            style="@style/Widget.AppCompat.ActionButton"
+            android:layout_width="0dp"
+            android:layout_height="50dp"
+            android:layout_weight="1"
+            android:text="@string/add"
+            android:textSize="20sp" />
+    </LinearLayout>
 
 </RelativeLayout>

File res/menu/music.xml

 <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.w4rlock.backpapermusic.MusicActivity" >
+    xmlns:tools="http://schemas.android.com/tools" >
 
     <item
-        android:id="@+id/action_settings"
-        android:orderInCategory="100"
-        android:title="@string/action_settings"
-        app:showAsAction="never"/>
+        android:id="@+id/action_search"
+        app:actionViewClass="android.support.v7.widget.SearchView"
+        app:showAsAction="always"/>
 
-</menu>
+</menu>

File res/values/colors.xml

  <color name="blue">#0000FF</color>
  <color name="navy">#000080</color>
  <color name="black">#000000</color>
+ <color name="holo_blue_light">#ff33b5e5</color>
 
  <color name="White">#FFFFFF</color>
  <color name="Ivory">#FFFFF0</color>

File res/values/strings.xml

 	<string name="time_duration_as_zeros">00:00/00:00</string>
 	<string name="image_content_desc">imageContentDesc</string>
 	<string name="cancel">Cancel</string>
+	<string name="add">Add</string>
+	<string name="search_albums_songs">Search Albums / Songs</string>
     
     <!-- service -->
     <string name="service_started">Service Started</string>

File src/com/w4rlock/backpapermusic/MusicActivity.java

 	@Override
 	public boolean onCreateOptionsMenu(Menu menu)
 	{
-		getMenuInflater().inflate(R.menu.music, menu);
 		return true;
 	}
 

File src/com/w4rlock/backpapermusic/adapters/SongItemListDiaplayAdapter.java

 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ArrayAdapter;
+import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import com.w4rlock.backpapermusic.R;
 			row = inflater.inflate(R.layout.each_song, parent, false);
 			songViewHolder = new SongViewHolder();
 			songViewHolder.songLabel = (TextView) row.findViewById(R.id.song_label);
+			songViewHolder.songLableParent = (LinearLayout) row.findViewById(R.id.song_lable_parent_ll);
 			row.setTag(songViewHolder);
 		} else
 		{
 		}
 		SongItem songItem = getItem(position);
 		songViewHolder.songLabel.setText(songItem.getTitle());
+		if (songItem.isSelected)
+		{
+			songViewHolder.songLableParent.setBackgroundColor(getContext().getResources().getColor(R.color.holo_blue_light));
+		} else
+		{
+			songViewHolder.songLableParent.setBackgroundColor(getContext().getResources().getColor(R.color.white));
+		}
 		return row;
 	}
 
 
 	static class SongViewHolder
 	{
+		public LinearLayout songLableParent;
 		public TextView songLabel;
 	}
 }

File src/com/w4rlock/backpapermusic/fragments/MusicListFragment.java

 package com.w4rlock.backpapermusic.fragments;
 
 import java.util.ArrayList;
+import java.util.List;
 
+import android.annotation.SuppressLint;
 import android.content.Intent;
 import android.net.Uri;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.LoaderManager;
 import android.support.v4.content.Loader;
+import android.support.v4.view.MenuItemCompat;
+import android.support.v7.widget.SearchView;
 import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
 import com.w4rlock.backpapermusic.models.AsyncResult;
 import com.w4rlock.backpapermusic.models.Music;
 import com.w4rlock.backpapermusic.models.SongItem;
+import com.w4rlock.backpapermusic.service.PlayList;
 import com.w4rlock.backpapermusic.service.google.MusicService;
 import com.w4rlock.backpapermusic.util.L;
 import com.w4rlock.backpapermusic.views.SongDialogPopup;
 
 public class MusicListFragment extends Fragment
 {
-
 	private static final String DEBUG_TAG = "MusicListFragment";
-	public static final ArrayList<Music> music = new ArrayList<Music>();
+	public static final ArrayList<Music> musics = new ArrayList<Music>();
 	private MusicListViewAdapter mMusicAdapter;
 	private static final int NETWORK_MAX_TRIES = 2;
 	private int networkTries = 0;
+	private ListView songsList;
 
 	public MusicListFragment()
 	{
 	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
 	{
 		View rootView = inflater.inflate(R.layout.fragment_music_list, container, false);
-		ListView songsList = (ListView) rootView.findViewById(R.id.songs_list_view);
-		mMusicAdapter = new MusicListViewAdapter(getActivity(), music);
+		setHasOptionsMenu(true);
+
+		songsList = (ListView) rootView.findViewById(R.id.songs_list_view);
+		mMusicAdapter = new MusicListViewAdapter(getActivity(), musics);
 		songsList.setAdapter(mMusicAdapter);
 		getLoaderManager().initLoader(0, null, new MusicLoaderCallbacks());
 		songsList.setOnItemClickListener(new AdapterView.OnItemClickListener()
 			}
 
 		});
-		// songsList.setOnChildClickListener(new
-		// ExpandableListView.OnChildClickListener()
-		// {
-		//
-		// @Override
-		// public boolean onChildClick(ExpandableListView parent, View v, int
-		// groupPosition, int childPosition, long id)
-		// {
-		// String CURRENT_SONG =
-		// music.get(groupPosition).getSongPath(childPosition);
-		// playThisSong(groupPosition, childPosition);
-		// L.d(DEBUG_TAG, CURRENT_SONG);
-		// return true;
-		// }
-		// });
 		songsList.setOnItemClickListener(new AdapterView.OnItemClickListener()
 		{
 
 		{
 
 			@Override
-			public void onSongItemClicked(SongItem songItem)
+			public void onSongItemClicked(ArrayList<SongItem> songItems)
 			{
-				playThisSong(songItem);
+				addToPlayList(songItems);
 			}
 		};
 		SongDialogPopup songDialogPopup = new SongDialogPopup(getActivity(), music, onItemClickListener);
 		songDialogPopup.show();
 	}
 
+	protected void addToPlayList(ArrayList<SongItem> songItems)
+	{
+		PlayList.addToPlayList(songItems);
+		Intent i  = new Intent(MusicService.ACTION_PLAY);
+		getActivity().startService(i);
+	}
+
 	protected void playThisSong(SongItem songItem)
 	{
 		String songUrl = songItem.getSongPath();
 		getActivity().startService(i);
 	}
 
-	protected void playThisSong(int groupPosition, int childPosition)
-	{
-		SongItem songItem = new SongItem(music.get(groupPosition), childPosition);
-		playThisSong(songItem);
-	}
-
 	private class MusicLoaderCallbacks implements LoaderManager.LoaderCallbacks<AsyncResult<ArrayList<Music>>>
 	{
 
 			{
 				return;
 			}
-			music.clear();
+			musics.clear();
 			networkTries = 0;
 			for (Music m : data.getResult())
 			{
-				music.add(m);
+				musics.add(m);
 			}
 			mMusicAdapter.notifyDataSetChanged();
 		}
 
 	}
 
+	@SuppressLint("NewApi")
+	@Override
+	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
+	{
+		super.onCreateOptionsMenu(menu, inflater);
+		inflater.inflate(R.menu.music, menu);
+		SearchView searchView;
+		if (android.os.Build.VERSION.SDK_INT >= 11)
+			searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
+		else
+			searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
+		final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener()
+		{
+			@Override
+			public boolean onQueryTextChange(String newText)
+			{
+				L.d(DEBUG_TAG, "query: " + newText);
+				filterMusicItems(newText);
+				return true;
+			}
+
+			@Override
+			public boolean onQueryTextSubmit(String query)
+			{
+				return true;
+			}
+		};
+		searchView.setOnQueryTextListener(queryTextListener);
+	}
+
+	public void filterMusicItems(String newText)
+	{
+		if (newText == null || newText.length() <= 0)
+		{
+			mMusicAdapter = new MusicListViewAdapter(getActivity(), musics);
+		} else
+		{
+			List<Music> tempMusic = new ArrayList<Music>();
+			for (Music m : musics)
+			{
+				if (m.getAlbumName().toLowerCase().contains(newText) || m.getDirname().toLowerCase().contains(newText))
+				{
+					tempMusic.add(m);
+				}
+			}
+			mMusicAdapter = new MusicListViewAdapter(getActivity(), tempMusic);
+		}
+		songsList.setAdapter(mMusicAdapter);
+	}
+
 	@Override
 	public void onResume()
 	{

File src/com/w4rlock/backpapermusic/models/Music.java

 
 public class Music implements Serializable
 {
+	private static final long serialVersionUID = 1L;
 	public static final String BASE_URL = "http://db.w4rlock.in/media/music/";
 
 	public ArrayList<SongItem> getSongs()
 
 	public static class Files implements Serializable
 	{
+		private static final long serialVersionUID = 1L;
 
 		public ArrayList<MP3> getMp3()
 		{
 
 	public static class MP3 implements Serializable
 	{
+		private static final long serialVersionUID = 1L;
+
 		public String getAlbum()
 		{
 			return album;

File src/com/w4rlock/backpapermusic/models/SongItem.java

 
 import java.io.Serializable;
 
-import com.w4rlock.backpapermusic.util.L;
-
 public class SongItem implements Serializable
 {
+	public boolean isSelected = false;
 	private static final long serialVersionUID = 1L;
 	private Integer selectedSongPosition;
 	private Music music;

File src/com/w4rlock/backpapermusic/service/PlayList.java

+package com.w4rlock.backpapermusic.service;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import com.w4rlock.backpapermusic.models.SongItem;
+
+public class PlayList
+{
+	public static final ArrayList<SongItem> playList = new ArrayList<SongItem>();
+
+	public static SongItem getNextSongItem()
+	{
+		Iterator<SongItem> i = playList.iterator();
+		if (i.hasNext())
+		{
+			SongItem so = i.next();
+			i.remove();
+			return so;
+		} else
+		{
+			return null;
+		}
+	}
+
+	public static void addToPlayList(ArrayList<SongItem> songItems)
+	{
+		playList.addAll(songItems);
+	}
+}

File src/com/w4rlock/backpapermusic/service/google/MusicService.java

 import com.w4rlock.backpapermusic.MusicPlayerActivity;
 import com.w4rlock.backpapermusic.R;
 import com.w4rlock.backpapermusic.models.SongItem;
+import com.w4rlock.backpapermusic.service.PlayList;
 import com.w4rlock.backpapermusic.service.binder.DummyMusicServiceCallback;
 import com.w4rlock.backpapermusic.service.binder.MusicServiceBinder;
 import com.w4rlock.backpapermusic.service.binder.MusicServiceCallbackInterface;
 	@Override
 	public int onStartCommand(Intent intent, int flags, int startId)
 	{
+		if(intent == null || intent.getAction() == null){
+			return START_NOT_STICKY;
+		}
 		String action = intent.getAction();
 		L.d(DEBUG_TAG, "Got action: " + action);
 		if (action.equals(ACTION_TOGGLE_PLAYBACK))
 		mState = State.Stopped;
 		mServiceCallback.onStateChanged(mState);
 		relaxResources(false); // release everything except MediaPlayer
-
+		mSongItem = PlayList.getNextSongItem();
+		if (mSongItem == null || mSongItem.getSongPath() == null)
+		{
+			manualUrl = null;
+		} else
+		{
+			L.d(DEBUG_TAG, "Got Next Song From PlayList " );
+			manualUrl = mSongItem.getSongPath();
+		}
 		try
 		{
 			if (manualUrl != null)
 			mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
 
 			mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE
-					| RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP);
+					| RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS);
 
 			// Update the remote controls
 			mRemoteControlClientCompat.editMetadata(true).putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, mSongItem.getArtist())

File src/com/w4rlock/backpapermusic/views/SongDialogPopup.java

 package com.w4rlock.backpapermusic.views;
 
+import java.util.ArrayList;
+
 import android.app.Dialog;
 import android.content.Context;
 import android.view.View;
 	ImageView mHeadingIcon;
 	TextView mHeadingText;
 	ListView mListView;
+	Button mAddButton;
 	SongItemListDiaplayAdapter mSongItemListDiaplayAdapter;
 	DisplayImageOptions doptions = Utils.getDisplayImageOptions();
 	ImageLoader imageLoader;
 		mListView = (ListView) findViewById(R.id.alert_dialog_list);
 		mHeadingIcon = (ImageView) findViewById(R.id.alert_dialog_heading_icon);
 		mHeadingText = (TextView) findViewById(R.id.alert_dialog_heading);
+		mAddButton = (Button) findViewById(R.id.alert_dialog_add);
 
 		imageLoader = ImageLoader.getInstance();
 		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).build();
 			@Override
 			public void onItemClick(AdapterView<?> parent, View view, int position, long id)
 			{
-				SongItem songItem = (SongItem)parent.getItemAtPosition(position);
-				mOnSongItemClicked.onSongItemClicked(songItem);
-				dismiss();
+				SongItem songItem = (SongItem) parent.getItemAtPosition(position);
+				songItem.isSelected = !songItem.isSelected;
+				mSongItemListDiaplayAdapter.notifyDataSetChanged();
 			}
 		});
 
-		L.d(DEBUG_TAG, "showing pop up from dialog view");
+		mAddButton.setOnClickListener(new View.OnClickListener()
+		{
+
+			@Override
+			public void onClick(View v)
+			{
+				ArrayList<SongItem> songitems = new ArrayList<SongItem>();
+				for (int i = 0; i < mSongItemListDiaplayAdapter.getCount(); i++)
+				{
+					SongItem si = mSongItemListDiaplayAdapter.getItem(i);
+					if(si.isSelected)
+						songitems.add(si);
+				}
+				L.d(DEBUG_TAG,"selected "+songitems.size());
+				mOnSongItemClicked.onSongItemClicked(songitems);
+				dismiss();
+			}
+		});
 
 		WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
 		lp.copyFrom(getWindow().getAttributes());
 	{
 		mListView.setAdapter(null);
 		mListView.setOnItemClickListener(null);
+		mSongItemListDiaplayAdapter = null;
 		super.dismiss();
 	}
-	
-	public static interface OnSongItemClicked{
-		public void onSongItemClicked(SongItem songItem);
+
+	public static interface OnSongItemClicked
+	{
+		public void onSongItemClicked(ArrayList<SongItem> songItems);
 	}
 
 }