public MainPageViewModel()
 {
     MessagingCenter.Subscribe <BottomTabViewModel, View>(this, ConstMessage.SET_MAIN_VIEW, (sender, e) =>
     {
         Task.Factory.StartNew(() =>
         {
             MainContentView = null;
             Device.BeginInvokeOnMainThread(() =>
             {
                 MainContentView = e;
                 MainContentView.TranslateTo(0, MainContentView.TranslationY, 500, Easing.CubicOut);
             });
         });
     });
 }
Beispiel #2
0
        protected override void OnCreate(Bundle bundle)
        {
            AndroidEnvironment.UnhandledExceptionRaiser += this.AndroidEnvironment_UnhandledExceptionRaiser;
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += this.HandleExceptions;

            TaskScheduler.UnobservedTaskException += this.TaskScheduler_UnobservedTaskException;

            UserDialogs.Init(this);
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            // ensure the initialization is done
            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(this.ApplicationContext);

            setup.EnsureInitialized();

            if (this.Intent.Extras.ContainsKey("notificationPlayList"))
            {
                if (this.ViewModel != null)
                {
                    ((BaseViewModel)this.ViewModel).ShowPlayer();
                }
                else
                {
                    var loaderService = Mvx.Resolve <IMvxViewModelLoader>();
                    this.ViewModel = loaderService.LoadViewModel(new MvxViewModelRequest(typeof(MainViewModel), null, null, null), null) as MainViewModel;
                    ((BaseViewModel)this.ViewModel).ShowPlayer();
                }
            }

            base.OnCreate(bundle);
            this.SetContentView(Resource.Layout.Main);

            var presenter       = (DroidPresenter)Mvx.Resolve <IMvxAndroidViewPresenter>();
            var initialFragment = new MainContentView {
                ViewModel = this.ViewModel
            };

            presenter.RegisterFragmentManager(this.FragmentManager, initialFragment);

            baseViewModel = (BaseViewModel)this.ViewModel;

            var prefs = Application.Context.GetSharedPreferences("Fildo", FileCreationMode.Private);

            this.CultureInfo = new CultureInfo(prefs.GetString("CultureForced", Thread.CurrentThread.CurrentUICulture.Name));

            ((BaseViewModel)this.ViewModel).SetCulture(this.CultureInfo);

            this.toolbar          = this.FindViewById <Toolbar>(Resource.Id.toolbar);
            this.menuDrawerLayout = this.FindViewById <DrawerLayout>(Resource.Id.mainContainer);
            this.menuDrawerToggle = new MvxActionBarDrawerToggle(
                this,
                // host Activity
                this.menuDrawerLayout,
                // DrawerLayout object

                Resource.String.Login,
                // "open drawer" description
                Resource.String.Login // "close drawer" description
                );
            this.menuDrawerLayout.SetDrawerListener(this.menuDrawerToggle);

            this.SetSupportActionBar(this.toolbar);
            this.SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            this.SupportActionBar.SetHomeButtonEnabled(true);

            this.progress = new BindableProgress(this, this.ViewModel);

            var set = this.CreateBindingSet <MainView, MainViewModel>();

            set.Bind(this.progress).For(p => p.Visible).To(vm => vm.IsBusy);
            set.Bind(this.progress).For(p => p.NoInternet).To(vm => vm.NoInternet);
            set.Bind(this.progress).For(p => p.NewVersion).To(vm => vm.NewVersion);
            set.Bind(this).For(p => p.ShowMenu).To(vm => vm.ShowMenu);
            set.Apply();

            if (prefs.GetBoolean("FirstTime", true))
            {
                this.menuDrawerLayout.OpenDrawer((int)GravityFlags.Start);
                var prefEditor = prefs.Edit();
                prefEditor.PutBoolean("FirstTime", false);
                prefEditor.Commit();
            }
            BackgroundStreamingService.Main = this;

            BackgroundStreamingService.SongNameChanged -= this.BackgroundStreamingService_SongNameChanged;
            BackgroundStreamingService.percentChanged  -= this.BackgroundStreamingService_posChanged;
            BackgroundStreamingService.SongNameChanged += this.BackgroundStreamingService_SongNameChanged;
            BackgroundStreamingService.percentChanged  += this.BackgroundStreamingService_posChanged;

            GAService.GetGASInstance().Initialize(this);
            GAService.GetGASInstance().Track_App_Page("Fildo Main Activity");
        }