Search in sources :

Example 1 with UserListener

use of com.naman14.timber.lastfmapi.callbacks.UserListener in project Timber by naman14.

the class LastFmLoginDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new MaterialDialog.Builder(getActivity()).positiveText("Login").negativeText("Cancel").title("Login to LastFM").customView(R.layout.dialog_lastfm_login, false).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        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 ProgressDialog progressDialog = new ProgressDialog(getActivity());
            progressDialog.setMessage("Logging in..");
            progressDialog.show();
            LastFmClient.getInstance(getActivity()).getUserLoginInfo(new UserLoginQuery(username, password), new UserListener() {

                @Override
                public void userSuccess() {
                    progressDialog.dismiss();
                    if (getTargetFragment() instanceof SettingsFragment) {
                        ((SettingsFragment) getTargetFragment()).updateLastFM();
                    }
                }

                @Override
                public void userInfoFailed() {
                    progressDialog.dismiss();
                    Toast.makeText(getTargetFragment().getActivity(), "Failed to Login", Toast.LENGTH_SHORT).show();
                }
            });
        }
    }).build();
}
Also used : SettingsFragment(com.naman14.timber.fragments.SettingsFragment) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) UserLoginQuery(com.naman14.timber.lastfmapi.models.UserLoginQuery) ProgressDialog(android.app.ProgressDialog) UserListener(com.naman14.timber.lastfmapi.callbacks.UserListener)

Aggregations

ProgressDialog (android.app.ProgressDialog)1 NonNull (android.support.annotation.NonNull)1 DialogAction (com.afollestad.materialdialogs.DialogAction)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 SettingsFragment (com.naman14.timber.fragments.SettingsFragment)1 UserListener (com.naman14.timber.lastfmapi.callbacks.UserListener)1 UserLoginQuery (com.naman14.timber.lastfmapi.models.UserLoginQuery)1