Repaire folder tracks

This commit is contained in:
Gboy9155
2017-10-21 20:56:52 +02:00
parent 0ecf4085ff
commit 4bd960ba65
5 changed files with 87 additions and 107 deletions

View File

@@ -66,6 +66,21 @@ namespace MusicApp
SupportActionBar.Title = "MusicApp"; SupportActionBar.Title = "MusicApp";
Navigate(Resource.Id.playlistLayout); Navigate(Resource.Id.playlistLayout);
} }
if (FolderTracks.instance != null)
{
var item2 = menu.FindItem(Resource.Id.search);
item2.SetVisible(false);
if (FolderTracks.instance.isEmpty)
{
ViewGroup rootView = FindViewById<ViewGroup>(Android.Resource.Id.Content);
rootView.RemoveView(PlaylistTracks.instance.emptyView);
}
SupportActionBar.SetHomeButtonEnabled(false);
SupportActionBar.SetDisplayHomeAsUpEnabled(false);
SupportActionBar.Title = "MusicApp";
FolderTracks.instance = null;
SetTabs(1);
}
} }
else if(item.ItemId == Resource.Id.search) else if(item.ItemId == Resource.Id.search)
{ {
@@ -147,7 +162,7 @@ namespace MusicApp
searchView.ClearFocus(); searchView.ClearFocus();
searchView.OnActionViewCollapsed(); searchView.OnActionViewCollapsed();
if (id == 3) if (id != 0)
return; return;
SupportActionBar.SetHomeButtonEnabled(false); SupportActionBar.SetHomeButtonEnabled(false);
@@ -195,7 +210,7 @@ namespace MusicApp
SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contentView, fragment).Commit(); SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contentView, fragment).Commit();
} }
void SetTabs() void SetTabs(int selectedTab = 0)
{ {
FrameLayout frame = FindViewById<FrameLayout>(Resource.Id.contentView); FrameLayout frame = FindViewById<FrameLayout>(Resource.Id.contentView);
frame.Visibility = ViewStates.Gone; frame.Visibility = ViewStates.Gone;
@@ -217,14 +232,21 @@ namespace MusicApp
pager.Adapter = adapter; pager.Adapter = adapter;
tabs.SetupWithViewPager(pager); tabs.SetupWithViewPager(pager);
pager.CurrentItem = selectedTab;
tabs.SetScrollPosition(selectedTab, 0f, true);
} }
//AFTER USING FOLDERTRACKS, BROWSE AND FOLDERBROWSE OONCLICK DOES NOT WORK;
public void HideTabs() public void HideTabs()
{ {
TabLayout tabs = FindViewById<TabLayout>(Resource.Id.tabs); TabLayout tabs = FindViewById<TabLayout>(Resource.Id.tabs);
tabs.RemoveAllTabs(); tabs.RemoveAllTabs();
tabs.Visibility = ViewStates.Gone; tabs.Visibility = ViewStates.Gone;
ViewPager pager = FindViewById<ViewPager>(Resource.Id.pager); ViewPager pager = FindViewById<ViewPager>(Resource.Id.pager);
if (pager.Adapter != null)
pager.Adapter.Dispose();
pager.Adapter = null; pager.Adapter = null;
FrameLayout frame = FindViewById<FrameLayout>(Resource.Id.contentView); FrameLayout frame = FindViewById<FrameLayout>(Resource.Id.contentView);

View File

@@ -77,6 +77,8 @@ namespace MusicApp.Resources.Portable_Class
if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(Android.App.Application.Context, permission) == (int)Permission.Granted) if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(Android.App.Application.Context, permission) == (int)Permission.Granted)
{ {
PopulateList(); PopulateList();
//if(FolderBrowse.instance != null)
// FolderBrowse.instance.PopulateList();
return; return;
} }
string[] permissions = new string[] { permission }; string[] permissions = new string[] { permission };

View File

