Пример #1
0
 private void InitShowDialog()
 {
     dialog_ShowBuilder = new AndroidX.AppCompat.App.AlertDialog.Builder(this, Resource.Style.Theme_Dialog_FullScreen);
     dialog_Show        = dialog_ShowBuilder.Create();
     dialog_Show.Show();
     dialog_Show.Dismiss();
 }
Пример #2
0
        private void ShowDialog(string title, string message)
        {
            var alert = new AndroidX.AppCompat.App.AlertDialog.Builder(this);

            alert.SetTitle(title);
            alert.SetMessage(message);
            alert.SetPositiveButton("OK", (s, e) => { });
            alert.Create().Show();
        }
        private async Task LoadRestaurantList()
        {
            var current = Connectivity.NetworkAccess;

            if (current == NetworkAccess.Internet)
            {
                try
                {
                    var result = await restaurantRecommenderPayLoad.RestaurantList();

                    var user_result = await restaurantRecommenderPayLoad.UserList();

                    RunOnUiThread(() =>
                    {
                        progressBar.Visibility = ViewStates.Gone;
                        if (result.Count() > 0 && user_result.Count() > 0)
                        {
                            Intent intent       = new Intent(this, typeof(UserActivity));
                            var restraunt_group = result.GroupBy(x => x.RestaurantType)
                                                  .Select(group => new RestaurantSection(group.Select(x => x.RestaurantName).ToList())
                            {
                                SectionName = group.Key,
                            }).OrderBy(x => x.SectionName).ToList();
                            intent.PutExtra("User_List", JsonConvert.SerializeObject(user_result));
                            intent.PutExtra("Restaurant_List", JsonConvert.SerializeObject(restraunt_group));
                            this.StartActivity(intent);
                        }
                    });
                }
                catch (Exception ex)
                {
                    RunOnUiThread(() =>
                    {
                        AndroidX.AppCompat.App.AlertDialog.Builder dialog = new AndroidX.AppCompat.App.AlertDialog.Builder(this);
                        AndroidX.AppCompat.App.AlertDialog alert          = dialog.Create();
                        alert.SetTitle("Error");
                        alert.SetMessage(ex.Message.ToString());
                        alert.SetCancelable(true);
                        alert.Show();
                    });
                }
            }
            else
            {
                RunOnUiThread(() =>
                {
                    AndroidX.AppCompat.App.AlertDialog.Builder dialog = new AndroidX.AppCompat.App.AlertDialog.Builder(this);
                    AndroidX.AppCompat.App.AlertDialog alert          = dialog.Create();
                    alert.SetTitle("Error");
                    alert.SetMessage("Please connect to the internet");
                    alert.SetCancelable(true);
                    alert.Show();
                });
            }
        }
Пример #4
0
        private async Task CheckUpdate()
        {
            await Task.Delay(100);

            bool isMissing = false;

            try
            {
                isMissing = CheckImage();

                if (!isMissing)
                {
                    using (WebClient wc = new WebClient())
                    {
                        string LocalVerPath = Path.Combine(ETC.systemPath, "ShortGuideVer.txt");

                        if (!File.Exists(LocalVerPath))
                        {
                            hasUpdate = true;
                        }
                        else
                        {
                            int serverVer = int.Parse(await wc.DownloadStringTaskAsync(Path.Combine(ETC.server, "ShortGuideVer.txt")));
                            int localVer  = 0;

                            using (StreamReader sr = new StreamReader(new FileStream(LocalVerPath, FileMode.Open, FileAccess.Read)))
                            {
                                localVer = int.Parse(sr.ReadToEnd());
                            }

                            hasUpdate = localVer < serverVer;
                        }
                    }
                }

                if (hasUpdate || isMissing)
                {
                    var builder = new AndroidX.AppCompat.App.AlertDialog.Builder(Activity);
                    builder.SetTitle(Resource.String.UpdateDialog_Title);
                    builder.SetMessage(Resource.String.UpdateDialog_Message);
                    builder.SetCancelable(true);
                    builder.SetPositiveButton(Resource.String.AlertDialog_Confirm, async delegate { await DownloadShortGuideImage(); });
                    builder.SetNegativeButton(Resource.String.AlertDialog_Cancel, delegate { });

                    var dialog = builder.Create();
                    dialog.Show();
                }
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, Activity);
                ETC.ShowSnackbar(snackbarLayoutF, Resource.String.UpdateCheck_Fail, Snackbar.LengthLong, Android.Graphics.Color.DarkRed);
            }
        }
