示例#1
0
        private void Render(string error)
        {
            if (string.IsNullOrEmpty(error))
            {
                if (_snackbar == null)
                {
                    return;
                }
                if (_snackbar.IsShownOrQueued)
                {
                    _snackbar.Dismiss();
                }
                return;
            }

            if (_snackbar == null)
            {
                _snackbar = Snackbar.Make(_container, error, Snackbar.LengthIndefinite);
            }
            else
            {
                _snackbar.SetText(error);
            }

            _snackbar.Show();
        }
示例#2
0
        public static async Task <List <Category> > DownloadDB(Action retryMethod, Snackbar snack)
        {
            try
            {
                var response = await client.GetAsync(AppResources.DbLink);

                if (response.IsSuccessStatusCode)
                {
                    var payload = await response.Content.ReadAsStringAsync();

                    newDB = JsonConvert.DeserializeObject <List <Category> >(payload);
                    var newideasdbResponse = await client.GetAsync(AppResources.NewIdeasDbLink);

                    if (newideasdbResponse.IsSuccessStatusCode)
                    {
                        newideastxt = await newideasdbResponse.Content.ReadAsStringAsync();

                        DBAssist.SerializeDBAsync(oldDBPath, Global.Categories);
                        DBAssist.SerializeDBAsync(newideastxtPath, newideastxt);
                        return(newDB);
                    }
                }

                // To prevent too many requests to server, only invalidate cache if app is opening fresh from launcher
                Global.LockRequests = true;
            }
            catch (TaskCanceledException)
            {
                snack.SetText("Can't load ideas. Your connection might be too slow.").SetAction("Retry", (v) => retryMethod?.Invoke()).Show();
            }
            catch (HttpRequestException)
            {
                snack.SetText("Can't load ideas. Check your connection.").SetAction("Retry", (v) => retryMethod?.Invoke()).Show();
            }
            catch (Exception e)
            {
                snack.SetText($"Oops! {e.Message}.").SetAction("Retry", (v) => retryMethod?.Invoke()).Show();
            }

            return(null);
        }
        public static void ShowSnackbar(Activity activity, SnackbarConfig config)
        {
            var view = activity.Window.DecorView.RootView.FindViewById(global::Android.Resource.Id.Content);

            if (_snackbar == null)
            {
                _snackbar = Snackbar.Make(view, config.Message, (int)config.Duration.TotalMilliseconds);
            }

            if (_snackbar.IsShownOrQueued)
            {
                _snackbar = Snackbar.Make(view, config.Message, (int)config.Duration.TotalMilliseconds);
            }

            _snackbar.SetDuration((int)config.Duration.TotalMilliseconds);
            _snackbar.SetText(config.Message);

            if (!string.IsNullOrWhiteSpace(config.ActionText))
            {
                _snackbar.SetAction(config.ActionText, (v) =>
                {
                    config.Action?.Invoke();

                    _snackbar.Dismiss();
                });

                if (config.ActionTextColor.HasValue)
                {
                    _snackbar.SetActionTextColor(config.ActionTextColor.Value.ToNativeColor());
                }
            }

            if (config.TextColor.HasValue)
            {
                //TextView textView = _snackbar.View.FindViewById<TextView>(Resource.Id.snackbar_text);
                //textView.SetTextColor(config.TextColor.Value.ToNativeColor());

                // TODO
            }

            if (config.BackgroundColor.HasValue)
            {
                //TextView textView = _snackbar.View.FindViewById<TextView>(Resource.Id.snackbar_text);
                //textView.SetBackgroundColor(config.BackgroundColor.Value.ToNativeColor());

                // TODO
            }

            //if (config.Position != ToastPosition.Default)
            //{
            //    // watch for this to change in future support lib versions
            //    var layoutParams = _snackbar.View.LayoutParameters as FrameLayout.LayoutParams;
            //    if (layoutParams != null)
            //    {
            //        if (config.Position == ToastPosition.Top)
            //        {
            //            layoutParams.Gravity = GravityFlags.Top;
            //            layoutParams.SetMargins(0, 80, 0, 0);
            //        }
            //        else if (config.Position == ToastPosition.Center)
            //        {
            //            layoutParams.Gravity = GravityFlags.Center;
            //        }
            //        else if (config.Position == ToastPosition.Bottom)
            //        {
            //            layoutParams.Gravity = GravityFlags.Bottom;
            //            layoutParams.SetMargins(0, 0, 0, 30);
            //        }

            //        _snackbar.View.LayoutParameters = layoutParams;
            //    }
            //}

            _snackbar.Show();
        }
