Skip to content

Commit

Permalink
Android: Fixed regression bug; the fragments would send a OnViewReady…
Browse files Browse the repository at this point in the history
… event even when the fragment is reactivated (i.e. not destroyed).

Related to issue #406.
  • Loading branch information
ycastonguay committed Jul 16, 2013
1 parent e926aa1 commit 5a744ac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
Expand Up @@ -66,7 +66,7 @@ public override int Count

public override View GetView(int position, View convertView, ViewGroup parent)
{
Console.WriteLine(">>>>>>>>> MobileLibraryBrowserGridAdapter - GetView - position: {0}", position);
//Console.WriteLine(">>>>>>>>> MobileLibraryBrowserGridAdapter - GetView - position: {0}", position);
var item = _items[position];
View view = convertView;
if (view == null) // no view to re-use, create new
Expand All @@ -82,7 +82,7 @@ public override View GetView(int position, View convertView, ViewGroup parent)

Task.Factory.StartNew(() => {
// WTF Android #549381: GetView position 0 gets called extremely often for no reason. Another job well done, Google. Why can't you optimize your code!?!?
Console.WriteLine(">>>>>>>>> MobileLibraryBrowserGridAdapter - Loading album art - position: {0} artistName: {1} albumTitle: {2}", position, _items[position].Query.ArtistName, _items[position].Query.AlbumTitle);
//Console.WriteLine(">>>>>>>>> MobileLibraryBrowserGridAdapter - Loading album art - position: {0} artistName: {1} albumTitle: {2}", position, _items[position].Query.ArtistName, _items[position].Query.AlbumTitle);
// Check if bitmap is in cache before requesting album art (Android likes to request GetView extremely often for no good reason)
//_fragment.OnRequestAlbumArt(_items[position].Query.ArtistName, _items[position].Query.AlbumTitle);
Expand All @@ -96,7 +96,7 @@ public void RefreshAlbumArtCell(string artistName, string albumTitle, byte[] alb
try
{
var mainActivity = (MainActivity)_context;
Console.WriteLine("MobileLibraryBrowserGridAdapter - Received album art for {0}/{1}", artistName, albumTitle);
//Console.WriteLine("MobileLibraryBrowserGridAdapter - Received album art for {0}/{1}", artistName, albumTitle);

int index = _items.FindIndex(x => x.Query.ArtistName == artistName && x.Query.AlbumTitle == albumTitle);
if (index >= 0)
Expand All @@ -111,7 +111,7 @@ public void RefreshAlbumArtCell(string artistName, string albumTitle, byte[] alb
}
catch (Exception ex)
{
Console.WriteLine("MobileLibraryBrowserGridAdapter - Failed to load album art: {0}", ex);
//Console.WriteLine("MobileLibraryBrowserGridAdapter - Failed to load album art: {0}", ex);
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions MPfm/MPfm.Android/Classes/Fragments/Base/BaseFragment.cs
Expand Up @@ -24,21 +24,22 @@ namespace MPfm.Android.Classes.Fragments.Base
{
public class BaseFragment : Fragment, IBaseView
{
bool _isViewAlreadyBound = false;

public BaseFragment(Action<IBaseView> onViewReady)
{
this.OnViewReady = onViewReady;
}

public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
//if (OnViewReady != null) OnViewReady(this);
}

public override void OnResume()
{
base.OnResume();
if (OnViewReady != null) OnViewReady(this);
if (OnViewReady != null && !_isViewAlreadyBound)
{
// Since OnResume is called if the fragment is reactivated (i.e. not destroyed), we need a flag to know if the view was already bound
_isViewAlreadyBound = true;
OnViewReady(this);
}
}

public override void OnDestroyView()
Expand Down
38 changes: 19 additions & 19 deletions MPfm/MPfm.Android/Classes/Fragments/MobileLibraryBrowserFragment.cs
Expand Up @@ -50,7 +50,7 @@ public MobileLibraryBrowserFragment(Action<IBaseView> onViewReady)

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
Console.WriteLine("MLBFragment - OnCreateView");
Console.WriteLine("##############>> MLBFragment - OnCreateView");

_view = inflater.Inflate(Resource.Layout.MobileLibraryBrowser, container, false);
_listView = _view.FindViewById<ListView>(Resource.Id.mobileLibraryBrowser_listView);
Expand Down Expand Up @@ -91,37 +91,37 @@ private void GridViewOnItemLongClick(object sender, AdapterView.ItemLongClickEve

public override void OnResume()
{
Console.WriteLine("MLBFragment - OnResume");
Console.WriteLine("##############>> MLBFragment - OnResume");
base.OnResume();
}

//public override void OnStart()
//{
// Console.WriteLine("MLBFragment - OnStart");
// base.OnStart();
//}
public override void OnStart()
{
Console.WriteLine("##############>> MLBFragment - OnStart");
base.OnStart();
}

//public override void OnStop()
//{
// Console.WriteLine("MLBFragment - OnStop");
// base.OnStop();
//}
public override void OnStop()
{
Console.WriteLine("##############>> MLBFragment - OnStop");
base.OnStop();
}

//public override void OnPause()
//{
// Console.WriteLine("MLBFragment - OnPause");
// base.OnPause();
//}
public override void OnPause()
{
Console.WriteLine("##############>> MLBFragment - OnPause");
base.OnPause();
}

public override void OnDestroy()
{
Console.WriteLine("MLBFragment - OnDestroy");
Console.WriteLine("##############>> MLBFragment - OnDestroy");
base.OnDestroy();
}

public override void OnDestroyView()
{
Console.WriteLine("MLBFragment - OnDestroyView");
Console.WriteLine("##############>> MLBFragment - OnDestroyView");
base.OnDestroyView();
}

Expand Down

0 comments on commit 5a744ac

Please sign in to comment.