예제 #1
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.State = await status.SuggestAsync();

            var helper = credential.GetHelper();

            if (helper != null)
            {
                FluxUser user = await helper.GetFluxAsync();

                widgetView.SetTextViewText(Resource.Id.widgetTitle, user.Username);
                widgetView.SetTextViewText(Resource.Id.widgetFlux, $"流量:{user.Flux}");
                widgetView.SetTextViewText(Resource.Id.widgetBalance, string.Format(CultureInfo.GetCultureInfo("zh-CN"), "余额:{0:C2}", user.Balance));
            }
            var intent = new Intent(context, typeof(AppWidget));

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

            widgetView.SetOnClickPendingIntent(Resource.Id.widgetBackground, piBackground);
            appWidgetManager.UpdateAppWidget(me, widgetView);
        }
예제 #2
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferral = taskInstance.GetDeferral();

            try
            {
                NetCredential  credential = new NetCredential();
                InternetStatus status     = new InternetStatus();
                credential.State = await status.SuggestAsync();

                var helper = credential.GetHelper();
                if (helper != null)
                {
                    FluxUser user = await helper.GetFluxAsync();

                    NotificationHelper.UpdateTile(user);
                    NetXFSettings settings = new NetXFSettings();
                    settings.LoadSettings();
                    if (settings.EnableFluxLimit)
                    {
                        NotificationHelper.SendWarningToast(user, settings.FluxLimit);
                    }
                }
            }
            finally
            {
                deferral.Complete();
            }
        }
예제 #3
0
        public static void SendToast(FluxUser user)
        {
            XmlDocument dom = new XmlDocument();

            dom.LoadXml(string.Format(zhCulture, toastText, user.Username, user.Flux, user.Balance));
            ToastNotification notification = new ToastNotification(dom);

            notification.ExpirationTime = DateTimeOffset.Now + TimeSpan.FromMinutes(1);
            ToastNotificationManager.CreateToastNotifier().Show(notification);
        }
예제 #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);
        }
예제 #5
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);
            }
        }
예제 #6
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);
        }
예제 #7
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));
            }
        }
예제 #8
0
 public async Task <FluxUser> GetFluxAsync() => FluxUser.Parse(await PostAsync(string.Format(FluxUri, version)), 2);
예제 #9
0
 public async Task <FluxUser> GetFluxAsync() => FluxUser.Parse(await PostAsync(FluxUri));