Search in sources :

Example 1 with ServerStatusCode

use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.

the class UserFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_account_user_fragment, container, false);
    progressImage = view.findViewById(R.id.activity_account_user_fragment_level_progress_image);
    userName = view.findViewById(R.id.activity_account_user_fragment_user_name);
    score = view.findViewById(R.id.activity_account_user_fragment_user_score);
    level = view.findViewById(R.id.activity_account_user_fragment_user_level);
    userBusAvatarTitle = view.findViewById(R.id.user_bus_avatar_title);
    levelBackground = view.findViewById(R.id.level_background);
    levelName = view.findViewById(R.id.level_name);
    rankingFrame = view.findViewById(R.id.ranking_frame);
    rankingPosition = view.findViewById(R.id.ranking_position);
    rankingButton = view.findViewById(R.id.ranking_layout);
    rankingProgressBar = view.findViewById(R.id.ranking_progress_bar);
    rankingProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(getContext(), R.color.green_button), android.graphics.PorterDuff.Mode.SRC_IN);
    View busPickerButton = view.findViewById(R.id.bus_layout);
    userBusAvatarView = view.findViewById(R.id.user_bus_avatar);
    View closeSessionButton = view.findViewById(R.id.close_session_button);
    closeSessionButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CloseSessionDialog dialog = new CloseSessionDialog();
            dialog.setListener(new CloseSessionDialog.OnButtonClickListener() {

                @Override
                public void onPositiveButtonClick() {
                    TranSappAccountManager.logOut(new AccountLogOutListener() {

                        @Override
                        public void onLoggedOut() {
                            callback.onLogout();
                        }

                        @Override
                        public void onError(ServerStatusCode error) {
                            // TODO(aantoine): show error message
                            callback.onLogout();
                        }
                    });
                }

                @Override
                public void onNegativeButtonClick() {
                }
            });
            dialog.show(getFragmentManager(), dialog.getClass().getSimpleName());
        }
    });
    View editButton = view.findViewById(R.id.edit_button);
    editButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivityForResult(new Intent(getActivity(), AccountSettingsActivity.class), USER_SETTINGS_CODE);
        }
    });
    busPickerButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivityForResult(new Intent(getActivity(), AccountBusPickerActivity.class), USER_BUS_PICKER_CODE);
        }
    });
    updateUI();
    return view;
}
Also used : AccountLogOutListener(cl.smartcities.isci.transportinspector.gamification.ui.listener.AccountLogOutListener) CloseSessionDialog(cl.smartcities.isci.transportinspector.dialogs.CloseSessionDialog) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) ActiveBusView(cl.smartcities.isci.transportinspector.drawables.ActiveBusView) TextView(android.widget.TextView)

Example 2 with ServerStatusCode

use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.

the class FacebookDataManager method getCredentials.

void getCredentials(final CredentialsListener listener) {
    Log.d(TAG, "getUserData");
    final AccessToken currentToken = AccessToken.getCurrentAccessToken();
    GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), "/me", null, HttpMethod.GET, new GraphRequest.Callback() {

        public void onCompleted(GraphResponse response) {
            try {
                Profile profile = Profile.getCurrentProfile();
                String email = response.getJSONObject().getString("email");
                String name = response.getJSONObject().getString("name");
                String imageUri = profile.getProfilePictureUri(200, 200).toString();
                SocialMediaCredentials credentials = new SocialMediaCredentials(currentToken.getToken(), currentToken.getUserId(), FACEBOOK_ACCOUNT, name, email, imageUri);
                listener.onSuccess(new FacebookAccount(credentials));
            } catch (JSONException | NullPointerException e) {
                listener.onError(new ServerStatusCode(ServerStatusCode.LOGIN_API_ERROR));
                Log.e(TAG, e.getMessage() == null ? "null message" : e.getMessage());
            }
        }
    });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,email");
    request.setParameters(parameters);
    request.executeAsync();
}
Also used : GraphRequest(com.facebook.GraphRequest) GraphResponse(com.facebook.GraphResponse) AccessToken(com.facebook.AccessToken) Bundle(android.os.Bundle) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) SocialMediaCredentials(cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaCredentials) Profile(com.facebook.Profile)

Example 3 with ServerStatusCode

use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.