@@ -20,6 +20,7 @@ namespace MusicApp.Resources.Portable_Class
public static FolderBrowse instance; public static FolderBrowse instance;
public static Context act; public static Context act;
public static LayoutInflater inflater; public static LayoutInflater inflater;
public List<string> pathDisplay = new List<string>();
public List<string> paths = new List<string>(); public List<string> paths = new List<string>();
public List<int> pathUse = new List<int>(); public List<int> pathUse = new List<int>();
public ArrayAdapter adapter; public ArrayAdapter adapter;
@@ -69,8 +70,11 @@ namespace MusicApp.Resources.Portable_Class
return instance; return instance;
} }
void PopulateList() public void PopulateList()
{ {
if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(Android.App.Application.Context, Manifest.Permission.ReadExternalStorage) != (int)Permission.Granted)
return;
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); CursorLoader cursorLoader = new CursorLoader(Android.App.Application.Context, musicUri, null, null, null, null);
@@ -84,10 +88,11 @@ namespace MusicApp.Resources.Portable_Class
{ {
string path = musicCursor.GetString(pathID); string path = musicCursor.GetString(pathID);
path = path.Substring(0, path.LastIndexOf("/")); path = path.Substring(0, path.LastIndexOf("/"));
string displayPath = path.Substring(path.LastIndexOf("/") + 1, path.Length - (path.LastIndexOf("/") + 1));
if (!paths.Contains(path)) if (!paths.Contains(path))
{ {
pathDisplay.Add(displayPath);
paths.Add(path); paths.Add(path);
pathUse.Add(1); pathUse.Add(1);
} }
@@ -98,7 +103,7 @@ namespace MusicApp.Resources.Portable_Class
musicCursor.Close(); musicCursor.Close();
} }
adapter = new TwoLineAdapter(Android.App.Application.Context, Resource.Layout.TwoLineLayout, paths, pathUse); adapter = new TwoLineAdapter(Android.App.Application.Context, Resource.Layout.TwoLineLayout, pathDisplay, pathUse);
ListAdapter = adapter; ListAdapter = adapter;
ListView.TextFilterEnabled = true; ListView.TextFilterEnabled = true;
ListView.ItemClick += ListView_ItemClick; ListView.ItemClick += ListView_ItemClick;
@@ -113,12 +118,13 @@ namespace MusicApp.Resources.Portable_Class
public void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e) public void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{ {
ListSongs(paths[e.Position]); ListSongs(pathDisplay[e.Position], paths[e.Position]);
} }
private void ListView_ItemLongClick(object sender, AdapterView.ItemLongClickEventArgs e) private void ListView_ItemLongClick(object sender, AdapterView.ItemLongClickEventArgs e)
{ {
string path = paths[e.Position]; string path = paths[e.Position];
string displayPath = pathDisplay[e.Position];
AlertDialog.Builder builder = new AlertDialog.Builder(Activity, Resource.Style.AppCompatAlertDialogStyle); AlertDialog.Builder builder = new AlertDialog.Builder(Activity, Resource.Style.AppCompatAlertDialogStyle);
builder.SetTitle("Pick an action"); builder.SetTitle("Pick an action");
@@ -127,7 +133,7 @@ namespace MusicApp.Resources.Portable_Class
switch (args.Which) switch (args.Which)
{ {
case 0: case 0:
ListSongs(path); ListSongs(displayPath, path);
break; break;
case 1: case 1:
GetPlaylist(path); GetPlaylist(path);
@@ -142,15 +148,15 @@ namespace MusicApp.Resources.Portable_Class
builder.Show(); builder.Show();
} }
void ListSongs(string path) void ListSongs(string displayPath, string path)
{ {
AppCompatActivity act = (AppCompatActivity)Activity; AppCompatActivity act = (AppCompatActivity)Activity;
act.SupportActionBar.SetHomeButtonEnabled(true); act.SupportActionBar.SetHomeButtonEnabled(true);
act.SupportActionBar.SetDisplayHomeAsUpEnabled(true); act.SupportActionBar.SetDisplayHomeAsUpEnabled(true);
act.SupportActionBar.Title = path; act.SupportActionBar.Title = displayPath;
MainActivity.instance.HideTabs(); //MainActivity.instance.HideTabs();
FragmentTransaction transaction = FragmentManager.BeginTransaction(); FragmentTransaction transaction = FragmentManager.BeginTransaction();
transaction.Replace(Resource.Id.contentView, FolderTracks.NewInstance(path)); transaction.Replace(Resource.Id.pager, FolderTracks.NewInstance(path));
transaction.AddToBackStack(null); transaction.AddToBackStack(null);
transaction.Commit(); transaction.Commit();
} }

View File

@@ -56,12 +56,14 @@ namespace MusicApp.Resources.Portable_Class
{ {
instance = new FolderTracks { Arguments = new Bundle() }; instance = new FolderTracks { Arguments = new Bundle() };
instance.path = path; instance.path = path;
System.Console.WriteLine("Path : " + path);
return instance; return instance;
} }
void PopulateList() void PopulateList()
{ {
Uri musicUri = MediaStore.Audio.Media.GetContentUriForPath(path); Uri musicUri = MediaStore.Audio.Media.GetContentUriForPath(path);
System.Console.WriteLine(path);
CursorLoader cursorLoader = new CursorLoader(Android.App.Application.Context, musicUri, null, null, null, null); CursorLoader cursorLoader = new CursorLoader(Android.App.Application.Context, musicUri, null, null, null, null);
ICursor musicCursor = (ICursor)cursorLoader.LoadInBackground(); ICursor musicCursor = (ICursor)cursorLoader.LoadInBackground();
@@ -76,12 +78,16 @@ namespace MusicApp.Resources.Portable_Class
int pathID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Data); int pathID = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Data);
do do
{ {
string path = musicCursor.GetString(pathID);
if (!path.Contains(this.path))
continue;
string Artist = musicCursor.GetString(artistID); string Artist = musicCursor.GetString(artistID);
string Title = musicCursor.GetString(titleID); string Title = musicCursor.GetString(titleID);
string Album = musicCursor.GetString(albumID); string Album = musicCursor.GetString(albumID);
long AlbumArt = musicCursor.GetLong(musicCursor.GetColumnIndex(MediaStore.Audio.Albums.InterfaceConsts.AlbumId)); long AlbumArt = musicCursor.GetLong(musicCursor.GetColumnIndex(MediaStore.Audio.Albums.InterfaceConsts.AlbumId));
long id = musicCursor.GetLong(thisID); long id = musicCursor.GetLong(thisID);
string path = musicCursor.GetString(pathID);
if (Title == null) if (Title == null)
Title = "Unknown Title"; Title = "Unknown Title";

View File

@@ -1,106 +1,50 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextColor="@android:color/white"
app:tabSelectedTextColor="@android:color/white"
app:tabIndicatorColor="@android:color/white"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/contentView"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomView"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="start"
android:layout_alignParentBottom="true"
android:background="@android:color/white"
app:elevation="16dp"
app:menu="@menu/bottom_items" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
<!--<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomView"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="start"
android:layout_alignParentBottom="true"
android:background="@android:color/white"
app:elevation="16dp"
app:menu="@menu/bottom_items" />
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true" android:fitsSystemWindows="true"
app:elevation="16dp" tools:context="com.journaldev.tablayoutviewpager.MainActivity">
android:id="@+id/toolbarCoordinator"
tools:context="com.journaldev.tablayoutappbar.MainActivity">
<android.support.design.widget.AppBarLayout <android.support.design.widget.AppBarLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar <android.support.v7.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> <android.support.design.widget.TabLayout
<android.support.design.widget.TabLayout android:id="@+id/tabs"
android:id="@+id/tabs" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
app:tabGravity="fill" app:tabTextColor="@android:color/white"
app:tabMode="fixed" app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@android:color/white" app:tabIndicatorColor="@android:color/white"
app:tabSelectedTextColor="@android:color/white" app:tabGravity="fill"
app:tabIndicatorColor="@android:color/white" app:tabMode="fixed" />
android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout> </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout> <android.support.v4.view.ViewPager
<FrameLayout android:id="@+id/pager"
android:id="@+id/contentView" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content" />
android:layout_width="match_parent" <RelativeLayout
android:layout_below="@+id/tabs" android:layout_width="match_parent"
android:layout_above="@+id/bottomView" /> android:layout_height="wrap_content">
<android.support.v4.view.ViewPager <FrameLayout
android:id="@+id/pager" android:id="@+id/contentView"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="fill_parent" android:layout_width="match_parent" />
android:layout_below="@id/tabs"/> <android.support.design.widget.BottomNavigationView
</RelativeLayout>--> android:id="@+id/bottomView"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="start"
android:layout_alignParentBottom="true"
android:background="@android:color/white"
app:elevation="16dp"
app:menu="@menu/bottom_items" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>