Пример #5
0
        private void Pickwallpaper_Click(object sender, EventArgs e)
        {
            var button = sender as Button;

            using (AndroidX.AppCompat.App.AlertDialog.Builder builder = new AndroidX.AppCompat.App.AlertDialog.Builder(button.Context))
            {
                int currentwallpapersetted = int.Parse(configurationManager.RetrieveAValue(ConfigurationParameters.ChangeWallpaper, "0"));
                builder.SetTitle(Resources.GetString(Resource.String.changewallpaper));
                builder.SetSingleChoiceItems(new string[] { button.Context.GetString(Resource.String.blackwallpaper), button.Context.GetString(Resource.String.defaultwallpaper), button.Context.GetString(Resource.String.pickwallpaper) }, currentwallpapersetted, OnDialogClickEventArgs);
                builder.Create();
                builder.Show();
            }
        }
Пример #6
0
        protected void ShowSingleChoseDialog(string[] items, Action <int> chosePosition, bool isCanCancel = true, bool isOutSideTouch = true)
        {
            var builder = new AndroidX.AppCompat.App.AlertDialog.Builder(this, Android.Resource.Style.ThemeDeviceDefaultLightDialogNoActionBarMinWidth);

            builder.SetItems(items, (object sender, DialogClickEventArgs e) =>
            {
                chosePosition?.Invoke(e.Which);
            });
            var dialog_Show = builder.Create();

            dialog_Show.SetCancelable(isCanCancel);
            dialog_Show.SetCanceledOnTouchOutside(isOutSideTouch);
            dialog_Show.Show();
        }
Пример #7
0
        private async Task LoadVisitedRestaurant(int id)
        {
            var current = Connectivity.NetworkAccess;

            if (current == NetworkAccess.Internet)
            {
                try
                {
                    restaurantItemModel = await restaurantRecommenderPayLoad.Restaurants_Visited_By_User(id);

                    if (restaurantItemModel.Count() > 0)
                    {
                        Activity.RunOnUiThread(() =>
                        {
                            restaurantlayoutManager = new LinearLayoutManager(restaurant_recyclerView.Context);
                            restaurant_recyclerView.SetLayoutManager(restaurantlayoutManager);
                            restaurantrecommendationAdapter = new VisitedRestaurantListAdapter(restaurantItemModel);
                            restaurant_recyclerView.SetAdapter(restaurantrecommendationAdapter);
                        });
                    }
                }
                catch (Exception ex)
                {
                    Activity.RunOnUiThread(() =>
                    {
                        AndroidX.AppCompat.App.AlertDialog.Builder dialog = new AndroidX.AppCompat.App.AlertDialog.Builder(Context);
                        AndroidX.AppCompat.App.AlertDialog alert          = dialog.Create();
                        alert.SetTitle("Error");
                        alert.SetMessage(ex.Message.ToString());
                        alert.SetCancelable(true);
                        alert.Show();
                    });
                }
            }
            else
            {
                Activity.RunOnUiThread(() =>
                {
                    AndroidX.AppCompat.App.AlertDialog.Builder dialog = new AndroidX.AppCompat.App.AlertDialog.Builder(Context);
                    AndroidX.AppCompat.App.AlertDialog alert          = dialog.Create();
                    alert.SetTitle("Error");
                    alert.SetMessage("Please connect to the internet");
                    alert.SetCancelable(true);
                    alert.Show();
                });
            }
        }
