Ejemplo n.º 1
0
        private void SetupMapIfNeeded()
        {
            if (Reachability.InternetConnectionStatus() == NetworkStatus.NotReachable)
            {
                return;
            }

            if (_GoogleMap == null)
            {
                _GoogleMap = _MapFragment.Map;
                if (_GoogleMap != null)
                {
                    var client = new WebClient();

                    client.DownloadStringCompleted += (sender, e) =>
                    {
                        if (e.Error != null)
                        {
                            return;
                        }

                        try
                        {
                            _XDoc = XDocument.Parse(e.Result);

                            RunOnUiThread(() => LoadPlacemarks());
                            //RunOnUiThread(() => HideLoadingOverlay());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    };

                    client.DownloadStringAsync(new Uri(_Mappa.Url));
                    ShowLoadingOverlay();

                    //_GoogleMap.SetInfoWindowAdapter(new CustomInfoWindowAdapter(this));
                }
            }
        }
Ejemplo n.º 2
0
        private void CheckUpdates()
        {
            Uri host = new Uri(DataManager.Get <ISettingsManager>().Settings.DownloadUrl);

            if (!Reachability.IsHostReachable("http://" + host.Host))
            {
                return;
            }

            var info = new DirectoryInfo(DataManager.Get <ISettingsManager>().Settings.DocPath);
            var dir  = _CurrentDir.FullName.Replace(info.FullName, "").Trim('/');

            ThreadPool.QueueUserWorkItem(delegate
            {
                var downloads = DownloadManager.GetDocuments(dir);

                //var updates = downloads.Where(d => d.Stato == DownloadStato.Update);

                _downloads = downloads.ToList();

                if (Activity == null)
                {
                    return;
                }

                Activity.RunOnUiThread(() =>
                {
                    try
                    {
                        EdicolaGridAdapter adapter = (EdicolaGridAdapter)_EdicolaGridView.Adapter;

                        adapter.CheckUpdates(_downloads);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("", ex.Message);
                    }
                });
            });
        }
Ejemplo n.º 3
0
        private void Register()
        {
            //string username = txtUsername.Text;
            string password = _txtPasswd.Text;
            string mail     = _txtUser.Text;

            if (!Regex.Match(mail, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$").Success)
            {
                _lblResult.Text = GetString(Resource.String.log_mail_invalid);
                return;
            }

            if (password.Length < 5)
            {
                _lblResult.Text = GetString(Resource.String.log_passwd_short);
                return;
            }

            Uri host = new Uri(DataManager.Get <ISettingsManager>().Settings.DownloadUrl);

            if (!Reachability.IsHostReachable("http://" + host.Host))
            {
                var alert = new AlertDialog.Builder(Activity);
                alert.SetTitle(GetString(Resource.String.gen_error));
                alert.SetMessage(GetString(Resource.String.gen_serverNotReachable));
                alert.SetPositiveButton("Ok", (EventHandler <DialogClickEventArgs>)null);
                alert.Show().SetDivider();
            }

            var result = Notification.RegisterUser(mail, password);

            if (result["success"].ToLower() == "true")
            {
                DataManager.Get <IPreferencesManager>().Preferences.DownloadUsername = mail;
                DataManager.Get <IPreferencesManager>().Preferences.DownloadPassword = password;
                DataManager.Get <IPreferencesManager>().Save();

                Intent myIntent = new Intent(Activity, typeof(DownloadFragment));
                myIntent.PutExtra("action", "refresh");
                Activity.SetResult(Result.Ok, myIntent);

                var alert = new AlertDialog.Builder(Activity);
                alert.SetMessage(GetString(Resource.String.log_account_created));
                alert.SetPositiveButton("Ok", delegate {
                    Activity.Finish();
                });

                alert.Show();
            }
            else
            {
                int resId = Resources.GetIdentifier(result["errorKey"], "string", Activity.PackageName);

                if (resId == 0)
                {
                    _lblResult.Text = result["errorKey"];
                }
                else
                {
                    _lblResult.Text = GetString(resId);
                }
            }
        }
Ejemplo n.º 4
0
        private bool CheckBeforeConnect()
        {
            Uri host = new Uri(DataManager.Get <ISettingsManager>().Settings.DownloadUrl);

            if (!Reachability.IsHostReachable("http://" + host.Host))
            {
                if (Activity == null)
                {
                    return(false);
                }

                Activity.RunOnUiThread(() =>
                {
                    StopUpdating();

                    var alert = new AlertDialog.Builder(Activity);
                    alert.SetTitle(GetString(Resource.String.gen_error));
                    alert.SetMessage(GetString(Resource.String.gen_serverNotReachable));
                    alert.SetPositiveButton("Ok", (EventHandler <DialogClickEventArgs>)null);
                    alert.Show().SetDivider();
                });
                return(false);
            }

            //se siamo nella cartella principale controllo la compatibilità con la versione dell'app
            var verResult = DownloadManager.CheckAppVersion(2);

            if (!verResult.Success)
            {
                Activity.RunOnUiThread(() =>
                {
                    StopUpdating();
                    var alert = new AlertDialog.Builder(Activity);
                    alert.SetCancelable(false);
                    alert.SetTitle(GetString(Resource.String.gen_error));
                    alert.SetMessage(GetString(Resource.String.gen_appVersion));
                    alert.SetPositiveButton(GetString(Resource.String.gen_downApp), delegate
                    {
                        var callIntent = new Intent(Intent.ActionView);

                        Android.Net.Uri uri = Android.Net.Uri.Parse(verResult.Link);
                        callIntent.SetData(uri);
                        this.StartActivity(callIntent);

                        //va all'edicola
                        var home = Activity as HomeScreen;
                        home.GoTo(0);
                    });

                    alert.SetNegativeButton(GetString(Resource.String.gen_cancel), delegate
                    {
                        //va all'edicola
                        var home = Activity as HomeScreen;
                        home.GoTo(0);
                    });

                    alert.Show().SetDivider();
                });

                this.IsUpdating = false;
                return(false);
            }

            //controllo utente disattivato
            var result = DownloadManager.CheckUser();

            if (!result.Success)
            {
                if (result.ErrBloccante)
                {
                    Activity.RunOnUiThread(() =>
                    {
                        StopUpdating();
                        var alert = new AlertDialog.Builder(Activity);
                        alert.SetTitle(GetString(Resource.String.gen_error));
                        alert.SetMessage(result.Message);
                        alert.SetPositiveButton("Ok", (EventHandler <DialogClickEventArgs>)null);
                        alert.Show().SetDivider();

                        var adapter       = new DownloadGridAdapter(Activity, new List <Object>());
                        _GridView.Adapter = adapter;
                        StopUpdating();
                    });

                    this.IsUpdating = false;
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        private void Initialize()
        {
            //Xamarin.Insights.Initialize(global::InPublishing.XamarinInsights.ApiKey, this);
            AppCenter.Start("cab73ad7-da5e-4ce1-a472-6d48df685f2f", typeof(Analytics), typeof(Crashes));

            //image loader
            var config = new ImageLoaderConfiguration.Builder(ApplicationContext);

            config.ThreadPriority(Java.Lang.Thread.NormPriority - 2);
            config.DenyCacheImageMultipleSizesInMemory();
            config.DiskCacheFileNameGenerator(new Md5FileNameGenerator());
            config.DiskCacheSize(50 * 1024 * 1024); // 50 MiB
            config.TasksProcessingOrder(QueueProcessingType.Lifo);
            config.WriteDebugLogs();                // Remove for release app

            // Initialize ImageLoader with configuration.
            ImageLoader.Instance.Init(config.Build());



            if (!DataManager.AlreadyRegistered <ISettingsManager>())
            {
                DataManager.RegisterReference <ISettingsManager, SettingsManager>();
            }

            DataManager.Get <ISettingsManager>().AndroidGetSettings = p =>
            {
                string content;
                using (StreamReader sr = new StreamReader(Assets.Open("AppSettings.xml")))
                {
                    content = sr.ReadToEnd();
                    return(content);
                }
            };

            DataManager.Get <ISettingsManager>().Load();

            //se è attiva la condivisione setto la cartella nella root
            string sharedPath = "";

            if (DataManager.Get <ISettingsManager>().Settings.ShareDir)
            {
                string appName = ApplicationInfo.LoadLabel(PackageManager);
                sharedPath = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, appName);
            }
            else
            {
                sharedPath = GetExternalFilesDir("shared").AbsolutePath;
            }

            if (this.CanAccessExternal())
            {
                if (!Directory.Exists(sharedPath))
                {
                    Directory.CreateDirectory(sharedPath);
                }
            }

            //cartella per le pubblicazioni nascosta

/*#if DEBUG
 *                      string docPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/.Inpublishing/Publications";
 *                      string notePath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/.Inpublishing/Notes";*/
//#else
            string docPath  = GetExternalFilesDir("publications").AbsolutePath;
            string notePath = GetExternalFilesDir("notes").AbsolutePath;

//#endif

            //Se non esiste la creo
            if (!Directory.Exists(docPath))
            {
                Directory.CreateDirectory(docPath);
            }

            DataManager.Get <ISettingsManager>().Settings.Debug      = true;
            DataManager.Get <ISettingsManager>().Settings.DocPath    = docPath;
            DataManager.Get <ISettingsManager>().Settings.SharedPath = sharedPath;
            DataManager.Get <ISettingsManager>().Settings.NotePath   = notePath;

            DataManager.Get <ISettingsManager>().Settings.AndroidContext = this;

            /*WifiManager manager = Application.Context.GetSystemService (Context.WifiService) as WifiManager;
             * WifiInfo info = manager.ConnectionInfo;
             * string address = info.MacAddress;*///uuid

            ISharedPreferences prefs = GetSharedPreferences(this.PackageName, FileCreationMode.Private);

            string deviceId = prefs.GetString("UniqueDeviceIdentifier", "");

            if (deviceId == "")
            {
                //Guid guid = Guid.NewGuid();
                //deviceId = guid.ToString ();
                deviceId = Android.Provider.Settings.Secure.GetString(ApplicationContext.ContentResolver, Android.Provider.Settings.Secure.AndroidId);
                ISharedPreferencesEditor editor = prefs.Edit();
                editor.PutString("UniqueDeviceIdentifier", deviceId);
                editor.Apply();
            }

            DataManager.Get <ISettingsManager>().Settings.DeviceUID  = deviceId;
            DataManager.Get <ISettingsManager>().Settings.DeviceOS   = DocumentOS.Android;
            DataManager.Get <ISettingsManager>().Settings.DeviceType = Utility.IsTablet(this) ? DocumentDevice.Tablet : DocumentDevice.Phone;

            //statistiche
            DataManager.Get <ISettingsManager>().Settings.StatsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

            FileSystemManager.AndroidCopyFunc = delegate()
            {
                //se è singola e devo importare i documenti elimino quelli presenti
                if (DataManager.Get <ISettingsManager>().Settings.SingolaApp&& Directory.Exists(DataManager.Get <ISettingsManager>().Settings.DocPath))
                {
                    System.IO.DirectoryInfo di = new DirectoryInfo(DataManager.Get <ISettingsManager>().Settings.DocPath);

                    foreach (FileInfo file in di.GetFiles())
                    {
                        file.Delete();
                    }
                    foreach (DirectoryInfo dir in di.GetDirectories())
                    {
                        dir.Delete(true);
                    }
                }

                string       dPath = DataManager.Get <ISettingsManager>().Settings.SharedPath;
                AssetManager am    = Resources.Assets;
                var          files = am.List("pub");
                foreach (string file in files)
                {
                    using (Stream source = Assets.Open("pub/" + file))
                    {
                        if (!File.Exists(Path.Combine(dPath, file)))
                        {
                            using (var dest = System.IO.File.Create(Path.Combine(dPath, file)))
                            {
                                source.CopyTo(dest);
                            }
                        }
                    }
                }
            };

            FileSystemManager.AndroidCountFunc = p =>
            {
                AssetManager am = Resources.Assets;
                return(am.List("pub").Length);
            };

            //preferenze
            if (!DataManager.AlreadyRegistered <IPreferencesManager>())
            {
                DataManager.RegisterReference <IPreferencesManager, PreferencesManager>();
            }

            DataManager.Get <ISettingsManager>().Load();

            //ordinamento
            if (!DataManager.Get <IPreferencesManager>().Preferences.AlreadyRun)
            {
                var order = DataManager.Get <ISettingsManager>().Settings.EdicolaOrder;

                DataManager.Get <IPreferencesManager>().Preferences.EdicolaOrder = order;
                DataManager.Get <IPreferencesManager>().Save();
            }

            //notifiche
            if (CheckPlayServices())
            {
                gcm   = GoogleCloudMessaging.GetInstance(this);
                regid = GetRegistrationId(ApplicationContext);
                //regid = "";
                if (regid == "")
                {
                    //ConnectivityManager connectivityManager = (ConnectivityManager) GetSystemService(ConnectivityService);
                    NetworkStatus internetStatus = Reachability.InternetConnectionStatus();
                    if (internetStatus == NetworkStatus.ReachableViaCarrierDataNetwork || internetStatus == NetworkStatus.ReachableViaWiFiNetwork)
                    {
                        RegisterInBackground();
                    }
                }
                else                 //anche se ho già il token registro comunque il dispositivo sull'edicola, saltando la richiesta del token però
                {
                    Thread _Thread = new Thread(() =>
                    {
                        try
                        {
                            SendRegistrationIdToBackend();
                        }
                        catch (Java.IO.IOException ex)
                        {
                            Log.Info(TAG, ex.Message);
                        }
                    });
                    _Thread.Start();
                }
            }
            else
            {
                Log.Info(TAG, "No valid Google Play Services APK found.");
            }

            //se la versione è diversa setto come se fosse la prima volta che l'app parte
            string version = PackageManager.GetPackageInfo(PackageName, 0).VersionCode.ToString();

            if (DataManager.Get <IPreferencesManager>().Preferences.AppVersion == "" || DataManager.Get <IPreferencesManager>().Preferences.AppVersion != version)
            {
                DataManager.Get <IPreferencesManager>().Preferences.DocImported = false;
            }

            DataManager.Get <IPreferencesManager>().Preferences.AppVersion = version;
            DataManager.Get <IPreferencesManager>().Save();

            if (DataManager.Get <ISettingsManager>().Settings.EdicolaEnabled&& !DataManager.Get <ISettingsManager>().Settings.SingolaApp)
            {
                //var intent = new Intent(this, typeof(EdicolaScreen));
                var intent = new Intent(this, typeof(HomeScreen));
                intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
                StartActivity(intent);
            }
            else
            {
                var intent = new Intent(this, typeof(DownloaderScreen));
                intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
                StartActivity(intent);
            }

            StatisticheManager.SendStats();

            MBDownloadManager.RemoveAll();

            //google analytics
            AnalyticsService.Initialize(this);
            AnalyticsService.SendEvent("App", AnalyticsEventAction.AppStart);

            DataManager.Get <IPreferencesManager>().Preferences.AlreadyRun = true;
            DataManager.Get <IPreferencesManager>().Save();
        }
Ejemplo n.º 6
0
        private void DownloadKML()
        {
            if (Reachability.InternetConnectionStatus() == NetworkStatus.NotReachable)
            {
                return;
            }

            var client = new WebClient();

            client.DownloadDataCompleted += (sender, e) =>
            {
                if (e.Error != null)
                {
                    return;
                }

                try
                {
                    var localKMZ = Utils.md5(_Mappa.Url) + ".zip";
                    var localKML = Utils.md5(_Mappa.Url) + ".kml";
                    var bytes    = e.Result;
                    var tmpPath  = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

                    File.WriteAllBytes(Path.Combine(tmpPath, localKMZ), bytes);

                    FileStream fs = File.OpenRead(Path.Combine(tmpPath, localKMZ));
                    ZipFile    zf = new ZipFile(fs);

                    foreach (ZipEntry zipEntry in zf)
                    {
                        if (zipEntry.IsFile && zipEntry.Name.Contains(".kml"))
                        {
                            using (FileStream streamWriter = File.Create(Path.Combine(tmpPath, localKML)))
                            {
                                byte[] buffer    = new byte[8192];
                                Stream zipStream = zf.GetInputStream(zipEntry);
                                StreamUtils.Copy(zipStream, streamWriter, buffer);
                            }

                            break;
                        }
                    }

                    if (File.Exists(Path.Combine(tmpPath, localKML)))
                    {
                        _XDoc = XDocument.Load(Path.Combine(tmpPath, localKML));

                        RunOnUiThread(() => {
                            LoadPlacemarks();

                            File.Delete(Path.Combine(tmpPath, localKMZ));
                            File.Delete(Path.Combine(tmpPath, localKML));
                        });
                    }

                    RunOnUiThread(() => HideLoadingOverlay());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);

                    RunOnUiThread(() => HideLoadingOverlay());
                }
            };

            client.DownloadDataAsync(new Uri(_Mappa.Url));
        }
Ejemplo n.º 7
0
        private void ShowResetDialog()
        {
            var builder = new AlertDialog.Builder(Activity);

            builder.SetTitle(GetString(Resource.String.set_reset));

            builder.SetView(Activity.LayoutInflater.Inflate(Resource.Layout.ResetPasswordDialog, null));

            builder.SetPositiveButton(GetString(Resource.String.gen_send), (EventHandler <DialogClickEventArgs>)null);
            builder.SetNegativeButton(GetString(Resource.String.gen_cancel), (EventHandler <DialogClickEventArgs>)null);

            builder.SetCancelable(true);

            var dialog = builder.Create();

            dialog.Show();
            dialog.SetDivider();

            EditText    txtMail    = dialog.FindViewById <EditText>(Resource.Id.txtMail);
            TextView    lblSuccess = dialog.FindViewById <TextView>(Resource.Id.lblSuccess);
            ProgressBar prgLogin   = dialog.FindViewById <ProgressBar>(Resource.Id.prgLogin);

            txtMail.Background.Colorize(DataManager.Get <ISettingsManager>().Settings.ButtonColor);

            //se è edicola con password nascondo il campo username

            //pulsante login
            var btnSend = dialog.GetButton((int)DialogButtonType.Positive);

            if (btnSend == null)
            {
                return;
            }

            btnSend.Click += (sender, e) =>
            {
                Activity.RunOnUiThread(() =>
                {
                    lblSuccess.Text       = "";
                    prgLogin.Visibility   = ViewStates.Visible;
                    lblSuccess.Visibility = ViewStates.Gone;
                });

                string url = DataManager.Get <ISettingsManager>().Settings.DownloadUrl;

                if (!Reachability.IsHostReachable("http://" + new Uri(url).Host))
                {
                    var alert = new AlertDialog.Builder(Activity);
                    alert.SetTitle(GetString(Resource.String.gen_error));
                    alert.SetMessage(GetString(Resource.String.gen_serverNotReachable));
                    alert.SetPositiveButton("Ok", (EventHandler <DialogClickEventArgs>)null);
                    alert.Show().SetDivider();

                    return;
                }

                url += "services/edicola_services.php?action=resetPassword&mail=" + txtMail.Text + "&app=" + DataManager.Get <ISettingsManager>().Settings.AppId;

                try
                {
                    XDocument xDoc = XDocument.Load(url);

                    var result = xDoc.Element("root").Element("result");

                    if (XMLUtils.GetBoolValue(result.Attribute("success")))
                    {
                        var alert = new AlertDialog.Builder(Activity);
                        alert.SetTitle(GetString(Resource.String.set_reset));
                        alert.SetMessage(GetString(Resource.String.set_mailPasswd));
                        alert.SetPositiveButton("Ok", delegate {
                            dialog.Dismiss();
                        });
                        alert.Show().SetDivider();
                    }
                    else
                    {
                        switch (XMLUtils.GetIntValue(result.Attribute("code")))
                        {
                        case 1:
                            lblSuccess.Text = GetString(Resource.String.set_mailNotValid);
                            break;

                        case 2:
                            lblSuccess.Text = GetString(Resource.String.set_mailProblem);
                            break;

                        default:
                            break;
                        }

                        lblSuccess.Visibility = ViewStates.Visible;
                        prgLogin.Visibility   = ViewStates.Gone;
                    }
                }
                catch (Exception ex)
                {
                    Log.Info("resetPassword", ex.Message);
                    lblSuccess.Text = GetString(Resource.String.gen_serverNotReachable);
                }
            };
        }
Ejemplo n.º 8
0
        private void ShowLoginDialog()
        {
            var builder = new AlertDialog.Builder(Activity);

            builder.SetTitle(_DownCategory.Title);

            builder.SetView(Activity.LayoutInflater.Inflate(Resource.Layout.LoginDialog, null));

            builder.SetPositiveButton("Login", (EventHandler <DialogClickEventArgs>)null);
            builder.SetNegativeButton(GetString(Resource.String.gen_cancel), (EventHandler <DialogClickEventArgs>)null);

            builder.SetCancelable(true);

            var dialog = builder.Create();

            dialog.Show();
            dialog.SetDivider();

            EditText    txtUser    = dialog.FindViewById <EditText>(Resource.Id.txtUser);      //new EditText(Activity);
            EditText    txtPasswd  = dialog.FindViewById <EditText>(Resource.Id.txtPasswd);    //new EditText(Activity);
            TextView    lblSuccess = dialog.FindViewById <TextView>(Resource.Id.lblSuccess);
            ProgressBar prgLogin   = dialog.FindViewById <ProgressBar>(Resource.Id.prgLogin);

            txtUser.Background.Colorize(DataManager.Get <ISettingsManager>().Settings.ButtonColor);
            txtPasswd.Background.Colorize(DataManager.Get <ISettingsManager>().Settings.ButtonColor);

            //se è edicola con password nasconto il campo username
            if (!DataManager.Get <ISettingsManager>().Settings.DownloadUtenti)
            {
                txtUser.Visibility = ViewStates.Gone;
            }

            //pulsante login
            var btnLogin = dialog.GetButton((int)DialogButtonType.Positive);

            if (btnLogin == null)
            {
                return;
            }

            btnLogin.Click += (sender, e) =>
            {
                Activity.RunOnUiThread(() =>
                {
                    lblSuccess.Text       = "";
                    prgLogin.Visibility   = ViewStates.Visible;
                    lblSuccess.Visibility = ViewStates.Gone;
                });

                Uri host = new Uri(DataManager.Get <ISettingsManager>().Settings.DownloadUrl);
                if (!Reachability.IsHostReachable("http://" + host.Host))
                {
                    var alert = new AlertDialog.Builder(Activity);
                    alert.SetTitle(GetString(Resource.String.gen_error));
                    alert.SetMessage(GetString(Resource.String.gen_serverNotReachable));
                    alert.SetPositiveButton("Ok", (EventHandler <DialogClickEventArgs>)null);
                    alert.Show().SetDivider();

                    return;
                }

                var result = DownloadManager.CheckUser(txtUser.Text, txtPasswd.Text);

                if (result.Success)
                {
                    DataManager.Get <IPreferencesManager>().Preferences.DownloadUsername = txtUser.Text;
                    DataManager.Get <IPreferencesManager>().Preferences.DownloadPassword = txtPasswd.Text;
                    DataManager.Get <IPreferencesManager>().Save();

                    if (DataManager.Get <ISettingsManager>().Settings.DownloadUtenti)
                    {
                        _DownUser.Summary = txtUser.Text;
                    }
                    else if (DataManager.Get <ISettingsManager>().Settings.DownloadPassword)
                    {
                        _DownUser.Summary = GetString(Resource.String.set_logged);
                    }

                    //registro il device
                    Notification notif = new Notification();

                    string pushId = Activity.DevicePushId();

                    var data = Activity.BaseContext.DeviceInfo();
                    data.Add("deviceToken", Activity.DevicePushId());

                    notif.RegisterDevice(data);

                    if ((Preference)this.FindPreference("DownLogout") == null)
                    {
                        _DownCategory.AddPreference(_DownLogout);
                    }

                    if ((Preference)this.FindPreference("DownReset") != null)
                    {
                        _DownCategory.RemovePreference(_DownReset);
                    }

                    dialog.Dismiss();
                }
                else
                {
                    if (result.Message != null && result.Message != "")
                    {
                        _DownUser.Summary = result.Message;
                    }
                    else
                    {
                        _DownUser.Summary = GetString(Resource.String.set_notLogged);
                    }

                    Activity.RunOnUiThread(() =>
                    {
                        if (result.Message != null && result.Message != "")
                        {
                            lblSuccess.Text = result.Message;
                        }
                        else
                        {
                            lblSuccess.Text = GetString(Resource.String.set_loginFailed);
                        }

                        lblSuccess.Visibility = ViewStates.Visible;
                        prgLogin.Visibility   = ViewStates.Gone;
                    });

                    DataManager.Get <IPreferencesManager>().Preferences.DownloadUsername = "";
                    DataManager.Get <IPreferencesManager>().Preferences.DownloadPassword = "";
                    DataManager.Get <IPreferencesManager>().Save();

                    if ((Preference)this.FindPreference("DownLogout") != null)
                    {
                        _DownCategory.RemovePreference(_DownLogout);
                    }

                    if (DataManager.Get <ISettingsManager>().Settings.PasswordReset&& (Preference)this.FindPreference("DownReset") == null)
                    {
                        _DownCategory.AddPreference(_DownReset);
                    }
                }
            };
        }