Пример #1
0
        public static async Task <Dictionary <string, int> > FillGroupsDictionary(bool rewrite, CancellationToken cts)
        {
            var    networkChecker = new NetworkChecker(Instance);
            string resultJson;

            var resourceName = "groups.json";

            var b = File.Exists(GetFileFullPath(resourceName));

            if (rewrite && networkChecker.Check())
            {
                var client = new HttpClient();
                resultJson = await HttpClientSL.GetResponseAsync(client, Instance.groupLink, cts);

                File.WriteAllText(GetFileFullPath(resourceName), resultJson);
            }
            else
            {
                using (var stream = GetEmbeddedResourceStream(resourceName))
                    using (var reader = b ? new StreamReader(GetFileFullPath(resourceName)) : new StreamReader(stream))
                    {
                        resultJson = await reader.ReadToEndAsync();
                    }
            }
            var groups     = JsonConvert.DeserializeObject <GroupRoot>(resultJson);
            var dictionary = groups.Groups.ToDictionary(x => x.Name, x => x.Id);

            return(dictionary);
        }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            MainApp.ChangeLanguage(this);
            SetTheme(Resource.Style.MyAppTheme);
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_authorization);

            networkChecker           = new NetworkChecker(this);
            autoCompleteTextViewAuth = FindViewById <AutoCompleteTextView>(Resource.Id.autocompletetextview_auth);
            autoCompleteTextViewAuth.SetOnEditorActionListener(this);
            autoCompleteTextViewAuth.AddTextChangedListener(this);
            progressBar = FindViewById <ProgressBar>(Resource.Id.progressbar_auth);

            progressBar.Visibility = ViewStates.Visible;
            Task.Run(async() =>
            {
                groupsDictionary = await MainApp.Instance.GroupsDictionary;
                array            = groupsDictionary.Select(x => x.Key).ToArray();

                RunOnUiThread(() =>
                {
                    suggestAdapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleDropDownItem1Line, array);

                    autoCompleteTextViewAuth.Adapter = suggestAdapter;

                    progressBar.Visibility = ViewStates.Invisible;
                });
            });

            var buttonAuth     = FindViewById <Button>(Resource.Id.button_auth);
            var textViewLater  = FindViewById <TextView>(Resource.Id.textview_later_auth);
            var textViewUpdate = FindViewById <TextView>(Resource.Id.textview_groupsupdate_auth);

            buttonAuth.Click     += ButtonAuth_Click;
            textViewLater.Click  += TextViewLater_Click;
            textViewUpdate.Click += TextViewUpdate_Click;

            prefEditor = MainApp.Instance.SharedPreferences.Edit();
        }