Пример #8
0
        internal async Task DownloadGFDImage()
        {
            View v = LayoutInflater.Inflate(Resource.Layout.ProgressDialogLayout, null);

            ProgressBar totalProgressBar = v.FindViewById <ProgressBar>(Resource.Id.TotalProgressBar);
            TextView    totalProgress    = v.FindViewById <TextView>(Resource.Id.TotalProgressPercentage);
            ProgressBar nowProgressBar   = v.FindViewById <ProgressBar>(Resource.Id.NowProgressBar);
            TextView    nowProgress      = v.FindViewById <TextView>(Resource.Id.NowProgressPercentage);

            var builder = new AndroidX.AppCompat.App.AlertDialog.Builder(Activity, ETC.dialogBGDownload);

            builder.SetTitle(Resource.String.UpdateDownloadDialog_Title);
            builder.SetView(v);
            builder.SetCancelable(false);

            Dialog dialog = builder.Create();

            dialog.Show();

            await Task.Delay(100);

            try
            {
                totalProgressBar.Max      = imageName.Length;
                totalProgressBar.Progress = 0;

                using (WebClient wc = new WebClient())
                {
                    wc.DownloadFileCompleted += (object sender, System.ComponentModel.AsyncCompletedEventArgs e) =>
                    {
                        totalProgressBar.Progress += 1;
                        totalProgress.Text         = $"{totalProgressBar.Progress} / {totalProgressBar.Max}";
                    };
                    wc.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) =>
                    {
                        nowProgressBar.Progress = e.ProgressPercentage;
                        nowProgress.Text        = $"{e.BytesReceived / 1024}KB";
                    };

                    foreach (string s in imageName)
                    {
                        string url    = Path.Combine(ETC.server, "Data", "Images", "OldGFD", "Images", lang, $"{s}.png");
                        string target = Path.Combine(ETC.cachePath, "OldGFD", "Images", $"{lang}_{s}.gfdcache");

                        await wc.DownloadFileTaskAsync(url, target);
                    }

                    wc.DownloadFile(Path.Combine(ETC.server, "OldGFDVer.txt"), Path.Combine(ETC.systemPath, "OldGFDVer.txt"));
                }

                ETC.ShowSnackbar(snackbarLayout_F, Resource.String.UpdateDownload_Complete, Snackbar.LengthLong, Android.Graphics.Color.DarkOliveGreen);
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, Activity);
                ETC.ShowSnackbar(snackbarLayout_F, Resource.String.UpdateDownload_Fail, Snackbar.LengthLong, Android.Graphics.Color.DarkRed);
            }
            finally
            {
                dialog.Dismiss();
            }

            await Task.Delay(100);
        }
Пример #9
0
        private async Task PVDownload(string pvName, int position)
        {
            Dialog dialog = null;

            try
            {
                ProgressBar nowProgressBar;
                TextView    nowProgress;

                View v = LayoutInflater.Inflate(Resource.Layout.ProgressDialogLayout, null);

                v.FindViewById <TextView>(Resource.Id.ProgressStatusMessage).SetText(Resource.String.GFPVActivity_DownloadDialog_Message);
                v.FindViewById <TextView>(Resource.Id.ProgressNowFile).Text = pvName;
                v.FindViewById <LinearLayout>(Resource.Id.TotalProgressLayout).Visibility = ViewStates.Gone;

                nowProgressBar = v.FindViewById <ProgressBar>(Resource.Id.NowProgressBar);
                nowProgress    = v.FindViewById <TextView>(Resource.Id.NowProgressPercentage);

                var pd = new AndroidX.AppCompat.App.AlertDialog.Builder(this, ETC.dialogBGDownload);
                pd.SetTitle(Resource.String.GFPVActivity_DownloadDialog_Title);
                pd.SetCancelable(false);
                pd.SetView(v);

                dialog = pd.Create();
                dialog.Show();

                string localPath  = Path.Combine(pvPath, $"{pvName}.mp4");
                string serverPath = Path.Combine(ETC.server, "Data", "Video", "PV", $"{pvName}.mp4");

                using (var wc = new WebClient())
                {
                    wc.DownloadProgressChanged += (sender, e) =>
                    {
                        MainThread.BeginInvokeOnMainThread(() =>
                        {
                            nowProgressBar.Progress = e.ProgressPercentage;
                            nowProgress.Text        = $"{e.ProgressPercentage}%";
                        });
                    };
                    wc.DownloadFileCompleted += (sender, e) =>
                    {
                        MainThread.BeginInvokeOnMainThread(() =>
                        {
                            nowProgressBar.Progress = 100;
                            nowProgress.Text        = "100%";
                        });
                    };

                    await wc.DownloadFileTaskAsync(serverPath, localPath);
                }

                await Task.Delay(500);

                recyclerView.GetAdapter().NotifyItemChanged(position);
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, this);
            }
            finally
            {
                dialog?.Dismiss();
            }
        }
Пример #10
0
        private async Task CropImageDownloadProcess <T>(List <T> downloadList, string serverPath, string targetPath)
        {
            Dialog      dialog;
            ProgressBar totalProgressBar;
            ProgressBar nowProgressBar;
            TextView    totalProgress;
            TextView    nowProgress;

            var v = LayoutInflater.Inflate(Resource.Layout.ProgressDialogLayout, null);

            int pNow   = 0;
            int pTotal = 0;

            var pd = new AndroidX.AppCompat.App.AlertDialog.Builder(this, ETC.dialogBGDownload);

            pd.SetTitle(Resource.String.DBList_DownloadCropImageTitle);
            pd.SetCancelable(false);
            pd.SetView(v);

            dialog = pd.Create();
            dialog.Show();

            try
            {
                totalProgressBar = v.FindViewById <ProgressBar>(Resource.Id.TotalProgressBar);
                totalProgress    = v.FindViewById <TextView>(Resource.Id.TotalProgressPercentage);
                nowProgressBar   = v.FindViewById <ProgressBar>(Resource.Id.NowProgressBar);
                nowProgress      = v.FindViewById <TextView>(Resource.Id.NowProgressPercentage);

                pTotal = downloadList.Count;
                totalProgressBar.Max      = 100;
                totalProgressBar.Progress = pNow;

                using (var wc = new WebClient())
                {
                    wc.DownloadProgressChanged += (sender, e) =>
                    {
                        nowProgressBar.Progress = e.ProgressPercentage;

                        MainThread.BeginInvokeOnMainThread(() => { nowProgress.Text = $"{e.ProgressPercentage}%"; });
                    };
                    wc.DownloadFileCompleted += (sender, e) =>
                    {
                        pNow += 1;
                        totalProgressBar.Progress = Convert.ToInt32((pNow / Convert.ToDouble(pTotal)) * 100);

                        MainThread.BeginInvokeOnMainThread(() => { totalProgress.Text = $"{totalProgressBar.Progress}%"; });
                    };

                    for (int i = 0; i < pTotal; ++i)
                    {
                        string url    = Path.Combine(serverPath, $"{downloadList[i]}.png");
                        string target = Path.Combine(targetPath, $"{downloadList[i]}.gfdcache");

                        await wc.DownloadFileTaskAsync(url, target);
                    }
                }

                ETC.ShowSnackbar(snackbarLayout, Resource.String.DBList_DownloadCropImageComplete, Snackbar.LengthLong, Android.Graphics.Color.DarkOliveGreen);

                await Task.Delay(500);

                _ = ListItem();
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, this);
                ETC.ShowSnackbar(snackbarLayout, Resource.String.DBList_DownloadCropImageFail, Snackbar.LengthShort, Android.Graphics.Color.DeepPink);
            }
            finally
            {
                dialog.Dismiss();
            }
        }
