summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/AppCompat/FormsFragmentPagerAdapter.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 20:02:25 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-03-22 23:13:41 (GMT)
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Platform.Android/AppCompat/FormsFragmentPagerAdapter.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
Initial import
Diffstat (limited to 'Xamarin.Forms.Platform.Android/AppCompat/FormsFragmentPagerAdapter.cs')
-rw-r--r--Xamarin.Forms.Platform.Android/AppCompat/FormsFragmentPagerAdapter.cs59
1 files changed, 59 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/FormsFragmentPagerAdapter.cs b/Xamarin.Forms.Platform.Android/AppCompat/FormsFragmentPagerAdapter.cs
new file mode 100644
index 0000000..99fbb39
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/AppCompat/FormsFragmentPagerAdapter.cs
@@ -0,0 +1,59 @@
+´╗┐using Android.OS;
+using Android.Support.V4.App;
+using Java.Lang;
+
+namespace Xamarin.Forms.Platform.Android.AppCompat
+{
+ internal class FormsFragmentPagerAdapter<T> : FragmentPagerAdapter where T : Page
+ {
+ MultiPage<T> _page;
+
+ public FormsFragmentPagerAdapter(MultiPage<T> page, FragmentManager fragmentManager) : base(fragmentManager)
+ {
+ _page = page;
+ }
+
+ public override int Count => CountOverride;
+
+ public int CountOverride { get; set; }
+
+ public override Fragment GetItem(int position)
+ {
+ return FragmentContainer.CreateInstance(_page.Children[position]);
+ }
+
+ public override long GetItemId(int position)
+ {
+ return _page.Children[position].GetHashCode();
+ }
+
+ public override int GetItemPosition(Object objectValue)
+ {
+ var fragContainer = objectValue as FragmentContainer;
+ if (fragContainer != null && fragContainer.Page != null)
+ {
+ int index = _page.Children.IndexOf(fragContainer.Page);
+ if (index >= 0)
+ return index;
+ }
+ return PositionNone;
+ }
+
+ public override ICharSequence GetPageTitleFormatted(int position)
+ {
+ return new String(_page.Children[position].Title);
+ }
+
+ // http://stackoverflow.com/questions/18642890/fragmentstatepageradapter-with-childfragmentmanager-fragmentmanagerimpl-getfra/19099987#19099987
+ public override void RestoreState(IParcelable state, ClassLoader loader)
+ {
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ _page = null;
+ base.Dispose(disposing);
+ }
+ }
+} \ No newline at end of file