Commit 25be8036 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Merge Search and Filter options

parent 67290fad
......@@ -6,6 +6,16 @@
<include layout="@layout/tab_layout" />
<include layout="@layout/button_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/sliding_tabs"
android:layout_marginTop="@dimen/default_margin"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginStart="@dimen/default_margin"
android:layout_marginRight="@dimen/default_margin"
android:layout_marginEnd="@dimen/default_margin" />
<TextView
android:id="@+id/no_media"
android:layout_width="wrap_content"
......@@ -25,7 +35,7 @@
android:id="@+id/swipeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/sliding_tabs">
android:layout_below="@+id/searchButton">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
......
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/searchButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:targetApi="11"
style="?android:attr/borderlessButtonStyle"
android:layout_marginTop="@dimen/default_margin"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginStart="@dimen/default_margin"
android:layout_marginRight="@dimen/default_margin"
android:layout_marginEnd="@dimen/default_margin"
android:text="@string/search_global"
android:gravity="center_horizontal"
android:textAppearance="@style/Result.Title"
android:visibility="gone" />
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/button_search" />
<org.videolan.vlc.gui.view.SwipeRefreshLayout
android:id="@+id/swipeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_below="@+id/searchButton">
<org.videolan.vlc.gui.view.AutoFitRecyclerView
android:id="@id/android:list"
android:layout_width="match_parent"
......@@ -101,4 +104,4 @@
</LinearLayout>
<include layout="@layout/shadow_top" />
</FrameLayout>
</RelativeLayout>
......@@ -17,16 +17,10 @@
vlc:showAsAction="ifRoom" />
<item
android:id="@+id/ml_menu_filter"
android:icon="@drawable/ic_menu_filter"
android:icon="@drawable/ic_menu_search"
vlc:actionViewClass="android.support.v7.widget.SearchView"
android:title="@string/searchable_hint"
vlc:showAsAction="always|collapseActionView"/>
<item
android:id="@+id/ml_menu_search"
android:icon="@drawable/ic_menu_search"
android:title="@string/search"
vlc:showAsAction="always" />
<item
android:id="@+id/ml_menu_last_playlist"
android:icon="@drawable/ic_menu_lastplaylist"
......
......@@ -403,6 +403,8 @@
<string name="network_empty">This directory is empty.</string>
<string name="network_connection_needed">No connection to local network.</string>
<string name="search_hint">Search media</string>
<string name="search_list_hint">Search media in current list</string>
<string name="search_global">Search in all media library</string>
<string name="directory_show_medialib">Show in MediaLib</string>
<string name="directory_hide_medialib">Hide from MediaLib</string>
<string name="playlist_save">Save Playlist</string>
......
......@@ -530,7 +530,7 @@ public class MainActivity extends AudioPlayerContainerActivity implements Device
MenuItem searchItem = menu.findItem(R.id.ml_menu_filter);
mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
mSearchView.setQueryHint(getString(R.string.search_hint));
mSearchView.setQueryHint(getString(R.string.search_list_hint));
mSearchView.setOnQueryTextListener(this);
MenuItemCompat.setOnActionExpandListener(searchItem, this);
return super.onCreateOptionsMenu(menu);
......@@ -777,11 +777,13 @@ public class MainActivity extends AudioPlayerContainerActivity implements Device
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
setSearchVisibility(true);
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
setSearchVisibility(false);
restoreCurrentList();
return true;
}
......@@ -791,6 +793,10 @@ public class MainActivity extends AudioPlayerContainerActivity implements Device
MenuItemCompat.collapseActionView(mMenu.findItem(R.id.ml_menu_filter));
}
public String getQuery() {
return mSearchView.getQuery().toString();
}
public void restoreCurrentList() {
Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
if (current instanceof Filterable) {
......@@ -798,6 +804,12 @@ public class MainActivity extends AudioPlayerContainerActivity implements Device
}
}
private void setSearchVisibility(boolean visible) {
Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
if (current instanceof Filterable)
((Filterable) current).setSearchVisibility(visible);
}
private static class MainActivityHandler extends WeakHandler<MainActivity> {
public MainActivityHandler(MainActivity owner) {
super(owner);
......
......@@ -21,6 +21,7 @@
package org.videolan.vlc.gui.audio;
import android.annotation.TargetApi;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
......@@ -36,7 +37,6 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
......@@ -61,6 +61,7 @@ import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.MediaInfoDialog;
import org.videolan.vlc.gui.SearchActivity;
import org.videolan.vlc.gui.SecondaryActivity;
import org.videolan.vlc.gui.browser.MediaBrowserFragment;
import org.videolan.vlc.gui.dialogs.SavePlaylistDialog;
......@@ -83,7 +84,7 @@ import java.util.List;
import java.util.Random;
import java.util.concurrent.ConcurrentLinkedQueue;
public class AudioBrowserFragment extends MediaBrowserFragment implements DevicesDiscoveryCb, SwipeRefreshLayout.OnRefreshListener, MediaBrowser.EventListener, IBrowser, ViewPager.OnPageChangeListener, AudioBrowserAdapter.ClickHandler, Medialibrary.ArtistsAddedCb, Medialibrary.ArtistsModifiedCb, Medialibrary.AlbumsAddedCb, Medialibrary.AlbumsModifiedCb, MediaAddedCb, MediaUpdatedCb, TabLayout.OnTabSelectedListener, Filterable {
public class AudioBrowserFragment extends MediaBrowserFragment implements DevicesDiscoveryCb, SwipeRefreshLayout.OnRefreshListener, MediaBrowser.EventListener, IBrowser, ViewPager.OnPageChangeListener, AudioBrowserAdapter.ClickHandler, Medialibrary.ArtistsAddedCb, Medialibrary.ArtistsModifiedCb, Medialibrary.AlbumsAddedCb, Medialibrary.AlbumsModifiedCb, MediaAddedCb, MediaUpdatedCb, TabLayout.OnTabSelectedListener, Filterable, View.OnClickListener {
public final static String TAG = "VLC/AudioBrowserFragment";
private MediaBrowser mMediaBrowser;
......@@ -102,6 +103,7 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements Device
private List<View> mLists;
private FastScroller mFastScroller;
private FloatingActionButton mFabPlayShuffleAll;
private View mSearchButtonView;
public static final int REFRESH = 101;
public static final int UPDATE_LIST = 102;
......@@ -166,6 +168,8 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements Device
mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipeLayout);
mSwipeRefreshLayout.setColorSchemeResources(R.color.orange700);
mSwipeRefreshLayout.setOnRefreshListener(this);
mSearchButtonView = v.findViewById(R.id.searchButton);
mSearchButtonView.setOnClickListener(this);
return v;
}
......@@ -230,6 +234,7 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements Device
@Override
public void onResume() {
super.onResume();
setSearchVisibility(false);
mViewPager.addOnPageChangeListener(this);
mMediaLibrary.addDeviceDiscoveryCb(this);
mMediaLibrary.setArtistsAddedCb(this);
......@@ -524,6 +529,21 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements Device
((AudioBrowserAdapter)((RecyclerView)mLists.get(mViewPager.getCurrentItem())).getAdapter()).restoreList();
}
@Override
public void setSearchVisibility(boolean visible) {
mSearchButtonView.setVisibility(visible ? View.VISIBLE : View.GONE);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.searchButton:
startActivity(new Intent(Intent.ACTION_SEARCH, null, getContext(), SearchActivity.class)
.putExtra(SearchManager.QUERY, ((MainActivity)getActivity()).getQuery()));
break;
}
}
private void updateEmptyView(int position) {
AudioBrowserAdapter adapter = (AudioBrowserAdapter) ((RecyclerView)mLists.get(position)).getAdapter();
mEmptyView.setVisibility(adapter.isEmpty() ? View.VISIBLE : View.GONE);
......
......@@ -20,6 +20,7 @@
package org.videolan.vlc.gui.video;
import android.app.SearchManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
......@@ -54,7 +55,9 @@ import org.videolan.medialibrary.interfaces.MediaUpdatedCb;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.MediaInfoDialog;
import org.videolan.vlc.gui.SearchActivity;
import org.videolan.vlc.gui.browser.MediaBrowserFragment;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.view.AutoFitRecyclerView;
......@@ -73,7 +76,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class VideoGridFragment extends MediaBrowserFragment implements MediaUpdatedCb, ISortable, SwipeRefreshLayout.OnRefreshListener, DevicesDiscoveryCb, MediaAddedCb, Filterable {
public class VideoGridFragment extends MediaBrowserFragment implements MediaUpdatedCb, ISortable, SwipeRefreshLayout.OnRefreshListener, DevicesDiscoveryCb, MediaAddedCb, Filterable, View.OnClickListener {
public final static String TAG = "VLC/VideoListFragment";
......@@ -84,6 +87,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
protected TextView mTextViewNomedia;
protected View mViewNomedia;
protected String mGroup;
private View mSearchButtonView;
private Handler mHandler = new Handler();
private VideoListAdapter mVideoAdapter;
......@@ -114,6 +118,8 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
mViewNomedia = v.findViewById(android.R.id.empty);
mGridView = (AutoFitRecyclerView) v.findViewById(android.R.id.list);
mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipeLayout);
mSearchButtonView = v.findViewById(R.id.searchButton);
mSearchButtonView.setOnClickListener(this);
mSwipeRefreshLayout.setColorSchemeResources(R.color.orange700);
mSwipeRefreshLayout.setOnRefreshListener(this);
......@@ -143,6 +149,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
@Override
public void onResume() {
super.onResume();
setSearchVisibility(false);
mMediaLibrary.setMediaUpdatedCb(this, Medialibrary.FLAG_MEDIA_UPDATED_VIDEO);
mMediaLibrary.setMediaAddedCb(this, Medialibrary.FLAG_MEDIA_ADDED_VIDEO);
final boolean isWorking = mMediaLibrary.isWorking();
......@@ -539,4 +546,19 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
public void restoreList() {
mVideoAdapter.restoreList();
}
@Override
public void setSearchVisibility(boolean visible) {
mSearchButtonView.setVisibility(visible ? View.VISIBLE : View.GONE);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.searchButton:
startActivity(new Intent(Intent.ACTION_SEARCH, null, getContext(), SearchActivity.class)
.putExtra(SearchManager.QUERY, ((MainActivity)getActivity()).getQuery()));
break;
}
}
}
......@@ -6,4 +6,5 @@ import android.widget.Filter;
public interface Filterable {
Filter getFilter();
void restoreList();
void setSearchVisibility(boolean visible);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment