Exemple #1
0
        public ResinTimerPage()
        {
            InitializeComponent();

            BindingContext = this;

            REnv.OneCountTime   = new();
            REnv.TotalCountTime = new();

            REnv.LoadValues();

            if (Device.RuntimePlatform is not Device.UWP)
            {
                _buttonPressTimer = new(500)
                {
                    AutoReset = false
                };
                _buttonPressTimer.Elapsed += delegate
                {
                    _isRunQuickCalc = true;

                    if (Preferences.Get(SettingConstants.QUICKCALC_VIBRATION, true))
                    {
                        Vibration.Vibrate(100);
                    }

                    QuickCalc();
                };
            }

            if (REnv.IsSyncEnabled)
            {
                _ = SyncData();
            }
        }
Exemple #2
0
        private void QuickCalc()
        {
            DateTime now = DateTime.Now;

            REnv.LastInputTime = now.ToString(AppEnv.DTCulture);

            if (REnv.EndTime < now)
            {
                REnv.EndTime = now;
            }

            if (_isQuickOTCalc)
            {
                REnv.EndTime = REnv.EndTime.AddSeconds(
                    REnv.OneRestoreInterval * (REnv.Resin / _quickOTCalcValue) * _quickOTCalcValue);

                _isQuickOTCalc = false;
            }
            else
            {
                REnv.EndTime = ((REnv.Resin - _quickCalcValue) < 0) ?
                               now.AddSeconds(REnv.OneRestoreInterval * REnv.MaxResin) :
                               REnv.EndTime.AddSeconds(REnv.OneRestoreInterval * _quickCalcValue);
            }

            REnv.UpdateSaveData();
        }
Exemple #3
0
        private void RefreshInfo()
        {
            try
            {
                TotalTimeHour.Text   = $"{REnv.TotalCountTime.Hours:D2}";
                TotalTimeMinute.Text = $"{REnv.TotalCountTime.Minutes:D2}";

                LastInputDateTimeLabel.Text = Utils.GetTimeString(
                    DateTime.Parse(REnv.LastInputTime, AppEnv.DTCulture));
                EndDateTimeLabel.Text = Utils.GetTimeString(REnv.EndTime);

                ResinCount.Text    = REnv.Resin.ToString();
                OneCountTimer.Text = $"{REnv.OneCountTime.Minutes} : {REnv.OneCountTime.Seconds:D2}";

                RangeValue.Value   = REnv.Resin;
                PointerValue.Value = REnv.Resin;

                ResinRemainTimeRange.EndValue = REnv.MaxResin - REnv.OneCountTime.TotalSeconds *
                                                ((double)REnv.MaxResin / REnv.OneRestoreInterval);

                int overflowValue = REnv.CalcResinOverflow();

                ResinOverflowLabel.Text = (Preferences.Get(
                                               SettingConstants.SHOW_OVERFLOW, false) && (overflowValue > 0)) ?
                                          $"{AppResources.Overflow_Text} : {overflowValue}" : "";
            }
            catch (Exception) { }
            finally
            {
                //System.Diagnostics.Debug.WriteLine("Resin info refresh");
            }
        }
Exemple #4
0
        private void CalcTimeResin(object statusInfo)
        {
            try
            {
                if (REnv.EndTime >= DateTime.Now)
                {
                    REnv.CalcResinTime();
                    REnv.CalcResin();
                }
                else
                {
                    REnv.TotalCountTime = new();
                    REnv.OneCountTime   = new();
                    REnv.Resin          = REnv.MaxResin;
                }

                MainThread.BeginInvokeOnMainThread(RefreshInfo);
            }
            catch (Exception ex)
            {
#if DEBUG
                DependencyService.Get <IToast>().Show(ex.ToString());
#endif
            }
        }
Exemple #5
0
        protected override void OnDisappearing()
        {
            base.OnDisappearing();

            _calcTimer?.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
            _calcTimer?.Dispose();

            REnv.SaveValue();
        }