Пример #11
0
        internal static async Task UpdateDB(Activity activity, bool dbLoad = false, int titleMsg = Resource.String.CheckDBUpdateDialog_Title, int messageMgs = Resource.String.CheckDBUpdateDialog_Message)
        {
            Dialog dialog;
            View   v = activity.LayoutInflater.Inflate(Resource.Layout.ProgressDialogLayout, null);

            TextView    status           = v.FindViewById <TextView>(Resource.Id.ProgressStatusMessage);
            ProgressBar totalProgressBar = v.FindViewById <ProgressBar>(Resource.Id.TotalProgressBar);
            TextView    totalProgress    = v.FindViewById <TextView>(Resource.Id.TotalProgressPercentage);
            ProgressBar nowProgressBar   = v.FindViewById <ProgressBar>(Resource.Id.NowProgressBar);
            TextView    nowProgress      = v.FindViewById <TextView>(Resource.Id.NowProgressPercentage);

            var pd = new AndroidX.AppCompat.App.AlertDialog.Builder(activity, dialogBGDownload);

            pd.SetTitle(titleMsg);
            pd.SetMessage(Resources.GetString(messageMgs));
            pd.SetView(v);
            pd.SetCancelable(false);

            dialog = pd.Create();
            dialog.Show();

            await Task.Delay(100);

            try
            {
                totalProgressBar.Max      = dbFiles.Length;
                totalProgressBar.Progress = 0;

                using (WebClient wc = new WebClient())
                {
                    wc.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) =>
                    {
                        nowProgressBar.Progress = e.ProgressPercentage;
                        nowProgress.Text        = (e.BytesReceived > 2048) ? $"{e.BytesReceived / 1024}KB" : $"{e.BytesReceived}B";
                    };
                    wc.DownloadFileCompleted += (object sender, System.ComponentModel.AsyncCompletedEventArgs e) =>
                    {
                        totalProgressBar.Progress += 1;
                        totalProgress.Text         = $"{totalProgressBar.Progress} / {totalProgressBar.Max}";
                    };

                    for (int i = 0; i < dbFiles.Length; ++i)
                    {
                        await wc.DownloadFileTaskAsync(Path.Combine(server, "Data", "DB", dbFiles[i]), Path.Combine(tempPath, dbFiles[i]));
                    }

                    await wc.DownloadFileTaskAsync(Path.Combine(server, "DBVer.txt"), Path.Combine(tempPath, "DBVer.txt"));

                    await Task.Delay(100);
                }

                for (int i = 0; i < dbFiles.Length; ++i)
                {
                    //File.Copy(Path.Combine(tempPath, DBFiles[i]), Path.Combine(DBPath, DBFiles[i]), true);
                    CopyFile(Path.Combine(tempPath, dbFiles[i]), Path.Combine(dbPath, dbFiles[i]));

                    await Task.Delay(100);
                }

                await Task.Delay(500);

                activity.RunOnUiThread(() => { status.Text = Resources.GetString(Resource.String.UpdateDBDialog_RefreshVersionMessage); });

                string oldVersion = Path.Combine(systemPath, "DBVer.txt");
                string newVersion = Path.Combine(tempPath, "DBVer.txt");

                //File.Copy(newVersion, oldVersion, true);
                CopyFile(newVersion, oldVersion);

                using (StreamReader sr = new StreamReader(new FileStream(oldVersion, FileMode.Open, FileAccess.Read)))
                {
                    _ = int.TryParse(sr.ReadToEnd(), out dbVersion);
                }

                await Task.Delay(500);

                if (dbLoad)
                {
                    activity.RunOnUiThread(() => { status.Text = Resources.GetString(Resource.String.UpdateDBDialog_LoadDB); });

                    await Task.Delay(100);
                    await LoadDB();
                }
            }
            catch (Exception ex)
            {
                LogError(ex, activity);
            }
            finally
            {
                dialog.Dismiss();
            }
        }
