Search in sources :

Example 1 with SignedInUser

use of com.instructure.loginapi.login.model.SignedInUser in project instructure-android by instructure.

the class OAuthWebLogin method getPreviouslySignedInUsers.

// Does the CURRENT user support Multiple Users.
public static ArrayList<SignedInUser> getPreviouslySignedInUsers(Context context, String preferenceKey) {
    if (TextUtils.isEmpty(preferenceKey)) {
        prefNameOtherSignedInUsers = Const.KEY_OTHER_SIGNED_IN_USERS_PREF_NAME;
        preferenceKey = prefNameOtherSignedInUsers;
    }
    Gson gson = CanvasRestAdapter.getGSONParser();
    ArrayList<SignedInUser> signedInUsers = new ArrayList<SignedInUser>();
    SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceKey, Context.MODE_PRIVATE);
    Map<String, ?> keys = sharedPreferences.getAll();
    for (Map.Entry<String, ?> entry : keys.entrySet()) {
        SignedInUser signedInUser = null;
        try {
            signedInUser = gson.fromJson(entry.getValue().toString(), SignedInUser.class);
        } catch (IllegalStateException e) {
        } catch (JsonSyntaxException e) {
        // Once in a great while some bad formatted json get stored, if that happens we end up here.
        }
        if (signedInUser != null) {
            signedInUsers.add(signedInUser);
        }
    }
    // Sort by last signed in date.
    Collections.sort(signedInUsers);
    return signedInUsers;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) SignedInUser(com.instructure.loginapi.login.model.SignedInUser) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Map(java.util.Map)

Example 2 with SignedInUser

use of com.instructure.loginapi.login.model.SignedInUser in project instructure-android by instructure.

the class URLSignIn method setupPreviouslySignedInUsers.

private void setupPreviouslySignedInUsers() {
    Utils.d("setting user adapter");
    setupAdapterWithHeaders(previouslySignedInUserAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            if (view.getId() == R.id.canvasNetworkHeader) {
                urlEnter.setText(Const.URL_CANVAS_NETWORK);
                connectToURL();
            } else if (view.getId() == R.id.canvasHelpFooter) {
                showHelpShiftSupport();
            } else {
                SignedInUser signedInUser = (SignedInUser) previouslySignedInUserAdapter.getItem(Math.abs(position - listView.getHeaderViewsCount()));
                APIHelpers.setProtocol(signedInUser.protocol, URLSignIn.this);
                APIHelpers.setCacheUser(URLSignIn.this, signedInUser.user);
                CanvasRestAdapter.setupInstance(URLSignIn.this, signedInUser.token, signedInUser.domain);
                // Set previously signed in domain.
                OAuthWebLogin.setLastSignedInDomain(signedInUser.domain, URLSignIn.this);
                previouslySignedInUserAdapter.setSelectedUserGlobalId(OAuthWebLogin.getGlobalUserId(signedInUser.domain, signedInUser.user), signedInUser, getContext());
                checkSignedIn(false);
            }
        }
    });
}
Also used : SignedInUser(com.instructure.loginapi.login.model.SignedInUser) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 3 with SignedInUser

use of com.instructure.loginapi.login.model.SignedInUser in project instructure-android by instructure.

the class BaseLoginLandingPageActivity method loadPreviousUsers.

