diff --git a/MusicApp/MainActivity.cs b/MusicApp/MainActivity.cs index 03a5baa..9bf7b98 100644 --- a/MusicApp/MainActivity.cs +++ b/MusicApp/MainActivity.cs @@ -8,6 +8,7 @@ using Android.Views; using Android.Support.V4.View; using Android.Runtime; using Android.Widget; +using Android.Content; namespace MusicApp { @@ -50,28 +51,37 @@ namespace MusicApp { if(item.ItemId == Android.Resource.Id.Home) { - var item2 = menu.FindItem(Resource.Id.search); - item2.SetVisible(false); if (PlaylistTracks.instance != null) { + var item2 = menu.FindItem(Resource.Id.search); + item2.SetVisible(false); if (PlaylistTracks.instance.isEmpty) { ViewGroup rootView = FindViewById(Android.Resource.Id.Content); rootView.RemoveView(PlaylistTracks.instance.emptyView); } + SupportActionBar.SetHomeButtonEnabled(false); + SupportActionBar.SetDisplayHomeAsUpEnabled(false); + SupportActionBar.Title = "MusicApp"; + Navigate(Resource.Id.playlistLayout); } - SupportActionBar.SetHomeButtonEnabled(false); - SupportActionBar.SetDisplayHomeAsUpEnabled(false); - SupportActionBar.Title = "MusicApp"; - Navigate(Resource.Id.playlistLayout); } else if(item.ItemId == Resource.Id.settings) { - HideTabs(); - Android.Support.V4.App.Fragment fragment = Preferences.NewInstance(); - SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contentView, fragment).Commit(); - } + //HideTabs(); + //SupportActionBar.SetDisplayHomeAsUpEnabled(true); + //FindViewById(Resource.Id.bottomView).Visibility = ViewStates.Gone; + //SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contentView, fragment).AddToBackStack(null).Commit(); + //FragmentTransaction transaction = FragmentManager.BeginTransaction(); + //transaction.Replace(Resource.Id.contentView, fragment); + //transaction.AddToBackStack(null); + //transaction.Commit(); + + Intent intent = new Intent(Android.App.Application.Context, typeof(Preferences)); + StartActivity(intent); + //startActivity(mainIntent); + } return base.OnOptionsItemSelected(item); } @@ -178,7 +188,7 @@ namespace MusicApp adapter.AddFragment(Browse.NewInstance(), "Songs"); adapter.AddFragment(DownloadFragment.NewInstance(), "Artists"); - adapter.AddFragment(DownloadFragment.NewInstance(), "Folders"); + adapter.AddFragment(FolderBrowse.NewInstance(), "Folders"); pager.Adapter = adapter; tabs.SetupWithViewPager(pager); diff --git a/MusicApp/MusicApp.csproj b/MusicApp/MusicApp.csproj index 88f620f..7bca6f3 100644 --- a/MusicApp/MusicApp.csproj +++ b/MusicApp/MusicApp.csproj @@ -153,6 +153,7 @@ + @@ -160,6 +161,7 @@ + @@ -318,6 +320,9 @@ Designer + + + diff --git a/MusicApp/Resources/Portable Class/Browse.cs b/MusicApp/Resources/Portable Class/Browse.cs index 836fef8..575ad22 100644 --- a/MusicApp/Resources/Portable Class/Browse.cs +++ b/MusicApp/Resources/Portable Class/Browse.cs @@ -65,6 +65,7 @@ namespace MusicApp.Resources.Portable_Class { View view = base.OnCreateView(inflater, container, savedInstanceState); this.view = view; + view.SetPadding(0, 0, 0, 100); return view; } @@ -150,8 +151,6 @@ namespace MusicApp.Resources.Portable_Class ListView.ItemClick += ListView_ItemClick; ListView.ItemLongClick += ListView_ItemLongClick; - //view.SetPadding(0, 55, 0, 0); - if (adapter == null || adapter.Count == 0) { isEmpty = true; diff --git a/MusicApp/Resources/Portable Class/FolderAdapter.cs b/MusicApp/Resources/Portable Class/FolderAdapter.cs index 1e1e3d1..983dd2f 100644 --- a/MusicApp/Resources/Portable Class/FolderAdapter.cs +++ b/MusicApp/Resources/Portable Class/FolderAdapter.cs @@ -60,7 +60,7 @@ namespace MusicApp.Resources.Portable_Class convertView.FindViewById(Resource.Id.folderList).SetPadding(folders[position].Padding, 0, 0, 0); holder.used.SetTag(Resource.Id.folderUsed, folders[position].uri); - holder.used.Click += Preferences.instance.Used_Click; + holder.used.Click += PreferencesFragment.instance.Used_Click; holder.used.Checked = position == selectedPosition; holder.used.SetTag(Resource.Id.folderName, position); diff --git a/MusicApp/Resources/Portable Class/FolderBrowse.cs b/MusicApp/Resources/Portable Class/FolderBrowse.cs index aaf8d21..acf7053 100644 --- a/MusicApp/Resources/Portable Class/FolderBrowse.cs +++ b/MusicApp/Resources/Portable Class/FolderBrowse.cs @@ -19,12 +19,13 @@ namespace MusicApp.Resources.Portable_Class public static FolderBrowse instance; public static Context act; public static LayoutInflater inflater; - public List musicList = new List(); - public Adapter adapter; + public List paths = new List(); + public List pathUse = new List(); + public ArrayAdapter adapter; public View emptyView; private View view; - private string[] actions = new string[] { "Play", "Play Next", "Play Last", "Add To Playlist" }; + private string[] actions = new string[] { "Add To Playlist" }; private bool isEmpty = false; @@ -37,12 +38,10 @@ namespace MusicApp.Resources.Portable_Class ListView.EmptyView = emptyView; GetStoragePermission(); - InitialiseSearchService(); } public override void OnDestroy() { - MainActivity.instance.RemoveSearchService(0); if (isEmpty) { ViewGroup rootView = Activity.FindViewById(Android.Resource.Id.Content); @@ -58,6 +57,7 @@ namespace MusicApp.Resources.Portable_Class { View view = base.OnCreateView(inflater, container, savedInstanceState); this.view = view; + view.SetPadding(0, 0, 0, 100); return view; } @@ -67,12 +67,6 @@ namespace MusicApp.Resources.Portable_Class return instance; } - private void InitialiseSearchService() - { - HasOptionsMenu = true; - MainActivity.instance.CreateSearch(0); - } - void GetStoragePermission() { const string permission = Manifest.Permission.ReadExternalStorage; @@ -102,7 +96,7 @@ namespace MusicApp.Resources.Portable_Class void PopulateList() { - Android.Net.Uri musicUri = MediaStore.Audio.Media.ExternalContentUri; + Uri musicUri = MediaStore.Audio.Media.ExternalContentUri; CursorLoader cursorLoader = new CursorLoader(Android.App.Application.Context, musicUri, null, null, null, null); ICursor musicCursor = (ICursor)cursorLoader.LoadInBackground(); @@ -110,41 +104,31 @@ namespace MusicApp.Resources.Portable_Class 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); + path = path.Substring(0, path.LastIndexOf("/")); - 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)); + if (!paths.Contains(path)) + { + paths.Add(path); + pathUse.Add(1); + } + else + pathUse[paths.IndexOf(path)] += 1; } while (musicCursor.MoveToNext()); musicCursor.Close(); } - adapter = new Adapter(Android.App.Application.Context, Resource.Layout.SongList, musicList); + adapter = new TwoLineAdapter(Android.App.Application.Context, Resource.Layout.TwoLineLayout, paths, pathUse); ListAdapter = adapter; ListView.TextFilterEnabled = true; ListView.ItemClick += ListView_ItemClick; ListView.ItemLongClick += ListView_ItemLongClick; - //view.SetPadding(0, 55, 0, 0); - if (adapter == null || adapter.Count == 0) { isEmpty = true; @@ -152,21 +136,26 @@ namespace MusicApp.Resources.Portable_Class } } - public void Search(string search) - { - List result = new List(); - foreach (Song item in musicList) - { - if (item.GetName().ToLower().Contains(search.ToLower()) || item.GetArtist().ToLower().Contains(search.ToLower())) - { - result.Add(item); - } - } - ListAdapter = new Adapter(Android.App.Application.Context, Resource.Layout.SongList, result); - } - public void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e) { - Song item = musicList[e.Position]; - Play(item); - } \ No newline at end of file + ListSongs(paths[e.Position]); + } + + private void ListView_ItemLongClick(object sender, AdapterView.ItemLongClickEventArgs e) + { + + } + + void ListSongs(string paths) + { + //AppCompatActivity act = (AppCompatActivity)Activity; + //act.SupportActionBar.SetHomeButtonEnabled(true); + //act.SupportActionBar.SetDisplayHomeAsUpEnabled(true); + //act.SupportActionBar.Title = playList[e.Position]; + //FragmentTransaction transaction = FragmentManager.BeginTransaction(); + //transaction.Replace(Resource.Id.contentView, PlaylistTracks.NewInstance(playlistId[e.Position])); + //transaction.AddToBackStack(null); + //transaction.Commit(); + } + } +} \ No newline at end of file diff --git a/MusicApp/Resources/Portable Class/Playlist.cs b/MusicApp/Resources/Portable Class/Playlist.cs index 6e4b9df..c9da43f 100644 --- a/MusicApp/Resources/Portable Class/Playlist.cs +++ b/MusicApp/Resources/Portable Class/Playlist.cs @@ -21,6 +21,7 @@ namespace MusicApp.Resources.Portable_Class public View emptyView; private List playList = new List(); + private List playListCount = new List(); private List playlistId = new List(); private string[] actions = new string[] { "Random play", "Rename", "Delete" }; private bool isEmpty = false; @@ -49,7 +50,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, 150, 0, 0); + view.SetPadding(0, 100, 0, 0); return view; } @@ -100,17 +101,22 @@ namespace MusicApp.Resources.Portable_Class if (cursor != null && cursor.MoveToFirst()) { int nameID = cursor.GetColumnIndex(MediaStore.Audio.Playlists.InterfaceConsts.Name); + //int countID = cursor.GetColumnIndex(MediaStore.Audio.Playlists.InterfaceConsts.Count); int listID = cursor.GetColumnIndex(MediaStore.Audio.Playlists.InterfaceConsts.Id); do { string name = cursor.GetString(nameID); + //int count = cursor.GetInt(countID); long id = cursor.GetLong(listID); playList.Add(name); + //playListCount.Add(count); playlistId.Add(id); + } while (cursor.MoveToNext()); cursor.Close(); } + //ListAdapter = new TwoLineAdapter(Android.App.Application.Context, Resource.Layout.TwoLineLayout, playList, playListCount); ListAdapter = new ArrayAdapter(Android.App.Application.Context, Resource.Layout.PlaylistList, playList); ListView.TextFilterEnabled = true; ListView.ItemClick += ListView_ItemClick; diff --git a/MusicApp/Resources/Portable Class/Preferences.cs b/MusicApp/Resources/Portable Class/Preferences.cs index 37204ba..7875aca 100644 --- a/MusicApp/Resources/Portable Class/Preferences.cs +++ b/MusicApp/Resources/Portable Class/Preferences.cs @@ -1,5 +1,4 @@ -using Android.Support.V4.App; -using Android.Support.V7.Preferences; +using Android.Preferences; using Android.Support.V7.App; using Android.Views; using Android.OS; @@ -9,20 +8,35 @@ using MusicApp.Resources.values; using Java.IO; using Android.Widget; using Android.Content; +using Android.App; + +using AlertDialog = Android.Support.V7.App.AlertDialog; namespace MusicApp.Resources.Portable_Class { - public class Preferences : PreferenceFragmentCompat + [Activity(Label = "Settings", Theme = "@style/Theme")] + public class Preferences : PreferenceActivity { - public static Preferences instance; + protected override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + FragmentManager.BeginTransaction().Replace(Android.Resource.Id.Content, new PreferencesFragment()).Commit(); + } + } + + public class PreferencesFragment : PreferenceFragment + { + public static PreferencesFragment instance; private List folders; private FolderAdapter adapter; private ListView folderList; private string path; private AlertDialog dialog; - public override void OnCreatePreferences(Bundle savedInstanceState, string rootKey) + public override void OnCreate(Bundle savedInstanceState) { + base.OnCreate(savedInstanceState); + instance = this; AddPreferencesFromResource(Resource.Layout.Preferences); Preference pref = PreferenceScreen.FindPreference("downloadPath"); pref.PreferenceClick += Pref_PreferenceClick; @@ -37,19 +51,6 @@ namespace MusicApp.Resources.Portable_Class instance = null; } - public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) - { - View view = base.OnCreateView(inflater, container, savedInstanceState); - //view.SetPadding(0, 150, 0, 0); - return view; - } - - public static Fragment NewInstance() - { - instance = new Preferences { Arguments = new Bundle() }; - return instance; - } - private void Pref_PreferenceClick(object sender, Preference.PreferenceClickEventArgs e) { folders = ListFolders(); @@ -146,7 +147,7 @@ namespace MusicApp.Resources.Portable_Class editor.PutString("downloadPath", path); editor.Apply(); - Preference prefButton = PreferenceScreen.FindPreference("downloadPath"); + Preference prefButton = FindPreference("downloadPath"); prefButton.Summary = path; } diff --git a/MusicApp/Resources/Portable Class/TwoLineAdapter.cs b/MusicApp/Resources/Portable Class/TwoLineAdapter.cs new file mode 100644 index 0000000..6d95f95 --- /dev/null +++ b/MusicApp/Resources/Portable Class/TwoLineAdapter.cs @@ -0,0 +1,52 @@ +using System.Collections.Generic; + +using Android.Content; +using Android.Views; +using Android.Widget; +using MusicApp.Resources.values; +using Android.Graphics; +using Android.Util; +using System.IO; +using Android.OS; +using Android.App; +using Square.Picasso; + +namespace MusicApp.Resources.Portable_Class +{ + public class TwoLineAdapter : ArrayAdapter + { + private Context context; + private List line1; + private List line2; + private LayoutInflater inflater; + private int resource; + + public TwoLineAdapter(Context context, int resource, List line1, List line2) : base(context, resource, line1) + { + this.context = context; + this.resource = resource; + this.line1 = line1; + this.line2 = line2; + } + + public override View GetView(int position, View convertView, ViewGroup parent) + { + if (inflater == null) + { + inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService); + } + if (convertView == null) + { + convertView = inflater.Inflate(resource, parent, false); + } + TwoLineHolder holder = new TwoLineHolder(convertView) + { + Line1 = { Text = line1[position] }, + Line2 = { Text = line2[position].ToString() + ((line2[position] > 1) ? " elements" : " element") }, + }; + + convertView.SetBackgroundColor(Color.White); + return convertView; + } + } +} \ No newline at end of file diff --git a/MusicApp/Resources/Resource.Designer.cs b/MusicApp/Resources/Resource.Designer.cs index 4117964..a829d3c 100644 --- a/MusicApp/Resources/Resource.Designer.cs +++ b/MusicApp/Resources/Resource.Designer.cs @@ -2477,8 +2477,8 @@ namespace MusicApp // aapt resource value: 0x7f07008c public const int bottomView = 2131165324; - // aapt resource value: 0x7f0700bc - public const int browseLayout = 2131165372; + // aapt resource value: 0x7f0700bd + public const int browseLayout = 2131165373; // aapt resource value: 0x7f070073 public const int browseList = 2131165299; @@ -2567,8 +2567,8 @@ namespace MusicApp // aapt resource value: 0x7f070012 public const int disableHome = 2131165202; - // aapt resource value: 0x7f0700bd - public const int downloadLayout = 2131165373; + // aapt resource value: 0x7f0700be + public const int downloadLayout = 2131165374; // aapt resource value: 0x7f070066 public const int edit_query = 2131165286; @@ -2657,6 +2657,9 @@ namespace MusicApp // aapt resource value: 0x7f0700a0 public const int line1 = 2131165344; + // aapt resource value: 0x7f0700b9 + public const int line2 = 2131165369; + // aapt resource value: 0x7f0700a2 public const int line3 = 2131165346; @@ -2669,8 +2672,8 @@ namespace MusicApp // aapt resource value: 0x7f070048 public const int list_item = 2131165256; - // aapt resource value: 0x7f0700ba - public const int masked = 2131165370; + // aapt resource value: 0x7f0700bb + public const int masked = 2131165371; // aapt resource value: 0x7f070094 public const int media_actions = 2131165332; @@ -2684,8 +2687,8 @@ namespace MusicApp // aapt resource value: 0x7f070019 public const int multiply = 2131165209; - // aapt resource value: 0x7f0700bb - public const int musicLayout = 2131165371; + // aapt resource value: 0x7f0700bc + public const int musicLayout = 2131165372; // aapt resource value: 0x7f07007d public const int navigation_header_container = 2131165309; @@ -2741,8 +2744,8 @@ namespace MusicApp // aapt resource value: 0x7f0700a8 public const int playerTitle = 2131165352; - // aapt resource value: 0x7f0700be - public const int playlistLayout = 2131165374; + // aapt resource value: 0x7f0700bf + public const int playlistLayout = 2131165375; // aapt resource value: 0x7f070074 public const int playlistName = 2131165300; @@ -2825,8 +2828,8 @@ namespace MusicApp // aapt resource value: 0x7f070072 public const int select_dialog_listview = 2131165298; - // aapt resource value: 0x7f0700bf - public const int settings = 2131165375; + // aapt resource value: 0x7f0700c0 + public const int settings = 2131165376; // aapt resource value: 0x7f07005c public const int shortcut = 2131165276; @@ -2954,8 +2957,8 @@ namespace MusicApp // aapt resource value: 0x7f07000e public const int view_offset_helper = 2131165198; - // aapt resource value: 0x7f0700b9 - public const int visible = 2131165369; + // aapt resource value: 0x7f0700ba + public const int visible = 2131165370; // aapt resource value: 0x7f070027 public const int withText = 2131165223; @@ -3280,6 +3283,9 @@ namespace MusicApp // aapt resource value: 0x7f030057 public const int TimerLayout = 2130903127; + // aapt resource value: 0x7f030058 + public const int TwoLineLayout = 2130903128; + static Layout() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); diff --git a/MusicApp/Resources/layout/Main.axml b/MusicApp/Resources/layout/Main.axml index 48c935d..6798c9f 100644 --- a/MusicApp/Resources/layout/Main.axml +++ b/MusicApp/Resources/layout/Main.axml @@ -14,7 +14,6 @@ android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" - app:layout_scrollFlags="scroll|enterAlways" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> - + android:layout_height="wrap_content" /> + - - + + - - \ No newline at end of file + + \ No newline at end of file diff --git a/MusicApp/Resources/layout/TwoLineLayout.xml b/MusicApp/Resources/layout/TwoLineLayout.xml new file mode 100644 index 0000000..06d248f --- /dev/null +++ b/MusicApp/Resources/layout/TwoLineLayout.xml @@ -0,0 +1,21 @@ + + + + + \ No newline at end of file diff --git a/MusicApp/Resources/values/TwoLineHolder.cs b/MusicApp/Resources/values/TwoLineHolder.cs new file mode 100644 index 0000000..aaa5b12 --- /dev/null +++ b/MusicApp/Resources/values/TwoLineHolder.cs @@ -0,0 +1,18 @@ +using Android.Views; +using Android.Widget; + +namespace MusicApp.Resources.values +{ + [System.Serializable] + public class TwoLineHolder + { + public TextView Line1; + public TextView Line2; + + public TwoLineHolder(View v) + { + Line1 = v.FindViewById(Resource.Id.line1); + Line2 = v.FindViewById(Resource.Id.line2); + } + } +} \ No newline at end of file