Ejemplo n.º 1
0
        public override StartCommandResult OnStartCommand(Android.Content.Intent intent, StartCommandFlags flags, int startId)
        {
            if (!_initted)
            {
                // This can be a program entry point.
                Log.SetLogger(new LogAndroid());

                Log.Info(LogTag, "Started LifeSharp service");
                s_instance = this;
                _settings  = new Settings(this.ApplicationContext);

                foreach (var service in s_services)
                {
                    service.start(this.ApplicationContext, _settings);
                }

                _initted = true;
            }
            else
            {
                foreach (var service in s_services)
                {
                    service.kick(this.ApplicationContext, _settings);
                }
            }

            return(StartCommandResult.Sticky);
        }
Ejemplo n.º 2
0
        static public void CompleteStartup(Context context, Settings settings)
        {
            if (Config.GcmNotificationKey != null)
            {
                if (!GCMRegistrationService.IsAvailable(context))
                {
                    settings.enabled = false;
                    settings.commit();
                    return;
                }
                GCMRegistrationService.Start(context);
            }

            if (settings.enabled)
            {
                LifeSharpService.Start(context);
            }
        }
Ejemplo n.º 3
0
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Log.SetLogger(new LogAndroid());

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Set support action bar based on toolbar from layout XML
            var mainToolbar = FindViewById <Toolbar>(Resource.Id.mainToolbar);

            SetSupportActionBar(mainToolbar);

            // Set flag to allow status bar colour to be managed by this activity.
            Window.SetFlags(WindowManagerFlags.DrawsSystemBarBackgrounds, WindowManagerFlags.DrawsSystemBarBackgrounds);

            Settings settings            = new Settings(ApplicationContext);
            var      statusLabel         = FindViewById <TextView>(Resource.Id.loginStatus);
            var      enabled             = FindViewById <CheckBox>(Resource.Id.checkEnable);
            var      buttonNotifications = FindViewById <Button>(Resource.Id.buttonNotifications);
            var      login    = FindViewById <TextView>(Resource.Id.editLogin);
            var      password = FindViewById <TextView>(Resource.Id.editPassword);

            // First run initialisation.
            if (!settings.afterFirstRun)
            {
                // Set default values from NotificationPreferences.xml
                PreferenceManager.SetDefaultValues(ApplicationContext, Resource.Xml.NotificationPreferences, true);

                // If notification sound is null, set it to the system-default sound
                if (settings.downloadSound == null)
                {
                    settings.downloadSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification).ToString();
                }
                if (settings.uploadSound == null)
                {
                    settings.uploadSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification).ToString();
                }

                // Indicate that first run init is complete.
                settings.afterFirstRun = true;
                settings.commit();
            }

            // Load up defaults from Settings.
            enabled.Checked = settings.enabled;
            login.Text      = settings.userName;
            password.Text   = settings.password;

            if (settings.authToken.IsNullOrEmpty())
            {
                statusLabel.Text = "Not logged in";
            }
            else
            {
                statusLabel.Text = "Logged in as " + settings.userName;
            }

            // Wire up UI events.
            enabled.CheckedChange += delegate {
                bool oldSetting = settings.enabled;

                settings.enabled = enabled.Checked;
                settings.commit();

                if (!oldSetting)
                {
                    LifeSharpService.Start(this);
                }
            };

            buttonNotifications.Click += delegate {
                Intent intent = new Intent(this, typeof(ConfigureNotificationsActivity));
                StartActivity(intent);
            };

            var defaultStreamSpinner = FindViewById <Spinner>(Resource.Id.defaultStream);

            await fillStreams(settings);

            defaultStreamSpinner.ItemSelected += delegate {
                if (_streamIds == null)
                {
                    return;
                }

                settings.defaultStream = _streamIds[defaultStreamSpinner.SelectedItemPosition];
                settings.commit();
                Log.Info("LifeSharp", "Setting new default stream to {0}", settings.defaultStream);
            };

            Button button = FindViewById <Button>(Resource.Id.buttonLogin);

            button.Click += async delegate {
                settings.userName = login.Text;
                settings.password = password.Text;
                settings.commit();
                Log.Info("LifeSharp", "Logging in with user {0} and password {1}", login.Text, password.Text);

                try
                {
                    string result = await Network.Login(settings);

                    if (result == null)
                    {
                        statusLabel.Text   = "Log in failed";
                        settings.authToken = null;
                        enabled.Checked    = false;
                    }
                    else
                    {
                        statusLabel.Text   = "Logged in successfully";
                        settings.authToken = result;
                        enabled.Checked    = true;
                    }

                    // Get our user ID.
                    Protocol.LoginInfo loginInfo = await Network.GetLoginInfo(result, settings.userName);

                    if (loginInfo.succeeded())
                    {
                        settings.userId = loginInfo.id;
                        // Commit so that user ID is available to upcoming fillStreams() call.
                        settings.commit();
                    }

                    // Obtain list of streams owned by user.
                    await fillStreams(settings);

                    settings.commit();

                    // This won't have already happened if we didn't have login info.
                    LifeSharpService.Start(this);
                }
                catch (Exception ex)
                {
                    Log.Info("LifeSharp", "Can't contact server: {0}", ex);
                    statusLabel.Text = "Exception during login";
                }
            };
            button        = FindViewById <Button>(Resource.Id.buttonGallery);
            button.Click += delegate(object sender, EventArgs e) {
                StartActivity(typeof(GalleryActivity));
            };

            ReceiveBoot.CompleteStartup(this, settings);
        }