Skip to content

Commit

Permalink
Showing some constraint.
Browse files Browse the repository at this point in the history
Switched to ConstraintLayout on Dribbble player screen, this pancake
flat hierarchy resolves some clipping issues we were seeing on the
entry/exit transition & makes me happy.
  • Loading branch information
nickbutcher committed Nov 2, 2016
1 parent e5e2bc8 commit 74f588c
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 160 deletions.
11 changes: 6 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,18 @@ repositories {
ext.supportLibVersion = '25.0.0'

dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta2'
compile "com.android.support:customtabs:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.android.support:palette-v7:${supportLibVersion}"
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.android.support:customtabs:${supportLibVersion}"
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
compile 'com.jakewharton:butterknife:8.3.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.3.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'org.jsoup:jsoup:1.9.2'
compile project(':bypass')
}
120 changes: 59 additions & 61 deletions app/src/main/java/io/plaidapp/ui/PlayerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ public class PlayerActivity extends Activity {
public static final String EXTRA_PLAYER_ID = "EXTRA_PLAYER_ID";
public static final String EXTRA_PLAYER_USERNAME = "EXTRA_PLAYER_USERNAME";

private User player;
private CircleTransform circleTransform;
private PlayerShotsDataManager dataManager;
private FeedAdapter adapter;
private GridLayoutManager layoutManager;
User player;
PlayerShotsDataManager dataManager;
FeedAdapter adapter;
GridLayoutManager layoutManager;
Boolean following;
private ElasticDragDismissFrameLayout.SystemChromeFader chromeFader;
private Boolean following;
private CircleTransform circleTransform;
private int followerCount;

@BindView(R.id.draggable_frame) ElasticDragDismissFrameLayout draggableFrame;
@BindView(R.id.player_description) ViewGroup playerDescription;
@BindView(R.id.container) ViewGroup container;
@BindView(R.id.avatar) ImageView avatar;
@BindView(R.id.player_name) TextView playerName;
@BindView(R.id.follow) Button follow;
Expand Down Expand Up @@ -110,7 +110,7 @@ protected void onCreate(Bundle savedInstanceState) {
String name = intent.getStringExtra(EXTRA_PLAYER_NAME);
playerName.setText(name);
if (intent.hasExtra(EXTRA_PLAYER_ID)) {
long userId = intent.getLongExtra(EXTRA_PLAYER_ID, 0l);
long userId = intent.getLongExtra(EXTRA_PLAYER_ID, 0L);
loadPlayer(userId);
} else if (intent.hasExtra(EXTRA_PLAYER_USERNAME)) {
String username = intent.getStringExtra(EXTRA_PLAYER_USERNAME);
Expand All @@ -133,7 +133,7 @@ public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
lpFrame.rightMargin += insets.getSystemWindowInsetRight(); // landscape
((ViewGroup.MarginLayoutParams) avatar.getLayoutParams()).topMargin
+= insets.getSystemWindowInsetTop();
ViewUtils.setPaddingTop(playerDescription, insets.getSystemWindowInsetTop());
ViewUtils.setPaddingTop(container, insets.getSystemWindowInsetTop());
ViewUtils.setPaddingBottom(shots, insets.getSystemWindowInsetBottom());
// clear this listener so insets aren't re-applied
draggableFrame.setOnApplyWindowInsetsListener(null);
Expand Down Expand Up @@ -170,8 +170,8 @@ public void onActivityReenter(int resultCode, Intent data) {

// When reentering, if the shared element is no longer on screen (e.g. after an
// orientation change) then scroll it into view.
final long sharedShotId = data.getLongExtra(DribbbleShot.RESULT_EXTRA_SHOT_ID, -1l);
if (sharedShotId != -1l // returning from a shot
final long sharedShotId = data.getLongExtra(DribbbleShot.RESULT_EXTRA_SHOT_ID, -1L);
if (sharedShotId != -1L // returning from a shot
&& adapter.getDataItemCount() > 0 // grid populated
&& shots.findViewHolderForItemId(sharedShotId) == null) { // view not attached
final int position = adapter.getItemPosition(sharedShotId);
Expand All @@ -191,10 +191,8 @@ public void onLayoutChange(View v, int l, int t, int r, int b,
}
}

private void bindPlayer() {
if (player == null) {
return;
}
void bindPlayer() {
if (player == null) return;

final Resources res = getResources();
final NumberFormat nf = NumberFormat.getInstance();
Expand Down Expand Up @@ -228,7 +226,7 @@ public void onDataLoaded(List<Shot> data) {
if (data != null && data.size() > 0) {
if (adapter.getDataItemCount() == 0) {
loading.setVisibility(View.GONE);
ViewUtils.setPaddingTop(shots, playerDescription.getHeight());
ViewUtils.setPaddingTop(shots, likesCount.getBottom());
}
adapter.addAndResort(data);
}
Expand Down Expand Up @@ -264,14 +262,14 @@ public boolean onTouch(View v, MotionEvent event) {

// if no data loaded then pass through
if (adapter.getDataItemCount() == 0) {
return playerDescription.dispatchTouchEvent(event);
return container.dispatchTouchEvent(event);
}

final RecyclerView.ViewHolder vh = shots.findViewHolderForAdapterPosition(0);
if (vh == null) return false;
final int firstTop = vh.itemView.getTop();
if (event.getY() < firstTop) {
return playerDescription.dispatchTouchEvent(event);
return container.dispatchTouchEvent(event);
}
return false;
}
Expand All @@ -280,9 +278,9 @@ public boolean onTouch(View v, MotionEvent event) {
// check if following
if (dataManager.getDribbblePrefs().isLoggedIn()) {
if (player.id == dataManager.getDribbblePrefs().getUserId()) {
TransitionManager.beginDelayedTransition(playerDescription);
TransitionManager.beginDelayedTransition(container);
follow.setVisibility(View.GONE);
ViewUtils.setPaddingTop(shots, playerDescription.getHeight() - follow.getHeight()
ViewUtils.setPaddingTop(shots, container.getHeight() - follow.getHeight()
- ((ViewGroup.MarginLayoutParams) follow.getLayoutParams()).bottomMargin);
} else {
final Call<Void> followingCall = dataManager.getDribbbleApi().following(player.id);
Expand All @@ -291,7 +289,7 @@ public boolean onTouch(View v, MotionEvent event) {
public void onResponse(Call<Void> call, Response<Void> response) {
following = response.isSuccessful();
if (!following) return;
TransitionManager.beginDelayedTransition(playerDescription);
TransitionManager.beginDelayedTransition(container);
follow.setText(R.string.following);
follow.setActivated(true);
}
Expand All @@ -308,43 +306,8 @@ public void onResponse(Call<Void> call, Response<Void> response) {
}
}

private void loadPlayer(long userId) {
final Call<User> userCall = DribbblePrefs.get(this).getApi().getUser(userId);
userCall.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
player = response.body();
bindPlayer();
}

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

private void loadPlayer(String username) {
final Call<User> userCall = DribbblePrefs.get(this).getApi().getUser(username);
userCall.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
player = response.body();
bindPlayer();
}

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

private void setFollowerCount(int count) {
followerCount = count;
followersCount.setText(getResources().getQuantityString(R.plurals.follower_count,
followerCount, NumberFormat.getInstance().format(followerCount)));
if (followerCount == 0) {
followersCount.setBackground(null);
}
}

@OnClick(R.id.follow)
/* package */ void follow() {
void follow() {
if (DribbblePrefs.get(this).isLoggedIn()) {
if (following != null && following) {
final Call<Void> unfollowCall = dataManager.getDribbbleApi().unfollow(player.id);
Expand All @@ -354,7 +317,7 @@ private void setFollowerCount(int count) {
@Override public void onFailure(Call<Void> call, Throwable t) { }
});
following = false;
TransitionManager.beginDelayedTransition(playerDescription);
TransitionManager.beginDelayedTransition(container);
follow.setText(R.string.follow);
follow.setActivated(false);
setFollowerCount(followerCount - 1);
Expand All @@ -366,7 +329,7 @@ private void setFollowerCount(int count) {
@Override public void onFailure(Call<Void> call, Throwable t) { }
});
following = true;
TransitionManager.beginDelayedTransition(playerDescription);
TransitionManager.beginDelayedTransition(container);
follow.setText(R.string.following);
follow.setActivated(true);
setFollowerCount(followerCount + 1);
Expand All @@ -382,8 +345,8 @@ private void setFollowerCount(int count) {
}
}

@OnClick({R.id.shot_count, R.id.followers_count, R.id.likes_count })
/* package */ void playerActionClick(TextView view) {
@OnClick({R.id.shot_count, R.id.followers_count, R.id.likes_count})
void playerActionClick(TextView view) {
((AnimatedVectorDrawable) view.getCompoundDrawables()[1]).start();
switch (view.getId()) {
case R.id.followers_count:
Expand All @@ -392,4 +355,39 @@ private void setFollowerCount(int count) {
}
}

private void loadPlayer(long userId) {
final Call<User> userCall = DribbblePrefs.get(this).getApi().getUser(userId);
userCall.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
player = response.body();
bindPlayer();
}

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

private void loadPlayer(String username) {
final Call<User> userCall = DribbblePrefs.get(this).getApi().getUser(username);
userCall.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
player = response.body();
bindPlayer();
}

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

private void setFollowerCount(int count) {
followerCount = count;
followersCount.setText(getResources().getQuantityString(R.plurals.follower_count,
followerCount, NumberFormat.getInstance().format(followerCount)));
if (followerCount == 0) {
followersCount.setBackground(null);
}
}

}
Loading

0 comments on commit 74f588c

Please sign in to comment.