Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to search videos for the current song #316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.naman14.timber.nowplaying;

import android.animation.ObjectAnimator;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.os.AsyncTask;
Expand All @@ -30,7 +31,9 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
Expand Down Expand Up @@ -221,6 +224,51 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
accentColor = Config.accentColor(getActivity(), ateKey);
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.now_playing, menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_search_videos:
pauseMusicPlayer();
openSongSearchOnYouTubeApp();
break;
}
return super.onOptionsItemSelected(item);
}

private void pauseMusicPlayer() {
if (MusicPlayer.isPlaying()) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
MusicPlayer.playOrPause();
if (recyclerView != null && recyclerView.getAdapter() != null)
recyclerView.getAdapter().notifyDataSetChanged();
}
}, 250);
}
}

private void openSongSearchOnYouTubeApp() {
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("com.google.android.youtube");
intent.putExtra("query", MusicPlayer.getArtistName() + " " + MusicPlayer.getTrackName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}

@Override
public void onPause() {
super.onPause();
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/menu/now_playing.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_search_videos"
android:title="@string/search_videos" />
</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,5 @@

<string name="cancel">Cancel</string>

<string name="search_videos">Search Videos</string>
</resources>