aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-04-28 17:19:01 -0700
committerScott Jackson <daneren2005@gmail.com>2013-04-28 17:19:01 -0700
commit68a033d58ac9bb4848244063089eae61cb7c968b (patch)
tree0b6d53e31e54bdcb0710e685273540194a7b943d
parent1c2ea00cc33f81ae5de68fbc918fa91c50e51127 (diff)
downloaddsub-68a033d58ac9bb4848244063089eae61cb7c968b.tar.gz
dsub-68a033d58ac9bb4848244063089eae61cb7c968b.tar.bz2
dsub-68a033d58ac9bb4848244063089eae61cb7c968b.zip
Use same callbacks for search fragment
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java54
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java125
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java131
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java10
4 files changed, 153 insertions, 167 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java
index 1b971cdf..ea09328d 100644
--- a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java
+++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java
@@ -32,14 +32,12 @@ import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.view.ArtistAdapter;
import github.daneren2005.dsub.util.BackgroundTask;
-import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.view.EntryAdapter;
import github.daneren2005.dsub.util.MergeAdapter;
-import github.daneren2005.dsub.util.TabActivityBackgroundTask;
import github.daneren2005.dsub.util.TabBackgroundTask;
import github.daneren2005.dsub.util.Util;
-public class SearchFragment extends SubsonicTabFragment {
+public class SearchFragment extends SubsonicFragment {
private static final int DEFAULT_ARTISTS = 3;
private static final int DEFAULT_ALBUMS = 5;
private static final int DEFAULT_SONGS = 10;
@@ -131,19 +129,8 @@ public class SearchFragment extends SubsonicTabFragment {
@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
- switch (item.getItemId()) {
- case R.id.menu_search:
- context.onSearchRequested();
- return true;
- case R.id.menu_exit:
- exit();
- return true;
- case R.id.menu_settings:
- startActivity(new Intent(context, SettingsActivity.class));
- return true;
- case R.id.menu_help:
- startActivity(new Intent(context, HelpActivity.class));
- return true;
+ if(super.onOptionsItemSelected(item)) {
+ return true;
}
return false;
@@ -173,38 +160,9 @@ public class SearchFragment extends SubsonicTabFragment {
public boolean onContextItemSelected(MenuItem menuItem) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
Object selectedItem = list.getItemAtPosition(info.position);
-
- Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null;
- MusicDirectory.Entry entry = selectedItem instanceof MusicDirectory.Entry ? (MusicDirectory.Entry) selectedItem : null;
- String id = artist != null ? artist.getId() : entry.getId();
-
- switch (menuItem.getItemId()) {
- case R.id.album_menu_play_now:
- downloadRecursively(id, false, false, true, false, false);
- break;
- case R.id.album_menu_play_shuffled:
- downloadRecursively(id, false, false, true, true, false);
- break;
- case R.id.album_menu_play_last:
- downloadRecursively(id, false, true, false, false, false);
- break;
- case R.id.album_menu_download:
- downloadRecursively(id, false, true, false, false, true);
- break;
- case R.id.album_menu_pin:
- downloadRecursively(id, true, true, false, false, true);
- break;
- case R.id.song_menu_play_now:
- onSongSelected(entry, false, false, true, false);
- break;
- case R.id.song_menu_play_next:
- onSongSelected(entry, false, true, false, true);
- break;
- case R.id.song_menu_play_last:
- onSongSelected(entry, false, true, false, false);
- break;
- default:
- return super.onContextItemSelected(menuItem);
+
+ if(super.onContextItemSelected(menuItem, selectedItem)) {
+ return true;
}
return true;
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
index 5bc15fb7..c518f73e 100644
--- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
+++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
@@ -219,80 +219,19 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap
@Override
public boolean onContextItemSelected(MenuItem menuItem) {
- if(!primaryFragment) {
- return false;
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
+ Object selectedItem = entries.get(info.position);
+
+ if(super.onContextItemSelected(menuItem, selectedItem)) {
+ return true;
}
- AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
- MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position);
- List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>(10);
- songs.add((MusicDirectory.Entry) entryList.getItemAtPosition(info.position));
switch (menuItem.getItemId()) {
- case R.id.album_menu_play_now:
- downloadRecursively(entry.getId(), false, false, true, false, false);
- break;
- case R.id.album_menu_play_shuffled:
- downloadRecursively(entry.getId(), false, false, true, true, false);
- break;
- case R.id.album_menu_play_last:
- downloadRecursively(entry.getId(), false, true, false, false, false);
- break;
- case R.id.album_menu_download:
- downloadRecursively(entry.getId(), false, true, false, false, true);
- break;
- case R.id.album_menu_pin:
- downloadRecursively(entry.getId(), true, true, false, false, true);
- break;
- case R.id.album_menu_star:
- toggleStarred(entry);
- break;
- case R.id.album_menu_delete:
- deleteRecursively(entry);
- break;
- case R.id.song_menu_play_now:
- getDownloadService().clear();
- getDownloadService().download(songs, false, true, true, false);
- Util.startActivityWithoutTransition(context, DownloadActivity.class);
- break;
- case R.id.song_menu_play_next:
- getDownloadService().download(songs, false, false, true, false);
- break;
- case R.id.song_menu_play_last:
- getDownloadService().download(songs, false, false, false, false);
- break;
- case R.id.song_menu_download:
- getDownloadService().downloadBackground(songs, false);
- break;
- case R.id.song_menu_pin:
- getDownloadService().downloadBackground(songs, true);
- break;
- case R.id.song_menu_delete:
- getDownloadService().delete(songs);
- break;
- case R.id.song_menu_add_playlist:
- addToPlaylist(songs);
- break;
- case R.id.song_menu_star:
- toggleStarred(entry);
- break;
- case R.id.song_menu_webview:
- playWebView(entry);
- break;
- case R.id.song_menu_play_external:
- playExternalPlayer(entry);
- break;
- case R.id.song_menu_info:
- displaySongInfo(entry);
- break;
- case R.id.song_menu_stream_external:
- streamExternalPlayer(entry);
- break;
case R.id.song_menu_remove_playlist:
removeFromPlaylist(playlistId, playlistName, Arrays.<Integer>asList(info.position - 1));
break;
- default:
- return super.onContextItemSelected(menuItem);
}
+
return true;
}
@@ -611,58 +550,6 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap
}
}
- private boolean entryExists(MusicDirectory.Entry entry) {
- DownloadFile check = new DownloadFile(context, entry, false);
- return check.isCompleteFileAvailable();
- }
-
- private void playWebView(MusicDirectory.Entry entry) {
- int maxBitrate = Util.getMaxVideoBitrate(context);
-
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setData(Uri.parse(MusicServiceFactory.getMusicService(context).getVideoUrl(maxBitrate, context, entry.getId())));
-
- startActivity(intent);
- }
- private void playExternalPlayer(MusicDirectory.Entry entry) {
- if(!entryExists(entry)) {
- Util.toast(context, R.string.download_need_download);
- } else {
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.parse(entry.getPath()), "video/*");
-
- List<ResolveInfo> intents = context.getPackageManager()
- .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
- if(intents != null && intents.size() > 0) {
- startActivity(intent);
- }else {
- Util.toast(context, R.string.download_no_streaming_player);
- }
- }
- }
- private void streamExternalPlayer(MusicDirectory.Entry entry) {
- int maxBitrate = Util.getMaxVideoBitrate(context);
-
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService(context).getVideoStreamUrl(maxBitrate, context, entry.getId())), "video/*");
-
- List<ResolveInfo> intents = context.getPackageManager()
- .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
- if(intents != null && intents.size() > 0) {
- startActivity(intent);
- } else {
- Util.toast(context, R.string.download_no_streaming_player);
- }
- }
-
- public void deleteRecursively(MusicDirectory.Entry album) {
- File dir = FileUtil.getAlbumDirectory(context, album);
- Util.recursiveDelete(dir);
- if(Util.isOffline(context)) {
- refresh();
- }
- }
-
public void removeFromPlaylist(final String id, final String name, final List<Integer> indexes) {
new LoadingTask<Void>(context, true) {
@Override
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
index 9fc1308e..043c7373 100644
--- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -24,10 +24,15 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.media.MediaMetadataRetriever;
+import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
+import android.view.MenuItem;
import android.view.View;
+import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
@@ -55,6 +60,7 @@ import github.daneren2005.dsub.util.LoadingTask;
import github.daneren2005.dsub.util.Util;
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
@@ -110,6 +116,79 @@ public class SubsonicFragment extends SherlockFragment {
return false;
}
+
+ public boolean onContextItemSelected(MenuItem menuItem, Object selectedItem) {
+ Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null;
+ MusicDirectory.Entry entry = selectedItem instanceof MusicDirectory.Entry ? (MusicDirectory.Entry) selectedItem : null;
+ List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>(10);
+ songs.add(entry);
+
+ switch (menuItem.getItemId()) {
+ case R.id.album_menu_play_now:
+ downloadRecursively(entry.getId(), false, false, true, false, false);
+ break;
+ case R.id.album_menu_play_shuffled:
+ downloadRecursively(entry.getId(), false, false, true, true, false);
+ break;
+ case R.id.album_menu_play_last:
+ downloadRecursively(entry.getId(), false, true, false, false, false);
+ break;
+ case R.id.album_menu_download:
+ downloadRecursively(entry.getId(), false, true, false, false, true);
+ break;
+ case R.id.album_menu_pin:
+ downloadRecursively(entry.getId(), true, true, false, false, true);
+ break;
+ case R.id.album_menu_star:
+ toggleStarred(entry);
+ break;
+ case R.id.album_menu_delete:
+ deleteRecursively(entry);
+ break;
+ case R.id.song_menu_play_now:
+ getDownloadService().clear();
+ getDownloadService().download(songs, false, true, true, false);
+ Util.startActivityWithoutTransition(context, DownloadActivity.class);
+ break;
+ case R.id.song_menu_play_next:
+ getDownloadService().download(songs, false, false, true, false);
+ break;
+ case R.id.song_menu_play_last:
+ getDownloadService().download(songs, false, false, false, false);
+ break;
+ case R.id.song_menu_download:
+ getDownloadService().downloadBackground(songs, false);
+ break;
+ case R.id.song_menu_pin:
+ getDownloadService().downloadBackground(songs, true);
+ break;
+ case R.id.song_menu_delete:
+ getDownloadService().delete(songs);
+ break;
+ case R.id.song_menu_add_playlist:
+ addToPlaylist(songs);
+ break;
+ case R.id.song_menu_star:
+ toggleStarred(entry);
+ break;
+ case R.id.song_menu_webview:
+ playWebView(entry);
+ break;
+ case R.id.song_menu_play_external:
+ playExternalPlayer(entry);
+ break;
+ case R.id.song_menu_info:
+ displaySongInfo(entry);
+ break;
+ case R.id.song_menu_stream_external:
+ streamExternalPlayer(entry);
+ break;
+ default:
+ return false;
+ }
+
+ return true;
+ }
public DownloadService getDownloadService() {
return context != null ? context.getDownloadService() : null;
@@ -479,4 +558,56 @@ public class SubsonicFragment extends SherlockFragment {
.setMessage(msg)
.show();
}
+
+ protected void playWebView(MusicDirectory.Entry entry) {
+ int maxBitrate = Util.getMaxVideoBitrate(context);
+
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setData(Uri.parse(MusicServiceFactory.getMusicService(context).getVideoUrl(maxBitrate, context, entry.getId())));
+
+ startActivity(intent);
+ }
+ protected void playExternalPlayer(MusicDirectory.Entry entry) {
+ if(!entryExists(entry)) {
+ Util.toast(context, R.string.download_need_download);
+ } else {
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setDataAndType(Uri.parse(entry.getPath()), "video/*");
+
+ List<ResolveInfo> intents = context.getPackageManager()
+ .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
+ if(intents != null && intents.size() > 0) {
+ startActivity(intent);
+ }else {
+ Util.toast(context, R.string.download_no_streaming_player);
+ }
+ }
+ }
+ protected void streamExternalPlayer(MusicDirectory.Entry entry) {
+ int maxBitrate = Util.getMaxVideoBitrate(context);
+
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService(context).getVideoStreamUrl(maxBitrate, context, entry.getId())), "video/*");
+
+ List<ResolveInfo> intents = context.getPackageManager()
+ .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
+ if(intents != null && intents.size() > 0) {
+ startActivity(intent);
+ } else {
+ Util.toast(context, R.string.download_no_streaming_player);
+ }
+ }
+
+ protected boolean entryExists(MusicDirectory.Entry entry) {
+ DownloadFile check = new DownloadFile(context, entry, false);
+ return check.isCompleteFileAvailable();
+ }
+
+ public void deleteRecursively(MusicDirectory.Entry album) {
+ File dir = FileUtil.getAlbumDirectory(context, album);
+ Util.recursiveDelete(dir);
+ if(Util.isOffline(context)) {
+ refresh();
+ }
+ }
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java
index eeed999a..3045d99b 100644
--- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java
+++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java
@@ -19,12 +19,22 @@
package github.daneren2005.dsub.fragments;
import android.util.Log;
+import android.view.MenuItem;
public class SubsonicTabFragment extends SubsonicFragment {
private static final String TAG = SubsonicTabFragment.class.getSimpleName();
protected boolean primaryFragment = false;
protected boolean invalidated = false;
+ @Override
+ public boolean onContextItemSelected(MenuItem menuItem, Object selectedItem) {
+ if(!primaryFragment) {
+ return true;
+ }
+
+ return super.onContextItemSelected(menuItem, selectedItem);
+ }
+
public void replaceFragment(SubsonicTabFragment fragment, int id) {
this.setPrimaryFragment(false);
fragment.setPrimaryFragment(true);