This repository has been archived by the owner on Dec 18, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
TabBarController.cs
112 lines (96 loc) · 3.91 KB
/
TabBarController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using Cirrious.Conference.Core.ViewModels;
using Cirrious.Conference.Core.ViewModels.HomeViewModels;
using Cirrious.Conference.Core.ViewModels.SessionLists;
using Cirrious.Conference.UI.Touch.Interfaces;
using Cirrious.CrossCore;
using Cirrious.MvvmCross.ViewModels;
using MonoTouch.UIKit;
using Cirrious.MvvmCross.Touch.Views;
using Cirrious.MvvmCross.Views;
using Cirrious.MvvmCross.Binding.Touch.Views;
namespace Cirrious.Conference.UI.Touch.Views
{
public class TabBarController
: MvxTabBarViewController
, ITabBarPresenter
{
public TabBarController()
{
Mvx.Resolve<ITabBarPresenterHost>().TabBarPresenter = this;
// because the UIKit base class does ViewDidLoad, we have to make a second call here
ViewDidLoad();
}
public new HomeViewModel ViewModel {
get { return (HomeViewModel)base.ViewModel; }
set { base.ViewModel = value; }
}
private int _createdSoFarCount = 0;
private UIViewController CreateTabFor(string title, string imageName, IMvxViewModel viewModel)
{
var controller = new UINavigationController();
controller.NavigationBar.TintColor = UIColor.Black;
var screen = this.CreateViewControllerFor(viewModel) as UIViewController;
SetTitleAndTabBarItem(screen, title, imageName);
controller.PushViewController(screen, false);
return controller;
}
private void SetTitleAndTabBarItem(UIViewController screen, string title, string imageName)
{
screen.Title = ViewModel.TextSource.GetText(title);
screen.TabBarItem = new UITabBarItem(title, UIImage.FromBundle("Images/Tabs/" + imageName + ".png"),
_createdSoFarCount);
_createdSoFarCount++;
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// first time around this will be null, second time it will be OK
if (ViewModel == null)
return;
var viewControllers = new UIViewController[]
{
CreateTabFor("Welcome", "home", ViewModel.Welcome),
CreateTabFor("Sessions", "sessions", ViewModel.Sessions),
CreateTabFor("Favorites", "favorites", ViewModel.Favorites),
CreateTabFor("Tweets", "twitter", ViewModel.Twitter),
};
ViewControllers = viewControllers;
CustomizableViewControllers = new UIViewController[] { };
SelectedViewController = ViewControllers[0];
}
/// <summary>
/// Only allow iPad application to rotate, iPhone is always portrait
/// </summary>
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
if (AppDelegate.IsPad)
return true;
else
return toInterfaceOrientation == UIInterfaceOrientation.Portrait;
}
public bool GoBack()
{
var subNavigation = this.SelectedViewController as UINavigationController;
if (subNavigation == null)
return false;
if (subNavigation.ViewControllers.Length <= 1)
return false;
subNavigation.PopViewControllerAnimated(true);
return true;
}
public bool ShowView(IMvxTouchView view)
{
if (TryShowViewInCurrentTab(view))
return true;
return false;
}
private bool TryShowViewInCurrentTab(IMvxTouchView view)
{
var navigationController = (UINavigationController)this.SelectedViewController;
navigationController.PushViewController((UIViewController)view, true);
return true;
}
}
}