From 7227d0dcb1c714376992db30e2948161c0dc5086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Cort=C3=A9s=20Fern=C3=A1ndez?= Date: Sun, 18 Nov 2018 23:10:49 -0500 Subject: [PATCH] Update to prevent IllegalStateException I changed the position where the Toast is created to avoid a IllegalStateException. This exception was thrown because the DialogFragment was no longer attached to the SettingsActivity when the userInfoFailed() method was called. --- .../java/com/naman14/timber/dialogs/LastFmLoginDialog.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/naman14/timber/dialogs/LastFmLoginDialog.java b/app/src/main/java/com/naman14/timber/dialogs/LastFmLoginDialog.java index ad4a99a79..603f419d1 100644 --- a/app/src/main/java/com/naman14/timber/dialogs/LastFmLoginDialog.java +++ b/app/src/main/java/com/naman14/timber/dialogs/LastFmLoginDialog.java @@ -5,6 +5,7 @@ import android.app.ProgressDialog; import android.os.Bundle; import android.support.annotation.NonNull; +import android.util.Log; import android.widget.EditText; import android.widget.Toast; @@ -36,9 +37,11 @@ public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) String username = ((EditText) dialog.findViewById(R.id.lastfm_username)).getText().toString(); String password = ((EditText) dialog.findViewById(R.id.lastfm_password)).getText().toString(); if (username.length() == 0 || password.length() == 0) return; + final Toast toast = Toast.makeText(getActivity(), getString(R.string.lastfm_login_failture), Toast.LENGTH_SHORT); final ProgressDialog progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage("Logging in.."); progressDialog.show(); + LastFmClient.getInstance(getActivity()).getUserLoginInfo(new UserLoginQuery(username, password), new UserListener() { @Override @@ -52,10 +55,11 @@ public void userSuccess() { @Override public void userInfoFailed() { progressDialog.dismiss(); - Toast.makeText(getTargetFragment().getActivity(), getString(R.string.lastfm_login_failture), Toast.LENGTH_SHORT).show(); + toast.show(); } }); } }).build(); } + }