コード例 #1
0
        public static void SendWarningToast(FluxUser user, ByteSize limit)
        {
            var remainFlux = FluxHelper.GetMaxFlux(user.Flux, user.Balance) - user.Flux;

            if (remainFlux < limit)
            {
                XmlDocument dom = new XmlDocument();
                dom.LoadXml(string.Format(zhCulture, toastWarningText, user.Username, user.Flux, remainFlux));
                ToastNotification notification = new ToastNotification(dom);
                notification.ExpirationTime = DateTimeOffset.Now + TimeSpan.FromMinutes(1);
                ToastNotificationManager.CreateToastNotifier().Show(notification);
            }
        }
コード例 #2
0
        public override async void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            var            me         = new ComponentName(context, Java.Lang.Class.FromType(typeof(AppWidget)).Name);
            var            widgetView = new RemoteViews(context.PackageName, Resource.Layout.Widget);
            InternetStatus status     = new InternetStatus();
            NetCredential  credential = new NetCredential();

            (credential.Username, credential.Password) = await CredentialStore.LoadCredentialAsync();

            credential.State = await status.SuggestAsync();

            NetXFSettings settings = new NetXFSettings();

            settings.LoadSettings();
            var helper = credential.GetHelper(settings);

            if (helper != null)
            {
                if (settings.BackgroundAutoLogin && !string.IsNullOrEmpty(credential.Username))
                {
                    if (settings.EnableRelogin)
                    {
                        await helper.LogoutAsync();
                    }
                    await helper.LoginAsync();
                }
                FluxUser user = await helper.GetFluxAsync();

                var remainFlux = FluxHelper.GetMaxFlux(user.Flux, user.Balance) - user.Flux;
                widgetView.SetTextViewText(Resource.Id.widgetTitle, $"用户:{user.Username}");
                widgetView.SetTextViewText(Resource.Id.widgetFlux, $"流量:{user.Flux}");
                widgetView.SetTextViewText(Resource.Id.widgetRemain, $"剩余:{remainFlux}");
                widgetView.SetTextViewText(Resource.Id.widgetBalance, string.Format(CultureInfo.GetCultureInfo("zh-CN"), "余额:{0:C2}", user.Balance));
            }
            else
            {
                widgetView.SetTextViewText(Resource.Id.widgetTitle, "暂无流量信息");
                widgetView.SetTextViewText(Resource.Id.widgetFlux, string.Empty);
                widgetView.SetTextViewText(Resource.Id.widgetRemain, string.Empty);
                widgetView.SetTextViewText(Resource.Id.widgetBalance, string.Empty);
            }
            var intent = new Intent(context, typeof(AppWidget));

            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);
            var piBackground = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);

            widgetView.SetOnClickPendingIntent(Resource.Id.widgetBackground, piBackground);
            appWidgetManager.UpdateAppWidget(me, widgetView);
        }
コード例 #3
0
        protected virtual async Task <LogResponse> RefreshAsync(IConnect helper)
        {
            FluxUser user = default;

            if (helper != null)
            {
                user = await helper.GetFluxAsync();
            }
            OnlineUser = user;
            var remainFlux = FluxHelper.GetMaxFlux(OnlineUser.Flux, OnlineUser.Balance) - OnlineUser.Flux;

            if (Settings.EnableFluxLimit && remainFlux < Settings.FluxLimit)
            {
                return(new LogResponse(false, $"流量仅剩余{remainFlux}"));
            }
            else
            {
                return(new LogResponse(true, string.Empty));
            }
        }
コード例 #4
0
        public static void UpdateTile(FluxUser user)
        {
            XmlDocument dom = new XmlDocument();

            dom.LoadXml(string.Format(tileText, user.Username, user.Flux, user.OnlineTime, user.Balance, FluxHelper.GetMaxFlux(user.Flux, user.Balance) - user.Flux));
            TileNotification notification = new TileNotification(dom);

            notification.ExpirationTime = DateTimeOffset.Now + TimeSpan.FromMinutes(15);
            TileUpdateManager.CreateTileUpdaterForApplication().Update(notification);
        }