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";
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)
{
@@ -147,7 +162,7 @@ namespace MusicApp
searchView.ClearFocus();
searchView.OnActionViewCollapsed();
if (id == 3)
if (id != 0)
return;
SupportActionBar.SetHomeButtonEnabled(false);
@@ -195,7 +210,7 @@ namespace MusicApp
SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contentView, fragment).Commit();
}
void SetTabs()
void SetTabs(int selectedTab = 0)
{
FrameLayout frame = FindViewById<FrameLayout>(Resource.Id.contentView);
frame.Visibility = ViewStates.Gone;
@@ -217,14 +232,21 @@ namespace MusicApp
pager.Adapter = adapter;
tabs.SetupWithViewPager(pager);
pager.CurrentItem = selectedTab;
tabs.SetScrollPosition(selectedTab, 0f, true);
}
//AFTER USING FOLDERTRACKS, BROWSE AND FOLDERBROWSE OONCLICK DOES NOT WORK;
public void HideTabs()
{
TabLayout tabs = FindViewById<TabLayout>(Resource.Id.tabs);
tabs.RemoveAllTabs();
tabs.Visibility = ViewStates.Gone;
ViewPager pager = FindViewById<ViewPager>(Resource.Id.pager);
if (pager.Adapter != null)
pager.Adapter.Dispose();
pager.Adapter = null;
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)
{
PopulateList();
//if(FolderBrowse.instance != null)
// FolderBrowse.instance.PopulateList();
return;
}
string[] permissions = new string[] { permission };

View File

@@ -20,6 +20,7 @@ namespace MusicApp.Resources.Portable_Class
public static FolderBrowse instance;
public static Context act;
public static LayoutInflater inflater;
public List<string> pathDisplay = new List<string>();
public List<string> paths = new List<string>();
public List<int> pathUse = new List<int>();
public ArrayAdapter adapter;
@@ -69,8 +70,11 @@ namespace MusicApp.Resources.Portable_Class
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;
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);
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);
}
@@ -98,7 +103,7 @@ namespace MusicApp.Resources.Portable_Class
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;
ListView.TextFilterEnabled = true;
ListView.ItemClick += ListView_ItemClick;
@@ -113,12 +118,13 @@ namespace MusicApp.Resources.Portable_Class
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)
{
string path = paths[e.Position];
string displayPath = pathDisplay[e.Position];
AlertDialog.Builder builder = new AlertDialog.Builder(Activity, Resource.Style.AppCompatAlertDialogStyle);
builder.SetTitle("Pick an action");
@@ -127,7 +133,7 @@ namespace MusicApp.Resources.Portable_Class
switch (args.Which)
{
case 0:
ListSongs(path);
ListSongs(displayPath, path);
break;
case 1:
GetPlaylist(path);
@@ -142,15 +148,15 @@ namespace MusicApp.Resources.Portable_Class
builder.Show();
}
void ListSongs(string path)
void ListSongs(string displayPath, string path)
{
AppCompatActivity act = (AppCompatActivity)Activity;
act.SupportActionBar.SetHomeButtonEnabled(true);
act.SupportActionBar.SetDisplayHomeAsUpEnabled(true);
act.SupportActionBar.Title = path;
MainActivity.instance.HideTabs();
act.SupportActionBar.Title = displayPath;
//MainActivity.instance.HideTabs();
FragmentTransaction transaction = FragmentManager.BeginTransaction();
transaction.Replace(Resource.Id.contentView, FolderTracks.NewInstance(path));
transaction.Replace(Resource.Id.pager, FolderTracks.NewInstance(path));
transaction.AddToBackStack(null);
transaction.Commit();
}

View File

@@ -56,12 +56,14 @@ namespace MusicApp.Resources.Portable_Class
{
instance = new FolderTracks { Arguments = new Bundle() };
instance.path = path;
System.Console.WriteLine("Path : " + path);
return instance;
}
void PopulateList()
{
Uri musicUri = MediaStore.Audio.Media.GetContentUriForPath(path);
System.Console.WriteLine(path);
CursorLoader cursorLoader = new CursorLoader(Android.App.Application.Context, musicUri, null, null, null, null);
ICursor musicCursor = (ICursor)cursorLoader.LoadInBackground();
@@ -76,12 +78,16 @@ namespace MusicApp.Resources.Portable_Class
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);
string path = musicCursor.GetString(pathID);
if (Title == null)
Title = "Unknown Title";

View File

@@ -1,106 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<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: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_height="match_parent"
android:fitsSystemWindows="true"
app:elevation="16dp"
android:id="@+id/toolbarCoordinator"
tools:context="com.journaldev.tablayoutappbar.MainActivity">
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"
app:layout_scrollFlags="scroll|enterAlways"
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"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabTextColor="@android:color/white"
app:tabSelectedTextColor="@android:color/white"
app:tabIndicatorColor="@android:color/white"
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.design.widget.CoordinatorLayout>
<FrameLayout
android:id="@+id/contentView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_below="@+id/tabs"
android:layout_above="@+id/bottomView" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/tabs"/>
</RelativeLayout>-->
<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>