Пример #12
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);

                Xamarin.Essentials.Platform.Init(this, savedInstanceState);

                SetContentView(Resource.Layout.content_main);

                #region Fragment navigation

                BottomNavigationView navigation = FindViewById <BottomNavigationView>(Resource.Id.navigation);
                navigation?.SetOnNavigationItemSelectedListener(this);

                SupportFragmentManager.BeginTransaction()
                .Replace(Resource.Id.content_frame, new HomeFragment())
                .Commit();

                #endregion

                #region Settings

                settings = Settings.Instance;

                #endregion

                #region App Center Crash (http: // appcenter.ms )

                if (settings.IsSendCrashes == true)
                {
                    AppCenter.Start(AppCenterId, new Type[] { typeof(Crashes) });

                    Crashes.SendingErrorReport += (sender, e) => CrashesSendingErrorReport(sender, e);

                    Crashes.ShouldAwaitUserConfirmation = () =>
                    {
                        AndroidX.AppCompat.App.AlertDialog.Builder alert = new AndroidX.AppCompat.App.AlertDialog.Builder(Platform.CurrentActivity);
                        alert.SetTitle("Confirm send");
                        alert.SetMessage("Send anonymous data about crashes in the app?");

                        alert.SetPositiveButton("Send", (senderAlert, args) =>
                        {
                            UserConfirmationDialog(UserConfirmation.Send);

                            Toast.MakeText(context, "Send", ToastLength.Short).Show();
                        });

                        alert.SetNegativeButton("Cancel", (senderAlert, args) =>
                        {
                            UserConfirmationDialog(UserConfirmation.DontSend);

                            Toast.MakeText(context, "Not Send", ToastLength.Short).Show();
                        });

                        Dialog dialog = alert.Create();
                        dialog.Show();

                        return(true);
                    };
                }

                #endregion

                if (settings.IsLogErrorStorage == true)
                {
                    Task.Run(() => PermissionsCheckRun());
                }
            }
            catch (Exception ex)
            {
                #region Logging
                LogRuntimeAttribute.InLogFiles(typeof(MainActivity), ex);
                #endregion
            }
        }
