Beispiel #1
0
        private void Logout()
        {
            try
            {
                var salir = loginService.Logout(client);
                if (salir)
                {
                    try
                    {
                        record = false;

                        ISharedPreferencesEditor l = logoutPref.Edit();
                        l.PutString("exit", "yes");
                        l.Commit();
                        database.DeleteDataDatabase();
                        FakeSessionDelete.DeleteSession();
                        ISharedPreferencesEditor shared = GetSharedPreferences("userPref", FileCreationMode.Private).Edit();
                        shared.Clear();
                        shared.Commit();
                        StopService(service);
                        textToSpeak = "Sesión cerrada correctamente";
                        toSpeech    = new TextToSpeech(this, this);
                    }
                    catch (Exception ex)
                    {
                        textToSpeak = "Ha ocurrido un problema al cerrar la sesión. Por favor, inténtelo más tarde. ¿Qué quiere hacer?. ¿Enviar, leer, contactos, configuración, o no hacer nada?";
                        toSpeech    = new TextToSpeech(this, this);
                    }
                }
                else
                {
                    count       = 0;
                    record      = true;
                    textToSpeak = "Lo siento, ha ocurrido un error cerrando la sesión. Inténtelo más tarde. ¿Qué quiere hacer?. ¿Enviar, leer, contactos, configuración, o no hacer nada?";
                    toSpeech    = new TextToSpeech(this, this);
                }
            }
            catch (Exception ex)
            {
                textToSpeak = "Ha ocurrido un problema al cerrar la sesión en Telegram. Por favor, inténtelo más tarde. ¿Qué quiere hacer?. ¿Enviar, leer, contactos, configuración, o no hacer nada?";
                toSpeech    = new TextToSpeech(this, this);
            }
        }
        public void Tear()
        {
            SQLiteRepository con = new SQLiteRepository();

            con.DeleteDataDatabase();
        }
