Show Errors on login!
This commit is contained in:
@@ -6,6 +6,7 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
@@ -476,36 +477,54 @@ public class MainActivity extends AppCompatActivity
|
||||
toLoginState(loginToken.getFullname(), loginToken.getEmail(), getDefaultFragmentAfterLogin(), "", onlineMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModulesFragmentInteraction(final String itemID) {
|
||||
changeFragment(FRAGMENT_MODULES_DETAILS, itemID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCanteensFragmentInteraction(final int itemID) {
|
||||
changeFragment(FRAGMENT_CANTEENS_DETAILS, String.valueOf(itemID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTitleTextChange(String newTitle) {
|
||||
setTitle(newTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTitleTextChange(@StringRes int titleId) {
|
||||
setTitle(titleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loginTokenInvalid(boolean doPrecheck) {
|
||||
getKVV().invalidate();
|
||||
checkAndDoLogin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshFailed(boolean isFailed) {
|
||||
setRefreshFailedBanner(isFailed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestPermissionsResultListener(RequestPermissionsResultListener listener, String id) {
|
||||
permissionListeners.put(id, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRequestPermissionsResultListener(String id) {
|
||||
permissionListeners.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showToast(@StringRes int msgStringRes) {
|
||||
showToast(getString(msgStringRes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showToast(String message) {
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import de.sebse.fuplanner.tools.logging.Logger;
|
||||
public class LoginFragment extends Fragment {
|
||||
private OnLoginFragmentInteractionListener mListener;
|
||||
private final Logger log = new Logger(this);
|
||||
private MainActivityListener mActivityListener;
|
||||
|
||||
public LoginFragment() {
|
||||
// Required empty public constructor
|
||||
@@ -96,10 +97,20 @@ public class LoginFragment extends Fragment {
|
||||
kvv.login(username, password, success -> {
|
||||
progressDialog.dismiss();
|
||||
gauth.setLoginState(username, password);
|
||||
if (mListener != null)
|
||||
if (mListener != null) {
|
||||
input_usr.setError(null);
|
||||
input_pwd.setError(null);
|
||||
mListener.onLoginFragmentInteraction(success, true);
|
||||
}
|
||||
}, error -> {
|
||||
progressDialog.dismiss();
|
||||
// Invalid password
|
||||
if (error.getCode() == 100131 && mActivityListener != null) {
|
||||
mActivityListener.showToast(R.string.invalid_credentials);
|
||||
input_usr.setError(input_usr.getResources().getString(R.string.invalid_credentials));
|
||||
input_pwd.setError(input_pwd.getResources().getString(R.string.invalid_credentials));
|
||||
} else
|
||||
mActivityListener.showToast(v.getResources().getString(R.string.error_occurred_code, error.getCode()));
|
||||
log.e("Error on KVV login!", error);
|
||||
});
|
||||
}
|
||||
@@ -120,9 +131,10 @@ public class LoginFragment extends Fragment {
|
||||
throw new RuntimeException(context.toString()
|
||||
+ " must implement OnLoginFragmentInteractionListener");
|
||||
}
|
||||
if (context instanceof MainActivityListener)
|
||||
((MainActivityListener) context).onTitleTextChange(R.string.log_in);
|
||||
else
|
||||
if (context instanceof MainActivityListener) {
|
||||
mActivityListener = (MainActivityListener) context;
|
||||
mActivityListener.onTitleTextChange(R.string.log_in);
|
||||
} else
|
||||
throw new RuntimeException(context.toString() + "must implement MainActivityListener");
|
||||
}
|
||||
|
||||
|
||||
@@ -24,4 +24,8 @@ public interface MainActivityListener {
|
||||
void addRequestPermissionsResultListener(RequestPermissionsResultListener listener, String id);
|
||||
|
||||
void removeRequestPermissionsResultListener(String id);
|
||||
|
||||
void showToast(@StringRes int msgStringRes);
|
||||
|
||||
void showToast(String message);
|
||||
}
|
||||
|
||||
@@ -61,4 +61,6 @@
|
||||
<string name="openFile">Datei Öffnen</string>
|
||||
<string name="ErrorFileDownload">Download-Fehler</string>
|
||||
<string name="ErrorFileDownloadText">Beim Herunterladen der Datei ist ein Fehler aufgetreten. Prüfe, ob Du mit dem Internet verbunden bist und der App Zugriff auf den Speicher gewährt hast.</string>
|
||||
<string name="invalid_credentials">Ungültiger Benutzername oder Password!</string>
|
||||
<string name="error_occurred_code">Fehler %1$d aufgetreten!</string>
|
||||
</resources>
|
||||
@@ -68,4 +68,6 @@
|
||||
<string name="openFile">Open File</string>
|
||||
<string name="ErrorFileDownload">Download Error</string>
|
||||
<string name="ErrorFileDownloadText">An error occurred while downloading the file. Please check if you are connected to the internet and if you have granted storage access to the app.</string>
|
||||
<string name="invalid_credentials">Invalid username or password!</string>
|
||||
<string name="error_occurred_code">Error occurred: %1$d</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user