Manage recipient activity.

This commit is contained in:
Alan Evans
2020-06-16 17:42:54 -03:00
committed by Greyson Parrelli
parent d9641128a8
commit b53827f32b
32 changed files with 1869 additions and 102 deletions

View File

@@ -1,129 +0,0 @@
package org.thoughtcrime.securesms.groups.ui.creategroup;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.TextView;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.material.appbar.AppBarLayout;
import org.thoughtcrime.securesms.R;
import java.lang.ref.WeakReference;
public final class GroupSettingsCoordinatorLayoutBehavior extends CoordinatorLayout.Behavior<View> {
private static final Interpolator INTERPOLATOR = new DecelerateInterpolator();
private final ViewRef avatarTargetRef = new ViewRef(R.id.avatar_target);
private final ViewRef groupNameRef = new ViewRef(R.id.group_name);
private final ViewRef groupNameTargetRef = new ViewRef(R.id.group_name_target);
private final Rect targetRect = new Rect();
private final Rect childRect = new Rect();
public GroupSettingsCoordinatorLayoutBehavior(@NonNull Context context, @Nullable AttributeSet attrs) {
}
@Override
public boolean layoutDependsOn(@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull View dependency) {
return dependency instanceof AppBarLayout;
}
@Override
public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull View dependency) {
AppBarLayout appBarLayout = (AppBarLayout) dependency;
int range = appBarLayout.getTotalScrollRange();
float factor = INTERPOLATOR.getInterpolation(-appBarLayout.getY() / range);
updateAvatarPositionAndScale(parent, child, factor);
updateNamePosition(parent, factor);
return true;
}
private void updateAvatarPositionAndScale(@NonNull CoordinatorLayout parent, @NonNull View child, float factor) {
View target = avatarTargetRef.require(parent);
targetRect.set(target.getLeft(), target.getTop(), target.getRight(), target.getBottom());
childRect.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
float widthScale = 1f - (1f - (targetRect.width() / (float) childRect.width())) * factor;
float heightScale = 1f - (1f - (targetRect.height() / (float) childRect.height())) * factor;
float superimposedLeft = childRect.left + (childRect.width() - targetRect.width()) / 2f;
float superimposedTop = childRect.top + (childRect.height() - targetRect.height()) / 2f;
float xTranslation = (targetRect.left - superimposedLeft) * factor;
float yTranslation = (targetRect.top - superimposedTop) * factor;
child.setScaleX(widthScale);
child.setScaleY(heightScale);
child.setTranslationX(xTranslation);
child.setTranslationY(yTranslation);
}
private void updateNamePosition(@NonNull CoordinatorLayout parent, float factor) {
TextView child = (TextView) groupNameRef.require(parent);
View target = groupNameTargetRef.require(parent);
targetRect.set(target.getLeft(), target.getTop(), target.getRight(), target.getBottom());
childRect.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
if (child.getMaxWidth() != targetRect.width()) {
child.setMaxWidth(targetRect.width());
}
float deltaTop = targetRect.top - childRect.top;
float deltaStart = getStart(parent, targetRect) - getStart(parent, childRect);
float yTranslation = deltaTop * factor;
float xTranslation = deltaStart * factor;
child.setTranslationY(yTranslation);
child.setTranslationX(xTranslation);
}
private static int getStart(@NonNull CoordinatorLayout parent, @NonNull Rect rect) {
return parent.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR ? rect.left : rect.right;
}
private static final class ViewRef {
private WeakReference<View> ref = new WeakReference<>(null);
private final @IdRes int idRes;
private ViewRef(@IdRes int idRes) {
this.idRes = idRes;
}
private @NonNull View require(@NonNull View parent) {
View view = ref.get();
if (view == null) {
view = getChildOrThrow(parent, idRes);
ref = new WeakReference<>(view);
}
return view;
}
private static @NonNull View getChildOrThrow(@NonNull View parent, @IdRes int id) {
View child = parent.findViewById(id);
if (child == null) {
throw new AssertionError("Can't find view with ID " + R.id.avatar_target);
} else {
return child;
}
}
}
}

View File

@@ -91,7 +91,7 @@ public class AddGroupDetailsFragment extends Fragment {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
create = view.findViewById(R.id.create);
name = view.findViewById(R.id.group_name);
name = view.findViewById(R.id.name);
toolbar = view.findViewById(R.id.toolbar);
setCreateEnabled(false, false);

View File

@@ -27,10 +27,11 @@ import org.thoughtcrime.securesms.MediaPreviewActivity;
import org.thoughtcrime.securesms.MuteDialog;
import org.thoughtcrime.securesms.PushContactSelectionActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.color.MaterialColor;
import org.thoughtcrime.securesms.components.AvatarImageView;
import org.thoughtcrime.securesms.components.ThreadPhotoRailView;
import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto;
import org.thoughtcrime.securesms.contacts.avatars.GroupFallbackPhoto80;
import org.thoughtcrime.securesms.contacts.avatars.FallbackPhoto80dp;
import org.thoughtcrime.securesms.groups.GroupId;
import org.thoughtcrime.securesms.groups.ui.GroupMemberListView;
import org.thoughtcrime.securesms.groups.ui.LeaveGroupDialog;
@@ -97,7 +98,7 @@ public class ManageGroupFragment extends Fragment {
private final Recipient.FallbackPhotoProvider fallbackPhotoProvider = new Recipient.FallbackPhotoProvider() {
@Override
public @NonNull FallbackContactPhoto getPhotoForGroup() {
return new GroupFallbackPhoto80();
return new FallbackPhoto80dp(R.drawable.ic_group_80, MaterialColor.ULTRAMARINE);
}
};
@@ -120,7 +121,7 @@ public class ManageGroupFragment extends Fragment {
avatar = view.findViewById(R.id.group_avatar);
toolbar = view.findViewById(R.id.toolbar);
groupName = view.findViewById(R.id.group_name);
groupName = view.findViewById(R.id.name);
memberCountUnderAvatar = view.findViewById(R.id.member_count);
memberCountAboveList = view.findViewById(R.id.member_count_2);
groupMemberList = view.findViewById(R.id.group_members);