Пример #13
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.baggagedistribution_fragment, container, false);

            view.FindViewById <TextView>(Resource.Id.totalBaggageLoadMassUnitTextView).Text = _massUnit;
            _picesRemainingCounterTextView = view.FindViewById <TextView>(Resource.Id.picesRemainingCounterTextView);
            _hold1LoadTextView             = view.FindViewById <TextView>(Resource.Id.hold1LoadTextView);
            _hold2LoadTextView             = view.FindViewById <TextView>(Resource.Id.hold2LoadTextView);
            _hold3LoadTextView             = view.FindViewById <TextView>(Resource.Id.hold3LoadTextView);
            _hold4LoadTextView             = view.FindViewById <TextView>(Resource.Id.hold4LoadTextView);
            view.FindViewById <TextView>(Resource.Id.hold1MassUnitTextView).Text = _massUnit;
            view.FindViewById <TextView>(Resource.Id.hold2MassUnitTextView).Text = _massUnit;
            view.FindViewById <TextView>(Resource.Id.hold3MassUnitTextView).Text = _massUnit;
            view.FindViewById <TextView>(Resource.Id.hold4MassUnitTextView).Text = _massUnit;
            _totalBaggageLoadEditText  = view.FindViewById <EditText>(Resource.Id.totalBaggageLoadEditText);
            _totalBaggagePicesEditText = view.FindViewById <EditText>(Resource.Id.totalBaggagePicesEditText);
            _hold1EditText             = view.FindViewById <EditText>(Resource.Id.hold1EditText);
            _hold2EditText             = view.FindViewById <EditText>(Resource.Id.hold2EditText);
            _hold3EditText             = view.FindViewById <EditText>(Resource.Id.hold3EditText);
            _hold4EditText             = view.FindViewById <EditText>(Resource.Id.hold4EditText);

            _totalBaggageLoadEditText.Text  = _settingsService.GetSetting <string>("TotalBaggageLoad");
            _totalBaggagePicesEditText.Text = _settingsService.GetSetting <string>("TotalBaggagePices");
            _hold1EditText.Text             = _settingsService.GetSetting <string>("Hold1Pices");
            _hold2EditText.Text             = _settingsService.GetSetting <string>("Hold2Pices");
            _hold3EditText.Text             = _settingsService.GetSetting <string>("Hold3Pices");
            _hold4EditText.Text             = _settingsService.GetSetting <string>("Hold4Pices");
            _baggageDistributionService.CalculateBaggageDistribution(_totalBaggageLoadEditText.Text, _totalBaggagePicesEditText.Text, _hold1EditText.Text, _hold2EditText.Text, _hold3EditText.Text, _hold4EditText.Text);
            SetValues();

            _totalBaggageLoadEditText.TextChanged += (s, e) =>
            {
                _baggageDistributionService.CalculateBaggageDistribution(_totalBaggageLoadEditText.Text, _totalBaggagePicesEditText.Text, _hold1EditText.Text, _hold2EditText.Text, _hold3EditText.Text, _hold4EditText.Text);
                SetValues();
                _settingsService.SaveSetting("TotalBaggageLoad", e.Text.ToString());
            };
            _totalBaggagePicesEditText.TextChanged += (s, e) =>
            {
                _baggageDistributionService.CalculateBaggageDistribution(_totalBaggageLoadEditText.Text, _totalBaggagePicesEditText.Text, _hold1EditText.Text, _hold2EditText.Text, _hold3EditText.Text, _hold4EditText.Text);
                SetValues();
                _settingsService.SaveSetting("TotalBaggagePices", e.Text.ToString());
            };
            _hold1EditText.TextChanged += (s, e) =>
            {
                _baggageDistributionService.CalculateBaggageDistribution(_totalBaggageLoadEditText.Text, _totalBaggagePicesEditText.Text, _hold1EditText.Text, _hold2EditText.Text, _hold3EditText.Text, _hold4EditText.Text);
                SetValues();
                _settingsService.SaveSetting("Hold1Pices", e.Text.ToString());
            };
            _hold2EditText.TextChanged += (s, e) =>
            {
                _baggageDistributionService.CalculateBaggageDistribution(_totalBaggageLoadEditText.Text, _totalBaggagePicesEditText.Text, _hold1EditText.Text, _hold2EditText.Text, _hold3EditText.Text, _hold4EditText.Text);
                SetValues();
                _settingsService.SaveSetting("Hold2Pices", e.Text.ToString());
            };
            _hold3EditText.TextChanged += (s, e) =>
            {
                _baggageDistributionService.CalculateBaggageDistribution(_totalBaggageLoadEditText.Text, _totalBaggagePicesEditText.Text, _hold1EditText.Text, _hold2EditText.Text, _hold3EditText.Text, _hold4EditText.Text);
                SetValues();
                _settingsService.SaveSetting("Hold3Pices", e.Text.ToString());
            };
            _hold4EditText.TextChanged += (s, e) =>
            {
                _baggageDistributionService.CalculateBaggageDistribution(_totalBaggageLoadEditText.Text, _totalBaggagePicesEditText.Text, _hold1EditText.Text, _hold2EditText.Text, _hold3EditText.Text, _hold4EditText.Text);
                SetValues();
                _settingsService.SaveSetting("Hold4Pices", e.Text.ToString());
            };

            view.FindViewById <Button>(Resource.Id.clearBaggageDistributionButton).Click += (s, e) =>
            {
                view.PerformHapticFeedback(FeedbackConstants.VirtualKey, FeedbackFlags.IgnoreGlobalSetting);
                _picesRemainingCounterTextView.Text = "0";
                _hold1LoadTextView.Text             = "0";
                _hold2LoadTextView.Text             = "0";
                _hold3LoadTextView.Text             = "0";
                _hold4LoadTextView.Text             = "0";
                _totalBaggageLoadEditText.Text      = "";
                _totalBaggagePicesEditText.Text     = "";
                _hold1EditText.Text = "";
                _hold2EditText.Text = "";
                _hold3EditText.Text = "";
                _hold4EditText.Text = "";
            };

            _baggageDistributionService.ErrorMessageEvent += (s, e) =>
            {
                AndroidX.AppCompat.App.AlertDialog.Builder alertDialogBuilder = new AndroidX.AppCompat.App.AlertDialog.Builder(Context);
                AndroidX.AppCompat.App.AlertDialog         alertDialog        = alertDialogBuilder.Create();
                alertDialog.SetTitle("Error");
                alertDialog.SetIcon(Resource.Drawable.ic_stat_error_outline);
                alertDialog.SetMessage((e as ErrorMessageEventArgs).ErrorMessage);
                alertDialog.SetButton((int)DialogButtonType.Positive, "OK", (sender, eventArgs) => { });
                alertDialog.Show();
            };
            return(view);
        }