Exemple #6
0
        public static async Task <bool> Update(SyncTarget target)
        {
            RTNoteData data = await GetRTNoteData();

            return(target switch
            {
                SyncTarget.Resin => REnv.SyncServerData(data),
                SyncTarget.RealmCurrency => RCEnv.SyncServerData(data),
                SyncTarget.Expedition => ExpEnv.SyncServerData(data),
                _ => false
            });
Exemple #7
0
        public ResinNoti(int resin)
        {
            NotiId   = Resin = resin;
            Interval = (REnv.MaxResin - Resin) * REnv.OneRestoreInterval;

            try
            {
                NotiTime = REnv.EndTime.AddSeconds(-Interval);
            }
            catch (Exception)
            {
                REnv.LoadValues();

                NotiTime = REnv.EndTime.AddSeconds(-Interval);
            }
        }
Exemple #8
0
        public override async void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            base.OnUpdate(context, appWidgetManager, appWidgetIds);

            try
            {
                REnv.LoadValues();

                if (REnv.IsSyncEnabled)
                {
                    if (await SyncHelper.Update(SyncHelper.SyncTarget.Resin))
                    {
                        REnv.SaveValue();

                        if (Preferences.Get(SettingConstants.NOTI_ENABLED, false))
                        {
                            var notiManager         = new ResinNotiManager();
                            var notiScheduleAndroid = new NotiScheduleAndroid();

                            if (notiManager.Notis.Count > 0)
                            {
                                notiManager.UpdateNotisTime();

                                notiScheduleAndroid.Cancel <ResinNoti>();
                                notiScheduleAndroid.Schedule <ResinNoti>();
                            }
                        }
                    }
                }

                REnv.CalcResin();

                UpdateLayout(context, appWidgetManager, appWidgetIds);
            }
            catch
            {
                Toast.MakeText(context, Resources.AppResources.ResinWidget_UpdateFail, ToastLength.Short).Show();
            }

            if (isClick)
            {
                Toast.MakeText(context, Resources.AppResources.ResinWidget_UpdateComplete, ToastLength.Short).Show();

                isClick = false;
            }
        }
Exemple #9
0
        internal override void ApplyValue()
        {
            base.ApplyValue();

            if (int.TryParse(SfUpDown.Text, out int inputValue))
            {
                REnv.EndTime       = REnv.EndTime.AddSeconds(REnv.OneRestoreInterval * (REnv.Resin - inputValue));
                REnv.LastInputTime = DateTime.Now.ToString(AppEnv.DTCulture);
                REnv.CalcResin();
                REnv.SaveValue();

                notiManager.UpdateNotisTime();
                notiManager.UpdateScheduledNoti <ResinNoti>();
            }
            else
            {
                DependencyService.Get <IToast>().Show(AppResources.ValueEdit_ValueError_Message);
            }
        }
        private void ApplyButtonClicked(object sender, EventArgs e)
        {
            if (CurrentPage.Title == AppResources.EditPage_TabTime_Title)
            {
                REnv.ManualApplyType = REnv.ApplyType.Time;
            }
            else if (CurrentPage.Title == AppResources.EditPage_TabResin_Title)
            {
                REnv.ManualApplyType = REnv.ApplyType.Resin;
            }

            switch (REnv.ManualApplyType)
            {
            case REnv.ApplyType.Time:
                SetTimeValue();
                break;

            case REnv.ApplyType.Resin:
                SetResinValue();
                break;

            default:
                break;
            }

            REnv.LastInputTime = DateTime.Now.ToString(AppEnv.DTCulture);

            CalcRemainTime();

            REnv.SaveValue();

            if (Preferences.Get(SettingConstants.NOTI_ENABLED, false))
            {
                ResinNotiManager notiManager = new();

                notiManager.UpdateNotisTime();
                notiManager.UpdateScheduledNoti <ResinNoti>();
            }

            Navigation.PopAsync();
        }
Exemple #11
0
        private async Task SyncData()
        {
            SyncStatusTipLabel.IsVisible = false;
            ManualSyncButton.IsEnabled   = false;
            ManualSyncButton.BorderColor = Color.Default;

            await Task.Delay(100);

            if (await SyncHelper.Update(SyncHelper.SyncTarget.Resin))
            {
                REnv.UpdateSaveData();

                ManualSyncButton.BorderColor = Color.Green;
            }
            else
            {
                ManualSyncButton.BorderColor = Color.OrangeRed;
                SyncStatusTipLabel.IsVisible = true;
            }

            ManualSyncButton.IsEnabled = true;
        }
Exemple #12
0
 public void UpdateInfo()
 {
     REnv.CalcResin();
     REnv.CalcResinTime();
 }
Exemple #13
0
 public ResinHomeItem()
 {
     REnv.LoadValues();
 }