private void loadPreviousUsers() {
    ArrayList<SignedInUser> previousUsers = PreviousUsersUtils.get(this);
    resizePreviousUsersRecyclerView(previousUsers);
    mPreviousLoginRecyclerView.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
    mPreviousLoginRecyclerView.setAdapter(new PreviousUsersAdapter(previousUsers, new PreviousUsersAdapter.PreviousUsersEvents() {

        @Override
        public void onPreviousUserClick(SignedInUser user) {
            ApiPrefs.setProtocol(user.protocol);
            ApiPrefs.setUser(user.user);
            ApiPrefs.setDomain(user.domain);
            ApiPrefs.setToken(user.token);
            Intent intent = launchApplicationMainActivityIntent();
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
            finish();
        }

        @Override
        public void onRemovePreviousUserClick(SignedInUser user, int position) {
            PreviousUsersUtils.remove(BaseLoginLandingPageActivity.this, user);
        }

        @Override
        public void onNowEmpty() {
            ObjectAnimator fade = ObjectAnimator.ofFloat(mPreviousLoginWrapper, View.ALPHA, 1F, 0F);
            ObjectAnimator move = ObjectAnimator.ofFloat(mPreviousLoginWrapper, View.TRANSLATION_Y, 0, mPreviousLoginWrapper.getTop());
            AnimatorSet set = new AnimatorSet();
            set.playTogether(fade, move);
            set.setDuration(430);
            set.start();
        }
    }));
    mPreviousLoginWrapper.setVisibility((previousUsers.size() > 0) ? View.VISIBLE : View.GONE);
}
Also used : SignedInUser(com.instructure.loginapi.login.model.SignedInUser) ObjectAnimator(android.animation.ObjectAnimator) PreviousUsersAdapter(com.instructure.loginapi.login.adapter.PreviousUsersAdapter) Intent(android.content.Intent) AnimatorSet(android.animation.AnimatorSet) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 4 with SignedInUser

use of com.instructure.loginapi.login.model.SignedInUser in project instructure-android by instructure.

the class PreviousUsersAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    SignedInUser user = mPreviousUsers.get(position);
    ProfileUtils.loadAvatarForUser(holder.userAvatar, user.user.getName(), user.user.getAvatarUrl());
    holder.userName.setText(user.user.getName());
    holder.schoolDomain.setText(user.domain);
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mCallback != null) {
                SignedInUser user = mPreviousUsers.get(holder.getAdapterPosition());
                mCallback.onPreviousUserClick(user);
            }
        }
    });
    holder.removeUser.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mCallback != null) {
                final int position = holder.getAdapterPosition();
                SignedInUser user = mPreviousUsers.get(position);
                mCallback.onRemovePreviousUserClick(user, position);
                mPreviousUsers.remove(position);
                notifyItemRemoved(position);
                if (mPreviousUsers.size() == 0) {
                    mCallback.onNowEmpty();
                }
            }
        }
    });
}
Also used : SignedInUser(com.instructure.loginapi.login.model.SignedInUser) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) CircleImageView(de.hdodenhof.circleimageview.CircleImageView)

Example 5 with SignedInUser

use of com.instructure.loginapi.login.model.SignedInUser in project instructure-android by instructure.

the class PreviousUsersUtils method get.

// Does the CURRENT user support Multiple Users.
public static ArrayList<SignedInUser> get(Context context) {
    ArrayList<SignedInUser> signedInUsers = new ArrayList<>();
    SharedPreferences sharedPreferences = context.getSharedPreferences(SIGNED_IN_USERS_PREF_NAME, Context.MODE_PRIVATE);
    Map<String, ?> keys = sharedPreferences.getAll();
    for (Map.Entry<String, ?> entry : keys.entrySet()) {
        SignedInUser signedInUser = null;
        try {
            signedInUser = new Gson().fromJson(entry.getValue().toString(), SignedInUser.class);
        } catch (Exception ignore) {
        // Do Nothing
        }
        if (signedInUser != null) {
            signedInUsers.add(signedInUser);
        }
    }
    // Sort by last signed in date.
    Collections.sort(signedInUsers);
    return signedInUsers;
}
Also used : SignedInUser(com.instructure.loginapi.login.model.SignedInUser) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Map(java.util.Map)

Aggregations

SignedInUser (com.instructure.loginapi.login.model.SignedInUser)8 View (android.view.View)3 TextView (android.widget.TextView)3 SharedPreferences (android.content.SharedPreferences)2 ImageView (android.widget.ImageView)2 Gson (com.google.gson.Gson)2 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 Intent (android.content.Intent)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 ListView (android.widget.ListView)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 PreviousUsersAdapter (com.instructure.loginapi.login.adapter.PreviousUsersAdapter)1 Date (java.util.Date)1