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;
}
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);
}
}
});
}
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);
}
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();
}
}
}
});
}
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;
}
Aggregations