mirror of
https://github.com/playmusicexporter/playmusicexporter
synced 2024-05-14 00:46:42 +00:00
Add search view
This commit is contained in:
parent
c75ac1e8a9
commit
819cce3870
|
@ -22,8 +22,6 @@
|
|||
|
||||
package de.arcus.framework.superuser;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import org.apache.http.util.ByteArrayBuffer;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
|
|
@ -24,9 +24,14 @@ package de.arcus.playmusicexporter2.activitys;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import de.arcus.framework.logger.Logger;
|
||||
import de.arcus.framework.crashhandler.CrashHandler;
|
||||
|
@ -59,11 +64,13 @@ import de.arcus.playmusiclib.items.MusicTrackList;
|
|||
*/
|
||||
public class MusicTrackListActivity extends ActionBarActivity
|
||||
implements MusicTrackListFragment.Callbacks
|
||||
, NavigationDrawerFragment.NavigationDrawerCallbacks {
|
||||
, NavigationDrawerFragment.NavigationDrawerCallbacks,
|
||||
SearchView.OnQueryTextListener {
|
||||
|
||||
@Override
|
||||
public void onViewTypeChanged(NavigationDrawerFragment.ViewType viewType) {
|
||||
loadList(viewType);
|
||||
mViewType = viewType;
|
||||
loadList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,6 +83,12 @@ public class MusicTrackListActivity extends ActionBarActivity
|
|||
|
||||
private NavigationDrawerFragment mNavigationDrawerFragment;
|
||||
|
||||
private String mSearchKeyword;
|
||||
|
||||
private NavigationDrawerFragment.ViewType mViewType;
|
||||
|
||||
private SearchView mSearchView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -141,13 +154,14 @@ public class MusicTrackListActivity extends ActionBarActivity
|
|||
}
|
||||
|
||||
// Loads the list
|
||||
loadList(mNavigationDrawerFragment.getViewType());
|
||||
mViewType = mNavigationDrawerFragment.getViewType();
|
||||
loadList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the music list with the current view type
|
||||
*/
|
||||
private void loadList(NavigationDrawerFragment.ViewType viewType) {
|
||||
private void loadList() {
|
||||
// Manager is not loaded
|
||||
if (mPlayMusicManager == null) return;
|
||||
|
||||
|
@ -155,23 +169,26 @@ public class MusicTrackListActivity extends ActionBarActivity
|
|||
MusicTrackListFragment musicTrackListFragment = (MusicTrackListFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.track_list);
|
||||
|
||||
switch(viewType) {
|
||||
switch(mViewType) {
|
||||
case Album:
|
||||
// Load all albums to the list
|
||||
AlbumDataSource dataSourceAlbum = new AlbumDataSource(mPlayMusicManager);
|
||||
dataSourceAlbum.setOfflineOnly(true);
|
||||
dataSourceAlbum.setSerchKey(mSearchKeyword);
|
||||
musicTrackListFragment.setMusicTrackList(dataSourceAlbum.getAll());
|
||||
break;
|
||||
case Artist:
|
||||
// Load all artists to the list
|
||||
ArtistDataSource dataSourceArtist = new ArtistDataSource(mPlayMusicManager);
|
||||
dataSourceArtist.setOfflineOnly(true);
|
||||
dataSourceArtist.setSerchKey(mSearchKeyword);
|
||||
musicTrackListFragment.setMusicTrackList(dataSourceArtist.getAll());
|
||||
break;
|
||||
case Playlist:
|
||||
// Load all playlists to the list
|
||||
PlaylistDataSource dataSourcePlaylist = new PlaylistDataSource(mPlayMusicManager);
|
||||
dataSourcePlaylist.setOfflineOnly(true);
|
||||
dataSourcePlaylist.setSerchKey(mSearchKeyword);
|
||||
musicTrackListFragment.setMusicTrackList(dataSourcePlaylist.getAll());
|
||||
break;
|
||||
case Rated:
|
||||
|
@ -179,6 +196,7 @@ public class MusicTrackListActivity extends ActionBarActivity
|
|||
AlbumDataSource dataSourceRatedAlbum = new AlbumDataSource(mPlayMusicManager);
|
||||
dataSourceRatedAlbum.setOfflineOnly(true);
|
||||
dataSourceRatedAlbum.setRatedOnly(true);
|
||||
dataSourceRatedAlbum.setSerchKey(mSearchKeyword);
|
||||
musicTrackListFragment.setMusicTrackList(dataSourceRatedAlbum.getAll());
|
||||
break;
|
||||
}
|
||||
|
@ -212,4 +230,36 @@ public class MusicTrackListActivity extends ActionBarActivity
|
|||
startActivity(detailIntent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.music_track_list, menu);
|
||||
|
||||
// Finds the search item and create the search view
|
||||
MenuItem itemSearch = menu.findItem(R.id.action_search);
|
||||
mSearchView = (SearchView)MenuItemCompat.getActionView(itemSearch);
|
||||
|
||||
if (mSearchView != null) {
|
||||
// Sets the search listener
|
||||
mSearchView.setOnQueryTextListener(this);
|
||||
mSearchView.setIconifiedByDefault(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String keyword) {
|
||||
mSearchView.clearFocus();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String keyword) {
|
||||
mSearchKeyword = keyword;
|
||||
loadList();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,8 +41,6 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
|
||||
|
||||
import de.arcus.framework.settings.AppSettings;
|
||||
import de.arcus.playmusicexporter2.R;
|
||||
import de.arcus.playmusicexporter2.activitys.SettingsActivity;
|
||||
import de.arcus.playmusicexporter2.settings.PlayMusicExporterSettings;
|
||||
|
@ -207,9 +205,6 @@ public class NavigationDrawerFragment extends Fragment {
|
|||
* @param active Active
|
||||
*/
|
||||
public void setButtonActive(Button button, boolean active) {
|
||||
// Gets the button
|
||||
//Button button = (Button)parentView.findViewById(resID);
|
||||
|
||||
int colorText;
|
||||
int colorBackground;
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="Large Text"
|
||||
android:text="List title"
|
||||
android:id="@+id/text_music_track_list_title"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentRight="true"
|
||||
|
@ -67,7 +67,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="Medium Text"
|
||||
android:text="List subtitle"
|
||||
android:id="@+id/text_music_track_list_description"
|
||||
android:layout_below="@+id/text_music_track_list_title"
|
||||
android:layout_alignParentLeft="true"
|
||||
|
|
32
playmusicexporter/src/main/res/menu/music_track_list.xml
Normal file
32
playmusicexporter/src/main/res/menu/music_track_list.xml
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2015 David Schulte
|
||||
~
|
||||
~ Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
~ of this software and associated documentation files (the "Software"), to deal
|
||||
~ in the Software without restriction, including without limitation the rights
|
||||
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
~ copies of the Software, and to permit persons to whom the Software is
|
||||
~ furnished to do so, subject to the following conditions:
|
||||
~
|
||||
~ The above copyright notice and this permission notice shall be included in
|
||||
~ all copies or substantial portions of the Software.
|
||||
~
|
||||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
~ THE SOFTWARE.
|
||||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto/">
|
||||
<item
|
||||
android:id="@+id/action_search"
|
||||
android:title="@string/search"
|
||||
android:icon="@android:drawable/ic_menu_search"
|
||||
app:showAsAction="always"
|
||||
app:actionViewClass="android.support.v7.widget.SearchView"
|
||||
/>
|
||||
</menu>
|
|
@ -50,4 +50,5 @@
|
|||
<string name="notification_export_working_summery">Titel %1$d von %2$d wird exportiert…</string>
|
||||
<string name="notification_export_finished_summery">%1$d Titel wurden erfolgreich exportiert!</string>
|
||||
<string name="notification_export_finished_title">Export abgeschlossen!</string>
|
||||
<string name="search">Suchen</string>
|
||||
</resources>
|
|
@ -44,6 +44,8 @@
|
|||
<string name="notification_export_finished_summery">%1$d tracks were exported successfully!</string>
|
||||
<string name="notification_export_finished_single_summery">Track was exported successfully!</string>
|
||||
|
||||
<string name="search">Search</string>
|
||||
|
||||
<string name="settings_category_export">Export settings</string>
|
||||
<string name="settings_category_extra">Extras</string>
|
||||
<string name="settings_category_about_me">About me</string>
|
||||
|
|
Loading…
Reference in a new issue