mirror of
https://github.com/zoriya/Opus.git
synced 2025-12-06 06:26:15 +00:00
Fixed bug conserning searchview
This commit is contained in:
@@ -81,6 +81,8 @@ namespace MusicApp
|
||||
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
searchView.Close += SearchClose;
|
||||
}
|
||||
else if(item.ItemId == Resource.Id.settings)
|
||||
{
|
||||
@@ -102,23 +104,51 @@ namespace MusicApp
|
||||
FolderTracks.instance.Search(e.NewText);
|
||||
}
|
||||
|
||||
void SearchClose(object sender, SearchView.CloseEventArgs e)
|
||||
{
|
||||
if (Browse.instance != null)
|
||||
Browse.instance.result = null;
|
||||
}
|
||||
|
||||
void HideSearch()
|
||||
{
|
||||
if (menu == null)
|
||||
return;
|
||||
|
||||
var item = menu.FindItem(Resource.Id.search);
|
||||
item.SetVisible(false);
|
||||
var searchItem = MenuItemCompat.GetActionView(item);
|
||||
var searchView = searchItem.JavaCast<Android.Support.V7.Widget.SearchView>();
|
||||
|
||||
searchView.SetQuery("", false);
|
||||
searchView.ClearFocus();
|
||||
searchView.OnActionViewCollapsed();
|
||||
|
||||
item.SetVisible(false);
|
||||
item.CollapseActionView();
|
||||
|
||||
SupportActionBar.SetHomeButtonEnabled(false);
|
||||
SupportActionBar.SetDisplayHomeAsUpEnabled(false);
|
||||
SupportActionBar.Title = "MusicApp";
|
||||
}
|
||||
|
||||
public void DisplaySearch()
|
||||
public void DisplaySearch(int id = 0)
|
||||
{
|
||||
var item = menu.FindItem(Resource.Id.search);
|
||||
item.SetVisible(true);
|
||||
item.CollapseActionView();
|
||||
var searchItem = MenuItemCompat.GetActionView(item);
|
||||
var searchView = searchItem.JavaCast<Android.Support.V7.Widget.SearchView>();
|
||||
|
||||
searchView.SetQuery("", false);
|
||||
searchView.ClearFocus();
|
||||
searchView.OnActionViewCollapsed();
|
||||
|
||||
if (id == 3)
|
||||
return;
|
||||
|
||||
SupportActionBar.SetHomeButtonEnabled(false);
|
||||
SupportActionBar.SetDisplayHomeAsUpEnabled(false);
|
||||
SupportActionBar.Title = "MusicApp";
|
||||
}
|
||||
|
||||
private void PreNavigate(object sender, BottomNavigationView.NavigationItemSelectedEventArgs e)
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
using Android.OS;
|
||||
using System.Collections.Generic;
|
||||
using Android.Widget;
|
||||
using Android.Net;
|
||||
using Android.Database;
|
||||
using Android.Provider;
|
||||
using MusicApp.Resources.values;
|
||||
using Android.Content;
|
||||
using Android;
|
||||
using Android.Support.Design.Widget;
|
||||
using Android.Support.V7.Widget;
|
||||
using Android.Views;
|
||||
using Android.Content.PM;
|
||||
using Android.Support.V4.App;
|
||||
using Android.Support.V4.View;
|
||||
using Android.Support.V7.App;
|
||||
using Android.Support.V4.Widget;
|
||||
using Android.Runtime;
|
||||
using System;
|
||||
using Java.Lang;
|
||||
@@ -27,6 +23,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public static Context act;
|
||||
public static LayoutInflater inflater;
|
||||
public List<Song> musicList = new List<Song>();
|
||||
public List<Song> result;
|
||||
public Adapter adapter;
|
||||
public View emptyView;
|
||||
|
||||
@@ -153,7 +150,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public void Search(string search)
|
||||
{
|
||||
List<Song> result = new List<Song>();
|
||||
result = new List<Song>();
|
||||
foreach(Song item in musicList)
|
||||
{
|
||||
if(item.GetName().ToLower().Contains(search.ToLower()) || item.GetArtist().ToLower().Contains(search.ToLower()))
|
||||
@@ -167,12 +164,18 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
|
||||
{
|
||||
Song item = musicList[e.Position];
|
||||
if (result != null)
|
||||
item = result[e.Position];
|
||||
|
||||
Play(item);
|
||||
}
|
||||
|
||||
public void ListView_ItemLongClick(object sender, AdapterView.ItemLongClickEventArgs e)
|
||||
{
|
||||
Song item = musicList[e.Position];
|
||||
if (result != null)
|
||||
item = result[e.Position];
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(Activity, Resource.Style.AppCompatAlertDialogStyle);
|
||||
builder.SetTitle("Pick an action");
|
||||
builder.SetItems(actions, (senderAlert, args) =>
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
void PopulateView()
|
||||
{
|
||||
Android.Net.Uri uri = MediaStore.Audio.Playlists.ExternalContentUri;
|
||||
Uri uri = MediaStore.Audio.Playlists.ExternalContentUri;
|
||||
CursorLoader loader = new CursorLoader(Android.App.Application.Context, uri, null, null, null, null);
|
||||
ICursor cursor = (ICursor)loader.LoadInBackground();
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public static PlaylistTracks instance;
|
||||
public Adapter adapter;
|
||||
public View emptyView;
|
||||
public List<Song> result;
|
||||
public long playlistId;
|
||||
public bool isEmpty = false;
|
||||
|
||||
@@ -35,7 +36,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
ListAdapter = adapter;
|
||||
|
||||
PopulateList();
|
||||
MainActivity.instance.DisplaySearch();
|
||||
MainActivity.instance.DisplaySearch(3);
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
@@ -123,7 +124,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public void Search(string search)
|
||||
{
|
||||
List<Song> result = new List<Song>();
|
||||
result = new List<Song>();
|
||||
foreach (Song item in tracks)
|
||||
{
|
||||
if (item.GetName().ToLower().Contains(search.ToLower()) || item.GetArtist().ToLower().Contains(search.ToLower()))
|
||||
@@ -136,8 +137,12 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
|
||||
{
|
||||
Song item = tracks[e.Position];
|
||||
if (result != null)
|
||||
item = result[e.Position];
|
||||
|
||||
Browse.act = Activity;
|
||||
Browse.Play(tracks[e.Position]);
|
||||
Browse.Play(item);
|
||||
}
|
||||
|
||||
private void ListView_ItemLongClick(object sender, AdapterView.ItemLongClickEventArgs e)
|
||||
@@ -145,6 +150,9 @@ namespace MusicApp.Resources.Portable_Class
|
||||
Browse.act = Activity;
|
||||
Browse.inflater = LayoutInflater;
|
||||
Song item = tracks[e.Position];
|
||||
if (result != null)
|
||||
item = result[e.Position];
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(Activity, Resource.Style.AppCompatAlertDialogStyle);
|
||||
builder.SetTitle("Pick an action");
|
||||
builder.SetItems(actions, (senderAlert, args) =>
|
||||
|
||||
Reference in New Issue
Block a user