示例#4
0
        private async void clickBtnLogIn(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(username.Text) || string.IsNullOrEmpty(username.Text))
            {
                Snackbar bar = Snackbar.Make(parentLayout, "Fill username", Snackbar.LengthLong);
                bar.SetText(Html.FromHtml("<font color=\"#000000\">Fill username</font>"));
                Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View;
                layout.SetMinimumHeight(100);
                layout.SetBackgroundColor(Android.Graphics.Color.White);
                layout.TextAlignment = TextAlignment.Center;
                layout.ScrollBarSize = 16;
                bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red));
                bar.SetDuration(Snackbar.LengthLong);
                bar.SetAction("Ok", (v) => { });
                bar.Show();
            }
            else if (string.IsNullOrWhiteSpace(password.Text) || string.IsNullOrEmpty(password.Text))
            {
                Snackbar bar = Snackbar.Make(parentLayout, Html.FromHtml("<font color=\"#000000\">Fill password</font>"), Snackbar.LengthLong);
                Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View;
                layout.SetMinimumHeight(100);
                layout.SetBackgroundColor(Android.Graphics.Color.White);
                layout.TextAlignment = TextAlignment.Center;
                layout.ScrollBarSize = 16;
                bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red));
                bar.SetDuration(Snackbar.LengthLong);
                bar.SetAction("Ok", (v) => { });
                bar.Show();
            }
            else
            {
                var progressDialog = new ProgressDialog(this);
                try
                {
                    progressDialog.SetIcon(2130968582);
                    progressDialog.SetCancelable(true);
                    progressDialog.SetMessage("Please wait!");
                    progressDialog.SetProgressStyle(ProgressDialogStyle.Spinner);
                    progressDialog.Show();

                    var client        = new HttpClient();
                    var keyValueLogIn = new List <KeyValuePair <string, string> >
                    {
                        new KeyValuePair <string, string>("username", username.Text),
                        new KeyValuePair <string, string>("password", password.Text),
                        new KeyValuePair <string, string>("grant_type", "password")
                    };
                    var request = new HttpRequestMessage(HttpMethod.Post, "UrlApiToken");
                    request.Content = new FormUrlEncodedContent(keyValueLogIn);
                    var response = await client.SendAsync(request);

                    var content = await response.Content.ReadAsStringAsync();

                    if (response.IsSuccessStatusCode)
                    {
                        TokenModel tokenFromServer = JsonConvert.DeserializeObject <TokenModel>(content);
                        var        jsonContent     = JsonConvert.SerializeObject(username.Text);
                        var        LogIncontent    = new StringContent(jsonContent, Encoding.ASCII, "application/json");

                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenFromServer.access_token);

                        response = await client.PostAsync("UrlApi" + "api/Account/userdata", LogIncontent);

                        var userData = await response.Content.ReadAsStringAsync();

                        User user = JsonConvert.DeserializeObject <User>(userData);

                        var userSession = new UserSession
                        {
                            FirstName  = user.FirstName,
                            LastName   = user.LastName,
                            userId     = user.userId,
                            Token      = tokenFromServer.access_token,
                            user_image = user.user_image
                        };
                        con.Insert(userSession);
                        progressDialog.Cancel();
                        StartActivity(typeof(MainActivity));
                    }
                    else
                    {
                        LogInError logInError      = JsonConvert.DeserializeObject <LogInError>(content);
                        var        alertLogInError = new Android.App.AlertDialog.Builder(this);
                        alertLogInError.SetTitle(logInError.error);
                        alertLogInError.SetMessage(logInError.error_description);
                        username.Text = "";
                        password.Text = "";

                        Snackbar bar = Snackbar.Make(parentLayout, Html.FromHtml("<font color=\"#000000\">" + logInError.error + " - " + logInError.error_description + "</font>"), Snackbar.LengthLong);
                        Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View;
                        layout.SetMinimumHeight(100);
                        layout.SetBackgroundColor(Android.Graphics.Color.White);
                        layout.TextAlignment = TextAlignment.Center;
                        layout.ScrollBarSize = 16;
                        bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red));
                        bar.SetDuration(Snackbar.LengthLong);
                        bar.SetAction("Ok", (v) => { });
                        bar.Show();

                        progressDialog.Cancel();
                    }
                }
                catch (HttpRequestException httpEx)
                {
                    Snackbar bar = Snackbar.Make(parentLayout, Html.FromHtml("<font color=\"#000000\">Please check your internet connection!</font>"), Snackbar.LengthLong);
                    Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View;
                    layout.SetMinimumHeight(100);
                    layout.SetBackgroundColor(Android.Graphics.Color.White);
                    layout.TextAlignment = TextAlignment.Center;
                    layout.ScrollBarSize = 16;
                    bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red));
                    bar.SetDuration(Snackbar.LengthIndefinite);
                    bar.SetAction("Ok", (v) => { });
                    bar.Show();
                    progressDialog.Cancel();
                }
                catch (Exception ex)
                {
                    Snackbar bar = Snackbar.Make(parentLayout, Html.FromHtml("<font color=\"#000000\">Error: " + ex + "</font>"), Snackbar.LengthLong);
                    Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View;
                    layout.SetMinimumHeight(100);
                    layout.SetBackgroundColor(Android.Graphics.Color.White);
                    layout.TextAlignment = TextAlignment.Center;
                    layout.ScrollBarSize = 16;
                    bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red));
                    bar.SetDuration(Snackbar.LengthIndefinite);
                    bar.SetAction("Ok", (v) => { });
                    bar.Show();
                    progressDialog.Cancel();
                }
            }
        }