the class LoginFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_account_login_fragment, container, false);
    facebookCallbackManager = CallbackManager.Factory.create();
    googleCallbackManager = new GoogleAccountLoginner.CallbackManager();
    facebookLoginView = view.findViewById(R.id.login_button);
    googleLoginView = view.findViewById(R.id.google_signin_button);
    loadingView = view.findViewById(R.id.loading_layout);
    termsAndConditions = view.findViewById(R.id.terms_and_conditions);
    termsAndConditions.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.terms_and_conditions_url)));
            startActivity(browserIntent);
        }
    });
    // termsAndConditions.setMovementMethod(LinkMovementMethod.getInstance());
    // termsAndConditions.setText(text);
    final CredentialsListener listener = new CredentialsListener() {

        @Override
        public void onSuccess(SocialMediaAccount account) {
            SocialMediaAccount.setCurrentAccount(account);
            loginCallback.onSocialNetworkLogin();
        }

        @Override
        public void onError(ServerStatusCode error) {
            facebookLoginView.setClickable(true);
            googleLoginView.setClickable(true);
            if (error.getErrorCode() == ServerStatusCode.INVALID_USER) {
                throw new IllegalStateException("Point of no return: There is no possible flow for this");
            } else {
                Toast.makeText(TranSappApplication.getAppContext(), "No se pudo iniciar sesiĆ³n", Toast.LENGTH_SHORT).show();
            }
        }
    };
    facebookLoginView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            facebookLoginView.setClickable(false);
            googleLoginView.setClickable(false);
            FacebookAccountLoginner loginner = new FacebookAccountLoginner(listener, LoginFragment.this);
            loginner.login();
        }
    });
    googleLoginView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            googleLoginView.setClickable(false);
            facebookLoginView.setClickable(false);
            GoogleAccountLoginner loginner = new GoogleAccountLoginner(listener, LoginFragment.this, googleCallbackManager);
            loginner.login();
        }
    });
    return view;
}
Also used : SocialMediaAccount(cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) GoogleAccountLoginner(cl.smartcities.isci.transportinspector.gamification.socialAccount.google.GoogleAccountLoginner) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) FacebookAccountLoginner(cl.smartcities.isci.transportinspector.gamification.socialAccount.facebook.FacebookAccountLoginner) CredentialsListener(cl.smartcities.isci.transportinspector.gamification.socialAccount.CredentialsListener)

Example 4 with ServerStatusCode

use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.

the class SocialAccountLoaderManager method loadAccount.

public void loadAccount(final LoaderInterface loaderInterface) {
    String accountType = preferences.getString(accountTypeKey, accountTypeKeyNull);
    CredentialsListener listener = new CredentialsListener() {

        @Override
        public void onSuccess(SocialMediaAccount account) {
            String nickname = TranSappApplication.getAppSharedPreferences().getString(SAVED_NICKNAME, "");
            loaderInterface.onLoad(account, nickname);
        }

        @Override
        public void onError(ServerStatusCode error) {
            loaderInterface.onError();
        }
    };
    switch(accountType) {
        case SocialMediaAccount.FACEBOOK_ACCOUNT:
            SocialAccountLoader facebookAccountLoader = new FacebookAccountLoader();
            facebookAccountLoader.load(listener);
            break;
        case SocialMediaAccount.GOOGLE_ACCOUNT:
            SocialAccountLoader googleAccountLoader = new GoogleAccountLoader();
            googleAccountLoader.load(listener);
            break;
        default:
            loaderInterface.onError();
    }
}
Also used : SocialMediaAccount(cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount) FacebookAccountLoader(cl.smartcities.isci.transportinspector.gamification.socialAccount.facebook.FacebookAccountLoader) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) GoogleAccountLoader(cl.smartcities.isci.transportinspector.gamification.socialAccount.google.GoogleAccountLoader) SocialAccountLoader(cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialAccountLoader) CredentialsListener(cl.smartcities.isci.transportinspector.gamification.socialAccount.CredentialsListener)

Example 5 with ServerStatusCode

use of cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode in project androidApp by InspectorIncognito.

the class TranSappAccountManager method handleLoginResult.

private static void handleLoginResult(String result, AccountLogInListener listener, String nickname, SocialMediaAccount socialMediaAccount) {
    try {
        JSONObject data = new JSONObject(result);
        int status = data.getInt("status");
        if (status == ServerStatusCode.OK) {
            account = createAccountFromLoginResult(result, nickname, socialMediaAccount);
        } else {
            Log.d(TAG, "Server responded error code " + status);
            socialMediaAccount.logout();
            listener.onError(new ServerStatusCode(status));
            return;
        }
    } catch (JSONException e) {
        e.printStackTrace();
        socialMediaAccount.logout();
        Log.d(TAG, "Server respond parse error");
        listener.onError(new ServerStatusCode(ServerStatusCode.PARSE_ERROR));
        return;
    }
    listener.onAccountReady(account);
}
Also used : JSONObject(org.json.JSONObject) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) JSONException(org.json.JSONException)

Aggregations

ServerStatusCode (cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode)13 SocialMediaAccount (cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount)4 Intent (android.content.Intent)3 View (android.view.View)3 CredentialsListener (cl.smartcities.isci.transportinspector.gamification.socialAccount.CredentialsListener)3 AccessToken (com.facebook.AccessToken)3 Bundle (android.os.Bundle)2 TextView (android.widget.TextView)2 CloseSessionDialog (cl.smartcities.isci.transportinspector.dialogs.CloseSessionDialog)2 AccountLogOutListener (cl.smartcities.isci.transportinspector.gamification.ui.listener.AccountLogOutListener)2 Request (cl.smartcities.isci.transportinspector.serverConnection.requests.Request)2 LoginRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.LoginRequest)2 LogoutRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.LogoutRequest)2 AccessTokenTracker (com.facebook.AccessTokenTracker)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 AvatarView (agency.tango.android.avatarview.views.AvatarView)1 ProgressDialog (android.app.ProgressDialog)1 NonNull (android.support.annotation.NonNull)1 EditText (android.widget.EditText)1