Skip to content

Commit

Permalink
Better orchestration during DN login dialog launch.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbutcher committed Nov 19, 2015
1 parent ce7ea8f commit 4e7466a
Showing 1 changed file with 44 additions and 10 deletions.
54 changes: 44 additions & 10 deletions app/src/main/java/io/plaidapp/ui/DesignerNewsLogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.transition.Transition;
import android.transition.TransitionManager;
import android.util.Log;
import android.util.Patterns;
Expand Down Expand Up @@ -69,6 +70,7 @@
import io.plaidapp.data.api.designernews.model.UserResponse;
import io.plaidapp.data.prefs.DesignerNewsPrefs;
import io.plaidapp.ui.transitions.FabDialogMorphSetup;
import io.plaidapp.util.AnimUtils;
import io.plaidapp.util.ScrimUtil;
import io.plaidapp.util.glide.CircleTransform;
import retrofit.Callback;
Expand All @@ -93,6 +95,7 @@ public class DesignerNewsLogin extends Activity {
@Bind(R.id.login) Button login;
@Bind(R.id.loading) ProgressBar loading;
private DesignerNewsPrefs designerNewsPrefs;
private boolean shouldPromptForPermission = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -101,17 +104,20 @@ protected void onCreate(Bundle savedInstanceState) {
ButterKnife.bind(this);
FabDialogMorphSetup.setupSharedEelementTransitions(this, container,
getResources().getDimensionPixelSize(R.dimen.dialog_corners));
if (getWindow().getSharedElementEnterTransition() != null) {
getWindow().getSharedElementEnterTransition().addListener(new AnimUtils
.TransitionListenerAdapter() {
@Override
public void onTransitionEnd(Transition transition) {
finishSetup();
}
});
} else {
finishSetup();
}

loading.setVisibility(View.GONE);
setupAccountAutocomplete();
username.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus && username.isAttachedToWindow()) {
username.showDropDown();
}
}
});
username.addTextChangedListener(loginFieldWatcher);
// the primer checkbox messes with focus order so force it
username.setOnEditorActionListener(new TextView.OnEditorActionListener() {
Expand Down Expand Up @@ -183,6 +189,26 @@ public void dismiss(View view) {
finishAfterTransition();
}

/**
* Postpone some of the setup steps so that we can run it after the enter transition
* (if there is one). Otherwise we may show the permissions dialog or account dropdown
* during the enter animation which is jarring.
*/
private void finishSetup() {
if (shouldPromptForPermission) {
requestPermissions(new String[]{ Manifest.permission.GET_ACCOUNTS },
PERMISSIONS_REQUEST_GET_ACCOUNTS);
shouldPromptForPermission = false;
}
username.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
maybeShowAccounts();
}
});
maybeShowAccounts();
}

private TextWatcher loginFieldWatcher = new TextWatcher() {
@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { }

Expand All @@ -194,6 +220,15 @@ public void afterTextChanged(Editable s) {
}
};

private void maybeShowAccounts() {
if (username.hasFocus()
&& username.isAttachedToWindow()
&& username.getAdapter() != null
&& username.getAdapter().getCount() > 0) {
username.showDropDown();
}
}

private boolean isLoginValid() {
return username.length() > 0 && password.length() > 0;
}
Expand Down Expand Up @@ -313,8 +348,7 @@ private void setupAccountAutocomplete() {
setupPermissionPrimer();
} else {
permissionPrimer.setVisibility(View.GONE);
requestPermissions(new String[]{ Manifest.permission.GET_ACCOUNTS },
PERMISSIONS_REQUEST_GET_ACCOUNTS);
shouldPromptForPermission = true;
}
}
}
Expand Down

0 comments on commit 4e7466a

Please sign in to comment.