mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-15 08:50:35 +03:00
Add left/right swipe gestures to change views
This commit is contained in:
parent
6cd6b47b03
commit
49c9d3184f
66
.project
66
.project
@ -1,33 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Subsonic-Android</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Subsonic</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<manifest xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
package="net.sourceforge.subsonic.androidapp"
|
||||
a:versionCode="47"
|
||||
a:versionName="3.9.9.2" a:installLocation="auto">
|
||||
a:versionName="3.9.9.3" a:installLocation="auto">
|
||||
|
||||
<uses-permission a:name="android.permission.INTERNET"/>
|
||||
<uses-permission a:name="android.permission.READ_PHONE_STATE"/>
|
||||
@ -12,7 +12,7 @@
|
||||
<uses-permission a:name="android.permission.RECORD_AUDIO"/>
|
||||
<uses-permission a:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
|
||||
|
||||
<uses-sdk a:minSdkVersion="9" a:targetSdkVersion="15"/>
|
||||
<uses-sdk a:minSdkVersion="11" a:targetSdkVersion="16"/>
|
||||
|
||||
<supports-screens a:anyDensity="true" a:xlargeScreens="true" a:largeScreens="true" a:normalScreens="true" a:smallScreens="true"/>
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
<manifest xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
package="net.sourceforge.subsonic.androidapp"
|
||||
a:versionCode="47"
|
||||
a:versionName="3.9.9.2" a:installLocation="auto">
|
||||
a:versionName="3.9.9.3" a:installLocation="auto">
|
||||
|
||||
<uses-permission a:name="android.permission.INTERNET"/>
|
||||
<uses-permission a:name="android.permission.READ_PHONE_STATE"/>
|
||||
@ -12,7 +12,7 @@
|
||||
<uses-permission a:name="android.permission.RECORD_AUDIO"/>
|
||||
<uses-permission a:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
|
||||
|
||||
<uses-sdk a:minSdkVersion="9" a:targetSdkVersion="15"/>
|
||||
<uses-sdk a:minSdkVersion="11" a:targetSdkVersion="16"/>
|
||||
|
||||
<supports-screens a:anyDensity="true" a:xlargeScreens="true" a:largeScreens="true" a:normalScreens="true" a:smallScreens="true"/>
|
||||
|
||||
|
BIN
bin/Subsonic.apk
Normal file
BIN
bin/Subsonic.apk
Normal file
Binary file not shown.
BIN
bin/classes.dex
BIN
bin/classes.dex
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -144,19 +144,19 @@ public final class R {
|
||||
public static final int action_button_4=0x7f0d0003;
|
||||
public static final int actionbar_home_icon=0x7f0d0000;
|
||||
public static final int actionbar_title_text=0x7f0d0001;
|
||||
public static final int album=0x7f0d0050;
|
||||
public static final int album=0x7f0d0051;
|
||||
public static final int album_artist=0x7f0d0008;
|
||||
public static final int album_coverart=0x7f0d0006;
|
||||
public static final int album_menu_pin=0x7f0d008a;
|
||||
public static final int album_menu_play_last=0x7f0d0089;
|
||||
public static final int album_menu_play_now=0x7f0d0088;
|
||||
public static final int album_menu_pin=0x7f0d008b;
|
||||
public static final int album_menu_play_last=0x7f0d008a;
|
||||
public static final int album_menu_play_now=0x7f0d0089;
|
||||
public static final int album_title=0x7f0d0007;
|
||||
public static final int appwidget_coverart=0x7f0d0009;
|
||||
public static final int appwidget_top=0x7f0d000b;
|
||||
public static final int artist=0x7f0d000d;
|
||||
public static final int artist_menu_pin=0x7f0d008d;
|
||||
public static final int artist_menu_play_last=0x7f0d008c;
|
||||
public static final int artist_menu_play_now=0x7f0d008b;
|
||||
public static final int artist_menu_pin=0x7f0d008e;
|
||||
public static final int artist_menu_play_last=0x7f0d008d;
|
||||
public static final int artist_menu_play_now=0x7f0d008c;
|
||||
public static final int button_bar=0x7f0d0011;
|
||||
public static final int button_bar_home=0x7f0d0012;
|
||||
public static final int button_bar_music=0x7f0d0013;
|
||||
@ -166,7 +166,7 @@ public final class R {
|
||||
public static final int control_next=0x7f0d0010;
|
||||
public static final int control_play=0x7f0d000f;
|
||||
public static final int control_previous=0x7f0d000e;
|
||||
public static final int control_stop=0x7f0d0051;
|
||||
public static final int control_stop=0x7f0d0052;
|
||||
public static final int download_album=0x7f0d002d;
|
||||
public static final int download_album_art_image=0x7f0d0027;
|
||||
public static final int download_album_art_layout=0x7f0d0026;
|
||||
@ -203,86 +203,87 @@ public final class R {
|
||||
public static final int help_buttons=0x7f0d0037;
|
||||
public static final int help_close=0x7f0d0039;
|
||||
public static final int help_contents=0x7f0d003a;
|
||||
public static final int ic_menu_shuffle=0x7f0d0080;
|
||||
public static final int icon=0x7f0d0076;
|
||||
public static final int ic_menu_shuffle=0x7f0d0081;
|
||||
public static final int icon=0x7f0d0077;
|
||||
public static final int jukebox_volume_progress_bar=0x7f0d003c;
|
||||
public static final int linearLayout1=0x7f0d000a;
|
||||
public static final int lyrics_artist=0x7f0d003d;
|
||||
public static final int lyrics_text=0x7f0d003f;
|
||||
public static final int lyrics_title=0x7f0d003e;
|
||||
public static final int main_select_server_1=0x7f0d0043;
|
||||
public static final int main_select_server_2=0x7f0d0044;
|
||||
public static final int main_albums=0x7f0d0045;
|
||||
public static final int main_albums_frequent=0x7f0d0048;
|
||||
public static final int main_albums_highest=0x7f0d0049;
|
||||
public static final int main_albums_newest=0x7f0d0046;
|
||||
public static final int main_albums_random=0x7f0d004b;
|
||||
public static final int main_albums_recent=0x7f0d0047;
|
||||
public static final int main_albums_starred=0x7f0d004a;
|
||||
public static final int main_dummy=0x7f0d0041;
|
||||
public static final int main_list=0x7f0d0040;
|
||||
public static final int main_select_server=0x7f0d0042;
|
||||
public static final int menu_exit=0x7f0d007d;
|
||||
public static final int menu_help=0x7f0d007f;
|
||||
public static final int menu_lyrics=0x7f0d0085;
|
||||
public static final int menu_remove=0x7f0d0086;
|
||||
public static final int menu_remove_all=0x7f0d0082;
|
||||
public static final int menu_save_playlist=0x7f0d0081;
|
||||
public static final int menu_screen_on_off=0x7f0d0083;
|
||||
public static final int menu_settings=0x7f0d007e;
|
||||
public static final int menu_show_album=0x7f0d0084;
|
||||
public static final int menu_shuffle=0x7f0d0087;
|
||||
public static final int notification_image=0x7f0d004d;
|
||||
public static final int play_video_contents=0x7f0d0052;
|
||||
public static final int progress_message=0x7f0d0053;
|
||||
public static final int save_playlist_name=0x7f0d0055;
|
||||
public static final int save_playlist_root=0x7f0d0054;
|
||||
public static final int search_albums=0x7f0d0059;
|
||||
public static final int search_artists=0x7f0d0058;
|
||||
public static final int search_list=0x7f0d0056;
|
||||
public static final int search_more_albums=0x7f0d005c;
|
||||
public static final int search_more_artists=0x7f0d005b;
|
||||
public static final int search_more_songs=0x7f0d005d;
|
||||
public static final int search_search=0x7f0d0057;
|
||||
public static final int search_songs=0x7f0d005a;
|
||||
public static final int select_album_cover_art=0x7f0d0067;
|
||||
public static final int select_album_delete=0x7f0d0065;
|
||||
public static final int select_album_empty=0x7f0d005e;
|
||||
public static final int select_album_entries=0x7f0d005f;
|
||||
public static final int select_album_more=0x7f0d0066;
|
||||
public static final int select_album_pin=0x7f0d0063;
|
||||
public static final int select_album_play_all=0x7f0d006a;
|
||||
public static final int select_album_play_last=0x7f0d0062;
|
||||
public static final int select_album_play_now=0x7f0d0061;
|
||||
public static final int select_album_select=0x7f0d0060;
|
||||
public static final int select_album_text1=0x7f0d0068;
|
||||
public static final int select_album_text2=0x7f0d0069;
|
||||
public static final int select_album_unpin=0x7f0d0064;
|
||||
public static final int select_artist_folder=0x7f0d006c;
|
||||
public static final int select_artist_folder_1=0x7f0d006d;
|
||||
public static final int select_artist_folder_2=0x7f0d006e;
|
||||
public static final int select_artist_list=0x7f0d006b;
|
||||
public static final int select_playlist_empty=0x7f0d006f;
|
||||
public static final int select_playlist_list=0x7f0d0070;
|
||||
public static final int song_artist=0x7f0d0074;
|
||||
public static final int song_check=0x7f0d0071;
|
||||
public static final int song_duration=0x7f0d0075;
|
||||
public static final int song_menu_play_last=0x7f0d0090;
|
||||
public static final int song_menu_play_next=0x7f0d008f;
|
||||
public static final int song_menu_play_now=0x7f0d008e;
|
||||
public static final int song_status=0x7f0d0073;
|
||||
public static final int song_title=0x7f0d0072;
|
||||
public static final int status_icon=0x7f0d004e;
|
||||
public static final int status_media_collapse=0x7f0d007a;
|
||||
public static final int status_media_next=0x7f0d0079;
|
||||
public static final int status_media_play=0x7f0d0078;
|
||||
public static final int status_media_prev=0x7f0d0077;
|
||||
public static final int statusbar=0x7f0d004c;
|
||||
public static final int tab_progress=0x7f0d007b;
|
||||
public static final int tab_progress_message=0x7f0d007c;
|
||||
public static final int lyrics_artist=0x7f0d003e;
|
||||
public static final int lyrics_scrollview=0x7f0d003d;
|
||||
public static final int lyrics_text=0x7f0d0040;
|
||||
public static final int lyrics_title=0x7f0d003f;
|
||||
public static final int main_select_server_1=0x7f0d0044;
|
||||
public static final int main_select_server_2=0x7f0d0045;
|
||||
public static final int main_albums=0x7f0d0046;
|
||||
public static final int main_albums_frequent=0x7f0d0049;
|
||||
public static final int main_albums_highest=0x7f0d004a;
|
||||
public static final int main_albums_newest=0x7f0d0047;
|
||||
public static final int main_albums_random=0x7f0d004c;
|
||||
public static final int main_albums_recent=0x7f0d0048;
|
||||
public static final int main_albums_starred=0x7f0d004b;
|
||||
public static final int main_dummy=0x7f0d0042;
|
||||
public static final int main_list=0x7f0d0041;
|
||||
public static final int main_select_server=0x7f0d0043;
|
||||
public static final int menu_exit=0x7f0d007e;
|
||||
public static final int menu_help=0x7f0d0080;
|
||||
public static final int menu_lyrics=0x7f0d0086;
|
||||
public static final int menu_remove=0x7f0d0087;
|
||||
public static final int menu_remove_all=0x7f0d0083;
|
||||
public static final int menu_save_playlist=0x7f0d0082;
|
||||
public static final int menu_screen_on_off=0x7f0d0084;
|
||||
public static final int menu_settings=0x7f0d007f;
|
||||
public static final int menu_show_album=0x7f0d0085;
|
||||
public static final int menu_shuffle=0x7f0d0088;
|
||||
public static final int notification_image=0x7f0d004e;
|
||||
public static final int play_video_contents=0x7f0d0053;
|
||||
public static final int progress_message=0x7f0d0054;
|
||||
public static final int save_playlist_name=0x7f0d0056;
|
||||
public static final int save_playlist_root=0x7f0d0055;
|
||||
public static final int search_albums=0x7f0d005a;
|
||||
public static final int search_artists=0x7f0d0059;
|
||||
public static final int search_list=0x7f0d0057;
|
||||
public static final int search_more_albums=0x7f0d005d;
|
||||
public static final int search_more_artists=0x7f0d005c;
|
||||
public static final int search_more_songs=0x7f0d005e;
|
||||
public static final int search_search=0x7f0d0058;
|
||||
public static final int search_songs=0x7f0d005b;
|
||||
public static final int select_album_cover_art=0x7f0d0068;
|
||||
public static final int select_album_delete=0x7f0d0066;
|
||||
public static final int select_album_empty=0x7f0d005f;
|
||||
public static final int select_album_entries=0x7f0d0060;
|
||||
public static final int select_album_more=0x7f0d0067;
|
||||
public static final int select_album_pin=0x7f0d0064;
|
||||
public static final int select_album_play_all=0x7f0d006b;
|
||||
public static final int select_album_play_last=0x7f0d0063;
|
||||
public static final int select_album_play_now=0x7f0d0062;
|
||||
public static final int select_album_select=0x7f0d0061;
|
||||
public static final int select_album_text1=0x7f0d0069;
|
||||
public static final int select_album_text2=0x7f0d006a;
|
||||
public static final int select_album_unpin=0x7f0d0065;
|
||||
public static final int select_artist_folder=0x7f0d006d;
|
||||
public static final int select_artist_folder_1=0x7f0d006e;
|
||||
public static final int select_artist_folder_2=0x7f0d006f;
|
||||
public static final int select_artist_list=0x7f0d006c;
|
||||
public static final int select_playlist_empty=0x7f0d0070;
|
||||
public static final int select_playlist_list=0x7f0d0071;
|
||||
public static final int song_artist=0x7f0d0075;
|
||||
public static final int song_check=0x7f0d0072;
|
||||
public static final int song_duration=0x7f0d0076;
|
||||
public static final int song_menu_play_last=0x7f0d0091;
|
||||
public static final int song_menu_play_next=0x7f0d0090;
|
||||
public static final int song_menu_play_now=0x7f0d008f;
|
||||
public static final int song_status=0x7f0d0074;
|
||||
public static final int song_title=0x7f0d0073;
|
||||
public static final int status_icon=0x7f0d004f;
|
||||
public static final int status_media_collapse=0x7f0d007b;
|
||||
public static final int status_media_next=0x7f0d007a;
|
||||
public static final int status_media_play=0x7f0d0079;
|
||||
public static final int status_media_prev=0x7f0d0078;
|
||||
public static final int statusbar=0x7f0d004d;
|
||||
public static final int tab_progress=0x7f0d007c;
|
||||
public static final int tab_progress_message=0x7f0d007d;
|
||||
public static final int title=0x7f0d000c;
|
||||
public static final int toast_layout_root=0x7f0d003b;
|
||||
public static final int trackname=0x7f0d004f;
|
||||
public static final int trackname=0x7f0d0050;
|
||||
}
|
||||
public static final class integer {
|
||||
public static final int config_activityDefaultDur=0x7f080001;
|
||||
|
@ -7,6 +7,7 @@
|
||||
<include layout="@layout/tab_progress"/>
|
||||
|
||||
<ScrollView
|
||||
a:id="@+id/lyrics_scrollview"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="0dip"
|
||||
a:layout_weight="1.0">
|
||||
|
@ -323,6 +323,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
||||
onProgressChanged();
|
||||
}
|
||||
});
|
||||
playlistView.setOnTouchListener(gestureListener);
|
||||
|
||||
registerForContextMenu(playlistView);
|
||||
|
||||
|
@ -1,72 +1,79 @@
|
||||
/*
|
||||
This file is part of Subsonic.
|
||||
|
||||
Subsonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Subsonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
|
||||
package net.sourceforge.subsonic.androidapp.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
import net.sourceforge.subsonic.androidapp.R;
|
||||
import net.sourceforge.subsonic.androidapp.domain.Lyrics;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicService;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
|
||||
import net.sourceforge.subsonic.androidapp.util.BackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Constants;
|
||||
import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
|
||||
|
||||
/**
|
||||
* Displays song lyrics.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public final class LyricsActivity extends SubsonicTabActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
setContentView(R.layout.lyrics);
|
||||
load();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
BackgroundTask<Lyrics> task = new TabActivityBackgroundTask<Lyrics>(this) {
|
||||
@Override
|
||||
protected Lyrics doInBackground() throws Throwable {
|
||||
String artist = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ARTIST);
|
||||
String title = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_TITLE);
|
||||
MusicService musicService = MusicServiceFactory.getMusicService(LyricsActivity.this);
|
||||
return musicService.getLyrics(artist, title, LyricsActivity.this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done(Lyrics result) {
|
||||
TextView artistView = (TextView) findViewById(R.id.lyrics_artist);
|
||||
TextView titleView = (TextView) findViewById(R.id.lyrics_title);
|
||||
TextView textView = (TextView) findViewById(R.id.lyrics_text);
|
||||
if (result != null && result.getArtist() != null) {
|
||||
artistView.setText(result.getArtist());
|
||||
titleView.setText(result.getTitle());
|
||||
textView.setText(result.getText());
|
||||
} else {
|
||||
artistView.setText(R.string.lyrics_nomatch);
|
||||
}
|
||||
}
|
||||
};
|
||||
task.execute();
|
||||
}
|
||||
/*
|
||||
This file is part of Subsonic.
|
||||
|
||||
Subsonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Subsonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
|
||||
package net.sourceforge.subsonic.androidapp.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import net.sourceforge.subsonic.androidapp.R;
|
||||
import net.sourceforge.subsonic.androidapp.domain.Lyrics;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicService;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
|
||||
import net.sourceforge.subsonic.androidapp.util.BackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Constants;
|
||||
import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
|
||||
|
||||
/**
|
||||
* Displays song lyrics.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public final class LyricsActivity extends SubsonicTabActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
setContentView(R.layout.lyrics);
|
||||
View view = findViewById(R.id.lyrics_scrollview);
|
||||
if (view != null) view.setOnTouchListener(gestureListener);
|
||||
load();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
BackgroundTask<Lyrics> task = new TabActivityBackgroundTask<Lyrics>(this) {
|
||||
@Override
|
||||
protected Lyrics doInBackground() throws Throwable {
|
||||
String artist = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ARTIST);
|
||||
String title = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_TITLE);
|
||||
MusicService musicService = MusicServiceFactory.getMusicService(LyricsActivity.this);
|
||||
return musicService.getLyrics(artist, title, LyricsActivity.this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done(Lyrics result) {
|
||||
TextView artistView = (TextView) findViewById(R.id.lyrics_artist);
|
||||
TextView titleView = (TextView) findViewById(R.id.lyrics_title);
|
||||
TextView textView = (TextView) findViewById(R.id.lyrics_text);
|
||||
|
||||
if (result != null && result.getArtist() != null) {
|
||||
artistView.setText(result.getArtist());
|
||||
titleView.setText(result.getTitle());
|
||||
textView.setText(result.getText());
|
||||
} else {
|
||||
artistView.setText(R.string.lyrics_nomatch);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
task.execute();
|
||||
}
|
||||
}
|
@ -90,6 +90,7 @@ public class MainActivity extends SubsonicTabActivity {
|
||||
serverTextView.setText(name);
|
||||
|
||||
ListView list = (ListView) findViewById(R.id.main_list);
|
||||
list.setOnTouchListener(gestureListener);
|
||||
|
||||
MergeAdapter adapter = new MergeAdapter();
|
||||
adapter.addViews(Arrays.asList(serverButton), true);
|
||||
|
@ -1,374 +1,376 @@
|
||||
/*
|
||||
This file is part of Subsonic.
|
||||
|
||||
Subsonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Subsonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
|
||||
package net.sourceforge.subsonic.androidapp.activity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.net.Uri;
|
||||
import net.sourceforge.subsonic.androidapp.R;
|
||||
import net.sourceforge.subsonic.androidapp.domain.Artist;
|
||||
import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
|
||||
import net.sourceforge.subsonic.androidapp.domain.SearchCritera;
|
||||
import net.sourceforge.subsonic.androidapp.domain.SearchResult;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicService;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
|
||||
import net.sourceforge.subsonic.androidapp.service.DownloadService;
|
||||
import net.sourceforge.subsonic.androidapp.util.ArtistAdapter;
|
||||
import net.sourceforge.subsonic.androidapp.util.BackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Constants;
|
||||
import net.sourceforge.subsonic.androidapp.util.EntryAdapter;
|
||||
import net.sourceforge.subsonic.androidapp.util.MergeAdapter;
|
||||
import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Util;
|
||||
|
||||
/**
|
||||
* Performs searches and displays the matching artists, albums and songs.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class SearchActivity extends SubsonicTabActivity {
|
||||
|
||||
private static final int DEFAULT_ARTISTS = 3;
|
||||
private static final int DEFAULT_ALBUMS = 5;
|
||||
private static final int DEFAULT_SONGS = 10;
|
||||
|
||||
private static final int MAX_ARTISTS = 10;
|
||||
private static final int MAX_ALBUMS = 20;
|
||||
private static final int MAX_SONGS = 25;
|
||||
private ListView list;
|
||||
|
||||
private View artistsHeading;
|
||||
private View albumsHeading;
|
||||
private View songsHeading;
|
||||
private TextView searchButton;
|
||||
private View moreArtistsButton;
|
||||
private View moreAlbumsButton;
|
||||
private View moreSongsButton;
|
||||
private SearchResult searchResult;
|
||||
private MergeAdapter mergeAdapter;
|
||||
private ArtistAdapter artistAdapter;
|
||||
private ListAdapter moreArtistsAdapter;
|
||||
private EntryAdapter albumAdapter;
|
||||
private ListAdapter moreAlbumsAdapter;
|
||||
private ListAdapter moreSongsAdapter;
|
||||
private EntryAdapter songAdapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.search);
|
||||
|
||||
setTitle(R.string.search_title);
|
||||
|
||||
View buttons = LayoutInflater.from(this).inflate(R.layout.search_buttons, null);
|
||||
|
||||
artistsHeading = buttons.findViewById(R.id.search_artists);
|
||||
albumsHeading = buttons.findViewById(R.id.search_albums);
|
||||
songsHeading = buttons.findViewById(R.id.search_songs);
|
||||
|
||||
searchButton = (TextView) buttons.findViewById(R.id.search_search);
|
||||
moreArtistsButton = buttons.findViewById(R.id.search_more_artists);
|
||||
moreAlbumsButton = buttons.findViewById(R.id.search_more_albums);
|
||||
moreSongsButton = buttons.findViewById(R.id.search_more_songs);
|
||||
|
||||
list = (ListView) findViewById(R.id.search_list);
|
||||
|
||||
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (view == searchButton) {
|
||||
onSearchRequested();
|
||||
} else if (view == moreArtistsButton) {
|
||||
expandArtists();
|
||||
} else if (view == moreAlbumsButton) {
|
||||
expandAlbums();
|
||||
} else if (view == moreSongsButton) {
|
||||
expandSongs();
|
||||
} else {
|
||||
Object item = parent.getItemAtPosition(position);
|
||||
if (item instanceof Artist) {
|
||||
onArtistSelected((Artist) item);
|
||||
} else if (item instanceof MusicDirectory.Entry) {
|
||||
MusicDirectory.Entry entry = (MusicDirectory.Entry) item;
|
||||
if (entry.isDirectory()) {
|
||||
onAlbumSelected(entry, false);
|
||||
} else if (entry.isVideo()) {
|
||||
onVideoSelected(entry);
|
||||
} else {
|
||||
onSongSelected(entry, false, true, true, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
registerForContextMenu(list);
|
||||
|
||||
// Button 1: gone
|
||||
findViewById(R.id.action_button_1).setVisibility(View.GONE);
|
||||
|
||||
// Button 2: gone
|
||||
findViewById(R.id.action_button_2).setVisibility(View.GONE);
|
||||
|
||||
// Button 3: gone
|
||||
findViewById(R.id.action_button_3).setVisibility(View.GONE);
|
||||
|
||||
// Button 4: search
|
||||
final ImageButton actionSearchButton = (ImageButton)findViewById(R.id.action_button_4);
|
||||
actionSearchButton.setImageResource(R.drawable.ic_menu_search);
|
||||
actionSearchButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
onSearchRequested();
|
||||
}
|
||||
});
|
||||
|
||||
onNewIntent(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
String query = intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY);
|
||||
boolean autoplay = intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false);
|
||||
boolean requestsearch = intent.getBooleanExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, false);
|
||||
|
||||
if (query != null) {
|
||||
mergeAdapter = new MergeAdapter();
|
||||
list.setAdapter(mergeAdapter);
|
||||
search(query, autoplay);
|
||||
} else {
|
||||
populateList();
|
||||
if (requestsearch)
|
||||
onSearchRequested();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, view, menuInfo);
|
||||
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
Object selectedItem = list.getItemAtPosition(info.position);
|
||||
|
||||
boolean isArtist = selectedItem instanceof Artist;
|
||||
boolean isAlbum = selectedItem instanceof MusicDirectory.Entry && ((MusicDirectory.Entry) selectedItem).isDirectory();
|
||||
boolean isSong = selectedItem instanceof MusicDirectory.Entry && (!((MusicDirectory.Entry) selectedItem).isDirectory())
|
||||
&& (!((MusicDirectory.Entry) selectedItem).isVideo());
|
||||
|
||||
if (isArtist || isAlbum) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.select_album_context, menu);
|
||||
} else if (isSong) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.select_song_context, menu);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
break;
|
||||
case R.id.album_menu_play_last:
|
||||
downloadRecursively(id, false, true, false);
|
||||
break;
|
||||
case R.id.album_menu_pin:
|
||||
downloadRecursively(id, true, true, false);
|
||||
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);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void search(final String query, final boolean autoplay) {
|
||||
BackgroundTask<SearchResult> task = new TabActivityBackgroundTask<SearchResult>(this) {
|
||||
@Override
|
||||
protected SearchResult doInBackground() throws Throwable {
|
||||
SearchCritera criteria = new SearchCritera(query, MAX_ARTISTS, MAX_ALBUMS, MAX_SONGS);
|
||||
MusicService service = MusicServiceFactory.getMusicService(SearchActivity.this);
|
||||
return service.search(criteria, SearchActivity.this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done(SearchResult result) {
|
||||
searchResult = result;
|
||||
populateList();
|
||||
if (autoplay) {
|
||||
autoplay();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
task.execute();
|
||||
}
|
||||
|
||||
private void populateList() {
|
||||
mergeAdapter = new MergeAdapter();
|
||||
mergeAdapter.addView(searchButton, true);
|
||||
|
||||
if (searchResult != null) {
|
||||
List<Artist> artists = searchResult.getArtists();
|
||||
if (!artists.isEmpty()) {
|
||||
mergeAdapter.addView(artistsHeading);
|
||||
List<Artist> displayedArtists = new ArrayList<Artist>(artists.subList(0, Math.min(DEFAULT_ARTISTS, artists.size())));
|
||||
artistAdapter = new ArtistAdapter(this, displayedArtists);
|
||||
mergeAdapter.addAdapter(artistAdapter);
|
||||
if (artists.size() > DEFAULT_ARTISTS) {
|
||||
moreArtistsAdapter = mergeAdapter.addView(moreArtistsButton, true);
|
||||
}
|
||||
}
|
||||
|
||||
List<MusicDirectory.Entry> albums = searchResult.getAlbums();
|
||||
if (!albums.isEmpty()) {
|
||||
mergeAdapter.addView(albumsHeading);
|
||||
List<MusicDirectory.Entry> displayedAlbums = new ArrayList<MusicDirectory.Entry>(albums.subList(0, Math.min(DEFAULT_ALBUMS, albums.size())));
|
||||
albumAdapter = new EntryAdapter(this, getImageLoader(), displayedAlbums, false);
|
||||
mergeAdapter.addAdapter(albumAdapter);
|
||||
if (albums.size() > DEFAULT_ALBUMS) {
|
||||
moreAlbumsAdapter = mergeAdapter.addView(moreAlbumsButton, true);
|
||||
}
|
||||
}
|
||||
|
||||
List<MusicDirectory.Entry> songs = searchResult.getSongs();
|
||||
if (!songs.isEmpty()) {
|
||||
mergeAdapter.addView(songsHeading);
|
||||
List<MusicDirectory.Entry> displayedSongs = new ArrayList<MusicDirectory.Entry>(songs.subList(0, Math.min(DEFAULT_SONGS, songs.size())));
|
||||
songAdapter = new EntryAdapter(this, getImageLoader(), displayedSongs, false);
|
||||
mergeAdapter.addAdapter(songAdapter);
|
||||
if (songs.size() > DEFAULT_SONGS) {
|
||||
moreSongsAdapter = mergeAdapter.addView(moreSongsButton, true);
|
||||
}
|
||||
}
|
||||
|
||||
boolean empty = searchResult.getArtists().isEmpty() && searchResult.getAlbums().isEmpty() && searchResult.getSongs().isEmpty();
|
||||
searchButton.setText(empty ? R.string.search_no_match : R.string.search_search);
|
||||
}
|
||||
|
||||
list.setAdapter(mergeAdapter);
|
||||
}
|
||||
|
||||
private void expandArtists() {
|
||||
artistAdapter.clear();
|
||||
for (Artist artist : searchResult.getArtists()) {
|
||||
artistAdapter.add(artist);
|
||||
}
|
||||
artistAdapter.notifyDataSetChanged();
|
||||
mergeAdapter.removeAdapter(moreArtistsAdapter);
|
||||
mergeAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void expandAlbums() {
|
||||
albumAdapter.clear();
|
||||
for (MusicDirectory.Entry album : searchResult.getAlbums()) {
|
||||
albumAdapter.add(album);
|
||||
}
|
||||
albumAdapter.notifyDataSetChanged();
|
||||
mergeAdapter.removeAdapter(moreAlbumsAdapter);
|
||||
mergeAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void expandSongs() {
|
||||
songAdapter.clear();
|
||||
for (MusicDirectory.Entry song : searchResult.getSongs()) {
|
||||
songAdapter.add(song);
|
||||
}
|
||||
songAdapter.notifyDataSetChanged();
|
||||
mergeAdapter.removeAdapter(moreSongsAdapter);
|
||||
mergeAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void onArtistSelected(Artist artist) {
|
||||
Intent intent = new Intent(this, SelectAlbumActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName());
|
||||
Util.startActivityWithoutTransition(this, intent);
|
||||
}
|
||||
|
||||
private void onAlbumSelected(MusicDirectory.Entry album, boolean autoplay) {
|
||||
Intent intent = new Intent(SearchActivity.this, SelectAlbumActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, album.getId());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, album.getTitle());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, autoplay);
|
||||
Util.startActivityWithoutTransition(SearchActivity.this, intent);
|
||||
}
|
||||
|
||||
private void onSongSelected(MusicDirectory.Entry song, boolean save, boolean append, boolean autoplay, boolean playNext) {
|
||||
DownloadService downloadService = getDownloadService();
|
||||
if (downloadService != null) {
|
||||
if (!append) {
|
||||
downloadService.clear();
|
||||
}
|
||||
downloadService.download(Arrays.asList(song), save, false, playNext);
|
||||
if (autoplay) {
|
||||
downloadService.play(downloadService.size() - 1);
|
||||
}
|
||||
|
||||
Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_added, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
private void onVideoSelected(MusicDirectory.Entry entry) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoUrl(this, entry.getId())));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void autoplay() {
|
||||
if (!searchResult.getSongs().isEmpty()) {
|
||||
onSongSelected(searchResult.getSongs().get(0), false, false, true, false);
|
||||
} else if (!searchResult.getAlbums().isEmpty()) {
|
||||
onAlbumSelected(searchResult.getAlbums().get(0), true);
|
||||
}
|
||||
}
|
||||
/*
|
||||
This file is part of Subsonic.
|
||||
|
||||
Subsonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Subsonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
|
||||
package net.sourceforge.subsonic.androidapp.activity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.net.Uri;
|
||||
import net.sourceforge.subsonic.androidapp.R;
|
||||
import net.sourceforge.subsonic.androidapp.domain.Artist;
|
||||
import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
|
||||
import net.sourceforge.subsonic.androidapp.domain.SearchCritera;
|
||||
import net.sourceforge.subsonic.androidapp.domain.SearchResult;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicService;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
|
||||
import net.sourceforge.subsonic.androidapp.service.DownloadService;
|
||||
import net.sourceforge.subsonic.androidapp.util.ArtistAdapter;
|
||||
import net.sourceforge.subsonic.androidapp.util.BackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Constants;
|
||||
import net.sourceforge.subsonic.androidapp.util.EntryAdapter;
|
||||
import net.sourceforge.subsonic.androidapp.util.MergeAdapter;
|
||||
import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Util;
|
||||
|
||||
/**
|
||||
* Performs searches and displays the matching artists, albums and songs.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class SearchActivity extends SubsonicTabActivity {
|
||||
|
||||
private static final int DEFAULT_ARTISTS = 3;
|
||||
private static final int DEFAULT_ALBUMS = 5;
|
||||
private static final int DEFAULT_SONGS = 10;
|
||||
|
||||
private static final int MAX_ARTISTS = 10;
|
||||
private static final int MAX_ALBUMS = 20;
|
||||
private static final int MAX_SONGS = 25;
|
||||
private ListView list;
|
||||
|
||||
private View artistsHeading;
|
||||
private View albumsHeading;
|
||||
private View songsHeading;
|
||||
private TextView searchButton;
|
||||
private View moreArtistsButton;
|
||||
private View moreAlbumsButton;
|
||||
private View moreSongsButton;
|
||||
private SearchResult searchResult;
|
||||
private MergeAdapter mergeAdapter;
|
||||
private ArtistAdapter artistAdapter;
|
||||
private ListAdapter moreArtistsAdapter;
|
||||
private EntryAdapter albumAdapter;
|
||||
private ListAdapter moreAlbumsAdapter;
|
||||
private ListAdapter moreSongsAdapter;
|
||||
private EntryAdapter songAdapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.search);
|
||||
|
||||
setTitle(R.string.search_title);
|
||||
|
||||
View buttons = LayoutInflater.from(this).inflate(R.layout.search_buttons, null);
|
||||
|
||||
artistsHeading = buttons.findViewById(R.id.search_artists);
|
||||
albumsHeading = buttons.findViewById(R.id.search_albums);
|
||||
songsHeading = buttons.findViewById(R.id.search_songs);
|
||||
|
||||
searchButton = (TextView) buttons.findViewById(R.id.search_search);
|
||||
moreArtistsButton = buttons.findViewById(R.id.search_more_artists);
|
||||
moreAlbumsButton = buttons.findViewById(R.id.search_more_albums);
|
||||
moreSongsButton = buttons.findViewById(R.id.search_more_songs);
|
||||
|
||||
list = (ListView) findViewById(R.id.search_list);
|
||||
|
||||
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (view == searchButton) {
|
||||
onSearchRequested();
|
||||
} else if (view == moreArtistsButton) {
|
||||
expandArtists();
|
||||
} else if (view == moreAlbumsButton) {
|
||||
expandAlbums();
|
||||
} else if (view == moreSongsButton) {
|
||||
expandSongs();
|
||||
} else {
|
||||
Object item = parent.getItemAtPosition(position);
|
||||
if (item instanceof Artist) {
|
||||
onArtistSelected((Artist) item);
|
||||
} else if (item instanceof MusicDirectory.Entry) {
|
||||
MusicDirectory.Entry entry = (MusicDirectory.Entry) item;
|
||||
if (entry.isDirectory()) {
|
||||
onAlbumSelected(entry, false);
|
||||
} else if (entry.isVideo()) {
|
||||
onVideoSelected(entry);
|
||||
} else {
|
||||
onSongSelected(entry, false, true, true, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
list.setOnTouchListener(gestureListener);
|
||||
|
||||
registerForContextMenu(list);
|
||||
|
||||
// Button 1: gone
|
||||
findViewById(R.id.action_button_1).setVisibility(View.GONE);
|
||||
|
||||
// Button 2: gone
|
||||
findViewById(R.id.action_button_2).setVisibility(View.GONE);
|
||||
|
||||
// Button 3: gone
|
||||
findViewById(R.id.action_button_3).setVisibility(View.GONE);
|
||||
|
||||
// Button 4: search
|
||||
final ImageButton actionSearchButton = (ImageButton)findViewById(R.id.action_button_4);
|
||||
actionSearchButton.setImageResource(R.drawable.ic_menu_search);
|
||||
actionSearchButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
onSearchRequested();
|
||||
}
|
||||
});
|
||||
|
||||
onNewIntent(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
String query = intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY);
|
||||
boolean autoplay = intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false);
|
||||
boolean requestsearch = intent.getBooleanExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, false);
|
||||
|
||||
if (query != null) {
|
||||
mergeAdapter = new MergeAdapter();
|
||||
list.setAdapter(mergeAdapter);
|
||||
search(query, autoplay);
|
||||
} else {
|
||||
populateList();
|
||||
if (requestsearch)
|
||||
onSearchRequested();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, view, menuInfo);
|
||||
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
Object selectedItem = list.getItemAtPosition(info.position);
|
||||
|
||||
boolean isArtist = selectedItem instanceof Artist;
|
||||
boolean isAlbum = selectedItem instanceof MusicDirectory.Entry && ((MusicDirectory.Entry) selectedItem).isDirectory();
|
||||
boolean isSong = selectedItem instanceof MusicDirectory.Entry && (!((MusicDirectory.Entry) selectedItem).isDirectory())
|
||||
&& (!((MusicDirectory.Entry) selectedItem).isVideo());
|
||||
|
||||
if (isArtist || isAlbum) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.select_album_context, menu);
|
||||
} else if (isSong) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.select_song_context, menu);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
break;
|
||||
case R.id.album_menu_play_last:
|
||||
downloadRecursively(id, false, true, false);
|
||||
break;
|
||||
case R.id.album_menu_pin:
|
||||
downloadRecursively(id, true, true, false);
|
||||
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);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void search(final String query, final boolean autoplay) {
|
||||
BackgroundTask<SearchResult> task = new TabActivityBackgroundTask<SearchResult>(this) {
|
||||
@Override
|
||||
protected SearchResult doInBackground() throws Throwable {
|
||||
SearchCritera criteria = new SearchCritera(query, MAX_ARTISTS, MAX_ALBUMS, MAX_SONGS);
|
||||
MusicService service = MusicServiceFactory.getMusicService(SearchActivity.this);
|
||||
return service.search(criteria, SearchActivity.this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done(SearchResult result) {
|
||||
searchResult = result;
|
||||
populateList();
|
||||
if (autoplay) {
|
||||
autoplay();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
task.execute();
|
||||
}
|
||||
|
||||
private void populateList() {
|
||||
mergeAdapter = new MergeAdapter();
|
||||
mergeAdapter.addView(searchButton, true);
|
||||
|
||||
if (searchResult != null) {
|
||||
List<Artist> artists = searchResult.getArtists();
|
||||
if (!artists.isEmpty()) {
|
||||
mergeAdapter.addView(artistsHeading);
|
||||
List<Artist> displayedArtists = new ArrayList<Artist>(artists.subList(0, Math.min(DEFAULT_ARTISTS, artists.size())));
|
||||
artistAdapter = new ArtistAdapter(this, displayedArtists);
|
||||
mergeAdapter.addAdapter(artistAdapter);
|
||||
if (artists.size() > DEFAULT_ARTISTS) {
|
||||
moreArtistsAdapter = mergeAdapter.addView(moreArtistsButton, true);
|
||||
}
|
||||
}
|
||||
|
||||
List<MusicDirectory.Entry> albums = searchResult.getAlbums();
|
||||
if (!albums.isEmpty()) {
|
||||
mergeAdapter.addView(albumsHeading);
|
||||
List<MusicDirectory.Entry> displayedAlbums = new ArrayList<MusicDirectory.Entry>(albums.subList(0, Math.min(DEFAULT_ALBUMS, albums.size())));
|
||||
albumAdapter = new EntryAdapter(this, getImageLoader(), displayedAlbums, false);
|
||||
mergeAdapter.addAdapter(albumAdapter);
|
||||
if (albums.size() > DEFAULT_ALBUMS) {
|
||||
moreAlbumsAdapter = mergeAdapter.addView(moreAlbumsButton, true);
|
||||
}
|
||||
}
|
||||
|
||||
List<MusicDirectory.Entry> songs = searchResult.getSongs();
|
||||
if (!songs.isEmpty()) {
|
||||
mergeAdapter.addView(songsHeading);
|
||||
List<MusicDirectory.Entry> displayedSongs = new ArrayList<MusicDirectory.Entry>(songs.subList(0, Math.min(DEFAULT_SONGS, songs.size())));
|
||||
songAdapter = new EntryAdapter(this, getImageLoader(), displayedSongs, false);
|
||||
mergeAdapter.addAdapter(songAdapter);
|
||||
if (songs.size() > DEFAULT_SONGS) {
|
||||
moreSongsAdapter = mergeAdapter.addView(moreSongsButton, true);
|
||||
}
|
||||
}
|
||||
|
||||
boolean empty = searchResult.getArtists().isEmpty() && searchResult.getAlbums().isEmpty() && searchResult.getSongs().isEmpty();
|
||||
searchButton.setText(empty ? R.string.search_no_match : R.string.search_search);
|
||||
}
|
||||
|
||||
list.setAdapter(mergeAdapter);
|
||||
}
|
||||
|
||||
private void expandArtists() {
|
||||
artistAdapter.clear();
|
||||
for (Artist artist : searchResult.getArtists()) {
|
||||
artistAdapter.add(artist);
|
||||
}
|
||||
artistAdapter.notifyDataSetChanged();
|
||||
mergeAdapter.removeAdapter(moreArtistsAdapter);
|
||||
mergeAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void expandAlbums() {
|
||||
albumAdapter.clear();
|
||||
for (MusicDirectory.Entry album : searchResult.getAlbums()) {
|
||||
albumAdapter.add(album);
|
||||
}
|
||||
albumAdapter.notifyDataSetChanged();
|
||||
mergeAdapter.removeAdapter(moreAlbumsAdapter);
|
||||
mergeAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void expandSongs() {
|
||||
songAdapter.clear();
|
||||
for (MusicDirectory.Entry song : searchResult.getSongs()) {
|
||||
songAdapter.add(song);
|
||||
}
|
||||
songAdapter.notifyDataSetChanged();
|
||||
mergeAdapter.removeAdapter(moreSongsAdapter);
|
||||
mergeAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void onArtistSelected(Artist artist) {
|
||||
Intent intent = new Intent(this, SelectAlbumActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName());
|
||||
Util.startActivityWithoutTransition(this, intent);
|
||||
}
|
||||
|
||||
private void onAlbumSelected(MusicDirectory.Entry album, boolean autoplay) {
|
||||
Intent intent = new Intent(SearchActivity.this, SelectAlbumActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, album.getId());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, album.getTitle());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, autoplay);
|
||||
Util.startActivityWithoutTransition(SearchActivity.this, intent);
|
||||
}
|
||||
|
||||
private void onSongSelected(MusicDirectory.Entry song, boolean save, boolean append, boolean autoplay, boolean playNext) {
|
||||
DownloadService downloadService = getDownloadService();
|
||||
if (downloadService != null) {
|
||||
if (!append) {
|
||||
downloadService.clear();
|
||||
}
|
||||
downloadService.download(Arrays.asList(song), save, false, playNext);
|
||||
if (autoplay) {
|
||||
downloadService.play(downloadService.size() - 1);
|
||||
}
|
||||
|
||||
Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_added, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
private void onVideoSelected(MusicDirectory.Entry entry) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoUrl(this, entry.getId())));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void autoplay() {
|
||||
if (!searchResult.getSongs().isEmpty()) {
|
||||
onSongSelected(searchResult.getSongs().get(0), false, false, true, false);
|
||||
} else if (!searchResult.getAlbums().isEmpty()) {
|
||||
onAlbumSelected(searchResult.getAlbums().get(0), true);
|
||||
}
|
||||
}
|
||||
}
|
@ -96,6 +96,7 @@ public class SelectAlbumActivity extends SubsonicTabActivity {
|
||||
}
|
||||
}
|
||||
});
|
||||
entryList.setOnTouchListener(gestureListener);
|
||||
|
||||
coverArtView = (ImageView) findViewById(R.id.actionbar_home_icon);
|
||||
selectButton = (Button) findViewById(R.id.select_album_select);
|
||||
|
@ -1,236 +1,237 @@
|
||||
/*
|
||||
This file is part of Subsonic.
|
||||
|
||||
Subsonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Subsonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
|
||||
package net.sourceforge.subsonic.androidapp.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import net.sourceforge.subsonic.androidapp.R;
|
||||
import net.sourceforge.subsonic.androidapp.domain.Artist;
|
||||
import net.sourceforge.subsonic.androidapp.domain.Indexes;
|
||||
import net.sourceforge.subsonic.androidapp.domain.MusicFolder;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicService;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
|
||||
import net.sourceforge.subsonic.androidapp.util.ArtistAdapter;
|
||||
import net.sourceforge.subsonic.androidapp.util.BackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Constants;
|
||||
import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SelectArtistActivity extends SubsonicTabActivity implements AdapterView.OnItemClickListener {
|
||||
|
||||
private static final int MENU_GROUP_MUSIC_FOLDER = 10;
|
||||
|
||||
private ListView artistList;
|
||||
private View folderButton;
|
||||
private TextView folderName;
|
||||
private List<MusicFolder> musicFolders;
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.select_artist);
|
||||
|
||||
artistList = (ListView) findViewById(R.id.select_artist_list);
|
||||
artistList.setOnItemClickListener(this);
|
||||
|
||||
folderButton = LayoutInflater.from(this).inflate(R.layout.select_artist_header, artistList, false);
|
||||
folderName = (TextView) folderButton.findViewById(R.id.select_artist_folder_2);
|
||||
|
||||
if (!Util.isOffline(this)) {
|
||||
artistList.addHeaderView(folderButton);
|
||||
}
|
||||
|
||||
registerForContextMenu(artistList);
|
||||
|
||||
setTitle(Util.isOffline(this) ? R.string.music_library_label_offline : R.string.music_library_label);
|
||||
|
||||
// Button 1: gone
|
||||
findViewById(R.id.action_button_1).setVisibility(View.GONE);
|
||||
|
||||
// Button 2: gone
|
||||
findViewById(R.id.action_button_2).setVisibility(View.GONE);
|
||||
|
||||
// Button 3: shuffle
|
||||
ImageButton shuffleButton = (ImageButton) findViewById(R.id.action_button_3);
|
||||
shuffleButton.setImageResource(R.drawable.ic_menu_shuffle);
|
||||
shuffleButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(SelectArtistActivity.this, DownloadActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true);
|
||||
Util.startActivityWithoutTransition(SelectArtistActivity.this, intent);
|
||||
}
|
||||
});
|
||||
|
||||
// Button 4: refresh
|
||||
ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_4);
|
||||
refreshButton.setImageResource(R.drawable.ic_menu_refresh);
|
||||
refreshButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
musicFolders = null;
|
||||
load();
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
finish();
|
||||
Intent intent = getIntent();
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true);
|
||||
Util.startActivityWithoutTransition(this, intent);
|
||||
}
|
||||
|
||||
private void selectFolder() {
|
||||
folderButton.showContextMenu();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
BackgroundTask<Indexes> task = new TabActivityBackgroundTask<Indexes>(this) {
|
||||
@Override
|
||||
protected Indexes doInBackground() throws Throwable {
|
||||
boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
|
||||
MusicService musicService = MusicServiceFactory.getMusicService(SelectArtistActivity.this);
|
||||
if (!Util.isOffline(SelectArtistActivity.this)) {
|
||||
musicFolders = musicService.getMusicFolders(SelectArtistActivity.this, this);
|
||||
}
|
||||
String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this);
|
||||
return musicService.getIndexes(musicFolderId, refresh, SelectArtistActivity.this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done(Indexes result) {
|
||||
List<Artist> artists = new ArrayList<Artist>(result.getShortcuts().size() + result.getArtists().size());
|
||||
artists.addAll(result.getShortcuts());
|
||||
artists.addAll(result.getArtists());
|
||||
artistList.setAdapter(new ArtistAdapter(SelectArtistActivity.this, artists));
|
||||
|
||||
// Display selected music folder
|
||||
if (musicFolders != null) {
|
||||
String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this);
|
||||
if (musicFolderId == null) {
|
||||
folderName.setText(R.string.select_artist_all_folders);
|
||||
} else {
|
||||
for (MusicFolder musicFolder : musicFolders) {
|
||||
if (musicFolder.getId().equals(musicFolderId)) {
|
||||
folderName.setText(musicFolder.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
task.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (view == folderButton) {
|
||||
selectFolder();
|
||||
} else {
|
||||
Artist artist = (Artist) parent.getItemAtPosition(position);
|
||||
Intent intent = new Intent(this, SelectAlbumActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName());
|
||||
Util.startActivityWithoutTransition(this, intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, view, menuInfo);
|
||||
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
|
||||
if (artistList.getItemAtPosition(info.position) instanceof Artist) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.select_artist_context, menu);
|
||||
} else if (info.position == 0) {
|
||||
String musicFolderId = Util.getSelectedMusicFolderId(this);
|
||||
MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders);
|
||||
if (musicFolderId == null) {
|
||||
menuItem.setChecked(true);
|
||||
}
|
||||
if (musicFolders != null) {
|
||||
for (int i = 0; i < musicFolders.size(); i++) {
|
||||
MusicFolder musicFolder = musicFolders.get(i);
|
||||
menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, i, i + 1, musicFolder.getName());
|
||||
if (musicFolder.getId().equals(musicFolderId)) {
|
||||
menuItem.setChecked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
menu.setGroupCheckable(MENU_GROUP_MUSIC_FOLDER, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem menuItem) {
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
|
||||
|
||||
Artist artist = (Artist) artistList.getItemAtPosition(info.position);
|
||||
|
||||
if (artist != null) {
|
||||
switch (menuItem.getItemId()) {
|
||||
case R.id.artist_menu_play_now:
|
||||
downloadRecursively(artist.getId(), false, false, true);
|
||||
break;
|
||||
case R.id.artist_menu_play_last:
|
||||
downloadRecursively(artist.getId(), false, true, false);
|
||||
break;
|
||||
case R.id.artist_menu_pin:
|
||||
downloadRecursively(artist.getId(), true, true, false);
|
||||
break;
|
||||
default:
|
||||
return super.onContextItemSelected(menuItem);
|
||||
}
|
||||
} else if (info.position == 0) {
|
||||
MusicFolder selectedFolder = menuItem.getItemId() == -1 ? null : musicFolders.get(menuItem.getItemId());
|
||||
String musicFolderId = selectedFolder == null ? null : selectedFolder.getId();
|
||||
String musicFolderName = selectedFolder == null ? getString(R.string.select_artist_all_folders)
|
||||
: selectedFolder.getName();
|
||||
Util.setSelectedMusicFolderId(this, musicFolderId);
|
||||
folderName.setText(musicFolderName);
|
||||
refresh();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
This file is part of Subsonic.
|
||||
|
||||
Subsonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Subsonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
|
||||
package net.sourceforge.subsonic.androidapp.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import net.sourceforge.subsonic.androidapp.R;
|
||||
import net.sourceforge.subsonic.androidapp.domain.Artist;
|
||||
import net.sourceforge.subsonic.androidapp.domain.Indexes;
|
||||
import net.sourceforge.subsonic.androidapp.domain.MusicFolder;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicService;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
|
||||
import net.sourceforge.subsonic.androidapp.util.ArtistAdapter;
|
||||
import net.sourceforge.subsonic.androidapp.util.BackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Constants;
|
||||
import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SelectArtistActivity extends SubsonicTabActivity implements AdapterView.OnItemClickListener {
|
||||
|
||||
private static final int MENU_GROUP_MUSIC_FOLDER = 10;
|
||||
|
||||
private ListView artistList;
|
||||
private View folderButton;
|
||||
private TextView folderName;
|
||||
private List<MusicFolder> musicFolders;
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.select_artist);
|
||||
|
||||
artistList = (ListView) findViewById(R.id.select_artist_list);
|
||||
artistList.setOnItemClickListener(this);
|
||||
artistList.setOnTouchListener(gestureListener);
|
||||
|
||||
folderButton = LayoutInflater.from(this).inflate(R.layout.select_artist_header, artistList, false);
|
||||
folderName = (TextView) folderButton.findViewById(R.id.select_artist_folder_2);
|
||||
|
||||
if (!Util.isOffline(this)) {
|
||||
artistList.addHeaderView(folderButton);
|
||||
}
|
||||
|
||||
registerForContextMenu(artistList);
|
||||
|
||||
setTitle(Util.isOffline(this) ? R.string.music_library_label_offline : R.string.music_library_label);
|
||||
|
||||
// Button 1: gone
|
||||
findViewById(R.id.action_button_1).setVisibility(View.GONE);
|
||||
|
||||
// Button 2: gone
|
||||
findViewById(R.id.action_button_2).setVisibility(View.GONE);
|
||||
|
||||
// Button 3: shuffle
|
||||
ImageButton shuffleButton = (ImageButton) findViewById(R.id.action_button_3);
|
||||
shuffleButton.setImageResource(R.drawable.ic_menu_shuffle);
|
||||
shuffleButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(SelectArtistActivity.this, DownloadActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true);
|
||||
Util.startActivityWithoutTransition(SelectArtistActivity.this, intent);
|
||||
}
|
||||
});
|
||||
|
||||
// Button 4: refresh
|
||||
ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_4);
|
||||
refreshButton.setImageResource(R.drawable.ic_menu_refresh);
|
||||
refreshButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
musicFolders = null;
|
||||
load();
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
finish();
|
||||
Intent intent = getIntent();
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true);
|
||||
Util.startActivityWithoutTransition(this, intent);
|
||||
}
|
||||
|
||||
private void selectFolder() {
|
||||
folderButton.showContextMenu();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
BackgroundTask<Indexes> task = new TabActivityBackgroundTask<Indexes>(this) {
|
||||
@Override
|
||||
protected Indexes doInBackground() throws Throwable {
|
||||
boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
|
||||
MusicService musicService = MusicServiceFactory.getMusicService(SelectArtistActivity.this);
|
||||
if (!Util.isOffline(SelectArtistActivity.this)) {
|
||||
musicFolders = musicService.getMusicFolders(SelectArtistActivity.this, this);
|
||||
}
|
||||
String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this);
|
||||
return musicService.getIndexes(musicFolderId, refresh, SelectArtistActivity.this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done(Indexes result) {
|
||||
List<Artist> artists = new ArrayList<Artist>(result.getShortcuts().size() + result.getArtists().size());
|
||||
artists.addAll(result.getShortcuts());
|
||||
artists.addAll(result.getArtists());
|
||||
artistList.setAdapter(new ArtistAdapter(SelectArtistActivity.this, artists));
|
||||
|
||||
// Display selected music folder
|
||||
if (musicFolders != null) {
|
||||
String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this);
|
||||
if (musicFolderId == null) {
|
||||
folderName.setText(R.string.select_artist_all_folders);
|
||||
} else {
|
||||
for (MusicFolder musicFolder : musicFolders) {
|
||||
if (musicFolder.getId().equals(musicFolderId)) {
|
||||
folderName.setText(musicFolder.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
task.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (view == folderButton) {
|
||||
selectFolder();
|
||||
} else {
|
||||
Artist artist = (Artist) parent.getItemAtPosition(position);
|
||||
Intent intent = new Intent(this, SelectAlbumActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName());
|
||||
Util.startActivityWithoutTransition(this, intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, view, menuInfo);
|
||||
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
|
||||
if (artistList.getItemAtPosition(info.position) instanceof Artist) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.select_artist_context, menu);
|
||||
} else if (info.position == 0) {
|
||||
String musicFolderId = Util.getSelectedMusicFolderId(this);
|
||||
MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders);
|
||||
if (musicFolderId == null) {
|
||||
menuItem.setChecked(true);
|
||||
}
|
||||
if (musicFolders != null) {
|
||||
for (int i = 0; i < musicFolders.size(); i++) {
|
||||
MusicFolder musicFolder = musicFolders.get(i);
|
||||
menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, i, i + 1, musicFolder.getName());
|
||||
if (musicFolder.getId().equals(musicFolderId)) {
|
||||
menuItem.setChecked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
menu.setGroupCheckable(MENU_GROUP_MUSIC_FOLDER, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem menuItem) {
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
|
||||
|
||||
Artist artist = (Artist) artistList.getItemAtPosition(info.position);
|
||||
|
||||
if (artist != null) {
|
||||
switch (menuItem.getItemId()) {
|
||||
case R.id.artist_menu_play_now:
|
||||
downloadRecursively(artist.getId(), false, false, true);
|
||||
break;
|
||||
case R.id.artist_menu_play_last:
|
||||
downloadRecursively(artist.getId(), false, true, false);
|
||||
break;
|
||||
case R.id.artist_menu_pin:
|
||||
downloadRecursively(artist.getId(), true, true, false);
|
||||
break;
|
||||
default:
|
||||
return super.onContextItemSelected(menuItem);
|
||||
}
|
||||
} else if (info.position == 0) {
|
||||
MusicFolder selectedFolder = menuItem.getItemId() == -1 ? null : musicFolders.get(menuItem.getItemId());
|
||||
String musicFolderId = selectedFolder == null ? null : selectedFolder.getId();
|
||||
String musicFolderName = selectedFolder == null ? getString(R.string.select_artist_all_folders)
|
||||
: selectedFolder.getName();
|
||||
Util.setSelectedMusicFolderId(this, musicFolderId);
|
||||
folderName.setText(musicFolderName);
|
||||
refresh();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,151 +1,152 @@
|
||||
/*
|
||||
This file is part of Subsonic.
|
||||
|
||||
Subsonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Subsonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
|
||||
package net.sourceforge.subsonic.androidapp.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
import net.sourceforge.subsonic.androidapp.R;
|
||||
import net.sourceforge.subsonic.androidapp.domain.Playlist;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicService;
|
||||
import net.sourceforge.subsonic.androidapp.util.BackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Constants;
|
||||
import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SelectPlaylistActivity extends SubsonicTabActivity implements AdapterView.OnItemClickListener {
|
||||
|
||||
private static final int MENU_ITEM_PLAY_ALL = 1;
|
||||
|
||||
private ListView list;
|
||||
private View emptyTextView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.select_playlist);
|
||||
|
||||
list = (ListView) findViewById(R.id.select_playlist_list);
|
||||
emptyTextView = findViewById(R.id.select_playlist_empty);
|
||||
list.setOnItemClickListener(this);
|
||||
registerForContextMenu(list);
|
||||
|
||||
// Title: Playlists
|
||||
setTitle(R.string.playlist_label);
|
||||
|
||||
// Button 1: gone
|
||||
findViewById(R.id.action_button_1).setVisibility(View.GONE);
|
||||
|
||||
// Button 2: gone
|
||||
findViewById(R.id.action_button_2).setVisibility(View.GONE);
|
||||
|
||||
// Button 3: gone
|
||||
findViewById(R.id.action_button_3).setVisibility(View.GONE);
|
||||
|
||||
// Button 4: refresh
|
||||
ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_4);
|
||||
refreshButton.setImageResource(R.drawable.ic_menu_refresh);
|
||||
refreshButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
finish();
|
||||
Intent intent = new Intent(this, SelectPlaylistActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true);
|
||||
Util.startActivityWithoutTransition(this, intent);
|
||||
}
|
||||
|
||||
private void load() {
|
||||
BackgroundTask<List<Playlist>> task = new TabActivityBackgroundTask<List<Playlist>>(this) {
|
||||
@Override
|
||||
protected List<Playlist> doInBackground() throws Throwable {
|
||||
MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this);
|
||||
boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
|
||||
return musicService.getPlaylists(refresh, SelectPlaylistActivity.this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done(List<Playlist> result) {
|
||||
list.setAdapter(new PlaylistAdapter(result));
|
||||
emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
};
|
||||
task.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, view, menuInfo);
|
||||
menu.add(Menu.NONE, MENU_ITEM_PLAY_ALL, MENU_ITEM_PLAY_ALL, R.string.common_play_now);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem menuItem) {
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
|
||||
Playlist playlist = (Playlist) list.getItemAtPosition(info.position);
|
||||
|
||||
switch (menuItem.getItemId()) {
|
||||
case MENU_ITEM_PLAY_ALL:
|
||||
Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true);
|
||||
Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent);
|
||||
break;
|
||||
default:
|
||||
return super.onContextItemSelected(menuItem);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
||||
Playlist playlist = (Playlist) parent.getItemAtPosition(position);
|
||||
|
||||
Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName());
|
||||
Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent);
|
||||
}
|
||||
|
||||
private class PlaylistAdapter extends ArrayAdapter<Playlist> {
|
||||
public PlaylistAdapter(List<Playlist> playlists) {
|
||||
super(SelectPlaylistActivity.this, R.layout.playlist_list_item, playlists);
|
||||
}
|
||||
}
|
||||
/*
|
||||
This file is part of Subsonic.
|
||||
|
||||
Subsonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Subsonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
|
||||
package net.sourceforge.subsonic.androidapp.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
import net.sourceforge.subsonic.androidapp.R;
|
||||
import net.sourceforge.subsonic.androidapp.domain.Playlist;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
|
||||
import net.sourceforge.subsonic.androidapp.service.MusicService;
|
||||
import net.sourceforge.subsonic.androidapp.util.BackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Constants;
|
||||
import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask;
|
||||
import net.sourceforge.subsonic.androidapp.util.Util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SelectPlaylistActivity extends SubsonicTabActivity implements AdapterView.OnItemClickListener {
|
||||
|
||||
private static final int MENU_ITEM_PLAY_ALL = 1;
|
||||
|
||||
private ListView list;
|
||||
private View emptyTextView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.select_playlist);
|
||||
|
||||
list = (ListView) findViewById(R.id.select_playlist_list);
|
||||
emptyTextView = findViewById(R.id.select_playlist_empty);
|
||||
list.setOnItemClickListener(this);
|
||||
list.setOnTouchListener(gestureListener);
|
||||
registerForContextMenu(list);
|
||||
|
||||
// Title: Playlists
|
||||
setTitle(R.string.playlist_label);
|
||||
|
||||
// Button 1: gone
|
||||
findViewById(R.id.action_button_1).setVisibility(View.GONE);
|
||||
|
||||
// Button 2: gone
|
||||
findViewById(R.id.action_button_2).setVisibility(View.GONE);
|
||||
|
||||
// Button 3: gone
|
||||
findViewById(R.id.action_button_3).setVisibility(View.GONE);
|
||||
|
||||
// Button 4: refresh
|
||||
ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_4);
|
||||
refreshButton.setImageResource(R.drawable.ic_menu_refresh);
|
||||
refreshButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
finish();
|
||||
Intent intent = new Intent(this, SelectPlaylistActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true);
|
||||
Util.startActivityWithoutTransition(this, intent);
|
||||
}
|
||||
|
||||
private void load() {
|
||||
BackgroundTask<List<Playlist>> task = new TabActivityBackgroundTask<List<Playlist>>(this) {
|
||||
@Override
|
||||
protected List<Playlist> doInBackground() throws Throwable {
|
||||
MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this);
|
||||
boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
|
||||
return musicService.getPlaylists(refresh, SelectPlaylistActivity.this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done(List<Playlist> result) {
|
||||
list.setAdapter(new PlaylistAdapter(result));
|
||||
emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
};
|
||||
task.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, view, menuInfo);
|
||||
menu.add(Menu.NONE, MENU_ITEM_PLAY_ALL, MENU_ITEM_PLAY_ALL, R.string.common_play_now);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem menuItem) {
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
|
||||
Playlist playlist = (Playlist) list.getItemAtPosition(info.position);
|
||||
|
||||
switch (menuItem.getItemId()) {
|
||||
case MENU_ITEM_PLAY_ALL:
|
||||
Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true);
|
||||
Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent);
|
||||
break;
|
||||
default:
|
||||
return super.onContextItemSelected(menuItem);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
||||
Playlist playlist = (Playlist) parent.getItemAtPosition(position);
|
||||
|
||||
Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId());
|
||||
intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName());
|
||||
Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent);
|
||||
}
|
||||
|
||||
private class PlaylistAdapter extends ArrayAdapter<Playlist> {
|
||||
public PlaylistAdapter(List<Playlist> playlists) {
|
||||
super(SelectPlaylistActivity.this, R.layout.playlist_list_item, playlists);
|
||||
}
|
||||
}
|
||||
}
|
@ -33,13 +33,19 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.GestureDetector.SimpleOnGestureListener;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.view.animation.TranslateAnimation;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import net.sourceforge.subsonic.androidapp.R;
|
||||
import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
|
||||
import net.sourceforge.subsonic.androidapp.service.DownloadService;
|
||||
@ -54,10 +60,12 @@ import net.sourceforge.subsonic.androidapp.util.Util;
|
||||
/**
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class SubsonicTabActivity extends Activity {
|
||||
|
||||
public class SubsonicTabActivity extends Activity implements OnClickListener{
|
||||
private static final String TAG = SubsonicTabActivity.class.getSimpleName();
|
||||
private static ImageLoader IMAGE_LOADER;
|
||||
private static final int SWIPE_MIN_DISTANCE = 120;
|
||||
private static final int SWIPE_MAX_OFF_PATH = 250;
|
||||
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
|
||||
|
||||
private boolean destroyed;
|
||||
private View homeButton;
|
||||
@ -65,6 +73,15 @@ public class SubsonicTabActivity extends Activity {
|
||||
private View searchButton;
|
||||
private View playlistButton;
|
||||
private View nowPlayingButton;
|
||||
|
||||
private GestureDetector gestureDetector;
|
||||
View.OnTouchListener gestureListener;
|
||||
|
||||
enum SwipeDirection
|
||||
{
|
||||
Left,
|
||||
Right
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
@ -74,6 +91,14 @@ public class SubsonicTabActivity extends Activity {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
startService(new Intent(this, DownloadServiceImpl.class));
|
||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
|
||||
gestureDetector = new GestureDetector(new GestureActivity());
|
||||
gestureListener = new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
return gestureDetector.onTouchEvent(event);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -89,7 +114,7 @@ public class SubsonicTabActivity extends Activity {
|
||||
Util.startActivityWithoutTransition(SubsonicTabActivity.this, intent);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
musicButton = findViewById(R.id.button_bar_music);
|
||||
musicButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -385,5 +410,105 @@ public class SubsonicTabActivity extends Activity {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
class GestureActivity extends SimpleOnGestureListener {
|
||||
@Override
|
||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||
try {
|
||||
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
|
||||
return false;
|
||||
|
||||
SwipeDirection swipe = null;
|
||||
|
||||
// right to left swipe
|
||||
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
|
||||
swipe = SwipeDirection.Left;
|
||||
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
|
||||
swipe = SwipeDirection.Right;
|
||||
}
|
||||
|
||||
String name = SubsonicTabActivity.this.getClass().getSimpleName();
|
||||
|
||||
switch (swipe)
|
||||
{
|
||||
case Right:
|
||||
if (name.equalsIgnoreCase("MainActivity"))
|
||||
{
|
||||
Intent intent = new Intent(SubsonicTabActivity.this, DownloadActivity.class);
|
||||
SubsonicTabActivity.this.startActivity(intent);
|
||||
}
|
||||
else if (name.equalsIgnoreCase("SelectArtistActivity") || name.equalsIgnoreCase("SelectAlbumActivity"))
|
||||
{
|
||||
Intent intent = new Intent(SubsonicTabActivity.this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
SubsonicTabActivity.this.startActivity(intent);
|
||||
}
|
||||
else if (name.equalsIgnoreCase("SearchActivity"))
|
||||
{
|
||||
Intent intent = new Intent(SubsonicTabActivity.this, SelectArtistActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
SubsonicTabActivity.this.startActivity(intent);
|
||||
}
|
||||
else if (name.equalsIgnoreCase("SelectPlaylistActivity"))
|
||||
{
|
||||
Intent intent = new Intent(SubsonicTabActivity.this, SearchActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, true);
|
||||
SubsonicTabActivity.this.startActivity(intent);
|
||||
}
|
||||
else if (name.equalsIgnoreCase("DownloadActivity") || name.equalsIgnoreCase("LyricsActivity"))
|
||||
{
|
||||
Intent intent = new Intent(SubsonicTabActivity.this, SelectPlaylistActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
SubsonicTabActivity.this.startActivity(intent);
|
||||
}
|
||||
|
||||
break;
|
||||
case Left:
|
||||
if (name.equalsIgnoreCase("MainActivity"))
|
||||
{
|
||||
Intent intent = new Intent(SubsonicTabActivity.this, SelectArtistActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
SubsonicTabActivity.this.startActivity(intent);
|
||||
}
|
||||
if (name.equalsIgnoreCase("SelectArtistActivity") || name.equalsIgnoreCase("SelectAlbumActivity"))
|
||||
{
|
||||
Intent intent = new Intent(SubsonicTabActivity.this, SearchActivity.class);
|
||||
intent.putExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, true);
|
||||
SubsonicTabActivity.this.startActivity(intent);
|
||||
}
|
||||
else if (name.equalsIgnoreCase("SearchActivity"))
|
||||
{
|
||||
Intent intent = new Intent(SubsonicTabActivity.this, SelectPlaylistActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
SubsonicTabActivity.this.startActivity(intent);
|
||||
}
|
||||
else if (name.equalsIgnoreCase("SelectPlaylistActivity"))
|
||||
{
|
||||
Intent intent = new Intent(SubsonicTabActivity.this, DownloadActivity.class);
|
||||
SubsonicTabActivity.this.startActivity(intent);
|
||||
}
|
||||
else if (name.equalsIgnoreCase("DownloadActivity") || name.equalsIgnoreCase("LyricsActivity"))
|
||||
{
|
||||
Intent intent = new Intent(SubsonicTabActivity.this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
SubsonicTabActivity.this.startActivity(intent);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,8 +74,8 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
||||
private final List<DownloadFile> cleanupCandidates = new ArrayList<DownloadFile>();
|
||||
private final Scrobbler scrobbler = new Scrobbler();
|
||||
private final JukeboxService jukeboxService = new JukeboxService(this);
|
||||
private final Notification notification = new Notification(R.drawable.ic_stat_subsonic, null, System.currentTimeMillis());
|
||||
|
||||
private final Notification notification = new Notification(R.drawable.ic_stat_subsonic, null, System.currentTimeMillis());
|
||||
|
||||
private DownloadFile currentPlaying;
|
||||
private DownloadFile currentDownloading;
|
||||
private CancellableTask bufferTask;
|
||||
|
@ -801,19 +801,18 @@ public class Util extends DownloadActivity {
|
||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
||||
views.setOnClickPendingIntent(R.id.control_play, pendingIntent);
|
||||
|
||||
intent = new Intent("2"); // Use a unique action name to ensure a different PendingIntent to be created.
|
||||
intent = new Intent("2");
|
||||
intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
|
||||
intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
|
||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
||||
views.setOnClickPendingIntent(R.id.control_next, pendingIntent);
|
||||
|
||||
intent = new Intent("3"); // Use a unique action name to ensure a different PendingIntent to be created.
|
||||
intent = new Intent("3");
|
||||
intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
|
||||
intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
|
||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
||||
views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
|
||||
|
||||
// Emulate media button clicks.
|
||||
intent = new Intent("4");
|
||||
intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
|
||||
intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP));
|
||||
|
Loading…
x
Reference in New Issue
Block a user