示例#5
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            view = inflater.Inflate(Resource.Layout.weld_condition_fragment, container, false);

            coordinatorLayout = view.FindViewById <CoordinatorLayout>(Resource.Id.coordinator_layout);

            selectedBackGroundColor = Context.Resources.GetColor(Resource.Color.tab3_textview_background);
            listView                   = view.FindViewById <ListView>(Resource.Id.wcdListView);
            listView.Adapter           = wcdListAdapter;
            listView.FastScrollEnabled = false;
            listView.ChoiceMode        = ChoiceMode.Multiple;
            listView.ItemClick        += (object sender, AdapterView.ItemClickEventArgs e) =>
            {
                wcdListAdapter[e.Position].ItemChecked = listView.IsItemChecked(e.Position);
                if (listView.IsItemChecked(e.Position))
                {
                    lastPosition = e.Position;
                    e.View.SetBackgroundColor(selectedBackGroundColor);
                }
                else
                {
                    e.View.SetBackgroundColor(defaultBackgroundColor);                      // 기본 백그라운드 색깔
                }

                try {
                    if (wcdListAdapter.Count == 0)
                    {
                        fabWcd.SetImageResource(Resource.Drawable.ic_refresh_white);
                    }
                    else if (listView.CheckedItemCount == 0)
                    {
                        fabWcd.SetImageResource(Resource.Drawable.ic_subject_white);
                    }
                    else
                    {
                        fabWcd.SetImageResource(Resource.Drawable.ic_edit_white);
                    }
                } catch { }

                if (snackbar == null)
                {
                    snackbar = Snackbar.Make(coordinatorLayout, listView.CheckedItemCount.ToString() + "개 항목 선택됨", Snackbar.LengthIndefinite)
                               .SetAction("선택 취소", (view) => { CheckListItem(); snackbar = null; });
                }
                if (listView.CheckedItemCount > 0)
                {
                    if (snackbar.IsShown)
                    {
                        snackbar.SetText(listView.CheckedItemCount.ToString() + "개 항목 선택됨");
                    }
                    else
                    {
                        snackbar.Show();
                    }
                }
                else if (snackbar != null)
                {
                    snackbar.Dismiss();
                    snackbar = null;
                }
            };
            listView.ItemLongClick += (object sender, AdapterView.ItemLongClickEventArgs e) =>
            {
                FabWcd_Click(sender, e);
            };

            var refresher = view.FindViewById <SwipeRefreshLayout>(Resource.Id.srl);

            if (refresher != null)
            {
                refresher.Refresh += delegate
                {
                    Refresh(forced: true);
                    refresher.Refreshing = false;
                };
            }

            // 떠 있는 액션버튼
            fabWcd        = view.FindViewById <FloatingActionButton>(Resource.Id.fab_wcd);
            fabWcd.Click += (object sender, EventArgs e) =>
            {
                if (listView.CheckedItemCount == 0)
                {
                    Pref.TextViewDialog(Context, robotPath);
                }
                else
                {
                    FabWcd_Click(sender, e);
                }
            };

            try {
                if (wcdListAdapter.Count == 0)
                {
                    fabWcd.SetImageResource(Resource.Drawable.ic_refresh_white);
                }
                else if (listView.CheckedItemCount == 0)
                {
                    fabWcd.SetImageResource(Resource.Drawable.ic_subject_white);
                }
                else
                {
                    fabWcd.SetImageResource(Resource.Drawable.ic_edit_white);
                }
            } catch { }

            return(view);
        }