Пример #14
0
        private async Task UpdateEvent()
        {
            View v = LayoutInflater.Inflate(Resource.Layout.ProgressDialogLayout, null);

            ProgressBar totalProgressBar = v.FindViewById <ProgressBar>(Resource.Id.TotalProgressBar);
            TextView    totalProgress    = v.FindViewById <TextView>(Resource.Id.TotalProgressPercentage);
            ProgressBar nowProgressBar   = v.FindViewById <ProgressBar>(Resource.Id.NowProgressBar);
            TextView    nowProgress      = v.FindViewById <TextView>(Resource.Id.NowProgressPercentage);

            var pd = new AndroidX.AppCompat.App.AlertDialog.Builder(this, ETC.dialogBGDownload);

            pd.SetTitle(Resource.String.UpdateEventDialog_Title);
            pd.SetMessage(Resources.GetString(Resource.String.UpdateEventDialog_Message));
            pd.SetView(v);
            pd.SetCancelable(false);

            Dialog dialog = pd.Create();

            dialog.Show();

            await Task.Delay(100);

            try
            {
                nowProgressBar.Indeterminate   = true;
                totalProgressBar.Indeterminate = true;

                if (!Directory.Exists(ETC.tempPath))
                {
                    Directory.CreateDirectory(ETC.tempPath);
                }
                if (!Directory.Exists(Path.Combine(ETC.cachePath, "Event", "Images")))
                {
                    Directory.CreateDirectory(Path.Combine(ETC.cachePath, "Event", "Images"));
                }

                using (WebClient wc = new WebClient())
                {
                    string url    = Path.Combine(ETC.server, "EventVer.txt");
                    string target = Path.Combine(ETC.tempPath, "EventVer.txt");

                    await wc.DownloadFileTaskAsync(url, target);

                    await Task.Delay(500);

                    nowProgressBar.Indeterminate   = false;
                    totalProgressBar.Indeterminate = false;
                    totalProgressBar.Progress      = 0;

                    wc.DownloadProgressChanged += (sender, e) =>
                    {
                        nowProgressBar.Progress = e.ProgressPercentage;
                        nowProgress.Text        = e.BytesReceived > 2048 ? $"{e.BytesReceived / 1024}KB" : $"{e.BytesReceived}B";
                    };
                    wc.DownloadFileCompleted += (sender, e) =>
                    {
                        totalProgressBar.Progress += 1;
                        totalProgress.Text         = $"{totalProgressBar.Progress} / {totalProgressBar.Max}";
                    };

                    int totalCount = 0;

                    using (StreamReader sr = new StreamReader(new FileStream(Path.Combine(ETC.tempPath, "EventVer.txt"), FileMode.Open, FileAccess.Read)))
                    {
                        totalCount += int.Parse(sr.ReadToEnd().Split(';')[2]);
                    }

                    totalProgressBar.Max = totalCount;

                    for (int i = 1; i <= totalCount; ++i)
                    {
                        string url2    = Path.Combine(ETC.server, "Data", "Images", "Events", "Event_" + i + ".png");
                        string target2 = Path.Combine(ETC.cachePath, "Event", "Images", "Event_" + i + ".png");

                        await wc.DownloadFileTaskAsync(url2, target2);

                        await Task.Delay(100);
                    }

                    await Task.Delay(500);

                    RunOnUiThread(() => { pd.SetMessage(Resources.GetString(Resource.String.UpdateEventDialog_RefreshVersionMessage)); });

                    string oldVersion = Path.Combine(ETC.cachePath, "Event", "EventVer.txt");
                    string newVersion = Path.Combine(ETC.tempPath, "EventVer.txt");

                    ETC.CopyFile(newVersion, oldVersion);

                    await Task.Delay(1000);
                }
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, this);
            }
            finally
            {
                dialog.Dismiss();
            }
        }