mirror of
https://github.com/zoriya/Opus.git
synced 2025-12-06 06:26:15 +00:00
adding swipe to refresh
This commit is contained in:
@@ -36,6 +36,7 @@ namespace MusicApp
|
||||
public IMenu menu;
|
||||
public SwipeRefreshLayout contentRefresh;
|
||||
public SwipeRefreshLayout pagerRefresh;
|
||||
public bool usePager;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
private ProgressBar bar;
|
||||
@@ -179,10 +180,18 @@ namespace MusicApp
|
||||
{
|
||||
get
|
||||
{
|
||||
return instance.SupportActionBar.Height;
|
||||
return 0/*instance.SupportActionBar.Height*/;
|
||||
}
|
||||
}
|
||||
|
||||
public void Scroll(object sender, AbsListView.ScrollEventArgs e)
|
||||
{
|
||||
if (usePager)
|
||||
pagerRefresh.SetEnabled(e.FirstVisibleItem == 0);
|
||||
else
|
||||
contentRefresh.SetEnabled(e.FirstVisibleItem == 0);
|
||||
}
|
||||
|
||||
|
||||
protected override void OnCreate(Bundle savedInstanceState)
|
||||
{
|
||||
@@ -450,6 +459,7 @@ namespace MusicApp
|
||||
|
||||
Console.WriteLine("Switching: " + canSwitch);
|
||||
canSwitch = false;
|
||||
usePager = true;
|
||||
|
||||
TabLayout tabs = FindViewById<TabLayout>(Resource.Id.tabs);
|
||||
ViewPager pager = FindViewById<ViewPager>(Resource.Id.pager);
|
||||
@@ -469,12 +479,11 @@ namespace MusicApp
|
||||
oldAdapter.AddFragment(FolderBrowse.NewInstance(), "Folders");
|
||||
|
||||
pager.Adapter = oldAdapter;
|
||||
pager.ClearOnPageChangeListeners();
|
||||
}
|
||||
else
|
||||
{
|
||||
FrameLayout frame = FindViewById<FrameLayout>(Resource.Id.contentView);
|
||||
frame.Visibility = ViewStates.Gone;
|
||||
contentRefresh.Visibility = ViewStates.Gone;
|
||||
pagerRefresh.Visibility = ViewStates.Visible;
|
||||
tabs.Visibility = ViewStates.Visible;
|
||||
tabs.AddTab(tabs.NewTab().SetText("Songs"));
|
||||
tabs.AddTab(tabs.NewTab().SetText("Folders"));
|
||||
@@ -486,10 +495,12 @@ namespace MusicApp
|
||||
adapter.AddFragment(FolderBrowse.NewInstance(), "Folders");
|
||||
|
||||
pager.Adapter = adapter;
|
||||
pager.AddOnPageChangeListener(this);
|
||||
pager.AddOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabs));
|
||||
|
||||
tabs.SetupWithViewPager(pager);
|
||||
}
|
||||
|
||||
pager.AddOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabs));
|
||||
pager.CurrentItem = selectedTab;
|
||||
tabs.SetScrollPosition(selectedTab, 0f, true);
|
||||
|
||||
@@ -509,6 +520,7 @@ namespace MusicApp
|
||||
|
||||
Console.WriteLine("Switching: " + canSwitch);
|
||||
canSwitch = false;
|
||||
usePager = true;
|
||||
|
||||
TabLayout tabs = FindViewById<TabLayout>(Resource.Id.tabs);
|
||||
ViewPager pager = FindViewById<ViewPager>(Resource.Id.pager);
|
||||
@@ -528,12 +540,11 @@ namespace MusicApp
|
||||
oldAdapter.AddFragment(YtPlaylist.NewInstance(), "Youtube playlists");
|
||||
|
||||
pager.Adapter = oldAdapter;
|
||||
pager.ClearOnPageChangeListeners();
|
||||
}
|
||||
else
|
||||
{
|
||||
FrameLayout frame = FindViewById<FrameLayout>(Resource.Id.contentView);
|
||||
frame.Visibility = ViewStates.Gone;
|
||||
contentRefresh.Visibility = ViewStates.Gone;
|
||||
pagerRefresh.Visibility = ViewStates.Visible;
|
||||
tabs.Visibility = ViewStates.Visible;
|
||||
tabs.AddTab(tabs.NewTab().SetText("Playlists"));
|
||||
tabs.AddTab(tabs.NewTab().SetText("Youtube playlists"));
|
||||
@@ -545,11 +556,11 @@ namespace MusicApp
|
||||
adapter.AddFragment(YtPlaylist.NewInstance(), "Youtube playlists");
|
||||
|
||||
pager.Adapter = adapter;
|
||||
pager.AddOnPageChangeListener(this);
|
||||
pager.AddOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabs));
|
||||
tabs.SetupWithViewPager(pager);
|
||||
}
|
||||
|
||||
pager.AddOnPageChangeListener(this);
|
||||
pager.AddOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabs));
|
||||
pager.CurrentItem = selectedTab;
|
||||
tabs.SetScrollPosition(selectedTab, 0f, true);
|
||||
|
||||
@@ -562,7 +573,10 @@ namespace MusicApp
|
||||
canSwitch = true;
|
||||
}
|
||||
|
||||
public void OnPageScrollStateChanged(int state) { }
|
||||
public void OnPageScrollStateChanged(int state)
|
||||
{
|
||||
pagerRefresh.SetEnabled( state == ViewPager.ScrollStateIdle );
|
||||
}
|
||||
|
||||
public void OnPageScrolled(int position, float positionOffset, int positionOffsetPixels) { }
|
||||
|
||||
@@ -576,6 +590,9 @@ namespace MusicApp
|
||||
Playlist.instance.AddEmptyView();
|
||||
if (YtPlaylist.instance.isEmpty)
|
||||
YtPlaylist.instance.RemoveEmptyView();
|
||||
|
||||
Playlist.instance.focused = true;
|
||||
YtPlaylist.instance.focused = false;
|
||||
}
|
||||
if (position == 1)
|
||||
{
|
||||
@@ -583,16 +600,33 @@ namespace MusicApp
|
||||
Playlist.instance.RemoveEmptyView();
|
||||
if (YtPlaylist.instance.isEmpty)
|
||||
YtPlaylist.instance.AddEmptyView();
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Browse switched" + FolderBrowse.instance.populated);
|
||||
|
||||
if (Browse.instance != null && !FolderBrowse.instance.populated)
|
||||
Playlist.instance.focused = false;
|
||||
YtPlaylist.instance.focused = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (Browse.instance != null)
|
||||
{
|
||||
if(!FolderBrowse.instance.populated)
|
||||
FolderBrowse.instance.PopulateList();
|
||||
|
||||
if(position == 0)
|
||||
{
|
||||
Browse.instance.focused = true;
|
||||
FolderBrowse.instance.focused = false;
|
||||
}
|
||||
if(position == 1)
|
||||
{
|
||||
Browse.instance.focused = false;
|
||||
FolderBrowse.instance.focused = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void HideTabs()
|
||||
{
|
||||
usePager = false;
|
||||
TabLayout tabs = FindViewById<TabLayout>(Resource.Id.tabs);
|
||||
tabs.RemoveAllTabs();
|
||||
tabs.Visibility = ViewStates.Gone;
|
||||
@@ -608,8 +642,8 @@ namespace MusicApp
|
||||
pager.Adapter = null;
|
||||
}
|
||||
|
||||
FrameLayout frame = FindViewById<FrameLayout>(Resource.Id.contentView);
|
||||
frame.Visibility = ViewStates.Visible;
|
||||
pagerRefresh.Visibility = ViewStates.Gone;
|
||||
contentRefresh.Visibility = ViewStates.Visible;
|
||||
}
|
||||
|
||||
public void PrepareSmallPlayer()
|
||||
@@ -748,7 +782,10 @@ namespace MusicApp
|
||||
|
||||
public void Transition(int Resource, Android.Support.V4.App.Fragment fragment, bool backStack)
|
||||
{
|
||||
if(backStack)
|
||||
SupportFragmentManager.BeginTransaction().Replace(Resource, fragment).AddToBackStack(null).Commit();
|
||||
else
|
||||
SupportFragmentManager.BeginTransaction().Replace(Resource, fragment).Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,13 @@ using Android.Support.V4.Widget;
|
||||
using Android.Support.V7.App;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Java.Lang;
|
||||
using MusicApp.Resources.values;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
public class Browse : ListFragment, SwipeRefreshLayout.IOnRefreshListener
|
||||
public class Browse : ListFragment
|
||||
{
|
||||
public static Browse instance;
|
||||
public static Context act;
|
||||
@@ -21,6 +22,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public List<Song> result;
|
||||
public Adapter adapter;
|
||||
public View emptyView;
|
||||
public bool focused = true;
|
||||
|
||||
private View view;
|
||||
private string[] actions = new string[] { "Play", "Play Next", "Play Last", "Add To Playlist" };
|
||||
@@ -34,7 +36,8 @@ namespace MusicApp.Resources.Portable_Class
|
||||
inflater = LayoutInflater;
|
||||
emptyView = LayoutInflater.Inflate(Resource.Layout.NoSong, null);
|
||||
ListView.EmptyView = emptyView;
|
||||
MainActivity.instance.pagerRefresh.SetOnRefreshListener(this);
|
||||
MainActivity.instance.pagerRefresh.Refresh += OnRefresh;
|
||||
ListView.Scroll += MainActivity.instance.Scroll;
|
||||
|
||||
if (ListView.Adapter == null)
|
||||
MainActivity.instance.GetStoragePermission();
|
||||
@@ -42,6 +45,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
MainActivity.instance.pagerRefresh.Refresh -= OnRefresh;
|
||||
if (isEmpty)
|
||||
{
|
||||
ViewGroup rootView = Activity.FindViewById<ViewGroup>(Android.Resource.Id.Content);
|
||||
@@ -74,7 +78,6 @@ namespace MusicApp.Resources.Portable_Class
|
||||
CursorLoader cursorLoader = new CursorLoader(Android.App.Application.Context, musicUri, null, null, null, null);
|
||||
ICursor musicCursor = (ICursor)cursorLoader.LoadInBackground();
|
||||
|
||||
|
||||
if (musicCursor != null && musicCursor.MoveToFirst())
|
||||
{
|
||||
int titleID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Title);
|
||||
@@ -117,9 +120,60 @@ namespace MusicApp.Resources.Portable_Class
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRefresh(object sender, System.EventArgs e)
|
||||
{
|
||||
if (!focused)
|
||||
return;
|
||||
Refresh();
|
||||
MainActivity.instance.pagerRefresh.Refreshing = false;
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
musicList.Clear();
|
||||
|
||||
Android.Net.Uri musicUri = MediaStore.Audio.Media.ExternalContentUri;
|
||||
|
||||
CursorLoader cursorLoader = new CursorLoader(Android.App.Application.Context, musicUri, null, null, null, null);
|
||||
ICursor musicCursor = (ICursor)cursorLoader.LoadInBackground();
|
||||
|
||||
if (musicCursor != null && musicCursor.MoveToFirst())
|
||||
{
|
||||
int titleID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Title);
|
||||
int artistID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Artist);
|
||||
int albumID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Album);
|
||||
int thisID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Id);
|
||||
int pathID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Data);
|
||||
do
|
||||
{
|
||||
string Artist = musicCursor.GetString(artistID);
|
||||
string Title = musicCursor.GetString(titleID);
|
||||
string Album = musicCursor.GetString(albumID);
|
||||
long AlbumArt = musicCursor.GetLong(musicCursor.GetColumnIndex(MediaStore.Audio.Albums.InterfaceConsts.AlbumId));
|
||||
long id = musicCursor.GetLong(thisID);
|
||||
string path = musicCursor.GetString(pathID);
|
||||
|
||||
if (Title == null)
|
||||
Title = "Unknown Title";
|
||||
if (Artist == null)
|
||||
Artist = "Unknow Artist";
|
||||
if (Album == null)
|
||||
Album = "Unknow Album";
|
||||
|
||||
musicList.Add(new Song(Title, Artist, Album, AlbumArt, id, path));
|
||||
}
|
||||
while (musicCursor.MoveToNext());
|
||||
musicCursor.Close();
|
||||
}
|
||||
|
||||
adapter = new Adapter(Android.App.Application.Context, Resource.Layout.SongList, musicList);
|
||||
ListAdapter = adapter;
|
||||
|
||||
if (adapter == null || adapter.Count == 0)
|
||||
{
|
||||
isEmpty = true;
|
||||
Activity.AddContentView(emptyView, View.LayoutParameters);
|
||||
}
|
||||
}
|
||||
|
||||
public void Search(string search)
|
||||
@@ -306,13 +360,5 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
AddToPlaylist(item, playList, playlistID);
|
||||
}
|
||||
|
||||
public void OnRefresh()
|
||||
|
||||
|
||||
{
|
||||
System.Console.WriteLine("Refreshing");
|
||||
Refresh(); //Handle refresh things (like iding the progress rotator)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public ArrayAdapter adapter;
|
||||
public View emptyView;
|
||||
public bool populated = false;
|
||||
public bool focused = false;
|
||||
|
||||
private View view;
|
||||
private string[] actions = new string[] { "List songs", "Add To Playlist", "Random Play" };
|
||||
@@ -37,13 +38,16 @@ namespace MusicApp.Resources.Portable_Class
|
||||
inflater = LayoutInflater;
|
||||
emptyView = LayoutInflater.Inflate(Resource.Layout.NoSong, null);
|
||||
ListView.EmptyView = emptyView;
|
||||
ListView.Scroll += MainActivity.instance.Scroll;
|
||||
MainActivity.instance.pagerRefresh.Refresh += OnRefresh;
|
||||
|
||||
if(ListView.Adapter == null)
|
||||
if (ListView.Adapter == null)
|
||||
PopulateList();
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
MainActivity.instance.pagerRefresh.Refresh -= OnRefresh;
|
||||
if (isEmpty)
|
||||
{
|
||||
ViewGroup rootView = Activity.FindViewById<ViewGroup>(Android.Resource.Id.Content);
|
||||
@@ -117,6 +121,58 @@ namespace MusicApp.Resources.Portable_Class
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRefresh(object sender, System.EventArgs e)
|
||||
{
|
||||
if (!focused)
|
||||
return;
|
||||
Refresh();
|
||||
MainActivity.instance.pagerRefresh.Refreshing = false;
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
Uri musicUri = MediaStore.Audio.Media.ExternalContentUri;
|
||||
|
||||
CursorLoader cursorLoader = new CursorLoader(Android.App.Application.Context, musicUri, null, null, null, null);
|
||||
ICursor musicCursor = (ICursor)cursorLoader.LoadInBackground();
|
||||
|
||||
paths.Clear();
|
||||
pathDisplay.Clear();
|
||||
pathUse.Clear();
|
||||
|
||||
|
||||
if (musicCursor != null && musicCursor.MoveToFirst())
|
||||
{
|
||||
int pathID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Data);
|
||||
do
|
||||
{
|
||||
string path = musicCursor.GetString(pathID);
|
||||
path = path.Substring(0, path.LastIndexOf("/"));
|
||||
string displayPath = path.Substring(path.LastIndexOf("/") + 1, path.Length - (path.LastIndexOf("/") + 1));
|
||||
|
||||
if (!paths.Contains(path))
|
||||
{
|
||||
pathDisplay.Add(displayPath);
|
||||
paths.Add(path);
|
||||
pathUse.Add(1);
|
||||
}
|
||||
else
|
||||
pathUse[paths.IndexOf(path)] += 1;
|
||||
}
|
||||
while (musicCursor.MoveToNext());
|
||||
musicCursor.Close();
|
||||
}
|
||||
|
||||
adapter = new TwoLineAdapter(Android.App.Application.Context, Resource.Layout.TwoLineLayout, pathDisplay, pathUse);
|
||||
ListAdapter = adapter;
|
||||
|
||||
if (adapter == null || adapter.Count == 0)
|
||||
{
|
||||
isEmpty = true;
|
||||
Activity.AddContentView(emptyView, View.LayoutParameters);
|
||||
}
|
||||
}
|
||||
|
||||
public void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
|
||||
{
|
||||
ListSongs(pathDisplay[e.Position], paths[e.Position]);
|
||||
|
||||
@@ -30,6 +30,8 @@ namespace MusicApp.Resources.Portable_Class
|
||||
base.OnActivityCreated(savedInstanceState);
|
||||
emptyView = LayoutInflater.Inflate(Resource.Layout.NoPlaylist, null);
|
||||
ListView.EmptyView = emptyView;
|
||||
ListView.Scroll += MainActivity.instance.Scroll;
|
||||
MainActivity.instance.contentRefresh.Refresh += OnRefresh;
|
||||
|
||||
PopulateList();
|
||||
MainActivity.instance.DisplaySearch(1);
|
||||
@@ -37,6 +39,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
MainActivity.instance.contentRefresh.Refresh -= OnRefresh;
|
||||
instance = null;
|
||||
base.OnDestroy();
|
||||
}
|
||||
@@ -90,6 +93,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
if (Album == null)
|
||||
Album = "Unknow Album";
|
||||
|
||||
System.Console.WriteLine(Title);
|
||||
tracks.Add(new Song(Title, Artist, Album, AlbumArt, id, path));
|
||||
}
|
||||
while (musicCursor.MoveToNext());
|
||||
@@ -109,6 +113,60 @@ namespace MusicApp.Resources.Portable_Class
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRefresh(object sender, System.EventArgs e)
|
||||
{
|
||||
tracks.Clear();
|
||||
|
||||
Uri musicUri = MediaStore.Audio.Media.GetContentUriForPath(path);
|
||||
|
||||
CursorLoader cursorLoader = new CursorLoader(Android.App.Application.Context, musicUri, null, null, null, null);
|
||||
ICursor musicCursor = (ICursor)cursorLoader.LoadInBackground();
|
||||
|
||||
|
||||
if (musicCursor != null && musicCursor.MoveToFirst())
|
||||
{
|
||||
int titleID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Title);
|
||||
int artistID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Artist);
|
||||
int albumID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Album);
|
||||
int thisID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Id);
|
||||
int pathID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Data);
|
||||
do
|
||||
{
|
||||
string path = musicCursor.GetString(pathID);
|
||||
|
||||
if (!path.Contains(this.path))
|
||||
continue;
|
||||
|
||||
string Artist = musicCursor.GetString(artistID);
|
||||
string Title = musicCursor.GetString(titleID);
|
||||
string Album = musicCursor.GetString(albumID);
|
||||
long AlbumArt = musicCursor.GetLong(musicCursor.GetColumnIndex(MediaStore.Audio.Albums.InterfaceConsts.AlbumId));
|
||||
long id = musicCursor.GetLong(thisID);
|
||||
|
||||
if (Title == null)
|
||||
Title = "Unknown Title";
|
||||
if (Artist == null)
|
||||
Artist = "Unknow Artist";
|
||||
if (Album == null)
|
||||
Album = "Unknow Album";
|
||||
|
||||
tracks.Add(new Song(Title, Artist, Album, AlbumArt, id, path));
|
||||
}
|
||||
while (musicCursor.MoveToNext());
|
||||
musicCursor.Close();
|
||||
}
|
||||
|
||||
adapter = new Adapter(Android.App.Application.Context, Resource.Layout.SongList, tracks);
|
||||
ListAdapter = adapter;
|
||||
|
||||
if (adapter == null || adapter.Count == 0)
|
||||
{
|
||||
isEmpty = true;
|
||||
Activity.AddContentView(emptyView, View.LayoutParameters);
|
||||
}
|
||||
MainActivity.instance.contentRefresh.Refreshing = false;
|
||||
}
|
||||
|
||||
public void Search(string search)
|
||||
{
|
||||
result = new List<Song>();
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public Adapter adapter;
|
||||
public View emptyView;
|
||||
public bool isEmpty = false;
|
||||
public bool focused = true;
|
||||
|
||||
private List<string> playList = new List<string>();
|
||||
private List<int> playListCount = new List<int>();
|
||||
@@ -33,6 +34,8 @@ namespace MusicApp.Resources.Portable_Class
|
||||
ListView.TextFilterEnabled = true;
|
||||
ListView.ItemClick += ListView_ItemClick;
|
||||
ListView.ItemLongClick += ListView_ItemLongClick;
|
||||
ListView.Scroll += MainActivity.instance.Scroll;
|
||||
MainActivity.instance.pagerRefresh.Refresh += OnRefresh;
|
||||
|
||||
if (ListView.Adapter == null)
|
||||
MainActivity.instance.GetStoragePermission();
|
||||
@@ -54,6 +57,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
MainActivity.instance.pagerRefresh.Refresh -= OnRefresh;
|
||||
if (isEmpty)
|
||||
{
|
||||
ViewGroup rootView = Activity.FindViewById<ViewGroup>(Android.Resource.Id.Content);
|
||||
@@ -79,6 +83,9 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public void PopulateView()
|
||||
{
|
||||
playList.Clear();
|
||||
playlistId.Clear();
|
||||
|
||||
Uri uri = Playlists.ExternalContentUri;
|
||||
CursorLoader loader = new CursorLoader(Android.App.Application.Context, uri, null, null, null, null);
|
||||
ICursor cursor = (ICursor)loader.LoadInBackground();
|
||||
@@ -113,9 +120,17 @@ namespace MusicApp.Resources.Portable_Class
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRefresh(object sender, System.EventArgs e)
|
||||
{
|
||||
if (!focused)
|
||||
return;
|
||||
Refresh();
|
||||
MainActivity.instance.pagerRefresh.Refreshing = false;
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
|
||||
PopulateView();
|
||||
}
|
||||
|
||||
private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
|
||||
|
||||
@@ -34,7 +34,8 @@ namespace MusicApp.Resources.Portable_Class
|
||||
base.OnActivityCreated(savedInstanceState);
|
||||
emptyView = LayoutInflater.Inflate(Resource.Layout.NoPlaylist, null);
|
||||
ListView.EmptyView = emptyView;
|
||||
ListAdapter = adapter;
|
||||
ListView.Scroll += MainActivity.instance.Scroll;
|
||||
MainActivity.instance.contentRefresh.Refresh += OnRefresh;
|
||||
|
||||
PopulateList();
|
||||
MainActivity.instance.DisplaySearch(1);
|
||||
@@ -42,6 +43,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
MainActivity.instance.contentRefresh.Refresh -= OnRefresh;
|
||||
base.OnDestroy();
|
||||
instance = null;
|
||||
}
|
||||
@@ -156,6 +158,82 @@ namespace MusicApp.Resources.Portable_Class
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnRefresh(object sender, System.EventArgs e)
|
||||
{
|
||||
tracks.Clear();
|
||||
if (playlistId != 0)
|
||||
{
|
||||
Uri musicUri = MediaStore.Audio.Playlists.Members.GetContentUri("external", playlistId);
|
||||
|
||||
CursorLoader cursorLoader = new CursorLoader(Android.App.Application.Context, musicUri, null, null, null, null);
|
||||
ICursor musicCursor = (ICursor)cursorLoader.LoadInBackground();
|
||||
|
||||
|
||||
if (musicCursor != null && musicCursor.MoveToFirst())
|
||||
{
|
||||
int titleID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Title);
|
||||
int artistID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Artist);
|
||||
int albumID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Album);
|
||||
int thisID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Id);
|
||||
int pathID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Data);
|
||||
do
|
||||
{
|
||||
string Artist = musicCursor.GetString(artistID);
|
||||
string Title = musicCursor.GetString(titleID);
|
||||
string Album = musicCursor.GetString(albumID);
|
||||
long AlbumArt = musicCursor.GetLong(musicCursor.GetColumnIndex(MediaStore.Audio.Albums.InterfaceConsts.AlbumId));
|
||||
long id = musicCursor.GetLong(thisID);
|
||||
string path = musicCursor.GetString(pathID);
|
||||
|
||||
if (Title == null)
|
||||
Title = "Unknown Title";
|
||||
if (Artist == null)
|
||||
Artist = "Unknow Artist";
|
||||
if (Album == null)
|
||||
Album = "Unknow Album";
|
||||
|
||||
tracks.Add(new Song(Title, Artist, Album, AlbumArt, id, path));
|
||||
}
|
||||
while (musicCursor.MoveToNext());
|
||||
musicCursor.Close();
|
||||
}
|
||||
|
||||
adapter = new Adapter(Android.App.Application.Context, Resource.Layout.SongList, tracks);
|
||||
ListAdapter = adapter;
|
||||
}
|
||||
else if (ytID != null)
|
||||
{
|
||||
string nextPageToken = "";
|
||||
while (nextPageToken != null)
|
||||
{
|
||||
var ytPlaylistRequest = YoutubeEngine.youtubeService.PlaylistItems.List("snippet, contentDetails");
|
||||
ytPlaylistRequest.PlaylistId = ytID;
|
||||
ytPlaylistRequest.MaxResults = 50;
|
||||
ytPlaylistRequest.PageToken = nextPageToken;
|
||||
|
||||
var ytPlaylist = await ytPlaylistRequest.ExecuteAsync();
|
||||
|
||||
foreach (var item in ytPlaylist.Items)
|
||||
{
|
||||
Song song = new Song(item.Snippet.Title, item.Snippet.ChannelTitle, item.Snippet.Thumbnails.Default__.Url, -1, -1, item.ContentDetails.VideoId, true);
|
||||
tracks.Add(song);
|
||||
ytTracksIDs.Add(item.Id);
|
||||
}
|
||||
|
||||
nextPageToken = ytPlaylist.NextPageToken;
|
||||
}
|
||||
}
|
||||
|
||||
adapter = new Adapter(Android.App.Application.Context, Resource.Layout.SongList, tracks);
|
||||
ListAdapter = adapter;
|
||||
|
||||
if (adapter == null || adapter.Count == 0)
|
||||
{
|
||||
isEmpty = true;
|
||||
Activity.AddContentView(emptyView, View.LayoutParameters);
|
||||
}
|
||||
}
|
||||
|
||||
public void Search(string search)
|
||||
{
|
||||
result = new List<Song>();
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
using Android.Preferences;
|
||||
using Android.Support.V7.App;
|
||||
using Android.Views;
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Preferences;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Java.IO;
|
||||
using MusicApp.Resources.values;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MusicApp.Resources.values;
|
||||
using Java.IO;
|
||||
using Android.Widget;
|
||||
using Android.Content;
|
||||
using Android.App;
|
||||
|
||||
using AlertDialog = Android.Support.V7.App.AlertDialog;
|
||||
using Toolbar = Android.Support.V7.Widget.Toolbar;
|
||||
|
||||
@@ -65,7 +63,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
{
|
||||
View view = base.OnCreateView(inflater, container, savedInstanceState);
|
||||
view.SetPadding(0, MainActivity.paddinTop, 0, 0);
|
||||
view.SetPadding(0, MainActivity.instance.SupportActionBar.Height, 0, 0);
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,12 +21,15 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
emptyView = LayoutInflater.Inflate(Resource.Layout.NoQueue, null);
|
||||
ListView.EmptyView = emptyView;
|
||||
ListView.Scroll += MainActivity.instance.Scroll;
|
||||
MainActivity.instance.contentRefresh.Refresh += OnRefresh;
|
||||
|
||||
PopulateView();
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
MainActivity.instance.contentRefresh.Refresh -= OnRefresh;
|
||||
if (isEmpty)
|
||||
{
|
||||
ViewGroup rootView = Activity.FindViewById<ViewGroup>(Android.Resource.Id.Content);
|
||||
@@ -53,13 +56,12 @@ namespace MusicApp.Resources.Portable_Class
|
||||
void PopulateView()
|
||||
{
|
||||
adapter = new Adapter(Android.App.Application.Context, Resource.Layout.SongList, MusicPlayer.queue);
|
||||
|
||||
ListAdapter = adapter;
|
||||
|
||||
ListView.TextFilterEnabled = true;
|
||||
ListView.ItemClick += ListView_ItemClick;
|
||||
ListView.ItemLongClick += ListView_ItemLongClick;
|
||||
|
||||
|
||||
if (adapter == null || adapter.Count == 0)
|
||||
{
|
||||
isEmpty = true;
|
||||
@@ -67,9 +69,22 @@ namespace MusicApp.Resources.Portable_Class
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRefresh(object sender, System.EventArgs e)
|
||||
{
|
||||
Refresh();
|
||||
MainActivity.instance.contentRefresh.Refreshing = false;
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
adapter = new Adapter(Android.App.Application.Context, Resource.Layout.SongList, MusicPlayer.queue);
|
||||
ListAdapter = adapter;
|
||||
|
||||
if (adapter == null || adapter.Count == 0)
|
||||
{
|
||||
isEmpty = true;
|
||||
Activity.AddContentView(emptyView, View.LayoutParameters);
|
||||
}
|
||||
}
|
||||
|
||||
private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
private View emptyView;
|
||||
private bool isEmpty = true;
|
||||
private string[] actions = new string[] { "Play", "Play Next", "Play Last", "Add To Playlist", "Download" };
|
||||
private string searchKeyWorld;
|
||||
|
||||
public override void OnActivityCreated(Bundle savedInstanceState)
|
||||
{
|
||||
@@ -34,6 +35,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
ListView.ItemClick += ListView_ItemClick;
|
||||
ListView.ItemLongClick += ListView_ItemLongClick;
|
||||
ListView.Scroll += MainActivity.instance.Scroll;
|
||||
|
||||
emptyView = LayoutInflater.Inflate(Resource.Layout.DownloadLayout, null);
|
||||
ListView.EmptyView = emptyView;
|
||||
@@ -49,10 +51,13 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
if(youtubeService == null)
|
||||
MainActivity.instance.Login();
|
||||
|
||||
MainActivity.instance.contentRefresh.Refresh += OnRefresh;
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
MainActivity.instance.contentRefresh.Refresh -= OnRefresh;
|
||||
if (isEmpty)
|
||||
{
|
||||
ViewGroup rootView = Activity.FindViewById<ViewGroup>(Android.Resource.Id.Content);
|
||||
@@ -75,11 +80,13 @@ namespace MusicApp.Resources.Portable_Class
|
||||
return instance;
|
||||
}
|
||||
|
||||
public async void Search(string search)
|
||||
public async Task Search(string search)
|
||||
{
|
||||
if (search == null || search == "")
|
||||
return;
|
||||
|
||||
searchKeyWorld = search;
|
||||
|
||||
if (MainActivity.instance.TokenHasExpire())
|
||||
{
|
||||
youtubeService = null;
|
||||
@@ -108,9 +115,15 @@ namespace MusicApp.Resources.Portable_Class
|
||||
ListAdapter = new Adapter(Android.App.Application.Context, Resource.Layout.SongList, result);
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
private async void OnRefresh(object sender, System.EventArgs e)
|
||||
{
|
||||
await Refresh();
|
||||
MainActivity.instance.contentRefresh.Refreshing = false;
|
||||
}
|
||||
|
||||
public async Task Refresh()
|
||||
{
|
||||
await Search(searchKeyWorld);
|
||||
}
|
||||
|
||||
private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public Adapter adapter;
|
||||
public View emptyView;
|
||||
public bool isEmpty = false;
|
||||
public bool focused = false;
|
||||
|
||||
private List<Song> playlists = new List<Song>();
|
||||
private List<Google.Apis.YouTube.v3.Data.Playlist> YtPlaylists = new List<Google.Apis.YouTube.v3.Data.Playlist>();
|
||||
@@ -29,6 +30,8 @@ namespace MusicApp.Resources.Portable_Class
|
||||
base.OnActivityCreated(savedInstanceState);
|
||||
emptyView = LayoutInflater.Inflate(Resource.Layout.NoYtPlaylist, null);
|
||||
ListView.EmptyView = emptyView;
|
||||
ListView.Scroll += MainActivity.instance.Scroll;
|
||||
MainActivity.instance.pagerRefresh.Refresh += OnRefresh;
|
||||
|
||||
if (YoutubeEngine.youtubeService == null)
|
||||
MainActivity.instance.Login();
|
||||
@@ -49,6 +52,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
MainActivity.instance.pagerRefresh.Refresh -= OnRefresh;
|
||||
if (isEmpty)
|
||||
{
|
||||
ViewGroup rootView = Activity.FindViewById<ViewGroup>(Android.Resource.Id.Content);
|
||||
@@ -144,6 +148,85 @@ namespace MusicApp.Resources.Portable_Class
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnRefresh(object sender, System.EventArgs e)
|
||||
{
|
||||
await Refresh();
|
||||
MainActivity.instance.pagerRefresh.Refreshing = false;
|
||||
}
|
||||
|
||||
private async Task Refresh()
|
||||
{
|
||||
if (MainActivity.instance.TokenHasExpire())
|
||||
{
|
||||
YoutubeEngine.youtubeService = null;
|
||||
MainActivity.instance.Login();
|
||||
|
||||
while (YoutubeEngine.youtubeService == null)
|
||||
await Task.Delay(500);
|
||||
}
|
||||
|
||||
HashMap parameters = new HashMap();
|
||||
parameters.Put("part", "snippet,contentDetails");
|
||||
parameters.Put("mine", "true");
|
||||
parameters.Put("maxResults", "25");
|
||||
parameters.Put("onBehalfOfContentOwner", "");
|
||||
parameters.Put("onBehalfOfContentOwnerChannel", "");
|
||||
|
||||
YouTubeService youtube = YoutubeEngine.youtubeService;
|
||||
|
||||
PlaylistsResource.ListRequest ytPlaylists = youtube.Playlists.List(parameters.Get("part").ToString());
|
||||
|
||||
if (parameters.ContainsKey("mine") && parameters.Get("mine").ToString() != "")
|
||||
{
|
||||
bool mine = (parameters.Get("mine").ToString() == "true") ? true : false;
|
||||
ytPlaylists.Mine = mine;
|
||||
}
|
||||
|
||||
if (parameters.ContainsKey("maxResults"))
|
||||
{
|
||||
ytPlaylists.MaxResults = long.Parse(parameters.Get("maxResults").ToString());
|
||||
}
|
||||
|
||||
if (parameters.ContainsKey("onBehalfOfContentOwner") && parameters.Get("onBehalfOfContentOwner").ToString() != "")
|
||||
{
|
||||
ytPlaylists.OnBehalfOfContentOwner = parameters.Get("onBehalfOfContentOwner").ToString();
|
||||
}
|
||||
|
||||
if (parameters.ContainsKey("onBehalfOfContentOwnerChannel") && parameters.Get("onBehalfOfContentOwnerChannel").ToString() != "")
|
||||
{
|
||||
ytPlaylists.OnBehalfOfContentOwnerChannel = parameters.Get("onBehalfOfContentOwnerChannel").ToString();
|
||||
}
|
||||
|
||||
PlaylistListResponse response = await ytPlaylists.ExecuteAsync();
|
||||
|
||||
if (instance == null)
|
||||
return;
|
||||
|
||||
playlists = new List<Song>();
|
||||
playlists.Clear();
|
||||
|
||||
for (int i = 0; i < response.Items.Count; i++)
|
||||
{
|
||||
Google.Apis.YouTube.v3.Data.Playlist playlist = response.Items[i];
|
||||
YtPlaylists.Add(playlist);
|
||||
Song song = new Song(playlist.Snippet.Title, playlist.Snippet.ChannelTitle, playlist.Snippet.Thumbnails.Default__.Url, -1, -1, playlist.Id, true);
|
||||
playlists.Add(song);
|
||||
}
|
||||
|
||||
adapter = new Adapter(Android.App.Application.Context, Resource.Layout.SongList, playlists);
|
||||
ListAdapter = adapter;
|
||||
|
||||
if (adapter == null || adapter.Count == 0)
|
||||
{
|
||||
if (isEmpty)
|
||||
return;
|
||||
isEmpty = true;
|
||||
Activity.AddContentView(emptyView, View.LayoutParameters);
|
||||
}
|
||||
|
||||
System.Console.WriteLine("Refreshing done");
|
||||
}
|
||||
|
||||
private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
|
||||
{
|
||||
AppCompatActivity act = (AppCompatActivity)Activity;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context="com.journaldev.tablayoutviewpager.MainActivity">
|
||||
android:orientation="vertical"
|
||||
android:fitsSystemWindows="true" >
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -38,6 +39,9 @@
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" >
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/pagerRefresh"
|
||||
@@ -52,7 +56,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/contentRefresh"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
@@ -83,4 +86,5 @@
|
||||
</FrameLayout>
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user