Skip to content

Commit

Permalink
Code clean up.
Browse files Browse the repository at this point in the history
– Organize imports after changes in 0b1ceef
– Remove some synthetic methods
– Re-organize code by visibility.
  • Loading branch information
nickbutcher committed Dec 12, 2016
1 parent f70f4f1 commit 24cbc0b
Showing 1 changed file with 38 additions and 49 deletions.
87 changes: 38 additions & 49 deletions app/src/main/java/io/plaidapp/ui/DribbbleLogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@

package io.plaidapp.ui;

import android.animation.ObjectAnimator;
import android.app.Activity;
import android.app.SharedElementCallback;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.transition.TransitionManager;
Expand All @@ -41,8 +35,6 @@

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.plaidapp.BuildConfig;
Expand Down Expand Up @@ -72,7 +64,7 @@ public class DribbbleLogin extends Activity {
@BindView(R.id.login) Button login;
@BindView(R.id.loading) ProgressBar loading;
@BindView(R.id.login_failed_message) TextView loginFailed;
private DribbblePrefs dribbblePrefs;
DribbblePrefs dribbblePrefs;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -124,6 +116,42 @@ protected void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putBoolean(STATE_LOGIN_FAILED, isLoginFailed);
}

void showLoginFailed() {
isLoginFailed = true;
showLogin();
loginFailed.setVisibility(View.VISIBLE);
}

void showLoggedInUser() {
final Call<User> authenticatedUser = dribbblePrefs.getApi().getAuthenticatedUser();
authenticatedUser.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
final User user = response.body();
dribbblePrefs.setLoggedInUser(user);
final Toast confirmLogin = new Toast(getApplicationContext());
final View v = LayoutInflater.from(DribbbleLogin.this).inflate(R.layout
.toast_logged_in_confirmation, null, false);
((TextView) v.findViewById(R.id.name)).setText(user.name.toLowerCase());
// need to use app context here as the activity will be destroyed shortly
Glide.with(getApplicationContext())
.load(user.avatar_url)
.placeholder(R.drawable.ic_player)
.transform(new CircleTransform(getApplicationContext()))
.into((ImageView) v.findViewById(R.id.avatar));
v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable
(ContextCompat.getColor(DribbbleLogin.this, R.color.scrim),
5, Gravity.BOTTOM));
confirmLogin.setView(v);
confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
confirmLogin.setDuration(Toast.LENGTH_LONG);
confirmLogin.show();
}

@Override public void onFailure(Call<User> call, Throwable t) { }
});
}

private void showLoading() {
TransitionManager.beginDelayedTransition(container);
message.setVisibility(View.GONE);
Expand Down Expand Up @@ -157,7 +185,7 @@ private void getAccessToken(String code) {
.create((DribbbleAuthService.class));

final Call<AccessToken> accessTokenCall = dribbbleAuthApi.getAccessToken(BuildConfig
.DRIBBBLE_CLIENT_ID,
.DRIBBBLE_CLIENT_ID,
BuildConfig.DRIBBBLE_CLIENT_SECRET,
code);
accessTokenCall.enqueue(new Callback<AccessToken>() {
Expand All @@ -181,43 +209,4 @@ public void onFailure(Call<AccessToken> call, Throwable t) {
}
});
}

private void showLoginFailed() {
isLoginFailed = true;
showLogin();
loginFailed.setVisibility(View.VISIBLE);
}

private void showLoggedInUser() {
final Call<User> authenticatedUser = dribbblePrefs.getApi().getAuthenticatedUser();
authenticatedUser.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
final User user = response.body();
dribbblePrefs.setLoggedInUser(user);
final Toast confirmLogin = new Toast(getApplicationContext());
final View v = LayoutInflater.from(DribbbleLogin.this).inflate(R.layout
.toast_logged_in_confirmation, null, false);
((TextView) v.findViewById(R.id.name)).setText(user.name.toLowerCase());
// need to use app context here as the activity will be destroyed shortly
Glide.with(getApplicationContext())
.load(user.avatar_url)
.placeholder(R.drawable.ic_player)
.transform(new CircleTransform(getApplicationContext()))
.into((ImageView) v.findViewById(R.id.avatar));
v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable
(ContextCompat.getColor(DribbbleLogin.this, R.color.scrim),
5, Gravity.BOTTOM));
confirmLogin.setView(v);
confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
confirmLogin.setDuration(Toast.LENGTH_LONG);
confirmLogin.show();
}

@Override
public void onFailure(Call<User> call, Throwable t) {

}
});
}
}

0 comments on commit 24cbc0b

Please sign in to comment.