...
  View open merge request
Commits (1)
package org.briarproject.briar.android.contact.add.remote;
import android.animation.ObjectAnimator;
import android.arch.lifecycle.ViewModelProvider;
import android.arch.lifecycle.ViewModelProviders;
import android.content.ClipData;
......@@ -11,7 +12,9 @@ import android.support.v4.app.ShareCompat.IntentBuilder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
......@@ -34,7 +37,8 @@ import static org.briarproject.briar.android.util.UiUtils.observeOnce;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class LinkExchangeFragment extends BaseFragment {
public class LinkExchangeFragment extends BaseFragment
implements OnGlobalLayoutListener {
private static final String TAG = LinkExchangeFragment.class.getName();
......@@ -90,9 +94,30 @@ public class LinkExchangeFragment extends BaseFragment {
observeOnce(viewModel.getHandshakeLink(), this,
this::onHandshakeLinkLoaded);
if (savedInstanceState == null) {
ScrollView scrollView = (ScrollView) v;
// we need to wait for views to be laid out to get the heights
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(this);
}
return v;
}
@Override
public void onGlobalLayout() {
ScrollView scrollView = (ScrollView) requireNonNull(getView());
View layout = scrollView.getChildAt(0);
int scrollBy = layout.getHeight() - scrollView.getHeight();
if (scrollBy > 0) {
// smoothScrollTo() is too fast due to the transition animation
ObjectAnimator animator = ObjectAnimator
.ofInt(scrollView, "scrollY", scrollBy);
animator.setDuration(1000);
animator.start();
}
layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
private void onHandshakeLinkLoaded(String link) {
View v = requireNonNull(getView());
......
......@@ -26,7 +26,8 @@
app:layout_constraintEnd_toStartOf="@+id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"/>
app:layout_constraintVertical_bias="0.0"
app:layout_constraintVertical_chainStyle="packed"/>
<TextView
android:id="@+id/stepOneText"
......@@ -74,12 +75,14 @@
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="32dp"
android:src="@drawable/ic_nickname"
app:layout_constraintBottom_toTopOf="@+id/nicknameIcon"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_max="256dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/stepOneText"
tools:ignore="ContentDescription"/>
......@@ -118,6 +121,7 @@
android:layout_marginTop="16dp"
app:errorEnabled="true"
app:hintEnabled="false"
app:layout_constraintBottom_toTopOf="@+id/space"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
......@@ -133,6 +137,16 @@
</android.support.design.widget.TextInputLayout>
<Space
android:id="@+id/space"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/addButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="wrap"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/contactNameLayout"/>
<Button
android:id="@+id/addButton"
style="@style/BriarButton"
......