Example #1
0
        public bool OnNavigationItemSelected(IMenuItem item)
        {
            int id         = item.ItemId;
            var fragmentId = Fragments.Other;
            var drawer     = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);

            Func <IFragmentBase> fragmentCreator = null;

            if (id == Resource.Id.nav_schedule)
            {
                fragmentId      = Fragments.ScheduleMain;
                fragmentCreator = () => ScheduleView.NewInstance();
            }
            else if (id == Resource.Id.nav_buildings)
            {
                fragmentId      = Fragments.Buildings;
                fragmentCreator = () => new AddressesView();
            }
            else if (id == Resource.Id.nav_settings)
            {
                fragmentId      = Fragments.Settings;
                fragmentCreator = () => SettingsView.NewInstance();
            }
            if (this.currFragment?.FragmentType == fragmentId)
            {
                drawer.CloseDrawer(GravityCompat.Start);
                return(false);
            }
            if (fragmentId == Fragments.Other)
            {
                this.logger.Warn("{ItemId} doesn't have own Fragments enum id", item.ItemId);
            }
            if (fragmentCreator == null)
            {
                drawer.CloseDrawer(GravityCompat.Start);
                return(false);
            }
            ChangeFragment(fragmentCreator.Invoke(), true);
            drawer.CloseDrawer(GravityCompat.Start);
            return(true);
        }
Example #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            if (savedInstanceState == null)
            {
                var prefs = PreferenceManager.GetDefaultSharedPreferences(this);
                AppCompatDelegate.DefaultNightMode = prefs.GetBoolean("NightMode", default) ?
                                                     AppCompatDelegate.ModeNightYes : AppCompatDelegate.ModeNightNo;



#warning fix on release
                int firstLaunch;
                try
                {
                    firstLaunch = prefs.GetInt(PreferencesConstants.FirstLaunch, launchCode);
                }
                catch
                {
                    firstLaunch = launchCode;
                }
                if (firstLaunch == launchCode)
                {
                    prefs.Edit().Clear().Apply();
                    prefs.Edit().PutInt(PreferencesConstants.FirstLaunch, launchCode + 1).Apply();
                }
                this.ScheduleVmPreloadTask = Task.Run(() => PrepareSchdeuleVm(prefs));
            }
            SetTheme(Resource.Style.AppTheme_NoActionBar);
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            if (this.loggerFactory == null)
            {
                this.loggerFactory = DependencyInjector.GetILoggerFactory();
            }
            StringProvider.Context     = this;
            AssetProvider.AssetManager = this.Assets;
            StringProvider.SetUpLogger(this.loggerFactory);

            if (savedInstanceState == null)
            {
                ChangeFragment(ScheduleView.NewInstance(this.ScheduleVmPreloadTask), true);
                //SplashView.ScheduleVmPreloadTask = null;
            }
            else
            {
                // TODO: Fix stack
                //ChangeFragment(this.SupportFragmentManager.GetBackStackEntryAt(0)., Fragments.ScheduleMain, false);
            }

            ActivityCompat.RequestPermissions(this,
                                              new string[] { Android.Manifest.Permission.Internet }, 123);

            this.logger = this.loggerFactory.Create <MainView>();

            var navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);
            navigationView.NavigationItemSelected += (obj, arg) => OnNavigationItemSelected(arg.MenuItem);
            navigationView.SetCheckedItem(Resource.Id.nav_schedule);
            this.clickBackAgain = GetString(Resource.String.click_back_again);
            this.doubleBackToExitPressedOnce = false;
            PreferenceManager.GetDefaultSharedPreferences(this)
            .RegisterOnSharedPreferenceChangeListener(this);
            this.logger.Debug("MainActivity created successfully");
        }