예제 #1
0
 // Simulates background work that happens behind the splash screen
 private void SimulateStartup()
 {
     if (!CheckIsDownload() || !File.Exists(System.IO.Path.Combine(_DownloadDirectoryPath, Constants.DATABASE_FILE_NAME)))
     {
         if (Controller.Permission.CheckPermission.PermissionGranted(ApplicationContext, Manifest.Permission.WriteExternalStorage))
         {
             //save temporary file
             _Downloader.OnFileDownloaded += OnFileDownloaded;
             // Use the configuration value
             _Downloader.DownloadFile(ConfigInstance.GetInstance().DatabaseUrl, _DownloadDirectoryPath, Constants.DATABASE_FILE_NAME);
             _Downloader.DownloadFile(ConfigInstance.GetInstance().ImageUrl, _DownloadDirectoryPath, Constants.IMG_FILE_NAME);
         }
         else
         {
             Android.Support.V4.App.ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.WriteExternalStorage }, 5);
             OnResume();
         }
     }
     else
     {
         Log.Debug("Download", "Database already save");
         DataManager.GetInstance(ConfigInstance.GetInstance().IsDev, SharedPreferenceManager.GetString(ApplicationContext, Constants.SHARED_DATABASE_PATH, ""));
         HideProgressBar();
         StartActivity(typeof(HomeActivity));
         Finish();
     }
 }
예제 #2
0
        private void OnFileDownloaded(object sender, DownloadEventArgs e)
        {
            if (e.FileSaved)
            {
                Log.Debug("Download", "File have been downloaded with success");
                _NbFileDownloaded++;
                if (_NbFileDownloaded == 2)
                {
                    SharedPreferenceManager.SaveString(ApplicationContext, Constants.DATE_DOWNLAOD, DateTime.Now.ToString());
                    SharedPreferenceManager.SaveString(ApplicationContext, Constants.SHARED_DATABASE_PATH, System.IO.Path.Combine(_DownloadDirectoryPath, Constants.DATABASE_FILE_NAME));

                    if (Controller.Permission.CheckPermission.PermissionGranted(ApplicationContext, Manifest.Permission.ReadExternalStorage))
                    {
                        DataManager.GetInstance(ConfigInstance.GetInstance().IsDev, SharedPreferenceManager.GetString(ApplicationContext, Constants.SHARED_DATABASE_PATH, ""));
                        string pathZipFile = System.IO.Path.Combine(_DownloadDirectoryPath, Constants.IMG_FILE_NAME);
                        ZipManager.Unzip(pathZipFile, _ImgDirectoryPath);
                    }
                    else
                    {
                        Toast.MakeText(ApplicationContext, "Permission non accordée pour la lecture du fichier, aller dans les paramètres de l'application pour modifier cette valeur.", ToastLength.Long).Show();
                    }

                    //delete temporary file after get values
                    File.Delete(System.IO.Path.Combine(_DownloadDirectoryPath, Constants.IMG_FILE_NAME));
                    HideProgressBar();
                    StartActivity(typeof(HomeActivity));
                    Finish();
                }
            }
            else
            {
                Log.Error("Download", "Error while saving the file");
            }
        }
예제 #3
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.settings, container, false);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
            {
                ((AppCompatActivity)Activity).SupportActionBar.Subtitle = Constants.PAGE_SETTING;
            }
            else
            {
                TextView TitleLabel = view.FindViewById <TextView>(Resource.Id.TitleSetting);
                TitleLabel.SetText(Constants.PAGE_SETTING, TextView.BufferType.Normal);
                TitleLabel.Visibility = ViewStates.Invisible;
            }

            Spinner spRefreshData = view.FindViewById <Spinner>(Resource.Id.cbSettingsReload);

            spRefreshData.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
            var adapter = ArrayAdapter.CreateFromResource(this.Activity, Resource.Array.refresh_mode, Android.Resource.Layout.SimpleSpinnerItem);

            adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            spRefreshData.Adapter = adapter;

            string refreshMode = SharedPreferenceManager.GetString(this.Activity, Constants.REFRESH_MODE_PREFERENCES);

            if (!string.IsNullOrEmpty(refreshMode))
            {
                int spinnerPosition = adapter.GetPosition(refreshMode);
                spRefreshData.SetSelection(spinnerPosition);
            }

            return(view);
        }
예제 #4
0
        private bool CheckIsDownload()
        {
            string date      = SharedPreferenceManager.GetString(ApplicationContext, Constants.DATE_DOWNLAOD, "");
            string parameter = SharedPreferenceManager.GetString(ApplicationContext, Constants.REFRESH_MODE_PREFERENCES, "");

            switch (parameter)
            {
            case "Tous les jours":
                return(date != "" || Convert.ToDateTime(date) >= DateTime.Now.AddDays(-1));

            case "A chaque démarrage":
                return(false);

            case "Toutes les semaines":
                return(date != "" || Convert.ToDateTime(date) >= DateTime.Now.AddDays(-7));;

            default:
                return(date != "" || Convert.ToDateTime(date) >= DateTime.Now.AddDays(-1));
            }
        }