示例#1
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Login);

            spConfig = GetSharedPreferences("config", FileCreationMode.Private);
            activity = this;

            webView = (WebView)FindViewById(Resource.Id.webView);
            webView.Settings.JavaScriptEnabled       = true;
            webView.Settings.DefaultTextEncodingName = "utf-8";
            webView.Settings.UseWideViewPort         = true;

            //判断是否已经登录
            var refreshToken = spConfig.GetString("refresh_token", string.Empty);

            if (!string.IsNullOrEmpty(refreshToken))
            {
                webView.LoadUrl("file:///android_asset/loading.html");
                //获取新的token,存储并跳转
                var service     = new TokenService(this);
                var accessToken = await service.RefreshToken(refreshToken);

                //获取项目及workitem信息并保存
                var VSTSService = new VSTSService(accessToken);
                var projects    = await VSTSService.GetMyProjectAsync();

                var workitems = await VSTSService.GetWorkItemsAsync();

                var spData = GetSharedPreferences("data", FileCreationMode.Private);
                var editor = spData.Edit();
                editor.PutString("projects", JsonConvert.SerializeObject(projects));
                editor.PutString("workitems", JsonConvert.SerializeObject(workitems));
                editor.Commit();

                var intent = new Intent(this, typeof(MainActivity));
                StartActivity(intent);
                Finish();
            }
            else
            {
                webView.SetWebViewClient(new MyWebViewClient());
                webView.LoadUrl("https://workitem.msdev.cc/");
            }
        }