mirror of
https://github.com/zoriya/Opus.git
synced 2025-12-06 06:26:15 +00:00
local quick play button done
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Content.PM;
|
||||
using Android.Database;
|
||||
using Android.Graphics.Drawables;
|
||||
using Android.OS;
|
||||
using Android.Provider;
|
||||
using Android.Runtime;
|
||||
using Android.Support.Design.Widget;
|
||||
using Android.Support.V4.View;
|
||||
@@ -23,6 +25,7 @@ using MusicApp.Resources.Portable_Class;
|
||||
using MusicApp.Resources.values;
|
||||
using Square.Picasso;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Auth;
|
||||
@@ -781,6 +784,8 @@ namespace MusicApp
|
||||
{
|
||||
Browse.instance?.PopulateList();
|
||||
Playlist.instance?.PopulateView();
|
||||
if (Browse.instance == null && Playlist.instance == null && PreferencesFragment.instance == null)
|
||||
LocalPlay(this, new EventArgs());
|
||||
}
|
||||
|
||||
public void Transition(int Resource, Android.Support.V4.App.Fragment fragment, bool backStack)
|
||||
@@ -850,7 +855,7 @@ namespace MusicApp
|
||||
quickPlayLayout.SetPadding(0, 0, 0, paddingBot + PxToDp(6));
|
||||
quickPlayLayout.FindViewById<FloatingActionButton>(Resource.Id.quickPlay).Click += QuickPlay;
|
||||
quickPlayLayout.FindViewById<FloatingActionButton>(Resource.Id.localPlay).Click += LocalPlay;
|
||||
quickPlayLayout.FindViewById<FloatingActionButton>(Resource.Id.ytPlay).Click += ytPlay;
|
||||
quickPlayLayout.FindViewById<FloatingActionButton>(Resource.Id.ytPlay).Click += YtPlay;
|
||||
OnPaddingChanged += QuickPlayChangePosition;
|
||||
}
|
||||
|
||||
@@ -900,12 +905,66 @@ namespace MusicApp
|
||||
|
||||
private void LocalPlay(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
QuickPlay(this, e);
|
||||
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(this);
|
||||
string shortcut = prefManager.GetString("localPlay", "Shuffle All Audio Files");
|
||||
if (shortcut == "Shuffle All Audio Files")
|
||||
{
|
||||
if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) != (int)Permission.Granted)
|
||||
{
|
||||
GetStoragePermission();
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> paths = new List<string>();
|
||||
Android.Net.Uri musicUri = MediaStore.Audio.Media.ExternalContentUri;
|
||||
|
||||
CursorLoader cursorLoader = new CursorLoader(this, musicUri, null, null, null, null);
|
||||
ICursor musicCursor = (ICursor)cursorLoader.LoadInBackground();
|
||||
|
||||
if (musicCursor != null && musicCursor.MoveToFirst())
|
||||
{
|
||||
int pathID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Data);
|
||||
do
|
||||
{
|
||||
paths.Add(musicCursor.GetString(pathID));
|
||||
}
|
||||
while (musicCursor.MoveToNext());
|
||||
musicCursor.Close();
|
||||
}
|
||||
|
||||
if(paths.Count == 0)
|
||||
{
|
||||
//MAKE HERE ERROR MESSAGE FOR NO FILES ON THE DEVICE
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, typeof(MusicPlayer));
|
||||
intent.PutStringArrayListExtra("files", paths);
|
||||
intent.SetAction("RandomPlay");
|
||||
StartService(intent);
|
||||
HideTabs();
|
||||
HideSearch();
|
||||
SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contentView, Player.NewInstance()).Commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
long playlistID = prefManager.GetLong("localPlaylistID", -1);
|
||||
if (playlistID != -1)
|
||||
{
|
||||
Playlist.RandomPlay(playlistID, this);
|
||||
HideTabs();
|
||||
HideSearch();
|
||||
SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contentView, Player.NewInstance()).Commit();
|
||||
}
|
||||
//else
|
||||
//MAKE ERROR MESSAGE WHEN PLAYLIST ID IS NULL
|
||||
}
|
||||
}
|
||||
|
||||
private void ytPlay(object sender, EventArgs e)
|
||||
private void YtPlay(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
QuickPlay(this, e);
|
||||
}
|
||||
|
||||
int PxToDp(int px)
|
||||
|
||||
@@ -153,7 +153,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
switch (args.Which)
|
||||
{
|
||||
case 0:
|
||||
RandomPlay(playlistId[e.Position]);
|
||||
RandomPlay(playlistId[e.Position], Activity);
|
||||
break;
|
||||
case 1:
|
||||
Rename(e.Position, playlistId[e.Position]);
|
||||
@@ -168,23 +168,20 @@ namespace MusicApp.Resources.Portable_Class
|
||||
builder.Show();
|
||||
}
|
||||
|
||||
void RandomPlay(long playlistID)
|
||||
public static void RandomPlay(long playlistID, Context context)
|
||||
{
|
||||
List<string> tracksPath = new List<string>();
|
||||
Uri musicUri = MediaStore.Audio.Playlists.Members.GetContentUri("external", playlistID);
|
||||
Uri musicUri = 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 pathID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Data);
|
||||
int pathID = musicCursor.GetColumnIndex(Media.InterfaceConsts.Data);
|
||||
do
|
||||
{
|
||||
string path = musicCursor.GetString(pathID);
|
||||
|
||||
tracksPath.Add(path);
|
||||
tracksPath.Add(musicCursor.GetString(pathID));
|
||||
}
|
||||
while (musicCursor.MoveToNext());
|
||||
musicCursor.Close();
|
||||
@@ -193,7 +190,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
Intent intent = new Intent(Android.App.Application.Context, typeof(MusicPlayer));
|
||||
intent.PutStringArrayListExtra("files", tracksPath);
|
||||
intent.SetAction("RandomPlay");
|
||||
Activity.StartService(intent);
|
||||
context.StartService(intent);
|
||||
}
|
||||
|
||||
void Rename(int position, long playlistID)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Database;
|
||||
using Android.OS;
|
||||
using Android.Preferences;
|
||||
using Android.Views;
|
||||
@@ -8,6 +9,7 @@ using Java.IO;
|
||||
using MusicApp.Resources.values;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static Android.Provider.MediaStore.Audio;
|
||||
using AlertDialog = Android.Support.V7.App.AlertDialog;
|
||||
using Toolbar = Android.Support.V7.Widget.Toolbar;
|
||||
|
||||
@@ -20,6 +22,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
base.OnCreate(savedInstanceState);
|
||||
FragmentManager.BeginTransaction().Replace(Android.Resource.Id.Content, new PreferencesFragment()).Commit();
|
||||
MainActivity.instance.GetStoragePermission();
|
||||
}
|
||||
|
||||
protected override void OnPostCreate(Bundle savedInstanceState)
|
||||
@@ -36,22 +39,34 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public class PreferencesFragment : PreferenceFragment
|
||||
{
|
||||
public static PreferencesFragment instance;
|
||||
|
||||
//DownloadPath
|
||||
private List<Folder> folders;
|
||||
private FolderAdapter adapter;
|
||||
private ListView folderList;
|
||||
private string path;
|
||||
private AlertDialog dialog;
|
||||
|
||||
//Local Shortcut
|
||||
private int LSposition;
|
||||
|
||||
public override void OnCreate(Bundle savedInstanceState)
|
||||
{
|
||||
base.OnCreate(savedInstanceState);
|
||||
instance = this;
|
||||
AddPreferencesFromResource(Resource.Layout.Preferences);
|
||||
Preference pref = PreferenceScreen.FindPreference("downloadPath");
|
||||
pref.PreferenceClick += Pref_PreferenceClick;
|
||||
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
|
||||
|
||||
//Download Path
|
||||
Preference downloadPref = PreferenceScreen.FindPreference("downloadPath");
|
||||
downloadPref.PreferenceClick += DownloadClick;
|
||||
downloadPref.Summary = prefManager.GetString("downloadPath", "not set");
|
||||
|
||||
//Local play shortcut
|
||||
Preference localShortcutPreference = PreferenceScreen.FindPreference("localPlay");
|
||||
localShortcutPreference.PreferenceClick += LocalShortcut;
|
||||
localShortcutPreference.Summary = prefManager.GetString("localPlay", "Shuffle All Audio Files");
|
||||
|
||||
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(Android.App.Application.Context);
|
||||
pref.Summary = prefManager.GetString("downloadPath", "not set");
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
@@ -67,10 +82,11 @@ namespace MusicApp.Resources.Portable_Class
|
||||
return view;
|
||||
}
|
||||
|
||||
private void Pref_PreferenceClick(object sender, Preference.PreferenceClickEventArgs e)
|
||||
#region Download location
|
||||
private void DownloadClick(object sender, Preference.PreferenceClickEventArgs e)
|
||||
{
|
||||
folders = ListFolders();
|
||||
adapter = new FolderAdapter(Android.App.Application.Context, Resource.Layout.folderList, folders);
|
||||
adapter = new FolderAdapter(Application.Context, Resource.Layout.folderList, folders);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(Activity, Resource.Style.AppCompatAlertDialogStyle);
|
||||
builder.SetTitle("Choose download location:");
|
||||
@@ -175,7 +191,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
if(file == null)
|
||||
{
|
||||
System.Console.WriteLine("file is null");
|
||||
System.Console.WriteLine("&file is null");
|
||||
return new List<Folder>();
|
||||
}
|
||||
|
||||
@@ -237,5 +253,74 @@ namespace MusicApp.Resources.Portable_Class
|
||||
}
|
||||
return folders;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region LocalShortcut
|
||||
private void LocalShortcut(object sender, Preference.PreferenceClickEventArgs e)
|
||||
{
|
||||
string[] items = new string[] { "Shuffle All Audio Files", "Shuffle a playlist" };
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(Activity, Resource.Style.AppCompatAlertDialogStyle);
|
||||
builder.SetTitle("Set the local storage shortcut:");
|
||||
builder.SetItems(items, (s, args) => { if (args.Which == 0) LCShuffleAll(); else LCSufflePlaylist(); });
|
||||
builder.Show();
|
||||
}
|
||||
|
||||
void LCShuffleAll()
|
||||
{
|
||||
ISharedPreferences pref = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
|
||||
ISharedPreferencesEditor editor = pref.Edit();
|
||||
editor.PutString("localPlay", "Shuffle All Audio Files");
|
||||
editor.Apply();
|
||||
|
||||
Preference prefButton = FindPreference("localPlay");
|
||||
prefButton.Summary = path;
|
||||
}
|
||||
|
||||
void LCSufflePlaylist()
|
||||
{
|
||||
List<string> playList = new List<string>();
|
||||
List<long> playlistId = new List<long>();
|
||||
|
||||
Android.Net.Uri uri = Playlists.ExternalContentUri;
|
||||
CursorLoader loader = new CursorLoader(Application.Context, uri, null, null, null, null);
|
||||
ICursor cursor = (ICursor)loader.LoadInBackground();
|
||||
|
||||
if (cursor != null && cursor.MoveToFirst())
|
||||
{
|
||||
int nameID = cursor.GetColumnIndex(Playlists.InterfaceConsts.Name);
|
||||
int listID = cursor.GetColumnIndex(Playlists.InterfaceConsts.Id);
|
||||
do
|
||||
{
|
||||
string name = cursor.GetString(nameID);
|
||||
long id = cursor.GetLong(listID);
|
||||
playList.Add(name);
|
||||
playlistId.Add(id);
|
||||
|
||||
}
|
||||
while (cursor.MoveToNext());
|
||||
cursor.Close();
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(Activity, Resource.Style.AppCompatAlertDialogStyle);
|
||||
builder.SetTitle("Set the local storage shortcut:");
|
||||
builder.SetSingleChoiceItems(playList.ToArray(), -1, (s, args) => { LSposition = args.Which; });
|
||||
builder.SetPositiveButton("Ok", (s, args) => { LCSufflePlaylist(playList[LSposition], playlistId[LSposition]); });
|
||||
builder.SetNegativeButton("Cancel", (s, args) => { return; });
|
||||
builder.Show();
|
||||
}
|
||||
|
||||
void LCSufflePlaylist(string playlist, long playlistID)
|
||||
{
|
||||
ISharedPreferences pref = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
|
||||
ISharedPreferencesEditor editor = pref.Edit();
|
||||
editor.PutString("localPlay", "Shuffle " + playlist);
|
||||
editor.PutLong("localPlaylistID", playlistID);
|
||||
editor.Apply();
|
||||
|
||||
Preference prefButton = FindPreference("localPlay");
|
||||
prefButton.Summary = path;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,21 @@ namespace MusicApp.Resources.Portable_Class
|
||||
ListView.EmptyView = emptyView;
|
||||
ListView.Scroll += MainActivity.instance.Scroll;
|
||||
MainActivity.instance.contentRefresh.Refresh += OnRefresh;
|
||||
MainActivity.instance.OnPaddingChanged += PaddingChanged;
|
||||
|
||||
PopulateView();
|
||||
}
|
||||
|
||||
private void PaddingChanged(object sender, PaddingChange e)
|
||||
{
|
||||
view.SetPadding(0, 0, 0, MainActivity.paddingBot);
|
||||
//view.Invalidate();
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
MainActivity.instance.contentRefresh.Refresh -= OnRefresh;
|
||||
MainActivity.instance.OnPaddingChanged -= PaddingChanged;
|
||||
if (isEmpty)
|
||||
{
|
||||
ViewGroup rootView = Activity.FindViewById<ViewGroup>(Android.Resource.Id.Content);
|
||||
|
||||
@@ -5,5 +5,11 @@
|
||||
android:key="downloadPath"
|
||||
android:title="Download directory"
|
||||
android:summary="test"/>
|
||||
</PreferenceCategory>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="QuickPlay Shortcut">
|
||||
<Preference
|
||||
android:key="localPlay"
|
||||
android:title="Local Play Action"
|
||||
android:summary="Shuffle All Audio Files" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
Reference in New Issue
Block a user