Beispiel #3
0
        public void OnResults(Bundle results)
        {
            int countOnResults = 0;
            IEnumerable <string> matches = results.GetStringArrayList(SpeechRecognizer.ResultsRecognition);
            string   text = "", codigo = "", hash = "";
            bool     isRegistered = true;
            TLUser   user;
            DateTime ahora = DateTime.UtcNow;

            Android.Net.Uri inboxURI = Android.Net.Uri.Parse("content://sms/inbox");

            foreach (string result in matches)
            {
                countOnResults++;
                try
                {
                    if (countOnResults == 1)
                    {
                        record = true;
                        if (int.TryParse(result[0].ToString(), out int num))
                        {
                            text = result.Replace(" ", string.Empty);
                            if (text.Length == 9)
                            {
                                telephone  = "34" + text;
                                phone.Text = telephone;

                                client = loginService.Connect();

                                isRegistered = loginService.IsPhoneRegistered(client, telephone);
                                if (!isRegistered)
                                {
                                    textToSpeak = "No tiene una cuenta registrada. ¿Cuál quiere que sea su nombre de usuario?";
                                    toSpeech    = new TextToSpeech(this, this);
                                }
                                else
                                {
                                    if (!client.IsUserAuthorized())
                                    {
                                        hash   = loginService.SendCodeRequest(client, telephone);
                                        codigo = LookForSms(ahora);
                                        if (codigo == "Ha habido un error")
                                        {
                                            record      = false;
                                            textToSpeak = "Ha habido un error en la recepción del SMS. Por favor, inténtelo en aproximadamente media hora";
                                            toSpeech    = new TextToSpeech(this, this);
                                        }
                                        else
                                        {
                                            code.Text = codigo;
                                            user      = loginService.MakeAuth(client, telephone, hash, codigo);

                                            try
                                            {
                                                User u = new User
                                                {
                                                    Phone          = telephone,
                                                    Username       = user.Username,
                                                    Hash           = hash,
                                                    Code           = codigo,
                                                    SessionExpires = (new DateTime(1970, 1, 1)).AddMilliseconds(client.Session.SessionExpires).AddHours(1),
                                                    AccessHash     = user.AccessHash
                                                };
                                                userRepo.InsertUser(u);

                                                configuracion = new Models.Config()
                                                {
                                                    Phone     = telephone,
                                                    Voz       = true,
                                                    Velocidad = (float)1.0,
                                                    TipoVoz   = toSpeech.Voice != null ? toSpeech.Voice.Name : ""
                                                };
                                                configRepo.InsertConfig(configuracion);
                                                bool contactos           = contactService.GetContacts(client, contactRepo);
                                                bool contactosBloqueados = contactService.GetBlockedContacts(client, contactRepo);
                                            }
                                            catch (Exception ex) { }

                                            Vibrator vibrator = (Vibrator)this.GetSystemService(Context.VibratorService);
                                            vibrator.Vibrate(1000);
                                            record = false;
                                            // Creación sesión
                                            InitSession(telephone);

                                            textToSpeak = "Login correcto";
                                            toSpeech    = new TextToSpeech(this, this);
                                        }
                                    }
                                    else
                                    {
                                        user = client.Session.TLUser;

                                        try
                                        {
                                            User u = new User
                                            {
                                                Phone          = telephone,
                                                Username       = user.Username,
                                                Hash           = hash,
                                                Code           = codigo,
                                                SessionExpires = (new DateTime(1970, 1, 1)).AddMilliseconds(client.Session.SessionExpires).AddHours(1),
                                                AccessHash     = user.AccessHash
                                            };
                                            userRepo.InsertUser(u);
                                            configuracion = new Models.Config()
                                            {
                                                Phone     = telephone,
                                                Voz       = true,
                                                Velocidad = (float)1.0,
                                                TipoVoz   = toSpeech.Voice != null ? toSpeech.Voice.Name : ""
                                            };
                                            configRepo.InsertConfig(configuracion);
                                        }
                                        catch (Exception ex) { }
                                        // Creación sesión
                                        InitSession(telephone);
                                        Vibrator vibrator = (Vibrator)this.GetSystemService(Context.VibratorService);
                                        vibrator.Vibrate(1000);
                                        record      = false;
                                        textToSpeak = "Login correcto";
                                        toSpeech    = new TextToSpeech(this, this);
                                    }
                                }
                            }
                            else
                            {
                                record      = true;
                                textToSpeak = "El número de teléfono no tiene un formato correcto. Por favor, diga un número de teléfono válido";
                                toSpeech    = new TextToSpeech(this, this);
                            }
                        }
                        else
                        {
                            client = loginService.Connect();
                            hash   = loginService.SendCodeRequest(client, telephone);

                            codigo = LookForSms(ahora);

                            if (int.TryParse(codigo, out int num2))
                            {
                                record      = false;
                                textToSpeak = "Ha habido un error esperando el código de verificación. Por favor, inténtelo en 30 minutos";
                                toSpeech    = new TextToSpeech(this, this);
                            }
                            else
                            {
                                user = loginService.SignUp(client, telephone, hash, codigo, result, "");
                                user = loginService.MakeAuth(client, telephone, hash, codigo);

                                try
                                {
                                    User u = new User
                                    {
                                        Phone          = telephone,
                                        Username       = user.Username,
                                        Hash           = hash,
                                        Code           = codigo,
                                        SessionExpires = (new DateTime(1970, 1, 1)).AddMilliseconds(client.Session.SessionExpires).AddHours(1),
                                        AccessHash     = user.AccessHash
                                    };
                                    userRepo.InsertUser(u);

                                    configuracion = new Models.Config()
                                    {
                                        Phone     = telephone,
                                        Voz       = true,
                                        Velocidad = (float)1.0,
                                        TipoVoz   = toSpeech.Voice != null ? toSpeech.Voice.Name : ""
                                    };
                                    configRepo.InsertConfig(configuracion);

                                    bool contactos           = contactService.GetContacts(client, contactRepo);
                                    bool contactosBloqueados = contactService.GetBlockedContacts(client, contactRepo);
                                }
                                catch (Exception ex) { }
                                Vibrator vibrator = (Vibrator)this.GetSystemService(Context.VibratorService);
                                vibrator.Vibrate(1000);
                                record = false;

                                // Creación sesión
                                InitSession(telephone);

                                textToSpeak = "Registro y login correctos";
                                toSpeech    = new TextToSpeech(this, this);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    // TODO: cerrar la aplicación
                    record = false;
                    database.DeleteDataDatabase();
                    FakeSessionDelete.DeleteSession();
                    textToSpeak = "Ha ocurrido un error. Por favor, inténtelo más tarde";
                    toSpeech    = new TextToSpeech(this, this);
                }
            }
        }